swamirishi commented on code in PR #9555:
URL: https://github.com/apache/ozone/pull/9555#discussion_r2649471876
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java:
##########
@@ -135,6 +132,118 @@ public String toString() {
}
}
+ private abstract static class Op implements Closeable {
+
+ private Op() {
+ }
+
+ abstract void apply(ColumnFamily family, ManagedWriteBatch batch) throws
RocksDatabaseException;
+
+ abstract int keyLen();
+
+ int valLen() {
+ return 0;
+ }
+
+ int totalLength() {
+ return keyLen() + valLen();
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+
+ /**
+ * Delete operation to be applied to a {@link ColumnFamily} batch.
+ */
+ private static final class DeleteOp extends Op {
+ private final byte[] key;
+
+ private DeleteOp(byte[] key) {
+ super();
Review Comment:
done
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java:
##########
@@ -135,6 +132,118 @@ public String toString() {
}
}
+ private abstract static class Op implements Closeable {
+
+ private Op() {
+ }
+
+ abstract void apply(ColumnFamily family, ManagedWriteBatch batch) throws
RocksDatabaseException;
+
+ abstract int keyLen();
+
+ int valLen() {
+ return 0;
+ }
+
+ int totalLength() {
+ return keyLen() + valLen();
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+
+ /**
+ * Delete operation to be applied to a {@link ColumnFamily} batch.
+ */
+ private static final class DeleteOp extends Op {
+ private final byte[] key;
+
+ private DeleteOp(byte[] key) {
+ super();
+ this.key = Objects.requireNonNull(key, "key == null");
+ }
+
+ @Override
+ public void apply(ColumnFamily family, ManagedWriteBatch batch) throws
RocksDatabaseException {
+ family.batchDelete(batch, this.key);
+ }
+
+ @Override
+ public int keyLen() {
+ return key.length;
+ }
+ }
+
+ /**
+ * Put operation to be applied to a {@link ColumnFamily} batch using the
CodecBuffer api.
+ */
+ private final class CodecBufferPutOp extends Op {
Review Comment:
Done renaming it
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java:
##########
@@ -194,68 +295,56 @@ void clear() {
final boolean warn = !isCommit && batchSize > 0;
String details = warn ? summary() : null;
- for (Object value : ops.values()) {
- if (value instanceof CodecBuffer) {
- ((CodecBuffer) value).release(); // the key will also be released
- }
- }
+ IOUtils.close(LOG, ops.values());
ops.clear();
if (warn) {
LOG.warn("discarding changes {}", details);
}
}
- void putOrDelete(Bytes key, int keyLen, Object val, int valLen) {
- Preconditions.checkState(!isCommit, "%s is already committed.", this);
- batchSize += keyLen + valLen;
- // remove previous first in order to call release()
- final Object previous = ops.remove(key);
+ private void deleteIfExist(Bytes key) {
+ final Op previous = ops.remove(key);
if (previous != null) {
- final boolean isPut = previous != Op.DELETE;
- final int preLen;
- if (!isPut) {
- preLen = 0;
- } else if (previous instanceof CodecBuffer) {
- final CodecBuffer previousValue = (CodecBuffer) previous;
- preLen = previousValue.readableBytes();
- previousValue.release(); // key will also be released
- } else if (previous instanceof byte[]) {
- preLen = ((byte[]) previous).length;
- } else {
- throw new IllegalStateException("Unexpected previous: " + previous
- + ", class=" + previous.getClass().getSimpleName());
- }
- discardedSize += keyLen + preLen;
+ previous.close();
+ discardedSize += previous.totalLength();
discardedCount++;
- debug(() -> String.format("%s overwriting a previous %s", this,
- isPut ? "put (value: " + byteSize2String(preLen) + ")" : "del"));
+ debug(() -> String.format("%s overwriting a previous %s[valLen =>
%s]", this,
+ previous.getClass().getName(), previous.valLen()));
}
- final Object overwritten = ops.put(key, val);
+ }
+
+ void overWriteOpIfExist(Bytes key, Op operation) {
Review Comment:
done
--
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]