swamirishi commented on code in PR #4584:
URL: https://github.com/apache/ozone/pull/4584#discussion_r1191855710
##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedSSTDumpIterator.java:
##########
@@ -86,51 +79,47 @@ 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());
}
- 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;
- }
- value.append(charBuffer, 0, noOfCharsRead);
- numberOfChars -= noOfCharsRead;
+ private Optional<byte[]> getNextByteArray() throws IOException {
+ Optional<Integer> size = getNextNumberInStream();
+ if (size.isPresent()) {
+ byte[] b = new byte[size.get()];
+ int n = processOutput.read(b);
+ return n != size.get() ? Optional.empty() : Optional.of(b);
}
+ return Optional.empty();
+ }
- return value.toString();
+ private Optional<UnsignedLong> getNextUnsignedLong() {
+ long val = 0;
+ for (int i = 0; i < 8; i++) {
+ val = val << 8;
+ int nextByte = processOutput.read();
+ if (nextByte < 0) {
+ return Optional.empty();
+ }
+ val += nextByte;
+ }
+ return Optional.of(UnsignedLong.fromLongBits(val));
}
private void init(ManagedSSTDumpTool sstDumpTool, File sstFile,
ManagedOptions options)
throws NativeLibraryNotLoadedException {
- String[] args = {"--file=" + sstFile.getAbsolutePath(), "--command=scan"};
+ String[] args = {"--file=" + sstFile.getAbsolutePath(), "--command=scan",
Review Comment:
done
##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedSSTDumpIterator.java:
##########
@@ -180,33 +169,25 @@ 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);
+ nextKey = Optional.empty();
+ try {
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]