HDDS-8740. Commit batch in SCMHADBTransactionBufferImpl on close()#4866
HDDS-8740. Commit batch in SCMHADBTransactionBufferImpl on close()#4866adoroszlai wants to merge 1 commit intoapache:masterfrom
Conversation
|
@adoroszlai , how about we clear the cache in +++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java
@@ -350,6 +350,7 @@ public void commit(RocksDatabase db, ManagedWriteOptions writeOptions)
@Override
public void close() {
debug(() -> String.format("%s: close", name));
+ opCache.clear();
writeBatch.close();
} |
Thanks @szetszwo for the suggestion. After posting this PR I was thinking along the same lines, but haven't updated the PR yet. Can we assume that all batches should be committed (to avoid data loss)? If so, we might want to combine |
We should support |
|
@adoroszlai , after HDDS-8803, do we still need this? |
|
In what cases would the buffer be closed before flush other than shutdown? Shutdown should not be a problem since the information would be replayed from the Ratis log on restart. If the buffer is closed and entries are not flushed but the SCM keeps accepting transactions, that seems like a larger problem outside of finalization. |
Then fixing the leak itself in HDDS-8803 seems enough. |
What changes were proposed in this pull request?
TestScmHAFinalizationintermittently reportsFound 2 leaked objects(CodecBufferinstances).FinalizationStateManagerImplis leaking a pair ofCodecBuffers allocated for writing layout version to SCM metadata store:finalizeLayoutFeatureLocaladds these to thetransactionBuffer, collecting them in a batch operation:ozone/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java
Lines 156 to 157 in b479a38
CodecBuffers are released on commit, which happens when transaction buffer is flushed.ozone/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java
Lines 333 to 339 in b479a38
The problem is that the buffer may be closed without being flushed. In this case the contents of the current batch, if any, are not committed. (The batch is closed, so RocksDB objects are not leaked.)
We could fix it by explicitly flushing the buffer when finalization completes. However, the problem may be more generic, any metadata stored by SCM via the transaction buffer may be lost. So this PR proposes to commit the in-progress batch operation, if any, before closing it.
Also:
closedflag. Allow closing only once. Reject operations if closed.currentBatchOperationbeing non-null.AtomicLong txFlushPendingwith aboolean, since the specific number is not important, only> 0or== 0cases are distinguished.SCMMetadataStoretofinalboth inSCMHADBTransactionBufferImpland inStorageContainerManagerhttps://issues.apache.org/jira/browse/HDDS-8740
How was this patch tested?
TestScmHAFinalization#testSnapshotFinalizationpassed in 30x10 runs:https://github.com/adoroszlai/hadoop-ozone/actions/runs/5221131625
Regular CI:
https://github.com/adoroszlai/hadoop-ozone/actions/runs/5221128846