leveldb-ruby 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/leveldb/extconf.rb +2 -6
- data/ext/leveldb/leveldb.cc +377 -33
- data/ext/leveldb/platform.rb +83 -0
- data/leveldb/Makefile +29 -28
- data/leveldb/build_detect_platform +23 -4
- data/leveldb/db/builder.cc +1 -1
- data/leveldb/db/builder.h +1 -1
- data/leveldb/db/corruption_test.cc +1 -1
- data/leveldb/db/db_bench.cc +2 -2
- data/leveldb/db/db_impl.cc +8 -16
- data/leveldb/db/db_impl.h +1 -1
- data/leveldb/db/db_iter.cc +1 -1
- data/leveldb/db/db_iter.h +1 -1
- data/leveldb/db/db_test.cc +180 -9
- data/leveldb/db/dbformat.cc +9 -7
- data/leveldb/db/dbformat.h +2 -2
- data/leveldb/db/dbformat_test.cc +1 -1
- data/leveldb/db/filename.cc +6 -2
- data/leveldb/db/filename.h +1 -1
- data/leveldb/db/filename_test.cc +1 -1
- data/leveldb/db/log_format.h +2 -2
- data/leveldb/db/log_reader.cc +2 -2
- data/leveldb/db/log_reader.h +2 -2
- data/leveldb/db/log_test.cc +2 -2
- data/leveldb/db/log_writer.cc +2 -2
- data/leveldb/db/log_writer.h +2 -2
- data/leveldb/db/memtable.cc +1 -1
- data/leveldb/db/memtable.h +1 -1
- data/leveldb/db/repair.cc +2 -2
- data/leveldb/db/skiplist.h +1 -1
- data/leveldb/db/skiplist_test.cc +1 -1
- data/leveldb/db/snapshot.h +1 -1
- data/leveldb/db/table_cache.cc +1 -1
- data/leveldb/db/table_cache.h +1 -1
- data/leveldb/db/version_edit.cc +1 -1
- data/leveldb/db/version_edit.h +1 -1
- data/leveldb/db/version_edit_test.cc +1 -1
- data/leveldb/db/version_set.cc +39 -14
- data/leveldb/db/version_set.h +1 -1
- data/leveldb/db/version_set_test.cc +1 -1
- data/leveldb/db/write_batch.cc +2 -2
- data/leveldb/db/write_batch_internal.h +1 -1
- data/leveldb/db/write_batch_test.cc +1 -1
- data/leveldb/helpers/memenv/memenv.cc +374 -0
- data/leveldb/helpers/memenv/memenv.h +20 -0
- data/leveldb/helpers/memenv/memenv_test.cc +232 -0
- data/leveldb/include/leveldb/cache.h +1 -1
- data/leveldb/include/leveldb/comparator.h +1 -1
- data/leveldb/include/leveldb/db.h +1 -1
- data/leveldb/include/leveldb/env.h +1 -1
- data/leveldb/include/leveldb/iterator.h +1 -1
- data/leveldb/include/leveldb/options.h +1 -1
- data/leveldb/include/leveldb/slice.h +1 -1
- data/leveldb/include/leveldb/status.h +1 -1
- data/leveldb/include/leveldb/table.h +1 -1
- data/leveldb/include/leveldb/table_builder.h +1 -1
- data/leveldb/include/leveldb/write_batch.h +1 -1
- data/leveldb/port/atomic_pointer.h +2 -2
- data/leveldb/port/port_android.cc +2 -2
- data/leveldb/port/port_android.h +2 -2
- data/leveldb/port/port_example.h +2 -2
- data/leveldb/port/port_posix.cc +2 -2
- data/leveldb/port/port_posix.h +11 -3
- data/leveldb/table/block.cc +1 -1
- data/leveldb/table/block.h +1 -1
- data/leveldb/table/block_builder.cc +1 -1
- data/leveldb/table/block_builder.h +1 -1
- data/leveldb/table/format.cc +1 -1
- data/leveldb/table/format.h +1 -1
- data/leveldb/table/iterator.cc +2 -2
- data/leveldb/table/merger.cc +2 -2
- data/leveldb/table/merger.h +1 -1
- data/leveldb/table/table.cc +1 -1
- data/leveldb/table/table_builder.cc +1 -1
- data/leveldb/table/table_test.cc +3 -3
- data/leveldb/table/two_level_iterator.cc +2 -2
- data/leveldb/table/two_level_iterator.h +1 -1
- data/leveldb/util/arena.cc +1 -1
- data/leveldb/util/arena.h +1 -1
- data/leveldb/util/arena_test.cc +1 -1
- data/leveldb/util/cache.cc +1 -1
- data/leveldb/util/cache_test.cc +1 -1
- data/leveldb/util/coding.cc +1 -1
- data/leveldb/util/coding.h +1 -1
- data/leveldb/util/coding_test.cc +1 -1
- data/leveldb/util/comparator.cc +7 -4
- data/leveldb/util/crc32c.cc +2 -2
- data/leveldb/util/crc32c.h +2 -2
- data/leveldb/util/crc32c_test.cc +2 -2
- data/leveldb/util/env.cc +17 -3
- data/leveldb/util/env_posix.cc +2 -2
- data/leveldb/util/env_test.cc +13 -11
- data/leveldb/util/hash.cc +1 -1
- data/leveldb/util/histogram.cc +1 -1
- data/leveldb/util/histogram.h +1 -1
- data/leveldb/util/logging.cc +1 -1
- data/leveldb/util/logging.h +1 -1
- data/leveldb/util/mutexlock.h +1 -1
- data/leveldb/util/options.cc +1 -1
- data/leveldb/util/posix_logger.h +1 -1
- data/leveldb/util/random.h +1 -1
- data/leveldb/util/status.cc +1 -1
- data/leveldb/util/testharness.cc +2 -2
- data/leveldb/util/testharness.h +2 -2
- data/leveldb/util/testutil.cc +2 -2
- data/leveldb/util/testutil.h +2 -2
- data/lib/leveldb.rb +34 -2
- metadata +7 -13
- data/leveldb/port/port_chromium.cc +0 -80
- data/leveldb/port/port_chromium.h +0 -97
- data/leveldb/port/port_osx.cc +0 -50
- data/leveldb/port/port_osx.h +0 -125
- data/leveldb/port/sha1_portable.cc +0 -298
- data/leveldb/port/sha1_portable.h +0 -25
- data/leveldb/port/sha1_test.cc +0 -39
- data/leveldb/util/env_chromium.cc +0 -612
data/leveldb/table/block.h
CHANGED
data/leveldb/table/format.cc
CHANGED
data/leveldb/table/format.h
CHANGED
data/leveldb/table/iterator.cc
CHANGED
@@ -54,7 +54,7 @@ class EmptyIterator : public Iterator {
|
|
54
54
|
private:
|
55
55
|
Status status_;
|
56
56
|
};
|
57
|
-
}
|
57
|
+
} // namespace
|
58
58
|
|
59
59
|
Iterator* NewEmptyIterator() {
|
60
60
|
return new EmptyIterator(Status::OK());
|
@@ -64,4 +64,4 @@ Iterator* NewErrorIterator(const Status& status) {
|
|
64
64
|
return new EmptyIterator(status);
|
65
65
|
}
|
66
66
|
|
67
|
-
}
|
67
|
+
} // namespace leveldb
|
data/leveldb/table/merger.cc
CHANGED
@@ -181,7 +181,7 @@ void MergingIterator::FindLargest() {
|
|
181
181
|
}
|
182
182
|
current_ = largest;
|
183
183
|
}
|
184
|
-
}
|
184
|
+
} // namespace
|
185
185
|
|
186
186
|
Iterator* NewMergingIterator(const Comparator* cmp, Iterator** list, int n) {
|
187
187
|
assert(n >= 0);
|
@@ -194,4 +194,4 @@ Iterator* NewMergingIterator(const Comparator* cmp, Iterator** list, int n) {
|
|
194
194
|
}
|
195
195
|
}
|
196
196
|
|
197
|
-
}
|
197
|
+
} // namespace leveldb
|
data/leveldb/table/merger.h
CHANGED
data/leveldb/table/table.cc
CHANGED
data/leveldb/table/table_test.cc
CHANGED
@@ -60,7 +60,7 @@ class ReverseKeyComparator : public Comparator {
|
|
60
60
|
*key = Reverse(s);
|
61
61
|
}
|
62
62
|
};
|
63
|
-
}
|
63
|
+
} // namespace
|
64
64
|
static ReverseKeyComparator reverse_key_comparator;
|
65
65
|
|
66
66
|
static void Increment(const Comparator* cmp, std::string* key) {
|
@@ -85,7 +85,7 @@ struct STLLessThan {
|
|
85
85
|
return cmp->Compare(Slice(a), Slice(b)) < 0;
|
86
86
|
}
|
87
87
|
};
|
88
|
-
}
|
88
|
+
} // namespace
|
89
89
|
|
90
90
|
class StringSink: public WritableFile {
|
91
91
|
public:
|
@@ -847,7 +847,7 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
|
|
847
847
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("xyz"), 4000, 6000));
|
848
848
|
}
|
849
849
|
|
850
|
-
}
|
850
|
+
} // namespace leveldb
|
851
851
|
|
852
852
|
int main(int argc, char** argv) {
|
853
853
|
return leveldb::test::RunAllTests();
|
@@ -169,7 +169,7 @@ void TwoLevelIterator::InitDataBlock() {
|
|
169
169
|
}
|
170
170
|
}
|
171
171
|
|
172
|
-
}
|
172
|
+
} // namespace
|
173
173
|
|
174
174
|
Iterator* NewTwoLevelIterator(
|
175
175
|
Iterator* index_iter,
|
@@ -179,4 +179,4 @@ Iterator* NewTwoLevelIterator(
|
|
179
179
|
return new TwoLevelIterator(index_iter, block_function, arg, options);
|
180
180
|
}
|
181
181
|
|
182
|
-
}
|
182
|
+
} // namespace leveldb
|
data/leveldb/util/arena.cc
CHANGED
data/leveldb/util/arena.h
CHANGED
data/leveldb/util/arena_test.cc
CHANGED
data/leveldb/util/cache.cc
CHANGED
data/leveldb/util/cache_test.cc
CHANGED
data/leveldb/util/coding.cc
CHANGED
data/leveldb/util/coding.h
CHANGED
data/leveldb/util/coding_test.cc
CHANGED
data/leveldb/util/comparator.cc
CHANGED
@@ -63,11 +63,14 @@ class BytewiseComparatorImpl : public Comparator {
|
|
63
63
|
// *key is a run of 0xffs. Leave it alone.
|
64
64
|
}
|
65
65
|
};
|
66
|
-
}
|
67
|
-
|
66
|
+
} // namespace
|
67
|
+
|
68
|
+
// Intentionally not destroyed to prevent destructor racing
|
69
|
+
// with background threads.
|
70
|
+
static const Comparator* bytewise = new BytewiseComparatorImpl;
|
68
71
|
|
69
72
|
const Comparator* BytewiseComparator() {
|
70
|
-
return
|
73
|
+
return bytewise;
|
71
74
|
}
|
72
75
|
|
73
|
-
}
|
76
|
+
} // namespace leveldb
|
data/leveldb/util/crc32c.cc
CHANGED
data/leveldb/util/crc32c.h
CHANGED
data/leveldb/util/crc32c_test.cc
CHANGED
data/leveldb/util/env.cc
CHANGED
@@ -33,14 +33,18 @@ void Log(Logger* info_log, const char* format, ...) {
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
Status
|
37
|
-
|
36
|
+
static Status DoWriteStringToFile(Env* env, const Slice& data,
|
37
|
+
const std::string& fname,
|
38
|
+
bool should_sync) {
|
38
39
|
WritableFile* file;
|
39
40
|
Status s = env->NewWritableFile(fname, &file);
|
40
41
|
if (!s.ok()) {
|
41
42
|
return s;
|
42
43
|
}
|
43
44
|
s = file->Append(data);
|
45
|
+
if (s.ok() && should_sync) {
|
46
|
+
s = file->Sync();
|
47
|
+
}
|
44
48
|
if (s.ok()) {
|
45
49
|
s = file->Close();
|
46
50
|
}
|
@@ -51,6 +55,16 @@ Status WriteStringToFile(Env* env, const Slice& data,
|
|
51
55
|
return s;
|
52
56
|
}
|
53
57
|
|
58
|
+
Status WriteStringToFile(Env* env, const Slice& data,
|
59
|
+
const std::string& fname) {
|
60
|
+
return DoWriteStringToFile(env, data, fname, false);
|
61
|
+
}
|
62
|
+
|
63
|
+
Status WriteStringToFileSync(Env* env, const Slice& data,
|
64
|
+
const std::string& fname) {
|
65
|
+
return DoWriteStringToFile(env, data, fname, true);
|
66
|
+
}
|
67
|
+
|
54
68
|
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
|
55
69
|
data->clear();
|
56
70
|
SequentialFile* file;
|
@@ -79,4 +93,4 @@ Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
|
|
79
93
|
EnvWrapper::~EnvWrapper() {
|
80
94
|
}
|
81
95
|
|
82
|
-
}
|
96
|
+
} // namespace leveldb
|
data/leveldb/util/env_posix.cc
CHANGED
@@ -553,7 +553,7 @@ void PosixEnv::StartThread(void (*function)(void* arg), void* arg) {
|
|
553
553
|
pthread_create(&t, NULL, &StartThreadWrapper, state));
|
554
554
|
}
|
555
555
|
|
556
|
-
}
|
556
|
+
} // namespace
|
557
557
|
|
558
558
|
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
559
559
|
static Env* default_env;
|
@@ -564,4 +564,4 @@ Env* Env::Default() {
|
|
564
564
|
return default_env;
|
565
565
|
}
|
566
566
|
|
567
|
-
}
|
567
|
+
} // namespace leveldb
|
data/leveldb/util/env_test.cc
CHANGED
@@ -22,29 +22,30 @@ class EnvPosixTest {
|
|
22
22
|
};
|
23
23
|
|
24
24
|
static void SetBool(void* ptr) {
|
25
|
-
|
25
|
+
reinterpret_cast<port::AtomicPointer*>(ptr)->NoBarrier_Store(ptr);
|
26
26
|
}
|
27
27
|
|
28
28
|
TEST(EnvPosixTest, RunImmediately) {
|
29
|
-
|
29
|
+
port::AtomicPointer called (NULL);
|
30
30
|
env_->Schedule(&SetBool, &called);
|
31
31
|
Env::Default()->SleepForMicroseconds(kDelayMicros);
|
32
|
-
ASSERT_TRUE(called);
|
32
|
+
ASSERT_TRUE(called.NoBarrier_Load() != NULL);
|
33
33
|
}
|
34
34
|
|
35
35
|
TEST(EnvPosixTest, RunMany) {
|
36
|
-
|
36
|
+
port::AtomicPointer last_id (NULL);
|
37
37
|
|
38
38
|
struct CB {
|
39
|
-
|
40
|
-
|
39
|
+
port::AtomicPointer* last_id_ptr; // Pointer to shared slot
|
40
|
+
uintptr_t id; // Order# for the execution of this callback
|
41
41
|
|
42
|
-
CB(
|
42
|
+
CB(port::AtomicPointer* p, int i) : last_id_ptr(p), id(i) { }
|
43
43
|
|
44
44
|
static void Run(void* v) {
|
45
45
|
CB* cb = reinterpret_cast<CB*>(v);
|
46
|
-
|
47
|
-
|
46
|
+
void* cur = cb->last_id_ptr->NoBarrier_Load();
|
47
|
+
ASSERT_EQ(cb->id-1, reinterpret_cast<uintptr_t>(cur));
|
48
|
+
cb->last_id_ptr->Release_Store(reinterpret_cast<void*>(cb->id));
|
48
49
|
}
|
49
50
|
};
|
50
51
|
|
@@ -59,7 +60,8 @@ TEST(EnvPosixTest, RunMany) {
|
|
59
60
|
env_->Schedule(&CB::Run, &cb4);
|
60
61
|
|
61
62
|
Env::Default()->SleepForMicroseconds(kDelayMicros);
|
62
|
-
|
63
|
+
void* cur = last_id.Acquire_Load();
|
64
|
+
ASSERT_EQ(4, reinterpret_cast<uintptr_t>(cur));
|
63
65
|
}
|
64
66
|
|
65
67
|
struct State {
|
@@ -95,7 +97,7 @@ TEST(EnvPosixTest, StartThread) {
|
|
95
97
|
ASSERT_EQ(state.val, 3);
|
96
98
|
}
|
97
99
|
|
98
|
-
}
|
100
|
+
} // namespace leveldb
|
99
101
|
|
100
102
|
int main(int argc, char** argv) {
|
101
103
|
return leveldb::test::RunAllTests();
|
data/leveldb/util/hash.cc
CHANGED
data/leveldb/util/histogram.cc
CHANGED
data/leveldb/util/histogram.h
CHANGED
data/leveldb/util/logging.cc
CHANGED
data/leveldb/util/logging.h
CHANGED
data/leveldb/util/mutexlock.h
CHANGED
data/leveldb/util/options.cc
CHANGED