Skip to content

Commit b8cf9a2

Browse files
author
Matthew V
committed
merge google's 1.5 release
1 parent b42f727 commit b8cf9a2

20 files changed

Lines changed: 290 additions & 82 deletions

Makefile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# found in the LICENSE file. See the AUTHORS file for names of contributors.
44

55
# Inherit some settings from environment variables, if available
6-
CXX ?= g++
7-
CC ?= gcc
86
INSTALL_PATH ?= $(CURDIR)
97

108
#-----------------------------------------------
@@ -63,21 +61,31 @@ default: all
6361

6462
# Should we build shared libraries?
6563
ifneq ($(PLATFORM_SHARED_EXT),)
64+
65+
ifneq ($(PLATFORM_SHARED_VERSIONED),true)
66+
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
67+
SHARED2 = $(SHARED1)
68+
SHARED3 = $(SHARED1)
69+
SHARED = $(SHARED1)
70+
else
6671
# Update db.h if you change these.
6772
SHARED_MAJOR = 1
68-
SHARED_MINOR = 4
73+
SHARED_MINOR = 5
6974
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
7075
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
7176
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
7277
SHARED = $(SHARED1) $(SHARED2) $(SHARED3)
73-
$(SHARED3):
74-
$(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(INSTALL_PATH)/$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3)
75-
$(SHARED2): $(SHARED3)
76-
ln -fs $(SHARED3) $(SHARED2)
7778
$(SHARED1): $(SHARED3)
7879
ln -fs $(SHARED3) $(SHARED1)
80+
$(SHARED2): $(SHARED3)
81+
ln -fs $(SHARED3) $(SHARED2)
7982
endif
8083

84+
$(SHARED3):
85+
$(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3)
86+
87+
endif # PLATFORM_SHARED_EXT
88+
8189
all: $(SHARED) $(LIBRARY)
8290

8391
check: all $(PROGRAMS) $(TESTS)
@@ -164,9 +172,10 @@ memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHAR
164172
ifeq ($(PLATFORM), IOS)
165173
# For iOS, create universal object files to be used on both the simulator and
166174
# a device.
167-
SIMULATORROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
168-
DEVICEROOT=/Developer/Platforms/iPhoneOS.platform/Developer
169-
IOSVERSION=$(shell defaults read /Developer/Platforms/iPhoneOS.platform/version CFBundleShortVersionString)
175+
PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
176+
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
177+
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
178+
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
170179

171180
.cc.o:
172181
mkdir -p ios-x86/$(dir $@)

build_detect_platform

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,38 @@
44
# argument, which in turn gets read while processing Makefile.
55
#
66
# The output will set the following variables:
7+
# CC C Compiler path
8+
# CXX C++ Compiler path
79
# PLATFORM_LDFLAGS Linker flags
810
# PLATFORM_SHARED_EXT Extension for shared libraries
911
# PLATFORM_SHARED_LDFLAGS Flags for building shared library
1012
# PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library
1113
# PLATFORM_CCFLAGS C compiler flags
1214
# PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
13-
# -DLEVELDB_PLATFORM_POSIX if cstdatomic is present
14-
# -DLEVELDB_PLATFORM_NOATOMIC if it is not
15+
# PLATFORM_SHARED_VERSIONED Set to 'true' if platform supports versioned
16+
# shared libraries, empty otherwise.
17+
#
18+
# The PLATFORM_CCFLAGS and PLATFORM_CXXFLAGS might include the following:
19+
#
20+
# -DLEVELDB_CSTDATOMIC_PRESENT if <cstdatomic> is present
21+
# -DLEVELDB_PLATFORM_POSIX for Posix-based platforms
22+
# -DSNAPPY if the Snappy library is present
23+
#
1524

1625
OUTPUT=$1
1726
if test -z "$OUTPUT"; then
18-
echo "usage: $0 <output-filename>"
27+
echo "usage: $0 <output-filename>" >&2
1928
exit 1
2029
fi
2130

2231
# Delete existing output, if it exists
2332
rm -f $OUTPUT
2433
touch $OUTPUT
2534

35+
if test -z "$CC"; then
36+
CC=cc
37+
fi
38+
2639
if test -z "$CXX"; then
2740
CXX=g++
2841
fi
@@ -33,12 +46,14 @@ if test -z "$TARGET_OS"; then
3346
fi
3447

3548
COMMON_FLAGS=
49+
CROSS_COMPILE=
3650
PLATFORM_CCFLAGS=
3751
PLATFORM_CXXFLAGS=
3852
PLATFORM_LDFLAGS=
3953
PLATFORM_SHARED_EXT="so"
4054
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
4155
PLATFORM_SHARED_CFLAGS="-fPIC"
56+
PLATFORM_SHARED_VERSIONED=true
4257

4358
# On GCC, we pick libc's memcmp over GCC's memcmp via -fno-builtin-memcmp
4459
case "$TARGET_OS" in
@@ -87,13 +102,14 @@ case "$TARGET_OS" in
87102
PORT_FILE=port/port_posix.cc
88103
;;
89104
OS_ANDROID_CROSSCOMPILE)
90-
PLATFORM="$TARGET_OS"
91-
COMMON_FLAGS=""
92-
PLATFORM_LDFLAGS=""
93-
PORT_FILE=port/port_android.cc
105+
PLATFORM=OS_ANDROID
106+
COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
107+
PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
108+
PORT_FILE=port/port_posix.cc
109+
CROSS_COMPILE=true
94110
;;
95111
*)
96-
echo "Unknown platform!"
112+
echo "Unknown platform!" >&2
97113
exit 1
98114
esac
99115

@@ -113,7 +129,7 @@ set +f # re-enable globbing
113129
echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> $OUTPUT
114130
echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
115131

116-
if [ "$PLATFORM" = "OS_ANDROID_CROSSCOMPILE" ]; then
132+
if [ "$CROSS_COMPILE" = "true" ]; then
117133
# Cross-compiling; do not try any compilation tests.
118134
true
119135
else
@@ -152,10 +168,13 @@ fi
152168
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
153169
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
154170

171+
echo "CC=$CC" >> $OUTPUT
172+
echo "CXX=$CXX" >> $OUTPUT
155173
echo "PLATFORM=$PLATFORM" >> $OUTPUT
156174
echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
157175
echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
158176
echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
159177
echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
160178
echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
161179
echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
180+
echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT

db/c_test.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ static void StartPhase(const char* name) {
1919
phase = name;
2020
}
2121

22+
static const char* GetTempDir(void) {
23+
const char* ret = getenv("TEST_TMPDIR");
24+
if (ret == NULL || ret[0] == '\0')
25+
ret = "/tmp";
26+
return ret;
27+
}
28+
2229
#define CheckNoError(err) \
2330
if ((err) != NULL) { \
2431
fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, phase, (err)); \
@@ -158,7 +165,9 @@ int main(int argc, char** argv) {
158165
char* err = NULL;
159166
int run = -1;
160167

161-
snprintf(dbname, sizeof(dbname), "/tmp/leveldb_c_test-%d",
168+
snprintf(dbname, sizeof(dbname),
169+
"%s/leveldb_c_test-%d",
170+
GetTempDir(),
162171
((int) geteuid()));
163172

164173
StartPhase("create_objects");

db/db_bench.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int FLAGS_bloom_bits = -1;
100100
static bool FLAGS_use_existing_db = false;
101101

102102
// Use the db with the following name.
103-
static const char* FLAGS_db = "/tmp/dbbench";
103+
static const char* FLAGS_db = NULL;
104104

105105
namespace leveldb {
106106

@@ -925,6 +925,7 @@ class Benchmark {
925925
int main(int argc, char** argv) {
926926
FLAGS_write_buffer_size = leveldb::Options().write_buffer_size;
927927
FLAGS_open_files = leveldb::Options().max_open_files;
928+
std::string default_db_path;
928929

929930
for (int i = 1; i < argc; i++) {
930931
double d;
@@ -964,6 +965,13 @@ int main(int argc, char** argv) {
964965
}
965966
}
966967

968+
// Choose a location for the test database if none given with --db=<path>
969+
if (FLAGS_db == NULL) {
970+
leveldb::Env::Default()->GetTestDirectory(&default_db_path);
971+
default_db_path += "/dbbench";
972+
FLAGS_db = default_db_path.c_str();
973+
}
974+
967975
leveldb::Benchmark benchmark;
968976
benchmark.Run();
969977
return 0;

db/db_impl.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
8585
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
8686
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
8787
}
88-
8988
Options SanitizeOptions(const std::string& dbname,
9089
const InternalKeyComparator* icmp,
9190
const InternalFilterPolicy* ipolicy,
@@ -109,7 +108,6 @@ Options SanitizeOptions(const std::string& dbname,
109108
if (result.block_cache == NULL) {
110109
result.block_cache = NewLRUCache(8 << 20);
111110
}
112-
113111
return result;
114112
}
115113

@@ -664,8 +662,21 @@ void DBImpl::BackgroundCall() {
664662
MutexLock l(&mutex_);
665663
assert(bg_compaction_scheduled_);
666664
if (!shutting_down_.Acquire_Load()) {
667-
BackgroundCompaction();
665+
Status s = BackgroundCompaction();
666+
if (!s.ok()) {
667+
// Wait a little bit before retrying background compaction in
668+
// case this is an environmental problem and we do not want to
669+
// chew up resources for failed compactions for the duration of
670+
// the problem.
671+
bg_cv_.SignalAll(); // In case a waiter can proceed despite the error
672+
Log(options_.info_log, "Waiting after background compaction error: %s",
673+
s.ToString().c_str());
674+
mutex_.Unlock();
675+
env_->SleepForMicroseconds(1000000);
676+
mutex_.Lock();
677+
}
668678
}
679+
669680
bg_compaction_scheduled_ = false;
670681

671682
// Previous compaction may have produced too many files in a level,
@@ -674,14 +685,16 @@ void DBImpl::BackgroundCall() {
674685
bg_cv_.SignalAll();
675686
}
676687

677-
void DBImpl::BackgroundCompaction() {
688+
Status DBImpl::BackgroundCompaction() {
689+
Status status;
690+
678691
mutex_.AssertHeld();
679692

680693
if (imm_ != NULL) {
681694
pthread_rwlock_rdlock(&gThreadLock0);
682-
CompactMemTable();
695+
status=CompactMemTable();
683696
pthread_rwlock_unlock(&gThreadLock0);
684-
return;
697+
return status;
685698
}
686699

687700
Compaction* c;
@@ -704,7 +717,6 @@ void DBImpl::BackgroundCompaction() {
704717
c = versions_->PickCompaction();
705718
}
706719

707-
Status status;
708720
if (c == NULL) {
709721
// Nothing to do
710722
} else if (!is_manual && c->IsTrivialMove()) {
@@ -756,6 +768,7 @@ void DBImpl::BackgroundCompaction() {
756768
}
757769
manual_compaction_ = NULL;
758770
}
771+
return status;
759772
}
760773

761774
void DBImpl::CleanupCompaction(CompactionState* compact) {
@@ -1318,6 +1331,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
13181331
WritableFile* lfile = NULL;
13191332
s = env_->NewWritableFile(LogFileName(dbname_, new_log_number), &lfile);
13201333
if (!s.ok()) {
1334+
// Avoid chewing through file number space in a tight loop.
1335+
versions_->ReuseFileNumber(new_log_number);
13211336
break;
13221337
}
13231338
delete log_;

db/db_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class DBImpl : public DB {
9494
void MaybeScheduleCompaction();
9595
static void BGWork(void* db);
9696
void BackgroundCall();
97-
void BackgroundCompaction();
97+
Status BackgroundCompaction();
9898
void CleanupCompaction(CompactionState* compact);
9999
Status DoCompactionWork(CompactionState* compact);
100100

0 commit comments

Comments
 (0)