3939#include < stack>
4040#include < stdexcept>
4141#include < type_traits>
42+ #include < unordered_map>
4243#include < vector>
4344
4445#include " db/column_family.h"
@@ -1225,6 +1226,22 @@ class MemTableInserter : public WriteBatch::Handler {
12251226 DupDetector duplicate_detector_;
12261227 bool dup_dectector_on_;
12271228
1229+ bool hint_per_batch_;
1230+ bool hint_created_;
1231+ // Hints for this batch
1232+ using HintMap = std::unordered_map<MemTable*, void *>;
1233+ using HintMapType = std::aligned_storage<sizeof (HintMap)>::type;
1234+ HintMapType hint_;
1235+
1236+ HintMap& GetHintMap () {
1237+ assert (hint_per_batch_);
1238+ if (!hint_created_) {
1239+ new (&hint_) HintMap ();
1240+ hint_created_ = true ;
1241+ }
1242+ return *reinterpret_cast <HintMap*>(&hint_);
1243+ }
1244+
12281245 MemPostInfoMap& GetPostMap () {
12291246 assert (concurrent_memtable_writes_);
12301247 if (!post_info_created_) {
@@ -1258,7 +1275,7 @@ class MemTableInserter : public WriteBatch::Handler {
12581275 uint64_t recovering_log_number, DB* db,
12591276 bool concurrent_memtable_writes,
12601277 bool * has_valid_writes = nullptr , bool seq_per_batch = false ,
1261- bool batch_per_txn = true )
1278+ bool batch_per_txn = true , bool hint_per_batch = false )
12621279 : sequence_(_sequence),
12631280 cf_mems_ (cf_mems),
12641281 flush_scheduler_(flush_scheduler),
@@ -1282,7 +1299,9 @@ class MemTableInserter : public WriteBatch::Handler {
12821299 write_before_prepare_(!batch_per_txn),
12831300 unprepared_batch_(false ),
12841301 duplicate_detector_(),
1285- dup_dectector_on_(false ) {
1302+ dup_dectector_on_(false ),
1303+ hint_per_batch_(hint_per_batch),
1304+ hint_created_(false ) {
12861305 assert (cf_mems_);
12871306 }
12881307
@@ -1295,6 +1314,12 @@ class MemTableInserter : public WriteBatch::Handler {
12951314 reinterpret_cast <MemPostInfoMap*>
12961315 (&mem_post_info_map_)->~MemPostInfoMap ();
12971316 }
1317+ if (hint_created_) {
1318+ for (auto iter : GetHintMap ()) {
1319+ delete[] reinterpret_cast <char *>(iter.second );
1320+ }
1321+ reinterpret_cast <HintMap*>(&hint_)->~HintMap ();
1322+ }
12981323 delete rebuilding_trx_;
12991324 }
13001325
@@ -1404,7 +1429,8 @@ class MemTableInserter : public WriteBatch::Handler {
14041429 if (!moptions->inplace_update_support ) {
14051430 bool mem_res =
14061431 mem->Add (sequence_, value_type, key, value,
1407- concurrent_memtable_writes_, get_post_process_info (mem));
1432+ concurrent_memtable_writes_, get_post_process_info (mem),
1433+ hint_per_batch_ ? &GetHintMap ()[mem] : nullptr );
14081434 if (UNLIKELY (!mem_res)) {
14091435 assert (seq_per_batch_);
14101436 ret_status = Status::TryAgain (" key+seq exists" );
@@ -1487,7 +1513,8 @@ class MemTableInserter : public WriteBatch::Handler {
14871513 MemTable* mem = cf_mems_->GetMemTable ();
14881514 bool mem_res =
14891515 mem->Add (sequence_, delete_type, key, value,
1490- concurrent_memtable_writes_, get_post_process_info (mem));
1516+ concurrent_memtable_writes_, get_post_process_info (mem),
1517+ hint_per_batch_ ? &GetHintMap ()[mem] : nullptr );
14911518 if (UNLIKELY (!mem_res)) {
14921519 assert (seq_per_batch_);
14931520 ret_status = Status::TryAgain (" key+seq exists" );
@@ -1962,7 +1989,7 @@ Status WriteBatchInternal::InsertInto(
19621989 TrimHistoryScheduler* trim_history_scheduler,
19631990 bool ignore_missing_column_families, uint64_t log_number, DB* db,
19641991 bool concurrent_memtable_writes, bool seq_per_batch, size_t batch_cnt,
1965- bool batch_per_txn) {
1992+ bool batch_per_txn, bool hint_per_batch ) {
19661993#ifdef NDEBUG
19671994 (void )batch_cnt;
19681995#endif
@@ -1971,7 +1998,7 @@ Status WriteBatchInternal::InsertInto(
19711998 sequence, memtables, flush_scheduler, trim_history_scheduler,
19721999 ignore_missing_column_families, log_number, db,
19732000 concurrent_memtable_writes, nullptr /* has_valid_writes*/ , seq_per_batch,
1974- batch_per_txn);
2001+ batch_per_txn, hint_per_batch );
19752002 SetSequence (writer->batch , sequence);
19762003 inserter.set_log_number_ref (writer->log_ref );
19772004 Status s = writer->batch ->Iterate (&inserter);
0 commit comments