Skip to content

Commit cf44e4c

Browse files
committed
Squashed 'src/leveldb/' changes from a31c8aa..196962f
196962f Add AcceleratedCRC32C to port_win.h 1bdf1c3 Merge upstream LevelDB v1.20 d31721e Merge #17: Fixed file sharing errors fecd449 Fixed file sharing error in Win32Env::GetFileSize(), Win32SequentialFile::_Init(), Win32RandomAccessFile::_Init() Fixed error checking in Win32SequentialFile::_Init() 5b7510f Merge #14: Merge upstream LevelDB 1.19 0d969fd Merge #16: [LevelDB] Do no crash if filesystem can't fsync c8c029b [LevelDB] Do no crash if filesystem can't fsync a53934a Increase leveldb version to 1.20. f3f1397 Separate Env tests from PosixEnv tests. eb4f097 leveldb: Fix compilation warnings in port_posix_sse.cc on x86 (32-bit). d0883b6 Fixed path to doc file: index.md. 7fa2094 Convert documentation to markdown. ea175e2 Implement support for Intel crc32 instruction (SSE 4.2) 95cd743 Including <limits> for std::numeric_limits. 646c358 Limit the number of read-only files the POSIX Env will have open. d40bc3f Merge #13: Typo ebbd772 Typo a2fb086 Add option for max file size. The currend hard-coded value of 2M is inefficient in colossus. git-subtree-dir: src/leveldb git-subtree-split: 196962f
1 parent 634ad51 commit cf44e4c

31 files changed

+1414
-1151
lines changed

Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ TESTS = \
4444
util/cache_test \
4545
util/coding_test \
4646
util/crc32c_test \
47+
util/env_posix_test \
4748
util/env_test \
4849
util/hash_test
4950

@@ -121,7 +122,7 @@ SHARED_MEMENVLIB = $(SHARED_OUTDIR)/libmemenv.a
121122
else
122123
# Update db.h if you change these.
123124
SHARED_VERSION_MAJOR = 1
124-
SHARED_VERSION_MINOR = 19
125+
SHARED_VERSION_MINOR = 20
125126
SHARED_LIB1 = libleveldb.$(PLATFORM_SHARED_EXT)
126127
SHARED_LIB2 = $(SHARED_LIB1).$(SHARED_VERSION_MAJOR)
127128
SHARED_LIB3 = $(SHARED_LIB1).$(SHARED_VERSION_MAJOR).$(SHARED_VERSION_MINOR)
@@ -337,6 +338,9 @@ $(STATIC_OUTDIR)/db_test:db/db_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS)
337338
$(STATIC_OUTDIR)/dbformat_test:db/dbformat_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS)
338339
$(CXX) $(LDFLAGS) $(CXXFLAGS) db/dbformat_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
339340

341+
$(STATIC_OUTDIR)/env_posix_test:util/env_posix_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS)
342+
$(CXX) $(LDFLAGS) $(CXXFLAGS) util/env_posix_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
343+
340344
$(STATIC_OUTDIR)/env_test:util/env_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS)
341345
$(CXX) $(LDFLAGS) $(CXXFLAGS) util/env_test.cc $(STATIC_LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
342346

@@ -412,3 +416,9 @@ $(SHARED_OUTDIR)/%.o: %.cc
412416

413417
$(SHARED_OUTDIR)/%.o: %.c
414418
$(CC) $(CFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@
419+
420+
$(STATIC_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc
421+
$(CXX) $(CXXFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@
422+
423+
$(SHARED_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc
424+
$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])
1616
* External activity (file system operations etc.) is relayed through a virtual interface so users can customize the operating system interactions.
1717

1818
# Documentation
19-
[LevelDB library documentation](https://rawgit.com/google/leveldb/master/doc/index.html) is online and bundled with the source code.
19+
[LevelDB library documentation](https://github.com/google/leveldb/blob/master/doc/index.md) is online and bundled with the source code.
2020

2121

2222
# Limitations
@@ -113,29 +113,30 @@ by the one or two disk seeks needed to fetch the data from disk.
113113
Write performance will be mostly unaffected by whether or not the
114114
working set fits in memory.
115115

116-
readrandom : 16.677 micros/op; (approximately 60,000 reads per second)
117-
readseq : 0.476 micros/op; 232.3 MB/s
118-
readreverse : 0.724 micros/op; 152.9 MB/s
116+
readrandom : 16.677 micros/op; (approximately 60,000 reads per second)
117+
readseq : 0.476 micros/op; 232.3 MB/s
118+
readreverse : 0.724 micros/op; 152.9 MB/s
119119

120120
LevelDB compacts its underlying storage data in the background to
121121
improve read performance. The results listed above were done
122122
immediately after a lot of random writes. The results after
123123
compactions (which are usually triggered automatically) are better.
124124

125-
readrandom : 11.602 micros/op; (approximately 85,000 reads per second)
126-
readseq : 0.423 micros/op; 261.8 MB/s
127-
readreverse : 0.663 micros/op; 166.9 MB/s
125+
readrandom : 11.602 micros/op; (approximately 85,000 reads per second)
126+
readseq : 0.423 micros/op; 261.8 MB/s
127+
readreverse : 0.663 micros/op; 166.9 MB/s
128128

129129
Some of the high cost of reads comes from repeated decompression of blocks
130130
read from disk. If we supply enough cache to the leveldb so it can hold the
131131
uncompressed blocks in memory, the read performance improves again:
132132

133-
readrandom : 9.775 micros/op; (approximately 100,000 reads per second before compaction)
134-
readrandom : 5.215 micros/op; (approximately 190,000 reads per second after compaction)
133+
readrandom : 9.775 micros/op; (approximately 100,000 reads per second before compaction)
134+
readrandom : 5.215 micros/op; (approximately 190,000 reads per second after compaction)
135135

136136
## Repository contents
137137

138-
See doc/index.html for more explanation. See doc/impl.html for a brief overview of the implementation.
138+
See [doc/index.md](doc/index.md) for more explanation. See
139+
[doc/impl.md](doc/impl.md) for a brief overview of the implementation.
139140

140141
The public interface is in include/*.h. Callers should not include or
141142
rely on the details of any other header files in this package. Those
@@ -148,7 +149,7 @@ Guide to header files:
148149
* **include/options.h**: Control over the behavior of an entire database,
149150
and also control over the behavior of individual reads and writes.
150151

151-
* **include/comparator.h**: Abstraction for user-specified comparison function.
152+
* **include/comparator.h**: Abstraction for user-specified comparison function.
152153
If you want just bytewise comparison of keys, you can use the default
153154
comparator, but clients can write their own comparator implementations if they
154155
want custom ordering (e.g. to handle different character encodings, etc.)
@@ -165,7 +166,7 @@ length into some other byte array.
165166
* **include/status.h**: Status is returned from many of the public interfaces
166167
and is used to report success and various kinds of errors.
167168

168-
* **include/env.h**:
169+
* **include/env.h**:
169170
Abstraction of the OS environment. A posix implementation of this interface is
170171
in util/env_posix.cc
171172

build_detect_platform

+29-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PLATFORM_SHARED_EXT="so"
6363
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
6464
PLATFORM_SHARED_CFLAGS="-fPIC"
6565
PLATFORM_SHARED_VERSIONED=true
66+
PLATFORM_SSEFLAGS=
6667

6768
MEMCMP_FLAG=
6869
if [ "$CXX" = "g++" ]; then
@@ -77,6 +78,7 @@ case "$TARGET_OS" in
7778
COMMON_FLAGS="$MEMCMP_FLAG -lpthread -DOS_LINUX -DCYGWIN"
7879
PLATFORM_LDFLAGS="-lpthread"
7980
PORT_FILE=port/port_posix.cc
81+
PORT_SSE_FILE=port/port_posix_sse.cc
8082
;;
8183
Darwin)
8284
PLATFORM=OS_MACOSX
@@ -85,24 +87,28 @@ case "$TARGET_OS" in
8587
[ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd`
8688
PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name $INSTALL_PATH/"
8789
PORT_FILE=port/port_posix.cc
90+
PORT_SSE_FILE=port/port_posix_sse.cc
8891
;;
8992
Linux)
9093
PLATFORM=OS_LINUX
9194
COMMON_FLAGS="$MEMCMP_FLAG -pthread -DOS_LINUX"
9295
PLATFORM_LDFLAGS="-pthread"
9396
PORT_FILE=port/port_posix.cc
97+
PORT_SSE_FILE=port/port_posix_sse.cc
9498
;;
9599
SunOS)
96100
PLATFORM=OS_SOLARIS
97101
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_SOLARIS"
98102
PLATFORM_LIBS="-lpthread -lrt"
99103
PORT_FILE=port/port_posix.cc
104+
PORT_SSE_FILE=port/port_posix_sse.cc
100105
;;
101106
FreeBSD)
102107
PLATFORM=OS_FREEBSD
103108
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_FREEBSD"
104109
PLATFORM_LIBS="-lpthread"
105110
PORT_FILE=port/port_posix.cc
111+
PORT_SSE_FILE=port/port_posix_sse.cc
106112
;;
107113
GNU/kFreeBSD)
108114
PLATFORM=OS_KFREEBSD
@@ -115,31 +121,36 @@ case "$TARGET_OS" in
115121
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD"
116122
PLATFORM_LIBS="-lpthread -lgcc_s"
117123
PORT_FILE=port/port_posix.cc
124+
PORT_SSE_FILE=port/port_posix_sse.cc
118125
;;
119126
OpenBSD)
120127
PLATFORM=OS_OPENBSD
121128
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_OPENBSD"
122129
PLATFORM_LDFLAGS="-pthread"
123130
PORT_FILE=port/port_posix.cc
131+
PORT_SSE_FILE=port/port_posix_sse.cc
124132
;;
125133
DragonFly)
126134
PLATFORM=OS_DRAGONFLYBSD
127135
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_DRAGONFLYBSD"
128136
PLATFORM_LIBS="-lpthread"
129137
PORT_FILE=port/port_posix.cc
138+
PORT_SSE_FILE=port/port_posix_sse.cc
130139
;;
131140
OS_ANDROID_CROSSCOMPILE)
132141
PLATFORM=OS_ANDROID
133142
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
134143
PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
135144
PORT_FILE=port/port_posix.cc
145+
PORT_SSE_FILE=port/port_posix_sse.cc
136146
CROSS_COMPILE=true
137147
;;
138148
HP-UX)
139149
PLATFORM=OS_HPUX
140150
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_HPUX"
141151
PLATFORM_LDFLAGS="-pthread"
142152
PORT_FILE=port/port_posix.cc
153+
PORT_SSE_FILE=port/port_posix_sse.cc
143154
# man ld: +h internal_name
144155
PLATFORM_SHARED_LDFLAGS="-shared -Wl,+h -Wl,"
145156
;;
@@ -148,6 +159,7 @@ case "$TARGET_OS" in
148159
COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX"
149160
[ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd`
150161
PORT_FILE=port/port_posix.cc
162+
PORT_SSE_FILE=port/port_posix_sse.cc
151163
PLATFORM_SHARED_EXT=
152164
PLATFORM_SHARED_LDFLAGS=
153165
PLATFORM_SHARED_CFLAGS=
@@ -182,7 +194,7 @@ set +f # re-enable globbing
182194

183195
# The sources consist of the portable files, plus the platform-specific port
184196
# file.
185-
echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> $OUTPUT
197+
echo "SOURCES=$PORTABLE_FILES $PORT_FILE $PORT_SSE_FILE" >> $OUTPUT
186198
echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
187199

188200
if [ "$CROSS_COMPILE" = "true" ]; then
@@ -213,6 +225,21 @@ EOF
213225
fi
214226

215227
rm -f $CXXOUTPUT 2>/dev/null
228+
229+
# Test if gcc SSE 4.2 is supported
230+
$CXX $CXXFLAGS -x c++ - -o $CXXOUTPUT -msse4.2 2>/dev/null <<EOF
231+
int main() {}
232+
EOF
233+
if [ "$?" = 0 ]; then
234+
PLATFORM_SSEFLAGS="-msse4.2"
235+
fi
236+
237+
rm -f $CXXOUTPUT 2>/dev/null
238+
fi
239+
240+
# Use the SSE 4.2 CRC32C intrinsics iff runtime checks indicate compiler supports them.
241+
if [ -n "$PLATFORM_SSEFLAGS" ]; then
242+
PLATFORM_SSEFLAGS="$PLATFORM_SSEFLAGS -DLEVELDB_PLATFORM_POSIX_SSE"
216243
fi
217244

218245
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
@@ -225,6 +252,7 @@ echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
225252
echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT
226253
echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
227254
echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
255+
echo "PLATFORM_SSEFLAGS=$PLATFORM_SSEFLAGS" >> $OUTPUT
228256
echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
229257
echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
230258
echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT

db/db_bench.cc

+29-9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ static bool FLAGS_histogram = false;
8484
// (initialized to default value by "main")
8585
static int FLAGS_write_buffer_size = 0;
8686

87+
// Number of bytes written to each file.
88+
// (initialized to default value by "main")
89+
static int FLAGS_max_file_size = 0;
90+
91+
// Approximate size of user data packed per block (before compression.
92+
// (initialized to default value by "main")
93+
static int FLAGS_block_size = 0;
94+
8795
// Number of bytes to use as a cache of uncompressed data.
8896
// Negative means use default settings.
8997
static int FLAGS_cache_size = -1;
@@ -109,6 +117,7 @@ static const char* FLAGS_db = NULL;
109117
namespace leveldb {
110118

111119
namespace {
120+
leveldb::Env* g_env = NULL;
112121

113122
// Helper for quickly generating random data.
114123
class RandomGenerator {
@@ -186,7 +195,7 @@ class Stats {
186195
done_ = 0;
187196
bytes_ = 0;
188197
seconds_ = 0;
189-
start_ = Env::Default()->NowMicros();
198+
start_ = g_env->NowMicros();
190199
finish_ = start_;
191200
message_.clear();
192201
}
@@ -204,7 +213,7 @@ class Stats {
204213
}
205214

206215
void Stop() {
207-
finish_ = Env::Default()->NowMicros();
216+
finish_ = g_env->NowMicros();
208217
seconds_ = (finish_ - start_) * 1e-6;
209218
}
210219

@@ -214,7 +223,7 @@ class Stats {
214223

215224
void FinishedSingleOp() {
216225
if (FLAGS_histogram) {
217-
double now = Env::Default()->NowMicros();
226+
double now = g_env->NowMicros();
218227
double micros = now - last_op_finish_;
219228
hist_.Add(micros);
220229
if (micros > 20000) {
@@ -404,10 +413,10 @@ class Benchmark {
404413
reads_(FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads),
405414
heap_counter_(0) {
406415
std::vector<std::string> files;
407-
Env::Default()->GetChildren(FLAGS_db, &files);
416+
g_env->GetChildren(FLAGS_db, &files);
408417
for (size_t i = 0; i < files.size(); i++) {
409418
if (Slice(files[i]).starts_with("heap-")) {
410-
Env::Default()->DeleteFile(std::string(FLAGS_db) + "/" + files[i]);
419+
g_env->DeleteFile(std::string(FLAGS_db) + "/" + files[i]);
411420
}
412421
}
413422
if (!FLAGS_use_existing_db) {
@@ -589,7 +598,7 @@ class Benchmark {
589598
arg[i].shared = &shared;
590599
arg[i].thread = new ThreadState(i);
591600
arg[i].thread->shared = &shared;
592-
Env::Default()->StartThread(ThreadBody, &arg[i]);
601+
g_env->StartThread(ThreadBody, &arg[i]);
593602
}
594603

595604
shared.mu.Lock();
@@ -700,9 +709,12 @@ class Benchmark {
700709
void Open() {
701710
assert(db_ == NULL);
702711
Options options;
712+
options.env = g_env;
703713
options.create_if_missing = !FLAGS_use_existing_db;
704714
options.block_cache = cache_;
705715
options.write_buffer_size = FLAGS_write_buffer_size;
716+
options.max_file_size = FLAGS_max_file_size;
717+
options.block_size = FLAGS_block_size;
706718
options.max_open_files = FLAGS_open_files;
707719
options.filter_policy = filter_policy_;
708720
options.reuse_logs = FLAGS_reuse_logs;
@@ -925,7 +937,7 @@ class Benchmark {
925937
char fname[100];
926938
snprintf(fname, sizeof(fname), "%s/heap-%04d", FLAGS_db, ++heap_counter_);
927939
WritableFile* file;
928-
Status s = Env::Default()->NewWritableFile(fname, &file);
940+
Status s = g_env->NewWritableFile(fname, &file);
929941
if (!s.ok()) {
930942
fprintf(stderr, "%s\n", s.ToString().c_str());
931943
return;
@@ -934,7 +946,7 @@ class Benchmark {
934946
delete file;
935947
if (!ok) {
936948
fprintf(stderr, "heap profiling not supported\n");
937-
Env::Default()->DeleteFile(fname);
949+
g_env->DeleteFile(fname);
938950
}
939951
}
940952
};
@@ -943,6 +955,8 @@ class Benchmark {
943955

944956
int main(int argc, char** argv) {
945957
FLAGS_write_buffer_size = leveldb::Options().write_buffer_size;
958+
FLAGS_max_file_size = leveldb::Options().max_file_size;
959+
FLAGS_block_size = leveldb::Options().block_size;
946960
FLAGS_open_files = leveldb::Options().max_open_files;
947961
std::string default_db_path;
948962

@@ -973,6 +987,10 @@ int main(int argc, char** argv) {
973987
FLAGS_value_size = n;
974988
} else if (sscanf(argv[i], "--write_buffer_size=%d%c", &n, &junk) == 1) {
975989
FLAGS_write_buffer_size = n;
990+
} else if (sscanf(argv[i], "--max_file_size=%d%c", &n, &junk) == 1) {
991+
FLAGS_max_file_size = n;
992+
} else if (sscanf(argv[i], "--block_size=%d%c", &n, &junk) == 1) {
993+
FLAGS_block_size = n;
976994
} else if (sscanf(argv[i], "--cache_size=%d%c", &n, &junk) == 1) {
977995
FLAGS_cache_size = n;
978996
} else if (sscanf(argv[i], "--bloom_bits=%d%c", &n, &junk) == 1) {
@@ -987,9 +1005,11 @@ int main(int argc, char** argv) {
9871005
}
9881006
}
9891007

1008+
leveldb::g_env = leveldb::Env::Default();
1009+
9901010
// Choose a location for the test database if none given with --db=<path>
9911011
if (FLAGS_db == NULL) {
992-
leveldb::Env::Default()->GetTestDirectory(&default_db_path);
1012+
leveldb::g_env->GetTestDirectory(&default_db_path);
9931013
default_db_path += "/dbbench";
9941014
FLAGS_db = default_db_path.c_str();
9951015
}

db/db_impl.cc

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Options SanitizeOptions(const std::string& dbname,
9696
result.filter_policy = (src.filter_policy != NULL) ? ipolicy : NULL;
9797
ClipToRange(&result.max_open_files, 64 + kNumNonTableCacheFiles, 50000);
9898
ClipToRange(&result.write_buffer_size, 64<<10, 1<<30);
99+
ClipToRange(&result.max_file_size, 1<<20, 1<<30);
99100
ClipToRange(&result.block_size, 1<<10, 4<<20);
100101
if (result.info_log == NULL) {
101102
// Open a log file in the same directory as the db

db/log_format.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file. See the AUTHORS file for names of contributors.
44
//
55
// Log format information shared by reader and writer.
6-
// See ../doc/log_format.txt for more detail.
6+
// See ../doc/log_format.md for more detail.
77

88
#ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_
99
#define STORAGE_LEVELDB_DB_LOG_FORMAT_H_

0 commit comments

Comments
 (0)