├── deps ├── snappy │ ├── snappy-1.1.1 │ │ ├── AUTHORS │ │ ├── testdata │ │ │ ├── sum │ │ │ ├── ptt5 │ │ │ ├── cp.html │ │ │ ├── house.jpg │ │ │ ├── kennedy.xls │ │ │ ├── geo.protodata │ │ │ ├── baddata1.snappy │ │ │ ├── baddata2.snappy │ │ │ ├── baddata3.snappy │ │ │ └── mapreduce-osdi-1.pdf │ │ ├── autogen.sh │ │ ├── Makefile.am │ │ ├── COPYING │ │ └── snappy-stubs-internal.cc │ └── win32 │ │ └── config.h └── leveldb │ ├── leveldb-basho.commit │ ├── leveldb-basho │ ├── .gitmodules │ ├── .travis.yml │ ├── AUTHORS │ ├── .gitignore │ ├── util │ │ ├── filter_policy.cc │ │ ├── hash.h │ │ ├── murmurhash.h │ │ ├── histogram.h │ │ ├── hash.cc │ │ ├── throttle.h │ │ ├── testutil.cc │ │ ├── crc32c.h │ │ ├── logging.h │ │ ├── arena_test.cc │ │ ├── testutil.h │ │ ├── arena.h │ │ ├── testharness.cc │ │ ├── db_list.h │ │ ├── crc32c_test.cc │ │ ├── mutexlock.h │ │ ├── status.cc │ │ ├── flexcache.h │ │ ├── arena.cc │ │ └── random.h │ ├── port │ │ ├── README │ │ ├── port.h │ │ ├── win │ │ │ └── stdint.h │ │ ├── thread_annotations.h │ │ └── port_android.cc │ ├── tools │ │ ├── pbuilder.list │ │ └── builder.list │ ├── TODO │ ├── NEWS │ ├── helpers │ │ └── memenv │ │ │ └── memenv.h │ ├── table │ │ ├── merger.h │ │ ├── block.h │ │ ├── two_level_iterator.h │ │ ├── iterator.cc │ │ ├── block_builder.h │ │ └── iterator_wrapper.h │ ├── db │ │ ├── db_iter.h │ │ ├── log_format.h │ │ ├── builder.h │ │ ├── log_writer.h │ │ ├── write_batch_internal.h │ │ └── snapshot.h │ ├── leveldb_os │ │ ├── compile_opt.cc │ │ ├── hot_backup_stub.cc │ │ ├── expiry_os_stub.cc │ │ └── warming_stub.cc │ ├── doc │ │ └── doc.css │ ├── LICENSE │ ├── README.GOOGLE │ └── include │ │ └── leveldb │ │ └── write_batch.h │ ├── 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 │ ├── 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 │ ├── table │ │ ├── merger.h │ │ ├── block.h │ │ ├── two_level_iterator.h │ │ ├── iterator.cc │ │ └── block_builder.h │ ├── include │ │ └── leveldb │ │ │ ├── dumpfile.h │ │ │ └── write_batch.h │ ├── doc │ │ └── doc.css │ ├── LICENSE │ ├── CONTRIBUTING.md │ └── issues │ │ └── issue200_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 ├── .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 ├── appveyor.yml ├── bench ├── write-sorted-plot.sh ├── write-random-plot.sh ├── write-random.js └── write-sorted.js ├── chained-batch.js ├── LICENSE.md ├── binding.gyp ├── .jshintrc ├── iterator.js └── package.json /deps/snappy/snappy-1.1.1/AUTHORS: -------------------------------------------------------------------------------- 1 | opensource@google.com 2 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho.commit: -------------------------------------------------------------------------------- 1 | 501c29fd0ab6a4202c91b53e654eeec48be676a8 2 | -------------------------------------------------------------------------------- /test/data/testdata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/master/test/data/testdata.bin -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "leveldb_ee"] 2 | path = leveldb_ee 3 | url = git@github.com:basho/leveldb_ee 4 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/sum -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/ptt5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/ptt5 -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/cp.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/cp.html -------------------------------------------------------------------------------- /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/house.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/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-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/kennedy.xls -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | script: ulimit -n 2048 && make check 4 | 5 | compiler: gcc 6 | 7 | git: 8 | submodules: false 9 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/geo.protodata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/geo.protodata -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata1.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/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-basho-andris/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-basho-andris/master/deps/snappy/snappy-1.1.1/testdata/baddata3.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andris9/leveldown-basho-andris/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | include/leveldb/ldb_config.h 3 | *.a 4 | *.o 5 | *.dylib* 6 | *.dSYM 7 | *.d 8 | *.so 9 | *.so.* 10 | *_test 11 | db_bench 12 | leveldb_repair 13 | perf_dump 14 | sst_scan 15 | sst_rewrite 16 | *~ 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 | -------------------------------------------------------------------------------- /.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 | .DS_Store 18 | 19 | -------------------------------------------------------------------------------- /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-1.19/ 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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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-basho/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-basho/tools/pbuilder.list: -------------------------------------------------------------------------------- 1 | 10.0.27.222 debian6 2 | 10.0.27.239 debian7 3 | 10.0.27.249 fedora19 4 | 10.0.27.190 freebsd9.2 5 | 10.0.27.220 rhel5 6 | 10.0.27.221 rhel6 7 | 10.0.27.248 rhel7 8 | 10.0.27.251 sles11 9 | 10.0.27.234 smartos1.8 10 | 10.0.27.217 solaris10 11 | 10.0.27.213 ubuntuLucid 12 | 10.0.27.212 ubuntuPrecise 13 | 10.0.27.250 ubuntuTrusty 14 | bsd-build.bos1 freebsd10 15 | mac-mini.bos1 osx10.8 16 | 10.0.27.240 smartos13.1 17 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/tools/builder.list: -------------------------------------------------------------------------------- 1 | 10.0.27.221 # Centos 6.3 2 | 10.0.27.222 # Debian Squeeze 3 | 10.0.27.231 # Fedora 17 4 | 10.0.27.248 # Centos 7 5 | 10.0.27.234 # SmartOS 1.8.4 6 | 10.0.27.211 # SmartOS 1.6.3 7 | 10.0.27.220 # Centos 5.8 8 | 10.0.27.251 # SLES 11 9 | 10.0.27.190 # FreeBSD 9.2 10 | 10.0.27.214 # FreeBSD 9 64 11 | 10.0.27.213 # Ubuntu Lucid 64 12 | 10.0.27.219 # Ubuntu Natty 64 13 | 10.0.27.212 # Ubuntu Precise 64 14 | 10.0.27.250 # Ubuntu 14 15 | 10.0.27.217 # Solaris 16 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | 11 | After a range is completely deleted, what gets rid of the 12 | corresponding files if we do no future changes to that range. Make 13 | the conditions for triggering compactions fire in more situations? 14 | -------------------------------------------------------------------------------- /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-basho/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | build: off 3 | skip_tags: true 4 | 5 | environment: 6 | matrix: 7 | - nodejs_version: "0.12" 8 | - nodejs_version: "4" 9 | - nodejs_version: "6" 10 | - nodejs_version: "7" 11 | 12 | platform: 13 | - x86 14 | - x64 15 | 16 | install: 17 | - ps: Install-Product node $env:nodejs_version $env:platform 18 | - npm -g i npm@latest 19 | - set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH% 20 | - npm i --ignore-scripts 21 | - for /f %%i in ('node -v') do set exact_nodejs_version=%%i 22 | - prebuild -b %exact_nodejs_version% --strip 23 | 24 | test_script: 25 | - npm test 26 | 27 | on_success: 28 | - for %%i in (prebuilds\*) do appveyor PushArtifact %%i 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/leveldb-basho/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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-basho/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-basho/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-basho/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 "leveldb/expiry.h" 11 | #include "db/dbformat.h" 12 | 13 | namespace leveldb { 14 | 15 | // Return a new iterator that converts internal keys (yielded by 16 | // "*internal_iter") that were live at the specified "sequence" number 17 | // into appropriate user keys. 18 | extern Iterator* NewDBIterator( 19 | const std::string* dbname, 20 | Env* env, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | const SequenceNumber& sequence, 24 | const ExpiryModule * expiry=NULL); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/util/murmurhash.h: -------------------------------------------------------------------------------- 1 | /* 2 | Murmurhash from http://sites.google.com/site/murmurhash/ 3 | 4 | All code is released to the public domain. For business purposes, Murmurhash is 5 | under the MIT license. 6 | */ 7 | #ifndef MURMURHASH_H 8 | #define MURMURHASH_H 9 | 10 | #include 11 | 12 | #if defined(__x86_64__) 13 | #define MURMUR_HASH MurmurHash64A 14 | uint64_t MurmurHash64A ( const void * key, int len, unsigned int seed ); 15 | #define MurmurHash MurmurHash64A 16 | typedef uint64_t murmur_t; 17 | 18 | #elif defined(__i386__) 19 | #define MURMUR_HASH MurmurHash2 20 | unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ); 21 | #define MurmurHash MurmurHash2 22 | typedef unsigned int murmur_t; 23 | 24 | #else 25 | #define MURMUR_HASH MurmurHashNeutral2 26 | unsigned int MurmurHashNeutral2 ( const void * key, int len, unsigned int seed ); 27 | #define MurmurHash MurmurHashNeutral2 28 | typedef unsigned int murmur_t; 29 | 30 | #endif 31 | 32 | #endif /* MURMURHASH_H */ 33 | -------------------------------------------------------------------------------- /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/leveldb-basho/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), type (1 byte), length (2 bytes). 30 | static const int kHeaderSize = 4 + 1 + 2; 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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/leveldb_os/compile_opt.cc: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // compile_opt.h 4 | // 5 | // Copyright (c) 2016 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include "leveldb/options.h" 24 | 25 | namespace leveldb 26 | { 27 | const char * CompileOptionsString() 28 | { 29 | return("(open source)"); 30 | } 31 | } // namespace leveldb 32 | 33 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | namespace leveldb { 10 | 11 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 12 | // Similar to murmur hash 13 | const uint32_t m = 0xc6a4a793; 14 | const uint32_t r = 24; 15 | const char* limit = data + n; 16 | uint32_t h = seed ^ (n * m); 17 | 18 | // Pick up four bytes at a time 19 | while (data + 4 <= limit) { 20 | uint32_t w = DecodeFixed32(data); 21 | data += 4; 22 | h += w; 23 | h *= m; 24 | h ^= (h >> 16); 25 | } 26 | 27 | // Pick up remaining bytes 28 | switch (limit - data) { 29 | case 3: 30 | h += data[2] << 16; 31 | // fall through 32 | case 2: 33 | h += data[1] << 8; 34 | // fall through 35 | case 1: 36 | h += data[0]; 37 | h *= m; 38 | h ^= (h >> r); 39 | break; 40 | } 41 | return h; 42 | } 43 | 44 | 45 | } // namespace leveldb 46 | -------------------------------------------------------------------------------- /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-basho/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 | uint32_t NumRestarts() const; 28 | 29 | private: 30 | 31 | const char* data_; 32 | size_t size_; 33 | uint32_t restart_offset_; // Offset in data_ of restart array 34 | bool owned_; // Block owns data_[] 35 | 36 | // No copying allowed 37 | Block(const Block&); 38 | void operator=(const Block&); 39 | 40 | class Iter; 41 | }; 42 | 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 46 | -------------------------------------------------------------------------------- /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-basho/leveldb_os/hot_backup_stub.cc: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // hot_backup_stub.cc 4 | // 5 | // Copyright (c) 2011-2016 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include "util/thread_tasks.h" 24 | 25 | namespace leveldb { 26 | 27 | /** 28 | * Called by throttle.cc's thread once a minute. Used to 29 | * test for trigger condition 30 | */ 31 | void 32 | CheckHotBackupTrigger() 33 | { 34 | return; 35 | } // CheckHotBackupTrigger 36 | 37 | } // namespace leveldb 38 | -------------------------------------------------------------------------------- /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 | "number. On success, the rest of 23 | // *meta will be filled with metadata about the generated table. 24 | // If no data is present in *iter, meta->file_size will be set to 25 | // zero, and no Table file will be produced. 26 | extern Status BuildTable(const std::string& dbname, 27 | Env* env, 28 | const Options& options, 29 | const Comparator * user_comparator, 30 | TableCache* table_cache, 31 | Iterator* iter, 32 | FileMetaData* meta, 33 | SequenceNumber smallest_snapshot); 34 | 35 | } // namespace leveldb 36 | 37 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 38 | -------------------------------------------------------------------------------- /deps/leveldb/port-libuv/atomic_pointer_win.h: -------------------------------------------------------------------------------- 1 | #include 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 | }) -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/leveldb_os/warming_stub.cc: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // cache_warm.cc 4 | // 5 | // Copyright (c) 2011-2016 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include "db/table_cache.h" 24 | 25 | namespace leveldb { 26 | 27 | 28 | /** 29 | * Riak specific routine to push list of open files to disk 30 | */ 31 | Status 32 | TableCache::SaveOpenFileList() 33 | { 34 | return(Status::OK()); 35 | } // TableCache::SaveOpenFiles 36 | 37 | 38 | /** 39 | * Riak specific routine to read list of previously open files 40 | * and preload them into the table cache 41 | */ 42 | Status 43 | TableCache::PreloadTableCache() 44 | { 45 | return(Status::OK()); 46 | } // TableCache::PreloadTableCache 47 | 48 | } // namespace leveldb 49 | -------------------------------------------------------------------------------- /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-basho/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/leveldb/leveldb-basho/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 | #include "leveldb/env.h" 13 | 14 | namespace leveldb { 15 | 16 | namespace log { 17 | 18 | class Writer { 19 | public: 20 | // Create a writer that will append data to "*dest". 21 | // "*dest" must be initially empty. 22 | // "*dest" must remain live while this Writer is in use. 23 | explicit Writer(WritableFile* dest); 24 | ~Writer(); 25 | 26 | Status AddRecord(const Slice& slice); 27 | 28 | void Close() {delete dest_; dest_=NULL;}; 29 | 30 | private: 31 | WritableFile* dest_; 32 | int block_offset_; // Current offset in block 33 | 34 | // crc32c values for all supported record types. These are 35 | // pre-computed to reduce the overhead of computing the crc of the 36 | // record type stored in the header. 37 | uint32_t type_crc_[kMaxRecordType + 1]; 38 | 39 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 40 | 41 | // No copying allowed 42 | Writer(const Writer&); 43 | void operator=(const Writer&); 44 | }; 45 | 46 | } // namespace log 47 | } // namespace leveldb 48 | 49 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 50 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/util/throttle.h: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // throttle.h 4 | // 5 | // Copyright (c) 2011-2013 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include 24 | 25 | 26 | namespace leveldb 27 | { 28 | 29 | void ThrottleInit(); 30 | 31 | void SetThrottleWriteRate(uint64_t Micros, uint64_t Keys, bool IsLevel0); 32 | 33 | uint64_t GetThrottleWriteRate(); 34 | uint64_t GetUnadjustedThrottleWriteRate(); 35 | 36 | // clock_gettime but only updated once every 60 seconds (roughly) 37 | // (SetTimeMinutes() intended for unit tests) 38 | uint64_t GetTimeMinutes(); 39 | void SetTimeMinutes(uint64_t); 40 | 41 | // step 1 in two step shutdown 42 | void ThrottleStopThreads(); 43 | 44 | // step 2 in two step shutdown 45 | void ThrottleClose(); 46 | 47 | } // namespace leveldb 48 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | 7 | // Some environments provide custom macros to aid in static thread-safety 8 | // analysis. Provide empty definitions of such macros unless they are already 9 | // defined. 10 | 11 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 12 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 13 | #endif 14 | 15 | #ifndef SHARED_LOCKS_REQUIRED 16 | #define SHARED_LOCKS_REQUIRED(...) 17 | #endif 18 | 19 | #ifndef LOCKS_EXCLUDED 20 | #define LOCKS_EXCLUDED(...) 21 | #endif 22 | 23 | #ifndef LOCK_RETURNED 24 | #define LOCK_RETURNED(x) 25 | #endif 26 | 27 | #ifndef LOCKABLE 28 | #define LOCKABLE 29 | #endif 30 | 31 | #ifndef SCOPED_LOCKABLE 32 | #define SCOPED_LOCKABLE 33 | #endif 34 | 35 | #ifndef EXCLUSIVE_LOCK_FUNCTION 36 | #define EXCLUSIVE_LOCK_FUNCTION(...) 37 | #endif 38 | 39 | #ifndef SHARED_LOCK_FUNCTION 40 | #define SHARED_LOCK_FUNCTION(...) 41 | #endif 42 | 43 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 44 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 45 | #endif 46 | 47 | #ifndef SHARED_TRYLOCK_FUNCTION 48 | #define SHARED_TRYLOCK_FUNCTION(...) 49 | #endif 50 | 51 | #ifndef UNLOCK_FUNCTION 52 | #define UNLOCK_FUNCTION(...) 53 | #endif 54 | 55 | #ifndef NO_THREAD_SAFETY_ANALYSIS 56 | #define NO_THREAD_SAFETY_ANALYSIS 57 | #endif 58 | 59 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H 60 | -------------------------------------------------------------------------------- /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-basho/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-basho/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 | int 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/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-basho/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 "leveldb/write_batch.h" 9 | 10 | namespace leveldb { 11 | 12 | class MemTable; 13 | 14 | // WriteBatchInternal provides static methods for manipulating a 15 | // WriteBatch that we don't want in the public WriteBatch interface. 16 | class WriteBatchInternal { 17 | public: 18 | // Return the number of entries in the batch. 19 | static int Count(const WriteBatch* batch); 20 | 21 | // Set the count for the number of entries in the batch. 22 | static void SetCount(WriteBatch* batch, int n); 23 | 24 | // Return the seqeunce number for the start of this batch. 25 | static SequenceNumber Sequence(const WriteBatch* batch); 26 | 27 | // Store the specified number as the seqeunce number for the start of 28 | // this batch. 29 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 30 | 31 | static Slice Contents(const WriteBatch* batch) { 32 | return Slice(batch->rep_); 33 | } 34 | 35 | static size_t ByteSize(const WriteBatch* batch) { 36 | return batch->rep_.size(); 37 | } 38 | 39 | static void SetContents(WriteBatch* batch, const Slice& contents); 40 | 41 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable, const Options * options); 42 | 43 | static void Append(WriteBatch* dst, const WriteBatch* src); 44 | }; 45 | 46 | } // namespace leveldb 47 | 48 | 49 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 50 | -------------------------------------------------------------------------------- /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-basho/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 | // switch function pointer from software crc to hardware 25 | extern void SwitchToHardwareCRC(); 26 | extern bool IsHardwareCRC(); 27 | 28 | static const uint32_t kMaskDelta = 0xa282ead8ul; 29 | 30 | // Return a masked representation of crc. 31 | // 32 | // Motivation: it is problematic to compute the CRC of a string that 33 | // contains embedded CRCs. Therefore we recommend that CRCs stored 34 | // somewhere (e.g., in files) should be masked before being stored. 35 | inline uint32_t Mask(uint32_t crc) { 36 | // Rotate right by 15 bits and add a constant. 37 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 38 | } 39 | 40 | // Return the crc whose masked representation is masked_crc. 41 | inline uint32_t Unmask(uint32_t masked_crc) { 42 | uint32_t rot = masked_crc - kMaskDelta; 43 | return ((rot >> 17) | (rot << 15)); 44 | } 45 | 46 | } // namespace crc32c 47 | } // namespace leveldb 48 | 49 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 50 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/port/port_android.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_android.h" 6 | 7 | #include 8 | 9 | extern "C" { 10 | size_t fread_unlocked(void *a, size_t b, size_t c, FILE *d) { 11 | return fread(a, b, c, d); 12 | } 13 | 14 | size_t fwrite_unlocked(const void *a, size_t b, size_t c, FILE *d) { 15 | return fwrite(a, b, c, d); 16 | } 17 | 18 | int fflush_unlocked(FILE *f) { 19 | return fflush(f); 20 | } 21 | 22 | int fdatasync(int fd) { 23 | return fsync(fd); 24 | } 25 | } 26 | 27 | namespace leveldb { 28 | namespace port { 29 | 30 | static void PthreadCall(const char* label, int result) { 31 | if (result != 0) { 32 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 33 | abort(); 34 | } 35 | } 36 | 37 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 38 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 39 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 40 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 41 | 42 | CondVar::CondVar(Mutex* mu) 43 | : mu_(mu) { 44 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 45 | } 46 | 47 | CondVar::~CondVar() { 48 | PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); 49 | } 50 | 51 | void CondVar::Wait() { 52 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 53 | } 54 | 55 | void CondVar::Signal(){ 56 | PthreadCall("signal", pthread_cond_signal(&cv_)); 57 | } 58 | 59 | void CondVar::SignalAll() { 60 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 61 | } 62 | 63 | } // namespace port 64 | } // namespace leveldb 65 | -------------------------------------------------------------------------------- /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-basho/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 | // Return human-readable hex string version of "value" 36 | extern std::string HexString(const Slice & value); 37 | 38 | // If *in starts with "c", advances *in past the first character and 39 | // returns true. Otherwise, returns false. 40 | extern bool ConsumeChar(Slice* in, char c); 41 | 42 | // Parse a human-readable number from "*in" into *value. On success, 43 | // advances "*in" past the consumed number and sets "*val" to the 44 | // numeric value. Otherwise, returns false and leaves *in in an 45 | // unspecified state. 46 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 47 | 48 | } // namespace leveldb 49 | 50 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 51 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/README.GOOGLE: -------------------------------------------------------------------------------- 1 | leveldb: A key-value store 2 | Authors: Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com) 3 | 4 | The code under this directory implements a system for maintaining a 5 | persistent key/value store. 6 | 7 | See doc/index.html for more explanation. 8 | See doc/impl.html for a brief overview of the implementation. 9 | 10 | The public interface is in include/*.h. Callers should not include or 11 | rely on the details of any other header files in this package. Those 12 | internal APIs may be changed without warning. 13 | 14 | Guide to header files: 15 | 16 | include/db.h 17 | Main interface to the DB: Start here 18 | 19 | include/options.h 20 | Control over the behavior of an entire database, and also 21 | control over the behavior of individual reads and writes. 22 | 23 | include/comparator.h 24 | Abstraction for user-specified comparison function. If you want 25 | just bytewise comparison of keys, you can use the default comparator, 26 | but clients can write their own comparator implementations if they 27 | want custom ordering (e.g. to handle different character 28 | encodings, etc.) 29 | 30 | include/iterator.h 31 | Interface for iterating over data. You can get an iterator 32 | from a DB object. 33 | 34 | include/write_batch.h 35 | Interface for atomically applying multiple updates to a database. 36 | 37 | include/slice.h 38 | A simple module for maintaining a pointer and a length into some 39 | other byte array. 40 | 41 | include/status.h 42 | Status is returned from many of the public interfaces and is used 43 | to report success and various kinds of errors. 44 | 45 | include/env.h 46 | Abstraction of the OS environment. A posix implementation of 47 | this interface is in util/env_posix.cc 48 | 49 | include/table.h 50 | include/table_builder.h 51 | Lower-level modules that most clients probably won't use directly 52 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 "leveldb/db.h" 9 | 10 | namespace leveldb { 11 | 12 | class SnapshotList; 13 | 14 | // Snapshots are kept in a doubly-linked list in the DB. 15 | // Each SnapshotImpl corresponds to a particular sequence number. 16 | class SnapshotImpl : public Snapshot { 17 | public: 18 | SequenceNumber number_; // const after creation 19 | 20 | private: 21 | friend class SnapshotList; 22 | 23 | // SnapshotImpl is kept in a doubly-linked circular list 24 | SnapshotImpl* prev_; 25 | SnapshotImpl* next_; 26 | 27 | SnapshotList* list_; // just for sanity checks 28 | }; 29 | 30 | class SnapshotList { 31 | public: 32 | SnapshotList() { 33 | list_.prev_ = &list_; 34 | list_.next_ = &list_; 35 | } 36 | 37 | bool empty() const { return list_.next_ == &list_; } 38 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 39 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 40 | 41 | const SnapshotImpl* New(SequenceNumber seq) { 42 | SnapshotImpl* s = new SnapshotImpl; 43 | s->number_ = seq; 44 | s->list_ = this; 45 | s->next_ = &list_; 46 | s->prev_ = list_.prev_; 47 | s->prev_->next_ = s; 48 | s->next_->prev_ = s; 49 | return s; 50 | } 51 | 52 | void Delete(const SnapshotImpl* s) { 53 | assert(s->list_ == this); 54 | s->prev_->next_ = s->next_; 55 | s->next_->prev_ = s->prev_; 56 | delete s; 57 | } 58 | 59 | private: 60 | // Dummy head of doubly-linked list of snapshots 61 | SnapshotImpl list_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 67 | -------------------------------------------------------------------------------- /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-basho/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 (int 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 (int i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (int 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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-basho/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 | int 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, size_t map_size) { 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, map_size); 47 | } 48 | }; 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | 53 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 54 | -------------------------------------------------------------------------------- /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-basho/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 callled 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/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | 13 | namespace leveldb { 14 | 15 | class Arena { 16 | public: 17 | Arena(); 18 | ~Arena(); 19 | 20 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 21 | char* Allocate(size_t bytes); 22 | 23 | // Allocate memory with the normal alignment guarantees provided by malloc 24 | char* AllocateAligned(size_t bytes); 25 | 26 | // Returns an estimate of the total memory usage of data allocated 27 | // by the arena (including space allocated but not yet used for user 28 | // allocations). 29 | size_t MemoryUsage() const { 30 | return blocks_memory_ + blocks_.capacity() * sizeof(char*); 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 | // Bytes of memory in blocks allocated so far 45 | size_t blocks_memory_; 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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 (int 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 | 58 | // cleanup memory for valgrind 59 | leveldb::Env::Shutdown(); 60 | delete tests; 61 | 62 | return 0; 63 | } 64 | 65 | std::string TmpDir() { 66 | std::string dir; 67 | Status s = Env::Default()->GetTestDirectory(&dir); 68 | ASSERT_TRUE(s.ok()) << s.ToString(); 69 | return dir; 70 | } 71 | 72 | int RandomSeed() { 73 | const char* env = getenv("TEST_RANDOM_SEED"); 74 | int result = (env != NULL ? atoi(env) : 301); 75 | if (result <= 0) { 76 | result = 301; 77 | } 78 | return result; 79 | } 80 | 81 | } // namespace test 82 | } // namespace leveldb 83 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/util/db_list.h: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // db_list.h 4 | // 5 | // Copyright (c) 2011-2013 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include "db/db_impl.h" 24 | #include "port/port.h" 25 | 26 | 27 | namespace leveldb 28 | { 29 | 30 | /** 31 | * DBList: class to provide management access to all 32 | * open databases (Riak vnodes) 33 | */ 34 | class DBListImpl 35 | { 36 | protected: 37 | typedef std::set db_set_t; 38 | 39 | port::Spin m_Lock; //!< thread protection for set 40 | db_set_t m_UserDBs; //!< set of pointers for user db 41 | db_set_t m_InternalDBs; //!< Riak internal dbs 42 | 43 | volatile size_t m_UserDBCount; //!< m_UserDBs size() for non-blocking retrieval 44 | volatile size_t m_InternalDBCount; //!< m_InternalDBs size() for non-blocking retrieval 45 | 46 | public: 47 | DBListImpl(); 48 | virtual ~DBListImpl() {}; 49 | 50 | bool AddDB(DBImpl *, bool is_internal); 51 | void ReleaseDB(DBImpl *, bool is_internal); 52 | 53 | size_t GetDBCount(bool is_internal); 54 | 55 | void ScanDBs(bool is_internal, void (DBImpl::*)()); 56 | 57 | }; // class DBListImpl 58 | 59 | 60 | // Universal access to dblist ... initialization order independent 61 | DBListImpl * DBList(); 62 | 63 | // cleanup memory, mostly for valgrind 64 | void DBListShutdown(); 65 | 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /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-basho/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 "leveldb/env.h" 6 | #include "util/crc32c.h" 7 | #include "util/testharness.h" 8 | 9 | namespace leveldb { 10 | namespace crc32c { 11 | 12 | class CRC { }; 13 | 14 | TEST(CRC, StandardResults) { 15 | // From rfc3720 section B.4. 16 | char buf[32]; 17 | 18 | memset(buf, 0, sizeof(buf)); 19 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 20 | 21 | memset(buf, 0xff, sizeof(buf)); 22 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 23 | 24 | for (int i = 0; i < 32; i++) { 25 | buf[i] = i; 26 | } 27 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 28 | 29 | for (int i = 0; i < 32; i++) { 30 | buf[i] = 31 - i; 31 | } 32 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 33 | 34 | unsigned char data[48] = { 35 | 0x01, 0xc0, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 39 | 0x14, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x04, 0x00, 41 | 0x00, 0x00, 0x00, 0x14, 42 | 0x00, 0x00, 0x00, 0x18, 43 | 0x28, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 45 | 0x02, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 47 | }; 48 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 49 | } 50 | 51 | TEST(CRC, Values) { 52 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 53 | } 54 | 55 | TEST(CRC, Extend) { 56 | ASSERT_EQ(Value("hello world", 11), 57 | Extend(Value("hello ", 6), "world", 5)); 58 | } 59 | 60 | TEST(CRC, Mask) { 61 | uint32_t crc = Value("foo", 3); 62 | ASSERT_NE(crc, Mask(crc)); 63 | ASSERT_NE(crc, Mask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Mask(crc))); 65 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 66 | } 67 | 68 | } // namespace crc32c 69 | } // namespace leveldb 70 | 71 | int main(int argc, char** argv) { 72 | 73 | // identify and potentially switch to hardware CRC 74 | leveldb::Env::Default(); 75 | 76 | return leveldb::test::RunAllTests(); 77 | } 78 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | 10 | namespace leveldb { 11 | 12 | // Helper class that locks a mutex on construction and unlocks the mutex when 13 | // the destructor of the MutexLock object is invoked. 14 | // 15 | // Typical usage: 16 | // 17 | // void MyClass::MyMethod() { 18 | // MutexLock l(&mu_); // mu_ is an instance variable 19 | // ... some complex code, possibly with multiple return paths ... 20 | // } 21 | 22 | class MutexLock { 23 | public: 24 | explicit MutexLock(port::Mutex *mu) : mu_(mu) { 25 | this->mu_->Lock(); 26 | } 27 | ~MutexLock() { this->mu_->Unlock(); } 28 | 29 | private: 30 | port::Mutex *const mu_; 31 | // No copying allowed 32 | MutexLock(const MutexLock&); 33 | void operator=(const MutexLock&); 34 | }; 35 | 36 | 37 | class SpinLock { 38 | public: 39 | explicit SpinLock(port::Spin *sp) : sp_(sp) { 40 | this->sp_->Lock(); 41 | } 42 | ~SpinLock() { this->sp_->Unlock(); } 43 | 44 | private: 45 | port::Spin *const sp_; 46 | // No copying allowed 47 | SpinLock(const SpinLock&); 48 | void operator=(const SpinLock&); 49 | }; 50 | 51 | 52 | class ReadLock { 53 | public: 54 | explicit ReadLock(port::RWMutex *mu) : mu_(mu) { 55 | this->mu_->ReadLock(); 56 | } 57 | ~ReadLock() { this->mu_->Unlock(); } 58 | 59 | private: 60 | port::RWMutex *const mu_; 61 | // No copying allowed 62 | ReadLock(const ReadLock&); 63 | void operator=(const ReadLock&); 64 | }; 65 | 66 | 67 | class WriteLock { 68 | public: 69 | explicit WriteLock(port::RWMutex *mu) : mu_(mu) { 70 | this->mu_->WriteLock(); 71 | } 72 | ~WriteLock() { this->mu_->Unlock(); } 73 | 74 | private: 75 | port::RWMutex *const mu_; 76 | // No copying allowed 77 | WriteLock(const WriteLock&); 78 | void operator=(const WriteLock&); 79 | }; 80 | 81 | } // namespace leveldb 82 | 83 | 84 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 85 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | #include "leveldb/options.h" 27 | 28 | namespace leveldb { 29 | 30 | class Slice; 31 | 32 | class WriteBatch { 33 | public: 34 | WriteBatch(); 35 | ~WriteBatch(); 36 | 37 | // Store the mapping "key->value" in the database. 38 | void Put(const Slice& key, const Slice& value, const KeyMetaData * meta=NULL); 39 | 40 | // If the database contains a mapping for "key", erase it. Else do nothing. 41 | void Delete(const Slice& key); 42 | 43 | // Clear all updates buffered in this batch. 44 | void Clear(); 45 | 46 | // Support for iterating over the contents of a batch. 47 | class Handler { 48 | public: 49 | virtual ~Handler(); 50 | virtual void Put(const Slice& key, const Slice& value, const ValueType & type, const ExpiryTime & expiry) = 0; 51 | virtual void Delete(const Slice& key) = 0; 52 | }; 53 | Status Iterate(Handler* handler) const; 54 | 55 | private: 56 | friend class WriteBatchInternal; 57 | 58 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 59 | 60 | // Intentionally copyable 61 | }; 62 | 63 | } // namespace leveldb 64 | 65 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/util/flexcache.h: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------- 2 | // 3 | // flexcache.h 4 | // 5 | // Copyright (c) 2011-2013 Basho Technologies, Inc. All Rights Reserved. 6 | // 7 | // This file is provided to you under the Apache License, 8 | // Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain 10 | // a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, 15 | // software distributed under the License is distributed on an 16 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | // KIND, either express or implied. See the License for the 18 | // specific language governing permissions and limitations 19 | // under the License. 20 | // 21 | // ------------------------------------------------------------------- 22 | 23 | #include "util/cache2.h" 24 | 25 | #ifndef STORAGE_LEVELDB_INCLUDE_FLEXCACHE_H_ 26 | #define STORAGE_LEVELDB_INCLUDE_FLEXCACHE_H_ 27 | 28 | namespace leveldb 29 | { 30 | 31 | // Constants declared in style of db/dbformat.h 32 | namespace flex 33 | { 34 | 35 | static const uint64_t kRlimSizeIsSmall = 2*1024*1024*1024ULL; // above 2G is lots of ram 36 | static const uint64_t kRlimSmall = 256*1024*1024ULL; 37 | static const uint64_t kRlimLargeReserve = 1024*1024*1024ULL; 38 | static const uint64_t kDefaultMemory = 340*1024*1024ULL; 39 | static const uint64_t kMinimumDBMemory = 10*1024*1024ULL; 40 | 41 | } // namespace flex 42 | 43 | /** 44 | * FlexCache tunes file cache versus block cache versus number 45 | * of open databases 46 | */ 47 | 48 | class FlexCache 49 | { 50 | public: 51 | FlexCache(); 52 | 53 | uint64_t GetDBCacheCapacity(bool IsInternalDB); 54 | 55 | void SetTotalMemory(uint64_t Total); 56 | 57 | void RecalculateAllocations() {SetTotalMemory(0);}; 58 | 59 | uint64_t GetTotalMemory() const {return(m_TotalMemory);}; 60 | 61 | protected: 62 | 63 | uint64_t m_TotalMemory; //!< complete memory assigned to all FlexCache clients 64 | 65 | }; // class FlexCache 66 | 67 | 68 | extern FlexCache gFlexCache; 69 | 70 | } // namespace leveldb 71 | 72 | #endif // STORAGE_LEVELDB_INCLUDE_FLEXCACHE_H_ 73 | -------------------------------------------------------------------------------- /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-basho/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() { 13 | blocks_memory_ = 0; 14 | alloc_ptr_ = NULL; // First allocation will allocate a block 15 | alloc_bytes_remaining_ = 0; 16 | } 17 | 18 | Arena::~Arena() { 19 | for (size_t i = 0; i < blocks_.size(); i++) { 20 | delete[] blocks_[i]; 21 | } 22 | } 23 | 24 | char* Arena::AllocateFallback(size_t bytes) { 25 | if (bytes > kBlockSize / 4) { 26 | // Object is more than a quarter of our block size. Allocate it separately 27 | // to avoid wasting too much space in leftover bytes. 28 | char* result = AllocateNewBlock(bytes); 29 | return result; 30 | } 31 | 32 | // We waste the remaining space in the current block. 33 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 34 | alloc_bytes_remaining_ = kBlockSize; 35 | 36 | char* result = alloc_ptr_; 37 | alloc_ptr_ += bytes; 38 | alloc_bytes_remaining_ -= bytes; 39 | return result; 40 | } 41 | 42 | char* Arena::AllocateAligned(size_t bytes) { 43 | const int align = sizeof(void*); // We'll align to pointer size 44 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 45 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 46 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 47 | size_t needed = bytes + slop; 48 | char* result; 49 | if (needed <= alloc_bytes_remaining_) { 50 | result = alloc_ptr_ + slop; 51 | alloc_ptr_ += needed; 52 | alloc_bytes_remaining_ -= needed; 53 | } else { 54 | // AllocateFallback always returned aligned memory 55 | result = AllocateFallback(bytes); 56 | } 57 | assert((reinterpret_cast(result) & (align-1)) == 0); 58 | return result; 59 | } 60 | 61 | char* Arena::AllocateNewBlock(size_t block_bytes) { 62 | char* result = new char[block_bytes]; 63 | blocks_memory_ += block_bytes; 64 | blocks_.push_back(result); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/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 | namespace leveldb { 9 | 10 | // A internal wrapper class with an interface similar to Iterator that 11 | // caches the valid() and key() results for an underlying iterator. 12 | // This can help avoid virtual function calls and also gives better 13 | // cache locality. 14 | class IteratorWrapper { 15 | public: 16 | IteratorWrapper(): iter_(NULL), valid_(false) { } 17 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 18 | Set(iter); 19 | } 20 | ~IteratorWrapper() { delete iter_; } 21 | Iterator* iter() const { return iter_; } 22 | 23 | // Takes ownership of "iter" and will delete it when destroyed, or 24 | // when Set() is invoked again. 25 | void Set(Iterator* iter) { 26 | delete iter_; 27 | iter_ = iter; 28 | if (iter_ == NULL) { 29 | valid_ = false; 30 | } else { 31 | Update(); 32 | } 33 | } 34 | 35 | 36 | // Iterator interface methods 37 | bool Valid() const { return valid_; } 38 | Slice key() const { assert(Valid()); return key_; } 39 | Slice value() const { assert(Valid()); return iter_->value(); } 40 | // Methods below require iter() != NULL 41 | Status status() const { assert(iter_); return iter_->status(); } 42 | void Next() { assert(iter_); iter_->Next(); Update(); } 43 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 44 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 45 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 46 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 47 | 48 | private: 49 | void Update() { 50 | valid_ = iter_->Valid(); 51 | if (valid_) { 52 | key_ = iter_->key(); 53 | } 54 | } 55 | 56 | Iterator* iter_; 57 | bool valid_; 58 | Slice key_; 59 | }; 60 | 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 64 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-basho/util/random.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_RANDOM_H_ 6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_ 7 | 8 | #include 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 | uint32_t Next() { 21 | static const uint32_t M = 2147483647L; // 2^31-1 22 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 23 | // We are computing 24 | // seed_ = (seed_ * A) % M, where M = 2^31-1 25 | // 26 | // seed_ must not be zero or M, or else all subsequent computed values 27 | // will be zero or M respectively. For all other values, seed_ will end 28 | // up cycling through every number in [1,M-1] 29 | uint64_t product = seed_ * A; 30 | 31 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 32 | seed_ = static_cast((product >> 31) + (product & M)); 33 | // The first reduction may overflow by 1 bit, so we may need to 34 | // repeat. mod == M is not possible; using > allows the faster 35 | // sign-bit-based test. 36 | if (seed_ > M) { 37 | seed_ -= M; 38 | } 39 | return seed_; 40 | } 41 | // Returns a uniformly distributed value in the range [0..n-1] 42 | // REQUIRES: n > 0 43 | uint32_t Uniform(int n) { return Next() % n; } 44 | 45 | // Randomly returns true ~"1/n" of the time, and false otherwise. 46 | // REQUIRES: n > 0 47 | bool OneIn(int n) { return (Next() % n) == 0; } 48 | 49 | // Skewed: pick "base" uniformly from range [0,max_log] and then 50 | // return "base" random bits. The effect is to pick a number in the 51 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 52 | uint32_t Skewed(int max_log) { 53 | return Uniform(1 << Uniform(max_log + 1)); 54 | } 55 | }; 56 | 57 | } // namespace leveldb 58 | 59 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 60 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leveldown-basho-andris", 3 | "description": "A Node.js LevelDB binding for Basho fork, primary backend for LevelUP", 4 | "version": "1.5.0-andris.4", 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/andris9/leveldown-basho-andris.git" 23 | }, 24 | "homepage": "https://github.com/andris9/leveldown-basho-andris", 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 | "prebuild-ci": "^1.0.9", 47 | "readfiletree": "~0.0.1", 48 | "rimraf": "~2.5.0", 49 | "slump": "~2.0.0", 50 | "tape": "^4.5.1" 51 | }, 52 | "scripts": { 53 | "install": "prebuild --install", 54 | "test": "tape test/*-test.js | faucet", 55 | "rebuild": "prebuild --compile", 56 | "prebuild": "prebuild --all --strip --verbose" 57 | }, 58 | "license": "MIT", 59 | "gypfile": true 60 | } 61 | -------------------------------------------------------------------------------- /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 | }) --------------------------------------------------------------------------------