forked from twmht/python-rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to iterate over a WriteBatch.
- Loading branch information
1 parent
cf95b57
commit 302d1a6
Showing
7 changed files
with
217 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include "rocksdb/write_batch.h" | ||
|
||
namespace py_rocks { | ||
|
||
class RecordItemsHandler: public rocksdb::WriteBatch::Handler { | ||
public: | ||
enum Optype {PutRecord, MergeRecord, DeleteRecord}; | ||
|
||
class BatchItem { | ||
public: | ||
BatchItem( | ||
const Optype& op, | ||
const rocksdb::Slice& key, | ||
const rocksdb::Slice& value): | ||
op(op), | ||
key(key), | ||
value(value) | ||
{} | ||
|
||
const Optype op; | ||
const rocksdb::Slice key; | ||
const rocksdb::Slice value; | ||
}; | ||
|
||
typedef std::vector<BatchItem> BatchItems; | ||
|
||
public: | ||
/* Items is filled during iteration. */ | ||
RecordItemsHandler(BatchItems* items): items(items) {} | ||
|
||
void Put(const Slice& key, const Slice& value) { | ||
this->items->emplace_back(PutRecord, key, value); | ||
} | ||
|
||
void Merge(const Slice& key, const Slice& value) { | ||
this->items->emplace_back(MergeRecord, key, value); | ||
} | ||
|
||
virtual void Delete(const Slice& key) { | ||
this->items->emplace_back(DeleteRecord, key, rocksdb::Slice()); | ||
} | ||
|
||
private: | ||
BatchItems* items; | ||
}; | ||
|
||
rocksdb::Status | ||
get_batch_items(const rocksdb::WriteBatch* batch, RecordItemsHandler::BatchItems* items) { | ||
RecordItemsHandler handler(items); | ||
return batch->Iterate(&handler); | ||
} | ||
|
||
} |
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