errose28 commented on code in PR #4029:
URL: https://github.com/apache/ozone/pull/4029#discussion_r1068740620
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogStateManagerImpl.java:
##########
@@ -78,12 +80,22 @@ DeletedBlocksTransaction>> getReadOnlyIterator() throws
IOException {
private TableIterator<Long,
? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter =
- deletedTable.iterator();
+ getTableIterator();
private TypedTable.KeyValue<Long, DeletedBlocksTransaction> nextTx;
{
findNext();
}
+
+ private TableIterator<Long, ? extends Table.KeyValue<Long,
+ DeletedBlocksTransaction>> getTableIterator() throws IOException {
+ if (transactionBuffer instanceof SCMHADBTransactionBuffer) {
+ RWBatchOperation batchOperation = ((SCMHADBTransactionBuffer)
+ transactionBuffer).getCurrentBatchOperation();
+ return deletedTable.iterator(batchOperation);
+ }
+ return deletedTable.iterator();
Review Comment:
I think we can clean this up by making our interface more closely follow the
[RocksDB
APIs](https://javadoc.io/static/org.rocksdb/rocksdbjni/6.29.5/org/rocksdb/WriteBatchWithIndex.html#newIterator(org.rocksdb.ColumnFamilyHandle)),
where the batch creates the iterator and is passed the table. In this code the
opposite is being done (the table creates the iterator and is passed the batch).
We could get rid of `SCMHADBTransactionBuffer#getCurrentBatchOperation` and
the instanceof/casting here by adding a method like
`DBTransactionBuffer#getBatchIterator(Table)`. The HA/non HA buffer
implementations can return the corresponding iterator implementation by calling
either `Table#iterator(batch)` or `Table#iterator()`
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RWBatchOperation.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.hdds.utils.db;
+
+import java.io.IOException;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator;
+import org.rocksdb.ColumnFamilyHandle;
+
+/**
+ * Class represents a read write batch operation,
+ * collects multiple db operation.
+ */
+public interface RWBatchOperation extends BatchOperation {
+ ManagedRocksIterator newIteratorWithBase(
+ ColumnFamilyHandle handle, ManagedRocksIterator newIterator)
+ throws IOException;
+
+ void lockOperation() throws IOException;
+
+ void releaseOperation();
Review Comment:
Why do we need to lock on the batch?
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBRWBatchOperation.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.hdds.utils.db;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.RocksDatabase.ColumnFamily;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedReadWriteBatch;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedWriteOptions;
+import org.rocksdb.ColumnFamilyHandle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static
org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator.managed;
+
+/**
+ * Read Write Batch operation implementation for rocks db.
+ */
+public class RDBRWBatchOperation implements RWBatchOperation {
+ public static final Logger LOG =
+ LoggerFactory.getLogger(RDBRWBatchOperation.class);
+ private final ManagedReadWriteBatch writeBatch;
+
+ private final AtomicLong operationCount = new AtomicLong(0);
+
+ private final AtomicBoolean isActive = new AtomicBoolean(true);
+
+ private final Object lock = new Object();
+
+ public RDBRWBatchOperation() {
+ writeBatch = new ManagedReadWriteBatch();
+ }
+
+ public RDBRWBatchOperation(ManagedReadWriteBatch writeBatch) {
+ this.writeBatch = writeBatch;
+ }
Review Comment:
This constructor is unused.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreIterator.java:
##########
@@ -52,6 +53,16 @@ public RDBStoreIterator(ManagedRocksIterator iterator,
RDBTable table) {
this(iterator, table, null);
}
+ public RDBStoreIterator(
+ ManagedRocksIterator iterator, RWBatchOperation rwBatch,
+ RDBTable table) throws IOException {
Review Comment:
The write batch iterator should probably be its own subclass of
`RDBStoreIterator`, since the `rwBatch` field is not used when the class is
used as a normal Rocks DB iterator.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RocksDatabase.java:
##########
@@ -300,6 +301,32 @@ public void batchPut(ManagedWriteBatch writeBatch, byte[]
key, byte[] value)
counter.decrementAndGet();
}
}
+
+ public void batchDelete(ManagedReadWriteBatch writeBatch, byte[] key)
+ throws IOException {
Review Comment:
The code duplication between the write batch and read write batch versions
of these methods is somewhat unfortunate, but I'm not sure there's much we can
do about it here since RocksDB did not put WriteBatch and WriteBatchWithIndex
under a common class or interface.
--
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]