1
1
#define NAPI_VERSION 3
2
2
3
3
#include " database.h"
4
- #include < node_api.h>
4
+
5
+ #include < node/node_api.h>
5
6
#include < rocksdb/db.h>
6
7
#include < rocksdb/status.h>
7
8
#include < rocksdb/slice.h>
8
9
#include < rocksdb/options.h>
9
10
#include < rocksdb/utilities/optimistic_transaction_db.h>
11
+
10
12
#include " worker.h"
11
13
12
- Database::Database ():
13
- db_(NULL ),
14
- currentIteratorId_(0 ),
15
- currentTransactionId_(0 ),
16
- pendingCloseWorker_(NULL ),
17
- ref_(NULL ),
18
- priorityWork_(0 ) {}
14
+ Database::Database ()
15
+ : db_(NULL ),
16
+ currentIteratorId_(0 ),
17
+ currentTransactionId_(0 ),
18
+ pendingCloseWorker_(NULL ),
19
+ ref_(NULL ),
20
+ priorityWork_(0 ) {}
19
21
20
22
Database::~Database () {
21
23
if (db_ != NULL ) {
@@ -24,107 +26,92 @@ Database::~Database() {
24
26
}
25
27
}
26
28
27
- rocksdb::Status Database::Open (
28
- const rocksdb::Options& options,
29
- const char * location
30
- ) {
29
+ rocksdb::Status Database::Open (const rocksdb::Options& options,
30
+ const char * location) {
31
31
return rocksdb::OptimisticTransactionDB::Open (options, location, &db_);
32
32
}
33
33
34
- void Database::CloseDatabase () {
34
+ void Database::CloseDatabase () {
35
35
delete db_;
36
36
db_ = NULL ;
37
37
}
38
38
39
- rocksdb::Status Database::Put (
40
- const rocksdb::WriteOptions& options,
41
- rocksdb::Slice key,
42
- rocksdb::Slice value
43
- ) {
39
+ rocksdb::Status Database::Put (const rocksdb::WriteOptions& options,
40
+ rocksdb::Slice key, rocksdb::Slice value) {
44
41
return db_->Put (options, key, value);
45
42
}
46
43
47
- rocksdb::Status Database::Get (
48
- const rocksdb::ReadOptions& options,
49
- rocksdb::Slice key,
50
- std::string& value
51
- ) {
44
+ rocksdb::Status Database::Get (const rocksdb::ReadOptions& options,
45
+ rocksdb::Slice key, std::string& value) {
52
46
return db_->Get (options, key, &value);
53
47
}
54
48
55
- rocksdb::Status Database::Del (
56
- const rocksdb::WriteOptions& options,
57
- rocksdb::Slice key
58
- ) {
49
+ rocksdb::Status Database::Del (const rocksdb::WriteOptions& options,
50
+ rocksdb::Slice key) {
59
51
return db_->Delete (options, key);
60
52
}
61
53
62
- rocksdb::Status Database::WriteBatch (
63
- const rocksdb::WriteOptions& options,
64
- rocksdb::WriteBatch* batch
65
- ) {
54
+ rocksdb::Status Database::WriteBatch (const rocksdb::WriteOptions& options,
55
+ rocksdb::WriteBatch* batch) {
66
56
return db_->Write (options, batch);
67
57
}
68
58
69
- uint64_t Database::ApproximateSize (const rocksdb::Range* range) {
59
+ uint64_t Database::ApproximateSize (const rocksdb::Range* range) {
70
60
uint64_t size = 0 ;
71
61
db_->GetApproximateSizes (range, 1 , &size);
72
62
return size;
73
63
}
74
64
75
- void Database::CompactRange (
76
- const rocksdb::Slice* start,
77
- const rocksdb::Slice* end
78
- ) {
65
+ void Database::CompactRange (const rocksdb::Slice* start,
66
+ const rocksdb::Slice* end) {
79
67
rocksdb::CompactRangeOptions options;
80
68
db_->CompactRange (options, start, end);
81
69
}
82
70
83
- void Database::GetProperty (const rocksdb::Slice& property, std::string* value) {
71
+ void Database::GetProperty (const rocksdb::Slice& property, std::string* value) {
84
72
db_->GetProperty (property, value);
85
73
}
86
74
87
- const rocksdb::Snapshot* Database::NewSnapshot () {
88
- return db_->GetSnapshot ();
89
- }
75
+ const rocksdb::Snapshot* Database::NewSnapshot () { return db_->GetSnapshot (); }
90
76
91
- rocksdb::Iterator* Database::NewIterator (rocksdb::ReadOptions* options) {
77
+ rocksdb::Iterator* Database::NewIterator (rocksdb::ReadOptions* options) {
92
78
return db_->NewIterator (*options);
93
79
}
94
80
95
- rocksdb::Transaction* Database::NewTransaction (rocksdb::WriteOptions* options) {
81
+ rocksdb::Transaction* Database::NewTransaction (rocksdb::WriteOptions* options) {
96
82
return db_->BeginTransaction (*options);
97
83
}
98
84
99
- void Database::ReleaseSnapshot (const rocksdb::Snapshot* snapshot) {
85
+ void Database::ReleaseSnapshot (const rocksdb::Snapshot* snapshot) {
100
86
return db_->ReleaseSnapshot (snapshot);
101
87
}
102
88
103
- void Database::AttachIterator (napi_env env, uint32_t id, Iterator* iterator) {
89
+ void Database::AttachIterator (napi_env env, uint32_t id, Iterator* iterator) {
104
90
iterators_[id] = iterator;
105
91
IncrementPriorityWork (env);
106
92
}
107
93
108
- void Database::DetachIterator (napi_env env, uint32_t id) {
94
+ void Database::DetachIterator (napi_env env, uint32_t id) {
109
95
iterators_.erase (id);
110
96
DecrementPriorityWork (env);
111
97
}
112
98
113
- void Database::AttachTransaction (napi_env env, uint32_t id, Transaction* transaction) {
99
+ void Database::AttachTransaction (napi_env env, uint32_t id,
100
+ Transaction* transaction) {
114
101
transactions_[id] = transaction;
115
102
IncrementPriorityWork (env);
116
103
}
117
104
118
- void Database::DetachTransaction (napi_env env, uint32_t id) {
105
+ void Database::DetachTransaction (napi_env env, uint32_t id) {
119
106
transactions_.erase (id);
120
107
DecrementPriorityWork (env);
121
108
}
122
109
123
- void Database::IncrementPriorityWork (napi_env env) {
110
+ void Database::IncrementPriorityWork (napi_env env) {
124
111
napi_reference_ref (env, ref_, &priorityWork_);
125
112
}
126
113
127
- void Database::DecrementPriorityWork (napi_env env) {
114
+ void Database::DecrementPriorityWork (napi_env env) {
128
115
napi_reference_unref (env, ref_, &priorityWork_);
129
116
130
117
if (priorityWork_ == 0 && pendingCloseWorker_ != NULL ) {
@@ -133,6 +120,4 @@ void Database::DecrementPriorityWork (napi_env env) {
133
120
}
134
121
}
135
122
136
- bool Database::HasPriorityWork () const {
137
- return priorityWork_ > 0 ;
138
- }
123
+ bool Database::HasPriorityWork () const { return priorityWork_ > 0 ; }
0 commit comments