diff --git a/db/write_batch.cc b/db/write_batch.cc index 30480f64e16625ba67966072d44ead4979720421..939b595305b8395ba26d0c4b1016678cf0fbbdd2 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -52,6 +52,7 @@ #include "monitoring/perf_context_imp.h" #include "monitoring/statistics.h" #include "rocksdb/merge_operator.h" +#include "util/autovector.h" #include "util/coding.h" #include "util/duplicate_detector.h" #include "util/string_util.h" @@ -137,34 +138,36 @@ struct BatchContentClassifier : public WriteBatch::Handler { } // anon namespace struct SavePoints { - std::stack stack; + std::stack> stack; }; WriteBatch::WriteBatch(size_t reserved_bytes, size_t max_bytes) - : save_points_(nullptr), content_flags_(0), max_bytes_(max_bytes), rep_() { + : content_flags_(0), max_bytes_(max_bytes), rep_() { rep_.reserve((reserved_bytes > WriteBatchInternal::kHeader) ? reserved_bytes : WriteBatchInternal::kHeader); rep_.resize(WriteBatchInternal::kHeader); } WriteBatch::WriteBatch(const std::string& rep) - : save_points_(nullptr), - content_flags_(ContentFlags::DEFERRED), + : content_flags_(ContentFlags::DEFERRED), max_bytes_(0), rep_(rep) {} WriteBatch::WriteBatch(std::string&& rep) - : save_points_(nullptr), - content_flags_(ContentFlags::DEFERRED), + : content_flags_(ContentFlags::DEFERRED), max_bytes_(0), rep_(std::move(rep)) {} WriteBatch::WriteBatch(const WriteBatch& src) - : save_points_(src.save_points_), - wal_term_point_(src.wal_term_point_), + : wal_term_point_(src.wal_term_point_), content_flags_(src.content_flags_.load(std::memory_order_relaxed)), max_bytes_(src.max_bytes_), - rep_(src.rep_) {} + rep_(src.rep_) { + if (src.save_points_ != nullptr) { + save_points_.reset(new SavePoints()); + save_points_->stack = src.save_points_->stack; + } +} WriteBatch::WriteBatch(WriteBatch&& src) noexcept : save_points_(std::move(src.save_points_)), @@ -189,7 +192,7 @@ WriteBatch& WriteBatch::operator=(WriteBatch&& src) { return *this; } -WriteBatch::~WriteBatch() { delete save_points_; } +WriteBatch::~WriteBatch() { } WriteBatch::Handler::~Handler() { } @@ -991,7 +994,7 @@ Status WriteBatch::PutLogData(const Slice& blob) { void WriteBatch::SetSavePoint() { if (save_points_ == nullptr) { - save_points_ = new SavePoints(); + save_points_.reset(new SavePoints()); } // Record length and count of current batch of writes. save_points_->stack.push(SavePoint( diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index 8782d08f1f1746caa2ee38a545d224ceff6fb916..29b660d19875c353d7d93f61fd0e36132dd82897 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include "rocksdb/status.h" #include "rocksdb/write_batch_base.h" @@ -337,7 +337,7 @@ class WriteBatch : public WriteBatchBase { // remove duplicate keys. Remove it when the hack is replaced with a proper // solution. friend class WriteBatchWithIndex; - SavePoints* save_points_; + std::unique_ptr save_points_; // When sending a WriteBatch through WriteImpl we might want to // specify that only the first x records of the batch be written to diff --git a/util/threadpool_imp.cc b/util/threadpool_imp.cc index acac0063bcdc721f2b3beee3870e948f837db290..ea5e875df21d00d154181fb1d6f01c8cd8ccd93c 100644 --- a/util/threadpool_imp.cc +++ b/util/threadpool_imp.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/utilities/transactions/transaction_base.cc b/utilities/transactions/transaction_base.cc index ac186a52834ebf607757719b2657ecbae93d1adf..fc2e6b5204b10f9ee06fa60cc92e3b083827ebd6 100644 --- a/utilities/transactions/transaction_base.cc +++ b/utilities/transactions/transaction_base.cc @@ -123,7 +123,7 @@ Status TransactionBaseImpl::TryLock(ColumnFamilyHandle* column_family, void TransactionBaseImpl::SetSavePoint() { if (save_points_ == nullptr) { - save_points_.reset(new std::stack()); + save_points_.reset(new std::stack>()); } save_points_->emplace(snapshot_, snapshot_needed_, snapshot_notifier_, num_puts_, num_deletes_, num_merges_); diff --git a/utilities/transactions/transaction_base.h b/utilities/transactions/transaction_base.h index 9154b32740af8866c9afdac23654c784b4e4ff73..cc3d0cdc3cd1675c09de46483dc301a0cae94df9 100644 --- a/utilities/transactions/transaction_base.h +++ b/utilities/transactions/transaction_base.h @@ -19,6 +19,7 @@ #include "rocksdb/utilities/transaction.h" #include "rocksdb/utilities/transaction_db.h" #include "rocksdb/utilities/write_batch_with_index.h" +#include "util/autovector.h" #include "utilities/transactions/transaction_util.h" namespace rocksdb { @@ -318,7 +319,7 @@ class TransactionBaseImpl : public Transaction { // Stack of the Snapshot saved at each save point. Saved snapshots may be // nullptr if there was no snapshot at the time SetSavePoint() was called. - std::unique_ptr> save_points_; + std::unique_ptr>> save_points_; // Map from column_family_id to map of keys that are involved in this // transaction.