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


##########
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:
   done



##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedSSTDumpIterator.java:
##########
@@ -86,51 +81,58 @@ public ManagedSSTDumpIterator(ManagedSSTDumpTool 
sstDumpTool,
    * @return Optional of the integer empty if no integer exists
    */
   private Optional<Integer> getNextNumberInStream() throws IOException {
-    StringBuilder value = new StringBuilder();
-    int val;
-    while ((val = processOutput.read()) != -1) {
-      if (val >= '0' && val <= '9') {
-        value.append((char) val);
-      } else if (value.length() > 0) {
-        break;
-      }
+    int n = processOutput.read(intBuffer, 0, 4);
+    if (n == 4) {
+      return Optional.of(ByteBuffer.wrap(intBuffer).getInt());
+    } else if (n >= 0) {
+      throw new IllegalStateException(String.format("Integer expects " +
+          "4 bytes to be read from the stream, but read only %d bytes", n));
     }
-    return value.length() > 0 ? Optional.of(Integer.valueOf(value.toString()))
-        : Optional.empty();
+    return Optional.empty();
   }
 
-  /**
-   * Reads the next n chars from the stream & makes a string.
-   *
-   * @param numberOfChars
-   * @return String of next chars read
-   * @throws IOException
-   */
-  private String readNextNumberOfCharsFromStream(int numberOfChars)
-      throws IOException {
-    StringBuilder value = new StringBuilder();
-    while (numberOfChars > 0) {
-      int noOfCharsRead = processOutput.read(charBuffer, 0,
-          Math.min(numberOfChars, charBuffer.length));
-      if (noOfCharsRead == -1) {
-        break;
+  private Optional<byte[]> getNextByteArray() throws IOException {
+    Optional<Integer> size = getNextNumberInStream();
+    if (size.isPresent()) {
+      byte[] b = new byte[size.get()];

Review Comment:
   done



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