szetszwo commented on code in PR #8125:
URL: https://github.com/apache/ozone/pull/8125#discussion_r2019489076
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -721,30 +716,28 @@ public Response getOmContainersDeletedInSCM(
limit = Integer.MAX_VALUE;
}
long minContainerID = prevKey + 1;
- Iterator<ContainerInfo> deletedStateSCMContainers =
containerManager.getContainers().stream()
- .filter(containerInfo -> containerInfo.getContainerID() >=
minContainerID)
- .filter(containerInfo -> containerInfo.getState() ==
HddsProtos.LifeCycleState.DELETED)
-
.sorted(Comparator.comparingLong(ContainerInfo::getContainerID)).iterator();
+ Iterator<ContainerInfo> deletedStateSCMContainers =
containerManager.getContainerInfoIterator(
+ HddsProtos.LifeCycleState.DELETED,
ContainerID.valueOf(minContainerID));
List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList;
try (SeekableIterator<Long, ContainerMetadata> omContainers =
reconContainerMetadataManager.getContainersIterator()) {
ContainerInfo scmContainerInfo = deletedStateSCMContainers.hasNext() ?
deletedStateSCMContainers.next() : null;
- ContainerMetadata containerMetadata = omContainers.hasNext() ?
omContainers.next() : null;
List<ContainerMetadata> omContainersDeletedInSCM = new ArrayList<>();
- while (containerMetadata != null && scmContainerInfo != null
+ while (omContainers.hasNext() && scmContainerInfo != null
&& omContainersDeletedInSCM.size() < limit) {
- Long omContainerID = containerMetadata.getContainerID();
+ Long omContainerID = omContainers.peekNextKey();
Review Comment:
```diff
@@ -725,7 +726,8 @@ public Response getOmContainersDeletedInSCM(
List<ContainerMetadata> omContainersDeletedInSCM = new ArrayList<>();
while (omContainers.hasNext() && scmContainerInfo != null
&& omContainersDeletedInSCM.size() < limit) {
- Long omContainerID = omContainers.peekNextKey();
+ final ContainerMetadata omContainer = omContainers.next();
+ Long omContainerID = omContainer.getContainerID();
Long scmContainerID = scmContainerInfo.getContainerID();
if (scmContainerID.equals(omContainerID)) {
ContainerMetadata containerMetadata = omContainers.next();
```
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -628,39 +627,35 @@ public Response getContainerMisMatchInsights(
case OM:
List<ContainerInfo> nonOMContainers = new ArrayList<>();
while (scmContainerInfo != null && nonOMContainers.size() < limit) {
- Long omContainerID = containerMetadata == null ? null :
containerMetadata.getContainerID();
+ Long omContainerID = omContainers.peekNextKey();
Review Comment:
```diff
@@ -627,7 +627,8 @@ public Response getContainerMisMatchInsights(
case OM:
List<ContainerInfo> nonOMContainers = new ArrayList<>();
while (scmContainerInfo != null && nonOMContainers.size() < limit) {
- Long omContainerID = omContainers.peekNextKey();
+ final ContainerMetadata omContainer = omContainers.hasNext()?
omContainers.next() : null;
+ final Long omContainerID = omContainer != null ?
omContainer.getContainerID() : null;
Long scmContainerID = scmContainerInfo.getContainerID();
if (scmContainerID.equals(omContainerID)) {
scmContainerInfo = scmNonDeletedContainers.hasNext() ?
scmNonDeletedContainers.next() : null;
```
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/SeekableIterator.java:
##########
@@ -25,4 +25,6 @@
*/
public interface SeekableIterator<K, E> extends ClosableIterator<E> {
void seek(K position) throws IOException;
+
+ K peekNextKey();
Review Comment:
This method is not needed. Simply call `next()`; see below.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -584,29 +584,28 @@ public Response getContainerMisMatchInsights(
new ArrayList<>();
Long minContainerID = prevKey + 1;
Iterator<ContainerInfo> scmNonDeletedContainers =
- containerManager.getContainers().stream()
- .filter(containerInfo -> (containerInfo.getContainerID()
>= minContainerID))
- .filter(containerInfo -> containerInfo.getState() !=
HddsProtos.LifeCycleState.DELETED)
-
.sorted(Comparator.comparingLong(ContainerInfo::getContainerID)).iterator();
- ContainerInfo scmContainerInfo = scmNonDeletedContainers.hasNext() ?
- scmNonDeletedContainers.next() : null;
+
containerManager.getContainerInfoIterator(ContainerID.valueOf(minContainerID),
+ containerInfo -> containerInfo.getState() !=
HddsProtos.LifeCycleState.DELETED);
+ ContainerInfo scmContainerInfo = scmNonDeletedContainers.hasNext() ?
scmNonDeletedContainers.next() : null;
DataFilter dataFilter = DataFilter.fromValue(missingIn.toUpperCase());
try (SeekableIterator<Long, ContainerMetadata> omContainers =
- reconContainerMetadataManager.getContainersIterator()) {
+ reconContainerMetadataManager.getContainersIterator()) {
omContainers.seek(minContainerID);
- ContainerMetadata containerMetadata = omContainers.hasNext() ?
omContainers.next() : null;
+
switch (dataFilter) {
case SCM:
List<ContainerMetadata> notSCMContainers = new ArrayList<>();
- while (containerMetadata != null && notSCMContainers.size() < limit) {
- Long omContainerID = containerMetadata.getContainerID();
+ while (omContainers.hasNext() && notSCMContainers.size() < limit) {
+ Long omContainerID = omContainers.peekNextKey();
Review Comment:
Use `next()` instead.
```diff
@@ -596,13 +596,13 @@ public Response getContainerMisMatchInsights(
case SCM:
List<ContainerMetadata> notSCMContainers = new ArrayList<>();
while (omContainers.hasNext() && notSCMContainers.size() < limit) {
- Long omContainerID = omContainers.peekNextKey();
+ final ContainerMetadata omContainer = omContainers.next();
+ final Long omContainerID = omContainer.getContainerID();
Long scmContainerID = scmContainerInfo == null ? null :
scmContainerInfo.getContainerID();
if (omContainerID.equals(scmContainerID)) {
omContainers.seek(omContainerID + 1);
scmContainerInfo = scmNonDeletedContainers.hasNext() ?
scmNonDeletedContainers.next() : null;
} else if (scmContainerID == null ||
omContainerID.compareTo(scmContainerID) < 0) {
- ContainerMetadata omContainer = omContainers.next();
if (omContainer.getNumberOfKeys() > 0) {
notSCMContainers.add(omContainer);
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]