Merge commit '84d6d69fc69662b2709fffbeaf3c3b4f53c535b1'
This commit is contained in:
commit
4a9a8f3f48
6 changed files with 107 additions and 9 deletions
1
src/leveldb/.gitignore
vendored
1
src/leveldb/.gitignore
vendored
|
@ -6,6 +6,7 @@ build_config.mk
|
||||||
*.so.*
|
*.so.*
|
||||||
*_test
|
*_test
|
||||||
db_bench
|
db_bench
|
||||||
|
leveldbutil
|
||||||
Release
|
Release
|
||||||
Debug
|
Debug
|
||||||
Benchmark
|
Benchmark
|
||||||
|
|
|
@ -12,7 +12,7 @@ OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode)
|
||||||
#-----------------------------------------------
|
#-----------------------------------------------
|
||||||
|
|
||||||
# detect what platform we're building on
|
# detect what platform we're building on
|
||||||
$(shell CC=$(CC) CXX=$(CXX) TARGET_OS=$(TARGET_OS) \
|
$(shell CC="$(CC)" CXX="$(CXX)" TARGET_OS="$(TARGET_OS)" \
|
||||||
./build_detect_platform build_config.mk ./)
|
./build_detect_platform build_config.mk ./)
|
||||||
# this file is generated by the previous line to set build flags and sources
|
# this file is generated by the previous line to set build flags and sources
|
||||||
include build_config.mk
|
include build_config.mk
|
||||||
|
|
|
@ -44,6 +44,10 @@ if test -z "$CXX"; then
|
||||||
CXX=g++
|
CXX=g++
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -z "$TMPDIR"; then
|
||||||
|
TMPDIR=/tmp
|
||||||
|
fi
|
||||||
|
|
||||||
# Detect OS
|
# Detect OS
|
||||||
if test -z "$TARGET_OS"; then
|
if test -z "$TARGET_OS"; then
|
||||||
TARGET_OS=`uname -s`
|
TARGET_OS=`uname -s`
|
||||||
|
@ -169,8 +173,10 @@ if [ "$CROSS_COMPILE" = "true" ]; then
|
||||||
# Cross-compiling; do not try any compilation tests.
|
# Cross-compiling; do not try any compilation tests.
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
CXXOUTPUT="${TMPDIR}/leveldb_build_detect_platform-cxx.$$"
|
||||||
|
|
||||||
# If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
|
# If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
|
||||||
$CXX $CXXFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
|
$CXX $CXXFLAGS -std=c++0x -x c++ - -o $CXXOUTPUT 2>/dev/null <<EOF
|
||||||
#include <cstdatomic>
|
#include <cstdatomic>
|
||||||
int main() {}
|
int main() {}
|
||||||
EOF
|
EOF
|
||||||
|
@ -182,12 +188,14 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test whether tcmalloc is available
|
# Test whether tcmalloc is available
|
||||||
$CXX $CXXFLAGS -x c++ - -o /dev/null -ltcmalloc 2>/dev/null <<EOF
|
$CXX $CXXFLAGS -x c++ - -o $CXXOUTPUT -ltcmalloc 2>/dev/null <<EOF
|
||||||
int main() {}
|
int main() {}
|
||||||
EOF
|
EOF
|
||||||
if [ "$?" = 0 ]; then
|
if [ "$?" = 0 ]; then
|
||||||
PLATFORM_LIBS="$PLATFORM_LIBS -ltcmalloc"
|
PLATFORM_LIBS="$PLATFORM_LIBS -ltcmalloc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f $CXXOUTPUT 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
|
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
|
||||||
|
|
|
@ -322,7 +322,7 @@ Status DBImpl::Recover(VersionEdit* edit) {
|
||||||
if (ParseFileName(filenames[i], &number, &type)) {
|
if (ParseFileName(filenames[i], &number, &type)) {
|
||||||
expected.erase(number);
|
expected.erase(number);
|
||||||
if (type == kLogFile && ((number >= min_log) || (number == prev_log)))
|
if (type == kLogFile && ((number >= min_log) || (number == prev_log)))
|
||||||
logs.push_back(number);
|
logs.push_back(number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!expected.empty()) {
|
if (!expected.empty()) {
|
||||||
|
@ -822,9 +822,6 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
|
||||||
(unsigned long long) output_number,
|
(unsigned long long) output_number,
|
||||||
(unsigned long long) current_entries,
|
(unsigned long long) current_entries,
|
||||||
(unsigned long long) current_bytes);
|
(unsigned long long) current_bytes);
|
||||||
|
|
||||||
// rate-limit compaction file creation with a 100ms pause
|
|
||||||
env_->SleepForMicroseconds(100000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
|
92
src/leveldb/issues/issue178_test.cc
Normal file
92
src/leveldb/issues/issue178_test.cc
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
// 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 "leveldb/db.h"
|
||||||
|
#include "leveldb/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();
|
||||||
|
}
|
|
@ -66,7 +66,7 @@ class BytewiseComparatorImpl : public Comparator {
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static port::OnceType once_comparator = LEVELDB_ONCE_INIT;
|
static port::OnceType once = LEVELDB_ONCE_INIT;
|
||||||
static const Comparator* bytewise;
|
static const Comparator* bytewise;
|
||||||
|
|
||||||
static void InitModule() {
|
static void InitModule() {
|
||||||
|
@ -74,7 +74,7 @@ static void InitModule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Comparator* BytewiseComparator() {
|
const Comparator* BytewiseComparator() {
|
||||||
port::InitOnce(&once_comparator, InitModule);
|
port::InitOnce(&once, InitModule);
|
||||||
return bytewise;
|
return bytewise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue