You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "errose28 (via GitHub)" <gi...@apache.org> on 2025/02/22 00:08:14 UTC
[PR] HDDS-12078 improve cli [ozone]
errose28 opened a new pull request, #7944:
URL: https://github.com/apache/ozone/pull/7944
## What changes were proposed in this pull request?
### Summary
Currently ozone admin container reconcile is used to trigger reconciliation for a specific container, but the resulting checksums are only shown in ozone admin container info --json which can be verbose and usually requires jq filtering to get the desired information.
This PR adds new functionality to the `ozone admin container reconcile command`:
- Multiple container IDs can be passed: `ozone admin container reconcile 1 2 3 4`
- IDs can be read from stdin, similar to `ozone admin container info`: `cat <id-file> | ozone admin container reconcile -`
- Either of the above options work with a `--status` flag that prints replica and checksum information instead of sending reconcile commands: `ozone admin container reconcile --status 1 2 3 4`
- In the status output, a `replicasMatch` field is set to `true` or `false` on the client side, which can be used to quickly filter out containers with mismatched replicas.
No proto changes are made. The same `ScmClient#getContainer` and `ScmClient#getContainerReplicas` methods used by `ozone admin container info` are re-used for `ozone admin container reconcile --status`. This command just provides a more filtered view of the results specific to reconciliation and adds the `replicasMatch` field.
### Examples
Querying status of one container:
```
$ ozone admin container reconcile --status 1
[ {
"containerID" : 1,
"state" : "CLOSING",
"replicationConfig" : {
"replicationFactor" : "THREE",
"requiredNodes" : 3,
"minimumNodes" : 1,
"replicationType" : "RATIS"
},
"replicasMatch" : true,
"replicas" : [ {
"datanode" : {
"hostname" : "ha-dn4-1.ha_net",
"uuid" : "cf484945-b60f-4906-9c4c-024ba429783a"
},
"state" : "OPEN",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn5-1.ha_net",
"uuid" : "927a2620-feb9-43f0-bf0c-3be63eae8f46"
},
"state" : "OPEN",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn3-1.ha_net",
"uuid" : "e39fb4dc-c676-4ace-a3f0-d52c8a3a21c8"
},
"state" : "OPEN",
"dataChecksum" : "0"
} ]
} ]
```
Querying the status of multiple containers (json list output):
```
sh-4.4$ ozone admin container reconcile --status 1 3
[ {
"containerID" : 1,
"state" : "CLOSED",
"replicationConfig" : {
"replicationFactor" : "THREE",
"requiredNodes" : 3,
"minimumNodes" : 1,
"replicationType" : "RATIS"
},
"replicasMatch" : true,
"replicas" : [ {
"datanode" : {
"hostname" : "ha-dn4-1.ha_net",
"uuid" : "cf484945-b60f-4906-9c4c-024ba429783a"
},
"state" : "CLOSED",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn5-1.ha_net",
"uuid" : "927a2620-feb9-43f0-bf0c-3be63eae8f46"
},
"state" : "CLOSED",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn3-1.ha_net",
"uuid" : "e39fb4dc-c676-4ace-a3f0-d52c8a3a21c8"
},
"state" : "CLOSED",
"dataChecksum" : "0"
} ]
}, {
"containerID" : 3,
"state" : "OPEN",
"replicationConfig" : {
"replicationFactor" : "THREE",
"requiredNodes" : 3,
"minimumNodes" : 1,
"replicationType" : "RATIS"
},
"replicasMatch" : true,
"replicas" : [ {
"datanode" : {
"hostname" : "ha-dn5-1.ha_net",
"uuid" : "927a2620-feb9-43f0-bf0c-3be63eae8f46"
},
"state" : "OPEN",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn3-1.ha_net",
"uuid" : "e39fb4dc-c676-4ace-a3f0-d52c8a3a21c8"
},
"state" : "OPEN",
"dataChecksum" : "0"
}, {
"datanode" : {
"hostname" : "ha-dn4-1.ha_net",
"uuid" : "cf484945-b60f-4906-9c4c-024ba429783a"
},
"state" : "OPEN",
"dataChecksum" : "0"
} ]
} ]
```
Given a list of container IDs in a file, output the IDs of all the ones with mismatched replicas:
```
$ cat ids.txt | ozone admin container reconcile --status - | jq '.[] | select(.replicasMatch = false) | .containerID'
1
3
```
Same as above, but now send the IDs of mismatched containers back in for reconciliation (TODO clean up duplicate output):
```
cat ids.txt | ozone admin container reconcile --status - | jq '.[] | select(.replicasMatch = true) | .containerID' | ozone admin container reconcile -
Reconciliation has been triggered for container 1
Use "ozone admin container reconcile --status 1" to see the checksums of each container replica
Reconciliation has been triggered for container 3
Use "ozone admin container reconcile --status 3" to see the checksums of each container replica
```
## What is the link to the Apache JIRA
HDDS-12078
## How was this patch tested?
- [x] Tested manually in docker
- [ ] Unit tests (WIP)
- [ ] Update existing acceptance tests (WIP)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3198694125
I found more issues with the output after trying things manually, which should be fixed now. I also updated the jq queries used in acceptance tests that were previously failing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2244043548
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
+ } else {
+ // A list of containers was provided.
+ idIterator = containerList.iterator();
+ }
+
+ if (status) {
+ // Automatically creates one array for the output, while allowing us to flush each object individually.
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
Review Comment:
Validation has been added in the latest set of changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-2683795466
> I prefer robot tests over integration tests. Overall seems fine, will go over a few more times.
Yes I will add robot tests as well. The current tests are unit tests without a mini ozone cluster. The scm client is mocked to return various combinations of replicas that would otherwise be hard to create in a mini ozone or docker cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3247602911
Thanks @aswinshakil for the review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 merged PR #7944:
URL: https://github.com/apache/ozone/pull/7944
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3138099261
The latest updates should have all functionality and unit tests. Just acceptance tests need to be updated. I've added container ID validation in the common `containerIDParameters#getValidatedIDs` so we can use the same validation for other commands like `ozone admin container info` as well, but migrating those can be done in a follow-up change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2271420392
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ContainerIDParameters.java:
##########
@@ -31,4 +32,34 @@ public class ContainerIDParameters extends ItemsFromStdin {
public void setContainerIDs(List<String> arguments) {
setItems(arguments);
}
+
+ public List<Long> getValidatedIDs() {
+ List<Long> containerIDs = new ArrayList<>(size());
+ boolean allValid = true;
+
+ for (String input: this) {
+ boolean idValid = true;
+ try {
+ long id = Long.parseLong(input);
+ if (id <= 0) {
+ idValid = false;
+ } else {
+ containerIDs.add(id);
+ }
+ } catch (NumberFormatException e) {
+ idValid = false;
+ }
+
+ if (!idValid) {
+ allValid = false;
+ System.err.println("Container ID must be a positive integer, got: " + input);
+ }
+ }
+
+ // After errors have been printed for all invalid containers, exit PicoCLI with a non-zero result.
+ if (!allValid) {
+ throw new IllegalArgumentException();
Review Comment:
A message to stderr has already been printed for each invalid container, this is just to make picoCLI exit after we have finished the list. If we want a summary message of some kind we could put it here, but the user will get feedback on each error anyways.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2271461818
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ } catch (Exception ex) {
+ System.err.println("Failed get reconciliation status of container " + containerID + ": " + ex.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ private void executeReconcile(ScmClient scmClient) {
+ int failureCount = 0;
+ for (Long containerID : containerList.getValidatedIDs()) {
+ try {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + (long) containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID +
+ "\" to see the checksums of each container replica");
+ } catch (Exception ex) {
+ System.err.println("Failed to trigger reconciliation for container " + containerID + ": " + ex.getMessage());
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + failureCount + " containers");
+ }
+ }
+
+ /**
+ * Used to json serialize the container and replica information for output.
+ */
+ private static class ContainerWrapper {
+ private final long containerID;
+ private final HddsProtos.LifeCycleState state;
+ private final ReplicationConfig replicationConfig;
+ private boolean replicasMatch;
+ private final List<ReplicaWrapper> replicas;
+
+ ContainerWrapper(ContainerInfo info, List<ContainerReplicaInfo> replicas) {
+ this.containerID = info.getContainerID();
+ this.state = info.getState();
+ this.replicationConfig = info.getReplicationConfig();
+
+ this.replicas = new ArrayList<>();
+ this.replicasMatch = true;
+ long firstChecksum = 0;
+ if (!replicas.isEmpty()) {
+ firstChecksum = replicas.get(0).getDataChecksum();
+ }
+ for (ContainerReplicaInfo replica: replicas) {
+ replicasMatch = replicasMatch && (firstChecksum == replica.getDataChecksum());
+ this.replicas.add(new ReplicaWrapper(replica));
+ }
+ }
+
+ public long getContainerID() {
+ return containerID;
+ }
+
+ public HddsProtos.LifeCycleState getState() {
+ return state;
+ }
+
+ public ReplicationConfig getReplicationConfig() {
+ return replicationConfig;
+ }
+
+ public boolean getReplicasMatch() {
+ return replicasMatch;
+ }
+
+ public List<ReplicaWrapper> getReplicas() {
+ return replicas;
+ }
+ }
+
+ private static class ReplicaWrapper {
+ private final DatanodeWrapper datanode;
+ private final String state;
+ private int replicaIndex;
+ @JsonSerialize(using = JsonUtils.ChecksumSerializer.class)
+ private final long dataChecksum;
+
+ ReplicaWrapper(ContainerReplicaInfo replica) {
+ this.datanode = new DatanodeWrapper(replica.getDatanodeDetails());
+ this.state = replica.getState();
+ // Only display replica index when it has a positive value for EC.
+ if (replica.getReplicaIndex() > 0) {
+ this.replicaIndex = replica.getReplicaIndex();
+ }
+ this.dataChecksum = replica.getDataChecksum();
+ }
+
+ public DatanodeWrapper getDatanode() {
+ return datanode;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ /**
+ * Replica index is only included in the output if it is non-zero, which will be the case for EC.
+ * For Ratis, avoid printing all zero replica indices to avoid confusion.
+ */
+ @JsonInclude(JsonInclude.Include.NON_DEFAULT)
+ public int getReplicaIndex() {
+ return replicaIndex;
+ }
+
+ public long getDataChecksum() {
+ return dataChecksum;
+ }
+ }
+
+ private static class DatanodeWrapper {
Review Comment:
It's harder to match json queries to the value returned by that method because the ID, hostname, and IP are all mixed together. If we want IP I can add it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1970837346
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
+ } else {
+ // A list of containers was provided.
+ idIterator = containerList.iterator();
+ }
+
+ if (status) {
+ // Automatically creates one array for the output, while allowing us to flush each object individually.
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
Review Comment:
Good catch. Forgot this wasn't being handled as a long automatically by picocli. Will add a test for this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3235031342
Each status is a separate call to SCM and the json is streamed as it is generated so it won't create a giant proto to send over the network or fill up client memory. The CLI to query status of multiple containers is a shorthand for running something like `for i in {1..1000} do; ozone admin container reconcile --status $i; done` so I don't think a limit per CLI invocation has any benefit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "aswinshakil (via GitHub)" <gi...@apache.org>.
aswinshakil commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3234719611
Overall, the changes look good to me. I was wondering if we should have a limit on the number list statuses so that we don't overwhelm the system.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2274223704
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ContainerIDParameters.java:
##########
@@ -31,4 +32,34 @@ public class ContainerIDParameters extends ItemsFromStdin {
public void setContainerIDs(List<String> arguments) {
setItems(arguments);
}
+
+ public List<Long> getValidatedIDs() {
+ List<Long> containerIDs = new ArrayList<>(size());
+ boolean allValid = true;
+
+ for (String input: this) {
+ boolean idValid = true;
+ try {
+ long id = Long.parseLong(input);
+ if (id <= 0) {
+ idValid = false;
+ } else {
+ containerIDs.add(id);
+ }
+ } catch (NumberFormatException e) {
+ idValid = false;
+ }
+
+ if (!idValid) {
+ allValid = false;
+ System.err.println("Container ID must be a positive integer, got: " + input);
+ }
+ }
+
+ // After errors have been printed for all invalid containers, exit PicoCLI with a non-zero result.
+ if (!allValid) {
+ throw new IllegalArgumentException();
Review Comment:
I've added an error message for checking status of open containers and tests for this as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2271220800
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
Review Comment:
Do we want to fail the status check for open containers? I don't see much harm in just returning the 0 checksum. EC we definitely want to fail because the current `replicasMatch` check won't handle them correctly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "aswinshakil (via GitHub)" <gi...@apache.org>.
aswinshakil commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2268094661
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ } catch (Exception ex) {
+ System.err.println("Failed get reconciliation status of container " + containerID + ": " + ex.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ private void executeReconcile(ScmClient scmClient) {
+ int failureCount = 0;
+ for (Long containerID : containerList.getValidatedIDs()) {
+ try {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + (long) containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID +
+ "\" to see the checksums of each container replica");
+ } catch (Exception ex) {
+ System.err.println("Failed to trigger reconciliation for container " + containerID + ": " + ex.getMessage());
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + failureCount + " containers");
+ }
+ }
+
+ /**
+ * Used to json serialize the container and replica information for output.
+ */
+ private static class ContainerWrapper {
+ private final long containerID;
+ private final HddsProtos.LifeCycleState state;
+ private final ReplicationConfig replicationConfig;
+ private boolean replicasMatch;
+ private final List<ReplicaWrapper> replicas;
+
+ ContainerWrapper(ContainerInfo info, List<ContainerReplicaInfo> replicas) {
+ this.containerID = info.getContainerID();
+ this.state = info.getState();
+ this.replicationConfig = info.getReplicationConfig();
+
+ this.replicas = new ArrayList<>();
+ this.replicasMatch = true;
+ long firstChecksum = 0;
+ if (!replicas.isEmpty()) {
+ firstChecksum = replicas.get(0).getDataChecksum();
+ }
+ for (ContainerReplicaInfo replica: replicas) {
+ replicasMatch = replicasMatch && (firstChecksum == replica.getDataChecksum());
+ this.replicas.add(new ReplicaWrapper(replica));
+ }
+ }
+
+ public long getContainerID() {
+ return containerID;
+ }
+
+ public HddsProtos.LifeCycleState getState() {
+ return state;
+ }
+
+ public ReplicationConfig getReplicationConfig() {
+ return replicationConfig;
+ }
+
+ public boolean getReplicasMatch() {
+ return replicasMatch;
+ }
+
+ public List<ReplicaWrapper> getReplicas() {
+ return replicas;
+ }
+ }
+
+ private static class ReplicaWrapper {
+ private final DatanodeWrapper datanode;
+ private final String state;
+ private int replicaIndex;
+ @JsonSerialize(using = JsonUtils.ChecksumSerializer.class)
+ private final long dataChecksum;
+
+ ReplicaWrapper(ContainerReplicaInfo replica) {
+ this.datanode = new DatanodeWrapper(replica.getDatanodeDetails());
+ this.state = replica.getState();
+ // Only display replica index when it has a positive value for EC.
+ if (replica.getReplicaIndex() > 0) {
+ this.replicaIndex = replica.getReplicaIndex();
+ }
+ this.dataChecksum = replica.getDataChecksum();
+ }
+
+ public DatanodeWrapper getDatanode() {
+ return datanode;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ /**
+ * Replica index is only included in the output if it is non-zero, which will be the case for EC.
+ * For Ratis, avoid printing all zero replica indices to avoid confusion.
+ */
+ @JsonInclude(JsonInclude.Include.NON_DEFAULT)
+ public int getReplicaIndex() {
+ return replicaIndex;
+ }
+
+ public long getDataChecksum() {
+ return dataChecksum;
+ }
+ }
+
+ private static class DatanodeWrapper {
Review Comment:
Do we need a DatanodeWrapper? Can we not just use DatanodeDetails#toString() ?
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ContainerIDParameters.java:
##########
@@ -31,4 +32,34 @@ public class ContainerIDParameters extends ItemsFromStdin {
public void setContainerIDs(List<String> arguments) {
setItems(arguments);
}
+
+ public List<Long> getValidatedIDs() {
+ List<Long> containerIDs = new ArrayList<>(size());
+ boolean allValid = true;
+
+ for (String input: this) {
+ boolean idValid = true;
+ try {
+ long id = Long.parseLong(input);
+ if (id <= 0) {
+ idValid = false;
+ } else {
+ containerIDs.add(id);
+ }
+ } catch (NumberFormatException e) {
+ idValid = false;
+ }
+
+ if (!idValid) {
+ allValid = false;
+ System.err.println("Container ID must be a positive integer, got: " + input);
+ }
+ }
+
+ // After errors have been printed for all invalid containers, exit PicoCLI with a non-zero result.
+ if (!allValid) {
+ throw new IllegalArgumentException();
Review Comment:
Can we add an exception message here so that we know why this exception is being thrown?
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ } catch (Exception ex) {
+ System.err.println("Failed get reconciliation status of container " + containerID + ": " + ex.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ private void executeReconcile(ScmClient scmClient) {
+ int failureCount = 0;
+ for (Long containerID : containerList.getValidatedIDs()) {
+ try {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + (long) containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID +
+ "\" to see the checksums of each container replica");
+ } catch (Exception ex) {
+ System.err.println("Failed to trigger reconciliation for container " + containerID + ": " + ex.getMessage());
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + failureCount + " containers");
Review Comment:
```suggestion
throw new RuntimeException("Failed to trigger reconciliation for " + failureCount + " containers");
```
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ } catch (Exception ex) {
+ System.err.println("Failed get reconciliation status of container " + containerID + ": " + ex.getMessage());
Review Comment:
```suggestion
System.err.println("Failed to get reconciliation status of container " + containerID + ": " + ex.getMessage());
```
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
Review Comment:
We can add one more check here for `OPEN` containers so that we don't print 0 checksums for those. Also we don't reconcile `OPEN` containers, so no need to add that to the status.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2274223704
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ContainerIDParameters.java:
##########
@@ -31,4 +32,34 @@ public class ContainerIDParameters extends ItemsFromStdin {
public void setContainerIDs(List<String> arguments) {
setItems(arguments);
}
+
+ public List<Long> getValidatedIDs() {
+ List<Long> containerIDs = new ArrayList<>(size());
+ boolean allValid = true;
+
+ for (String input: this) {
+ boolean idValid = true;
+ try {
+ long id = Long.parseLong(input);
+ if (id <= 0) {
+ idValid = false;
+ } else {
+ containerIDs.add(id);
+ }
+ } catch (NumberFormatException e) {
+ idValid = false;
+ }
+
+ if (!idValid) {
+ allValid = false;
+ System.err.println("Container ID must be a positive integer, got: " + input);
+ }
+ }
+
+ // After errors have been printed for all invalid containers, exit PicoCLI with a non-zero result.
+ if (!allValid) {
+ throw new IllegalArgumentException();
Review Comment:
I've added an error message for checking status of open containers and tests for this as well.
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
Review Comment:
I've added an error message for checking status of open containers and tests for this as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1968786190
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
+ } else {
+ // A list of containers was provided.
+ idIterator = containerList.iterator();
+ }
+
+ if (status) {
+ // Automatically creates one array for the output, while allowing us to flush each object individually.
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ invalidCount++;
+ }
+ }
+ if (invalidCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + invalidCount + " containers");
+ }
+ }
+ } else {
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
+ try {
+ executeReconciliation(scmClient, containerID);
+ } catch (Exception ex) {
+ System.err.println("Failed to send reconciliation to container " + containerID + ": " + ex.getMessage());
+ invalidCount++;
+ }
+ }
+ if (invalidCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + invalidCount + " containers");
+ }
+ }
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter)
+ throws IOException {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ return true;
+ }
+
+ private void executeReconciliation(ScmClient scmClient, long containerID) throws IOException {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID + "\" to see the checksums of " +
+ "each container replica");
Review Comment:
We don't have a good way to indicate when reconciliation is completed... Maybe we add a reconciliation count as a metric to the container info?
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
+ } else {
+ // A list of containers was provided.
+ idIterator = containerList.iterator();
+ }
+
+ if (status) {
+ // Automatically creates one array for the output, while allowing us to flush each object individually.
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
Review Comment:
Might be useful to catch `NumberFormatException` and print a more friendly error message.
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
Review Comment:
Not for this PR, but we can look into brace expansion so that the CLI can specify a range {1...1000}. This can ease the scanning for status via CLI across many containers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1970182288
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
Review Comment:
We can get rid of code duplicated from container `InfoSubcommand` after #7970.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2274223051
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ } catch (Exception ex) {
+ System.err.println("Failed get reconciliation status of container " + containerID + ": " + ex.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ private void executeReconcile(ScmClient scmClient) {
+ int failureCount = 0;
+ for (Long containerID : containerList.getValidatedIDs()) {
+ try {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + (long) containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID +
+ "\" to see the checksums of each container replica");
+ } catch (Exception ex) {
+ System.err.println("Failed to trigger reconciliation for container " + containerID + ": " + ex.getMessage());
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + failureCount + " containers");
+ }
+ }
+
+ /**
+ * Used to json serialize the container and replica information for output.
+ */
+ private static class ContainerWrapper {
+ private final long containerID;
+ private final HddsProtos.LifeCycleState state;
+ private final ReplicationConfig replicationConfig;
+ private boolean replicasMatch;
+ private final List<ReplicaWrapper> replicas;
+
+ ContainerWrapper(ContainerInfo info, List<ContainerReplicaInfo> replicas) {
+ this.containerID = info.getContainerID();
+ this.state = info.getState();
+ this.replicationConfig = info.getReplicationConfig();
+
+ this.replicas = new ArrayList<>();
+ this.replicasMatch = true;
+ long firstChecksum = 0;
+ if (!replicas.isEmpty()) {
+ firstChecksum = replicas.get(0).getDataChecksum();
+ }
+ for (ContainerReplicaInfo replica: replicas) {
+ replicasMatch = replicasMatch && (firstChecksum == replica.getDataChecksum());
+ this.replicas.add(new ReplicaWrapper(replica));
+ }
+ }
+
+ public long getContainerID() {
+ return containerID;
+ }
+
+ public HddsProtos.LifeCycleState getState() {
+ return state;
+ }
+
+ public ReplicationConfig getReplicationConfig() {
+ return replicationConfig;
+ }
+
+ public boolean getReplicasMatch() {
+ return replicasMatch;
+ }
+
+ public List<ReplicaWrapper> getReplicas() {
+ return replicas;
+ }
+ }
+
+ private static class ReplicaWrapper {
+ private final DatanodeWrapper datanode;
+ private final String state;
+ private int replicaIndex;
+ @JsonSerialize(using = JsonUtils.ChecksumSerializer.class)
+ private final long dataChecksum;
+
+ ReplicaWrapper(ContainerReplicaInfo replica) {
+ this.datanode = new DatanodeWrapper(replica.getDatanodeDetails());
+ this.state = replica.getState();
+ // Only display replica index when it has a positive value for EC.
+ if (replica.getReplicaIndex() > 0) {
+ this.replicaIndex = replica.getReplicaIndex();
+ }
+ this.dataChecksum = replica.getDataChecksum();
+ }
+
+ public DatanodeWrapper getDatanode() {
+ return datanode;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ /**
+ * Replica index is only included in the output if it is non-zero, which will be the case for EC.
+ * For Ratis, avoid printing all zero replica indices to avoid confusion.
+ */
+ @JsonInclude(JsonInclude.Include.NON_DEFAULT)
+ public int getReplicaIndex() {
+ return replicaIndex;
+ }
+
+ public long getDataChecksum() {
+ return dataChecksum;
+ }
+ }
+
+ private static class DatanodeWrapper {
Review Comment:
I've added IP address to the identifying information.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1970837005
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
Review Comment:
Yeah having a "recipes" section or similar in our CLI docs would help to call out tricks like this one and some of the jq examples given in the PR description. Probably too verbose to put in our one-ish line CLI help messages and we don't have man pages, so I think website docs would be the place to add such details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1970839829
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
+ } else {
+ // A list of containers was provided.
+ idIterator = containerList.iterator();
+ }
+
+ if (status) {
+ // Automatically creates one array for the output, while allowing us to flush each object individually.
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ invalidCount++;
+ }
+ }
+ if (invalidCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + invalidCount + " containers");
+ }
+ }
+ } else {
+ int invalidCount = 0;
+ while (idIterator.hasNext()) {
+ long containerID = Long.parseLong(idIterator.next());
+ try {
+ executeReconciliation(scmClient, containerID);
+ } catch (Exception ex) {
+ System.err.println("Failed to send reconciliation to container " + containerID + ": " + ex.getMessage());
+ invalidCount++;
+ }
+ }
+ if (invalidCount > 0) {
+ throw new RuntimeException("Failed trigger reconciliation for " + invalidCount + " containers");
+ }
+ }
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter)
+ throws IOException {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
+ System.err.println("Cannot get status of container " + containerID +
+ ". Reconciliation is only supported for Ratis replicated containers");
+ return false;
+ }
+ List<ContainerReplicaInfo> replicas = scmClient.getContainerReplicas(containerID);
+ arrayWriter.write(new ContainerWrapper(containerInfo, replicas));
+ arrayWriter.flush();
+ return true;
+ }
+
+ private void executeReconciliation(ScmClient scmClient, long containerID) throws IOException {
+ scmClient.reconcileContainer(containerID);
+ System.out.println("Reconciliation has been triggered for container " + containerID);
+ System.out.println("Use \"ozone admin container reconcile --status " + containerID + "\" to see the checksums of " +
+ "each container replica");
Review Comment:
Agreed, some sort of feedback that it finished would be good. I was planning to revisit this with the SCM integration. For example, SCM may end up tracking the known in-flight reconciliations and could report the results.
Are you suggesting adding a jmx metric or just a counter in the code? I'm not sure exactly how this work, but I imagine the counter would get persisted on the DN side and SCM would see the updates. Users would then look for the count to increase when they send in a command.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1970840084
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
Review Comment:
Nice. Do you want us to review and merge that one first?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r1968798303
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
Review Comment:
It's not something Ozone CLI needs to implement. Shells like `bash` and `zsh` do that already with any command:
```bash
$ echo {1..5}
1 2 3 4 5
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2244044180
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +48,188 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Parameters(description = "One or more container IDs separated by spaces. " +
+ "To read from stdin, specify '-' and supply the container IDs " +
+ "separated by newlines.",
+ arity = "1..*",
+ paramLabel = "<container ID>")
+ private List<String> containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO a better option to check status may be added later.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ Iterator<String> idIterator;
+ // PicoCLI arity check guarantees at least one element will be present.
+ if (containerList.get(0).equals("-")) {
+ // Read from stdin.
+ idIterator = new Scanner(System.in, StandardCharsets.UTF_8.name());
Review Comment:
I've incorporated this mixin in the latest changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #7944:
URL: https://github.com/apache/ozone/pull/7944#issuecomment-3165677579
@aswinshakil I've updated the acceptance tests for the new CLI, although most of the testing is still happening in the unit test. PTAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "aswinshakil (via GitHub)" <gi...@apache.org>.
aswinshakil commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2271416134
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
Review Comment:
There is no point in displaying 0 checksum for OPEN containers in Reconciliation Status as we don't reconcile OPEN containers. We don't have to throw an error, rather skip those container.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12078. Improve container reconciliation CLIs [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #7944:
URL: https://github.com/apache/ozone/pull/7944#discussion_r2271492967
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ReconcileSubcommand.java:
##########
@@ -34,15 +45,183 @@
versionProvider = HddsVersionProvider.class)
public class ReconcileSubcommand extends ScmSubcommand {
- @CommandLine.Parameters(description = "ID of the container to reconcile")
- private long containerId;
+ @CommandLine.Mixin
+ private ContainerIDParameters containerList;
+
+ @CommandLine.Option(names = { "--status" },
+ defaultValue = "false",
+ fallbackValue = "true",
+ description = "Display the reconciliation status of this container's replicas")
+ private boolean status;
@Override
public void execute(ScmClient scmClient) throws IOException {
- scmClient.reconcileContainer(containerId);
- System.out.println("Reconciliation has been triggered for container " + containerId);
- // TODO HDDS-12078 allow status to be checked from the reconcile subcommand directly.
- System.out.println("Use \"ozone admin container info --json " + containerId + "\" to see the checksums of each " +
- "container replica");
+ if (status) {
+ executeStatus(scmClient);
+ } else {
+ executeReconcile(scmClient);
+ }
+ }
+
+ private void executeStatus(ScmClient scmClient) throws IOException {
+ // Do validation outside the json array writer, otherwise failed validation will print an empty json array.
+ List<Long> containerIDs = containerList.getValidatedIDs();
+ try (SequenceWriter arrayWriter = JsonUtils.getSequenceWriter(System.out)) {
+ // Since status is retrieved using container info, do client side validation that it is only used for Ratis
+ // containers. If EC containers are given, print a message to stderr and eventually exit non-zero, but continue
+ // processing the remaining containers.
+ int failureCount = 0;
+ for (Long containerID : containerIDs) {
+ if (!printReconciliationStatus(scmClient, containerID, arrayWriter)) {
+ failureCount++;
+ }
+ }
+ if (failureCount > 0) {
+ throw new RuntimeException("Failed to process reconciliation status for " + failureCount + " containers");
+ }
+ }
+ // Array writer will not add a newline to the end.
+ System.out.println();
+ }
+
+ private boolean printReconciliationStatus(ScmClient scmClient, long containerID, SequenceWriter arrayWriter) {
+ try {
+ ContainerInfo containerInfo = scmClient.getContainer(containerID);
+ if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.RATIS) {
Review Comment:
Seems like poor usability to skip them. For example `ozone admin container reconcile --status 1` where 1 is open will print nothing but exit 0. If it's in a list like `ozone admin container reconcile --status 1 {2...100} ` it may be even harder to tell that container got skipped. If we want to do something in this case I think the two options would be to either print an error or print the values.
Perhaps error could be helpful because we can't actually tell if the checksums match, we are only checking the placeholder value?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org