Skip to content

Commit

Permalink
Add comment for memory usage in BeginTransaction() and WriteBatch::Cl…
Browse files Browse the repository at this point in the history
…ear() (#13042)

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: #13042

Test Plan: no code change.

Reviewed By: jowlyzhang

Differential Revision: D63570612

Pulled By: cbi42

fbshipit-source-id: f19ff556f76d54831fb94715e8808035d07e25fa
  • Loading branch information
cbi42 authored and facebook-github-bot committed Sep 30, 2024
1 parent 2c2776f commit 389e66b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/rocksdb/utilities/transaction_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/write_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 389e66b

Please sign in to comment.