├── deps ├── snappy │ ├── snappy-1.1.1 │ │ ├── AUTHORS │ │ ├── testdata │ │ │ ├── ptt5 │ │ │ ├── sum │ │ │ ├── cp.html │ │ │ ├── house.jpg │ │ │ ├── kennedy.xls │ │ │ ├── baddata1.snappy │ │ │ ├── baddata2.snappy │ │ │ ├── baddata3.snappy │ │ │ ├── geo.protodata │ │ │ └── mapreduce-osdi-1.pdf │ │ ├── autogen.sh │ │ ├── Makefile.am │ │ ├── COPYING │ │ ├── snappy-stubs-internal.cc │ │ └── snappy-sinksource.cc │ ├── win32 │ │ ├── config.h │ │ └── snappy-stubs-public.h │ ├── snappy.gyp │ ├── linux │ │ └── snappy-stubs-public.h │ ├── mac │ │ └── snappy-stubs-public.h │ ├── freebsd │ │ └── snappy-stubs-public.h │ └── solaris │ │ └── snappy-stubs-public.h └── leveldb │ ├── leveldb-1.19 │ ├── .gitignore │ ├── AUTHORS │ ├── util │ │ ├── filter_policy.cc │ │ ├── hash.h │ │ ├── options.cc │ │ ├── histogram.h │ │ ├── mutexlock.h │ │ ├── hash.cc │ │ ├── logging.h │ │ ├── crc32c.h │ │ ├── testutil.cc │ │ ├── hash_test.cc │ │ ├── arena_test.cc │ │ ├── testharness.cc │ │ ├── logging.cc │ │ ├── crc32c_test.cc │ │ ├── arena.h │ │ ├── status.cc │ │ ├── arena.cc │ │ ├── testutil.h │ │ ├── random.h │ │ ├── comparator.cc │ │ ├── env.cc │ │ ├── env_test.cc │ │ ├── posix_logger.h │ │ └── bloom.cc │ ├── port │ │ ├── README │ │ ├── port.h │ │ ├── win │ │ │ └── stdint.h │ │ ├── thread_annotations.h │ │ └── port_posix.cc │ ├── NEWS │ ├── TODO │ ├── helpers │ │ └── memenv │ │ │ └── memenv.h │ ├── db │ │ ├── db_iter.h │ │ ├── log_format.h │ │ ├── builder.h │ │ ├── version_edit_test.cc │ │ ├── log_writer.h │ │ ├── write_batch_internal.h │ │ ├── leveldbutil.cc │ │ ├── snapshot.h │ │ ├── table_cache.h │ │ ├── builder.cc │ │ ├── memtable.h │ │ └── filename.h │ ├── table │ │ ├── merger.h │ │ ├── block.h │ │ ├── two_level_iterator.h │ │ ├── iterator.cc │ │ ├── block_builder.h │ │ ├── iterator_wrapper.h │ │ └── filter_block.h │ ├── include │ │ └── leveldb │ │ │ ├── dumpfile.h │ │ │ ├── write_batch.h │ │ │ ├── comparator.h │ │ │ ├── filter_policy.h │ │ │ └── table.h │ ├── doc │ │ ├── doc.css │ │ └── log_format.txt │ ├── LICENSE │ ├── CONTRIBUTING.md │ └── issues │ │ ├── issue200_test.cc │ │ └── issue178_test.cc │ └── port-libuv │ ├── win_logger.h │ ├── port_uv.cc │ ├── atomic_pointer_win.h │ ├── uv_condvar.h │ └── win_logger.cc ├── test ├── data │ └── testdata.bin ├── leveldown-test.js ├── batch-test.js ├── del-test.js ├── get-test.js ├── open-test.js ├── put-test.js ├── ranges-test.js ├── chained-batch-test.js ├── approximate-size-test.js ├── put-get-del-test.js ├── port-libuv-fix-test.js ├── close-test.js ├── stack-blower.js ├── make.js ├── leak-tester.js ├── cleanup-hanging-iterators-test.js ├── getproperty-test.js ├── iterator-recursion-test.js ├── repair-test.js ├── iterator-test.js ├── leak-tester-batch.js └── destroy-test.js ├── .gitignore ├── .npmignore ├── .travis.yml ├── .dntrc ├── src ├── batch_async.cc ├── batch_async.h ├── async.h ├── batch.h ├── leveldown_async.h ├── leveldown_async.cc ├── common.h ├── iterator_async.h ├── leveldown.cc ├── iterator.h └── iterator_async.cc ├── bench ├── write-sorted-plot.sh ├── write-random-plot.sh ├── write-random.js ├── write-sorted.js ├── db-bench-plot.sh └── memory.js ├── chained-batch.js ├── LICENSE.md ├── binding.gyp ├── .jshintrc ├── iterator.js ├── package.json └── leveldown.js /deps/snappy/snappy-1.1.1/AUTHORS: -------------------------------------------------------------------------------- 1 | opensource@google.com 2 | -------------------------------------------------------------------------------- /test/data/testdata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/test/data/testdata.bin -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/ptt5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/ptt5 -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/sum -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/cp.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/cp.html -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/house.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/house.jpg -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/kennedy.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/kennedy.xls -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata1.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/baddata1.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata2.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/baddata2.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata3.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/baddata3.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/geo.protodata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/geo.protodata -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | *.a 3 | *.o 4 | *.dylib* 5 | *.so 6 | *.so.* 7 | *_test 8 | db_bench 9 | leveldbutil 10 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown/master/deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh -e 2 | rm -rf autom4te.cache 3 | aclocal -I m4 4 | autoheader 5 | libtoolize --copy 6 | automake --add-missing --copy 7 | autoconf 8 | -------------------------------------------------------------------------------- /test/leveldown-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , leveldown = require('../') 3 | , abstract = require('abstract-leveldown/abstract/leveldown-test') 4 | 5 | abstract.args(leveldown, test) 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | build/ 3 | build-pre-gyp/ 4 | Release/ 5 | libleveldb.so 6 | libleveldb.a 7 | leakydb 8 | *.sln 9 | *.vcxproj 10 | *.vcxproj.filters 11 | *.tlog 12 | *.obj 13 | *.1sdk.pdb 14 | *.lastbuildstate 15 | npm-debug.log 16 | prebuilds/ 17 | -------------------------------------------------------------------------------- /test/batch-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/batch-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/del-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/del-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/get-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/get-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/open-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/open-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/put-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/put-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/ranges-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/ranges-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/chained-batch-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/chained-batch-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /test/approximate-size-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/approximate-size-test') 5 | 6 | abstract.all(leveldown, test, testCommon) 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | build/ 3 | build-pre-gyp/ 4 | test-data.tar 5 | test-data.db.tar 6 | deps/leveldb/leveldb-basho/ 7 | deps/leveldb/leveldb-hyper/ 8 | deps/leveldb/leveldb-rocksdb/ 9 | deps/snappy/snappy-1.1.1/testdata/ 10 | leakydb 11 | bench/ 12 | test/ 13 | deps/leveldb/leveldb-1.17.0/doc/ 14 | README 15 | INSTALL 16 | NEWS 17 | AUTHORS 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | env: 6 | - CXX=g++-4.8 7 | 8 | addons: 9 | apt: 10 | sources: 11 | - ubuntu-toolchain-r-test 12 | packages: 13 | - g++-4.8 14 | 15 | before_install: 16 | - export JOBS=max 17 | 18 | node_js: 19 | - "6" 20 | - "5" 21 | - "4" 22 | - "0.12" 23 | - "0.10" 24 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /test/put-get-del-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , fs = require('fs') 5 | , path = require('path') 6 | , testBuffer = fs.readFileSync(path.join(__dirname, 'data/testdata.bin')) 7 | , abstract = require('abstract-leveldown/abstract/put-get-del-test') 8 | 9 | abstract.all(leveldown, test, testCommon, testBuffer) 10 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/NEWS: -------------------------------------------------------------------------------- 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. 18 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/TODO: -------------------------------------------------------------------------------- 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? 15 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/hash.h: -------------------------------------------------------------------------------- 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 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /test/port-libuv-fix-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , path = require('path') 3 | , fs = require('fs') 4 | 5 | test('test port-libuv is being used', function (t) { 6 | var version = fs.readFileSync(path.join(__dirname, '../deps/leveldb/leveldb.gyp'), 'utf8') 7 | .match(/'ldbversion': '([^']+)'/)[1] 8 | , porth 9 | 10 | t.ok(version, 'matched current leveldb version') 11 | 12 | porth = fs.readFileSync(path.join(__dirname, '../deps/leveldb/leveldb-' + version + '/port/port.h'), 'utf8') 13 | 14 | t.ok(/"port_uv\.h"/.test(porth), 'port.h includes reference to port_uv.h') 15 | 16 | t.end() 17 | }) 18 | -------------------------------------------------------------------------------- /test/close-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/close-test') 5 | 6 | module.exports.setUp = function () { 7 | test('setUp', testCommon.setUp) 8 | } 9 | 10 | module.exports.close = abstract.close 11 | 12 | module.exports.tearDown = function () { 13 | test('tearDown', testCommon.tearDown) 14 | } 15 | 16 | module.exports.all = function (leveldown) { 17 | module.exports.setUp() 18 | module.exports.close(leveldown, test, testCommon) 19 | module.exports.tearDown() 20 | } 21 | 22 | module.exports.all(leveldown) 23 | -------------------------------------------------------------------------------- /.dntrc: -------------------------------------------------------------------------------- 1 | ## DNT config file 2 | ## see https://github.com/rvagg/dnt 3 | 4 | NODE_VERSIONS="\ 5 | v0.10.40 \ 6 | v0.12.7 \ 7 | " 8 | IOJS_VERSIONS="\ 9 | v1.8.4 \ 10 | v2.0.1 \ 11 | v2.3.4 \ 12 | v3.0.0-rc.3 \ 13 | " 14 | OUTPUT_PREFIX="leveldown-" 15 | TEST_CMD="\ 16 | cd /dnt/ && \ 17 | npm install && \ 18 | npm run-script prebuild \ 19 | --nodedir=/usr/src/node/ && \ 20 | node_modules/.bin/tape test/*-test.js \ 21 | " 22 | # for tape 23 | LOG_OK_CMD="tail -2 | head -1 | sed 's/^# //'" 24 | -------------------------------------------------------------------------------- /src/batch_async.cc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | 7 | #include 8 | #include "batch.h" 9 | #include "batch_async.h" 10 | 11 | namespace leveldown { 12 | 13 | /** NEXT WORKER **/ 14 | 15 | BatchWriteWorker::BatchWriteWorker ( 16 | Batch* batch 17 | , Nan::Callback *callback 18 | ) : AsyncWorker(NULL, callback) 19 | , batch(batch) 20 | {}; 21 | 22 | BatchWriteWorker::~BatchWriteWorker () {} 23 | 24 | void BatchWriteWorker::Execute () { 25 | SetStatus(batch->Write()); 26 | } 27 | 28 | } // namespace leveldown 29 | -------------------------------------------------------------------------------- /bench/write-sorted-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot < 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_BATCH_ASYNC_H 7 | #define LD_BATCH_ASYNC_H 8 | 9 | #include 10 | #include 11 | 12 | #include "async.h" 13 | #include "batch.h" 14 | #include "database.h" 15 | 16 | namespace leveldown { 17 | 18 | class BatchWriteWorker : public AsyncWorker { 19 | public: 20 | BatchWriteWorker ( 21 | Batch* batch 22 | , Nan::Callback *callback 23 | ); 24 | 25 | virtual ~BatchWriteWorker (); 26 | virtual void Execute (); 27 | 28 | private: 29 | Batch* batch; 30 | }; 31 | 32 | } // namespace leveldown 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /chained-batch.js: -------------------------------------------------------------------------------- 1 | const util = require('util') 2 | , AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch 3 | 4 | 5 | function ChainedBatch (db) { 6 | AbstractChainedBatch.call(this, db) 7 | this.binding = db.binding.batch() 8 | } 9 | 10 | 11 | ChainedBatch.prototype._put = function (key, value) { 12 | this.binding.put(key, value) 13 | } 14 | 15 | 16 | ChainedBatch.prototype._del = function (key) { 17 | this.binding.del(key) 18 | } 19 | 20 | 21 | ChainedBatch.prototype._clear = function (key) { 22 | this.binding.clear(key) 23 | } 24 | 25 | 26 | ChainedBatch.prototype._write = function (options, callback) { 27 | this.binding.write(options, callback) 28 | } 29 | 30 | util.inherits(ChainedBatch, AbstractChainedBatch) 31 | 32 | 33 | module.exports = ChainedBatch -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /deps/leveldb/port-libuv/win_logger.h: -------------------------------------------------------------------------------- 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 | // Logger implementation for Windows 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 8 | #define STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 9 | 10 | #include 11 | #include "leveldb/env.h" 12 | 13 | namespace leveldb { 14 | 15 | class WinLogger : public Logger { 16 | private: 17 | FILE* file_; 18 | public: 19 | explicit WinLogger(FILE* f) : file_(f) { assert(file_); } 20 | virtual ~WinLogger() { 21 | fclose(file_); 22 | } 23 | virtual void Logv(const char* format, va_list ap); 24 | 25 | }; 26 | 27 | } 28 | #endif // STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_ 29 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/port/port.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_UV) 14 | # include "port_uv.h" 15 | #elif defined(LEVELDB_PLATFORM_POSIX) 16 | # include "port/port_posix.h" 17 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 18 | # include "port/port_chromium.h" 19 | #endif 20 | 21 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 22 | -------------------------------------------------------------------------------- /bench/write-random-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot < 2 | typedef SSIZE_T ssize_t; 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_WINDOWS_H 1 6 | 7 | /* Name of package */ 8 | #define PACKAGE "snappy" 9 | 10 | /* Define to the address where bug reports for this package should be sent. */ 11 | #define PACKAGE_BUGREPORT "" 12 | 13 | /* Define to the full name of this package. */ 14 | #define PACKAGE_NAME "snappy" 15 | 16 | /* Define to the full name and version of this package. */ 17 | #define PACKAGE_STRING "snappy 1.1.1" 18 | 19 | /* Define to the one symbol short name of this package. */ 20 | #define PACKAGE_TARNAME "snappy" 21 | 22 | /* Define to the version of this package. */ 23 | #define PACKAGE_VERSION "1.1.1" 24 | 25 | /* Define to 1 if you have the ANSI C header files. */ 26 | #define STDC_HEADERS 1 27 | 28 | /* Version number of package */ 29 | #define VERSION "1.1.1" 30 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/options.cc: -------------------------------------------------------------------------------- 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 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | compression(kSnappyCompression), 25 | reuse_logs(false), 26 | filter_policy(NULL) { 27 | } 28 | 29 | } // namespace leveldb 30 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/db_iter.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /src/async.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_ASYNC_H 7 | #define LD_ASYNC_H 8 | 9 | #include 10 | #include 11 | #include "database.h" 12 | 13 | namespace leveldown { 14 | 15 | class Database; 16 | 17 | /* abstract */ class AsyncWorker : public Nan::AsyncWorker { 18 | public: 19 | AsyncWorker ( 20 | leveldown::Database* database 21 | , Nan::Callback *callback 22 | ) : Nan::AsyncWorker(callback), database(database) { } 23 | 24 | protected: 25 | void SetStatus(leveldb::Status status) { 26 | this->status = status; 27 | if (!status.ok()) 28 | SetErrorMessage(status.ToString().c_str()); 29 | } 30 | Database* database; 31 | private: 32 | leveldb::Status status; 33 | }; 34 | 35 | } // namespace leveldown 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/batch.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_BATCH_H 2 | #define LD_BATCH_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "database.h" 10 | 11 | namespace leveldown { 12 | 13 | class Batch : public Nan::ObjectWrap { 14 | public: 15 | static void Init(); 16 | static v8::Local NewInstance ( 17 | v8::Local database 18 | , v8::Local optionsObj 19 | ); 20 | 21 | Batch (leveldown::Database* database, bool sync); 22 | ~Batch (); 23 | leveldb::Status Write (); 24 | 25 | private: 26 | leveldown::Database* database; 27 | leveldb::WriteOptions* options; 28 | leveldb::WriteBatch* batch; 29 | bool hasData; // keep track of whether we're writing data or not 30 | 31 | static NAN_METHOD(New); 32 | static NAN_METHOD(Put); 33 | static NAN_METHOD(Del); 34 | static NAN_METHOD(Clear); 35 | static NAN_METHOD(Write); 36 | }; 37 | 38 | } // namespace leveldown 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/stack-blower.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This test uses infinite recursion to test iterator creation with limited 3 | * stack space. In order to isolate the test harness, we run in a different 4 | * process. This is achieved through a fork() command in 5 | * iterator-recursion-test.js. To prevent tap from trying to run this test 6 | * directly, we check for a command-line argument. 7 | */ 8 | const testCommon = require('abstract-leveldown/testCommon') 9 | , leveldown = require('../') 10 | 11 | if (process.argv[2] == 'run') { 12 | testCommon.cleanup(function () { 13 | var db = leveldown(testCommon.location()) 14 | , depth = 0 15 | 16 | db.open(function () { 17 | function recurse() { 18 | db.iterator({ start: '0' }) 19 | depth++ 20 | recurse() 21 | } 22 | 23 | try { 24 | recurse() 25 | } catch (e) { 26 | process.send("Catchable error at depth " + depth) 27 | } 28 | }) 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/port/win/stdint.h: -------------------------------------------------------------------------------- 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 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/merger.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 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 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /src/leveldown_async.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_LEVELDOWN_ASYNC_H 7 | #define LD_LEVELDOWN_ASYNC_H 8 | 9 | #include 10 | 11 | #include "async.h" 12 | 13 | namespace leveldown { 14 | 15 | class DestroyWorker : public AsyncWorker { 16 | public: 17 | DestroyWorker ( 18 | Nan::Utf8String* location 19 | , Nan::Callback *callback 20 | ); 21 | 22 | virtual ~DestroyWorker (); 23 | virtual void Execute (); 24 | 25 | private: 26 | Nan::Utf8String* location; 27 | }; 28 | 29 | class RepairWorker : public AsyncWorker { 30 | public: 31 | RepairWorker ( 32 | Nan::Utf8String* location 33 | , Nan::Callback *callback 34 | ); 35 | 36 | virtual ~RepairWorker (); 37 | virtual void Execute (); 38 | 39 | private: 40 | Nan::Utf8String* location; 41 | }; 42 | 43 | } // namespace leveldown 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/log_format.h: -------------------------------------------------------------------------------- 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 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.txt for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /deps/leveldb/port-libuv/port_uv.cc: -------------------------------------------------------------------------------- 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 | #include "port_uv.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include "util/logging.h" 11 | 12 | namespace leveldb { 13 | namespace port { 14 | 15 | Mutex::Mutex() { uv_mutex_init(&mu_); } 16 | 17 | Mutex::~Mutex() { uv_mutex_destroy(&mu_); } 18 | 19 | void Mutex::Lock() { uv_mutex_lock(&mu_); } 20 | 21 | void Mutex::Unlock() { uv_mutex_unlock(&mu_); } 22 | 23 | CondVar::CondVar(Mutex* mu) : mu_(mu) { uv_cond_init(&cv_); } 24 | 25 | CondVar::~CondVar() { uv_cond_destroy(&cv_); } 26 | 27 | void CondVar::Wait() { uv_cond_wait(&cv_, &mu_->mu_); } 28 | 29 | void CondVar::Signal() { uv_cond_signal(&cv_); } 30 | 31 | void CondVar::SignalAll() { uv_cond_broadcast(&cv_); } 32 | 33 | void InitOnce(OnceType* once, void (*initializer)()) { uv_once(once, initializer); } 34 | 35 | } // namespace port 36 | } // namespace leveldb 37 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/histogram.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright (c) 2016 Rod Vagg 5 | --------------------------- 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | -------------------------------------------------------------------------------- /src/leveldown_async.cc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #include 7 | 8 | #include "leveldown.h" 9 | #include "leveldown_async.h" 10 | 11 | namespace leveldown { 12 | 13 | /** DESTROY WORKER **/ 14 | 15 | DestroyWorker::DestroyWorker ( 16 | Nan::Utf8String* location 17 | , Nan::Callback *callback 18 | ) : AsyncWorker(NULL, callback) 19 | , location(location) 20 | {}; 21 | 22 | DestroyWorker::~DestroyWorker () { 23 | delete location; 24 | } 25 | 26 | void DestroyWorker::Execute () { 27 | leveldb::Options options; 28 | SetStatus(leveldb::DestroyDB(**location, options)); 29 | } 30 | 31 | /** REPAIR WORKER **/ 32 | 33 | RepairWorker::RepairWorker ( 34 | Nan::Utf8String* location 35 | , Nan::Callback *callback 36 | ) : AsyncWorker(NULL, callback) 37 | , location(location) 38 | {}; 39 | 40 | RepairWorker::~RepairWorker () { 41 | delete location; 42 | } 43 | 44 | void RepairWorker::Execute () { 45 | leveldb::Options options; 46 | SetStatus(leveldb::RepairDB(**location, options)); 47 | } 48 | 49 | } // namespace leveldown 50 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/block.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_COMMON_H 7 | #define LD_COMMON_H 8 | 9 | #include 10 | 11 | namespace leveldown { 12 | 13 | NAN_INLINE bool BooleanOptionValue(v8::Local options, 14 | const char* _key, 15 | bool def = false) { 16 | Nan::HandleScope scope; 17 | v8::Local key = Nan::New(_key).ToLocalChecked(); 18 | return !options.IsEmpty() 19 | && options->Has(key) 20 | ? options->Get(key)->BooleanValue() 21 | : def; 22 | } 23 | 24 | NAN_INLINE uint32_t UInt32OptionValue(v8::Local options, 25 | const char* _key, 26 | uint32_t def) { 27 | Nan::HandleScope scope; 28 | v8::Local key = Nan::New(_key).ToLocalChecked(); 29 | return !options.IsEmpty() 30 | && options->Has(key) 31 | && options->Get(key)->IsNumber() 32 | ? options->Get(key)->Uint32Value() 33 | : def; 34 | } 35 | 36 | } // namespace leveldown 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/builder.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /src/iterator_async.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_ITERATOR_ASYNC_H 7 | #define LD_ITERATOR_ASYNC_H 8 | 9 | #include 10 | #include 11 | 12 | #include "async.h" 13 | #include "iterator.h" 14 | 15 | namespace leveldown { 16 | 17 | class NextWorker : public AsyncWorker { 18 | public: 19 | NextWorker ( 20 | Iterator* iterator 21 | , Nan::Callback *callback 22 | , void (*localCallback)(Iterator*) 23 | ); 24 | 25 | virtual ~NextWorker (); 26 | virtual void Execute (); 27 | virtual void HandleOKCallback (); 28 | 29 | private: 30 | Iterator* iterator; 31 | void (*localCallback)(Iterator*); 32 | std::vector > result; 33 | bool ok; 34 | }; 35 | 36 | class EndWorker : public AsyncWorker { 37 | public: 38 | EndWorker ( 39 | Iterator* iterator 40 | , Nan::Callback *callback 41 | ); 42 | 43 | virtual ~EndWorker (); 44 | virtual void Execute (); 45 | virtual void HandleOKCallback (); 46 | 47 | private: 48 | Iterator* iterator; 49 | }; 50 | 51 | } // namespace leveldown 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /test/make.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , cleanup = testCommon.cleanup 4 | , location = testCommon.location 5 | , leveldown = require('../') 6 | 7 | function makeTest (name, testFn) { 8 | test(name, function (t) { 9 | cleanup(function () { 10 | var loc = location() 11 | , db = leveldown(loc) 12 | , done = function (close) { 13 | if (close === false) 14 | return cleanup(t.end.bind(t)) 15 | db.close(function (err) { 16 | t.notOk(err, 'no error from close()') 17 | cleanup(t.end.bind(t)) 18 | }) 19 | } 20 | db.open(function (err) { 21 | t.notOk(err, 'no error from open()') 22 | db.batch( 23 | [ 24 | { type: 'put', key: 'one', value: '1' } 25 | , { type: 'put', key: 'two', value: '2' } 26 | , { type: 'put', key: 'three', value: '3' } 27 | ] 28 | , function (err) { 29 | t.notOk(err, 'no error from batch()') 30 | testFn(db, t, done, loc) 31 | } 32 | ) 33 | }) 34 | }) 35 | }) 36 | } 37 | 38 | module.exports = makeTest 39 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/mutexlock.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [{ 3 | "target_name": "leveldown" 4 | , "conditions": [ 5 | ["OS == 'win'", { 6 | "defines": [ 7 | "_HAS_EXCEPTIONS=0" 8 | ] 9 | , "msvs_settings": { 10 | "VCCLCompilerTool": { 11 | "RuntimeTypeInfo": "false" 12 | , "EnableFunctionLevelLinking": "true" 13 | , "ExceptionHandling": "2" 14 | , "DisableSpecificWarnings": [ "4355", "4530" ,"4267", "4244", "4506" ] 15 | } 16 | } 17 | }] 18 | , ['OS == "linux"', { 19 | 'cflags': [ 20 | ] 21 | , 'cflags!': [ '-fno-tree-vrp' ] 22 | }] 23 | ] 24 | , "dependencies": [ 25 | "<(module_root_dir)/deps/leveldb/leveldb.gyp:leveldb" 26 | ] 27 | , "include_dirs" : [ 28 | " 2 | #include 3 | 4 | // credit: https://groups.google.com/forum/#!msg/leveldb/VuECZMnsob4/F6pGPGaK-XwJ 5 | 6 | namespace leveldb { 7 | namespace port { 8 | 9 | class AtomicPointer { 10 | private: 11 | void* rep_; 12 | 13 | public: 14 | AtomicPointer () {} 15 | explicit AtomicPointer(void* v) { 16 | InterlockedExchangePointer(&rep_, v); 17 | } 18 | 19 | // Read and return the stored pointer with the guarantee that no 20 | // later memory access (read or write) by this thread can be 21 | // reordered ahead of this read. 22 | inline void* Acquire_Load() const { 23 | void* r; 24 | InterlockedExchangePointer(&r, rep_ ); 25 | return r; 26 | } 27 | 28 | // Set v as the stored pointer with the guarantee that no earlier 29 | // memory access (read or write) by this thread can be reordered 30 | // after this store. 31 | inline void Release_Store(void* v) { 32 | InterlockedExchangePointer(&rep_, v); 33 | } 34 | 35 | // Read the stored pointer with no ordering guarantees. 36 | inline void* NoBarrier_Load() const { 37 | void* r = reinterpret_cast(rep_); 38 | return r; 39 | } 40 | 41 | // Set va as the stored pointer with no ordering guarantees. 42 | inline void NoBarrier_Store(void* v) { 43 | rep_ = reinterpret_cast(v); 44 | } 45 | }; 46 | 47 | } // namespace port 48 | } // namespace leveldb 49 | -------------------------------------------------------------------------------- /test/leak-tester.js: -------------------------------------------------------------------------------- 1 | const BUFFERS = false 2 | 3 | var leveldown = require('..') 4 | , crypto = require('crypto') 5 | , putCount = 0 6 | , getCount = 0 7 | , rssBase 8 | , db 9 | 10 | function run () { 11 | var key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000)) 12 | 13 | if (BUFFERS) key = new Buffer(key) 14 | 15 | db.get(key, function (err, value) { 16 | getCount++ 17 | 18 | if (err) { 19 | var putValue = crypto.randomBytes(1024) 20 | if (!BUFFERS) putValue = putValue.toString('hex') 21 | 22 | return db.put(key, putValue, function () { 23 | putCount++ 24 | process.nextTick(run) 25 | }) 26 | } 27 | 28 | process.nextTick(run) 29 | }) 30 | 31 | if (getCount % 1000 === 0) { 32 | if (typeof gc != 'undefined') 33 | gc() 34 | console.log( 35 | 'getCount =' 36 | , getCount 37 | , ', putCount = ' 38 | , putCount 39 | , ', rss =' 40 | , Math.round(process.memoryUsage().rss / rssBase * 100) + '%' 41 | , Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M' 42 | , JSON.stringify([0,1,2,3,4,5,6].map(function (l) { 43 | return db.getProperty('leveldb.num-files-at-level' + l) 44 | })) 45 | ) 46 | } 47 | } 48 | 49 | leveldown.destroy('./leakydb', function () { 50 | db = leveldown('./leakydb') 51 | db.open({ xcacheSize: 0, xmaxOpenFiles: 10 }, function () { 52 | rssBase = process.memoryUsage().rss 53 | run() 54 | }) 55 | }) -------------------------------------------------------------------------------- /iterator.js: -------------------------------------------------------------------------------- 1 | const util = require('util') 2 | , AbstractIterator = require('abstract-leveldown').AbstractIterator 3 | , fastFuture = require('fast-future') 4 | 5 | 6 | function Iterator (db, options) { 7 | AbstractIterator.call(this, db) 8 | 9 | this.binding = db.binding.iterator(options) 10 | this.cache = null 11 | this.finished = false 12 | this.fastFuture = fastFuture() 13 | } 14 | 15 | util.inherits(Iterator, AbstractIterator) 16 | 17 | Iterator.prototype.seek = function (key) { 18 | if (typeof key !== 'string') 19 | throw new Error('seek requires a string key') 20 | this.cache = null 21 | this.binding.seek(key) 22 | } 23 | 24 | Iterator.prototype._next = function (callback) { 25 | var that = this 26 | , key 27 | , value 28 | 29 | if (this.cache && this.cache.length) { 30 | key = this.cache.pop() 31 | value = this.cache.pop() 32 | 33 | this.fastFuture(function () { 34 | callback(null, key, value) 35 | }) 36 | 37 | } else if (this.finished) { 38 | this.fastFuture(function () { 39 | callback() 40 | }) 41 | } else { 42 | this.binding.next(function (err, array, finished) { 43 | if (err) return callback(err) 44 | 45 | that.cache = array 46 | that.finished = finished 47 | that._next(callback) 48 | }) 49 | } 50 | 51 | return this 52 | } 53 | 54 | 55 | Iterator.prototype._end = function (callback) { 56 | delete this.cache 57 | this.binding.end(callback) 58 | } 59 | 60 | 61 | module.exports = Iterator 62 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/doc/doc.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 0.5in; 3 | margin-right: 0.5in; 4 | background: white; 5 | color: black; 6 | } 7 | 8 | h1 { 9 | margin-left: -0.2in; 10 | font-size: 14pt; 11 | } 12 | h2 { 13 | margin-left: -0in; 14 | font-size: 12pt; 15 | } 16 | h3 { 17 | margin-left: -0in; 18 | } 19 | h4 { 20 | margin-left: -0in; 21 | } 22 | hr { 23 | margin-left: -0in; 24 | } 25 | 26 | /* Definition lists: definition term bold */ 27 | dt { 28 | font-weight: bold; 29 | } 30 | 31 | address { 32 | text-align: center; 33 | } 34 | code,samp,var { 35 | color: blue; 36 | } 37 | kbd { 38 | color: #600000; 39 | } 40 | div.note p { 41 | float: right; 42 | width: 3in; 43 | margin-right: 0%; 44 | padding: 1px; 45 | border: 2px solid #6060a0; 46 | background-color: #fffff0; 47 | } 48 | 49 | ul { 50 | margin-top: -0em; 51 | margin-bottom: -0em; 52 | } 53 | 54 | ol { 55 | margin-top: -0em; 56 | margin-bottom: -0em; 57 | } 58 | 59 | UL.nobullets { 60 | list-style-type: none; 61 | list-style-image: none; 62 | margin-left: -1em; 63 | } 64 | 65 | p { 66 | margin: 1em 0 1em 0; 67 | padding: 0 0 0 0; 68 | } 69 | 70 | pre { 71 | line-height: 1.3em; 72 | padding: 0.4em 0 0.8em 0; 73 | margin: 0 0 0 0; 74 | border: 0 0 0 0; 75 | color: blue; 76 | } 77 | 78 | .datatable { 79 | margin-left: auto; 80 | margin-right: auto; 81 | margin-top: 2em; 82 | margin-bottom: 2em; 83 | border: 1px solid; 84 | } 85 | 86 | .datatable td,th { 87 | padding: 0 0.5em 0 0.5em; 88 | text-align: right; 89 | } 90 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/version_edit_test.cc: -------------------------------------------------------------------------------- 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 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2011, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/LICENSE: -------------------------------------------------------------------------------- 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. 28 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/hash.cc: -------------------------------------------------------------------------------- 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 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/logging.h: -------------------------------------------------------------------------------- 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 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/crc32c.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/port/port_posix.cc: -------------------------------------------------------------------------------- 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 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace port { 13 | 14 | static void PthreadCall(const char* label, int result) { 15 | if (result != 0) { 16 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 17 | abort(); 18 | } 19 | } 20 | 21 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 22 | 23 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 24 | 25 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 26 | 27 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 28 | 29 | CondVar::CondVar(Mutex* mu) 30 | : mu_(mu) { 31 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 32 | } 33 | 34 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 35 | 36 | void CondVar::Wait() { 37 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 38 | } 39 | 40 | void CondVar::Signal() { 41 | PthreadCall("signal", pthread_cond_signal(&cv_)); 42 | } 43 | 44 | void CondVar::SignalAll() { 45 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 46 | } 47 | 48 | void InitOnce(OnceType* once, void (*initializer)()) { 49 | PthreadCall("once", pthread_once(once, initializer)); 50 | } 51 | 52 | } // namespace port 53 | } // namespace leveldb 54 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/testutil.cc: -------------------------------------------------------------------------------- 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 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/log_writer.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/write_batch_internal.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/CONTRIBUTING.md: -------------------------------------------------------------------------------- 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. 37 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | }; 23 | 24 | bool HandleDumpCommand(Env* env, char** files, int num) { 25 | StdoutPrinter printer; 26 | bool ok = true; 27 | for (int i = 0; i < num; i++) { 28 | Status s = DumpFile(env, files[i], &printer); 29 | if (!s.ok()) { 30 | fprintf(stderr, "%s\n", s.ToString().c_str()); 31 | ok = false; 32 | } 33 | } 34 | return ok; 35 | } 36 | 37 | } // namespace 38 | } // namespace leveldb 39 | 40 | static void Usage() { 41 | fprintf( 42 | stderr, 43 | "Usage: leveldbutil command...\n" 44 | " dump files... -- dump contents of specified files\n" 45 | ); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | leveldb::Env* env = leveldb::Env::Default(); 50 | bool ok = true; 51 | if (argc < 2) { 52 | Usage(); 53 | ok = false; 54 | } else { 55 | std::string command = argv[1]; 56 | if (command == "dump") { 57 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 58 | } else { 59 | Usage(); 60 | ok = false; 61 | } 62 | } 63 | return (ok ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /bench/write-random.js: -------------------------------------------------------------------------------- 1 | const leveldown = require('../') 2 | , crypto = require('crypto') 3 | , fs = require('fs') 4 | , du = require('du') 5 | , uuid = require('node-uuid') 6 | 7 | , entryCount = 10000000 8 | , concurrency = 10 9 | , timesFile = './write_random_times.csv' 10 | , dbDir = './write_random.db' 11 | , data = crypto.randomBytes(256) // buffer 12 | 13 | var db = leveldown(dbDir) 14 | , timesStream = fs.createWriteStream(timesFile, 'utf8') 15 | 16 | function report (ms) { 17 | console.log('Wrote', entryCount, 'in', Math.floor(ms / 1000) + 's') 18 | timesStream.end() 19 | du(dbDir, function (err, size) { 20 | if (err) 21 | throw err 22 | console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M') 23 | }) 24 | console.log('Wrote times to ', timesFile) 25 | } 26 | 27 | db.open(function (err) { 28 | if (err) 29 | throw err 30 | 31 | var inProgress = 0 32 | , totalWrites = 0 33 | , startTime = Date.now() 34 | , writeBuf = '' 35 | 36 | function write() { 37 | if (totalWrites % 100000 == 0) console.log(inProgress, totalWrites) 38 | 39 | if (totalWrites % 1000 == 0) { 40 | timesStream.write(writeBuf) 41 | writeBuf = '' 42 | } 43 | 44 | if (totalWrites++ == entryCount) 45 | return report(Date.now() - startTime) 46 | 47 | if (inProgress >= concurrency || totalWrites > entryCount) 48 | return 49 | 50 | var time = process.hrtime() 51 | inProgress++ 52 | 53 | db.put(uuid.v4(), data, function (err) { 54 | if (err) 55 | throw err 56 | writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n' 57 | inProgress-- 58 | process.nextTick(write) 59 | }) 60 | 61 | process.nextTick(write) 62 | } 63 | 64 | write() 65 | }) 66 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/hash_test.cc: -------------------------------------------------------------------------------- 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 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /test/cleanup-hanging-iterators-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , makeTest = require('./make') 5 | 6 | makeTest('test ended iterator', function (db, t, done) { 7 | // standard iterator with an end() properly called, easy 8 | 9 | var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) 10 | it.next(function (err, key, value) { 11 | t.notOk(err, 'no error from next()') 12 | t.equal(key, 'one', 'correct key') 13 | t.equal(value, '1', 'correct value') 14 | it.end(function (err) { 15 | t.notOk(err, 'no error from next()') 16 | done() 17 | }) 18 | }) 19 | }) 20 | 21 | makeTest('test non-ended iterator', function (db, t, done) { 22 | // no end() call on our iterator, cleanup should crash Node if not handled properly 23 | var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) 24 | it.next(function (err, key, value) { 25 | t.notOk(err, 'no error from next()') 26 | t.equal(key, 'one', 'correct key') 27 | t.equal(value, '1', 'correct value') 28 | done() 29 | }) 30 | }) 31 | 32 | makeTest('test multiple non-ended iterators', function (db, t, done) { 33 | // no end() call on our iterator, cleanup should crash Node if not handled properly 34 | db.iterator() 35 | db.iterator().next(function () {}) 36 | db.iterator().next(function () {}) 37 | db.iterator().next(function () {}) 38 | setTimeout(done, 50) 39 | }) 40 | 41 | makeTest('test ending iterators', function (db, t, done) { 42 | // at least one end() should be in progress when we try to close the db 43 | var it1 = db.iterator().next(function () { 44 | it1.end(function () {}) 45 | }) 46 | , it2 = db.iterator().next(function () { 47 | it2.end(function () {}) 48 | done() 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /bench/write-sorted.js: -------------------------------------------------------------------------------- 1 | const leveldown = require('../') 2 | , timestamp = require('monotonic-timestamp') 3 | , crypto = require('crypto') 4 | , fs = require('fs') 5 | , du = require('du') 6 | 7 | , entryCount = 10000000 8 | , concurrency = 10 9 | , timesFile = './write_sorted_times.csv' 10 | , dbDir = './write_sorted.db' 11 | , data = crypto.randomBytes(256) // buffer 12 | 13 | var db = leveldown(dbDir) 14 | , timesStream = fs.createWriteStream(timesFile, 'utf8') 15 | 16 | function report (ms) { 17 | console.log('Wrote', entryCount, 'in', Math.floor(ms / 1000) + 's') 18 | timesStream.end() 19 | du(dbDir, function (err, size) { 20 | if (err) 21 | throw err 22 | console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M') 23 | }) 24 | console.log('Wrote times to ', timesFile) 25 | } 26 | 27 | db.open({ errorIfExists: true, createIfMissing: true }, function (err) { 28 | if (err) 29 | throw err 30 | 31 | var inProgress = 0 32 | , totalWrites = 0 33 | , startTime = Date.now() 34 | , writeBuf = '' 35 | 36 | function write() { 37 | if (totalWrites % 100000 == 0) console.log(inProgress, totalWrites) 38 | 39 | if (totalWrites % 1000 == 0) { 40 | timesStream.write(writeBuf) 41 | writeBuf = '' 42 | } 43 | 44 | if (totalWrites++ == entryCount) 45 | return report(Date.now() - startTime) 46 | 47 | if (inProgress >= concurrency || totalWrites > entryCount) 48 | return 49 | 50 | var time = process.hrtime() 51 | inProgress++ 52 | 53 | db.put(timestamp(), data, function (err) { 54 | if (err) 55 | throw err 56 | writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n' 57 | inProgress-- 58 | process.nextTick(write) 59 | }) 60 | 61 | process.nextTick(write) 62 | } 63 | 64 | write() 65 | }) 66 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 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 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/snapshot.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/arena_test.cc: -------------------------------------------------------------------------------- 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 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /test/getproperty-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | 5 | var db 6 | 7 | test('setUp common', testCommon.setUp) 8 | 9 | test('setUp db', function (t) { 10 | db = leveldown(testCommon.location()) 11 | db.open(t.end.bind(t)) 12 | }) 13 | 14 | test('test argument-less getProperty() throws', function (t) { 15 | t.throws( 16 | db.getProperty.bind(db) 17 | , { name: 'Error', message: 'getProperty() requires a valid `property` argument' } 18 | , 'no-arg getProperty() throws' 19 | ) 20 | t.end() 21 | }) 22 | 23 | test('test non-string getProperty() throws', function (t) { 24 | t.throws( 25 | db.getProperty.bind(db, {}) 26 | , { name: 'Error', message: 'getProperty() requires a valid `property` argument' } 27 | , 'no-arg getProperty() throws' 28 | ) 29 | t.end() 30 | }) 31 | 32 | test('test invalid getProperty() returns empty string', function (t) { 33 | t.equal(db.getProperty('foo'), '', 'invalid property') 34 | t.equal(db.getProperty('leveldb.foo'), '', 'invalid leveldb.* property') 35 | t.end() 36 | }) 37 | 38 | test('test invalid getProperty("leveldb.num-files-at-levelN") returns numbers', function (t) { 39 | for (var i = 0; i < 7; i++) 40 | t.equal(db.getProperty('leveldb.num-files-at-level' + i), '0', '"leveldb.num-files-at-levelN" === "0"') 41 | t.end() 42 | }) 43 | 44 | test('test invalid getProperty("leveldb.stats")', function (t) { 45 | t.ok(db.getProperty('leveldb.stats').split('\n').length > 3, 'leveldb.stats has > 3 newlines') 46 | t.end() 47 | }) 48 | 49 | test('test invalid getProperty("leveldb.sstables")', function (t) { 50 | var expected = [0,1,2,3,4,5,6].map(function (l) { return '--- level ' + l + ' ---' }).join('\n') + '\n' 51 | t.equal(db.getProperty('leveldb.sstables'), expected, 'leveldb.sstables') 52 | t.end() 53 | }) 54 | 55 | test('tearDown', function (t) { 56 | db.close(testCommon.tearDown.bind(null, t)) 57 | }) 58 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/iterator.cc: -------------------------------------------------------------------------------- 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 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /src/leveldown.cc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #include 7 | 8 | #include "leveldown.h" 9 | #include "database.h" 10 | #include "iterator.h" 11 | #include "batch.h" 12 | #include "leveldown_async.h" 13 | 14 | namespace leveldown { 15 | 16 | NAN_METHOD(DestroyDB) { 17 | Nan::HandleScope scope; 18 | 19 | Nan::Utf8String* location = new Nan::Utf8String(info[0]); 20 | 21 | Nan::Callback* callback = new Nan::Callback( 22 | v8::Local::Cast(info[1])); 23 | 24 | DestroyWorker* worker = new DestroyWorker( 25 | location 26 | , callback 27 | ); 28 | 29 | Nan::AsyncQueueWorker(worker); 30 | 31 | info.GetReturnValue().SetUndefined(); 32 | } 33 | 34 | NAN_METHOD(RepairDB) { 35 | Nan::HandleScope scope; 36 | 37 | Nan::Utf8String* location = new Nan::Utf8String(info[0]); 38 | 39 | Nan::Callback* callback = new Nan::Callback( 40 | v8::Local::Cast(info[1])); 41 | 42 | RepairWorker* worker = new RepairWorker( 43 | location 44 | , callback 45 | ); 46 | 47 | Nan::AsyncQueueWorker(worker); 48 | 49 | info.GetReturnValue().SetUndefined(); 50 | } 51 | 52 | void Init (v8::Local target) { 53 | Database::Init(); 54 | leveldown::Iterator::Init(); 55 | leveldown::Batch::Init(); 56 | 57 | v8::Local leveldown = 58 | Nan::New(LevelDOWN)->GetFunction(); 59 | 60 | leveldown->Set( 61 | Nan::New("destroy").ToLocalChecked() 62 | , Nan::New(DestroyDB)->GetFunction() 63 | ); 64 | 65 | leveldown->Set( 66 | Nan::New("repair").ToLocalChecked() 67 | , Nan::New(RepairDB)->GetFunction() 68 | ); 69 | 70 | target->Set(Nan::New("leveldown").ToLocalChecked(), leveldown); 71 | } 72 | 73 | NODE_MODULE(leveldown, Init) 74 | 75 | } // namespace leveldown 76 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/snappy-stubs-internal.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. 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. 28 | 29 | #include 30 | #include 31 | 32 | #include "snappy-stubs-internal.h" 33 | 34 | namespace snappy { 35 | 36 | void Varint::Append32(string* s, uint32 value) { 37 | char buf[Varint::kMax32]; 38 | const char* p = Varint::Encode32(buf, value); 39 | s->append(buf, p - buf); 40 | } 41 | 42 | } // namespace snappy 43 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/block_builder.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/testharness.cc: -------------------------------------------------------------------------------- 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 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/logging.cc: -------------------------------------------------------------------------------- 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 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /test/iterator-recursion-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , child_process = require('child_process') 5 | 6 | var db 7 | , sourceData = (function () { 8 | var d = [] 9 | , i = 0 10 | , k 11 | for (; i < 100000; i++) { 12 | k = (i < 10 ? '0' : '') + i 13 | d.push({ 14 | type : 'put' 15 | , key : k 16 | , value : Math.random() 17 | }) 18 | } 19 | return d 20 | }()) 21 | 22 | test('setUp common', testCommon.setUp) 23 | 24 | test('try to create an iterator with a blown stack', function (t) { 25 | // Reducing the stack size down from the default 984 for the child node 26 | // process makes it easier to trigger the bug condition. But making it too low 27 | // causes the child process to die for other reasons. 28 | var opts = { execArgv: [ '--stack-size=128' ] } 29 | , child = child_process.fork(__dirname + '/stack-blower.js', [ 'run' ], opts) 30 | 31 | t.plan(2) 32 | 33 | child.on('message', function (m) { 34 | t.ok(true, m) 35 | child.disconnect() 36 | }) 37 | 38 | child.on('exit', function (code, sig) { 39 | t.equal(code, 0, 'child exited normally') 40 | }) 41 | }) 42 | 43 | test('setUp db', function (t) { 44 | db = leveldown(testCommon.location()) 45 | db.open(function (err) { 46 | t.error(err) 47 | db.batch(sourceData, t.end.bind(t)) 48 | }) 49 | }) 50 | 51 | test('iterate over a large iterator with a large watermark', function (t) { 52 | var iterator = db.iterator({ 53 | highWaterMark: 10000000 54 | }) 55 | , count = 0 56 | , read = function () { 57 | iterator.next(function () { 58 | count++ 59 | 60 | if (!arguments.length) 61 | t.end() 62 | else 63 | read() 64 | }) 65 | } 66 | 67 | read() 68 | }) 69 | 70 | test('tearDown', function (t) { 71 | db.close(testCommon.tearDown.bind(null, t)) 72 | }) 73 | -------------------------------------------------------------------------------- /deps/leveldb/port-libuv/uv_condvar.h: -------------------------------------------------------------------------------- 1 | // uv_cond_* backport 2 | // Lifted from the Node 0.9 version of libuv for Node 0.8 compatibility 3 | // https://github.com/joyent/libuv/ 4 | 5 | // libuv copyright notice: 6 | 7 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to 11 | * deal in the Software without restriction, including without limitation the 12 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 | * sell copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 25 | * IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef LEVELDB_PORT_LIBUV_CONVAR_H_ 29 | #define LEVELDB_PORT_LIBUV_CONVAR_H_ 30 | 31 | #include 32 | 33 | #ifdef LDB_UV_POSIX 34 | typedef pthread_cond_t ldb_uv_cond_t; 35 | #endif 36 | 37 | 38 | UV_EXTERN int ldb_uv_cond_init(ldb_uv_cond_t* cond); 39 | UV_EXTERN void ldb_uv_cond_destroy(ldb_uv_cond_t* cond); 40 | UV_EXTERN void ldb_uv_cond_signal(ldb_uv_cond_t* cond); 41 | UV_EXTERN void ldb_uv_cond_broadcast(ldb_uv_cond_t* cond); 42 | UV_EXTERN void ldb_uv_cond_wait(ldb_uv_cond_t* cond, uv_mutex_t* mutex); 43 | UV_EXTERN int ldb_uv_cond_timedwait(ldb_uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout); 44 | 45 | #endif // LEVELDB_PORT_LIBUV_CONVAR_H_ 46 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/crc32c_test.cc: -------------------------------------------------------------------------------- 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 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/arena.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class Arena { 17 | public: 18 | Arena(); 19 | ~Arena(); 20 | 21 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 22 | char* Allocate(size_t bytes); 23 | 24 | // Allocate memory with the normal alignment guarantees provided by malloc 25 | char* AllocateAligned(size_t bytes); 26 | 27 | // Returns an estimate of the total memory usage of data allocated 28 | // by the arena. 29 | size_t MemoryUsage() const { 30 | return reinterpret_cast(memory_usage_.NoBarrier_Load()); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Total memory usage of the arena. 45 | port::AtomicPointer memory_usage_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /test/repair-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , fs = require('fs') 3 | , path = require('path') 4 | , mkfiletree = require('mkfiletree') 5 | , readfiletree = require('readfiletree') 6 | , testCommon = require('abstract-leveldown/testCommon') 7 | , leveldown = require('../') 8 | , makeTest = require('./make') 9 | 10 | test('test argument-less repair() throws', function (t) { 11 | t.throws( 12 | leveldown.repair 13 | , { name: 'Error', message: 'repair() requires `location` and `callback` arguments' } 14 | , 'no-arg repair() throws' 15 | ) 16 | t.end() 17 | }) 18 | 19 | test('test callback-less, 1-arg, repair() throws', function (t) { 20 | t.throws( 21 | leveldown.repair.bind(null, 'foo') 22 | , { name: 'Error', message: 'repair() requires `location` and `callback` arguments' } 23 | , 'callback-less, 1-arg repair() throws' 24 | ) 25 | t.end() 26 | }) 27 | 28 | test('test repair non-existent directory returns error', function (t) { 29 | leveldown.repair('/1/2/3/4', function (err) { 30 | if (process.platform !== 'win32') 31 | t.ok(/no such file or directory/i.test(err), 'error on callback') 32 | else 33 | t.ok(/IO error/i.test(err), 'error on callback') 34 | t.end() 35 | }) 36 | }) 37 | 38 | // a proxy indicator that RepairDB is being called and doing its thing 39 | makeTest('test repair() compacts', function (db, t, done, location) { 40 | db.close(function (err) { 41 | t.notOk(err, 'no error') 42 | var files = fs.readdirSync(location) 43 | t.ok(files.some(function (f) { return (/\.log$/).test(f) }), 'directory contains log file(s)') 44 | t.notOk(files.some(function (f) { return (/\.ldb$/).test(f) }), 'directory does not contain ldb file(s)') 45 | leveldown.repair(location, function () { 46 | files = fs.readdirSync(location) 47 | t.notOk(files.some(function (f) { return (/\.log$/).test(f) }), 'directory does not contain log file(s)') 48 | t.ok(files.some(function (f) { return (/\.ldb$/).test(f) }), 'directory contains ldb file(s)') 49 | done(false) 50 | }) 51 | }) 52 | }) 53 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 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 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /test/iterator-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , testCommon = require('abstract-leveldown/testCommon') 3 | , leveldown = require('../') 4 | , abstract = require('abstract-leveldown/abstract/iterator-test') 5 | , make = require('./make') 6 | 7 | abstract.all(leveldown, test, testCommon) 8 | 9 | make('iterator throws if key is not a string', function (db, t, done) { 10 | var ite = db.iterator() 11 | var error 12 | try { 13 | ite.seek() 14 | } catch (e) { 15 | error = e 16 | } 17 | 18 | t.ok(error, 'had error') 19 | t.end() 20 | }) 21 | 22 | make('iterator is seekable', function (db, t, done) { 23 | var ite = db.iterator() 24 | ite.seek('two') 25 | ite.next(function (err, key, value) { 26 | t.error(err, 'no error') 27 | t.same(key.toString(), 'two', 'key matches') 28 | t.same(value.toString(), '2', 'value matches') 29 | ite.next(function (err, key, value) { 30 | t.error(err, 'no error') 31 | t.same(key, undefined, 'end of iterator') 32 | t.same(value, undefined, 'end of iterator') 33 | ite.end(done) 34 | }) 35 | }) 36 | }) 37 | 38 | make('reverse seek in the middle', function (db, t, done) { 39 | var ite = db.iterator({reverse: true, limit: 1}) 40 | ite.seek('three!') 41 | ite.next(function (err, key, value) { 42 | t.error(err, 'no error') 43 | t.same(key.toString(), 'three', 'key matches') 44 | t.same(value.toString(), '3', 'value matches') 45 | ite.end(done) 46 | }) 47 | }) 48 | 49 | make('iterator invalid seek', function (db, t, done) { 50 | var ite = db.iterator() 51 | ite.seek('zzz') 52 | ite.next(function (err, key, value) { 53 | t.error(err, 'no error') 54 | t.same(key, undefined, 'end of iterator') 55 | t.same(value, undefined, 'end of iterator') 56 | ite.end(done) 57 | }) 58 | }) 59 | 60 | make('reverse seek from invalid range', function (db, t, done) { 61 | var ite = db.iterator({reverse: true}) 62 | ite.seek('zzz') 63 | ite.next(function (err, key, value) { 64 | t.error(err, 'no error') 65 | t.same(key.toString(), 'two', 'end of iterator') 66 | t.same(value.toString(), '2', 'end of iterator') 67 | ite.end(done) 68 | }) 69 | }) 70 | -------------------------------------------------------------------------------- /deps/leveldb/port-libuv/win_logger.cc: -------------------------------------------------------------------------------- 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 | #include "win_logger.h" 6 | 7 | #include 8 | 9 | namespace leveldb { 10 | 11 | void WinLogger::Logv(const char* format, va_list ap) { 12 | const uint64_t thread_id = static_cast(::GetCurrentThreadId()); 13 | 14 | // We try twice: the first time with a fixed-size stack allocated buffer, 15 | // and the second time with a much larger dynamically allocated buffer. 16 | char buffer[500]; 17 | 18 | for (int iter = 0; iter < 2; iter++) { 19 | char* base; 20 | int bufsize; 21 | if (iter == 0) { 22 | bufsize = sizeof(buffer); 23 | base = buffer; 24 | } else { 25 | bufsize = 30000; 26 | base = new char[bufsize]; 27 | } 28 | 29 | char* p = base; 30 | char* limit = base + bufsize; 31 | 32 | SYSTEMTIME st; 33 | 34 | // GetSystemTime returns UTC time, we want local time! 35 | ::GetLocalTime(&st); 36 | 37 | p += _snprintf_s(p, limit - p, _TRUNCATE, 38 | "%04d/%02d/%02d-%02d:%02d:%02d.%03d %llx ", 39 | st.wYear, 40 | st.wMonth, 41 | st.wDay, 42 | st.wHour, 43 | st.wMinute, 44 | st.wSecond, 45 | st.wMilliseconds, 46 | static_cast(thread_id)); 47 | 48 | // Print the message 49 | if (p < limit) { 50 | va_list backup_ap = ap; 51 | p += vsnprintf(p, limit - p, format, backup_ap); 52 | va_end(backup_ap); 53 | } 54 | 55 | // Truncate to available space if necessary 56 | if (p >= limit) { 57 | if (iter == 0) { 58 | continue; // Try again with larger buffer 59 | } else { 60 | p = limit - 1; 61 | } 62 | } 63 | 64 | // Add newline if necessary 65 | if (p == base || p[-1] != '\n') { 66 | *p++ = '\n'; 67 | } 68 | 69 | assert(p <= limit); 70 | fwrite(base, 1, p - base, file_); 71 | fflush(file_); 72 | if (base != buffer) { 73 | delete[] base; 74 | } 75 | break; 76 | } 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/status.cc: -------------------------------------------------------------------------------- 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 | #include 6 | #include "port/port.h" 7 | #include "leveldb/status.h" 8 | 9 | namespace leveldb { 10 | 11 | const char* Status::CopyState(const char* state) { 12 | uint32_t size; 13 | memcpy(&size, state, sizeof(size)); 14 | char* result = new char[size + 5]; 15 | memcpy(result, state, size + 5); 16 | return result; 17 | } 18 | 19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) { 20 | assert(code != kOk); 21 | const uint32_t len1 = msg.size(); 22 | const uint32_t len2 = msg2.size(); 23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 24 | char* result = new char[size + 5]; 25 | memcpy(result, &size, sizeof(size)); 26 | result[4] = static_cast(code); 27 | memcpy(result + 5, msg.data(), len1); 28 | if (len2) { 29 | result[5 + len1] = ':'; 30 | result[6 + len1] = ' '; 31 | memcpy(result + 7 + len1, msg2.data(), len2); 32 | } 33 | state_ = result; 34 | } 35 | 36 | std::string Status::ToString() const { 37 | if (state_ == NULL) { 38 | return "OK"; 39 | } else { 40 | char tmp[30]; 41 | const char* type; 42 | switch (code()) { 43 | case kOk: 44 | type = "OK"; 45 | break; 46 | case kNotFound: 47 | type = "NotFound: "; 48 | break; 49 | case kCorruption: 50 | type = "Corruption: "; 51 | break; 52 | case kNotSupported: 53 | type = "Not implemented: "; 54 | break; 55 | case kInvalidArgument: 56 | type = "Invalid argument: "; 57 | break; 58 | case kIOError: 59 | type = "IO error: "; 60 | break; 61 | default: 62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 63 | static_cast(code())); 64 | type = tmp; 65 | break; 66 | } 67 | std::string result(type); 68 | uint32_t length; 69 | memcpy(&length, state_, sizeof(length)); 70 | result.append(state_ + 5, length); 71 | return result; 72 | } 73 | } 74 | 75 | } // namespace leveldb 76 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leveldown", 3 | "description": "A Node.js LevelDB binding, primary backend for LevelUP", 4 | "version": "1.5.0", 5 | "contributors": [ 6 | "Rod Vagg (https://github.com/rvagg)", 7 | "John Chesley (https://github.com/chesles/)", 8 | "Jake Verbaten (https://github.com/raynos)", 9 | "Dominic Tarr (https://github.com/dominictarr)", 10 | "Max Ogden (https://github.com/maxogden)", 11 | "Lars-Magnus Skog (https://github.com/ralphtheninja)", 12 | "David Björklund (https://github.com/kesla)", 13 | "Julian Gruber (https://github.com/juliangruber)", 14 | "Paolo Fragomeni (https://github.com/hij1nx)", 15 | "Anton Whalley (https://github.com/No9)", 16 | "Matteo Collina (https://github.com/mcollina)", 17 | "Pedro Teixeira (https://github.com/pgte)", 18 | "James Halliday (https://github.com/substack)" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/level/leveldown.git" 23 | }, 24 | "homepage": "https://github.com/level/leveldown", 25 | "keywords": [ 26 | "leveldb", 27 | "level" 28 | ], 29 | "main": "leveldown.js", 30 | "dependencies": { 31 | "abstract-leveldown": "~2.6.1", 32 | "bindings": "~1.2.1", 33 | "fast-future": "~1.0.0", 34 | "nan": "~2.4.0", 35 | "prebuild": "^4.1.1" 36 | }, 37 | "devDependencies": { 38 | "async": "^2.0.1", 39 | "delayed": "~1.0.1", 40 | "du": "~0.1.0", 41 | "faucet": "0.0.1", 42 | "mkfiletree": "~1.0.1", 43 | "monotonic-timestamp": "~0.0.8", 44 | "node-uuid": "~1.4.3", 45 | "optimist": "~0.6.1", 46 | "readfiletree": "~0.0.1", 47 | "rimraf": "~2.5.0", 48 | "slump": "~2.0.0", 49 | "tape": "^4.5.1" 50 | }, 51 | "scripts": { 52 | "install": "prebuild --install", 53 | "test": "tape test/*-test.js | faucet", 54 | "rebuild": "prebuild --compile", 55 | "prebuild": "prebuild --all --strip --verbose" 56 | }, 57 | "license": "MIT", 58 | "gypfile": true 59 | } 60 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/table_cache.h: -------------------------------------------------------------------------------- 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 | // Thread-safe (provides internal synchronization) 6 | 7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 | 10 | #include 11 | #include 12 | #include "db/dbformat.h" 13 | #include "leveldb/cache.h" 14 | #include "leveldb/table.h" 15 | #include "port/port.h" 16 | 17 | namespace leveldb { 18 | 19 | class Env; 20 | 21 | class TableCache { 22 | public: 23 | TableCache(const std::string& dbname, const Options* options, int entries); 24 | ~TableCache(); 25 | 26 | // Return an iterator for the specified file number (the corresponding 27 | // file length must be exactly "file_size" bytes). If "tableptr" is 28 | // non-NULL, also sets "*tableptr" to point to the Table object 29 | // underlying the returned iterator, or NULL if no Table object underlies 30 | // the returned iterator. The returned "*tableptr" object is owned by 31 | // the cache and should not be deleted, and is valid for as long as the 32 | // returned iterator is live. 33 | Iterator* NewIterator(const ReadOptions& options, 34 | uint64_t file_number, 35 | uint64_t file_size, 36 | Table** tableptr = NULL); 37 | 38 | // If a seek to internal key "k" in specified file finds an entry, 39 | // call (*handle_result)(arg, found_key, found_value). 40 | Status Get(const ReadOptions& options, 41 | uint64_t file_number, 42 | uint64_t file_size, 43 | const Slice& k, 44 | void* arg, 45 | void (*handle_result)(void*, const Slice&, const Slice&)); 46 | 47 | // Evict any entry for the specified file number 48 | void Evict(uint64_t file_number); 49 | 50 | private: 51 | Env* const env_; 52 | const std::string dbname_; 53 | const Options* options_; 54 | Cache* cache_; 55 | 56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 57 | }; 58 | 59 | } // namespace leveldb 60 | 61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 62 | -------------------------------------------------------------------------------- /src/iterator.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #ifndef LD_ITERATOR_H 7 | #define LD_ITERATOR_H 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "leveldown.h" 14 | #include "database.h" 15 | #include "async.h" 16 | 17 | namespace leveldown { 18 | 19 | class Database; 20 | class AsyncWorker; 21 | 22 | class Iterator : public Nan::ObjectWrap { 23 | public: 24 | static void Init (); 25 | static v8::Local NewInstance ( 26 | v8::Local database 27 | , v8::Local id 28 | , v8::Local optionsObj 29 | ); 30 | 31 | Iterator ( 32 | Database* database 33 | , uint32_t id 34 | , leveldb::Slice* start 35 | , std::string* end 36 | , bool reverse 37 | , bool keys 38 | , bool values 39 | , int limit 40 | , std::string* lt 41 | , std::string* lte 42 | , std::string* gt 43 | , std::string* gte 44 | , bool fillCache 45 | , bool keyAsBuffer 46 | , bool valueAsBuffer 47 | , size_t highWaterMark 48 | ); 49 | 50 | ~Iterator (); 51 | 52 | bool IteratorNext (std::vector >& result); 53 | leveldb::Status IteratorStatus (); 54 | void IteratorEnd (); 55 | void Release (); 56 | 57 | private: 58 | Database* database; 59 | uint32_t id; 60 | leveldb::Iterator* dbIterator; 61 | leveldb::ReadOptions* options; 62 | leveldb::Slice* start; 63 | std::string* end; 64 | bool seeking; 65 | bool reverse; 66 | bool keys; 67 | bool values; 68 | int limit; 69 | std::string* lt; 70 | std::string* lte; 71 | std::string* gt; 72 | std::string* gte; 73 | int count; 74 | size_t highWaterMark; 75 | 76 | public: 77 | bool keyAsBuffer; 78 | bool valueAsBuffer; 79 | bool nexting; 80 | bool ended; 81 | AsyncWorker* endWorker; 82 | 83 | private: 84 | bool Read (std::string& key, std::string& value); 85 | bool GetIterator (); 86 | 87 | static NAN_METHOD(New); 88 | static NAN_METHOD(Seek); 89 | static NAN_METHOD(Next); 90 | static NAN_METHOD(End); 91 | }; 92 | 93 | } // namespace leveldown 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/arena.cc: -------------------------------------------------------------------------------- 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 | #include "util/arena.h" 6 | #include 7 | 8 | namespace leveldb { 9 | 10 | static const int kBlockSize = 4096; 11 | 12 | Arena::Arena() : memory_usage_(0) { 13 | alloc_ptr_ = NULL; // First allocation will allocate a block 14 | alloc_bytes_remaining_ = 0; 15 | } 16 | 17 | Arena::~Arena() { 18 | for (size_t i = 0; i < blocks_.size(); i++) { 19 | delete[] blocks_[i]; 20 | } 21 | } 22 | 23 | char* Arena::AllocateFallback(size_t bytes) { 24 | if (bytes > kBlockSize / 4) { 25 | // Object is more than a quarter of our block size. Allocate it separately 26 | // to avoid wasting too much space in leftover bytes. 27 | char* result = AllocateNewBlock(bytes); 28 | return result; 29 | } 30 | 31 | // We waste the remaining space in the current block. 32 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 33 | alloc_bytes_remaining_ = kBlockSize; 34 | 35 | char* result = alloc_ptr_; 36 | alloc_ptr_ += bytes; 37 | alloc_bytes_remaining_ -= bytes; 38 | return result; 39 | } 40 | 41 | char* Arena::AllocateAligned(size_t bytes) { 42 | const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8; 43 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 44 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 45 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 46 | size_t needed = bytes + slop; 47 | char* result; 48 | if (needed <= alloc_bytes_remaining_) { 49 | result = alloc_ptr_ + slop; 50 | alloc_ptr_ += needed; 51 | alloc_bytes_remaining_ -= needed; 52 | } else { 53 | // AllocateFallback always returned aligned memory 54 | result = AllocateFallback(bytes); 55 | } 56 | assert((reinterpret_cast(result) & (align-1)) == 0); 57 | return result; 58 | } 59 | 60 | char* Arena::AllocateNewBlock(size_t block_bytes) { 61 | char* result = new char[block_bytes]; 62 | blocks_.push_back(result); 63 | memory_usage_.NoBarrier_Store( 64 | reinterpret_cast(MemoryUsage() + block_bytes + sizeof(char*))); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/testutil.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 7 | 8 | #include "leveldb/env.h" 9 | #include "leveldb/slice.h" 10 | #include "util/random.h" 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | // Store in *dst a random string of length "len" and return a Slice that 16 | // references the generated data. 17 | extern Slice RandomString(Random* rnd, int len, std::string* dst); 18 | 19 | // Return a random key with the specified length that may contain interesting 20 | // characters (e.g. \x00, \xff, etc.). 21 | extern std::string RandomKey(Random* rnd, int len); 22 | 23 | // Store in *dst a string of length "len" that will compress to 24 | // "N*compressed_fraction" bytes and return a Slice that references 25 | // the generated data. 26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 27 | size_t len, std::string* dst); 28 | 29 | // A wrapper that allows injection of errors. 30 | class ErrorEnv : public EnvWrapper { 31 | public: 32 | bool writable_file_error_; 33 | int num_writable_file_errors_; 34 | 35 | ErrorEnv() : EnvWrapper(Env::Default()), 36 | writable_file_error_(false), 37 | num_writable_file_errors_(0) { } 38 | 39 | virtual Status NewWritableFile(const std::string& fname, 40 | WritableFile** result) { 41 | if (writable_file_error_) { 42 | ++num_writable_file_errors_; 43 | *result = NULL; 44 | return Status::IOError(fname, "fake error"); 45 | } 46 | return target()->NewWritableFile(fname, result); 47 | } 48 | 49 | virtual Status NewAppendableFile(const std::string& fname, 50 | WritableFile** result) { 51 | if (writable_file_error_) { 52 | ++num_writable_file_errors_; 53 | *result = NULL; 54 | return Status::IOError(fname, "fake error"); 55 | } 56 | return target()->NewAppendableFile(fname, result); 57 | } 58 | }; 59 | 60 | } // namespace test 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 64 | -------------------------------------------------------------------------------- /test/leak-tester-batch.js: -------------------------------------------------------------------------------- 1 | const BUFFERS = false 2 | , CHAINED = false 3 | 4 | var leveldown = require('..') 5 | , crypto = require('crypto') 6 | , assert = require('assert') 7 | , writeCount = 0 8 | , rssBase 9 | , db 10 | 11 | function print () { 12 | if (writeCount % 100 === 0) { 13 | if (typeof gc != 'undefined') 14 | gc() 15 | 16 | console.log( 17 | 'writeCount =' 18 | , writeCount 19 | , ', rss =' 20 | , Math.round(process.memoryUsage().rss / rssBase * 100) + '%' 21 | , Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M' 22 | , JSON.stringify([0,1,2,3,4,5,6].map(function (l) { 23 | return db.getProperty('leveldb.num-files-at-level' + l) 24 | })) 25 | ) 26 | } 27 | } 28 | 29 | var run = CHAINED 30 | ? function () { 31 | var batch = db.batch() 32 | , i = 0 33 | , key 34 | , value 35 | 36 | for (i = 0; i < 100; i++) { 37 | key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000)) 38 | if (BUFFERS) 39 | key = new Buffer(key) 40 | value = crypto.randomBytes(1024) 41 | if (!BUFFERS) 42 | value = value.toString('hex') 43 | batch.put(key, value) 44 | } 45 | 46 | batch.write(function (err) { 47 | assert(!err) 48 | process.nextTick(run) 49 | }) 50 | 51 | writeCount++ 52 | 53 | print() 54 | } 55 | : function () { 56 | var batch = [] 57 | , i 58 | , key 59 | , value 60 | 61 | for (i = 0; i < 100; i++) { 62 | key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000)) 63 | if (BUFFERS) 64 | key = new Buffer(key) 65 | value = crypto.randomBytes(1024) 66 | if (!BUFFERS) 67 | value = value.toString('hex') 68 | batch.push({ type: 'put', key: key, value: value }) 69 | } 70 | 71 | db.batch(batch, function (err) { 72 | assert(!err) 73 | process.nextTick(run) 74 | }) 75 | 76 | writeCount++ 77 | 78 | print() 79 | } 80 | 81 | leveldown.destroy('./leakydb', function () { 82 | db = leveldown('./leakydb') 83 | db.open({ xcacheSize: 0, xmaxOpenFiles: 10 }, function () { 84 | rssBase = process.memoryUsage().rss 85 | run() 86 | }) 87 | }) -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/iterator_wrapper.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | #include "leveldb/slice.h" 10 | 11 | namespace leveldb { 12 | 13 | // A internal wrapper class with an interface similar to Iterator that 14 | // caches the valid() and key() results for an underlying iterator. 15 | // This can help avoid virtual function calls and also gives better 16 | // cache locality. 17 | class IteratorWrapper { 18 | public: 19 | IteratorWrapper(): iter_(NULL), valid_(false) { } 20 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 21 | Set(iter); 22 | } 23 | ~IteratorWrapper() { delete iter_; } 24 | Iterator* iter() const { return iter_; } 25 | 26 | // Takes ownership of "iter" and will delete it when destroyed, or 27 | // when Set() is invoked again. 28 | void Set(Iterator* iter) { 29 | delete iter_; 30 | iter_ = iter; 31 | if (iter_ == NULL) { 32 | valid_ = false; 33 | } else { 34 | Update(); 35 | } 36 | } 37 | 38 | 39 | // Iterator interface methods 40 | bool Valid() const { return valid_; } 41 | Slice key() const { assert(Valid()); return key_; } 42 | Slice value() const { assert(Valid()); return iter_->value(); } 43 | // Methods below require iter() != NULL 44 | Status status() const { assert(iter_); return iter_->status(); } 45 | void Next() { assert(iter_); iter_->Next(); Update(); } 46 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 47 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 48 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 49 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 50 | 51 | private: 52 | void Update() { 53 | valid_ = iter_->Valid(); 54 | if (valid_) { 55 | key_ = iter_->key(); 56 | } 57 | } 58 | 59 | Iterator* iter_; 60 | bool valid_; 61 | Slice key_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 67 | -------------------------------------------------------------------------------- /bench/db-bench-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot < 9 | 10 | namespace leveldb { 11 | 12 | // A very simple random number generator. Not especially good at 13 | // generating truly random bits, but good enough for our needs in this 14 | // package. 15 | class Random { 16 | private: 17 | uint32_t seed_; 18 | public: 19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { 20 | // Avoid bad seeds. 21 | if (seed_ == 0 || seed_ == 2147483647L) { 22 | seed_ = 1; 23 | } 24 | } 25 | uint32_t Next() { 26 | static const uint32_t M = 2147483647L; // 2^31-1 27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 28 | // We are computing 29 | // seed_ = (seed_ * A) % M, where M = 2^31-1 30 | // 31 | // seed_ must not be zero or M, or else all subsequent computed values 32 | // will be zero or M respectively. For all other values, seed_ will end 33 | // up cycling through every number in [1,M-1] 34 | uint64_t product = seed_ * A; 35 | 36 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 37 | seed_ = static_cast((product >> 31) + (product & M)); 38 | // The first reduction may overflow by 1 bit, so we may need to 39 | // repeat. mod == M is not possible; using > allows the faster 40 | // sign-bit-based test. 41 | if (seed_ > M) { 42 | seed_ -= M; 43 | } 44 | return seed_; 45 | } 46 | // Returns a uniformly distributed value in the range [0..n-1] 47 | // REQUIRES: n > 0 48 | uint32_t Uniform(int n) { return Next() % n; } 49 | 50 | // Randomly returns true ~"1/n" of the time, and false otherwise. 51 | // REQUIRES: n > 0 52 | bool OneIn(int n) { return (Next() % n) == 0; } 53 | 54 | // Skewed: pick "base" uniformly from range [0,max_log] and then 55 | // return "base" random bits. The effect is to pick a number in the 56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 57 | uint32_t Skewed(int max_log) { 58 | return Uniform(1 << Uniform(max_log + 1)); 59 | } 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 65 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/table/filter_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | // A filter block is stored near the end of a Table file. It contains 6 | // filters (e.g., bloom filters) for all data blocks in the table combined 7 | // into a single filter block. 8 | 9 | #ifndef STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 10 | #define STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "leveldb/slice.h" 17 | #include "util/hash.h" 18 | 19 | namespace leveldb { 20 | 21 | class FilterPolicy; 22 | 23 | // A FilterBlockBuilder is used to construct all of the filters for a 24 | // particular Table. It generates a single string which is stored as 25 | // a special block in the Table. 26 | // 27 | // The sequence of calls to FilterBlockBuilder must match the regexp: 28 | // (StartBlock AddKey*)* Finish 29 | class FilterBlockBuilder { 30 | public: 31 | explicit FilterBlockBuilder(const FilterPolicy*); 32 | 33 | void StartBlock(uint64_t block_offset); 34 | void AddKey(const Slice& key); 35 | Slice Finish(); 36 | 37 | private: 38 | void GenerateFilter(); 39 | 40 | const FilterPolicy* policy_; 41 | std::string keys_; // Flattened key contents 42 | std::vector start_; // Starting index in keys_ of each key 43 | std::string result_; // Filter data computed so far 44 | std::vector tmp_keys_; // policy_->CreateFilter() argument 45 | std::vector filter_offsets_; 46 | 47 | // No copying allowed 48 | FilterBlockBuilder(const FilterBlockBuilder&); 49 | void operator=(const FilterBlockBuilder&); 50 | }; 51 | 52 | class FilterBlockReader { 53 | public: 54 | // REQUIRES: "contents" and *policy must stay live while *this is live. 55 | FilterBlockReader(const FilterPolicy* policy, const Slice& contents); 56 | bool KeyMayMatch(uint64_t block_offset, const Slice& key); 57 | 58 | private: 59 | const FilterPolicy* policy_; 60 | const char* data_; // Pointer to filter data (at block-start) 61 | const char* offset_; // Pointer to beginning of offset array (at block-end) 62 | size_t num_; // Number of entries in offset array 63 | size_t base_lg_; // Encoding parameter (see kFilterBaseLg in .cc file) 64 | }; 65 | 66 | } 67 | 68 | #endif // STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 69 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/comparator.cc: -------------------------------------------------------------------------------- 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 | #include 6 | #include 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/slice.h" 9 | #include "port/port.h" 10 | #include "util/logging.h" 11 | 12 | namespace leveldb { 13 | 14 | Comparator::~Comparator() { } 15 | 16 | namespace { 17 | class BytewiseComparatorImpl : public Comparator { 18 | public: 19 | BytewiseComparatorImpl() { } 20 | 21 | virtual const char* Name() const { 22 | return "leveldb.BytewiseComparator"; 23 | } 24 | 25 | virtual int Compare(const Slice& a, const Slice& b) const { 26 | return a.compare(b); 27 | } 28 | 29 | virtual void FindShortestSeparator( 30 | std::string* start, 31 | const Slice& limit) const { 32 | // Find length of common prefix 33 | size_t min_length = std::min(start->size(), limit.size()); 34 | size_t diff_index = 0; 35 | while ((diff_index < min_length) && 36 | ((*start)[diff_index] == limit[diff_index])) { 37 | diff_index++; 38 | } 39 | 40 | if (diff_index >= min_length) { 41 | // Do not shorten if one string is a prefix of the other 42 | } else { 43 | uint8_t diff_byte = static_cast((*start)[diff_index]); 44 | if (diff_byte < static_cast(0xff) && 45 | diff_byte + 1 < static_cast(limit[diff_index])) { 46 | (*start)[diff_index]++; 47 | start->resize(diff_index + 1); 48 | assert(Compare(*start, limit) < 0); 49 | } 50 | } 51 | } 52 | 53 | virtual void FindShortSuccessor(std::string* key) const { 54 | // Find first character that can be incremented 55 | size_t n = key->size(); 56 | for (size_t i = 0; i < n; i++) { 57 | const uint8_t byte = (*key)[i]; 58 | if (byte != static_cast(0xff)) { 59 | (*key)[i] = byte + 1; 60 | key->resize(i+1); 61 | return; 62 | } 63 | } 64 | // *key is a run of 0xffs. Leave it alone. 65 | } 66 | }; 67 | } // namespace 68 | 69 | static port::OnceType once = LEVELDB_ONCE_INIT; 70 | static const Comparator* bytewise; 71 | 72 | static void InitModule() { 73 | bytewise = new BytewiseComparatorImpl; 74 | } 75 | 76 | const Comparator* BytewiseComparator() { 77 | port::InitOnce(&once, InitModule); 78 | return bytewise; 79 | } 80 | 81 | } // namespace leveldb 82 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/builder.cc: -------------------------------------------------------------------------------- 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 | #include "db/builder.h" 6 | 7 | #include "db/filename.h" 8 | #include "db/dbformat.h" 9 | #include "db/table_cache.h" 10 | #include "db/version_edit.h" 11 | #include "leveldb/db.h" 12 | #include "leveldb/env.h" 13 | #include "leveldb/iterator.h" 14 | 15 | namespace leveldb { 16 | 17 | Status BuildTable(const std::string& dbname, 18 | Env* env, 19 | const Options& options, 20 | TableCache* table_cache, 21 | Iterator* iter, 22 | FileMetaData* meta) { 23 | Status s; 24 | meta->file_size = 0; 25 | iter->SeekToFirst(); 26 | 27 | std::string fname = TableFileName(dbname, meta->number); 28 | if (iter->Valid()) { 29 | WritableFile* file; 30 | s = env->NewWritableFile(fname, &file); 31 | if (!s.ok()) { 32 | return s; 33 | } 34 | 35 | TableBuilder* builder = new TableBuilder(options, file); 36 | meta->smallest.DecodeFrom(iter->key()); 37 | for (; iter->Valid(); iter->Next()) { 38 | Slice key = iter->key(); 39 | meta->largest.DecodeFrom(key); 40 | builder->Add(key, iter->value()); 41 | } 42 | 43 | // Finish and check for builder errors 44 | if (s.ok()) { 45 | s = builder->Finish(); 46 | if (s.ok()) { 47 | meta->file_size = builder->FileSize(); 48 | assert(meta->file_size > 0); 49 | } 50 | } else { 51 | builder->Abandon(); 52 | } 53 | delete builder; 54 | 55 | // Finish and check for file errors 56 | if (s.ok()) { 57 | s = file->Sync(); 58 | } 59 | if (s.ok()) { 60 | s = file->Close(); 61 | } 62 | delete file; 63 | file = NULL; 64 | 65 | if (s.ok()) { 66 | // Verify that the table is usable 67 | Iterator* it = table_cache->NewIterator(ReadOptions(), 68 | meta->number, 69 | meta->file_size); 70 | s = it->status(); 71 | delete it; 72 | } 73 | } 74 | 75 | // Check for input iterator errors 76 | if (!iter->status().ok()) { 77 | s = iter->status(); 78 | } 79 | 80 | if (s.ok() && meta->file_size > 0) { 81 | // Keep it 82 | } else { 83 | env->DeleteFile(fname); 84 | } 85 | return s; 86 | } 87 | 88 | } // namespace leveldb 89 | -------------------------------------------------------------------------------- /deps/snappy/snappy.gyp: -------------------------------------------------------------------------------- 1 | {'targets': [{ 2 | 'variables': { 3 | 'conditions': [ 4 | ['OS=="linux"', {'os_include': 'linux'}] 5 | , ['OS=="mac"', {'os_include': 'mac'}] 6 | , ['OS=="solaris"', {'os_include': 'solaris'}] 7 | , ['OS=="win"', {'os_include': 'win32'}] 8 | , ['OS=="freebsd"', {'os_include': 'freebsd'}] 9 | ] 10 | } 11 | , 'target_name': 'snappy' 12 | , 'type': 'static_library' 13 | # Overcomes an issue with the linker and thin .a files on SmartOS 14 | , 'standalone_static_library': 1 15 | , 'include_dirs': [ 16 | '<(os_include)' 17 | , 'snappy-1.1.1' 18 | ] 19 | , 'direct_dependent_settings': { 20 | 'include_dirs': [ 21 | 'snappy-1.1.1' 22 | ] 23 | } 24 | , 'defines': [ 25 | 'HAVE_CONFIG_H=1' 26 | ] 27 | , 'conditions': [ 28 | ['OS == "win"', { 29 | 'defines': [ 30 | '_HAS_EXCEPTIONS=0' 31 | ] 32 | , 'msvs_settings': { 33 | 'VCCLCompilerTool': { 34 | 'RuntimeTypeInfo': 'false' 35 | , 'EnableFunctionLevelLinking': 'true' 36 | , 'ExceptionHandling': '2' 37 | , 'DisableSpecificWarnings': [ '4355', '4530' ,'4267', '4244', '4506', '4018' ] 38 | } 39 | } 40 | }] 41 | , ['OS == "linux"', { 42 | 'cflags': [ 43 | '-Wno-sign-compare' 44 | , '-Wno-unused-function' 45 | ] 46 | , 'cflags!': [ '-fno-tree-vrp' ] 47 | }] 48 | , ['OS == "freebsd"', { 49 | 'cflags': [ 50 | '-Wno-sign-compare' 51 | , '-Wno-unused-function' 52 | ] 53 | }] 54 | , ['OS == "solaris"', { 55 | 'cflags': [ 56 | '-Wno-sign-compare' 57 | , '-Wno-unused-function' 58 | ] 59 | }] 60 | , ['OS == "mac"', { 61 | 'xcode_settings': { 62 | 'WARNING_CFLAGS': [ 63 | '-Wno-sign-compare' 64 | , '-Wno-unused-function' 65 | ] 66 | } 67 | }] 68 | ] 69 | , 'sources': [ 70 | 'snappy-1.1.1/snappy-internal.h' 71 | , 'snappy-1.1.1/snappy-sinksource.cc' 72 | , 'snappy-1.1.1/snappy-sinksource.h' 73 | , 'snappy-1.1.1/snappy-stubs-internal.cc' 74 | , 'snappy-1.1.1/snappy-stubs-internal.h' 75 | , 'snappy-1.1.1/snappy.cc' 76 | , 'snappy-1.1.1/snappy.h' 77 | ] 78 | }]} 79 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/include/leveldb/comparator.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Slice; 13 | 14 | // A Comparator object provides a total order across slices that are 15 | // used as keys in an sstable or a database. A Comparator implementation 16 | // must be thread-safe since leveldb may invoke its methods concurrently 17 | // from multiple threads. 18 | class Comparator { 19 | public: 20 | virtual ~Comparator(); 21 | 22 | // Three-way comparison. Returns value: 23 | // < 0 iff "a" < "b", 24 | // == 0 iff "a" == "b", 25 | // > 0 iff "a" > "b" 26 | virtual int Compare(const Slice& a, const Slice& b) const = 0; 27 | 28 | // The name of the comparator. Used to check for comparator 29 | // mismatches (i.e., a DB created with one comparator is 30 | // accessed using a different comparator. 31 | // 32 | // The client of this package should switch to a new name whenever 33 | // the comparator implementation changes in a way that will cause 34 | // the relative ordering of any two keys to change. 35 | // 36 | // Names starting with "leveldb." are reserved and should not be used 37 | // by any clients of this package. 38 | virtual const char* Name() const = 0; 39 | 40 | // Advanced functions: these are used to reduce the space requirements 41 | // for internal data structures like index blocks. 42 | 43 | // If *start < limit, changes *start to a short string in [start,limit). 44 | // Simple comparator implementations may return with *start unchanged, 45 | // i.e., an implementation of this method that does nothing is correct. 46 | virtual void FindShortestSeparator( 47 | std::string* start, 48 | const Slice& limit) const = 0; 49 | 50 | // Changes *key to a short string >= *key. 51 | // Simple comparator implementations may return with *key unchanged, 52 | // i.e., an implementation of this method that does nothing is correct. 53 | virtual void FindShortSuccessor(std::string* key) const = 0; 54 | }; 55 | 56 | // Return a builtin comparator that uses lexicographic byte-wise 57 | // ordering. The result remains the property of this module and 58 | // must not be deleted. 59 | extern const Comparator* BytewiseComparator(); 60 | 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 64 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/snappy-sinksource.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. 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. 28 | 29 | #include 30 | 31 | #include "snappy-sinksource.h" 32 | 33 | namespace snappy { 34 | 35 | Source::~Source() { } 36 | 37 | Sink::~Sink() { } 38 | 39 | char* Sink::GetAppendBuffer(size_t length, char* scratch) { 40 | return scratch; 41 | } 42 | 43 | ByteArraySource::~ByteArraySource() { } 44 | 45 | size_t ByteArraySource::Available() const { return left_; } 46 | 47 | const char* ByteArraySource::Peek(size_t* len) { 48 | *len = left_; 49 | return ptr_; 50 | } 51 | 52 | void ByteArraySource::Skip(size_t n) { 53 | left_ -= n; 54 | ptr_ += n; 55 | } 56 | 57 | UncheckedByteArraySink::~UncheckedByteArraySink() { } 58 | 59 | void UncheckedByteArraySink::Append(const char* data, size_t n) { 60 | // Do no copying if the caller filled in the result of GetAppendBuffer() 61 | if (data != dest_) { 62 | memcpy(dest_, data, n); 63 | } 64 | dest_ += n; 65 | } 66 | 67 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { 68 | return dest_; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /test/destroy-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | , fs = require('fs') 3 | , path = require('path') 4 | , mkfiletree = require('mkfiletree') 5 | , readfiletree = require('readfiletree') 6 | , testCommon = require('abstract-leveldown/testCommon') 7 | , leveldown = require('../') 8 | , makeTest = require('./make') 9 | 10 | test('test argument-less destroy() throws', function (t) { 11 | t.throws( 12 | leveldown.destroy 13 | , { name: 'Error', message: 'destroy() requires `location` and `callback` arguments' } 14 | , 'no-arg destroy() throws' 15 | ) 16 | t.end() 17 | }) 18 | 19 | test('test callback-less, 1-arg, destroy() throws', function (t) { 20 | t.throws( 21 | leveldown.destroy.bind(null, 'foo') 22 | , { name: 'Error', message: 'destroy() requires `location` and `callback` arguments' } 23 | , 'callback-less, 1-arg destroy() throws' 24 | ) 25 | t.end() 26 | }) 27 | 28 | test('test destroy non-existant directory', function (t) { 29 | leveldown.destroy('/1/2/3/4', function () { 30 | t.equal(arguments.length, 0, 'no arguments returned on callback') 31 | t.end() 32 | }) 33 | }) 34 | 35 | test('test destroy non leveldb directory', function (t) { 36 | var tree = { 37 | 'foo': 'FOO' 38 | , 'bar': { 'one': 'ONE', 'two': 'TWO', 'three': 'THREE' } 39 | } 40 | mkfiletree.makeTemp('destroy-test', tree, function (err, dir) { 41 | t.notOk(err, 'no error') 42 | leveldown.destroy(dir, function () { 43 | t.ok(arguments, 'no arguments') 44 | readfiletree(dir, function (err, actual) { 45 | t.notOk(err, 'no error') 46 | t.deepEqual(actual, tree, 'directory remains untouched') 47 | mkfiletree.cleanUp(function (err) { 48 | t.notOk(err, 'no error') 49 | t.end() 50 | }) 51 | }) 52 | }) 53 | }) 54 | }) 55 | 56 | makeTest('test destroy() cleans and removes leveldb-only dir', function (db, t, done, location) { 57 | db.close(function (err) { 58 | t.notOk(err, 'no error') 59 | leveldown.destroy(location, function () { 60 | t.notOk(fs.existsSync(), 'directory completely removed') 61 | done(false) 62 | }) 63 | }) 64 | }) 65 | 66 | makeTest('test destroy() cleans and removes only leveldb parts of a dir', function (db, t, done, location) { 67 | fs.writeFileSync(path.join(location, 'foo'), 'FOO') 68 | db.close(function (err) { 69 | t.notOk(err, 'no error') 70 | leveldown.destroy(location, function () { 71 | readfiletree(location, function (err, tree) { 72 | t.deepEqual(tree, { 'foo': 'FOO' }, 'non-leveldb files left intact') 73 | done(false) 74 | }) 75 | }) 76 | }) 77 | }) 78 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/env.cc: -------------------------------------------------------------------------------- 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 | #include "leveldb/env.h" 6 | 7 | namespace leveldb { 8 | 9 | Env::~Env() { 10 | } 11 | 12 | Status Env::NewAppendableFile(const std::string& fname, WritableFile** result) { 13 | return Status::NotSupported("NewAppendableFile", fname); 14 | } 15 | 16 | SequentialFile::~SequentialFile() { 17 | } 18 | 19 | RandomAccessFile::~RandomAccessFile() { 20 | } 21 | 22 | WritableFile::~WritableFile() { 23 | } 24 | 25 | Logger::~Logger() { 26 | } 27 | 28 | FileLock::~FileLock() { 29 | } 30 | 31 | void Log(Logger* info_log, const char* format, ...) { 32 | if (info_log != NULL) { 33 | va_list ap; 34 | va_start(ap, format); 35 | info_log->Logv(format, ap); 36 | va_end(ap); 37 | } 38 | } 39 | 40 | static Status DoWriteStringToFile(Env* env, const Slice& data, 41 | const std::string& fname, 42 | bool should_sync) { 43 | WritableFile* file; 44 | Status s = env->NewWritableFile(fname, &file); 45 | if (!s.ok()) { 46 | return s; 47 | } 48 | s = file->Append(data); 49 | if (s.ok() && should_sync) { 50 | s = file->Sync(); 51 | } 52 | if (s.ok()) { 53 | s = file->Close(); 54 | } 55 | delete file; // Will auto-close if we did not close above 56 | if (!s.ok()) { 57 | env->DeleteFile(fname); 58 | } 59 | return s; 60 | } 61 | 62 | Status WriteStringToFile(Env* env, const Slice& data, 63 | const std::string& fname) { 64 | return DoWriteStringToFile(env, data, fname, false); 65 | } 66 | 67 | Status WriteStringToFileSync(Env* env, const Slice& data, 68 | const std::string& fname) { 69 | return DoWriteStringToFile(env, data, fname, true); 70 | } 71 | 72 | Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { 73 | data->clear(); 74 | SequentialFile* file; 75 | Status s = env->NewSequentialFile(fname, &file); 76 | if (!s.ok()) { 77 | return s; 78 | } 79 | static const int kBufferSize = 8192; 80 | char* space = new char[kBufferSize]; 81 | while (true) { 82 | Slice fragment; 83 | s = file->Read(kBufferSize, &fragment, space); 84 | if (!s.ok()) { 85 | break; 86 | } 87 | data->append(fragment.data(), fragment.size()); 88 | if (fragment.empty()) { 89 | break; 90 | } 91 | } 92 | delete[] space; 93 | delete file; 94 | return s; 95 | } 96 | 97 | EnvWrapper::~EnvWrapper() { 98 | } 99 | 100 | } // namespace leveldb 101 | -------------------------------------------------------------------------------- /bench/memory.js: -------------------------------------------------------------------------------- 1 | var leveldown = require('../') 2 | 3 | var addr = '1111111111111111111114oLvT2' 4 | 5 | var db = leveldown(process.env.HOME + '/iterleak.db') 6 | var records = { 7 | 'w/a/14r6JPSJNzBXXJEM2jnmoybQCw3arseKuY/primary': '00', 8 | 'w/a/17nJuKqjTyAeujSJnPCebpSTEz1v9kjNKg/primary': '00', 9 | 'w/a/18cxWLCiJMESL34Ev1LJ2meGTgL14bAxfj/primary': '00', 10 | 'w/a/18pghEAnqCRTrjd7iyUj6XNKmSNx4fAywB/primary': '00', 11 | 'w/a/19EWPPzY6XkQeM7DxqJ4THbY3DGekRQKbt/primary': '00', 12 | 'w/a/1DKDeLQyBCkV5aMG15XbAdpwwHnxqw9rvY/primary': '00', 13 | 'w/a/1HSJAoU5TaGKhAJxwpTC1imiMM1ab8SFGW/primary': '00', 14 | 'w/a/1HkeafxVvStf2Np6wxUjkTpCt1gTDJSLpi/primary': '00', 15 | 'w/a/1Hr5JduPFdZ4n4dHBUqRoxLQEG4P93C658/primary': '00', 16 | 'w/a/1KATodK9Ko8MchJZzDxLhjWz4d8oAuCqEh/primary': '00', 17 | 'w/a/1NhRKhiAAJrmwXoLhL9dGG1z6oMiFGrxZ7/primary': '00', 18 | 'w/a/1yTq3DpyUNqUCxDttczGjufbEBKAXMTSq/primary': '00', 19 | 'w/w/primary': '00' 20 | } 21 | 22 | db.open({ 23 | createIfMissing: true, 24 | errorIfExists: false, 25 | compression: true, 26 | cacheSize: 8 << 20, 27 | writeBufferSize: 4 << 20, 28 | maxOpenFiles: 8192 29 | }, function(err) { 30 | if (err) 31 | throw err 32 | 33 | memory() 34 | 35 | var batch = db.batch(); 36 | Object.keys(records).forEach(function(key) { 37 | var value = new Buffer(records[key], 'hex') 38 | batch.put(key, value) 39 | }) 40 | 41 | batch.write(function(err) { 42 | if (err) 43 | throw err 44 | 45 | // This will leak roughly 1mb per call. 46 | setTimeout(function self() { 47 | var i = 0 48 | ;(function next(err) { 49 | if (err) 50 | throw err 51 | if (i++ >= 10000) { 52 | memory() 53 | return setTimeout(self, 1000) 54 | } 55 | iterate(addr, next) 56 | })() 57 | }, 1000) 58 | }) 59 | }) 60 | 61 | function memory() { 62 | var mem = process.memoryUsage() 63 | console.log('Memory: rss=%dmb, js-heap=%d/%dmb native-heap=%dmb', 64 | mb(mem.rss), 65 | mb(mem.heapUsed), 66 | mb(mem.heapTotal), 67 | mb(mem.rss - mem.heapTotal)) 68 | } 69 | 70 | function mb(size) { 71 | return size / 1024 / 1024 | 0 72 | } 73 | 74 | function iterate(address, callback) { 75 | var iter = db.iterator({ 76 | gte: 'w/a/' + address, 77 | lte: 'w/a/' + address + '~', 78 | keys: true, 79 | values: false, 80 | fillCache: false, 81 | keyAsBuffer: false 82 | }) 83 | 84 | ;(function next() { 85 | iter.next(function(err, key, value) { 86 | if (err) { 87 | return iter.end(function(e) { 88 | if (e) 89 | throw e 90 | callback(err) 91 | }) 92 | } 93 | 94 | if (key === undefined) 95 | return iter.end(callback) 96 | 97 | next() 98 | }) 99 | })() 100 | } 101 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/issues/issue178_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 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 | // Test for issue 178: a manual compaction causes deleted data to reappear. 6 | #include 7 | #include 8 | #include 9 | 10 | #include "leveldb/db.h" 11 | #include "leveldb/write_batch.h" 12 | #include "util/testharness.h" 13 | 14 | namespace { 15 | 16 | const int kNumKeys = 1100000; 17 | 18 | std::string Key1(int i) { 19 | char buf[100]; 20 | snprintf(buf, sizeof(buf), "my_key_%d", i); 21 | return buf; 22 | } 23 | 24 | std::string Key2(int i) { 25 | return Key1(i) + "_xxx"; 26 | } 27 | 28 | class Issue178 { }; 29 | 30 | TEST(Issue178, Test) { 31 | // Get rid of any state from an old run. 32 | std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test"; 33 | DestroyDB(dbpath, leveldb::Options()); 34 | 35 | // Open database. Disable compression since it affects the creation 36 | // of layers and the code below is trying to test against a very 37 | // specific scenario. 38 | leveldb::DB* db; 39 | leveldb::Options db_options; 40 | db_options.create_if_missing = true; 41 | db_options.compression = leveldb::kNoCompression; 42 | ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db)); 43 | 44 | // create first key range 45 | leveldb::WriteBatch batch; 46 | for (size_t i = 0; i < kNumKeys; i++) { 47 | batch.Put(Key1(i), "value for range 1 key"); 48 | } 49 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 50 | 51 | // create second key range 52 | batch.Clear(); 53 | for (size_t i = 0; i < kNumKeys; i++) { 54 | batch.Put(Key2(i), "value for range 2 key"); 55 | } 56 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 57 | 58 | // delete second key range 59 | batch.Clear(); 60 | for (size_t i = 0; i < kNumKeys; i++) { 61 | batch.Delete(Key2(i)); 62 | } 63 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 64 | 65 | // compact database 66 | std::string start_key = Key1(0); 67 | std::string end_key = Key1(kNumKeys - 1); 68 | leveldb::Slice least(start_key.data(), start_key.size()); 69 | leveldb::Slice greatest(end_key.data(), end_key.size()); 70 | 71 | // commenting out the line below causes the example to work correctly 72 | db->CompactRange(&least, &greatest); 73 | 74 | // count the keys 75 | leveldb::Iterator* iter = db->NewIterator(leveldb::ReadOptions()); 76 | size_t num_keys = 0; 77 | for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { 78 | num_keys++; 79 | } 80 | delete iter; 81 | ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys"; 82 | 83 | // close database 84 | delete db; 85 | DestroyDB(dbpath, leveldb::Options()); 86 | } 87 | 88 | } // anonymous namespace 89 | 90 | int main(int argc, char** argv) { 91 | return leveldb::test::RunAllTests(); 92 | } 93 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/memtable.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_ 6 | #define STORAGE_LEVELDB_DB_MEMTABLE_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | #include "db/skiplist.h" 12 | #include "util/arena.h" 13 | 14 | namespace leveldb { 15 | 16 | class InternalKeyComparator; 17 | class Mutex; 18 | class MemTableIterator; 19 | 20 | class MemTable { 21 | public: 22 | // MemTables are reference counted. The initial reference count 23 | // is zero and the caller must call Ref() at least once. 24 | explicit MemTable(const InternalKeyComparator& comparator); 25 | 26 | // Increase reference count. 27 | void Ref() { ++refs_; } 28 | 29 | // Drop reference count. Delete if no more references exist. 30 | void Unref() { 31 | --refs_; 32 | assert(refs_ >= 0); 33 | if (refs_ <= 0) { 34 | delete this; 35 | } 36 | } 37 | 38 | // Returns an estimate of the number of bytes of data in use by this 39 | // data structure. It is safe to call when MemTable is being modified. 40 | size_t ApproximateMemoryUsage(); 41 | 42 | // Return an iterator that yields the contents of the memtable. 43 | // 44 | // The caller must ensure that the underlying MemTable remains live 45 | // while the returned iterator is live. The keys returned by this 46 | // iterator are internal keys encoded by AppendInternalKey in the 47 | // db/format.{h,cc} module. 48 | Iterator* NewIterator(); 49 | 50 | // Add an entry into memtable that maps key to value at the 51 | // specified sequence number and with the specified type. 52 | // Typically value will be empty if type==kTypeDeletion. 53 | void Add(SequenceNumber seq, ValueType type, 54 | const Slice& key, 55 | const Slice& value); 56 | 57 | // If memtable contains a value for key, store it in *value and return true. 58 | // If memtable contains a deletion for key, store a NotFound() error 59 | // in *status and return true. 60 | // Else, return false. 61 | bool Get(const LookupKey& key, std::string* value, Status* s); 62 | 63 | private: 64 | ~MemTable(); // Private since only Unref() should be used to delete it 65 | 66 | struct KeyComparator { 67 | const InternalKeyComparator comparator; 68 | explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { } 69 | int operator()(const char* a, const char* b) const; 70 | }; 71 | friend class MemTableIterator; 72 | friend class MemTableBackwardIterator; 73 | 74 | typedef SkipList Table; 75 | 76 | KeyComparator comparator_; 77 | int refs_; 78 | Arena arena_; 79 | Table table_; 80 | 81 | // No copying allowed 82 | MemTable(const MemTable&); 83 | void operator=(const MemTable&); 84 | }; 85 | 86 | } // namespace leveldb 87 | 88 | #endif // STORAGE_LEVELDB_DB_MEMTABLE_H_ 89 | -------------------------------------------------------------------------------- /leveldown.js: -------------------------------------------------------------------------------- 1 | const util = require('util') 2 | , AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN 3 | 4 | , binding = require('bindings')('leveldown').leveldown 5 | 6 | , ChainedBatch = require('./chained-batch') 7 | , Iterator = require('./iterator') 8 | 9 | 10 | function LevelDOWN (location) { 11 | if (!(this instanceof LevelDOWN)) 12 | return new LevelDOWN(location) 13 | 14 | AbstractLevelDOWN.call(this, location) 15 | this.binding = binding(location) 16 | } 17 | 18 | util.inherits(LevelDOWN, AbstractLevelDOWN) 19 | 20 | 21 | LevelDOWN.prototype._open = function (options, callback) { 22 | this.binding.open(options, callback) 23 | } 24 | 25 | 26 | LevelDOWN.prototype._close = function (callback) { 27 | this.binding.close(callback) 28 | } 29 | 30 | 31 | LevelDOWN.prototype._put = function (key, value, options, callback) { 32 | this.binding.put(key, value, options, callback) 33 | } 34 | 35 | 36 | LevelDOWN.prototype._get = function (key, options, callback) { 37 | this.binding.get(key, options, callback) 38 | } 39 | 40 | 41 | LevelDOWN.prototype._del = function (key, options, callback) { 42 | this.binding.del(key, options, callback) 43 | } 44 | 45 | 46 | LevelDOWN.prototype._chainedBatch = function () { 47 | return new ChainedBatch(this) 48 | } 49 | 50 | 51 | LevelDOWN.prototype._batch = function (operations, options, callback) { 52 | return this.binding.batch(operations, options, callback) 53 | } 54 | 55 | 56 | LevelDOWN.prototype._approximateSize = function (start, end, callback) { 57 | this.binding.approximateSize(start, end, callback) 58 | } 59 | 60 | 61 | LevelDOWN.prototype.getProperty = function (property) { 62 | if (typeof property != 'string') 63 | throw new Error('getProperty() requires a valid `property` argument') 64 | 65 | return this.binding.getProperty(property) 66 | } 67 | 68 | 69 | LevelDOWN.prototype._iterator = function (options) { 70 | return new Iterator(this, options) 71 | } 72 | 73 | 74 | LevelDOWN.destroy = function (location, callback) { 75 | if (arguments.length < 2) 76 | throw new Error('destroy() requires `location` and `callback` arguments') 77 | 78 | if (typeof location != 'string') 79 | throw new Error('destroy() requires a location string argument') 80 | 81 | if (typeof callback != 'function') 82 | throw new Error('destroy() requires a callback function argument') 83 | 84 | binding.destroy(location, callback) 85 | } 86 | 87 | 88 | LevelDOWN.repair = function (location, callback) { 89 | if (arguments.length < 2) 90 | throw new Error('repair() requires `location` and `callback` arguments') 91 | 92 | if (typeof location != 'string') 93 | throw new Error('repair() requires a location string argument') 94 | 95 | if (typeof callback != 'function') 96 | throw new Error('repair() requires a callback function argument') 97 | 98 | binding.repair(location, callback) 99 | } 100 | 101 | 102 | module.exports = LevelDOWN 103 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/env_test.cc: -------------------------------------------------------------------------------- 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 | #include "leveldb/env.h" 6 | 7 | #include "port/port.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | static const int kDelayMicros = 100000; 13 | 14 | class EnvPosixTest { 15 | private: 16 | port::Mutex mu_; 17 | std::string events_; 18 | 19 | public: 20 | Env* env_; 21 | EnvPosixTest() : env_(Env::Default()) { } 22 | }; 23 | 24 | static void SetBool(void* ptr) { 25 | reinterpret_cast(ptr)->NoBarrier_Store(ptr); 26 | } 27 | 28 | TEST(EnvPosixTest, RunImmediately) { 29 | port::AtomicPointer called (NULL); 30 | env_->Schedule(&SetBool, &called); 31 | Env::Default()->SleepForMicroseconds(kDelayMicros); 32 | ASSERT_TRUE(called.NoBarrier_Load() != NULL); 33 | } 34 | 35 | TEST(EnvPosixTest, RunMany) { 36 | port::AtomicPointer last_id (NULL); 37 | 38 | struct CB { 39 | port::AtomicPointer* last_id_ptr; // Pointer to shared slot 40 | uintptr_t id; // Order# for the execution of this callback 41 | 42 | CB(port::AtomicPointer* p, int i) : last_id_ptr(p), id(i) { } 43 | 44 | static void Run(void* v) { 45 | CB* cb = reinterpret_cast(v); 46 | void* cur = cb->last_id_ptr->NoBarrier_Load(); 47 | ASSERT_EQ(cb->id-1, reinterpret_cast(cur)); 48 | cb->last_id_ptr->Release_Store(reinterpret_cast(cb->id)); 49 | } 50 | }; 51 | 52 | // Schedule in different order than start time 53 | CB cb1(&last_id, 1); 54 | CB cb2(&last_id, 2); 55 | CB cb3(&last_id, 3); 56 | CB cb4(&last_id, 4); 57 | env_->Schedule(&CB::Run, &cb1); 58 | env_->Schedule(&CB::Run, &cb2); 59 | env_->Schedule(&CB::Run, &cb3); 60 | env_->Schedule(&CB::Run, &cb4); 61 | 62 | Env::Default()->SleepForMicroseconds(kDelayMicros); 63 | void* cur = last_id.Acquire_Load(); 64 | ASSERT_EQ(4, reinterpret_cast(cur)); 65 | } 66 | 67 | struct State { 68 | port::Mutex mu; 69 | int val; 70 | int num_running; 71 | }; 72 | 73 | static void ThreadBody(void* arg) { 74 | State* s = reinterpret_cast(arg); 75 | s->mu.Lock(); 76 | s->val += 1; 77 | s->num_running -= 1; 78 | s->mu.Unlock(); 79 | } 80 | 81 | TEST(EnvPosixTest, StartThread) { 82 | State state; 83 | state.val = 0; 84 | state.num_running = 3; 85 | for (int i = 0; i < 3; i++) { 86 | env_->StartThread(&ThreadBody, &state); 87 | } 88 | while (true) { 89 | state.mu.Lock(); 90 | int num = state.num_running; 91 | state.mu.Unlock(); 92 | if (num == 0) { 93 | break; 94 | } 95 | Env::Default()->SleepForMicroseconds(kDelayMicros); 96 | } 97 | ASSERT_EQ(state.val, 3); 98 | } 99 | 100 | } // namespace leveldb 101 | 102 | int main(int argc, char** argv) { 103 | return leveldb::test::RunAllTests(); 104 | } 105 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/doc/log_format.txt: -------------------------------------------------------------------------------- 1 | The log file contents are a sequence of 32KB blocks. The only 2 | exception is that the tail of the file may contain a partial block. 3 | 4 | Each block consists of a sequence of records: 5 | block := record* trailer? 6 | record := 7 | checksum: uint32 // crc32c of type and data[] ; little-endian 8 | length: uint16 // little-endian 9 | type: uint8 // One of FULL, FIRST, MIDDLE, LAST 10 | data: uint8[length] 11 | 12 | A record never starts within the last six bytes of a block (since it 13 | won't fit). Any leftover bytes here form the trailer, which must 14 | consist entirely of zero bytes and must be skipped by readers. 15 | 16 | Aside: if exactly seven bytes are left in the current block, and a new 17 | non-zero length record is added, the writer must emit a FIRST record 18 | (which contains zero bytes of user data) to fill up the trailing seven 19 | bytes of the block and then emit all of the user data in subsequent 20 | blocks. 21 | 22 | More types may be added in the future. Some Readers may skip record 23 | types they do not understand, others may report that some data was 24 | skipped. 25 | 26 | FULL == 1 27 | FIRST == 2 28 | MIDDLE == 3 29 | LAST == 4 30 | 31 | The FULL record contains the contents of an entire user record. 32 | 33 | FIRST, MIDDLE, LAST are types used for user records that have been 34 | split into multiple fragments (typically because of block boundaries). 35 | FIRST is the type of the first fragment of a user record, LAST is the 36 | type of the last fragment of a user record, and MIDDLE is the type of 37 | all interior fragments of a user record. 38 | 39 | Example: consider a sequence of user records: 40 | A: length 1000 41 | B: length 97270 42 | C: length 8000 43 | A will be stored as a FULL record in the first block. 44 | 45 | B will be split into three fragments: first fragment occupies the rest 46 | of the first block, second fragment occupies the entirety of the 47 | second block, and the third fragment occupies a prefix of the third 48 | block. This will leave six bytes free in the third block, which will 49 | be left empty as the trailer. 50 | 51 | C will be stored as a FULL record in the fourth block. 52 | 53 | =================== 54 | 55 | Some benefits over the recordio format: 56 | 57 | (1) We do not need any heuristics for resyncing - just go to next 58 | block boundary and scan. If there is a corruption, skip to the next 59 | block. As a side-benefit, we do not get confused when part of the 60 | contents of one log file are embedded as a record inside another log 61 | file. 62 | 63 | (2) Splitting at approximate boundaries (e.g., for mapreduce) is 64 | simple: find the next block boundary and skip records until we 65 | hit a FULL or FIRST record. 66 | 67 | (3) We do not need extra buffering for large records. 68 | 69 | Some downsides compared to recordio format: 70 | 71 | (1) No packing of tiny records. This could be fixed by adding a new 72 | record type, so it is a shortcoming of the current implementation, 73 | not necessarily the format. 74 | 75 | (2) No compression. Again, this could be fixed by adding new record types. 76 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/posix_logger.h: -------------------------------------------------------------------------------- 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 | // Logger implementation that can be shared by all environments 6 | // where enough posix functionality is available. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 9 | #define STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "leveldb/env.h" 16 | 17 | namespace leveldb { 18 | 19 | class PosixLogger : public Logger { 20 | private: 21 | FILE* file_; 22 | uint64_t (*gettid_)(); // Return the thread id for the current thread 23 | public: 24 | PosixLogger(FILE* f, uint64_t (*gettid)()) : file_(f), gettid_(gettid) { } 25 | virtual ~PosixLogger() { 26 | fclose(file_); 27 | } 28 | virtual void Logv(const char* format, va_list ap) { 29 | const uint64_t thread_id = (*gettid_)(); 30 | 31 | // We try twice: the first time with a fixed-size stack allocated buffer, 32 | // and the second time with a much larger dynamically allocated buffer. 33 | char buffer[500]; 34 | for (int iter = 0; iter < 2; iter++) { 35 | char* base; 36 | int bufsize; 37 | if (iter == 0) { 38 | bufsize = sizeof(buffer); 39 | base = buffer; 40 | } else { 41 | bufsize = 30000; 42 | base = new char[bufsize]; 43 | } 44 | char* p = base; 45 | char* limit = base + bufsize; 46 | 47 | struct timeval now_tv; 48 | gettimeofday(&now_tv, NULL); 49 | const time_t seconds = now_tv.tv_sec; 50 | struct tm t; 51 | localtime_r(&seconds, &t); 52 | p += snprintf(p, limit - p, 53 | "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", 54 | t.tm_year + 1900, 55 | t.tm_mon + 1, 56 | t.tm_mday, 57 | t.tm_hour, 58 | t.tm_min, 59 | t.tm_sec, 60 | static_cast(now_tv.tv_usec), 61 | static_cast(thread_id)); 62 | 63 | // Print the message 64 | if (p < limit) { 65 | va_list backup_ap; 66 | va_copy(backup_ap, ap); 67 | p += vsnprintf(p, limit - p, format, backup_ap); 68 | va_end(backup_ap); 69 | } 70 | 71 | // Truncate to available space if necessary 72 | if (p >= limit) { 73 | if (iter == 0) { 74 | continue; // Try again with larger buffer 75 | } else { 76 | p = limit - 1; 77 | } 78 | } 79 | 80 | // Add newline if necessary 81 | if (p == base || p[-1] != '\n') { 82 | *p++ = '\n'; 83 | } 84 | 85 | assert(p <= limit); 86 | fwrite(base, 1, p - base, file_); 87 | fflush(file_); 88 | if (base != buffer) { 89 | delete[] base; 90 | } 91 | break; 92 | } 93 | } 94 | }; 95 | 96 | } // namespace leveldb 97 | 98 | #endif // STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 99 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/include/leveldb/filter_policy.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | // A database can be configured with a custom FilterPolicy object. 6 | // This object is responsible for creating a small filter from a set 7 | // of keys. These filters are stored in leveldb and are consulted 8 | // automatically by leveldb to decide whether or not to read some 9 | // information from disk. In many cases, a filter can cut down the 10 | // number of disk seeks form a handful to a single disk seek per 11 | // DB::Get() call. 12 | // 13 | // Most people will want to use the builtin bloom filter support (see 14 | // NewBloomFilterPolicy() below). 15 | 16 | #ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 17 | #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 18 | 19 | #include 20 | 21 | namespace leveldb { 22 | 23 | class Slice; 24 | 25 | class FilterPolicy { 26 | public: 27 | virtual ~FilterPolicy(); 28 | 29 | // Return the name of this policy. Note that if the filter encoding 30 | // changes in an incompatible way, the name returned by this method 31 | // must be changed. Otherwise, old incompatible filters may be 32 | // passed to methods of this type. 33 | virtual const char* Name() const = 0; 34 | 35 | // keys[0,n-1] contains a list of keys (potentially with duplicates) 36 | // that are ordered according to the user supplied comparator. 37 | // Append a filter that summarizes keys[0,n-1] to *dst. 38 | // 39 | // Warning: do not change the initial contents of *dst. Instead, 40 | // append the newly constructed filter to *dst. 41 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) 42 | const = 0; 43 | 44 | // "filter" contains the data appended by a preceding call to 45 | // CreateFilter() on this class. This method must return true if 46 | // the key was in the list of keys passed to CreateFilter(). 47 | // This method may return true or false if the key was not on the 48 | // list, but it should aim to return false with a high probability. 49 | virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const = 0; 50 | }; 51 | 52 | // Return a new filter policy that uses a bloom filter with approximately 53 | // the specified number of bits per key. A good value for bits_per_key 54 | // is 10, which yields a filter with ~ 1% false positive rate. 55 | // 56 | // Callers must delete the result after any database that is using the 57 | // result has been closed. 58 | // 59 | // Note: if you are using a custom comparator that ignores some parts 60 | // of the keys being compared, you must not use NewBloomFilterPolicy() 61 | // and must provide your own FilterPolicy that also ignores the 62 | // corresponding parts of the keys. For example, if the comparator 63 | // ignores trailing spaces, it would be incorrect to use a 64 | // FilterPolicy (like NewBloomFilterPolicy) that does not ignore 65 | // trailing spaces in keys. 66 | extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key); 67 | 68 | } 69 | 70 | #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 71 | -------------------------------------------------------------------------------- /src/iterator_async.cc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2016 LevelDOWN contributors 2 | * See list at 3 | * MIT License 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include "database.h" 10 | #include "leveldown.h" 11 | #include "async.h" 12 | #include "iterator_async.h" 13 | 14 | namespace leveldown { 15 | 16 | /** NEXT-MULTI WORKER **/ 17 | 18 | NextWorker::NextWorker ( 19 | Iterator* iterator 20 | , Nan::Callback *callback 21 | , void (*localCallback)(Iterator*) 22 | ) : AsyncWorker(NULL, callback) 23 | , iterator(iterator) 24 | , localCallback(localCallback) 25 | {}; 26 | 27 | NextWorker::~NextWorker () {} 28 | 29 | void NextWorker::Execute () { 30 | ok = iterator->IteratorNext(result); 31 | if (!ok) 32 | SetStatus(iterator->IteratorStatus()); 33 | } 34 | 35 | void NextWorker::HandleOKCallback () { 36 | Nan::HandleScope scope; 37 | size_t idx = 0; 38 | 39 | size_t arraySize = result.size() * 2; 40 | v8::Local returnArray = Nan::New(arraySize); 41 | 42 | for(idx = 0; idx < result.size(); ++idx) { 43 | std::pair row = result[idx]; 44 | std::string key = row.first; 45 | std::string value = row.second; 46 | 47 | v8::Local returnKey; 48 | if (iterator->keyAsBuffer) { 49 | //TODO: use NewBuffer, see database_async.cc 50 | returnKey = Nan::CopyBuffer((char*)key.data(), key.size()).ToLocalChecked(); 51 | } else { 52 | returnKey = Nan::New((char*)key.data(), key.size()).ToLocalChecked(); 53 | } 54 | 55 | v8::Local returnValue; 56 | if (iterator->valueAsBuffer) { 57 | //TODO: use NewBuffer, see database_async.cc 58 | returnValue = Nan::CopyBuffer((char*)value.data(), value.size()).ToLocalChecked(); 59 | } else { 60 | returnValue = Nan::New((char*)value.data(), value.size()).ToLocalChecked(); 61 | } 62 | 63 | // put the key & value in a descending order, so that they can be .pop:ed in javascript-land 64 | returnArray->Set(Nan::New(static_cast(arraySize - idx * 2 - 1)), returnKey); 65 | returnArray->Set(Nan::New(static_cast(arraySize - idx * 2 - 2)), returnValue); 66 | } 67 | 68 | // clean up & handle the next/end state see iterator.cc/checkEndCallback 69 | localCallback(iterator); 70 | 71 | v8::Local argv[] = { 72 | Nan::Null() 73 | , returnArray 74 | // when ok === false all data has been read, so it's then finished 75 | , Nan::New(!ok) 76 | }; 77 | callback->Call(3, argv); 78 | } 79 | 80 | /** END WORKER **/ 81 | 82 | EndWorker::EndWorker ( 83 | Iterator* iterator 84 | , Nan::Callback *callback 85 | ) : AsyncWorker(NULL, callback) 86 | , iterator(iterator) 87 | {}; 88 | 89 | EndWorker::~EndWorker () { } 90 | 91 | void EndWorker::Execute () { 92 | iterator->IteratorEnd(); 93 | } 94 | 95 | void EndWorker::HandleOKCallback () { 96 | iterator->Release(); 97 | callback->Call(0, NULL); 98 | } 99 | 100 | } // namespace leveldown 101 | -------------------------------------------------------------------------------- /deps/snappy/linux/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/mac/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/win32/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 0 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 1 49 | #define SNAPPY_PATCHLEVEL 1 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 0 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/freebsd/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/solaris/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/util/bloom.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 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 | #include "leveldb/filter_policy.h" 6 | 7 | #include "leveldb/slice.h" 8 | #include "util/hash.h" 9 | 10 | namespace leveldb { 11 | 12 | namespace { 13 | static uint32_t BloomHash(const Slice& key) { 14 | return Hash(key.data(), key.size(), 0xbc9f1d34); 15 | } 16 | 17 | class BloomFilterPolicy : public FilterPolicy { 18 | private: 19 | size_t bits_per_key_; 20 | size_t k_; 21 | 22 | public: 23 | explicit BloomFilterPolicy(int bits_per_key) 24 | : bits_per_key_(bits_per_key) { 25 | // We intentionally round down to reduce probing cost a little bit 26 | k_ = static_cast(bits_per_key * 0.69); // 0.69 =~ ln(2) 27 | if (k_ < 1) k_ = 1; 28 | if (k_ > 30) k_ = 30; 29 | } 30 | 31 | virtual const char* Name() const { 32 | return "leveldb.BuiltinBloomFilter2"; 33 | } 34 | 35 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const { 36 | // Compute bloom filter size (in both bits and bytes) 37 | size_t bits = n * bits_per_key_; 38 | 39 | // For small n, we can see a very high false positive rate. Fix it 40 | // by enforcing a minimum bloom filter length. 41 | if (bits < 64) bits = 64; 42 | 43 | size_t bytes = (bits + 7) / 8; 44 | bits = bytes * 8; 45 | 46 | const size_t init_size = dst->size(); 47 | dst->resize(init_size + bytes, 0); 48 | dst->push_back(static_cast(k_)); // Remember # of probes in filter 49 | char* array = &(*dst)[init_size]; 50 | for (int i = 0; i < n; i++) { 51 | // Use double-hashing to generate a sequence of hash values. 52 | // See analysis in [Kirsch,Mitzenmacher 2006]. 53 | uint32_t h = BloomHash(keys[i]); 54 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits 55 | for (size_t j = 0; j < k_; j++) { 56 | const uint32_t bitpos = h % bits; 57 | array[bitpos/8] |= (1 << (bitpos % 8)); 58 | h += delta; 59 | } 60 | } 61 | } 62 | 63 | virtual bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const { 64 | const size_t len = bloom_filter.size(); 65 | if (len < 2) return false; 66 | 67 | const char* array = bloom_filter.data(); 68 | const size_t bits = (len - 1) * 8; 69 | 70 | // Use the encoded k so that we can read filters generated by 71 | // bloom filters created using different parameters. 72 | const size_t k = array[len-1]; 73 | if (k > 30) { 74 | // Reserved for potentially new encodings for short bloom filters. 75 | // Consider it a match. 76 | return true; 77 | } 78 | 79 | uint32_t h = BloomHash(key); 80 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits 81 | for (size_t j = 0; j < k; j++) { 82 | const uint32_t bitpos = h % bits; 83 | if ((array[bitpos/8] & (1 << (bitpos % 8))) == 0) return false; 84 | h += delta; 85 | } 86 | return true; 87 | } 88 | }; 89 | } 90 | 91 | const FilterPolicy* NewBloomFilterPolicy(int bits_per_key) { 92 | return new BloomFilterPolicy(bits_per_key); 93 | } 94 | 95 | } // namespace leveldb 96 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/include/leveldb/table.h: -------------------------------------------------------------------------------- 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 | #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_TABLE_H_ 7 | 8 | #include 9 | #include "leveldb/iterator.h" 10 | 11 | namespace leveldb { 12 | 13 | class Block; 14 | class BlockHandle; 15 | class Footer; 16 | struct Options; 17 | class RandomAccessFile; 18 | struct ReadOptions; 19 | class TableCache; 20 | 21 | // A Table is a sorted map from strings to strings. Tables are 22 | // immutable and persistent. A Table may be safely accessed from 23 | // multiple threads without external synchronization. 24 | class Table { 25 | public: 26 | // Attempt to open the table that is stored in bytes [0..file_size) 27 | // of "file", and read the metadata entries necessary to allow 28 | // retrieving data from the table. 29 | // 30 | // If successful, returns ok and sets "*table" to the newly opened 31 | // table. The client should delete "*table" when no longer needed. 32 | // If there was an error while initializing the table, sets "*table" 33 | // to NULL and returns a non-ok status. Does not take ownership of 34 | // "*source", but the client must ensure that "source" remains live 35 | // for the duration of the returned table's lifetime. 36 | // 37 | // *file must remain live while this Table is in use. 38 | static Status Open(const Options& options, 39 | RandomAccessFile* file, 40 | uint64_t file_size, 41 | Table** table); 42 | 43 | ~Table(); 44 | 45 | // Returns a new iterator over the table contents. 46 | // The result of NewIterator() is initially invalid (caller must 47 | // call one of the Seek methods on the iterator before using it). 48 | Iterator* NewIterator(const ReadOptions&) const; 49 | 50 | // Given a key, return an approximate byte offset in the file where 51 | // the data for that key begins (or would begin if the key were 52 | // present in the file). The returned value is in terms of file 53 | // bytes, and so includes effects like compression of the underlying data. 54 | // E.g., the approximate offset of the last key in the table will 55 | // be close to the file length. 56 | uint64_t ApproximateOffsetOf(const Slice& key) const; 57 | 58 | private: 59 | struct Rep; 60 | Rep* rep_; 61 | 62 | explicit Table(Rep* rep) { rep_ = rep; } 63 | static Iterator* BlockReader(void*, const ReadOptions&, const Slice&); 64 | 65 | // Calls (*handle_result)(arg, ...) with the entry found after a call 66 | // to Seek(key). May not make such a call if filter policy says 67 | // that key is not present. 68 | friend class TableCache; 69 | Status InternalGet( 70 | const ReadOptions&, const Slice& key, 71 | void* arg, 72 | void (*handle_result)(void* arg, const Slice& k, const Slice& v)); 73 | 74 | 75 | void ReadMeta(const Footer& footer); 76 | void ReadFilter(const Slice& filter_handle_value); 77 | 78 | // No copying allowed 79 | Table(const Table&); 80 | void operator=(const Table&); 81 | }; 82 | 83 | } // namespace leveldb 84 | 85 | #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_ 86 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-1.19/db/filename.h: -------------------------------------------------------------------------------- 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 | // File names used by DB code 6 | 7 | #ifndef STORAGE_LEVELDB_DB_FILENAME_H_ 8 | #define STORAGE_LEVELDB_DB_FILENAME_H_ 9 | 10 | #include 11 | #include 12 | #include "leveldb/slice.h" 13 | #include "leveldb/status.h" 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Env; 19 | 20 | enum FileType { 21 | kLogFile, 22 | kDBLockFile, 23 | kTableFile, 24 | kDescriptorFile, 25 | kCurrentFile, 26 | kTempFile, 27 | kInfoLogFile // Either the current one, or an old one 28 | }; 29 | 30 | // Return the name of the log file with the specified number 31 | // in the db named by "dbname". The result will be prefixed with 32 | // "dbname". 33 | extern std::string LogFileName(const std::string& dbname, uint64_t number); 34 | 35 | // Return the name of the sstable with the specified number 36 | // in the db named by "dbname". The result will be prefixed with 37 | // "dbname". 38 | extern std::string TableFileName(const std::string& dbname, uint64_t number); 39 | 40 | // Return the legacy file name for an sstable with the specified number 41 | // in the db named by "dbname". The result will be prefixed with 42 | // "dbname". 43 | extern std::string SSTTableFileName(const std::string& dbname, uint64_t number); 44 | 45 | // Return the name of the descriptor file for the db named by 46 | // "dbname" and the specified incarnation number. The result will be 47 | // prefixed with "dbname". 48 | extern std::string DescriptorFileName(const std::string& dbname, 49 | uint64_t number); 50 | 51 | // Return the name of the current file. This file contains the name 52 | // of the current manifest file. The result will be prefixed with 53 | // "dbname". 54 | extern std::string CurrentFileName(const std::string& dbname); 55 | 56 | // Return the name of the lock file for the db named by 57 | // "dbname". The result will be prefixed with "dbname". 58 | extern std::string LockFileName(const std::string& dbname); 59 | 60 | // Return the name of a temporary file owned by the db named "dbname". 61 | // The result will be prefixed with "dbname". 62 | extern std::string TempFileName(const std::string& dbname, uint64_t number); 63 | 64 | // Return the name of the info log file for "dbname". 65 | extern std::string InfoLogFileName(const std::string& dbname); 66 | 67 | // Return the name of the old info log file for "dbname". 68 | extern std::string OldInfoLogFileName(const std::string& dbname); 69 | 70 | // If filename is a leveldb file, store the type of the file in *type. 71 | // The number encoded in the filename is stored in *number. If the 72 | // filename was successfully parsed, returns true. Else return false. 73 | extern bool ParseFileName(const std::string& filename, 74 | uint64_t* number, 75 | FileType* type); 76 | 77 | // Make the CURRENT file point to the descriptor file with the 78 | // specified number. 79 | extern Status SetCurrentFile(Env* env, const std::string& dbname, 80 | uint64_t descriptor_number); 81 | 82 | 83 | } // namespace leveldb 84 | 85 | #endif // STORAGE_LEVELDB_DB_FILENAME_H_ 86 | --------------------------------------------------------------------------------