Skip to content

Commit c25e981

Browse files
committed
Squashed 'src/leveldb/' content from commit aca1ffc
git-subtree-dir: src/leveldb git-subtree-split: aca1ffc4b65be5e099b2088c6e6a308d69e1ad73
0 parents  commit c25e981

File tree

136 files changed

+27582
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+27582
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
build_config.mk
2+
*.a
3+
*.o
4+
*.dylib*
5+
*.so
6+
*.so.*
7+
*_test
8+
db_bench
9+
Release
10+
Debug
11+
Benchmark
12+
vs2010.*

AUTHORS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Names should be added to this file like so:
2+
# Name or Organization <email address>
3+
4+
Google Inc.
5+
6+
# Initial version authors:
7+
Jeffrey Dean <[email protected]>
8+
Sanjay Ghemawat <[email protected]>

LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file. See the AUTHORS file for names of contributors.
4+
5+
#-----------------------------------------------
6+
# Uncomment exactly one of the lines labelled (A), (B), and (C) below
7+
# to switch between compilation modes.
8+
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
12+
#-----------------------------------------------
13+
14+
# detect what platform we're building on
15+
$(shell CC=$(CC) CXX=$(CXX) TARGET_OS=$(TARGET_OS) \
16+
./build_detect_platform build_config.mk ./)
17+
# this file is generated by the previous line to set build flags and sources
18+
include build_config.mk
19+
20+
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
21+
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
22+
23+
LDFLAGS += $(PLATFORM_LDFLAGS)
24+
LIBS += $(PLATFORM_LIBS)
25+
26+
LIBOBJECTS = $(SOURCES:.cc=.o)
27+
MEMENVOBJECTS = $(MEMENV_SOURCES:.cc=.o)
28+
29+
TESTUTIL = ./util/testutil.o
30+
TESTHARNESS = ./util/testharness.o $(TESTUTIL)
31+
32+
TESTS = \
33+
arena_test \
34+
bloom_test \
35+
c_test \
36+
cache_test \
37+
coding_test \
38+
corruption_test \
39+
crc32c_test \
40+
db_test \
41+
dbformat_test \
42+
env_test \
43+
filename_test \
44+
filter_block_test \
45+
log_test \
46+
memenv_test \
47+
skiplist_test \
48+
table_test \
49+
version_edit_test \
50+
version_set_test \
51+
write_batch_test
52+
53+
PROGRAMS = db_bench leveldbutil $(TESTS)
54+
BENCHMARKS = db_bench_sqlite3 db_bench_tree_db
55+
56+
LIBRARY = libleveldb.a
57+
MEMENVLIBRARY = libmemenv.a
58+
59+
default: all
60+
61+
# Should we build shared libraries?
62+
ifneq ($(PLATFORM_SHARED_EXT),)
63+
64+
ifneq ($(PLATFORM_SHARED_VERSIONED),true)
65+
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
66+
SHARED2 = $(SHARED1)
67+
SHARED3 = $(SHARED1)
68+
SHARED = $(SHARED1)
69+
else
70+
# Update db.h if you change these.
71+
SHARED_MAJOR = 1
72+
SHARED_MINOR = 9
73+
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
74+
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
75+
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
76+
SHARED = $(SHARED1) $(SHARED2) $(SHARED3)
77+
$(SHARED1): $(SHARED3)
78+
ln -fs $(SHARED3) $(SHARED1)
79+
$(SHARED2): $(SHARED3)
80+
ln -fs $(SHARED3) $(SHARED2)
81+
endif
82+
83+
$(SHARED3):
84+
$(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3) $(LIBS)
85+
86+
endif # PLATFORM_SHARED_EXT
87+
88+
all: $(SHARED) $(LIBRARY)
89+
90+
check: all $(PROGRAMS) $(TESTS)
91+
for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
92+
93+
clean:
94+
-rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk
95+
-rm -rf ios-x86/* ios-arm/*
96+
97+
$(LIBRARY): $(LIBOBJECTS)
98+
rm -f $@
99+
$(AR) -rs $@ $(LIBOBJECTS)
100+
101+
db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL)
102+
$(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LIBS)
103+
104+
db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL)
105+
$(CXX) $(LDFLAGS) doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lsqlite3 $(LIBS)
106+
107+
db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL)
108+
$(CXX) $(LDFLAGS) doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lkyotocabinet $(LIBS)
109+
110+
leveldbutil: db/leveldb_main.o $(LIBOBJECTS)
111+
$(CXX) $(LDFLAGS) db/leveldb_main.o $(LIBOBJECTS) -o $@ $(LIBS)
112+
113+
arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS)
114+
$(CXX) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
115+
116+
bloom_test: util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS)
117+
$(CXX) $(LDFLAGS) util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
118+
119+
c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS)
120+
$(CXX) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
121+
122+
cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS)
123+
$(CXX) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
124+
125+
coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS)
126+
$(CXX) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
127+
128+
corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS)
129+
$(CXX) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
130+
131+
crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS)
132+
$(CXX) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
133+
134+
db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS)
135+
$(CXX) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
136+
137+
dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS)
138+
$(CXX) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
139+
140+
env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS)
141+
$(CXX) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
142+
143+
filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS)
144+
$(CXX) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
145+
146+
filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS)
147+
$(CXX) $(LDFLAGS) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
148+
149+
log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS)
150+
$(CXX) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
151+
152+
table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS)
153+
$(CXX) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
154+
155+
skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS)
156+
$(CXX) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
157+
158+
version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS)
159+
$(CXX) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
160+
161+
version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS)
162+
$(CXX) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
163+
164+
write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS)
165+
$(CXX) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
166+
167+
$(MEMENVLIBRARY) : $(MEMENVOBJECTS)
168+
rm -f $@
169+
$(AR) -rs $@ $(MEMENVOBJECTS)
170+
171+
memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS)
172+
$(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LIBS)
173+
174+
ifeq ($(PLATFORM), IOS)
175+
# For iOS, create universal object files to be used on both the simulator and
176+
# a device.
177+
PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
178+
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
179+
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
180+
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
181+
182+
.cc.o:
183+
mkdir -p ios-x86/$(dir $@)
184+
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
185+
mkdir -p ios-arm/$(dir $@)
186+
$(DEVICEROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
187+
lipo ios-x86/$@ ios-arm/$@ -create -output $@
188+
189+
.c.o:
190+
mkdir -p ios-x86/$(dir $@)
191+
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
192+
mkdir -p ios-arm/$(dir $@)
193+
$(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
194+
lipo ios-x86/$@ ios-arm/$@ -create -output $@
195+
196+
else
197+
.cc.o:
198+
$(CXX) $(CXXFLAGS) -c $< -o $@
199+
200+
.c.o:
201+
$(CC) $(CFLAGS) -c $< -o $@
202+
endif

NEWS

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Release 1.2 2011-05-16
2+
----------------------
3+
4+
Fixes for larger databases (tested up to one billion 100-byte entries,
5+
i.e., ~100GB).
6+
7+
(1) Place hard limit on number of level-0 files. This fixes errors
8+
of the form "too many open files".
9+
10+
(2) Fixed memtable management. Before the fix, a heavy write burst
11+
could cause unbounded memory usage.
12+
13+
A fix for a logging bug where the reader would incorrectly complain
14+
about corruption.
15+
16+
Allow public access to WriteBatch contents so that users can easily
17+
wrap a DB.

README

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
leveldb: A key-value store
2+
Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])
3+
4+
The code under this directory implements a system for maintaining a
5+
persistent key/value store.
6+
7+
See doc/index.html for more explanation.
8+
See doc/impl.html for a brief overview of the implementation.
9+
10+
The public interface is in include/*.h. Callers should not include or
11+
rely on the details of any other header files in this package. Those
12+
internal APIs may be changed without warning.
13+
14+
Guide to header files:
15+
16+
include/db.h
17+
Main interface to the DB: Start here
18+
19+
include/options.h
20+
Control over the behavior of an entire database, and also
21+
control over the behavior of individual reads and writes.
22+
23+
include/comparator.h
24+
Abstraction for user-specified comparison function. If you want
25+
just bytewise comparison of keys, you can use the default comparator,
26+
but clients can write their own comparator implementations if they
27+
want custom ordering (e.g. to handle different character
28+
encodings, etc.)
29+
30+
include/iterator.h
31+
Interface for iterating over data. You can get an iterator
32+
from a DB object.
33+
34+
include/write_batch.h
35+
Interface for atomically applying multiple updates to a database.
36+
37+
include/slice.h
38+
A simple module for maintaining a pointer and a length into some
39+
other byte array.
40+
41+
include/status.h
42+
Status is returned from many of the public interfaces and is used
43+
to report success and various kinds of errors.
44+
45+
include/env.h
46+
Abstraction of the OS environment. A posix implementation of
47+
this interface is in util/env_posix.cc
48+
49+
include/table.h
50+
include/table_builder.h
51+
Lower-level modules that most clients probably won't use directly

TODO

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ss
2+
- Stats
3+
4+
db
5+
- Maybe implement DB::BulkDeleteForRange(start_key, end_key)
6+
that would blow away files whose ranges are entirely contained
7+
within [start_key..end_key]? For Chrome, deletion of obsolete
8+
object stores, etc. can be done in the background anyway, so
9+
probably not that important.
10+
- There have been requests for MultiGet.
11+
12+
After a range is completely deleted, what gets rid of the
13+
corresponding files if we do no future changes to that range. Make
14+
the conditions for triggering compactions fire in more situations?

WINDOWS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Building LevelDB On Windows
2+
3+
## Prereqs
4+
5+
Install the [Windows Software Development Kit version 7.1](http://www.microsoft.com/downloads/dlx/en-us/listdetailsview.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b).
6+
7+
Download and extract the [Snappy source distribution](http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz)
8+
9+
1. Open the "Windows SDK 7.1 Command Prompt" :
10+
Start Menu -> "Microsoft Windows SDK v7.1" > "Windows SDK 7.1 Command Prompt"
11+
2. Change the directory to the leveldb project
12+
13+
## Building the Static lib
14+
15+
* 32 bit Version
16+
17+
setenv /x86
18+
msbuild.exe /p:Configuration=Release /p:Platform=Win32 /p:Snappy=..\snappy-1.0.5
19+
20+
* 64 bit Version
21+
22+
setenv /x64
23+
msbuild.exe /p:Configuration=Release /p:Platform=x64 /p:Snappy=..\snappy-1.0.5
24+
25+
26+
## Building and Running the Benchmark app
27+
28+
* 32 bit Version
29+
30+
setenv /x86
31+
msbuild.exe /p:Configuration=Benchmark /p:Platform=Win32 /p:Snappy=..\snappy-1.0.5
32+
Benchmark\leveldb.exe
33+
34+
* 64 bit Version
35+
36+
setenv /x64
37+
msbuild.exe /p:Configuration=Benchmark /p:Platform=x64 /p:Snappy=..\snappy-1.0.5
38+
x64\Benchmark\leveldb.exe
39+

0 commit comments

Comments
 (0)