leveldb-ruby 0.10 → 0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. data/ext/leveldb/extconf.rb +2 -6
  2. data/ext/leveldb/leveldb.cc +377 -33
  3. data/ext/leveldb/platform.rb +83 -0
  4. data/leveldb/Makefile +29 -28
  5. data/leveldb/build_detect_platform +23 -4
  6. data/leveldb/db/builder.cc +1 -1
  7. data/leveldb/db/builder.h +1 -1
  8. data/leveldb/db/corruption_test.cc +1 -1
  9. data/leveldb/db/db_bench.cc +2 -2
  10. data/leveldb/db/db_impl.cc +8 -16
  11. data/leveldb/db/db_impl.h +1 -1
  12. data/leveldb/db/db_iter.cc +1 -1
  13. data/leveldb/db/db_iter.h +1 -1
  14. data/leveldb/db/db_test.cc +180 -9
  15. data/leveldb/db/dbformat.cc +9 -7
  16. data/leveldb/db/dbformat.h +2 -2
  17. data/leveldb/db/dbformat_test.cc +1 -1
  18. data/leveldb/db/filename.cc +6 -2
  19. data/leveldb/db/filename.h +1 -1
  20. data/leveldb/db/filename_test.cc +1 -1
  21. data/leveldb/db/log_format.h +2 -2
  22. data/leveldb/db/log_reader.cc +2 -2
  23. data/leveldb/db/log_reader.h +2 -2
  24. data/leveldb/db/log_test.cc +2 -2
  25. data/leveldb/db/log_writer.cc +2 -2
  26. data/leveldb/db/log_writer.h +2 -2
  27. data/leveldb/db/memtable.cc +1 -1
  28. data/leveldb/db/memtable.h +1 -1
  29. data/leveldb/db/repair.cc +2 -2
  30. data/leveldb/db/skiplist.h +1 -1
  31. data/leveldb/db/skiplist_test.cc +1 -1
  32. data/leveldb/db/snapshot.h +1 -1
  33. data/leveldb/db/table_cache.cc +1 -1
  34. data/leveldb/db/table_cache.h +1 -1
  35. data/leveldb/db/version_edit.cc +1 -1
  36. data/leveldb/db/version_edit.h +1 -1
  37. data/leveldb/db/version_edit_test.cc +1 -1
  38. data/leveldb/db/version_set.cc +39 -14
  39. data/leveldb/db/version_set.h +1 -1
  40. data/leveldb/db/version_set_test.cc +1 -1
  41. data/leveldb/db/write_batch.cc +2 -2
  42. data/leveldb/db/write_batch_internal.h +1 -1
  43. data/leveldb/db/write_batch_test.cc +1 -1
  44. data/leveldb/helpers/memenv/memenv.cc +374 -0
  45. data/leveldb/helpers/memenv/memenv.h +20 -0
  46. data/leveldb/helpers/memenv/memenv_test.cc +232 -0
  47. data/leveldb/include/leveldb/cache.h +1 -1
  48. data/leveldb/include/leveldb/comparator.h +1 -1
  49. data/leveldb/include/leveldb/db.h +1 -1
  50. data/leveldb/include/leveldb/env.h +1 -1
  51. data/leveldb/include/leveldb/iterator.h +1 -1
  52. data/leveldb/include/leveldb/options.h +1 -1
  53. data/leveldb/include/leveldb/slice.h +1 -1
  54. data/leveldb/include/leveldb/status.h +1 -1
  55. data/leveldb/include/leveldb/table.h +1 -1
  56. data/leveldb/include/leveldb/table_builder.h +1 -1
  57. data/leveldb/include/leveldb/write_batch.h +1 -1
  58. data/leveldb/port/atomic_pointer.h +2 -2
  59. data/leveldb/port/port_android.cc +2 -2
  60. data/leveldb/port/port_android.h +2 -2
  61. data/leveldb/port/port_example.h +2 -2
  62. data/leveldb/port/port_posix.cc +2 -2
  63. data/leveldb/port/port_posix.h +11 -3
  64. data/leveldb/table/block.cc +1 -1
  65. data/leveldb/table/block.h +1 -1
  66. data/leveldb/table/block_builder.cc +1 -1
  67. data/leveldb/table/block_builder.h +1 -1
  68. data/leveldb/table/format.cc +1 -1
  69. data/leveldb/table/format.h +1 -1
  70. data/leveldb/table/iterator.cc +2 -2
  71. data/leveldb/table/merger.cc +2 -2
  72. data/leveldb/table/merger.h +1 -1
  73. data/leveldb/table/table.cc +1 -1
  74. data/leveldb/table/table_builder.cc +1 -1
  75. data/leveldb/table/table_test.cc +3 -3
  76. data/leveldb/table/two_level_iterator.cc +2 -2
  77. data/leveldb/table/two_level_iterator.h +1 -1
  78. data/leveldb/util/arena.cc +1 -1
  79. data/leveldb/util/arena.h +1 -1
  80. data/leveldb/util/arena_test.cc +1 -1
  81. data/leveldb/util/cache.cc +1 -1
  82. data/leveldb/util/cache_test.cc +1 -1
  83. data/leveldb/util/coding.cc +1 -1
  84. data/leveldb/util/coding.h +1 -1
  85. data/leveldb/util/coding_test.cc +1 -1
  86. data/leveldb/util/comparator.cc +7 -4
  87. data/leveldb/util/crc32c.cc +2 -2
  88. data/leveldb/util/crc32c.h +2 -2
  89. data/leveldb/util/crc32c_test.cc +2 -2
  90. data/leveldb/util/env.cc +17 -3
  91. data/leveldb/util/env_posix.cc +2 -2
  92. data/leveldb/util/env_test.cc +13 -11
  93. data/leveldb/util/hash.cc +1 -1
  94. data/leveldb/util/histogram.cc +1 -1
  95. data/leveldb/util/histogram.h +1 -1
  96. data/leveldb/util/logging.cc +1 -1
  97. data/leveldb/util/logging.h +1 -1
  98. data/leveldb/util/mutexlock.h +1 -1
  99. data/leveldb/util/options.cc +1 -1
  100. data/leveldb/util/posix_logger.h +1 -1
  101. data/leveldb/util/random.h +1 -1
  102. data/leveldb/util/status.cc +1 -1
  103. data/leveldb/util/testharness.cc +2 -2
  104. data/leveldb/util/testharness.h +2 -2
  105. data/leveldb/util/testutil.cc +2 -2
  106. data/leveldb/util/testutil.h +2 -2
  107. data/lib/leveldb.rb +34 -2
  108. metadata +7 -13
  109. data/leveldb/port/port_chromium.cc +0 -80
  110. data/leveldb/port/port_chromium.h +0 -97
  111. data/leveldb/port/port_osx.cc +0 -50
  112. data/leveldb/port/port_osx.h +0 -125
  113. data/leveldb/port/sha1_portable.cc +0 -298
  114. data/leveldb/port/sha1_portable.h +0 -25
  115. data/leveldb/port/sha1_test.cc +0 -39
  116. data/leveldb/util/env_chromium.cc +0 -612
@@ -38,6 +38,6 @@ class Block {
38
38
  class Iter;
39
39
  };
40
40
 
41
- }
41
+ } // namespace leveldb
42
42
 
43
43
  #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_
@@ -106,4 +106,4 @@ void BlockBuilder::Add(const Slice& key, const Slice& value) {
106
106
  counter_++;
107
107
  }
108
108
 
109
- }
109
+ } // namespace leveldb
@@ -52,6 +52,6 @@ class BlockBuilder {
52
52
  void operator=(const BlockBuilder&);
53
53
  };
54
54
 
55
- }
55
+ } // namespace leveldb
56
56
 
57
57
  #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
@@ -132,4 +132,4 @@ Status ReadBlock(RandomAccessFile* file,
132
132
  return Status::OK();
133
133
  }
134
134
 
135
- }
135
+ } // namespace leveldb
@@ -98,6 +98,6 @@ inline BlockHandle::BlockHandle()
98
98
  size_(~static_cast<uint64_t>(0)) {
99
99
  }
100
100
 
101
- }
101
+ } // namespace leveldb
102
102
 
103
103
  #endif // STORAGE_LEVELDB_TABLE_FORMAT_H_
@@ -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
@@ -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
@@ -21,6 +21,6 @@ class Iterator;
21
21
  extern Iterator* NewMergingIterator(
22
22
  const Comparator* comparator, Iterator** children, int n);
23
23
 
24
- }
24
+ } // namespace leveldb
25
25
 
26
26
  #endif // STORAGE_LEVELDB_TABLE_MERGER_H_
@@ -172,4 +172,4 @@ uint64_t Table::ApproximateOffsetOf(const Slice& key) const {
172
172
  return result;
173
173
  }
174
174
 
175
- }
175
+ } // namespace leveldb
@@ -224,4 +224,4 @@ uint64_t TableBuilder::FileSize() const {
224
224
  return rep_->offset;
225
225
  }
226
226
 
227
- }
227
+ } // namespace leveldb
@@ -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
@@ -29,6 +29,6 @@ extern Iterator* NewTwoLevelIterator(
29
29
  void* arg,
30
30
  const ReadOptions& options);
31
31
 
32
- }
32
+ } // namespace leveldb
33
33
 
34
34
  #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_
@@ -65,4 +65,4 @@ char* Arena::AllocateNewBlock(size_t block_bytes) {
65
65
  return result;
66
66
  }
67
67
 
68
- }
68
+ } // namespace leveldb
@@ -63,6 +63,6 @@ inline char* Arena::Allocate(size_t bytes) {
63
63
  return AllocateFallback(bytes);
64
64
  }
65
65
 
66
- }
66
+ } // namespace leveldb
67
67
 
68
68
  #endif // STORAGE_LEVELDB_UTIL_ARENA_H_
@@ -61,7 +61,7 @@ TEST(ArenaTest, Simple) {
61
61
  }
62
62
  }
63
63
 
64
- }
64
+ } // namespace leveldb
65
65
 
66
66
  int main(int argc, char** argv) {
67
67
  return leveldb::test::RunAllTests();
@@ -325,4 +325,4 @@ Cache* NewLRUCache(size_t capacity) {
325
325
  return new ShardedLRUCache(capacity);
326
326
  }
327
327
 
328
- }
328
+ } // namespace leveldb
@@ -179,7 +179,7 @@ TEST(CacheTest, NewId) {
179
179
  ASSERT_NE(a, b);
180
180
  }
181
181
 
182
- }
182
+ } // namespace leveldb
183
183
 
184
184
  int main(int argc, char** argv) {
185
185
  return leveldb::test::RunAllTests();
@@ -191,4 +191,4 @@ bool GetLengthPrefixedSlice(Slice* input, Slice* result) {
191
191
  }
192
192
  }
193
193
 
194
- }
194
+ } // namespace leveldb
@@ -99,6 +99,6 @@ inline const char* GetVarint32Ptr(const char* p,
99
99
  return GetVarint32PtrFallback(p, limit, value);
100
100
  }
101
101
 
102
- }
102
+ } // namespace leveldb
103
103
 
104
104
  #endif // STORAGE_LEVELDB_UTIL_CODING_H_
@@ -166,7 +166,7 @@ TEST(Coding, Strings) {
166
166
  ASSERT_EQ("", input.ToString());
167
167
  }
168
168
 
169
- }
169
+ } // namespace leveldb
170
170
 
171
171
  int main(int argc, char** argv) {
172
172
  return leveldb::test::RunAllTests();
@@ -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
- static const BytewiseComparatorImpl bytewise;
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 &bytewise;
73
+ return bytewise;
71
74
  }
72
75
 
73
- }
76
+ } // namespace leveldb
@@ -328,5 +328,5 @@ uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
328
328
  return l ^ 0xffffffffu;
329
329
  }
330
330
 
331
- }
332
- }
331
+ } // namespace crc32c
332
+ } // namespace leveldb
@@ -39,7 +39,7 @@ inline uint32_t Unmask(uint32_t masked_crc) {
39
39
  return ((rot >> 17) | (rot << 15));
40
40
  }
41
41
 
42
- }
43
- }
42
+ } // namespace crc32c
43
+ } // namespace leveldb
44
44
 
45
45
  #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_
@@ -64,8 +64,8 @@ TEST(CRC, Mask) {
64
64
  ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc)))));
65
65
  }
66
66
 
67
- }
68
- }
67
+ } // namespace crc32c
68
+ } // namespace leveldb
69
69
 
70
70
  int main(int argc, char** argv) {
71
71
  return leveldb::test::RunAllTests();
@@ -33,14 +33,18 @@ void Log(Logger* info_log, const char* format, ...) {
33
33
  }
34
34
  }
35
35
 
36
- Status WriteStringToFile(Env* env, const Slice& data,
37
- const std::string& fname) {
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
@@ -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
@@ -22,29 +22,30 @@ class EnvPosixTest {
22
22
  };
23
23
 
24
24
  static void SetBool(void* ptr) {
25
- *(reinterpret_cast<bool*>(ptr)) = true;
25
+ reinterpret_cast<port::AtomicPointer*>(ptr)->NoBarrier_Store(ptr);
26
26
  }
27
27
 
28
28
  TEST(EnvPosixTest, RunImmediately) {
29
- bool called = false;
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
- int last_id = 0;
36
+ port::AtomicPointer last_id (NULL);
37
37
 
38
38
  struct CB {
39
- int* last_id_ptr; // Pointer to shared slot
40
- int id; // Order# for the execution of this callback
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(int* p, int i) : last_id_ptr(p), id(i) { }
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
- ASSERT_EQ(cb->id-1, *cb->last_id_ptr);
47
- *cb->last_id_ptr = cb->id;
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
- ASSERT_EQ(4, last_id);
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();
@@ -42,4 +42,4 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) {
42
42
  }
43
43
 
44
44
 
45
- }
45
+ } // namespace leveldb
@@ -136,4 +136,4 @@ std::string Histogram::ToString() const {
136
136
  return r;
137
137
  }
138
138
 
139
- }
139
+ } // namespace leveldb
@@ -37,6 +37,6 @@ class Histogram {
37
37
  double StandardDeviation() const;
38
38
  };
39
39
 
40
- }
40
+ } // namespace leveldb
41
41
 
42
42
  #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
@@ -78,4 +78,4 @@ bool ConsumeDecimalNumber(Slice* in, uint64_t* val) {
78
78
  return (digits > 0);
79
79
  }
80
80
 
81
- }
81
+ } // namespace leveldb
@@ -42,6 +42,6 @@ extern bool ConsumeChar(Slice* in, char c);
42
42
  // unspecified state.
43
43
  extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val);
44
44
 
45
- }
45
+ } // namespace leveldb
46
46
 
47
47
  #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_
@@ -33,7 +33,7 @@ class MutexLock {
33
33
  void operator=(const MutexLock&);
34
34
  };
35
35
 
36
- }
36
+ } // namespace leveldb
37
37
 
38
38
 
39
39
  #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
@@ -25,4 +25,4 @@ Options::Options()
25
25
  }
26
26
 
27
27
 
28
- }
28
+ } // namespace leveldb
@@ -93,6 +93,6 @@ class PosixLogger : public Logger {
93
93
  }
94
94
  };
95
95
 
96
- }
96
+ } // namespace leveldb
97
97
 
98
98
  #endif // STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_