mirror of
https://github.com/google/leveldb.git
synced 2026-08-22 10:53:27 +08:00
LevelDB: Add WriteBatch::ApproximateSize().
This can be used to report metrics on LevelDB usage. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=156934930
This commit is contained in:
@@ -39,6 +39,10 @@ void WriteBatch::Clear() {
|
|||||||
rep_.resize(kHeader);
|
rep_.resize(kHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t WriteBatch::ApproximateSize() {
|
||||||
|
return rep_.size();
|
||||||
|
}
|
||||||
|
|
||||||
Status WriteBatch::Iterate(Handler* handler) const {
|
Status WriteBatch::Iterate(Handler* handler) const {
|
||||||
Slice input(rep_);
|
Slice input(rep_);
|
||||||
if (input.size() < kHeader) {
|
if (input.size() < kHeader) {
|
||||||
|
|||||||
@@ -113,6 +113,23 @@ TEST(WriteBatchTest, Append) {
|
|||||||
PrintContents(&b1));
|
PrintContents(&b1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(WriteBatchTest, ApproximateSize) {
|
||||||
|
WriteBatch batch;
|
||||||
|
size_t empty_size = batch.ApproximateSize();
|
||||||
|
|
||||||
|
batch.Put(Slice("foo"), Slice("bar"));
|
||||||
|
size_t one_key_size = batch.ApproximateSize();
|
||||||
|
ASSERT_LT(empty_size, one_key_size);
|
||||||
|
|
||||||
|
batch.Put(Slice("baz"), Slice("boo"));
|
||||||
|
size_t two_keys_size = batch.ApproximateSize();
|
||||||
|
ASSERT_LT(one_key_size, two_keys_size);
|
||||||
|
|
||||||
|
batch.Delete(Slice("box"));
|
||||||
|
size_t post_delete_size = batch.ApproximateSize();
|
||||||
|
ASSERT_LT(two_keys_size, post_delete_size);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace leveldb
|
} // namespace leveldb
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ class WriteBatch {
|
|||||||
// Clear all updates buffered in this batch.
|
// Clear all updates buffered in this batch.
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
// The size of the database changes caused by this batch.
|
||||||
|
//
|
||||||
|
// This number is tied to implementation details, and may change across
|
||||||
|
// releases. It is intended for LevelDB usage metrics.
|
||||||
|
size_t ApproximateSize();
|
||||||
|
|
||||||
// Support for iterating over the contents of a batch.
|
// Support for iterating over the contents of a batch.
|
||||||
class Handler {
|
class Handler {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user