szetszwo commented on code in PR #10879:
URL: https://github.com/apache/ozone/pull/10879#discussion_r3667773663
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -111,16 +110,22 @@ public DBStore getDbStore() {
return dbStore;
}
- static void truncateTable(Table table) throws IOException {
+ static <K> void truncateTable(Table<K, ?> table) throws IOException {
if (table == null) {
return;
}
- try (TableIterator<Object, Table.KeyValue<Object, Object>> tableIterator =
table.iterator()) {
- while (tableIterator.hasNext()) {
- KeyValue<Object, Object> entry = tableIterator.next();
- table.delete(entry.getKey());
+ final K firstKey;
+ final K lastKey;
+ try (TableIterator<K, K> keyIterator = table.keyIterator()) {
+ if (!keyIterator.hasNext()) {
+ return;
}
+ firstKey = keyIterator.next();
+ keyIterator.seekToLast();
+ lastKey = keyIterator.next();
}
+ table.deleteRange(firstKey, lastKey);
+ table.delete(lastKey);
Review Comment:
@chihsuan , you suggestion is good! In this case, let's
- add the clear() method,
- don't add the new deleteRange method, and
- clearify the deleteRange javadoc
```java
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/Table.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/Table.java
index 400547a0e3..ad764568ab 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/Table.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/Table.java
@@ -134,13 +134,30 @@ default VALUE getReadCopy(KEY key) throws
RocksDatabaseException, CodecException
void deleteWithBatch(BatchOperation batch, KEY key) throws CodecException;
/**
- * Deletes a range of keys from the metadata store.
+ * Deletes a range of keys from this table.
*
- * @param beginKey start metadata key
- * @param endKey end metadata key
+ * @param beginKey start key (inclusive)
+ * @param endKey end key (exclusive)
*/
void deleteRange(KEY beginKey, KEY endKey) throws RocksDatabaseException,
CodecException;
+ /** Deletes all entries from this table. */
+ default void clear() throws RocksDatabaseException, CodecException {
+ final KEY beginKey;
+ final KEY endKey;
+ try (TableIterator<KEY, KEY> keyIterator = keyIterator()) {
+ if (!keyIterator.hasNext()) {
+ return;
+ }
+ beginKey = keyIterator.next();
+ keyIterator.seekToLast();
+ endKey = keyIterator.next();
+ }
+
+ deleteRange(beginKey, endKey);
+ delete(endKey);
+ }
+
/** The same as iterator(null, KEY_AND_VALUE). */
default KeyValueIterator<KEY, VALUE> iterator() throws
RocksDatabaseException, CodecException {
return iterator(null, IteratorType.KEY_AND_VALUE);
```
--
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]