errose28 commented on a change in pull request #1298:
URL: https://github.com/apache/hadoop-ozone/pull/1298#discussion_r482276218



##########
File path: 
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/metadata/DatanodeTable.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.ozone.container.metadata;
+
+import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Wrapper class to represent a table in a datanode RocksDB instance.
+ * This class can wrap any {@link Table} instance, but will throw
+ * {@link UnsupportedOperationException} for {@link Table#iterator}.
+ * This is because differing schema versions used in datanode DB layouts may
+ * have differing underlying table structures, so iterating a table instance
+ * directly, without taking into account key prefixes, may yield unexpected
+ * results.
+ */
+public class DatanodeTable<KEY, VALUE> implements Table<KEY, VALUE> {
+
+  private final Table<KEY, VALUE> table;
+
+  public DatanodeTable(Table<KEY, VALUE> table) {
+    this.table = table;
+  }
+
+  @Override
+  public void put(KEY key, VALUE value) throws IOException {
+    table.put(key, value);
+  }
+
+  @Override
+  public void putWithBatch(BatchOperation batch, KEY key,
+                           VALUE value) throws IOException {
+    table.putWithBatch(batch, key, value);
+  }
+
+  @Override
+  public boolean isEmpty() throws IOException {
+    return table.isEmpty();
+  }
+
+  @Override
+  public void delete(KEY key) throws IOException {
+    table.delete(key);
+  }
+
+  @Override
+  public void deleteWithBatch(BatchOperation batch, KEY key)
+          throws IOException {
+    table.deleteWithBatch(batch, key);
+  }
+
+  @Override
+  public final TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> iterator() {
+    throw new UnsupportedOperationException("Iterating tables directly is not" 
+
+            " supported for datanode containers due to differing schema " +
+            "version.");
+  }
+
+  @Override
+  public String getName() throws IOException {
+    return table.getName();
+  }
+
+  @Override
+  public long getEstimatedKeyCount() throws IOException {
+    return table.getEstimatedKeyCount();
+  }
+
+  @Override
+  public void addCacheEntry(CacheKey<KEY> cacheKey,
+                            CacheValue<VALUE> cacheValue) {

Review comment:
       Table cache is only used in OM, but these methods exist in the general 
table interface, so we must either provide an implementation or throw 
UnsupportedOperationException. Having an implementation does not break 
anything, and since all the tables for all components are using RawTable 
anyways, we can re use its implementation. For this reason, I chose to just 
delegate to the existing implementation.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to