hemantk-12 commented on code in PR #6182:
URL: https://github.com/apache/ozone/pull/6182#discussion_r1498528481


##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRawSSTFileReader.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.utils.db.managed;
+
+import org.apache.hadoop.hdds.utils.NativeLibraryLoader;
+import org.apache.hadoop.hdds.utils.NativeLibraryNotLoadedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.util.function.Function;
+
+import static 
org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME;
+
+/**
+ * JNI for RocksDB RawSSTFileReader.
+ */
+public class ManagedRawSSTFileReader<T> implements Closeable {
+
+  public static boolean loadLibrary() throws NativeLibraryNotLoadedException {
+    ManagedRocksObjectUtils.loadRocksDBLibrary();
+    if (!NativeLibraryLoader.getInstance()
+        .loadLibrary(ROCKS_TOOLS_NATIVE_LIBRARY_NAME)) {
+      throw new NativeLibraryNotLoadedException(
+          ROCKS_TOOLS_NATIVE_LIBRARY_NAME);
+    }
+    return true;
+  }
+
+  private final ManagedOptions options;
+  private final String fileName;
+  private final int readAheadSize;
+  private final long nativeHandle;
+  private static final Logger LOG =
+      LoggerFactory.getLogger(ManagedRawSSTFileReader.class);
+
+  public ManagedRawSSTFileReader(final ManagedOptions options,
+                                 final String fileName,
+                                 final int readAheadSize) {
+    this.options = options;
+    this.fileName = fileName;
+    this.readAheadSize = readAheadSize;
+    this.nativeHandle = this.newRawSSTFileReader(options.getNativeHandle(),
+        fileName, readAheadSize);
+  }
+
+  public ManagedRawSSTFileReaderIterator<T> newIterator(
+      Function<ManagedRawSSTFileReaderIterator.KeyValue, T> 
transformerFunction,
+      ManagedSlice fromSlice, ManagedSlice toSlice) {
+    long fromNativeHandle = fromSlice == null ? 0 : 
fromSlice.getNativeHandle();
+    long toNativeHandle = toSlice == null ? 0 : toSlice.getNativeHandle();

Review Comment:
   We can leave it for now and come back later if -1 can be used of now.



##########
hadoop-hdds/rocks-native/src/main/patches/rocks-native.patch:
##########
@@ -16,592 +16,557 @@
  * limitations under the License.
  */
 
-diff --git a/include/rocksdb/sst_dump_tool.h b/include/rocksdb/sst_dump_tool.h
-index 9261ba47d..1e62b88a3 100644
---- a/include/rocksdb/sst_dump_tool.h
-+++ b/include/rocksdb/sst_dump_tool.h
-@@ -11,7 +11,8 @@ namespace ROCKSDB_NAMESPACE {
- 
- class SSTDumpTool {
-  public:
--  int Run(int argc, char const* const* argv, Options options = Options());
-+  int Run(int argc, char const* const* argv, Options options = Options(),
-+          FILE* out = stdout, FILE* err = stderr);
- };
- 
- }  // namespace ROCKSDB_NAMESPACE
-diff --git a/table/sst_file_dumper.cc b/table/sst_file_dumper.cc
-index eefbaaeee..734a2f0dd 100644
---- a/table/sst_file_dumper.cc
-+++ b/table/sst_file_dumper.cc
-@@ -45,7 +45,7 @@ SstFileDumper::SstFileDumper(const Options& options,
-                              Temperature file_temp, size_t readahead_size,
-                              bool verify_checksum, bool output_hex,
-                              bool decode_blob_index, const EnvOptions& 
soptions,
--                             bool silent)
-+                             bool silent, FILE* out, FILE* err)
-     : file_name_(file_path),
-       read_num_(0),
-       file_temp_(file_temp),
-@@ -57,10 +57,13 @@ SstFileDumper::SstFileDumper(const Options& options,
-       ioptions_(options_),
-       moptions_(ColumnFamilyOptions(options_)),
-       read_options_(verify_checksum, false),
--      internal_comparator_(BytewiseComparator()) {
-+      internal_comparator_(BytewiseComparator()),
-+      out_(out),
-+      err_(err)
-+      {
-   read_options_.readahead_size = readahead_size;
-   if (!silent_) {
--    fprintf(stdout, "Process %s\n", file_path.c_str());
-+    fprintf(out_, "Process %s\n", file_path.c_str());
-   }
-   init_result_ = GetTableReader(file_name_);
- }
-@@ -253,17 +256,17 @@ Status SstFileDumper::ShowAllCompressionSizes(
-     int32_t compress_level_from, int32_t compress_level_to,
-     uint32_t max_dict_bytes, uint32_t zstd_max_train_bytes,
-     uint64_t max_dict_buffer_bytes, bool use_zstd_dict_trainer) {
--  fprintf(stdout, "Block Size: %" ROCKSDB_PRIszt "\n", block_size);
-+  fprintf(out_, "Block Size: %" ROCKSDB_PRIszt "\n", block_size);
-   for (auto& i : compression_types) {
-     if (CompressionTypeSupported(i.first)) {
--      fprintf(stdout, "Compression: %-24s\n", i.second);
-+      fprintf(out_, "Compression: %-24s\n", i.second);
-       CompressionOptions compress_opt;
-       compress_opt.max_dict_bytes = max_dict_bytes;
-       compress_opt.zstd_max_train_bytes = zstd_max_train_bytes;
-       compress_opt.max_dict_buffer_bytes = max_dict_buffer_bytes;
-       compress_opt.use_zstd_dict_trainer = use_zstd_dict_trainer;
-       for (int32_t j = compress_level_from; j <= compress_level_to; j++) {
--        fprintf(stdout, "Compression level: %d", j);
-+        fprintf(out_, "Compression level: %d", j);
-         compress_opt.level = j;
-         Status s = ShowCompressionSize(block_size, i.first, compress_opt);
-         if (!s.ok()) {
-@@ -271,7 +274,7 @@ Status SstFileDumper::ShowAllCompressionSizes(
-         }
-       }
-     } else {
--      fprintf(stdout, "Unsupported compression type: %s.\n", i.second);
-+      fprintf(err_, "Unsupported compression type: %s.\n", i.second);
-     }
-   }
-   return Status::OK();
-@@ -307,9 +310,9 @@ Status SstFileDumper::ShowCompressionSize(
-   }
- 
-   std::chrono::steady_clock::time_point end = 
std::chrono::steady_clock::now();
--  fprintf(stdout, " Size: %10" PRIu64, file_size);
--  fprintf(stdout, " Blocks: %6" PRIu64, num_data_blocks);
--  fprintf(stdout, " Time Taken: %10s microsecs",
-+  fprintf(out_, " Size: %10" PRIu64, file_size);
-+  fprintf(out_, " Blocks: %6" PRIu64, num_data_blocks);
-+  fprintf(out_, " Time Taken: %10s microsecs",
-           std::to_string(
-               std::chrono::duration_cast<std::chrono::microseconds>(end - 
start)
-                   .count())
-@@ -342,11 +345,11 @@ Status SstFileDumper::ShowCompressionSize(
-                              : ((static_cast<double>(not_compressed_blocks) /
-                                  static_cast<double>(num_data_blocks)) *
-                                 100.0);
--  fprintf(stdout, " Compressed: %6" PRIu64 " (%5.1f%%)", compressed_blocks,
-+  fprintf(out_, " Compressed: %6" PRIu64 " (%5.1f%%)", compressed_blocks,
-           compressed_pcnt);
--  fprintf(stdout, " Not compressed (ratio): %6" PRIu64 " (%5.1f%%)",
-+  fprintf(out_, " Not compressed (ratio): %6" PRIu64 " (%5.1f%%)",
-           ratio_not_compressed_blocks, ratio_not_compressed_pcnt);
--  fprintf(stdout, " Not compressed (abort): %6" PRIu64 " (%5.1f%%)\n",
-+  fprintf(out_, " Not compressed (abort): %6" PRIu64 " (%5.1f%%)\n",
-           not_compressed_blocks, not_compressed_pcnt);
-   return Status::OK();
- }
-@@ -362,7 +365,7 @@ Status SstFileDumper::ReadTableProperties(uint64_t 
table_magic_number,
-       /* memory_allocator= */ nullptr, prefetch_buffer);
-   if (!s.ok()) {
-     if (!silent_) {
--      fprintf(stdout, "Not able to read table properties\n");
-+      fprintf(err_, "Not able to read table properties\n");
-     }
-   }
-   return s;
-@@ -410,7 +413,7 @@ Status SstFileDumper::SetTableOptionsByMagicNumber(
- 
-     options_.table_factory.reset(NewPlainTableFactory(plain_table_options));
-     if (!silent_) {
--      fprintf(stdout, "Sst file format: plain table\n");
-+      fprintf(out_, "Sst file format: plain table\n");
-     }
-   } else {
-     char error_msg_buffer[80];
-@@ -427,15 +430,56 @@ Status SstFileDumper::SetOldTableOptions() {
-   assert(table_properties_ == nullptr);
-   options_.table_factory = std::make_shared<BlockBasedTableFactory>();
-   if (!silent_) {
--    fprintf(stdout, "Sst file format: block-based(old version)\n");
-+    fprintf(out_, "Sst file format: block-based(old version)\n");
-   }
- 
-   return Status::OK();
- }
- 
-+void write(int value, FILE* file) {
-+  char b[4];
-+  b[3] =  value & 0x000000ff;
-+  b[2] = (value & 0x0000ff00) >> 8;
-+  b[1] = (value & 0x00ff0000) >> 16;
-+  b[0] = (value & 0xff000000) >> 24;
-+  std::fwrite(b, 4, 1, file);
+diff --git a/include/rocksdb/raw_iterator.h b/include/rocksdb/raw_iterator.h
+new file mode 100644
+index 000000000..ec3c05d6d
+--- /dev/null
++++ b/include/rocksdb/raw_iterator.h
+@@ -0,0 +1,25 @@
++// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
++//  This source code is licensed under both the GPLv2 (found in the
++//  COPYING file in the root directory) and Apache 2.0 License
++//  (found in the LICENSE.Apache file in the root directory).
++#pragma once
++#ifndef ROCKSDB_LITE
++
++
++#include "rocksdb/advanced_options.h"
++namespace ROCKSDB_NAMESPACE {
++
++class RawIterator {
++ public:
++  virtual ~RawIterator() {}
++  virtual bool has_next() const = 0;
++  virtual Slice getKey() const = 0;
++  virtual Slice getValue() const = 0;

Review Comment:
   I would defer because it is RocksDB's code in the end for us and better to 
have same terminology. Rest is upto you.



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