File: write_batch_iter_helper.hpp

package info (click to toggle)
python-rocksdb 0.8.0~rc3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 480 kB
  • sloc: python: 798; cpp: 408; makefile: 158
file content (65 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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,
                    uint32_t column_family_id,
                    const rocksdb::Slice& key,
                    const rocksdb::Slice& value):
                        op(op),
                        column_family_id(column_family_id),
                        key(key),
                        value(value)
                {}

            const Optype op;
            uint32_t column_family_id;
            const rocksdb::Slice key;
            const rocksdb::Slice value;
        };

        typedef std::vector<BatchItem> BatchItems;

    public:
        /* Items is filled during iteration. */
        RecordItemsHandler(BatchItems* items): items(items) {}

        virtual rocksdb::Status PutCF(
          uint32_t column_family_id, const Slice& key, const Slice& value) {
            this->items->emplace_back(PutRecord, column_family_id, key, value);
            return rocksdb::Status::OK();
        }

        virtual rocksdb::Status MergeCF(
          uint32_t column_family_id, const Slice& key, const Slice& value) {
            this->items->emplace_back(MergeRecord, column_family_id, key, value);
            return rocksdb::Status::OK();
        }

        virtual rocksdb::Status DeleteCF(
          uint32_t column_family_id, const Slice& key) {
            this->items->emplace_back(DeleteRecord, column_family_id, key, rocksdb::Slice());
            return rocksdb::Status::OK();
        }

    private:
        BatchItems* items;
};

rocksdb::Status
get_batch_items(const rocksdb::WriteBatch* batch, RecordItemsHandler::BatchItems* items) {
    RecordItemsHandler handler(items);
    return batch->Iterate(&handler);
}

}