diff options
author | Changyu Bi <changyubi@meta.com> | 2024-09-30 10:27:45 -0700 |
---|---|---|
committer | Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> | 2024-09-30 10:27:45 -0700 |
commit | 389e66bef56b4f81d3c9683469acb5affc32bd7f (patch) | |
tree | 15698505be0774f05797291ee954b9d6153ecfb9 | |
parent | 2c2776f1f396e0f23dd4d484b871144a2972d787 (diff) |
Summary:
... to note that memory may not be freed when reusing a transaction. This means reusing a large transaction can cause excessive memory usage and it may be better to destruct the transaction object in some cases.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/13042
Test Plan: no code change.
Reviewed By: jowlyzhang
Differential Revision: D63570612
Pulled By: cbi42
fbshipit-source-id: f19ff556f76d54831fb94715e8808035d07e25fa
-rw-r--r-- | include/rocksdb/utilities/transaction_db.h | 5 | ||||
-rw-r--r-- | include/rocksdb/write_batch.h | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/include/rocksdb/utilities/transaction_db.h b/include/rocksdb/utilities/transaction_db.h index 702266640..78ff0816f 100644 --- a/include/rocksdb/utilities/transaction_db.h +++ b/include/rocksdb/utilities/transaction_db.h @@ -460,7 +460,10 @@ class TransactionDB : public StackableDB { // // If old_txn is not null, BeginTransaction will reuse this Transaction // handle instead of allocating a new one. This is an optimization to avoid - // extra allocations when repeatedly creating transactions. + // extra allocations when repeatedly creating transactions. **Note that this + // may not free all the allocated memory by the previous transaction (see + // WriteBatch::Clear()). To ensure that all allocated memory is freed, users + // must destruct the transaction object. virtual Transaction* BeginTransaction( const WriteOptions& write_options, const TransactionOptions& txn_options = TransactionOptions(), diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index df7048af3..7cdca233a 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -209,6 +209,8 @@ class WriteBatch : public WriteBatchBase { using WriteBatchBase::Clear; // Clear all updates buffered in this batch. + // Internally, it calls resize() on the string buffer. So allocated memory + // capacity may not be freed. void Clear() override; // Records the state of the batch for future calls to RollbackToSavePoint(). |