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
@@ -0,0 +1,20 @@
|
|
1
|
+
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
3
|
+
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
4
|
+
|
5
|
+
#ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
|
6
|
+
#define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
|
7
|
+
|
8
|
+
namespace leveldb {
|
9
|
+
|
10
|
+
class Env;
|
11
|
+
|
12
|
+
// Returns a new environment that stores its data in memory and delegates
|
13
|
+
// all non-file-storage tasks to base_env. The caller must delete the result
|
14
|
+
// when it is no longer needed.
|
15
|
+
// *base_env must remain live while the result is in use.
|
16
|
+
Env* NewMemEnv(Env* base_env);
|
17
|
+
|
18
|
+
} // namespace leveldb
|
19
|
+
|
20
|
+
#endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
|
@@ -0,0 +1,232 @@
|
|
1
|
+
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
3
|
+
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
4
|
+
|
5
|
+
#include "helpers/memenv/memenv.h"
|
6
|
+
|
7
|
+
#include "db/db_impl.h"
|
8
|
+
#include "leveldb/db.h"
|
9
|
+
#include "leveldb/env.h"
|
10
|
+
#include "util/testharness.h"
|
11
|
+
#include <string>
|
12
|
+
#include <vector>
|
13
|
+
|
14
|
+
namespace leveldb {
|
15
|
+
|
16
|
+
class MemEnvTest {
|
17
|
+
public:
|
18
|
+
Env* env_;
|
19
|
+
|
20
|
+
MemEnvTest()
|
21
|
+
: env_(NewMemEnv(Env::Default())) {
|
22
|
+
}
|
23
|
+
~MemEnvTest() {
|
24
|
+
delete env_;
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
TEST(MemEnvTest, Basics) {
|
29
|
+
uint64_t file_size;
|
30
|
+
WritableFile* writable_file;
|
31
|
+
std::vector<std::string> children;
|
32
|
+
|
33
|
+
ASSERT_OK(env_->CreateDir("/dir"));
|
34
|
+
|
35
|
+
// Check that the directory is empty.
|
36
|
+
ASSERT_TRUE(!env_->FileExists("/dir/non_existent"));
|
37
|
+
ASSERT_TRUE(!env_->GetFileSize("/dir/non_existent", &file_size).ok());
|
38
|
+
ASSERT_OK(env_->GetChildren("/dir", &children));
|
39
|
+
ASSERT_EQ(0, children.size());
|
40
|
+
|
41
|
+
// Create a file.
|
42
|
+
ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
|
43
|
+
delete writable_file;
|
44
|
+
|
45
|
+
// Check that the file exists.
|
46
|
+
ASSERT_TRUE(env_->FileExists("/dir/f"));
|
47
|
+
ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
|
48
|
+
ASSERT_EQ(0, file_size);
|
49
|
+
ASSERT_OK(env_->GetChildren("/dir", &children));
|
50
|
+
ASSERT_EQ(1, children.size());
|
51
|
+
ASSERT_EQ("f", children[0]);
|
52
|
+
|
53
|
+
// Write to the file.
|
54
|
+
ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
|
55
|
+
ASSERT_OK(writable_file->Append("abc"));
|
56
|
+
delete writable_file;
|
57
|
+
|
58
|
+
// Check for expected size.
|
59
|
+
ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
|
60
|
+
ASSERT_EQ(3, file_size);
|
61
|
+
|
62
|
+
// Check that renaming works.
|
63
|
+
ASSERT_TRUE(!env_->RenameFile("/dir/non_existent", "/dir/g").ok());
|
64
|
+
ASSERT_OK(env_->RenameFile("/dir/f", "/dir/g"));
|
65
|
+
ASSERT_TRUE(!env_->FileExists("/dir/f"));
|
66
|
+
ASSERT_TRUE(env_->FileExists("/dir/g"));
|
67
|
+
ASSERT_OK(env_->GetFileSize("/dir/g", &file_size));
|
68
|
+
ASSERT_EQ(3, file_size);
|
69
|
+
|
70
|
+
// Check that opening non-existent file fails.
|
71
|
+
SequentialFile* seq_file;
|
72
|
+
RandomAccessFile* rand_file;
|
73
|
+
ASSERT_TRUE(!env_->NewSequentialFile("/dir/non_existent", &seq_file).ok());
|
74
|
+
ASSERT_TRUE(!seq_file);
|
75
|
+
ASSERT_TRUE(!env_->NewRandomAccessFile("/dir/non_existent", &rand_file).ok());
|
76
|
+
ASSERT_TRUE(!rand_file);
|
77
|
+
|
78
|
+
// Check that deleting works.
|
79
|
+
ASSERT_TRUE(!env_->DeleteFile("/dir/non_existent").ok());
|
80
|
+
ASSERT_OK(env_->DeleteFile("/dir/g"));
|
81
|
+
ASSERT_TRUE(!env_->FileExists("/dir/g"));
|
82
|
+
ASSERT_OK(env_->GetChildren("/dir", &children));
|
83
|
+
ASSERT_EQ(0, children.size());
|
84
|
+
ASSERT_OK(env_->DeleteDir("/dir"));
|
85
|
+
}
|
86
|
+
|
87
|
+
TEST(MemEnvTest, ReadWrite) {
|
88
|
+
WritableFile* writable_file;
|
89
|
+
SequentialFile* seq_file;
|
90
|
+
RandomAccessFile* rand_file;
|
91
|
+
Slice result;
|
92
|
+
char scratch[100];
|
93
|
+
|
94
|
+
ASSERT_OK(env_->CreateDir("/dir"));
|
95
|
+
|
96
|
+
ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
|
97
|
+
ASSERT_OK(writable_file->Append("hello "));
|
98
|
+
ASSERT_OK(writable_file->Append("world"));
|
99
|
+
delete writable_file;
|
100
|
+
|
101
|
+
// Read sequentially.
|
102
|
+
ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
|
103
|
+
ASSERT_OK(seq_file->Read(5, &result, scratch)); // Read "hello".
|
104
|
+
ASSERT_EQ(0, result.compare("hello"));
|
105
|
+
ASSERT_OK(seq_file->Skip(1));
|
106
|
+
ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Read "world".
|
107
|
+
ASSERT_EQ(0, result.compare("world"));
|
108
|
+
ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Try reading past EOF.
|
109
|
+
ASSERT_EQ(0, result.size());
|
110
|
+
ASSERT_OK(seq_file->Skip(100)); // Try to skip past end of file.
|
111
|
+
ASSERT_OK(seq_file->Read(1000, &result, scratch));
|
112
|
+
ASSERT_EQ(0, result.size());
|
113
|
+
delete seq_file;
|
114
|
+
|
115
|
+
// Random reads.
|
116
|
+
ASSERT_OK(env_->NewRandomAccessFile("/dir/f", &rand_file));
|
117
|
+
ASSERT_OK(rand_file->Read(6, 5, &result, scratch)); // Read "world".
|
118
|
+
ASSERT_EQ(0, result.compare("world"));
|
119
|
+
ASSERT_OK(rand_file->Read(0, 5, &result, scratch)); // Read "hello".
|
120
|
+
ASSERT_EQ(0, result.compare("hello"));
|
121
|
+
ASSERT_OK(rand_file->Read(10, 100, &result, scratch)); // Read "d".
|
122
|
+
ASSERT_EQ(0, result.compare("d"));
|
123
|
+
|
124
|
+
// Too high offset.
|
125
|
+
ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
|
126
|
+
delete rand_file;
|
127
|
+
}
|
128
|
+
|
129
|
+
TEST(MemEnvTest, Locks) {
|
130
|
+
FileLock* lock;
|
131
|
+
|
132
|
+
// These are no-ops, but we test they return success.
|
133
|
+
ASSERT_OK(env_->LockFile("some file", &lock));
|
134
|
+
ASSERT_OK(env_->UnlockFile(lock));
|
135
|
+
}
|
136
|
+
|
137
|
+
TEST(MemEnvTest, Misc) {
|
138
|
+
std::string test_dir;
|
139
|
+
ASSERT_OK(env_->GetTestDirectory(&test_dir));
|
140
|
+
ASSERT_TRUE(!test_dir.empty());
|
141
|
+
|
142
|
+
WritableFile* writable_file;
|
143
|
+
ASSERT_OK(env_->NewWritableFile("/a/b", &writable_file));
|
144
|
+
|
145
|
+
// These are no-ops, but we test they return success.
|
146
|
+
ASSERT_OK(writable_file->Sync());
|
147
|
+
ASSERT_OK(writable_file->Flush());
|
148
|
+
ASSERT_OK(writable_file->Close());
|
149
|
+
delete writable_file;
|
150
|
+
}
|
151
|
+
|
152
|
+
TEST(MemEnvTest, LargeWrite) {
|
153
|
+
const size_t kWriteSize = 300 * 1024;
|
154
|
+
char* scratch = new char[kWriteSize * 2];
|
155
|
+
|
156
|
+
std::string write_data;
|
157
|
+
for (size_t i = 0; i < kWriteSize; ++i) {
|
158
|
+
write_data.append(1, static_cast<char>(i));
|
159
|
+
}
|
160
|
+
|
161
|
+
WritableFile* writable_file;
|
162
|
+
ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
|
163
|
+
ASSERT_OK(writable_file->Append("foo"));
|
164
|
+
ASSERT_OK(writable_file->Append(write_data));
|
165
|
+
delete writable_file;
|
166
|
+
|
167
|
+
SequentialFile* seq_file;
|
168
|
+
Slice result;
|
169
|
+
ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
|
170
|
+
ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo".
|
171
|
+
ASSERT_EQ(0, result.compare("foo"));
|
172
|
+
|
173
|
+
size_t read = 0;
|
174
|
+
std::string read_data;
|
175
|
+
while (read < kWriteSize) {
|
176
|
+
ASSERT_OK(seq_file->Read(kWriteSize - read, &result, scratch));
|
177
|
+
read_data.append(result.data(), result.size());
|
178
|
+
read += result.size();
|
179
|
+
}
|
180
|
+
ASSERT_TRUE(write_data == read_data);
|
181
|
+
delete seq_file;
|
182
|
+
delete [] scratch;
|
183
|
+
}
|
184
|
+
|
185
|
+
TEST(MemEnvTest, DBTest) {
|
186
|
+
Options options;
|
187
|
+
options.create_if_missing = true;
|
188
|
+
options.env = env_;
|
189
|
+
DB* db;
|
190
|
+
|
191
|
+
const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
|
192
|
+
const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
|
193
|
+
|
194
|
+
ASSERT_OK(DB::Open(options, "/dir/db", &db));
|
195
|
+
for (size_t i = 0; i < 3; ++i) {
|
196
|
+
ASSERT_OK(db->Put(WriteOptions(), keys[i], vals[i]));
|
197
|
+
}
|
198
|
+
|
199
|
+
for (size_t i = 0; i < 3; ++i) {
|
200
|
+
std::string res;
|
201
|
+
ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
|
202
|
+
ASSERT_TRUE(res == vals[i]);
|
203
|
+
}
|
204
|
+
|
205
|
+
Iterator* iterator = db->NewIterator(ReadOptions());
|
206
|
+
iterator->SeekToFirst();
|
207
|
+
for (size_t i = 0; i < 3; ++i) {
|
208
|
+
ASSERT_TRUE(iterator->Valid());
|
209
|
+
ASSERT_TRUE(keys[i] == iterator->key());
|
210
|
+
ASSERT_TRUE(vals[i] == iterator->value());
|
211
|
+
iterator->Next();
|
212
|
+
}
|
213
|
+
ASSERT_TRUE(!iterator->Valid());
|
214
|
+
delete iterator;
|
215
|
+
|
216
|
+
DBImpl* dbi = reinterpret_cast<DBImpl*>(db);
|
217
|
+
ASSERT_OK(dbi->TEST_CompactMemTable());
|
218
|
+
|
219
|
+
for (size_t i = 0; i < 3; ++i) {
|
220
|
+
std::string res;
|
221
|
+
ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
|
222
|
+
ASSERT_TRUE(res == vals[i]);
|
223
|
+
}
|
224
|
+
|
225
|
+
delete db;
|
226
|
+
}
|
227
|
+
|
228
|
+
} // namespace leveldb
|
229
|
+
|
230
|
+
int main(int argc, char** argv) {
|
231
|
+
return leveldb::test::RunAllTests();
|
232
|
+
}
|
@@ -155,6 +155,6 @@ Status DestroyDB(const std::string& name, const Options& options);
|
|
155
155
|
// on a database that contains important information.
|
156
156
|
Status RepairDB(const std::string& dbname, const Options& options);
|
157
157
|
|
158
|
-
}
|
158
|
+
} // namespace leveldb
|
159
159
|
|
160
160
|
#endif // STORAGE_LEVELDB_INCLUDE_DB_H_
|
data/leveldb/port/port_android.h
CHANGED
data/leveldb/port/port_example.h
CHANGED
@@ -119,7 +119,7 @@ extern bool Snappy_Uncompress(const char* input_data, size_t input_length,
|
|
119
119
|
// The concatenation of all "data[0,n-1]" fragments is the heap profile.
|
120
120
|
extern bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg);
|
121
121
|
|
122
|
-
}
|
123
|
-
}
|
122
|
+
} // namespace port
|
123
|
+
} // namespace leveldb
|
124
124
|
|
125
125
|
#endif // STORAGE_LEVELDB_PORT_PORT_EXAMPLE_H_
|
data/leveldb/port/port_posix.cc
CHANGED
data/leveldb/port/port_posix.h
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
#ifndef STORAGE_LEVELDB_PORT_PORT_POSIX_H_
|
8
8
|
#define STORAGE_LEVELDB_PORT_PORT_POSIX_H_
|
9
9
|
|
10
|
-
#if defined(OS_MACOSX)
|
10
|
+
#if defined(OS_MACOSX)
|
11
11
|
#include <machine/endian.h>
|
12
12
|
#elif defined(OS_SOLARIS)
|
13
13
|
#include <sys/isa_defs.h>
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#else
|
17
17
|
#define BIG_ENDIAN
|
18
18
|
#endif
|
19
|
+
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
|
20
|
+
defined(OS_DRAGONFLYBSD)
|
21
|
+
#include <sys/types.h>
|
22
|
+
#include <sys/endian.h>
|
19
23
|
#else
|
20
24
|
#include <endian.h>
|
21
25
|
#endif
|
@@ -33,13 +37,17 @@
|
|
33
37
|
#define IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
|
34
38
|
#endif
|
35
39
|
|
36
|
-
#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD)
|
40
|
+
#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
|
41
|
+
defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
|
42
|
+
// Use fread/fwrite/fflush on platforms without _unlocked variants
|
37
43
|
#define fread_unlocked fread
|
38
44
|
#define fwrite_unlocked fwrite
|
39
45
|
#define fflush_unlocked fflush
|
40
46
|
#endif
|
41
47
|
|
42
|
-
#if defined(OS_MACOSX) || defined(OS_FREEBSD)
|
48
|
+
#if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\
|
49
|
+
defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
|
50
|
+
// Use fsync() on platforms without fdatasync()
|
43
51
|
#define fdatasync fsync
|
44
52
|
#endif
|
45
53
|
|
data/leveldb/table/block.cc
CHANGED