forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce MergeContext to Lazily Initialize merge operand list
Summary: In get operations, merge_operands is only used in few cases. Lazily initialize it can reduce average latency in some cases Test Plan: make all check Reviewers: haobo, kailiu, dhruba Reviewed By: haobo CC: igor, nkg-, leveldb Differential Revision: https://reviews.facebook.net/D14415 Conflicts: db/db_impl.cc db/memtable.cc
- Loading branch information
Showing
10 changed files
with
129 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2013, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. An additional grant | ||
// of patent rights can be found in the PATENTS file in the same directory. | ||
// | ||
#pragma once | ||
#include "db/dbformat.h" | ||
#include "rocksdb/slice.h" | ||
#include <string> | ||
#include <deque> | ||
|
||
namespace rocksdb { | ||
|
||
const std::deque<std::string> empty_operand_list; | ||
|
||
// The merge context for merging a user key. | ||
// When doing a Get(), DB will create such a class and pass it when | ||
// issuing Get() operation to memtables and version_set. The operands | ||
// will be fetched from the context when issuing partial of full merge. | ||
class MergeContext { | ||
public: | ||
// Clear all the operands | ||
void Clear() { | ||
if (operand_list) { | ||
operand_list->clear(); | ||
} | ||
} | ||
// Replace the first two operands of merge_result, which are expected be the | ||
// merge results of them. | ||
void PushPartialMergeResult(std::string& merge_result) { | ||
assert (operand_list); | ||
operand_list->pop_front(); | ||
swap(operand_list->front(), merge_result); | ||
} | ||
// Push a merge operand | ||
void PushOperand(const Slice& operand_slice) { | ||
Initialize(); | ||
operand_list->push_front(operand_slice.ToString()); | ||
} | ||
// return total number of operands in the list | ||
size_t GetNumOperands() const { | ||
if (!operand_list) { | ||
return 0; | ||
} | ||
return operand_list->size(); | ||
} | ||
// Get the operand at the index. | ||
Slice GetOperand(int index) const { | ||
assert (operand_list); | ||
return (*operand_list)[index]; | ||
} | ||
// Return all the operands. | ||
const std::deque<std::string>& GetOperands() const { | ||
if (!operand_list) { | ||
return empty_operand_list; | ||
} | ||
return *operand_list; | ||
} | ||
private: | ||
void Initialize() { | ||
if (!operand_list) { | ||
operand_list.reset(new std::deque<std::string>()); | ||
} | ||
} | ||
std::unique_ptr<std::deque<std::string>> operand_list; | ||
}; | ||
|
||
} // namespace rocksdb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.