mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
25511b7 Merge branch 'master' of github.com:rescrv/HyperLevelDB into hyperdb ed01020 Make "source" universal 3784d92 Ignore the static file 507319b Don't package with snappy 3e2cc8b Tolerate -fno-rtti 4dcdd6e Drop revision down to 1.0.dev 2542163 Drop all but the latest kept for garbage reasons 9c270b7 Update .gitignore 5331878 Add upack script adc2a7a Explicitly add -lpthread for Ubuntu 7b57bbd Strip NULL chars passed to LiveBackup e3b87e7 Add write-buffer-size option to benchmark 2f11087 Followup to snappy support with -DSNAPPY af503da Improve efficiency of ReplayIterator; fix a bug 33c1f0c Add snappy support ce1cacf Fix a race in ReplayIterator 5c4679b Fix a bug in the replay_iterator ca332bd Fix sort algorithm used for compaction boundaries. d9ec544 make checK b83a9cd Fix a deadlock in the ReplayIterator dtor 273547b Fix a double-delete in ReplayIterator 3377c7a Add "all" to set of special timestamps 387f43a Timestamp comparison and validation. f9a6eb1 make distcheck 9a4d0b7 Add a ReplayIterator. 1d53869 Conditionally enable read-driven compaction. f6fa561 16% end-to-end performance improvement from the skiplist 28ffd32 Merge remote-tracking branch 'upstream/master' a58de73 Revert "Remove read-driven compactions." e19fc0c Fix upstream issue 200 748539c LevelDB 1.13 78b7812 Add install instructions to README e47a48e Make benchmark dir variable 820a096 Update distributed files. 486ca7f Live backup of LevelDB instances 6579884 Put a reference counter on log_/logfile_ 3075253 Update internal benchmark. 2a6b0bd Make the Version a parameter of PickCompaction 5bd76dc Release leveldb 1.12 git-subtree-dir: src/hyperleveldb git-subtree-split: 25511b7a9101b0bafb57349d2194ba80ccbf7bc3
93 lines
2.5 KiB
C++
93 lines
2.5 KiB
C++
// Copyright (c) 2013 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
// Test for issue 178: a manual compaction causes deleted data to reappear.
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <cstdlib>
|
|
|
|
#include "hyperleveldb/db.h"
|
|
#include "hyperleveldb/write_batch.h"
|
|
#include "util/testharness.h"
|
|
|
|
namespace {
|
|
|
|
const int kNumKeys = 1100000;
|
|
|
|
std::string Key1(int i) {
|
|
char buf[100];
|
|
snprintf(buf, sizeof(buf), "my_key_%d", i);
|
|
return buf;
|
|
}
|
|
|
|
std::string Key2(int i) {
|
|
return Key1(i) + "_xxx";
|
|
}
|
|
|
|
class Issue178 { };
|
|
|
|
TEST(Issue178, Test) {
|
|
// Get rid of any state from an old run.
|
|
std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test";
|
|
DestroyDB(dbpath, leveldb::Options());
|
|
|
|
// Open database. Disable compression since it affects the creation
|
|
// of layers and the code below is trying to test against a very
|
|
// specific scenario.
|
|
leveldb::DB* db;
|
|
leveldb::Options db_options;
|
|
db_options.create_if_missing = true;
|
|
db_options.compression = leveldb::kNoCompression;
|
|
ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db));
|
|
|
|
// create first key range
|
|
leveldb::WriteBatch batch;
|
|
for (size_t i = 0; i < kNumKeys; i++) {
|
|
batch.Put(Key1(i), "value for range 1 key");
|
|
}
|
|
ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
|
|
|
|
// create second key range
|
|
batch.Clear();
|
|
for (size_t i = 0; i < kNumKeys; i++) {
|
|
batch.Put(Key2(i), "value for range 2 key");
|
|
}
|
|
ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
|
|
|
|
// delete second key range
|
|
batch.Clear();
|
|
for (size_t i = 0; i < kNumKeys; i++) {
|
|
batch.Delete(Key2(i));
|
|
}
|
|
ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
|
|
|
|
// compact database
|
|
std::string start_key = Key1(0);
|
|
std::string end_key = Key1(kNumKeys - 1);
|
|
leveldb::Slice least(start_key.data(), start_key.size());
|
|
leveldb::Slice greatest(end_key.data(), end_key.size());
|
|
|
|
// commenting out the line below causes the example to work correctly
|
|
db->CompactRange(&least, &greatest);
|
|
|
|
// count the keys
|
|
leveldb::Iterator* iter = db->NewIterator(leveldb::ReadOptions());
|
|
size_t num_keys = 0;
|
|
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
num_keys++;
|
|
}
|
|
delete iter;
|
|
ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys";
|
|
|
|
// close database
|
|
delete db;
|
|
DestroyDB(dbpath, leveldb::Options());
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
int main(int argc, char** argv) {
|
|
return leveldb::test::RunAllTests();
|
|
}
|