smengcl commented on code in PR #4584:
URL: https://github.com/apache/ozone/pull/4584#discussion_r1195746725


##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedSSTDumpIterator.java:
##########
@@ -180,33 +182,33 @@ public boolean hasNext() {
   public T next() {
     checkSanityOfProcess();
     currentKey = nextKey;
-    nextKey = null;
-    boolean keyFound = false;
-    while (!keyFound) {
-      try {
-        Optional<Integer> keyLength = getNextNumberInStream();
-        if (!keyLength.isPresent()) {
-          return getTransformedValue(currentKey);
-        }
-        String keyStr = readNextNumberOfCharsFromStream(keyLength.get());
-        Matcher matcher = PATTERN_MATCHER.matcher(keyStr);
-        if (keyStr.length() == keyLength.get() && matcher.find()) {
-          Optional<Integer> valueLength = getNextNumberInStream();
-          if (valueLength.isPresent()) {
-            String valueStr = readNextNumberOfCharsFromStream(
-                valueLength.get());
-            if (valueStr.length() == valueLength.get()) {
-              keyFound = true;
-              nextKey = new KeyValue(matcher.group(PATTERN_KEY_GROUP_NUMBER),
-                  matcher.group(PATTERN_SEQ_GROUP_NUMBER),
-                  matcher.group(PATTERN_TYPE_GROUP_NUMBER),
-                  valueStr);
-            }
-          }
-        }
-      } catch (IOException e) {
-        throw new RuntimeIOException(e);
+    nextKey = Optional.empty();
+    try {
+      Optional<byte[]> key = getNextByteArray();
+      if (!key.isPresent()) {
+        return getTransformedValue(currentKey);
       }
+      UnsignedLong sequenceNumber = getNextUnsignedLong()
+          .orElseThrow(() -> new IllegalStateException(
+              String.format("Error while trying to read sequence number" +
+                      " for key %s", StringUtils.bytes2String(key.get()))));
+
+      Integer type = getNextNumberInStream()
+          .orElseThrow(() -> new IllegalStateException(
+              String.format("Error while trying to read sequence number for " +
+                      "key %s with sequence number %s",
+                  StringUtils.bytes2String(key.get()),
+                  sequenceNumber.toString())));
+      byte[] val = getNextByteArray().orElseThrow(() ->
+          new IllegalStateException(
+              String.format("Error while trying to read sequence number for " +
+                      "key %s with sequence number %s of type %d",
+                  StringUtils.bytes2String(key.get()),
+                  sequenceNumber.toString(), type)));
+      nextKey = Optional.of(new KeyValue(key.get(), sequenceNumber, type, 
val));
+    } catch (IOException e) {
+      // TODO [Snapshot] : Throw custom snapshot exception

Review Comment:
   nit
   
   ```suggestion
         // TODO: [SNAPSHOT] Throw custom snapshot exception
   ```



-- 
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]

Reply via email to