Skip to content

Commit 803d692

Browse files
committed
Release 1.18
Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue bitcoin#143 * issue bitcoin#198 * issue bitcoin#249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue bitcoin#243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue bitcoin#166 * issue bitcoin#241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue bitcoin#201)
1 parent e353fbc commit 803d692

40 files changed

+602
-282
lines changed

CONTRIBUTING.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributing
2+
3+
We'd love to accept your code patches! However, before we can take them, we
4+
have to jump a couple of legal hurdles.
5+
6+
## Contributor License Agreements
7+
8+
Please fill out either the individual or corporate Contributor License
9+
Agreement as appropriate.
10+
11+
* If you are an individual writing original source code and you're sure you
12+
own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual).
13+
* If you work for a company that wants to allow you to contribute your work,
14+
then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate).
15+
16+
Follow either of the two links above to access the appropriate CLA and
17+
instructions for how to sign and return it.
18+
19+
## Submitting a Patch
20+
21+
1. Sign the contributors license agreement above.
22+
2. Decide which code you want to submit. A submission should be a set of changes
23+
that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues).
24+
Please don't mix more than one logical change per submission, because it makes
25+
the history hard to follow. If you want to make a change
26+
(e.g. add a sample or feature) that doesn't have a corresponding issue in the
27+
issue tracker, please create one.
28+
3. **Submitting**: When you are ready to submit, send us a Pull Request. Be
29+
sure to include the issue number you fixed and the name you used to sign
30+
the CLA.
31+
32+
## Writing Code ##
33+
34+
If your contribution contains code, please make sure that it follows
35+
[the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml).
36+
Otherwise we will have to ask you to make changes, and that's no fun for anyone.

Makefile

+20-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
# Uncomment exactly one of the lines labelled (A), (B), and (C) below
77
# to switch between compilation modes.
88

9-
OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode)
10-
# OPT ?= -g2 # (B) Debug mode, w/ full line-level debugging symbols
11-
# OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols
9+
# (A) Production use (optimized mode)
10+
OPT ?= -O2 -DNDEBUG
11+
# (B) Debug mode, w/ full line-level debugging symbols
12+
# OPT ?= -g2
13+
# (C) Profiling mode: opt, but w/debugging symbols
14+
# OPT ?= -O2 -g2 -DNDEBUG
1215
#-----------------------------------------------
1316

1417
# detect what platform we're building on
@@ -29,6 +32,11 @@ MEMENVOBJECTS = $(MEMENV_SOURCES:.cc=.o)
2932
TESTUTIL = ./util/testutil.o
3033
TESTHARNESS = ./util/testharness.o $(TESTUTIL)
3134

35+
# Note: iOS should probably be using libtool, not ar.
36+
ifeq ($(PLATFORM), IOS)
37+
AR=xcrun ar
38+
endif
39+
3240
TESTS = \
3341
arena_test \
3442
autocompact_test \
@@ -43,6 +51,7 @@ TESTS = \
4351
env_test \
4452
filename_test \
4553
filter_block_test \
54+
hash_test \
4655
issue178_test \
4756
issue200_test \
4857
log_test \
@@ -72,7 +81,7 @@ SHARED = $(SHARED1)
7281
else
7382
# Update db.h if you change these.
7483
SHARED_MAJOR = 1
75-
SHARED_MINOR = 17
84+
SHARED_MINOR = 18
7685
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
7786
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
7887
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
@@ -152,6 +161,9 @@ filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS)
152161
filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS)
153162
$(CXX) $(LDFLAGS) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
154163

164+
hash_test: util/hash_test.o $(LIBOBJECTS) $(TESTHARNESS)
165+
$(CXX) $(LDFLAGS) util/hash_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
166+
155167
issue178_test: issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS)
156168
$(CXX) $(LDFLAGS) issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
157169

@@ -194,17 +206,17 @@ IOSARCH=-arch armv6 -arch armv7 -arch armv7s -arch arm64
194206

195207
.cc.o:
196208
mkdir -p ios-x86/$(dir $@)
197-
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
209+
xcrun -sdk iphonesimulator $(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
198210
mkdir -p ios-arm/$(dir $@)
199211
xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
200-
lipo ios-x86/$@ ios-arm/$@ -create -output $@
212+
xcrun lipo ios-x86/$@ ios-arm/$@ -create -output $@
201213

202214
.c.o:
203215
mkdir -p ios-x86/$(dir $@)
204-
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
216+
xcrun -sdk iphonesimulator $(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
205217
mkdir -p ios-arm/$(dir $@)
206218
xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
207-
lipo ios-x86/$@ ios-arm/$@ -create -output $@
219+
xcrun lipo ios-x86/$@ ios-arm/$@ -create -output $@
208220

209221
else
210222
.cc.o:

README.md

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
**LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.**
2+
3+
Authors: Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)
4+
5+
# Features
6+
* Keys and values are arbitrary byte arrays.
7+
* Data is stored sorted by key.
8+
* Callers can provide a custom comparison function to override the sort order.
9+
* The basic operations are `Put(key,value)`, `Get(key)`, `Delete(key)`.
10+
* Multiple changes can be made in one atomic batch.
11+
* Users can create a transient snapshot to get a consistent view of data.
12+
* Forward and backward iteration is supported over the data.
13+
* Data is automatically compressed using the [Snappy compression library](http://code.google.com/p/snappy).
14+
* External activity (file system operations etc.) is relayed through a virtual interface so users can customize the operating system interactions.
15+
* [Detailed documentation](http://htmlpreview.github.io/?https://github.com/google/leveldb/blob/master/doc/index.html) about how to use the library is included with the source code.
16+
17+
18+
# Limitations
19+
* This is not a SQL database. It does not have a relational data model, it does not support SQL queries, and it has no support for indexes.
20+
* Only a single process (possibly multi-threaded) can access a particular database at a time.
21+
* There is no client-server support builtin to the library. An application that needs such support will have to wrap their own server around the library.
22+
23+
# Performance
24+
25+
Here is a performance report (with explanations) from the run of the
26+
included db_bench program. The results are somewhat noisy, but should
27+
be enough to get a ballpark performance estimate.
28+
29+
## Setup
30+
31+
We use a database with a million entries. Each entry has a 16 byte
32+
key, and a 100 byte value. Values used by the benchmark compress to
33+
about half their original size.
34+
35+
LevelDB: version 1.1
36+
Date: Sun May 1 12:11:26 2011
37+
CPU: 4 x Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
38+
CPUCache: 4096 KB
39+
Keys: 16 bytes each
40+
Values: 100 bytes each (50 bytes after compression)
41+
Entries: 1000000
42+
Raw Size: 110.6 MB (estimated)
43+
File Size: 62.9 MB (estimated)
44+
45+
## Write performance
46+
47+
The "fill" benchmarks create a brand new database, in either
48+
sequential, or random order. The "fillsync" benchmark flushes data
49+
from the operating system to the disk after every operation; the other
50+
write operations leave the data sitting in the operating system buffer
51+
cache for a while. The "overwrite" benchmark does random writes that
52+
update existing keys in the database.
53+
54+
fillseq : 1.765 micros/op; 62.7 MB/s
55+
fillsync : 268.409 micros/op; 0.4 MB/s (10000 ops)
56+
fillrandom : 2.460 micros/op; 45.0 MB/s
57+
overwrite : 2.380 micros/op; 46.5 MB/s
58+
59+
Each "op" above corresponds to a write of a single key/value pair.
60+
I.e., a random write benchmark goes at approximately 400,000 writes per second.
61+
62+
Each "fillsync" operation costs much less (0.3 millisecond)
63+
than a disk seek (typically 10 milliseconds). We suspect that this is
64+
because the hard disk itself is buffering the update in its memory and
65+
responding before the data has been written to the platter. This may
66+
or may not be safe based on whether or not the hard disk has enough
67+
power to save its memory in the event of a power failure.
68+
69+
## Read performance
70+
71+
We list the performance of reading sequentially in both the forward
72+
and reverse direction, and also the performance of a random lookup.
73+
Note that the database created by the benchmark is quite small.
74+
Therefore the report characterizes the performance of leveldb when the
75+
working set fits in memory. The cost of reading a piece of data that
76+
is not present in the operating system buffer cache will be dominated
77+
by the one or two disk seeks needed to fetch the data from disk.
78+
Write performance will be mostly unaffected by whether or not the
79+
working set fits in memory.
80+
81+
readrandom : 16.677 micros/op; (approximately 60,000 reads per second)
82+
readseq : 0.476 micros/op; 232.3 MB/s
83+
readreverse : 0.724 micros/op; 152.9 MB/s
84+
85+
LevelDB compacts its underlying storage data in the background to
86+
improve read performance. The results listed above were done
87+
immediately after a lot of random writes. The results after
88+
compactions (which are usually triggered automatically) are better.
89+
90+
readrandom : 11.602 micros/op; (approximately 85,000 reads per second)
91+
readseq : 0.423 micros/op; 261.8 MB/s
92+
readreverse : 0.663 micros/op; 166.9 MB/s
93+
94+
Some of the high cost of reads comes from repeated decompression of blocks
95+
read from disk. If we supply enough cache to the leveldb so it can hold the
96+
uncompressed blocks in memory, the read performance improves again:
97+
98+
readrandom : 9.775 micros/op; (approximately 100,000 reads per second before compaction)
99+
readrandom : 5.215 micros/op; (approximately 190,000 reads per second after compaction)
100+
101+
## Repository contents
102+
103+
See doc/index.html for more explanation. See doc/impl.html for a brief overview of the implementation.
104+
105+
The public interface is in include/*.h. Callers should not include or
106+
rely on the details of any other header files in this package. Those
107+
internal APIs may be changed without warning.
108+
109+
Guide to header files:
110+
111+
* **include/db.h**: Main interface to the DB: Start here
112+
113+
* **include/options.h**: Control over the behavior of an entire database,
114+
and also control over the behavior of individual reads and writes.
115+
116+
* **include/comparator.h**: Abstraction for user-specified comparison function.
117+
If you want just bytewise comparison of keys, you can use the default
118+
comparator, but clients can write their own comparator implementations if they
119+
want custom ordering (e.g. to handle different character encodings, etc.)
120+
121+
* **include/iterator.h**: Interface for iterating over data. You can get
122+
an iterator from a DB object.
123+
124+
* **include/write_batch.h**: Interface for atomically applying multiple
125+
updates to a database.
126+
127+
* **include/slice.h**: A simple module for maintaining a pointer and a
128+
length into some other byte array.
129+
130+
* **include/status.h**: Status is returned from many of the public interfaces
131+
and is used to report success and various kinds of errors.
132+
133+
* **include/env.h**:
134+
Abstraction of the OS environment. A posix implementation of this interface is
135+
in util/env_posix.cc
136+
137+
* **include/table.h, include/table_builder.h**: Lower-level modules that most
138+
clients probably won't use directly

build_detect_platform

+11-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121
# The PLATFORM_CCFLAGS and PLATFORM_CXXFLAGS might include the following:
2222
#
23-
# -DLEVELDB_CSTDATOMIC_PRESENT if <cstdatomic> is present
23+
# -DLEVELDB_ATOMIC_PRESENT if <atomic> is present
2424
# -DLEVELDB_PLATFORM_POSIX for Posix-based platforms
2525
# -DSNAPPY if the Snappy library is present
2626
#
@@ -72,6 +72,12 @@ if [ "$CXX" = "g++" ]; then
7272
fi
7373

7474
case "$TARGET_OS" in
75+
CYGWIN_*)
76+
PLATFORM=OS_LINUX
77+
COMMON_FLAGS="$MEMCMP_FLAG -lpthread -DOS_LINUX -DCYGWIN"
78+
PLATFORM_LDFLAGS="-lpthread"
79+
PORT_FILE=port/port_posix.cc
80+
;;
7581
Darwin)
7682
PLATFORM=OS_MACOSX
7783
COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX"
@@ -171,13 +177,14 @@ if [ "$CROSS_COMPILE" = "true" ]; then
171177
else
172178
CXXOUTPUT="${TMPDIR}/leveldb_build_detect_platform-cxx.$$"
173179

174-
# If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
180+
# If -std=c++0x works, use <atomic> as fallback for when memory barriers
181+
# are not available.
175182
$CXX $CXXFLAGS -std=c++0x -x c++ - -o $CXXOUTPUT 2>/dev/null <<EOF
176-
#include <cstdatomic>
183+
#include <atomic>
177184
int main() {}
178185
EOF
179186
if [ "$?" = 0 ]; then
180-
COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT"
187+
COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_ATOMIC_PRESENT"
181188
PLATFORM_CXXFLAGS="-std=c++0x"
182189
else
183190
COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"

db/db_bench.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class Benchmark {
431431
benchmarks = sep + 1;
432432
}
433433

434-
// Reset parameters that may be overriddden bwlow
434+
// Reset parameters that may be overridden below
435435
num_ = FLAGS_num;
436436
reads_ = (FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads);
437437
value_size_ = FLAGS_value_size;
@@ -811,7 +811,6 @@ class Benchmark {
811811

812812
void SeekRandom(ThreadState* thread) {
813813
ReadOptions options;
814-
std::string value;
815814
int found = 0;
816815
for (int i = 0; i < reads_; i++) {
817816
Iterator* iter = db_->NewIterator(options);

db/db_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number,
392392
reporter.info_log = options_.info_log;
393393
reporter.fname = fname.c_str();
394394
reporter.status = (options_.paranoid_checks ? &status : NULL);
395-
// We intentially make log::Reader do checksumming even if
395+
// We intentionally make log::Reader do checksumming even if
396396
// paranoid_checks==false so that corruptions cause entire commits
397397
// to be skipped instead of propagating bad information (like overly
398398
// large sequence numbers).
@@ -1267,7 +1267,7 @@ WriteBatch* DBImpl::BuildBatchGroup(Writer** last_writer) {
12671267
break;
12681268
}
12691269

1270-
// Append to *reuslt
1270+
// Append to *result
12711271
if (result == first->batch) {
12721272
// Switch to temporary batch instead of disturbing caller's batch
12731273
result = tmp_batch_;

db/db_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ TEST(DBTest, GetEncountersEmptyLevel) {
626626
// * sstable B in level 2
627627
// Then do enough Get() calls to arrange for an automatic compaction
628628
// of sstable A. A bug would cause the compaction to be marked as
629-
// occuring at level 1 (instead of the correct level 0).
629+
// occurring at level 1 (instead of the correct level 0).
630630

631631
// Step 1: First place sstables in levels 0 and 2
632632
int compaction_count = 0;

db/dbformat.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file. See the AUTHORS file for names of contributors.
44

5-
#ifndef STORAGE_LEVELDB_DB_FORMAT_H_
6-
#define STORAGE_LEVELDB_DB_FORMAT_H_
5+
#ifndef STORAGE_LEVELDB_DB_DBFORMAT_H_
6+
#define STORAGE_LEVELDB_DB_DBFORMAT_H_
77

88
#include <stdio.h>
99
#include "leveldb/comparator.h"
@@ -227,4 +227,4 @@ inline LookupKey::~LookupKey() {
227227

228228
} // namespace leveldb
229229

230-
#endif // STORAGE_LEVELDB_DB_FORMAT_H_
230+
#endif // STORAGE_LEVELDB_DB_DBFORMAT_H_

0 commit comments

Comments
 (0)