Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1547,17 +1547,16 @@ public BootstrapStateHandler.Lock getBootstrapStateLock() {
return lock;
}

public String pngPrintMutableGraph(String fileName, GraphType graphType)
public void pngPrintMutableGraph(String filePath, GraphType graphType)
throws IOException {
Objects.requireNonNull(fileName, "Image file name is required.");
Objects.requireNonNull(filePath, "Image file path is required.");
Objects.requireNonNull(graphType, "Graph type is required.");

PrintableGraph graph;
synchronized (this) {
graph = new PrintableGraph(forwardCompactionDAG, graphType);
graph = new PrintableGraph(backwardCompactionDAG, graphType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the switch? Or should we just print both?

Copy link
Contributor Author

@hemantk-12 hemantk-12 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my miss in previous PR. backwardCompactionDAG will give the same result as in https://user-images.githubusercontent.com/6820020/211372896-c4f6eada-3fb0-4838-bcc6-08c47606a43f.png

Attaching the images to differentiate.

  1. backwardCompactionDAG

  2. forwardCompactionDAG

}

graph.generateImage(fileName);
return fileName;
graph.generateImage(filePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,14 @@ public Iterator<? extends OzoneSnapshot> listSnapshot(

/**
* Create an image of the current compaction log DAG in the OM.
* @param fileName name of the image file.
* @param graphType type of node name to use in the graph image.
* @return path of the image file.
* @throws IOException
* @param fileNamePrefix file name prefix of the image file.
* @param graphType type of node name to use in the graph image.
* @return message which tells the image name, parent dir and OM leader
* node information.
*/
public String printCompactionLogDag(String fileName,
public String printCompactionLogDag(String fileNamePrefix,
String graphType) throws IOException {
return proxy.printCompactionLogDag(fileName, graphType);
return proxy.printCompactionLogDag(fileNamePrefix, graphType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,12 @@ void deleteSnapshot(String volumeName,

/**
* Create an image of the current compaction log DAG in the OM.
* @param fileName name of the image file.
* @param graphType type of node name to use in the graph image.
* @return path of the image file.
* @throws IOException
* @param fileNamePrefix file name prefix of the image file.
* @param graphType type of node name to use in the graph image.
* @return message which tells the image name, parent dir and OM leader
* node information.
*/
String printCompactionLogDag(String fileName, String graphType)
String printCompactionLogDag(String fileNamePrefix, String graphType)
throws IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,15 +989,15 @@ public void deleteSnapshot(String volumeName,

/**
* Create an image of the current compaction log DAG in the OM.
* @param fileName name of the image file.
* @param graphType type of node name to use in the graph image.
* @return path of the image file.
* @throws IOException
* @param fileNamePrefix file name prefix of the image file.
* @param graphType type of node name to use in the graph image.
* @return message which tells the image name, parent dir and OM leader
* node information.
*/
@Override
public String printCompactionLogDag(String fileName,
public String printCompactionLogDag(String fileNamePrefix,
String graphType) throws IOException {
return ozoneManagerClient.printCompactionLogDag(fileName, graphType);
return ozoneManagerClient.printCompactionLogDag(fileNamePrefix, graphType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ default void deleteSnapshot(String volumeName,

/**
* Create an image of the current compaction log DAG in the OM.
* @param fileName name of the image file.
* @param graphType type of node name to use in the graph image.
* @return path of the image file.
* @throws IOException
* @param fileNamePrefix file name prefix of the image file.
* @param graphType type of node name to use in the graph image.
* @return message which tells the image name, parent dir and OM leader
* node information.
*/
default String printCompactionLogDag(String fileName, String graphType)
default String printCompactionLogDag(String fileNamePrefix, String graphType)
throws IOException {
throw new UnsupportedOperationException("OzoneManager does not require " +
"this to be implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,13 +1194,13 @@ public void deleteSnapshot(String volumeName,
* {@inheritDoc}
*/
@Override
public String printCompactionLogDag(String fileName, String graphType)
public String printCompactionLogDag(String fileNamePrefix, String graphType)
throws IOException {
final PrintCompactionLogDagRequest.Builder request =
PrintCompactionLogDagRequest.newBuilder();

if (fileName != null) {
request.setFileName(fileName);
if (fileNamePrefix != null) {
request.setFileNamePrefix(fileNamePrefix);
}
if (graphType != null) {
request.setGraphType(graphType);
Expand All @@ -1211,7 +1211,7 @@ public String printCompactionLogDag(String fileName, String graphType)
.build();
final OMResponse omResponse = submitRequest(omRequest);
handleError(omResponse);
return omResponse.getPrintCompactionLogDagResponse().getImagePath();
return omResponse.getPrintCompactionLogDagResponse().getMessage();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ message DeleteSnapshotRequest {
}

message PrintCompactionLogDagRequest {
optional string fileName = 1;
optional string fileNamePrefix = 1;
optional string graphType = 2;
}

Expand Down Expand Up @@ -1879,7 +1879,7 @@ message DeleteSnapshotResponse {
}

message PrintCompactionLogDagResponse {
optional string imagePath = 1;
optional string message = 1;
}

message SnapshotMoveDeletedKeysResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@
import static org.apache.hadoop.ozone.OzoneConsts.OM_METRICS_FILE;
import static org.apache.hadoop.ozone.OzoneConsts.OM_METRICS_TEMP_FILE;
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_DIR;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
import static org.apache.hadoop.ozone.OzoneConsts.PREPARE_MARKER_KEY;
import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_DIR;
import static org.apache.hadoop.ozone.OzoneConsts.RPC_PORT;
Expand Down Expand Up @@ -4646,16 +4645,23 @@ public List<SnapshotDiffJob> listSnapshotDiffJobs(String volume,
bucket, jobStatus, listAll);
}

public String printCompactionLogDag(String fileName,
public String printCompactionLogDag(String fileNamePrefix,
String graphType)
throws IOException {

if (StringUtils.isBlank(fileName)) {
fileName = "dag-" + System.currentTimeMillis();
final UserGroupInformation ugi = getRemoteUser();
if (!isAdmin(ugi)) {
throw new OMException(
"Only Ozone admins are allowed to print compaction DAG.",
PERMISSION_DENIED);
}

// Append the tmp file prefix and image file suffix.
fileName = "/tmp" + OZONE_URI_DELIMITER + fileName + ".png";
if (StringUtils.isBlank(fileNamePrefix)) {
fileNamePrefix = "dag-";
} else {
fileNamePrefix = fileNamePrefix + "-";
}
File tempFile = File.createTempFile(fileNamePrefix, ".png");

PrintableGraph.GraphType type;

Expand All @@ -4665,10 +4671,13 @@ public String printCompactionLogDag(String fileName,
type = FILE_NAME;
}

return getMetadataManager()
getMetadataManager()
.getStore()
.getRocksDBCheckpointDiffer()
.pngPrintMutableGraph(fileName, type);
.pngPrintMutableGraph(tempFile.getAbsolutePath(), type);

return String.format("Graph was generated at '\\tmp\\%s' on OM " +
"node '%s'.", tempFile.getName(), getOMNodeId());
}

private String reconfOzoneAdmins(String newVal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,11 +1335,11 @@ private ListSnapshotDiffJobResponse listSnapshotDiffJobs(
private PrintCompactionLogDagResponse printCompactionLogDag(
PrintCompactionLogDagRequest printCompactionLogDagRequest)
throws IOException {
String imagePath = impl.printCompactionLogDag(
printCompactionLogDagRequest.getFileName(),
String message = impl.printCompactionLogDag(
printCompactionLogDagRequest.getFileNamePrefix(),
printCompactionLogDagRequest.getGraphType());
return PrintCompactionLogDagResponse.newBuilder()
.setImagePath(imagePath)
.setMessage(message)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public void deleteSnapshot(String volumeName,

}

public String printCompactionLogDag(String fileName,
public String printCompactionLogDag(String fileNamePrefix,
String graphType) throws IOException {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.io.IOException;

/**
* Handler to generate image for current compaction DAG in the OM.
* Handler to generate image for current compaction DAG in the OM leader node.
* ozone sh snapshot print-log-dag.
*/
@CommandLine.Command(
Expand All @@ -40,15 +40,15 @@
public class CompactionLogDagPrinter extends Handler
implements SubcommandWithParent {

@CommandLine.Option(names = {"-f", "--file-name"},
description = "Name of the image file. (optional)")
private String fileName;
@CommandLine.Option(names = {"-f", "--file-name-prefix"},
description = "Prefix to be use in image file name. (optional)")
private String fileNamePrefix;

// TODO: Change graphType to enum.
@CommandLine.Option(names = {"-t", "--graph-type"},
description = "Type of node name to use in the graph image.\n" +
"Accepted values are: \n" +
" file_name: to use file name as node name in DAG,\n" +
description = "Type of node name to use in the graph image. " +
"(optional)\n Accepted values are: \n" +
" file_name (default) : to use file name as node name in DAG,\n" +
" key_size: to show the no. of keys in the file along with file " +
"name in the DAG node name,\n" +
" cumulative_size: to show the cumulative size along with file " +
Expand All @@ -64,8 +64,8 @@ public Class<?> getParentType() {
@Override
protected void execute(OzoneClient client, OzoneAddress address)
throws IOException, OzoneClientException {
String imagePath = client.getObjectStore()
.printCompactionLogDag(fileName, graphType);
System.out.println("DAG image is created on path: " + imagePath);
String message = client.getObjectStore()
.printCompactionLogDag(fileNamePrefix, graphType);
System.out.println(message);
}
}