This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a450d37012 HDDS-8560. TypedTable should store key/value codecs in its 
fields. (#4769)
a450d37012 is described below

commit a450d37012b58c7d49957f8a3b5d7d8ab12bdece
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Sat May 27 03:18:53 2023 +0800

    HDDS-8560. TypedTable should store key/value codecs in its fields. (#4769)
---
 .../org/apache/hadoop/hdds/utils/db/RDBStore.java  |  10 +-
 .../hadoop/hdds/utils/db/RDBStoreIterator.java     |   6 +-
 .../org/apache/hadoop/hdds/utils/db/RDBTable.java  |  27 ++--
 .../apache/hadoop/hdds/utils/db/TypedTable.java    | 173 +++++++++------------
 .../hadoop/hdds/utils/db/TestRDBStoreIterator.java |   4 +-
 5 files changed, 98 insertions(+), 122 deletions(-)

diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
index d1a2402063..220c0b797a 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
@@ -73,18 +73,17 @@ public class RDBStore implements DBStore {
   private final String snapshotsParentDir;
   private final RDBMetrics rdbMetrics;
   private final RocksDBCheckpointDiffer rocksDBCheckpointDiffer;
-  private final String dbJmxBeanName;
 
   // this is to track the total size of dbUpdates data since sequence
   // number in request to avoid increase in heap memory.
-  private long maxDbUpdatesSizeThreshold;
+  private final long maxDbUpdatesSizeThreshold;
   private final ManagedDBOptions dbOptions;
 
   @SuppressWarnings("parameternumber")
   public RDBStore(File dbFile, ManagedDBOptions dbOptions,
                   ManagedWriteOptions writeOptions, Set<TableConfig> families,
                   CodecRegistry registry, boolean readOnly, int maxFSSnapshots,
-                  String dbJmxBeanNameName, boolean enableCompactionDag,
+                  String dbJmxBeanName, boolean enableCompactionDag,
                   long maxDbUpdatesSizeThreshold,
                   boolean createCheckpointDirs,
                   ConfigurationSource configuration)
@@ -96,8 +95,6 @@ public class RDBStore implements DBStore {
     this.maxDbUpdatesSizeThreshold = maxDbUpdatesSizeThreshold;
     codecRegistry = registry;
     dbLocation = dbFile;
-    dbJmxBeanName = dbJmxBeanNameName == null ? dbFile.getName() :
-        dbJmxBeanNameName;
     this.dbOptions = dbOptions;
 
     try {
@@ -116,6 +113,9 @@ public class RDBStore implements DBStore {
 
       // dbOptions.statistics() only contribute to part of RocksDB metrics in
       // Ozone. Enable RocksDB metrics even dbOptions.statistics() is off.
+      if (dbJmxBeanName == null) {
+        dbJmxBeanName = dbFile.getName();
+      }
       metrics = RocksDBStoreMetrics.create(dbOptions.statistics(), db,
           dbJmxBeanName);
       if (metrics == null) {
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java
index 9058d327fc..ee96072f46 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java
@@ -32,13 +32,13 @@ import org.slf4j.LoggerFactory;
  * RocksDB store iterator.
  */
 public class RDBStoreIterator
-    implements TableIterator<byte[], ByteArrayKeyValue> {
+    implements TableIterator<byte[], Table.KeyValue<byte[], byte[]>> {
 
   private static final Logger LOG =
       LoggerFactory.getLogger(RDBStoreIterator.class);
 
   private final ManagedRocksIterator rocksDBIterator;
-  private RDBTable rocksDBTable;
+  private final RDBTable rocksDBTable;
   private ByteArrayKeyValue currentEntry;
   // This is for schemas that use a fixed-length
   // prefix for each key.
@@ -64,7 +64,7 @@ public class RDBStoreIterator
 
   @Override
   public void forEachRemaining(
-      Consumer<? super ByteArrayKeyValue> action) {
+      Consumer<? super Table.KeyValue<byte[], byte[]>> action) {
     while (hasNext()) {
       action.accept(next());
     }
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
index 9ec199d8b8..81d1a8a89f 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBTable.java
@@ -98,7 +98,7 @@ class RDBTable implements Table<byte[], byte[]> {
 
   @Override
   public boolean isEmpty() throws IOException {
-    try (TableIterator<byte[], ByteArrayKeyValue> keyIter = iterator()) {
+    try (TableIterator<byte[], KeyValue<byte[], byte[]>> keyIter = iterator()) 
{
       keyIter.seekToFirst();
       return !keyIter.hasNext();
     }
@@ -177,13 +177,13 @@ class RDBTable implements Table<byte[], byte[]> {
   }
 
   @Override
-  public TableIterator<byte[], ByteArrayKeyValue> iterator()
+  public TableIterator<byte[], KeyValue<byte[], byte[]>> iterator()
       throws IOException {
     return new RDBStoreIterator(db.newIterator(family, false), this);
   }
 
   @Override
-  public TableIterator<byte[], ByteArrayKeyValue> iterator(byte[] prefix)
+  public TableIterator<byte[], KeyValue<byte[], byte[]>> iterator(byte[] 
prefix)
       throws IOException {
     return new RDBStoreIterator(db.newIterator(family, false), this,
         prefix);
@@ -205,7 +205,7 @@ class RDBTable implements Table<byte[], byte[]> {
   }
 
   @Override
-  public List<ByteArrayKeyValue> getRangeKVs(byte[] startKey,
+  public List<KeyValue<byte[], byte[]>> getRangeKVs(byte[] startKey,
       int count, byte[] prefix,
       MetadataKeyFilters.MetadataKeyFilter... filters)
       throws IOException, IllegalArgumentException {
@@ -213,7 +213,7 @@ class RDBTable implements Table<byte[], byte[]> {
   }
 
   @Override
-  public List<ByteArrayKeyValue> getSequentialRangeKVs(byte[] startKey,
+  public List<KeyValue<byte[], byte[]>> getSequentialRangeKVs(byte[] startKey,
       int count, byte[] prefix,
       MetadataKeyFilters.MetadataKeyFilter... filters)
       throws IOException, IllegalArgumentException {
@@ -223,7 +223,8 @@ class RDBTable implements Table<byte[], byte[]> {
   @Override
   public void deleteBatchWithPrefix(BatchOperation batch, byte[] prefix)
       throws IOException {
-    try (TableIterator<byte[], ByteArrayKeyValue> iter = iterator(prefix)) {
+    try (TableIterator<byte[], KeyValue<byte[], byte[]>> iter
+             = iterator(prefix)) {
       while (iter.hasNext()) {
         deleteWithBatch(batch, iter.next().getKey());
       }
@@ -233,11 +234,12 @@ class RDBTable implements Table<byte[], byte[]> {
   @Override
   public void dumpToFileWithPrefix(File externalFile, byte[] prefix)
       throws IOException {
-    try (TableIterator<byte[], ByteArrayKeyValue> iter = iterator(prefix);
+    try (TableIterator<byte[], KeyValue<byte[], byte[]>> iter
+             = iterator(prefix);
          DumpFileWriter fileWriter = new RDBSstFileWriter()) {
       fileWriter.open(externalFile);
       while (iter.hasNext()) {
-        ByteArrayKeyValue entry = iter.next();
+        final KeyValue<byte[], byte[]> entry = iter.next();
         fileWriter.put(entry.getKey(), entry.getValue());
       }
     }
@@ -250,18 +252,19 @@ class RDBTable implements Table<byte[], byte[]> {
     }
   }
 
-  private List<ByteArrayKeyValue> getRangeKVs(byte[] startKey,
+  private List<KeyValue<byte[], byte[]>> getRangeKVs(byte[] startKey,
       int count, boolean sequential, byte[] prefix,
       MetadataKeyFilters.MetadataKeyFilter... filters)
       throws IOException, IllegalArgumentException {
-    List<ByteArrayKeyValue> result = new ArrayList<>();
     long start = System.currentTimeMillis();
 
     if (count < 0) {
       throw new IllegalArgumentException(
             "Invalid count given " + count + ", count must be greater than 0");
     }
-    try (TableIterator<byte[], ByteArrayKeyValue> it = iterator(prefix)) {
+    final List<KeyValue<byte[], byte[]>> result = new ArrayList<>();
+    try (TableIterator<byte[], KeyValue<byte[], byte[]>> it
+             = iterator(prefix)) {
       if (startKey == null) {
         it.seekToFirst();
       } else {
@@ -274,7 +277,7 @@ class RDBTable implements Table<byte[], byte[]> {
       }
 
       while (it.hasNext() && result.size() < count) {
-        ByteArrayKeyValue currentEntry = it.next();
+        final KeyValue<byte[], byte[]> currentEntry = it.next();
         byte[] currentKey = currentEntry.getKey();
 
         if (filters == null) {
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
index 54239b2015..b1890a99dd 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
@@ -51,23 +52,19 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
   private final RDBTable rawTable;
 
-  private final CodecRegistry codecRegistry;
-
   private final Class<KEY> keyType;
-
+  private final Codec<KEY> keyCodec;
   private final Class<VALUE> valueType;
+  private final Codec<VALUE> valueCodec;
 
+  private final boolean supportCodecBuffer;
   private final TableCache<CacheKey<KEY>, CacheValue<VALUE>> cache;
 
   private static final long EPOCH_DEFAULT = -1L;
 
   /**
-   * Create an TypedTable from the raw table.
-   * Default cache type for the table is {@link CacheType#PARTIAL_CACHE}.
-   * @param rawTable
-   * @param codecRegistry
-   * @param keyType
-   * @param valueType
+   * The same as this(rawTable, codecRegistry, keyType, valueType,
+   *                  CacheType.PARTIAL_CACHE).
    */
   public TypedTable(RDBTable rawTable,
       CodecRegistry codecRegistry, Class<KEY> keyType,
@@ -78,21 +75,31 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
   /**
    * Create an TypedTable from the raw table with specified cache type.
-   * @param rawTable
-   * @param codecRegistry
-   * @param keyType
-   * @param valueType
-   * @param cacheType
-   * @throws IOException
+   *
+   * @param rawTable The underlying (untyped) table in RocksDB.
+   * @param codecRegistry To look up codecs.
+   * @param keyType The key type.
+   * @param valueType The value type.
+   * @param cacheType How to cache the entries?
+   * @throws IOException if failed to iterate the raw table.
    */
   public TypedTable(RDBTable rawTable,
       CodecRegistry codecRegistry, Class<KEY> keyType,
       Class<VALUE> valueType,
       CacheType cacheType) throws IOException {
-    this.rawTable = rawTable;
-    this.codecRegistry = codecRegistry;
-    this.keyType = keyType;
-    this.valueType = valueType;
+    this.rawTable = Objects.requireNonNull(rawTable, "rawTable==null");
+    Objects.requireNonNull(codecRegistry, "codecRegistry == null");
+
+    this.keyType = Objects.requireNonNull(keyType, "keyType == null");
+    this.keyCodec = codecRegistry.getCodecFromClass(keyType);
+    Objects.requireNonNull(keyCodec, "keyCodec == null");
+
+    this.valueType = Objects.requireNonNull(valueType, "valueType == null");
+    this.valueCodec = codecRegistry.getCodecFromClass(valueType);
+    Objects.requireNonNull(valueCodec, "valueCodec == null");
+
+    this.supportCodecBuffer = keyCodec.supportCodecBuffer()
+        && valueCodec.supportCodecBuffer();
 
     if (cacheType == CacheType.FULL_CACHE) {
       cache = new FullTableCache<>();
@@ -115,38 +122,45 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
     }
   }
 
+  private byte[] encodeKey(KEY key) throws IOException {
+    return key == null ? null : keyCodec.toPersistedFormat(key);
+  }
+
+  private byte[] encodeValue(VALUE value) throws IOException {
+    return value == null ? null : valueCodec.toPersistedFormat(value);
+  }
+
+  private KEY decodeKey(byte[] key) throws IOException {
+    return key == null ? null : keyCodec.fromPersistedFormat(key);
+  }
+
+  private VALUE decodeValue(byte[] value) throws IOException {
+    return value == null ? null : valueCodec.fromPersistedFormat(value);
+  }
+
   @Override
   public void put(KEY key, VALUE value) throws IOException {
-    final Codec<KEY> keyCodec = codecRegistry.getCodec(key);
-    final Codec<VALUE> valueCodec = codecRegistry.getCodec(value);
-    if (keyCodec.supportCodecBuffer() && valueCodec.supportCodecBuffer()) {
+    if (supportCodecBuffer) {
       try (CodecBuffer k = keyCodec.toDirectCodecBuffer(key);
            CodecBuffer v = valueCodec.toDirectCodecBuffer(value)) {
         rawTable.put(k.asReadOnlyByteBuffer(), v.asReadOnlyByteBuffer());
       }
-      return;
+    } else {
+      rawTable.put(encodeKey(key), encodeValue(value));
     }
-
-    byte[] keyData = codecRegistry.asRawData(key);
-    byte[] valueData = codecRegistry.asRawData(value);
-    rawTable.put(keyData, valueData);
   }
 
   @Override
   public void putWithBatch(BatchOperation batch, KEY key, VALUE value)
       throws IOException {
-    final Codec<KEY> keyCodec = codecRegistry.getCodec(key);
-    final Codec<VALUE> valueCodec = codecRegistry.getCodec(value);
-    if (keyCodec.supportCodecBuffer() && valueCodec.supportCodecBuffer()) {
+    if (supportCodecBuffer) {
       // The buffers will be released after commit.
       rawTable.putWithBatch(batch,
           keyCodec.toDirectCodecBuffer(key),
           valueCodec.toDirectCodecBuffer(value));
+    } else {
+      rawTable.putWithBatch(batch, encodeKey(key), encodeValue(value));
     }
-
-    byte[] keyData = codecRegistry.asRawData(key);
-    byte[] valueData = codecRegistry.asRawData(value);
-    rawTable.putWithBatch(batch, keyData, valueData);
   }
 
   @Override
@@ -165,7 +179,7 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
     } else if (cacheResult.getCacheStatus() == NOT_EXIST) {
       return false;
     } else {
-      return rawTable.isExist(codecRegistry.asRawData(key));
+      return rawTable.isExist(encodeKey(key));
     }
   }
 
@@ -190,8 +204,7 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
         cache.lookup(new CacheKey<>(key));
 
     if (cacheResult.getCacheStatus() == EXISTS) {
-      return codecRegistry.copyObject(cacheResult.getValue().getCacheValue(),
-          valueType);
+      return valueCodec.copyObject(cacheResult.getValue().getCacheValue());
     } else if (cacheResult.getCacheStatus() == NOT_EXIST) {
       return null;
     } else {
@@ -258,8 +271,7 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
         cache.lookup(new CacheKey<>(key));
 
     if (cacheResult.getCacheStatus() == EXISTS) {
-      return codecRegistry.copyObject(cacheResult.getValue().getCacheValue(),
-          valueType);
+      return valueCodec.copyObject(cacheResult.getValue().getCacheValue());
     } else if (cacheResult.getCacheStatus() == NOT_EXIST) {
       return null;
     } else {
@@ -268,47 +280,43 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
   }
 
   private VALUE getFromTable(KEY key) throws IOException {
-    byte[] keyBytes = codecRegistry.asRawData(key);
+    final byte[] keyBytes = encodeKey(key);
     byte[] valueBytes = rawTable.get(keyBytes);
-    return codecRegistry.asObject(valueBytes, valueType);
+    return decodeValue(valueBytes);
   }
 
   private VALUE getFromTableIfExist(KEY key) throws IOException {
-    byte[] keyBytes = codecRegistry.asRawData(key);
+    final byte[] keyBytes = encodeKey(key);
     byte[] valueBytes = rawTable.getIfExist(keyBytes);
-    return codecRegistry.asObject(valueBytes, valueType);
+    return decodeValue(valueBytes);
   }
 
   @Override
   public void delete(KEY key) throws IOException {
-    rawTable.delete(codecRegistry.asRawData(key));
+    rawTable.delete(encodeKey(key));
   }
 
   @Override
   public void deleteWithBatch(BatchOperation batch, KEY key)
       throws IOException {
-    rawTable.deleteWithBatch(batch, codecRegistry.asRawData(key));
+    rawTable.deleteWithBatch(batch, encodeKey(key));
   }
 
   @Override
   public void deleteRange(KEY beginKey, KEY endKey) throws IOException {
-    rawTable.deleteRange(codecRegistry.asRawData(beginKey),
-        codecRegistry.asRawData(endKey));
+    rawTable.deleteRange(encodeKey(beginKey), encodeKey(endKey));
   }
 
   @Override
   public TableIterator<KEY, TypedKeyValue> iterator() throws IOException {
-    TableIterator<byte[], ? extends KeyValue<byte[], byte[]>> iterator =
-        rawTable.iterator();
-    return new TypedTableIterator(iterator, keyType, valueType);
+    return new TypedTableIterator(rawTable.iterator());
   }
 
   @Override
   public TableIterator<KEY, TypedKeyValue> iterator(KEY prefix)
       throws IOException {
-    TableIterator<byte[], ? extends KeyValue<byte[], byte[]>> iterator =
-        rawTable.iterator(codecRegistry.asRawData(prefix));
-    return new TypedTableIterator(iterator, keyType, valueType);
+    final byte[] prefixBytes = encodeKey(prefix);
+    return new TypedTableIterator(rawTable.iterator(prefixBytes));
   }
 
   @Override
@@ -357,14 +365,8 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
     // A null start key means to start from the beginning of the table.
     // Cannot convert a null key to bytes.
-    byte[] startKeyBytes = null;
-    byte[] prefixBytes = null;
-    if (startKey != null) {
-      startKeyBytes = codecRegistry.asRawData(startKey);
-    }
-    if (prefix != null) {
-      prefixBytes = codecRegistry.asRawData(prefix);
-    }
+    final byte[] startKeyBytes = encodeKey(startKey);
+    final byte[] prefixBytes = encodeKey(prefix);
 
     List<? extends KeyValue<byte[], byte[]>> rangeKVBytes =
         rawTable.getRangeKVs(startKeyBytes, count, prefixBytes, filters);
@@ -383,14 +385,8 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
     // A null start key means to start from the beginning of the table.
     // Cannot convert a null key to bytes.
-    byte[] startKeyBytes = null;
-    byte[] prefixBytes = null;
-    if (startKey != null) {
-      startKeyBytes = codecRegistry.asRawData(startKey);
-    }
-    if (prefix != null) {
-      prefixBytes = codecRegistry.asRawData(prefix);
-    }
+    final byte[] startKeyBytes = encodeKey(startKey);
+    final byte[] prefixBytes = encodeKey(prefix);
 
     List<? extends KeyValue<byte[], byte[]>> rangeKVBytes =
         rawTable.getSequentialRangeKVs(startKeyBytes, count,
@@ -405,14 +401,13 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
   @Override
   public void deleteBatchWithPrefix(BatchOperation batch, KEY prefix)
       throws IOException {
-    rawTable.deleteBatchWithPrefix(batch, codecRegistry.asRawData(prefix));
+    rawTable.deleteBatchWithPrefix(batch, encodeKey(prefix));
   }
 
   @Override
   public void dumpToFileWithPrefix(File externalFile, KEY prefix)
       throws IOException {
-    rawTable.dumpToFileWithPrefix(externalFile,
-        codecRegistry.asRawData(prefix));
+    rawTable.dumpToFileWithPrefix(externalFile, encodeKey(prefix));
   }
 
   @Override
@@ -430,28 +425,12 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
     return cache;
   }
 
-  public Table<byte[], byte[]> getRawTable() {
-    return rawTable;
-  }
-
-  public CodecRegistry getCodecRegistry() {
-    return codecRegistry;
-  }
-
-  public Class<KEY> getKeyType() {
-    return keyType;
-  }
-
-  public Class<VALUE> getValueType() {
-    return valueType;
-  }
-
   /**
    * Key value implementation for strongly typed tables.
    */
   public class TypedKeyValue implements KeyValue<KEY, VALUE> {
 
-    private KeyValue<byte[], byte[]> rawKeyValue;
+    private final KeyValue<byte[], byte[]> rawKeyValue;
 
     public TypedKeyValue(KeyValue<byte[], byte[]> rawKeyValue) {
       this.rawKeyValue = rawKeyValue;
@@ -464,12 +443,12 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
     @Override
     public KEY getKey() throws IOException {
-      return codecRegistry.asObject(rawKeyValue.getKey(), keyType);
+      return decodeKey(rawKeyValue.getKey());
     }
 
     @Override
     public VALUE getValue() throws IOException {
-      return codecRegistry.asObject(rawKeyValue.getValue(), valueType);
+      return decodeValue(rawKeyValue.getValue());
     }
   }
 
@@ -478,18 +457,12 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
    */
   public class TypedTableIterator implements TableIterator<KEY, TypedKeyValue> 
{
 
-    private TableIterator<byte[], ? extends KeyValue<byte[], byte[]>>
+    private TableIterator<byte[], KeyValue<byte[], byte[]>>
         rawIterator;
-    private final Class<KEY> keyClass;
-    private final Class<VALUE> valueClass;
 
     public TypedTableIterator(
-        TableIterator<byte[], ? extends KeyValue<byte[], byte[]>> rawIterator,
-        Class<KEY> keyType,
-        Class<VALUE> valueType) {
+        TableIterator<byte[], KeyValue<byte[], byte[]>> rawIterator) {
       this.rawIterator = rawIterator;
-      keyClass = keyType;
-      valueClass = valueType;
     }
 
     @Override
@@ -504,7 +477,7 @@ public class TypedTable<KEY, VALUE> implements Table<KEY, 
VALUE> {
 
     @Override
     public TypedKeyValue seek(KEY key) throws IOException {
-      byte[] keyBytes = codecRegistry.asRawData(key);
+      final byte[] keyBytes = encodeKey(key);
       KeyValue<byte[], byte[]> result = rawIterator.seek(keyBytes);
       if (result == null) {
         return null;
diff --git 
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStoreIterator.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStoreIterator.java
index bd99c0e55f..9006fb5721 100644
--- 
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStoreIterator.java
+++ 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStoreIterator.java
@@ -82,8 +82,8 @@ public class TestRDBStoreIterator {
             new byte[]{0x7d})
         .thenThrow(new NoSuchElementException());
 
-
-    Consumer<ByteArrayKeyValue> consumerStub = mock(Consumer.class);
+    final Consumer<Table.KeyValue<byte[], byte[]>> consumerStub
+        = mock(Consumer.class);
 
     RDBStoreIterator iter = new RDBStoreIterator(managedRocksIterator);
     iter.forEachRemaining(consumerStub);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to