filiptepper-leveldb-ruby 0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +24 -0
- data/README +72 -0
- data/ext/leveldb/extconf.rb +14 -0
- data/ext/leveldb/leveldb.cc +530 -0
- data/ext/leveldb/platform.rb +83 -0
- data/leveldb/Makefile +191 -0
- data/leveldb/build_detect_platform +160 -0
- data/leveldb/db/builder.cc +88 -0
- data/leveldb/db/builder.h +34 -0
- data/leveldb/db/c.cc +581 -0
- data/leveldb/db/corruption_test.cc +359 -0
- data/leveldb/db/db_bench.cc +970 -0
- data/leveldb/db/db_impl.cc +1448 -0
- data/leveldb/db/db_impl.h +194 -0
- data/leveldb/db/db_iter.cc +299 -0
- data/leveldb/db/db_iter.h +26 -0
- data/leveldb/db/db_test.cc +1901 -0
- data/leveldb/db/dbformat.cc +140 -0
- data/leveldb/db/dbformat.h +227 -0
- data/leveldb/db/dbformat_test.cc +112 -0
- data/leveldb/db/filename.cc +139 -0
- data/leveldb/db/filename.h +80 -0
- data/leveldb/db/filename_test.cc +122 -0
- data/leveldb/db/log_format.h +35 -0
- data/leveldb/db/log_reader.cc +259 -0
- data/leveldb/db/log_reader.h +108 -0
- data/leveldb/db/log_test.cc +500 -0
- data/leveldb/db/log_writer.cc +103 -0
- data/leveldb/db/log_writer.h +48 -0
- data/leveldb/db/memtable.cc +145 -0
- data/leveldb/db/memtable.h +91 -0
- data/leveldb/db/repair.cc +389 -0
- data/leveldb/db/skiplist.h +379 -0
- data/leveldb/db/skiplist_test.cc +378 -0
- data/leveldb/db/snapshot.h +66 -0
- data/leveldb/db/table_cache.cc +121 -0
- data/leveldb/db/table_cache.h +61 -0
- data/leveldb/db/version_edit.cc +266 -0
- data/leveldb/db/version_edit.h +107 -0
- data/leveldb/db/version_edit_test.cc +46 -0
- data/leveldb/db/version_set.cc +1402 -0
- data/leveldb/db/version_set.h +370 -0
- data/leveldb/db/version_set_test.cc +179 -0
- data/leveldb/db/write_batch.cc +147 -0
- data/leveldb/db/write_batch_internal.h +49 -0
- data/leveldb/db/write_batch_test.cc +120 -0
- 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/c.h +275 -0
- data/leveldb/include/leveldb/cache.h +99 -0
- data/leveldb/include/leveldb/comparator.h +63 -0
- data/leveldb/include/leveldb/db.h +161 -0
- data/leveldb/include/leveldb/env.h +323 -0
- data/leveldb/include/leveldb/filter_policy.h +70 -0
- data/leveldb/include/leveldb/iterator.h +100 -0
- data/leveldb/include/leveldb/options.h +195 -0
- data/leveldb/include/leveldb/slice.h +109 -0
- data/leveldb/include/leveldb/status.h +106 -0
- data/leveldb/include/leveldb/table.h +85 -0
- data/leveldb/include/leveldb/table_builder.h +92 -0
- data/leveldb/include/leveldb/write_batch.h +64 -0
- data/leveldb/port/atomic_pointer.h +144 -0
- data/leveldb/port/port.h +21 -0
- data/leveldb/port/port_android.cc +64 -0
- data/leveldb/port/port_android.h +159 -0
- data/leveldb/port/port_example.h +125 -0
- data/leveldb/port/port_posix.cc +50 -0
- data/leveldb/port/port_posix.h +129 -0
- data/leveldb/port/win/stdint.h +24 -0
- data/leveldb/table/block.cc +267 -0
- data/leveldb/table/block.h +44 -0
- data/leveldb/table/block_builder.cc +109 -0
- data/leveldb/table/block_builder.h +57 -0
- data/leveldb/table/filter_block.cc +111 -0
- data/leveldb/table/filter_block.h +68 -0
- data/leveldb/table/filter_block_test.cc +128 -0
- data/leveldb/table/format.cc +145 -0
- data/leveldb/table/format.h +108 -0
- data/leveldb/table/iterator.cc +67 -0
- data/leveldb/table/iterator_wrapper.h +63 -0
- data/leveldb/table/merger.cc +197 -0
- data/leveldb/table/merger.h +26 -0
- data/leveldb/table/table.cc +276 -0
- data/leveldb/table/table_builder.cc +270 -0
- data/leveldb/table/table_test.cc +838 -0
- data/leveldb/table/two_level_iterator.cc +182 -0
- data/leveldb/table/two_level_iterator.h +34 -0
- data/leveldb/util/arena.cc +68 -0
- data/leveldb/util/arena.h +68 -0
- data/leveldb/util/arena_test.cc +68 -0
- data/leveldb/util/bloom.cc +95 -0
- data/leveldb/util/bloom_test.cc +159 -0
- data/leveldb/util/cache.cc +328 -0
- data/leveldb/util/cache_test.cc +186 -0
- data/leveldb/util/coding.cc +194 -0
- data/leveldb/util/coding.h +104 -0
- data/leveldb/util/coding_test.cc +173 -0
- data/leveldb/util/comparator.cc +76 -0
- data/leveldb/util/crc32c.cc +332 -0
- data/leveldb/util/crc32c.h +45 -0
- data/leveldb/util/crc32c_test.cc +72 -0
- data/leveldb/util/env.cc +96 -0
- data/leveldb/util/env_posix.cc +609 -0
- data/leveldb/util/env_test.cc +104 -0
- data/leveldb/util/filter_policy.cc +11 -0
- data/leveldb/util/hash.cc +45 -0
- data/leveldb/util/hash.h +19 -0
- data/leveldb/util/histogram.cc +139 -0
- data/leveldb/util/histogram.h +42 -0
- data/leveldb/util/logging.cc +81 -0
- data/leveldb/util/logging.h +47 -0
- data/leveldb/util/mutexlock.h +39 -0
- data/leveldb/util/options.cc +29 -0
- data/leveldb/util/posix_logger.h +98 -0
- data/leveldb/util/random.h +59 -0
- data/leveldb/util/status.cc +75 -0
- data/leveldb/util/testharness.cc +77 -0
- data/leveldb/util/testharness.h +138 -0
- data/leveldb/util/testutil.cc +51 -0
- data/leveldb/util/testutil.h +53 -0
- data/lib/leveldb.rb +76 -0
- metadata +175 -0
@@ -0,0 +1,66 @@
|
|
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_DB_SNAPSHOT_H_
|
6
|
+
#define STORAGE_LEVELDB_DB_SNAPSHOT_H_
|
7
|
+
|
8
|
+
#include "leveldb/db.h"
|
9
|
+
|
10
|
+
namespace leveldb {
|
11
|
+
|
12
|
+
class SnapshotList;
|
13
|
+
|
14
|
+
// Snapshots are kept in a doubly-linked list in the DB.
|
15
|
+
// Each SnapshotImpl corresponds to a particular sequence number.
|
16
|
+
class SnapshotImpl : public Snapshot {
|
17
|
+
public:
|
18
|
+
SequenceNumber number_; // const after creation
|
19
|
+
|
20
|
+
private:
|
21
|
+
friend class SnapshotList;
|
22
|
+
|
23
|
+
// SnapshotImpl is kept in a doubly-linked circular list
|
24
|
+
SnapshotImpl* prev_;
|
25
|
+
SnapshotImpl* next_;
|
26
|
+
|
27
|
+
SnapshotList* list_; // just for sanity checks
|
28
|
+
};
|
29
|
+
|
30
|
+
class SnapshotList {
|
31
|
+
public:
|
32
|
+
SnapshotList() {
|
33
|
+
list_.prev_ = &list_;
|
34
|
+
list_.next_ = &list_;
|
35
|
+
}
|
36
|
+
|
37
|
+
bool empty() const { return list_.next_ == &list_; }
|
38
|
+
SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
|
39
|
+
SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
|
40
|
+
|
41
|
+
const SnapshotImpl* New(SequenceNumber seq) {
|
42
|
+
SnapshotImpl* s = new SnapshotImpl;
|
43
|
+
s->number_ = seq;
|
44
|
+
s->list_ = this;
|
45
|
+
s->next_ = &list_;
|
46
|
+
s->prev_ = list_.prev_;
|
47
|
+
s->prev_->next_ = s;
|
48
|
+
s->next_->prev_ = s;
|
49
|
+
return s;
|
50
|
+
}
|
51
|
+
|
52
|
+
void Delete(const SnapshotImpl* s) {
|
53
|
+
assert(s->list_ == this);
|
54
|
+
s->prev_->next_ = s->next_;
|
55
|
+
s->next_->prev_ = s->prev_;
|
56
|
+
delete s;
|
57
|
+
}
|
58
|
+
|
59
|
+
private:
|
60
|
+
// Dummy head of doubly-linked list of snapshots
|
61
|
+
SnapshotImpl list_;
|
62
|
+
};
|
63
|
+
|
64
|
+
} // namespace leveldb
|
65
|
+
|
66
|
+
#endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
|
@@ -0,0 +1,121 @@
|
|
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 "db/table_cache.h"
|
6
|
+
|
7
|
+
#include "db/filename.h"
|
8
|
+
#include "leveldb/env.h"
|
9
|
+
#include "leveldb/table.h"
|
10
|
+
#include "util/coding.h"
|
11
|
+
|
12
|
+
namespace leveldb {
|
13
|
+
|
14
|
+
struct TableAndFile {
|
15
|
+
RandomAccessFile* file;
|
16
|
+
Table* table;
|
17
|
+
};
|
18
|
+
|
19
|
+
static void DeleteEntry(const Slice& key, void* value) {
|
20
|
+
TableAndFile* tf = reinterpret_cast<TableAndFile*>(value);
|
21
|
+
delete tf->table;
|
22
|
+
delete tf->file;
|
23
|
+
delete tf;
|
24
|
+
}
|
25
|
+
|
26
|
+
static void UnrefEntry(void* arg1, void* arg2) {
|
27
|
+
Cache* cache = reinterpret_cast<Cache*>(arg1);
|
28
|
+
Cache::Handle* h = reinterpret_cast<Cache::Handle*>(arg2);
|
29
|
+
cache->Release(h);
|
30
|
+
}
|
31
|
+
|
32
|
+
TableCache::TableCache(const std::string& dbname,
|
33
|
+
const Options* options,
|
34
|
+
int entries)
|
35
|
+
: env_(options->env),
|
36
|
+
dbname_(dbname),
|
37
|
+
options_(options),
|
38
|
+
cache_(NewLRUCache(entries)) {
|
39
|
+
}
|
40
|
+
|
41
|
+
TableCache::~TableCache() {
|
42
|
+
delete cache_;
|
43
|
+
}
|
44
|
+
|
45
|
+
Status TableCache::FindTable(uint64_t file_number, uint64_t file_size,
|
46
|
+
Cache::Handle** handle) {
|
47
|
+
Status s;
|
48
|
+
char buf[sizeof(file_number)];
|
49
|
+
EncodeFixed64(buf, file_number);
|
50
|
+
Slice key(buf, sizeof(buf));
|
51
|
+
*handle = cache_->Lookup(key);
|
52
|
+
if (*handle == NULL) {
|
53
|
+
std::string fname = TableFileName(dbname_, file_number);
|
54
|
+
RandomAccessFile* file = NULL;
|
55
|
+
Table* table = NULL;
|
56
|
+
s = env_->NewRandomAccessFile(fname, &file);
|
57
|
+
if (s.ok()) {
|
58
|
+
s = Table::Open(*options_, file, file_size, &table);
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!s.ok()) {
|
62
|
+
assert(table == NULL);
|
63
|
+
delete file;
|
64
|
+
// We do not cache error results so that if the error is transient,
|
65
|
+
// or somebody repairs the file, we recover automatically.
|
66
|
+
} else {
|
67
|
+
TableAndFile* tf = new TableAndFile;
|
68
|
+
tf->file = file;
|
69
|
+
tf->table = table;
|
70
|
+
*handle = cache_->Insert(key, tf, 1, &DeleteEntry);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return s;
|
74
|
+
}
|
75
|
+
|
76
|
+
Iterator* TableCache::NewIterator(const ReadOptions& options,
|
77
|
+
uint64_t file_number,
|
78
|
+
uint64_t file_size,
|
79
|
+
Table** tableptr) {
|
80
|
+
if (tableptr != NULL) {
|
81
|
+
*tableptr = NULL;
|
82
|
+
}
|
83
|
+
|
84
|
+
Cache::Handle* handle = NULL;
|
85
|
+
Status s = FindTable(file_number, file_size, &handle);
|
86
|
+
if (!s.ok()) {
|
87
|
+
return NewErrorIterator(s);
|
88
|
+
}
|
89
|
+
|
90
|
+
Table* table = reinterpret_cast<TableAndFile*>(cache_->Value(handle))->table;
|
91
|
+
Iterator* result = table->NewIterator(options);
|
92
|
+
result->RegisterCleanup(&UnrefEntry, cache_, handle);
|
93
|
+
if (tableptr != NULL) {
|
94
|
+
*tableptr = table;
|
95
|
+
}
|
96
|
+
return result;
|
97
|
+
}
|
98
|
+
|
99
|
+
Status TableCache::Get(const ReadOptions& options,
|
100
|
+
uint64_t file_number,
|
101
|
+
uint64_t file_size,
|
102
|
+
const Slice& k,
|
103
|
+
void* arg,
|
104
|
+
void (*saver)(void*, const Slice&, const Slice&)) {
|
105
|
+
Cache::Handle* handle = NULL;
|
106
|
+
Status s = FindTable(file_number, file_size, &handle);
|
107
|
+
if (s.ok()) {
|
108
|
+
Table* t = reinterpret_cast<TableAndFile*>(cache_->Value(handle))->table;
|
109
|
+
s = t->InternalGet(options, k, arg, saver);
|
110
|
+
cache_->Release(handle);
|
111
|
+
}
|
112
|
+
return s;
|
113
|
+
}
|
114
|
+
|
115
|
+
void TableCache::Evict(uint64_t file_number) {
|
116
|
+
char buf[sizeof(file_number)];
|
117
|
+
EncodeFixed64(buf, file_number);
|
118
|
+
cache_->Erase(Slice(buf, sizeof(buf)));
|
119
|
+
}
|
120
|
+
|
121
|
+
} // namespace leveldb
|
@@ -0,0 +1,61 @@
|
|
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
|
+
// Thread-safe (provides internal synchronization)
|
6
|
+
|
7
|
+
#ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_
|
8
|
+
#define STORAGE_LEVELDB_DB_TABLE_CACHE_H_
|
9
|
+
|
10
|
+
#include <string>
|
11
|
+
#include <stdint.h>
|
12
|
+
#include "db/dbformat.h"
|
13
|
+
#include "leveldb/cache.h"
|
14
|
+
#include "leveldb/table.h"
|
15
|
+
#include "port/port.h"
|
16
|
+
|
17
|
+
namespace leveldb {
|
18
|
+
|
19
|
+
class Env;
|
20
|
+
|
21
|
+
class TableCache {
|
22
|
+
public:
|
23
|
+
TableCache(const std::string& dbname, const Options* options, int entries);
|
24
|
+
~TableCache();
|
25
|
+
|
26
|
+
// Return an iterator for the specified file number (the corresponding
|
27
|
+
// file length must be exactly "file_size" bytes). If "tableptr" is
|
28
|
+
// non-NULL, also sets "*tableptr" to point to the Table object
|
29
|
+
// underlying the returned iterator, or NULL if no Table object underlies
|
30
|
+
// the returned iterator. The returned "*tableptr" object is owned by
|
31
|
+
// the cache and should not be deleted, and is valid for as long as the
|
32
|
+
// returned iterator is live.
|
33
|
+
Iterator* NewIterator(const ReadOptions& options,
|
34
|
+
uint64_t file_number,
|
35
|
+
uint64_t file_size,
|
36
|
+
Table** tableptr = NULL);
|
37
|
+
|
38
|
+
// If a seek to internal key "k" in specified file finds an entry,
|
39
|
+
// call (*handle_result)(arg, found_key, found_value).
|
40
|
+
Status Get(const ReadOptions& options,
|
41
|
+
uint64_t file_number,
|
42
|
+
uint64_t file_size,
|
43
|
+
const Slice& k,
|
44
|
+
void* arg,
|
45
|
+
void (*handle_result)(void*, const Slice&, const Slice&));
|
46
|
+
|
47
|
+
// Evict any entry for the specified file number
|
48
|
+
void Evict(uint64_t file_number);
|
49
|
+
|
50
|
+
private:
|
51
|
+
Env* const env_;
|
52
|
+
const std::string dbname_;
|
53
|
+
const Options* options_;
|
54
|
+
Cache* cache_;
|
55
|
+
|
56
|
+
Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**);
|
57
|
+
};
|
58
|
+
|
59
|
+
} // namespace leveldb
|
60
|
+
|
61
|
+
#endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_
|
@@ -0,0 +1,266 @@
|
|
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 "db/version_edit.h"
|
6
|
+
|
7
|
+
#include "db/version_set.h"
|
8
|
+
#include "util/coding.h"
|
9
|
+
|
10
|
+
namespace leveldb {
|
11
|
+
|
12
|
+
// Tag numbers for serialized VersionEdit. These numbers are written to
|
13
|
+
// disk and should not be changed.
|
14
|
+
enum Tag {
|
15
|
+
kComparator = 1,
|
16
|
+
kLogNumber = 2,
|
17
|
+
kNextFileNumber = 3,
|
18
|
+
kLastSequence = 4,
|
19
|
+
kCompactPointer = 5,
|
20
|
+
kDeletedFile = 6,
|
21
|
+
kNewFile = 7,
|
22
|
+
// 8 was used for large value refs
|
23
|
+
kPrevLogNumber = 9
|
24
|
+
};
|
25
|
+
|
26
|
+
void VersionEdit::Clear() {
|
27
|
+
comparator_.clear();
|
28
|
+
log_number_ = 0;
|
29
|
+
prev_log_number_ = 0;
|
30
|
+
last_sequence_ = 0;
|
31
|
+
next_file_number_ = 0;
|
32
|
+
has_comparator_ = false;
|
33
|
+
has_log_number_ = false;
|
34
|
+
has_prev_log_number_ = false;
|
35
|
+
has_next_file_number_ = false;
|
36
|
+
has_last_sequence_ = false;
|
37
|
+
deleted_files_.clear();
|
38
|
+
new_files_.clear();
|
39
|
+
}
|
40
|
+
|
41
|
+
void VersionEdit::EncodeTo(std::string* dst) const {
|
42
|
+
if (has_comparator_) {
|
43
|
+
PutVarint32(dst, kComparator);
|
44
|
+
PutLengthPrefixedSlice(dst, comparator_);
|
45
|
+
}
|
46
|
+
if (has_log_number_) {
|
47
|
+
PutVarint32(dst, kLogNumber);
|
48
|
+
PutVarint64(dst, log_number_);
|
49
|
+
}
|
50
|
+
if (has_prev_log_number_) {
|
51
|
+
PutVarint32(dst, kPrevLogNumber);
|
52
|
+
PutVarint64(dst, prev_log_number_);
|
53
|
+
}
|
54
|
+
if (has_next_file_number_) {
|
55
|
+
PutVarint32(dst, kNextFileNumber);
|
56
|
+
PutVarint64(dst, next_file_number_);
|
57
|
+
}
|
58
|
+
if (has_last_sequence_) {
|
59
|
+
PutVarint32(dst, kLastSequence);
|
60
|
+
PutVarint64(dst, last_sequence_);
|
61
|
+
}
|
62
|
+
|
63
|
+
for (size_t i = 0; i < compact_pointers_.size(); i++) {
|
64
|
+
PutVarint32(dst, kCompactPointer);
|
65
|
+
PutVarint32(dst, compact_pointers_[i].first); // level
|
66
|
+
PutLengthPrefixedSlice(dst, compact_pointers_[i].second.Encode());
|
67
|
+
}
|
68
|
+
|
69
|
+
for (DeletedFileSet::const_iterator iter = deleted_files_.begin();
|
70
|
+
iter != deleted_files_.end();
|
71
|
+
++iter) {
|
72
|
+
PutVarint32(dst, kDeletedFile);
|
73
|
+
PutVarint32(dst, iter->first); // level
|
74
|
+
PutVarint64(dst, iter->second); // file number
|
75
|
+
}
|
76
|
+
|
77
|
+
for (size_t i = 0; i < new_files_.size(); i++) {
|
78
|
+
const FileMetaData& f = new_files_[i].second;
|
79
|
+
PutVarint32(dst, kNewFile);
|
80
|
+
PutVarint32(dst, new_files_[i].first); // level
|
81
|
+
PutVarint64(dst, f.number);
|
82
|
+
PutVarint64(dst, f.file_size);
|
83
|
+
PutLengthPrefixedSlice(dst, f.smallest.Encode());
|
84
|
+
PutLengthPrefixedSlice(dst, f.largest.Encode());
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
static bool GetInternalKey(Slice* input, InternalKey* dst) {
|
89
|
+
Slice str;
|
90
|
+
if (GetLengthPrefixedSlice(input, &str)) {
|
91
|
+
dst->DecodeFrom(str);
|
92
|
+
return true;
|
93
|
+
} else {
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
static bool GetLevel(Slice* input, int* level) {
|
99
|
+
uint32_t v;
|
100
|
+
if (GetVarint32(input, &v) &&
|
101
|
+
v < config::kNumLevels) {
|
102
|
+
*level = v;
|
103
|
+
return true;
|
104
|
+
} else {
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
Status VersionEdit::DecodeFrom(const Slice& src) {
|
110
|
+
Clear();
|
111
|
+
Slice input = src;
|
112
|
+
const char* msg = NULL;
|
113
|
+
uint32_t tag;
|
114
|
+
|
115
|
+
// Temporary storage for parsing
|
116
|
+
int level;
|
117
|
+
uint64_t number;
|
118
|
+
FileMetaData f;
|
119
|
+
Slice str;
|
120
|
+
InternalKey key;
|
121
|
+
|
122
|
+
while (msg == NULL && GetVarint32(&input, &tag)) {
|
123
|
+
switch (tag) {
|
124
|
+
case kComparator:
|
125
|
+
if (GetLengthPrefixedSlice(&input, &str)) {
|
126
|
+
comparator_ = str.ToString();
|
127
|
+
has_comparator_ = true;
|
128
|
+
} else {
|
129
|
+
msg = "comparator name";
|
130
|
+
}
|
131
|
+
break;
|
132
|
+
|
133
|
+
case kLogNumber:
|
134
|
+
if (GetVarint64(&input, &log_number_)) {
|
135
|
+
has_log_number_ = true;
|
136
|
+
} else {
|
137
|
+
msg = "log number";
|
138
|
+
}
|
139
|
+
break;
|
140
|
+
|
141
|
+
case kPrevLogNumber:
|
142
|
+
if (GetVarint64(&input, &prev_log_number_)) {
|
143
|
+
has_prev_log_number_ = true;
|
144
|
+
} else {
|
145
|
+
msg = "previous log number";
|
146
|
+
}
|
147
|
+
break;
|
148
|
+
|
149
|
+
case kNextFileNumber:
|
150
|
+
if (GetVarint64(&input, &next_file_number_)) {
|
151
|
+
has_next_file_number_ = true;
|
152
|
+
} else {
|
153
|
+
msg = "next file number";
|
154
|
+
}
|
155
|
+
break;
|
156
|
+
|
157
|
+
case kLastSequence:
|
158
|
+
if (GetVarint64(&input, &last_sequence_)) {
|
159
|
+
has_last_sequence_ = true;
|
160
|
+
} else {
|
161
|
+
msg = "last sequence number";
|
162
|
+
}
|
163
|
+
break;
|
164
|
+
|
165
|
+
case kCompactPointer:
|
166
|
+
if (GetLevel(&input, &level) &&
|
167
|
+
GetInternalKey(&input, &key)) {
|
168
|
+
compact_pointers_.push_back(std::make_pair(level, key));
|
169
|
+
} else {
|
170
|
+
msg = "compaction pointer";
|
171
|
+
}
|
172
|
+
break;
|
173
|
+
|
174
|
+
case kDeletedFile:
|
175
|
+
if (GetLevel(&input, &level) &&
|
176
|
+
GetVarint64(&input, &number)) {
|
177
|
+
deleted_files_.insert(std::make_pair(level, number));
|
178
|
+
} else {
|
179
|
+
msg = "deleted file";
|
180
|
+
}
|
181
|
+
break;
|
182
|
+
|
183
|
+
case kNewFile:
|
184
|
+
if (GetLevel(&input, &level) &&
|
185
|
+
GetVarint64(&input, &f.number) &&
|
186
|
+
GetVarint64(&input, &f.file_size) &&
|
187
|
+
GetInternalKey(&input, &f.smallest) &&
|
188
|
+
GetInternalKey(&input, &f.largest)) {
|
189
|
+
new_files_.push_back(std::make_pair(level, f));
|
190
|
+
} else {
|
191
|
+
msg = "new-file entry";
|
192
|
+
}
|
193
|
+
break;
|
194
|
+
|
195
|
+
default:
|
196
|
+
msg = "unknown tag";
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
if (msg == NULL && !input.empty()) {
|
202
|
+
msg = "invalid tag";
|
203
|
+
}
|
204
|
+
|
205
|
+
Status result;
|
206
|
+
if (msg != NULL) {
|
207
|
+
result = Status::Corruption("VersionEdit", msg);
|
208
|
+
}
|
209
|
+
return result;
|
210
|
+
}
|
211
|
+
|
212
|
+
std::string VersionEdit::DebugString() const {
|
213
|
+
std::string r;
|
214
|
+
r.append("VersionEdit {");
|
215
|
+
if (has_comparator_) {
|
216
|
+
r.append("\n Comparator: ");
|
217
|
+
r.append(comparator_);
|
218
|
+
}
|
219
|
+
if (has_log_number_) {
|
220
|
+
r.append("\n LogNumber: ");
|
221
|
+
AppendNumberTo(&r, log_number_);
|
222
|
+
}
|
223
|
+
if (has_prev_log_number_) {
|
224
|
+
r.append("\n PrevLogNumber: ");
|
225
|
+
AppendNumberTo(&r, prev_log_number_);
|
226
|
+
}
|
227
|
+
if (has_next_file_number_) {
|
228
|
+
r.append("\n NextFile: ");
|
229
|
+
AppendNumberTo(&r, next_file_number_);
|
230
|
+
}
|
231
|
+
if (has_last_sequence_) {
|
232
|
+
r.append("\n LastSeq: ");
|
233
|
+
AppendNumberTo(&r, last_sequence_);
|
234
|
+
}
|
235
|
+
for (size_t i = 0; i < compact_pointers_.size(); i++) {
|
236
|
+
r.append("\n CompactPointer: ");
|
237
|
+
AppendNumberTo(&r, compact_pointers_[i].first);
|
238
|
+
r.append(" ");
|
239
|
+
r.append(compact_pointers_[i].second.DebugString());
|
240
|
+
}
|
241
|
+
for (DeletedFileSet::const_iterator iter = deleted_files_.begin();
|
242
|
+
iter != deleted_files_.end();
|
243
|
+
++iter) {
|
244
|
+
r.append("\n DeleteFile: ");
|
245
|
+
AppendNumberTo(&r, iter->first);
|
246
|
+
r.append(" ");
|
247
|
+
AppendNumberTo(&r, iter->second);
|
248
|
+
}
|
249
|
+
for (size_t i = 0; i < new_files_.size(); i++) {
|
250
|
+
const FileMetaData& f = new_files_[i].second;
|
251
|
+
r.append("\n AddFile: ");
|
252
|
+
AppendNumberTo(&r, new_files_[i].first);
|
253
|
+
r.append(" ");
|
254
|
+
AppendNumberTo(&r, f.number);
|
255
|
+
r.append(" ");
|
256
|
+
AppendNumberTo(&r, f.file_size);
|
257
|
+
r.append(" ");
|
258
|
+
r.append(f.smallest.DebugString());
|
259
|
+
r.append(" .. ");
|
260
|
+
r.append(f.largest.DebugString());
|
261
|
+
}
|
262
|
+
r.append("\n}\n");
|
263
|
+
return r;
|
264
|
+
}
|
265
|
+
|
266
|
+
} // namespace leveldb
|