├── .dntrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS.md ├── LICENSE.md ├── README.md ├── UPGRADING.md ├── bench ├── db-bench-plot.sh ├── db-bench.js ├── write-random-plot.sh ├── write-random.js ├── write-sorted-plot.sh └── write-sorted.js ├── binding.gyp ├── chained-batch.js ├── deps ├── leveldb │ ├── leveldb-hyper-1.0.2 │ │ ├── .tarballignore │ │ ├── AUTHORS │ │ ├── LICENSE │ │ ├── Makefile.am │ │ ├── NEWS │ │ ├── README │ │ ├── TODO │ │ ├── benchmark.cc │ │ ├── configure.ac │ │ ├── db │ │ │ ├── autocompact_test.cc │ │ │ ├── builder.cc │ │ │ ├── builder.h │ │ │ ├── c.cc │ │ │ ├── c_test.c │ │ │ ├── corruption_test.cc │ │ │ ├── db_bench.cc │ │ │ ├── db_impl.cc │ │ │ ├── db_impl.h │ │ │ ├── db_iter.cc │ │ │ ├── db_iter.h │ │ │ ├── db_test.cc │ │ │ ├── dbformat.cc │ │ │ ├── dbformat.h │ │ │ ├── dbformat_test.cc │ │ │ ├── filename.cc │ │ │ ├── filename.h │ │ │ ├── filename_test.cc │ │ │ ├── leveldb_main.cc │ │ │ ├── log_format.h │ │ │ ├── log_reader.cc │ │ │ ├── log_reader.h │ │ │ ├── log_test.cc │ │ │ ├── log_writer.cc │ │ │ ├── log_writer.h │ │ │ ├── memtable.cc │ │ │ ├── memtable.h │ │ │ ├── repair.cc │ │ │ ├── replay_iterator.cc │ │ │ ├── replay_iterator.h │ │ │ ├── skiplist.h │ │ │ ├── skiplist_test.cc │ │ │ ├── snapshot.h │ │ │ ├── table_cache.cc │ │ │ ├── table_cache.h │ │ │ ├── version_edit.cc │ │ │ ├── version_edit.h │ │ │ ├── version_edit_test.cc │ │ │ ├── version_set.cc │ │ │ ├── version_set.h │ │ │ ├── version_set_test.cc │ │ │ ├── write_batch.cc │ │ │ ├── write_batch_internal.h │ │ │ └── write_batch_test.cc │ │ ├── doc │ │ │ ├── benchmark.html │ │ │ ├── doc.css │ │ │ ├── impl.html │ │ │ ├── index.html │ │ │ ├── log_format.txt │ │ │ └── table_format.txt │ │ ├── helpers │ │ │ └── memenv │ │ │ │ ├── memenv.cc │ │ │ │ ├── memenv.h │ │ │ │ └── memenv_test.cc │ │ ├── hyperleveldb.upack.in │ │ ├── hyperleveldb │ │ │ ├── c.h │ │ │ ├── cache.h │ │ │ ├── comparator.h │ │ │ ├── db.h │ │ │ ├── env.h │ │ │ ├── filter_policy.h │ │ │ ├── iterator.h │ │ │ ├── options.h │ │ │ ├── replay_iterator.h │ │ │ ├── slice.h │ │ │ ├── status.h │ │ │ ├── table.h │ │ │ ├── table_builder.h │ │ │ └── write_batch.h │ │ ├── issues │ │ │ ├── issue178_test.cc │ │ │ └── issue200_test.cc │ │ ├── leveldb-verify.cc │ │ ├── libhyperleveldb.pc.in │ │ ├── m4 │ │ │ ├── anal_warnings.m4 │ │ │ ├── anal_warnings_cxx.m4 │ │ │ └── ax_check_compile_flag.m4 │ │ ├── port │ │ │ ├── README │ │ │ ├── atomic_pointer.h │ │ │ ├── port.h │ │ │ ├── port_example.h │ │ │ ├── port_posix.cc │ │ │ ├── port_posix.h │ │ │ ├── thread_annotations.h │ │ │ └── win │ │ │ │ └── stdint.h │ │ ├── table │ │ │ ├── block.cc │ │ │ ├── block.h │ │ │ ├── block_builder.cc │ │ │ ├── block_builder.h │ │ │ ├── filter_block.cc │ │ │ ├── filter_block.h │ │ │ ├── filter_block_test.cc │ │ │ ├── format.cc │ │ │ ├── format.h │ │ │ ├── iterator.cc │ │ │ ├── iterator_wrapper.h │ │ │ ├── merger.cc │ │ │ ├── merger.h │ │ │ ├── table.cc │ │ │ ├── table_builder.cc │ │ │ ├── table_test.cc │ │ │ ├── two_level_iterator.cc │ │ │ └── two_level_iterator.h │ │ └── util │ │ │ ├── arena.cc │ │ │ ├── arena.h │ │ │ ├── arena_test.cc │ │ │ ├── bloom.cc │ │ │ ├── bloom_test.cc │ │ │ ├── cache.cc │ │ │ ├── cache_test.cc │ │ │ ├── coding.cc │ │ │ ├── coding.h │ │ │ ├── coding_test.cc │ │ │ ├── comparator.cc │ │ │ ├── crc32c.cc │ │ │ ├── crc32c.h │ │ │ ├── crc32c_test.cc │ │ │ ├── env.cc │ │ │ ├── env_posix.cc │ │ │ ├── env_test.cc │ │ │ ├── filter_policy.cc │ │ │ ├── hash.cc │ │ │ ├── hash.h │ │ │ ├── histogram.cc │ │ │ ├── histogram.h │ │ │ ├── logging.cc │ │ │ ├── logging.h │ │ │ ├── mutexlock.h │ │ │ ├── options.cc │ │ │ ├── posix_logger.h │ │ │ ├── random.h │ │ │ ├── status.cc │ │ │ ├── testharness.cc │ │ │ ├── testharness.h │ │ │ ├── testutil.cc │ │ │ └── testutil.h │ ├── leveldb-hyper-conf │ │ ├── linux │ │ │ └── config.h │ │ └── mac │ │ │ └── config.h │ ├── leveldb.gyp │ └── port-libuv │ │ ├── atomic_pointer_win.h │ │ ├── env_win.cc │ │ ├── port_uv.cc │ │ ├── port_uv.h │ │ ├── port_uv.h.bak │ │ ├── stdint-msvc2008.h │ │ ├── uv_condvar.h │ │ ├── uv_condvar_posix.cc │ │ ├── win_logger.cc │ │ └── win_logger.h └── snappy │ ├── freebsd │ ├── config.h │ └── snappy-stubs-public.h │ ├── linux │ ├── config.h │ └── snappy-stubs-public.h │ ├── mac │ ├── config.h │ └── snappy-stubs-public.h │ ├── snappy-1.1.1 │ ├── AUTHORS │ ├── COPYING │ ├── ChangeLog │ ├── INSTALL │ ├── Makefile.am │ ├── Makefile.in │ ├── NEWS │ ├── README │ ├── aclocal.m4 │ ├── autogen.sh │ ├── config.guess │ ├── config.h.in │ ├── config.sub │ ├── configure │ ├── configure.ac │ ├── depcomp │ ├── format_description.txt │ ├── framing_format.txt │ ├── install-sh │ ├── ltmain.sh │ ├── m4 │ │ └── gtest.m4 │ ├── missing │ ├── snappy-c.cc │ ├── snappy-c.h │ ├── snappy-internal.h │ ├── snappy-sinksource.cc │ ├── snappy-sinksource.h │ ├── snappy-stubs-internal.cc │ ├── snappy-stubs-internal.h │ ├── snappy-stubs-public.h │ ├── snappy-stubs-public.h.in │ ├── snappy-test.cc │ ├── snappy-test.h │ ├── snappy.cc │ ├── snappy.h │ ├── snappy_unittest.cc │ └── testdata │ │ ├── alice29.txt │ │ ├── asyoulik.txt │ │ ├── baddata1.snappy │ │ ├── baddata2.snappy │ │ ├── baddata3.snappy │ │ ├── cp.html │ │ ├── fields.c │ │ ├── geo.protodata │ │ ├── grammar.lsp │ │ ├── house.jpg │ │ ├── html │ │ ├── html_x_4 │ │ ├── kennedy.xls │ │ ├── kppkn.gtb │ │ ├── lcet10.txt │ │ ├── mapreduce-osdi-1.pdf │ │ ├── plrabn12.txt │ │ ├── ptt5 │ │ ├── sum │ │ ├── urls.10K │ │ └── xargs.1 │ ├── snappy.gyp │ ├── solaris │ ├── config.h │ └── snappy-stubs-public.h │ └── win32 │ ├── config.h │ └── snappy-stubs-public.h ├── iterator.js ├── leveldown-hyper.js ├── package.json ├── src ├── async.h ├── batch.cc ├── batch.h ├── batch_async.cc ├── batch_async.h ├── common.h ├── database.cc ├── database.h ├── database_async.cc ├── database_async.h ├── iterator.cc ├── iterator.h ├── iterator_async.cc ├── iterator_async.h ├── leveldown.cc ├── leveldown.h ├── leveldown_async.cc └── leveldown_async.h └── test ├── approximate-size-test.js ├── batch-test.js ├── chained-batch-test.js ├── cleanup-hanging-iterators-test.js ├── close-test.js ├── data └── testdata.bin ├── del-test.js ├── destroy-test.js ├── get-test.js ├── getproperty-test.js ├── iterator-range-test.js ├── iterator-recursion-test.js ├── iterator-test.js ├── leak-tester-batch.js ├── leak-tester.js ├── leveldown-test.js ├── livebackup-test.js ├── make.js ├── open-test.js ├── port-libuv-fix-test.js ├── put-get-del-test.js ├── put-test.js ├── repair-test.js └── stack-blower.js /.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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | build/ 3 | libleveldb.so 4 | libleveldb.a 5 | leakydb 6 | bench/ 7 | *.sln 8 | *.vcxproj 9 | *.vcxproj.filters 10 | *.tlog 11 | *.obj 12 | *.1sdk.pdb 13 | *.lastbuildstate 14 | npm-debug.log 15 | prebuilds/ 16 | .nyc_output/ 17 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | build/ 3 | test-data.tar 4 | test-data.db.tar 5 | deps/leveldb/leveldb-basho/ 6 | deps/leveldb/leveldb-hyper/ 7 | deps/leveldb/leveldb-rocksdb/ 8 | deps/snappy/snappy-1.1.1/testdata/ 9 | leakydb 10 | bench/ 11 | test/ 12 | deps/leveldb/leveldb-1.17.0/doc/ 13 | README 14 | INSTALL 15 | NEWS 16 | AUTHORS 17 | .nyc_output/ 18 | 19 | .travis.yml 20 | .dntrc 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | before_install: 6 | - export JOBS=max 7 | 8 | os: 9 | - osx 10 | - linux 11 | 12 | node_js: 13 | - 6 14 | - 8 15 | - 10 16 | 17 | after_success: npm run coverage 18 | 19 | notifications: 20 | email: false 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | **Copyright © 2012-present [Contributors](CONTRIBUTORS.md).** 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # leveldown-hyper 2 | 3 | **Discontinued.** 4 | 5 | --- 6 | 7 | `leveldown-hyper` is a fork of `leveldown` and uses [`HyperLevelDB`](https://github.com/rescrv/HyperLevelDB) as backend. It extends the `leveldown` api with functionality to do live backups. This README only documents the `liveBackup()` method. For a complete reference we refer to [`leveldown`](https://github.com/Level/leveldown). 8 | 9 | `leveldown` can be considered an upstream repository to `leveldown-hyper` and any common logic and bug fixes will be merged from upstream into this repository. 10 | 11 | **If you are upgrading:** please see [UPGRADING.md](UPGRADING.md). 12 | 13 | ### `db.liveBackup(name, callback)` 14 | 15 | liveBackup() is an instance method on an existing database object, used to make a live backup of the current state of the database. 16 | 17 | The `name` parameter is a `String`. A successful live backup will result in a backup folder named `backup-:name` inside the `location` folder of the current database. 18 | 19 | The `callback` function will be called with no arguments when a live backup was successful, or with a single `error` argument if the backup operation failed for any reason. 20 | 21 | ## Contributing 22 | 23 | [`Level/leveldown-hyper`](https://github.com/Level/leveldown-hyper) is an **OPEN Open Source Project**. This means that: 24 | 25 | > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 26 | 27 | See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details. 28 | 29 | ## License 30 | 31 | [MIT](LICENSE.md) © 2012-present [Contributors](CONTRIBUTORS.md). 32 | 33 | _`leveldown-hyper` builds on the excellent work of the [`HyperLevelDB`](https://github.com/rescrv/HyperLevelDB) team and the LevelDB and Snappy teams from Google and additional contributors. HyperLevelDB, LevelDB and Snappy are issued under the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)._ 34 | -------------------------------------------------------------------------------- /UPGRADING.md: -------------------------------------------------------------------------------- 1 | # Upgrade Guide 2 | 3 | This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md). 4 | 5 | ## v2 6 | 7 | Dropped support for node 0.12, 4, 5, and 7. 8 | 9 | If you're using node v10 you'll need at least `leveldown-hyper@2.0.0` to successfully compile. 10 | 11 | ### `.batch(array)` enforces objects 12 | 13 | This major release contains an upgrade to `abstract-leveldown` with a [breaking change](https://github.com/Level/abstract-leveldown/commit/a2621ad70571f6ade9d2be42632ece042e068805) for the array version of `.batch()`. This change ensures all elements in the batch array are objects. 14 | 15 | If you previously passed arrays to `.batch()` that contained `undefined` or `null`, they would be silently ignored. Now this will produce an error. 16 | -------------------------------------------------------------------------------- /bench/db-bench-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot <= 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 | -------------------------------------------------------------------------------- /bench/write-sorted-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot <= 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 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [{ 3 | "target_name": "leveldownhyper" 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-hyper" 26 | ] 27 | , "include_dirs" : [ 28 | " 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 | 14 | # HyperLevelDB authors: 15 | Robert Escriva 16 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/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-hyper-1.0.2/README: -------------------------------------------------------------------------------- 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 | 53 | Install 54 | ======= 55 | 56 | Get up and running quickly: 57 | 58 | $ autoreconf -i 59 | $ ./configure 60 | $ make 61 | # make install 62 | # ldconfig 63 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/db/builder.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/builder.h" 6 | 7 | #include "db/filename.h" 8 | #include "db/dbformat.h" 9 | #include "db/table_cache.h" 10 | #include "db/version_edit.h" 11 | #include "hyperleveldb/db.h" 12 | #include "hyperleveldb/env.h" 13 | #include "hyperleveldb/iterator.h" 14 | 15 | namespace leveldb { 16 | 17 | Status BuildTable(const std::string& dbname, 18 | Env* env, 19 | const Options& options, 20 | TableCache* table_cache, 21 | Iterator* iter, 22 | FileMetaData* meta) { 23 | Status s; 24 | meta->file_size = 0; 25 | iter->SeekToFirst(); 26 | 27 | std::string fname = SSTTableFileName(dbname, meta->number); 28 | if (iter->Valid()) { 29 | WritableFile* file; 30 | s = env->NewWritableFile(fname, &file); 31 | if (!s.ok()) { 32 | return s; 33 | } 34 | 35 | TableBuilder* builder = new TableBuilder(options, file); 36 | meta->smallest.DecodeFrom(iter->key()); 37 | for (; iter->Valid(); iter->Next()) { 38 | Slice key = iter->key(); 39 | meta->largest.DecodeFrom(key); 40 | builder->Add(key, iter->value()); 41 | } 42 | 43 | // Finish and check for builder errors 44 | if (s.ok()) { 45 | s = builder->Finish(); 46 | if (s.ok()) { 47 | meta->file_size = builder->FileSize(); 48 | assert(meta->file_size > 0); 49 | } 50 | } else { 51 | builder->Abandon(); 52 | } 53 | delete builder; 54 | 55 | // Finish and check for file errors 56 | if (s.ok()) { 57 | s = file->Sync(); 58 | } 59 | if (s.ok()) { 60 | s = file->Close(); 61 | } 62 | delete file; 63 | file = NULL; 64 | 65 | if (s.ok()) { 66 | // Verify that the table is usable 67 | Iterator* it = table_cache->NewIterator(ReadOptions(), 68 | meta->number, 69 | meta->file_size); 70 | s = it->status(); 71 | delete it; 72 | } 73 | } 74 | 75 | // Check for input iterator errors 76 | if (!iter->status().ok()) { 77 | s = iter->status(); 78 | } 79 | 80 | if (s.ok() && meta->file_size > 0) { 81 | // Keep it 82 | } else { 83 | env->DeleteFile(fname); 84 | } 85 | return s; 86 | } 87 | 88 | } // namespace leveldb 89 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/db/filename.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // File names used by DB code 6 | 7 | #ifndef STORAGE_LEVELDB_DB_FILENAME_H_ 8 | #define STORAGE_LEVELDB_DB_FILENAME_H_ 9 | 10 | #include 11 | #include 12 | #include "hyperleveldb/slice.h" 13 | #include "hyperleveldb/status.h" 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Env; 19 | 20 | enum FileType { 21 | kLogFile, 22 | kDBLockFile, 23 | kTableFile, 24 | kDescriptorFile, 25 | kCurrentFile, 26 | kTempFile, 27 | kInfoLogFile // Either the current one, or an old one 28 | }; 29 | 30 | // Return the name of the log file with the specified number 31 | // in the db named by "dbname". The result will be prefixed with 32 | // "dbname". 33 | extern std::string LogFileName(const std::string& dbname, uint64_t number); 34 | 35 | // Return the name of the sstable with the specified number 36 | // in the db named by "dbname". The result will be prefixed with 37 | // "dbname". 38 | extern std::string TableFileName(const std::string& dbname, uint64_t number); 39 | 40 | // Return the legacy file name for an sstable with the specified number 41 | // in the db named by "dbname". The result will be prefixed with 42 | // "dbname". 43 | extern std::string SSTTableFileName(const std::string& dbname, uint64_t number); 44 | 45 | // Return the name of the descriptor file for the db named by 46 | // "dbname" and the specified incarnation number. The result will be 47 | // prefixed with "dbname". 48 | extern std::string DescriptorFileName(const std::string& dbname, 49 | uint64_t number); 50 | 51 | // Return the name of the current file. This file contains the name 52 | // of the current manifest file. The result will be prefixed with 53 | // "dbname". 54 | extern std::string CurrentFileName(const std::string& dbname); 55 | 56 | // Return the name of the lock file for the db named by 57 | // "dbname". The result will be prefixed with "dbname". 58 | extern std::string LockFileName(const std::string& dbname); 59 | 60 | // Return the name of a temporary file owned by the db named "dbname". 61 | // The result will be prefixed with "dbname". 62 | extern std::string TempFileName(const std::string& dbname, uint64_t number); 63 | 64 | // Return the name of the info log file for "dbname". 65 | extern std::string InfoLogFileName(const std::string& dbname); 66 | 67 | // Return the name of the old info log file for "dbname". 68 | extern std::string OldInfoLogFileName(const std::string& dbname); 69 | 70 | // If filename is a leveldb file, store the type of the file in *type. 71 | // The number encoded in the filename is stored in *number. If the 72 | // filename was successfully parsed, returns true. Else return false. 73 | extern bool ParseFileName(const std::string& filename, 74 | uint64_t* number, 75 | FileType* type); 76 | 77 | // Make the CURRENT file point to the descriptor file with the 78 | // specified number. 79 | extern Status SetCurrentFile(Env* env, const std::string& dbname, 80 | uint64_t descriptor_number); 81 | 82 | 83 | } // namespace leveldb 84 | 85 | #endif // STORAGE_LEVELDB_DB_FILENAME_H_ 86 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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/leveldb-hyper-1.0.2/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 "hyperleveldb/slice.h" 11 | #include "hyperleveldb/status.h" 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class WritableFile; 17 | 18 | namespace log { 19 | 20 | class Writer { 21 | public: 22 | // Create a writer that will append data to "*dest". 23 | // "*dest" must be initially empty. 24 | // "*dest" must remain live while this Writer is in use. 25 | explicit Writer(WritableFile* dest); 26 | ~Writer(); 27 | 28 | Status AddRecord(const Slice& slice); 29 | 30 | private: 31 | WritableFile* dest_; 32 | port::Mutex offset_mtx_; 33 | uint64_t offset_; // Current offset in file 34 | 35 | // crc32c values for all supported record types. These are 36 | // pre-computed to reduce the overhead of computing the crc of the 37 | // record type stored in the header. 38 | uint32_t type_crc_[kMaxRecordType + 1]; 39 | 40 | Status EmitPhysicalRecordAt(RecordType type, const char* ptr, uint64_t offset, size_t length); 41 | 42 | // No copying allowed 43 | Writer(const Writer&); 44 | void operator=(const Writer&); 45 | }; 46 | 47 | } // namespace log 48 | } // namespace leveldb 49 | 50 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 51 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/db/memtable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_ 6 | #define STORAGE_LEVELDB_DB_MEMTABLE_H_ 7 | 8 | #include 9 | #include "hyperleveldb/db.h" 10 | #include "db/dbformat.h" 11 | #include "db/skiplist.h" 12 | #include "util/arena.h" 13 | 14 | namespace leveldb { 15 | 16 | class InternalKeyComparator; 17 | class Mutex; 18 | class MemTableIterator; 19 | 20 | class MemTable { 21 | public: 22 | // MemTables are reference counted. The initial reference count 23 | // is zero and the caller must call Ref() at least once. 24 | explicit MemTable(const InternalKeyComparator& comparator); 25 | 26 | // Increase reference count. 27 | // XXX use a release increment if not using GCC intrinsics 28 | void Ref() { __sync_add_and_fetch(&refs_, 1); } 29 | 30 | // Drop reference count. Delete if no more references exist. 31 | // XXX use an acquire decrement if not using GCC intrinsics 32 | void Unref() { 33 | int refs = __sync_sub_and_fetch(&refs_, 1); 34 | assert(refs >= 0); 35 | if (refs <= 0) { 36 | delete this; 37 | } 38 | } 39 | 40 | // Returns an estimate of the number of bytes of data in use by this 41 | // data structure. 42 | // 43 | // REQUIRES: external synchronization to prevent simultaneous 44 | // operations on the same MemTable. 45 | size_t ApproximateMemoryUsage(); 46 | 47 | // Return an iterator that yields the contents of the memtable. 48 | // 49 | // The caller must ensure that the underlying MemTable remains live 50 | // while the returned iterator is live. The keys returned by this 51 | // iterator are internal keys encoded by AppendInternalKey in the 52 | // db/format.{h,cc} module. 53 | Iterator* NewIterator(); 54 | 55 | // Add an entry into memtable that maps key to value at the 56 | // specified sequence number and with the specified type. 57 | // Typically value will be empty if type==kTypeDeletion. 58 | void Add(SequenceNumber seq, ValueType type, 59 | const Slice& key, 60 | const Slice& value); 61 | 62 | // If memtable contains a value for key, store it in *value and return true. 63 | // If memtable contains a deletion for key, store a NotFound() error 64 | // in *status and return true. 65 | // Else, return false. 66 | bool Get(const LookupKey& key, std::string* value, Status* s); 67 | 68 | private: 69 | ~MemTable(); // Private since only Unref() should be used to delete it 70 | typedef std::pair TableKey; 71 | 72 | struct KeyComparator { 73 | const InternalKeyComparator comparator; 74 | explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { } 75 | int operator()(TableKey a, TableKey b) const; 76 | }; 77 | friend class MemTableIterator; 78 | friend class MemTableBackwardIterator; 79 | 80 | typedef SkipList Table; 81 | 82 | KeyComparator comparator_; 83 | int refs_; 84 | port::Mutex mtx_; 85 | Arena arena_; 86 | Table table_; 87 | 88 | // No copying allowed 89 | MemTable(const MemTable&); 90 | void operator=(const MemTable&); 91 | }; 92 | 93 | } // namespace leveldb 94 | 95 | #endif // STORAGE_LEVELDB_DB_MEMTABLE_H_ 96 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/db/replay_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The HyperLevelDB 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_ROLLING_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_DB_ROLLING_ITERATOR_H_ 7 | 8 | #include 9 | #include 10 | #include "hyperleveldb/db.h" 11 | #include "hyperleveldb/replay_iterator.h" 12 | #include "db/dbformat.h" 13 | #include "db/memtable.h" 14 | 15 | namespace leveldb { 16 | 17 | class DBImpl; 18 | struct ReplayState { 19 | ReplayState(Iterator* i, SequenceNumber s, SequenceNumber l); 20 | ReplayState(MemTable* m, SequenceNumber s); 21 | MemTable* mem_; 22 | Iterator* iter_; 23 | SequenceNumber seq_start_; 24 | SequenceNumber seq_limit_; 25 | }; 26 | 27 | class ReplayIteratorImpl : public ReplayIterator { 28 | public: 29 | // Refs the memtable on its own; caller must hold mutex while creating this 30 | ReplayIteratorImpl(DBImpl* db, port::Mutex* mutex, const Comparator* cmp, 31 | Iterator* iter, MemTable* m, SequenceNumber s); 32 | virtual bool Valid(); 33 | virtual void Next(); 34 | virtual bool HasValue(); 35 | virtual Slice key() const; 36 | virtual Slice value() const; 37 | virtual Status status() const; 38 | 39 | // extra interface 40 | 41 | // we ref the memtable; caller holds mutex passed into ctor 42 | // REQUIRES: caller must hold mutex passed into ctor 43 | void enqueue(MemTable* m, SequenceNumber s); 44 | 45 | // REQUIRES: caller must hold mutex passed into ctor 46 | void cleanup(); // calls delete this; 47 | 48 | private: 49 | virtual ~ReplayIteratorImpl(); 50 | bool ParseKey(ParsedInternalKey* ikey); 51 | bool ParseKey(const Slice& k, ParsedInternalKey* ikey); 52 | void Prime(); 53 | 54 | DBImpl* const db_; 55 | port::Mutex* mutex_; 56 | const Comparator* const user_comparator_; 57 | SequenceNumber const start_at_; 58 | bool valid_; 59 | Status status_; 60 | 61 | bool has_current_user_key_; 62 | std::string current_user_key_; 63 | SequenceNumber current_user_sequence_; 64 | 65 | ReplayState rs_; 66 | std::list mems_; 67 | }; 68 | 69 | } // namespace leveldb 70 | 71 | #endif // STORAGE_LEVELDB_DB_ROLLING_ITERATOR_H_ 72 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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-hyper-1.0.2/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 "hyperleveldb/cache.h" 14 | #include "hyperleveldb/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-hyper-1.0.2/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-hyper-1.0.2/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 "hyperleveldb/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); 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-hyper-1.0.2/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-hyper-1.0.2/doc/log_format.txt: -------------------------------------------------------------------------------- 1 | The log file contents are a sequence of 32KB blocks. The only 2 | exception is that the tail of the file may contain a partial block. 3 | 4 | Each block consists of a sequence of records: 5 | block := record* trailer? 6 | record := 7 | checksum: uint32 // crc32c of type and data[] ; little-endian 8 | length: uint16 // little-endian 9 | type: uint8 // One of FULL, FIRST, MIDDLE, LAST 10 | data: uint8[length] 11 | 12 | A record never starts within the last six bytes of a block (since it 13 | won't fit). Any leftover bytes here form the trailer, which must 14 | consist entirely of zero bytes and must be skipped by readers. 15 | 16 | Aside: if exactly seven bytes are left in the current block, and a new 17 | non-zero length record is added, the writer must emit a FIRST record 18 | (which contains zero bytes of user data) to fill up the trailing seven 19 | bytes of the block and then emit all of the user data in subsequent 20 | blocks. 21 | 22 | More types may be added in the future. Some Readers may skip record 23 | types they do not understand, others may report that some data was 24 | skipped. 25 | 26 | FULL == 1 27 | FIRST == 2 28 | MIDDLE == 3 29 | LAST == 4 30 | 31 | The FULL record contains the contents of an entire user record. 32 | 33 | FIRST, MIDDLE, LAST are types used for user records that have been 34 | split into multiple fragments (typically because of block boundaries). 35 | FIRST is the type of the first fragment of a user record, LAST is the 36 | type of the last fragment of a user record, and MID is the type of all 37 | interior fragments of a user record. 38 | 39 | Example: consider a sequence of user records: 40 | A: length 1000 41 | B: length 97270 42 | C: length 8000 43 | A will be stored as a FULL record in the first block. 44 | 45 | B will be split into three fragments: first fragment occupies the rest 46 | of the first block, second fragment occupies the entirety of the 47 | second block, and the third fragment occupies a prefix of the third 48 | block. This will leave six bytes free in the third block, which will 49 | be left empty as the trailer. 50 | 51 | C will be stored as a FULL record in the fourth block. 52 | 53 | =================== 54 | 55 | Some benefits over the recordio format: 56 | 57 | (1) We do not need any heuristics for resyncing - just go to next 58 | block boundary and scan. If there is a corruption, skip to the next 59 | block. As a side-benefit, we do not get confused when part of the 60 | contents of one log file are embedded as a record inside another log 61 | file. 62 | 63 | (2) Splitting at approximate boundaries (e.g., for mapreduce) is 64 | simple: find the next block boundary and skip records until we 65 | hit a FULL or FIRST record. 66 | 67 | (3) We do not need extra buffering for large records. 68 | 69 | Some downsides compared to recordio format: 70 | 71 | (1) No packing of tiny records. This could be fixed by adding a new 72 | record type, so it is a shortcoming of the current implementation, 73 | not necessarily the format. 74 | 75 | (2) No compression. Again, this could be fixed by adding new record types. 76 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/hyperleveldb.upack.in: -------------------------------------------------------------------------------- 1 | package hyperleveldb 2 | | source="hyperleveldb" 3 | | debian name="libhyperleveldb0" 4 | | version="@VERSION@" 5 | | release="1" 6 | | license="BSD" 7 | | copyright="2011-2013 The LevelDB Authors" 8 | | homepage="http://hyperdex.org" 9 | | tarball="http://hyperdex.org/src/hyperleveldb-{version}.tar.gz" 10 | | debian section="libs" 11 | | configure="--disable-static" 12 | | summary="A fast key-value storage library" 13 | + {libdir}/libhyperleveldb.so.0 14 | + {libdir}/libhyperleveldb.so.0.0.0 15 | '''LevelDB is a fast key-value storage library written at Google that provides 16 | an ordered mapping from string keys to string values.''' 17 | 18 | subpackage hyperleveldb-devel 19 | | debian name="libhyperleveldb-dev" 20 | | debian section="libdevel" 21 | | debian requires="libhyperleveldb0{self}" 22 | | fedora requires="hyperleveldb{self}" 23 | | summary="A fast key-value storage library (development files)" 24 | + {includedir}/hyperleveldb/cache.h 25 | + {includedir}/hyperleveldb/c.h 26 | + {includedir}/hyperleveldb/comparator.h 27 | + {includedir}/hyperleveldb/db.h 28 | + {includedir}/hyperleveldb/env.h 29 | + {includedir}/hyperleveldb/filter_policy.h 30 | + {includedir}/hyperleveldb/iterator.h 31 | + {includedir}/hyperleveldb/options.h 32 | + {includedir}/hyperleveldb/replay_iterator.h 33 | + {includedir}/hyperleveldb/slice.h 34 | + {includedir}/hyperleveldb/status.h 35 | + {includedir}/hyperleveldb/table_builder.h 36 | + {includedir}/hyperleveldb/table.h 37 | + {includedir}/hyperleveldb/write_batch.h 38 | + {libdir}/libhyperleveldb.so 39 | + {libdir}/pkgconfig/libhyperleveldb.pc 40 | 41 | exclude {libdir}/libhyperleveldb.la 42 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/comparator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | 13 | class Slice; 14 | 15 | // A Comparator object provides a total order across slices that are 16 | // used as keys in an sstable or a database. A Comparator implementation 17 | // must be thread-safe since leveldb may invoke its methods concurrently 18 | // from multiple threads. 19 | class Comparator { 20 | public: 21 | virtual ~Comparator(); 22 | 23 | // Three-way comparison. Returns value: 24 | // < 0 iff "a" < "b", 25 | // == 0 iff "a" == "b", 26 | // > 0 iff "a" > "b" 27 | virtual int Compare(const Slice& a, const Slice& b) const = 0; 28 | 29 | // The name of the comparator. Used to check for comparator 30 | // mismatches (i.e., a DB created with one comparator is 31 | // accessed using a different comparator. 32 | // 33 | // The client of this package should switch to a new name whenever 34 | // the comparator implementation changes in a way that will cause 35 | // the relative ordering of any two keys to change. 36 | // 37 | // Names starting with "leveldb." are reserved and should not be used 38 | // by any clients of this package. 39 | virtual const char* Name() const = 0; 40 | 41 | // Advanced functions: these are used to reduce the space requirements 42 | // for internal data structures like index blocks. 43 | 44 | // If *start < limit, changes *start to a short string in [start,limit). 45 | // Simple comparator implementations may return with *start unchanged, 46 | // i.e., an implementation of this method that does nothing is correct. 47 | virtual void FindShortestSeparator( 48 | std::string* start, 49 | const Slice& limit) const = 0; 50 | 51 | // Changes *key to a short string >= *key. 52 | // Simple comparator implementations may return with *key unchanged, 53 | // i.e., an implementation of this method that does nothing is correct. 54 | virtual void FindShortSuccessor(std::string* key) const = 0; 55 | 56 | // If unsure, return 0; 57 | virtual uint64_t KeyNum(const Slice& key) const; 58 | }; 59 | 60 | // Return a builtin comparator that uses lexicographic byte-wise 61 | // ordering. The result remains the property of this module and 62 | // must not be deleted. 63 | extern const Comparator* BytewiseComparator(); 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 68 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/filter_policy.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A database can be configured with a custom FilterPolicy object. 6 | // This object is responsible for creating a small filter from a set 7 | // of keys. These filters are stored in leveldb and are consulted 8 | // automatically by leveldb to decide whether or not to read some 9 | // information from disk. In many cases, a filter can cut down the 10 | // number of disk seeks form a handful to a single disk seek per 11 | // DB::Get() call. 12 | // 13 | // Most people will want to use the builtin bloom filter support (see 14 | // NewBloomFilterPolicy() below). 15 | 16 | #ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 17 | #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 18 | 19 | #include 20 | 21 | namespace leveldb { 22 | 23 | class Slice; 24 | 25 | class FilterPolicy { 26 | public: 27 | virtual ~FilterPolicy(); 28 | 29 | // Return the name of this policy. Note that if the filter encoding 30 | // changes in an incompatible way, the name returned by this method 31 | // must be changed. Otherwise, old incompatible filters may be 32 | // passed to methods of this type. 33 | virtual const char* Name() const = 0; 34 | 35 | // keys[0,n-1] contains a list of keys (potentially with duplicates) 36 | // that are ordered according to the user supplied comparator. 37 | // Append a filter that summarizes keys[0,n-1] to *dst. 38 | // 39 | // Warning: do not change the initial contents of *dst. Instead, 40 | // append the newly constructed filter to *dst. 41 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) 42 | const = 0; 43 | 44 | // "filter" contains the data appended by a preceding call to 45 | // CreateFilter() on this class. This method must return true if 46 | // the key was in the list of keys passed to CreateFilter(). 47 | // This method may return true or false if the key was not on the 48 | // list, but it should aim to return false with a high probability. 49 | virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const = 0; 50 | }; 51 | 52 | // Return a new filter policy that uses a bloom filter with approximately 53 | // the specified number of bits per key. A good value for bits_per_key 54 | // is 10, which yields a filter with ~ 1% false positive rate. 55 | // 56 | // Callers must delete the result after any database that is using the 57 | // result has been closed. 58 | // 59 | // Note: if you are using a custom comparator that ignores some parts 60 | // of the keys being compared, you must not use NewBloomFilterPolicy() 61 | // and must provide your own FilterPolicy that also ignores the 62 | // corresponding parts of the keys. For example, if the comparator 63 | // ignores trailing spaces, it would be incorrect to use a 64 | // FilterPolicy (like NewBloomFilterPolicy) that does not ignore 65 | // trailing spaces in keys. 66 | extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key); 67 | 68 | } 69 | 70 | #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 71 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/replay_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The HyperLevelDB 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_REPLAY_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_ 7 | 8 | #include "hyperleveldb/slice.h" 9 | #include "hyperleveldb/status.h" 10 | 11 | namespace leveldb { 12 | 13 | class ReplayIterator { 14 | public: 15 | ReplayIterator(); 16 | 17 | // An iterator is either positioned at a deleted key, present key/value pair, 18 | // or not valid. This method returns true iff the iterator is valid. 19 | virtual bool Valid() = 0; 20 | 21 | // Moves to the next entry in the source. After this call, Valid() is 22 | // true iff the iterator was not positioned at the last entry in the source. 23 | // REQUIRES: Valid() 24 | virtual void Next() = 0; 25 | 26 | // Return true if the current entry points to a key-value pair. If this 27 | // returns false, it means the current entry is a deleted entry. 28 | virtual bool HasValue() = 0; 29 | 30 | // Return the key for the current entry. The underlying storage for 31 | // the returned slice is valid only until the next modification of 32 | // the iterator. 33 | // REQUIRES: Valid() 34 | virtual Slice key() const = 0; 35 | 36 | // Return the value for the current entry. The underlying storage for 37 | // the returned slice is valid only until the next modification of 38 | // the iterator. 39 | // REQUIRES: !AtEnd() && !AtStart() 40 | virtual Slice value() const = 0; 41 | 42 | // If an error has occurred, return it. Else return an ok status. 43 | virtual Status status() const = 0; 44 | 45 | protected: 46 | // must be released by giving it back to the DB 47 | virtual ~ReplayIterator(); 48 | 49 | private: 50 | // No copying allowed 51 | ReplayIterator(const ReplayIterator&); 52 | void operator=(const ReplayIterator&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_ 58 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/table.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_TABLE_H_ 7 | 8 | #include 9 | #include "hyperleveldb/iterator.h" 10 | 11 | namespace leveldb { 12 | 13 | class Block; 14 | class BlockHandle; 15 | class Footer; 16 | struct Options; 17 | class RandomAccessFile; 18 | struct ReadOptions; 19 | class TableCache; 20 | 21 | // A Table is a sorted map from strings to strings. Tables are 22 | // immutable and persistent. A Table may be safely accessed from 23 | // multiple threads without external synchronization. 24 | class Table { 25 | public: 26 | // Attempt to open the table that is stored in bytes [0..file_size) 27 | // of "file", and read the metadata entries necessary to allow 28 | // retrieving data from the table. 29 | // 30 | // If successful, returns ok and sets "*table" to the newly opened 31 | // table. The client should delete "*table" when no longer needed. 32 | // If there was an error while initializing the table, sets "*table" 33 | // to NULL and returns a non-ok status. Does not take ownership of 34 | // "*source", but the client must ensure that "source" remains live 35 | // for the duration of the returned table's lifetime. 36 | // 37 | // *file must remain live while this Table is in use. 38 | static Status Open(const Options& options, 39 | RandomAccessFile* file, 40 | uint64_t file_size, 41 | Table** table); 42 | 43 | ~Table(); 44 | 45 | // Returns a new iterator over the table contents. 46 | // The result of NewIterator() is initially invalid (caller must 47 | // call one of the Seek methods on the iterator before using it). 48 | Iterator* NewIterator(const ReadOptions&) const; 49 | 50 | // Given a key, return an approximate byte offset in the file where 51 | // the data for that key begins (or would begin if the key were 52 | // present in the file). The returned value is in terms of file 53 | // bytes, and so includes effects like compression of the underlying data. 54 | // E.g., the approximate offset of the last key in the table will 55 | // be close to the file length. 56 | uint64_t ApproximateOffsetOf(const Slice& key) const; 57 | 58 | private: 59 | struct Rep; 60 | Rep* rep_; 61 | 62 | explicit Table(Rep* rep) { rep_ = rep; } 63 | static Iterator* BlockReader(void*, const ReadOptions&, const Slice&); 64 | 65 | // Calls (*handle_result)(arg, ...) with the entry found after a call 66 | // to Seek(key). May not make such a call if filter policy says 67 | // that key is not present. 68 | friend class TableCache; 69 | Status InternalGet( 70 | const ReadOptions&, const Slice& key, 71 | void* arg, 72 | void (*handle_result)(void* arg, const Slice& k, const Slice& v)); 73 | 74 | 75 | void ReadMeta(const Footer& footer); 76 | void ReadFilter(const Slice& filter_handle_value); 77 | 78 | // No copying allowed 79 | Table(const Table&); 80 | void operator=(const Table&); 81 | }; 82 | 83 | } // namespace leveldb 84 | 85 | #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_ 86 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/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 "hyperleveldb/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-hyper-1.0.2/issues/issue178_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 178: a manual compaction causes deleted data to reappear. 6 | #include 7 | #include 8 | #include 9 | 10 | #include "hyperleveldb/db.h" 11 | #include "hyperleveldb/write_batch.h" 12 | #include "util/testharness.h" 13 | 14 | namespace { 15 | 16 | const int kNumKeys = 1100000; 17 | 18 | std::string Key1(int i) { 19 | char buf[100]; 20 | snprintf(buf, sizeof(buf), "my_key_%d", i); 21 | return buf; 22 | } 23 | 24 | std::string Key2(int i) { 25 | return Key1(i) + "_xxx"; 26 | } 27 | 28 | class Issue178 { }; 29 | 30 | TEST(Issue178, Test) { 31 | // Get rid of any state from an old run. 32 | std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test"; 33 | DestroyDB(dbpath, leveldb::Options()); 34 | 35 | // Open database. Disable compression since it affects the creation 36 | // of layers and the code below is trying to test against a very 37 | // specific scenario. 38 | leveldb::DB* db; 39 | leveldb::Options db_options; 40 | db_options.create_if_missing = true; 41 | db_options.compression = leveldb::kNoCompression; 42 | ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db)); 43 | 44 | // create first key range 45 | leveldb::WriteBatch batch; 46 | for (size_t i = 0; i < kNumKeys; i++) { 47 | batch.Put(Key1(i), "value for range 1 key"); 48 | } 49 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 50 | 51 | // create second key range 52 | batch.Clear(); 53 | for (size_t i = 0; i < kNumKeys; i++) { 54 | batch.Put(Key2(i), "value for range 2 key"); 55 | } 56 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 57 | 58 | // delete second key range 59 | batch.Clear(); 60 | for (size_t i = 0; i < kNumKeys; i++) { 61 | batch.Delete(Key2(i)); 62 | } 63 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); 64 | 65 | // compact database 66 | std::string start_key = Key1(0); 67 | std::string end_key = Key1(kNumKeys - 1); 68 | leveldb::Slice least(start_key.data(), start_key.size()); 69 | leveldb::Slice greatest(end_key.data(), end_key.size()); 70 | 71 | // commenting out the line below causes the example to work correctly 72 | db->CompactRange(&least, &greatest); 73 | 74 | // count the keys 75 | leveldb::Iterator* iter = db->NewIterator(leveldb::ReadOptions()); 76 | size_t num_keys = 0; 77 | for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { 78 | num_keys++; 79 | } 80 | delete iter; 81 | ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys"; 82 | 83 | // close database 84 | delete db; 85 | DestroyDB(dbpath, leveldb::Options()); 86 | } 87 | 88 | } // anonymous namespace 89 | 90 | int main(int argc, char** argv) { 91 | return leveldb::test::RunAllTests(); 92 | } 93 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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-hyper-1.0.2/libhyperleveldb.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: HyperLevelDB 7 | Description: A fast and lightweight key-value storage library 8 | Version: @VERSION@ 9 | 10 | Requires: 11 | Libs: -L${libdir} -lhyperleveldb 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/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_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #endif 18 | 19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 20 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 | #include "util/logging.h" 11 | 12 | namespace leveldb { 13 | namespace port { 14 | 15 | static void PthreadCall(const char* label, int result) { 16 | if (result != 0) { 17 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 18 | abort(); 19 | } 20 | } 21 | 22 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 23 | 24 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 25 | 26 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 27 | 28 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 29 | 30 | CondVar::CondVar(Mutex* mu) 31 | : mu_(mu) { 32 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 33 | } 34 | 35 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 36 | 37 | void CondVar::Wait() { 38 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 39 | } 40 | 41 | void CondVar::Signal() { 42 | PthreadCall("signal", pthread_cond_signal(&cv_)); 43 | } 44 | 45 | void CondVar::SignalAll() { 46 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 47 | } 48 | 49 | void InitOnce(OnceType* once, void (*initializer)()) { 50 | PthreadCall("once", pthread_once(once, initializer)); 51 | } 52 | 53 | } // namespace port 54 | } // namespace leveldb 55 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/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 "hyperleveldb/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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-hyper-1.0.2/table/filter_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A filter block is stored near the end of a Table file. It contains 6 | // filters (e.g., bloom filters) for all data blocks in the table combined 7 | // into a single filter block. 8 | 9 | #ifndef STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 10 | #define STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "hyperleveldb/slice.h" 17 | #include "util/hash.h" 18 | 19 | namespace leveldb { 20 | 21 | class FilterPolicy; 22 | 23 | // A FilterBlockBuilder is used to construct all of the filters for a 24 | // particular Table. It generates a single string which is stored as 25 | // a special block in the Table. 26 | // 27 | // The sequence of calls to FilterBlockBuilder must match the regexp: 28 | // (StartBlock AddKey*)* Finish 29 | class FilterBlockBuilder { 30 | public: 31 | explicit FilterBlockBuilder(const FilterPolicy*); 32 | 33 | void StartBlock(uint64_t block_offset); 34 | void AddKey(const Slice& key); 35 | Slice Finish(); 36 | 37 | private: 38 | void GenerateFilter(); 39 | 40 | const FilterPolicy* policy_; 41 | std::string keys_; // Flattened key contents 42 | std::vector start_; // Starting index in keys_ of each key 43 | std::string result_; // Filter data computed so far 44 | std::vector tmp_keys_; // policy_->CreateFilter() argument 45 | std::vector filter_offsets_; 46 | 47 | // No copying allowed 48 | FilterBlockBuilder(const FilterBlockBuilder&); 49 | void operator=(const FilterBlockBuilder&); 50 | }; 51 | 52 | class FilterBlockReader { 53 | public: 54 | // REQUIRES: "contents" and *policy must stay live while *this is live. 55 | FilterBlockReader(const FilterPolicy* policy, const Slice& contents); 56 | bool KeyMayMatch(uint64_t block_offset, const Slice& key); 57 | 58 | private: 59 | const FilterPolicy* policy_; 60 | const char* data_; // Pointer to filter data (at block-start) 61 | const char* offset_; // Pointer to beginning of offset array (at block-end) 62 | size_t num_; // Number of entries in offset array 63 | size_t base_lg_; // Encoding parameter (see kFilterBaseLg in .cc file) 64 | }; 65 | 66 | } 67 | 68 | #endif // STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_ 69 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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-hyper-1.0.2/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-hyper-1.0.2/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-hyper-1.0.2/table/two_level_iterator.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_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "hyperleveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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*) > 8) ? sizeof(void*) : 8; 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-hyper-1.0.2/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-hyper-1.0.2/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-hyper-1.0.2/util/bloom.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "hyperleveldb/filter_policy.h" 6 | 7 | #include "hyperleveldb/slice.h" 8 | #include "util/hash.h" 9 | 10 | namespace leveldb { 11 | 12 | namespace { 13 | static uint32_t BloomHash(const Slice& key) { 14 | return Hash(key.data(), key.size(), 0xbc9f1d34); 15 | } 16 | 17 | class BloomFilterPolicy : public FilterPolicy { 18 | private: 19 | size_t bits_per_key_; 20 | size_t k_; 21 | 22 | public: 23 | explicit BloomFilterPolicy(int bits_per_key) 24 | : bits_per_key_(bits_per_key) { 25 | // We intentionally round down to reduce probing cost a little bit 26 | k_ = static_cast(bits_per_key * 0.69); // 0.69 =~ ln(2) 27 | if (k_ < 1) k_ = 1; 28 | if (k_ > 30) k_ = 30; 29 | } 30 | 31 | virtual const char* Name() const { 32 | return "leveldb.BuiltinBloomFilter"; 33 | } 34 | 35 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const { 36 | // Compute bloom filter size (in both bits and bytes) 37 | size_t bits = n * bits_per_key_; 38 | 39 | // For small n, we can see a very high false positive rate. Fix it 40 | // by enforcing a minimum bloom filter length. 41 | if (bits < 64) bits = 64; 42 | 43 | size_t bytes = (bits + 7) / 8; 44 | bits = bytes * 8; 45 | 46 | const size_t init_size = dst->size(); 47 | dst->resize(init_size + bytes, 0); 48 | dst->push_back(static_cast(k_)); // Remember # of probes in filter 49 | char* array = &(*dst)[init_size]; 50 | for (size_t i = 0; i < n; i++) { 51 | // Use double-hashing to generate a sequence of hash values. 52 | // See analysis in [Kirsch,Mitzenmacher 2006]. 53 | uint32_t h = BloomHash(keys[i]); 54 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits 55 | for (size_t j = 0; j < k_; j++) { 56 | const uint32_t bitpos = h % bits; 57 | array[bitpos/8] |= (1 << (bitpos % 8)); 58 | h += delta; 59 | } 60 | } 61 | } 62 | 63 | virtual bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const { 64 | const size_t len = bloom_filter.size(); 65 | if (len < 2) return false; 66 | 67 | const char* array = bloom_filter.data(); 68 | const size_t bits = (len - 1) * 8; 69 | 70 | // Use the encoded k so that we can read filters generated by 71 | // bloom filters created using different parameters. 72 | const size_t k = array[len-1]; 73 | if (k > 30) { 74 | // Reserved for potentially new encodings for short bloom filters. 75 | // Consider it a match. 76 | return true; 77 | } 78 | 79 | uint32_t h = BloomHash(key); 80 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits 81 | for (size_t j = 0; j < k; j++) { 82 | const uint32_t bitpos = h % bits; 83 | if ((array[bitpos/8] & (1 << (bitpos % 8))) == 0) return false; 84 | h += delta; 85 | } 86 | return true; 87 | } 88 | }; 89 | } 90 | 91 | const FilterPolicy* NewBloomFilterPolicy(int bits_per_key) { 92 | return new BloomFilterPolicy(bits_per_key); 93 | } 94 | 95 | } // namespace leveldb 96 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/util/comparator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include 7 | #include "hyperleveldb/comparator.h" 8 | #include "hyperleveldb/slice.h" 9 | #include "port/port.h" 10 | #include "util/coding.h" 11 | #include "util/logging.h" 12 | 13 | namespace leveldb { 14 | 15 | Comparator::~Comparator() { } 16 | 17 | uint64_t Comparator::KeyNum(const Slice& key) const { 18 | return 0; 19 | } 20 | 21 | namespace { 22 | class BytewiseComparatorImpl : public Comparator { 23 | public: 24 | BytewiseComparatorImpl() { } 25 | 26 | virtual const char* Name() const { 27 | return "leveldb.BytewiseComparator"; 28 | } 29 | 30 | virtual int Compare(const Slice& a, const Slice& b) const { 31 | return a.compare(b); 32 | } 33 | 34 | virtual void FindShortestSeparator( 35 | std::string* start, 36 | const Slice& limit) const { 37 | // Find length of common prefix 38 | size_t min_length = std::min(start->size(), limit.size()); 39 | size_t diff_index = 0; 40 | while ((diff_index < min_length) && 41 | ((*start)[diff_index] == limit[diff_index])) { 42 | diff_index++; 43 | } 44 | 45 | if (diff_index >= min_length) { 46 | // Do not shorten if one string is a prefix of the other 47 | } else { 48 | uint8_t diff_byte = static_cast((*start)[diff_index]); 49 | if (diff_byte < static_cast(0xff) && 50 | diff_byte + 1 < static_cast(limit[diff_index])) { 51 | (*start)[diff_index]++; 52 | start->resize(diff_index + 1); 53 | assert(Compare(*start, limit) < 0); 54 | } 55 | } 56 | } 57 | 58 | virtual void FindShortSuccessor(std::string* key) const { 59 | // Find first character that can be incremented 60 | size_t n = key->size(); 61 | for (size_t i = 0; i < n; i++) { 62 | const uint8_t byte = (*key)[i]; 63 | if (byte != static_cast(0xff)) { 64 | (*key)[i] = byte + 1; 65 | key->resize(i+1); 66 | return; 67 | } 68 | } 69 | // *key is a run of 0xffs. Leave it alone. 70 | } 71 | 72 | virtual uint64_t KeyNum(const Slice& key) const { 73 | unsigned char buf[sizeof(uint64_t)]; 74 | memset(buf, 0, sizeof(buf)); 75 | memmove(buf, key.data(), std::min(key.size(), sizeof(uint64_t))); 76 | uint64_t number; 77 | number = static_cast(buf[0]) << 56 78 | | static_cast(buf[1]) << 48 79 | | static_cast(buf[2]) << 40 80 | | static_cast(buf[3]) << 32 81 | | static_cast(buf[4]) << 24 82 | | static_cast(buf[5]) << 16 83 | | static_cast(buf[6]) << 8 84 | | static_cast(buf[7]); 85 | return number; 86 | } 87 | }; 88 | } // namespace 89 | 90 | static port::OnceType once = LEVELDB_ONCE_INIT; 91 | static const Comparator* bytewise; 92 | 93 | static void InitModule() { 94 | bytewise = new BytewiseComparatorImpl; 95 | } 96 | 97 | const Comparator* BytewiseComparator() { 98 | port::InitOnce(&once, InitModule); 99 | return bytewise; 100 | } 101 | 102 | } // namespace leveldb 103 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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-hyper-1.0.2/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-hyper-1.0.2/util/env.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "hyperleveldb/env.h" 6 | 7 | namespace leveldb { 8 | 9 | Env::~Env() { 10 | } 11 | 12 | SequentialFile::~SequentialFile() { 13 | } 14 | 15 | RandomAccessFile::~RandomAccessFile() { 16 | } 17 | 18 | WritableFile::~WritableFile() { 19 | } 20 | 21 | Logger::~Logger() { 22 | } 23 | 24 | FileLock::~FileLock() { 25 | } 26 | 27 | void Log(Logger* info_log, const char* format, ...) { 28 | if (info_log != NULL) { 29 | va_list ap; 30 | va_start(ap, format); 31 | info_log->Logv(format, ap); 32 | va_end(ap); 33 | } 34 | } 35 | 36 | static Status DoWriteStringToFile(Env* env, const Slice& data, 37 | const std::string& fname, 38 | bool should_sync) { 39 | WritableFile* file; 40 | Status s = env->NewWritableFile(fname, &file); 41 | if (!s.ok()) { 42 | return s; 43 | } 44 | s = file->Append(data); 45 | if (s.ok() && should_sync) { 46 | s = file->Sync(); 47 | } 48 | if (s.ok()) { 49 | s = file->Close(); 50 | } 51 | delete file; // Will auto-close if we did not close above 52 | if (!s.ok()) { 53 | env->DeleteFile(fname); 54 | } 55 | return s; 56 | } 57 | 58 | Status WriteStringToFile(Env* env, const Slice& data, 59 | const std::string& fname) { 60 | return DoWriteStringToFile(env, data, fname, false); 61 | } 62 | 63 | Status WriteStringToFileSync(Env* env, const Slice& data, 64 | const std::string& fname) { 65 | return DoWriteStringToFile(env, data, fname, true); 66 | } 67 | 68 | Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { 69 | data->clear(); 70 | SequentialFile* file; 71 | Status s = env->NewSequentialFile(fname, &file); 72 | if (!s.ok()) { 73 | return s; 74 | } 75 | static const int kBufferSize = 8192; 76 | char* space = new char[kBufferSize]; 77 | while (true) { 78 | Slice fragment; 79 | s = file->Read(kBufferSize, &fragment, space); 80 | if (!s.ok()) { 81 | break; 82 | } 83 | data->append(fragment.data(), fragment.size()); 84 | if (fragment.empty()) { 85 | break; 86 | } 87 | } 88 | delete[] space; 89 | delete file; 90 | return s; 91 | } 92 | 93 | EnvWrapper::~EnvWrapper() { 94 | } 95 | 96 | } // namespace leveldb 97 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/util/env_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "hyperleveldb/env.h" 6 | 7 | #include "port/port.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | static const int kDelayMicros = 100000; 13 | 14 | class EnvPosixTest { 15 | private: 16 | port::Mutex mu_; 17 | std::string events_; 18 | 19 | public: 20 | Env* env_; 21 | EnvPosixTest() : env_(Env::Default()) { } 22 | }; 23 | 24 | static void SetBool(void* ptr) { 25 | reinterpret_cast(ptr)->NoBarrier_Store(ptr); 26 | } 27 | 28 | TEST(EnvPosixTest, RunImmediately) { 29 | port::AtomicPointer called (NULL); 30 | env_->Schedule(&SetBool, &called); 31 | Env::Default()->SleepForMicroseconds(kDelayMicros); 32 | ASSERT_TRUE(called.NoBarrier_Load() != NULL); 33 | } 34 | 35 | TEST(EnvPosixTest, RunMany) { 36 | port::AtomicPointer last_id (NULL); 37 | 38 | struct CB { 39 | port::AtomicPointer* last_id_ptr; // Pointer to shared slot 40 | uintptr_t id; // Order# for the execution of this callback 41 | 42 | CB(port::AtomicPointer* p, int i) : last_id_ptr(p), id(i) { } 43 | 44 | static void Run(void* v) { 45 | CB* cb = reinterpret_cast(v); 46 | void* cur = cb->last_id_ptr->NoBarrier_Load(); 47 | ASSERT_EQ(cb->id-1, reinterpret_cast(cur)); 48 | cb->last_id_ptr->Release_Store(reinterpret_cast(cb->id)); 49 | } 50 | }; 51 | 52 | // Schedule in different order than start time 53 | CB cb1(&last_id, 1); 54 | CB cb2(&last_id, 2); 55 | CB cb3(&last_id, 3); 56 | CB cb4(&last_id, 4); 57 | env_->Schedule(&CB::Run, &cb1); 58 | env_->Schedule(&CB::Run, &cb2); 59 | env_->Schedule(&CB::Run, &cb3); 60 | env_->Schedule(&CB::Run, &cb4); 61 | 62 | Env::Default()->SleepForMicroseconds(kDelayMicros); 63 | void* cur = last_id.Acquire_Load(); 64 | ASSERT_EQ(4, reinterpret_cast(cur)); 65 | } 66 | 67 | struct State { 68 | port::Mutex mu; 69 | int val; 70 | int num_running; 71 | }; 72 | 73 | static void ThreadBody(void* arg) { 74 | State* s = reinterpret_cast(arg); 75 | s->mu.Lock(); 76 | s->val += 1; 77 | s->num_running -= 1; 78 | s->mu.Unlock(); 79 | } 80 | 81 | TEST(EnvPosixTest, StartThread) { 82 | State state; 83 | state.val = 0; 84 | state.num_running = 3; 85 | for (int i = 0; i < 3; i++) { 86 | env_->StartThread(&ThreadBody, &state); 87 | } 88 | while (true) { 89 | state.mu.Lock(); 90 | int num = state.num_running; 91 | state.mu.Unlock(); 92 | if (num == 0) { 93 | break; 94 | } 95 | Env::Default()->SleepForMicroseconds(kDelayMicros); 96 | } 97 | ASSERT_EQ(state.val, 3); 98 | } 99 | 100 | } // namespace leveldb 101 | 102 | int main(int argc, char** argv) { 103 | return leveldb::test::RunAllTests(); 104 | } 105 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 += data[2] << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += data[1] << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += 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-hyper-1.0.2/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-hyper-1.0.2/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-hyper-1.0.2/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 "hyperleveldb/env.h" 12 | #include "hyperleveldb/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 ConsumeChar(Slice* in, char c) { 49 | if (!in->empty() && (*in)[0] == c) { 50 | in->remove_prefix(1); 51 | return true; 52 | } else { 53 | return false; 54 | } 55 | } 56 | 57 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 58 | uint64_t v = 0; 59 | int digits = 0; 60 | while (!in->empty()) { 61 | char c = (*in)[0]; 62 | if (c >= '0' && c <= '9') { 63 | ++digits; 64 | const int delta = (c - '0'); 65 | static const uint64_t kMaxUint64 = ~static_cast(0); 66 | if (v > kMaxUint64/10 || 67 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 68 | // Overflow 69 | return false; 70 | } 71 | v = (v * 10) + delta; 72 | in->remove_prefix(1); 73 | } else { 74 | break; 75 | } 76 | } 77 | *val = v; 78 | return (digits > 0); 79 | } 80 | 81 | } // namespace leveldb 82 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 | // If *in starts with "c", advances *in past the first character and 36 | // returns true. Otherwise, returns false. 37 | extern bool ConsumeChar(Slice* in, char c); 38 | 39 | // Parse a human-readable number from "*in" into *value. On success, 40 | // advances "*in" past the consumed number and sets "*val" to the 41 | // numeric value. Otherwise, returns false and leaves *in in an 42 | // unspecified state. 43 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 44 | 45 | } // namespace leveldb 46 | 47 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 48 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/options.h" 6 | 7 | #include "hyperleveldb/comparator.h" 8 | #include "hyperleveldb/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 | filter_policy(NULL), 26 | manual_garbage_collection(false) { 27 | } 28 | 29 | 30 | } // namespace leveldb 31 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/util/posix_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Logger implementation that can be shared by all environments 6 | // where enough posix functionality is available. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 9 | #define STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "hyperleveldb/env.h" 16 | 17 | namespace leveldb { 18 | 19 | class PosixLogger : public Logger { 20 | private: 21 | FILE* file_; 22 | uint64_t (*gettid_)(); // Return the thread id for the current thread 23 | public: 24 | PosixLogger(FILE* f, uint64_t (*gettid)()) : file_(f), gettid_(gettid) { } 25 | virtual ~PosixLogger() { 26 | fclose(file_); 27 | } 28 | virtual void Logv(const char* format, va_list ap) { 29 | const uint64_t thread_id = (*gettid_)(); 30 | 31 | // We try twice: the first time with a fixed-size stack allocated buffer, 32 | // and the second time with a much larger dynamically allocated buffer. 33 | char buffer[500]; 34 | for (int iter = 0; iter < 2; iter++) { 35 | char* base; 36 | int bufsize; 37 | if (iter == 0) { 38 | bufsize = sizeof(buffer); 39 | base = buffer; 40 | } else { 41 | bufsize = 30000; 42 | base = new char[bufsize]; 43 | } 44 | char* p = base; 45 | char* limit = base + bufsize; 46 | 47 | struct timeval now_tv; 48 | gettimeofday(&now_tv, NULL); 49 | const time_t seconds = now_tv.tv_sec; 50 | struct tm t; 51 | localtime_r(&seconds, &t); 52 | p += snprintf(p, limit - p, 53 | "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", 54 | t.tm_year + 1900, 55 | t.tm_mon + 1, 56 | t.tm_mday, 57 | t.tm_hour, 58 | t.tm_min, 59 | t.tm_sec, 60 | static_cast(now_tv.tv_usec), 61 | static_cast(thread_id)); 62 | 63 | // Print the message 64 | if (p < limit) { 65 | va_list backup_ap; 66 | va_copy(backup_ap, ap); 67 | p += vsnprintf(p, limit - p, format, backup_ap); 68 | va_end(backup_ap); 69 | } 70 | 71 | // Truncate to available space if necessary 72 | if (p >= limit) { 73 | if (iter == 0) { 74 | continue; // Try again with larger buffer 75 | } else { 76 | p = limit - 1; 77 | } 78 | } 79 | 80 | // Add newline if necessary 81 | if (p == base || p[-1] != '\n') { 82 | *p++ = '\n'; 83 | } 84 | 85 | assert(p <= limit); 86 | fwrite(base, 1, p - base, file_); 87 | fflush(file_); 88 | if (base != buffer) { 89 | delete[] base; 90 | } 91 | break; 92 | } 93 | } 94 | }; 95 | 96 | } // namespace leveldb 97 | 98 | #endif // STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_ 99 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 | // Avoid bad seeds. 21 | if (seed_ == 0 || seed_ == 2147483647L) { 22 | seed_ = 1; 23 | } 24 | } 25 | uint32_t Next() { 26 | static const uint32_t M = 2147483647L; // 2^31-1 27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 28 | // We are computing 29 | // seed_ = (seed_ * A) % M, where M = 2^31-1 30 | // 31 | // seed_ must not be zero or M, or else all subsequent computed values 32 | // will be zero or M respectively. For all other values, seed_ will end 33 | // up cycling through every number in [1,M-1] 34 | uint64_t product = seed_ * A; 35 | 36 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 37 | seed_ = static_cast((product >> 31) + (product & M)); 38 | // The first reduction may overflow by 1 bit, so we may need to 39 | // repeat. mod == M is not possible; using > allows the faster 40 | // sign-bit-based test. 41 | if (seed_ > M) { 42 | seed_ -= M; 43 | } 44 | return seed_; 45 | } 46 | // Returns a uniformly distributed value in the range [0..n-1] 47 | // REQUIRES: n > 0 48 | uint32_t Uniform(int n) { return Next() % n; } 49 | 50 | // Randomly returns true ~"1/n" of the time, and false otherwise. 51 | // REQUIRES: n > 0 52 | bool OneIn(int n) { return (Next() % n) == 0; } 53 | 54 | // Skewed: pick "base" uniformly from range [0,max_log] and then 55 | // return "base" random bits. The effect is to pick a number in the 56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 57 | uint32_t Skewed(int max_log) { 58 | return Uniform(1 << Uniform(max_log + 1)); 59 | } 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 65 | -------------------------------------------------------------------------------- /deps/leveldb/leveldb-hyper-1.0.2/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 "hyperleveldb/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-hyper-1.0.2/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 | 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-hyper-1.0.2/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-hyper-1.0.2/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 "hyperleveldb/env.h" 9 | #include "hyperleveldb/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) { 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 | 50 | } // namespace test 51 | } // namespace leveldb 52 | 53 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 54 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/snappy/freebsd/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/linux/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/mac/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/AUTHORS: -------------------------------------------------------------------------------- 1 | opensource@google.com 2 | -------------------------------------------------------------------------------- /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/snappy/snappy-1.1.1/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | # Library. 4 | lib_LTLIBRARIES = libsnappy.la 5 | libsnappy_la_SOURCES = snappy.cc snappy-sinksource.cc snappy-stubs-internal.cc snappy-c.cc 6 | libsnappy_la_LDFLAGS = -version-info $(SNAPPY_LTVERSION) 7 | 8 | include_HEADERS = snappy.h snappy-sinksource.h snappy-stubs-public.h snappy-c.h 9 | noinst_HEADERS = snappy-internal.h snappy-stubs-internal.h snappy-test.h 10 | 11 | # Unit tests and benchmarks. 12 | snappy_unittest_CPPFLAGS = $(gflags_CFLAGS) $(GTEST_CPPFLAGS) 13 | snappy_unittest_SOURCES = snappy_unittest.cc snappy-test.cc 14 | snappy_unittest_LDFLAGS = $(GTEST_LDFLAGS) 15 | snappy_unittest_LDADD = libsnappy.la $(UNITTEST_LIBS) $(gflags_LIBS) $(GTEST_LIBS) 16 | TESTS = snappy_unittest 17 | noinst_PROGRAMS = $(TESTS) 18 | 19 | EXTRA_DIST = autogen.sh testdata/alice29.txt testdata/asyoulik.txt testdata/baddata1.snappy testdata/baddata2.snappy testdata/baddata3.snappy testdata/cp.html testdata/fields.c testdata/geo.protodata testdata/grammar.lsp testdata/house.jpg testdata/html testdata/html_x_4 testdata/kennedy.xls testdata/kppkn.gtb testdata/lcet10.txt testdata/mapreduce-osdi-1.pdf testdata/plrabn12.txt testdata/ptt5 testdata/sum testdata/urls.10K testdata/xargs.1 20 | dist_doc_DATA = ChangeLog COPYING INSTALL NEWS README format_description.txt framing_format.txt 21 | 22 | libtool: $(LIBTOOL_DEPS) 23 | $(SHELL) ./config.status --recheck 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/snappy-sinksource.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | 31 | #include "snappy-sinksource.h" 32 | 33 | namespace snappy { 34 | 35 | Source::~Source() { } 36 | 37 | Sink::~Sink() { } 38 | 39 | char* Sink::GetAppendBuffer(size_t length, char* scratch) { 40 | return scratch; 41 | } 42 | 43 | ByteArraySource::~ByteArraySource() { } 44 | 45 | size_t ByteArraySource::Available() const { return left_; } 46 | 47 | const char* ByteArraySource::Peek(size_t* len) { 48 | *len = left_; 49 | return ptr_; 50 | } 51 | 52 | void ByteArraySource::Skip(size_t n) { 53 | left_ -= n; 54 | ptr_ += n; 55 | } 56 | 57 | UncheckedByteArraySink::~UncheckedByteArraySink() { } 58 | 59 | void UncheckedByteArraySink::Append(const char* data, size_t n) { 60 | // Do no copying if the caller filled in the result of GetAppendBuffer() 61 | if (data != dest_) { 62 | memcpy(dest_, data, n); 63 | } 64 | dest_ += n; 65 | } 66 | 67 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { 68 | return dest_; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /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/snappy/snappy-1.1.1/testdata/baddata1.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata1.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata2.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata2.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/baddata3.snappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata3.snappy -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/cp.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/cp.html -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/geo.protodata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/geo.protodata -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/house.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/house.jpg -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/kennedy.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/kennedy.xls -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/ptt5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/ptt5 -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.1/testdata/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/sum -------------------------------------------------------------------------------- /deps/snappy/snappy.gyp: -------------------------------------------------------------------------------- 1 | {'targets': [{ 2 | 'variables': { 3 | 'conditions': [ 4 | ['OS=="linux"', {'os_include': 'linux'}] 5 | , ['OS=="mac"', {'os_include': 'mac'}] 6 | , ['OS=="solaris"', {'os_include': 'solaris'}] 7 | , ['OS=="win"', {'os_include': 'win32'}] 8 | , ['OS=="freebsd"', {'os_include': 'freebsd'}] 9 | ] 10 | } 11 | , 'target_name': 'snappy' 12 | , 'type': 'static_library' 13 | # Overcomes an issue with the linker and thin .a files on SmartOS 14 | , 'standalone_static_library': 1 15 | , 'include_dirs': [ 16 | '<(os_include)' 17 | , 'snappy-1.1.1' 18 | ] 19 | , 'direct_dependent_settings': { 20 | 'include_dirs': [ 21 | 'snappy-1.1.1' 22 | ] 23 | } 24 | , 'defines': [ 25 | 'HAVE_CONFIG_H=1' 26 | ] 27 | , 'conditions': [ 28 | ['OS == "win"', { 29 | 'defines': [ 30 | '_HAS_EXCEPTIONS=0' 31 | ] 32 | , 'msvs_settings': { 33 | 'VCCLCompilerTool': { 34 | 'RuntimeTypeInfo': 'false' 35 | , 'EnableFunctionLevelLinking': 'true' 36 | , 'ExceptionHandling': '2' 37 | , 'DisableSpecificWarnings': [ '4355', '4530' ,'4267', '4244', '4506', '4018' ] 38 | } 39 | } 40 | }] 41 | , ['OS == "linux"', { 42 | 'cflags': [ 43 | '-Wno-sign-compare' 44 | , '-Wno-unused-function' 45 | ] 46 | , 'cflags!': [ '-fno-tree-vrp' ] 47 | }] 48 | , ['OS == "freebsd"', { 49 | 'cflags': [ 50 | '-Wno-sign-compare' 51 | , '-Wno-unused-function' 52 | ] 53 | }] 54 | , ['OS == "solaris"', { 55 | 'cflags': [ 56 | '-Wno-sign-compare' 57 | , '-Wno-unused-function' 58 | ] 59 | }] 60 | , ['OS == "mac"', { 61 | 'xcode_settings': { 62 | 'WARNING_CFLAGS': [ 63 | '-Wno-sign-compare' 64 | , '-Wno-unused-function' 65 | ] 66 | } 67 | }] 68 | ] 69 | , 'sources': [ 70 | 'snappy-1.1.1/snappy-internal.h' 71 | , 'snappy-1.1.1/snappy-sinksource.cc' 72 | , 'snappy-1.1.1/snappy-sinksource.h' 73 | , 'snappy-1.1.1/snappy-stubs-internal.cc' 74 | , 'snappy-1.1.1/snappy-stubs-internal.h' 75 | , 'snappy-1.1.1/snappy.cc' 76 | , 'snappy-1.1.1/snappy.h' 77 | ] 78 | }]} 79 | -------------------------------------------------------------------------------- /deps/snappy/solaris/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 0 49 | #define SNAPPY_PATCHLEVEL 5 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 1 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /deps/snappy/win32/config.h: -------------------------------------------------------------------------------- 1 | #include 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/snappy/win32/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 0 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #define SNAPPY_MAJOR 1 48 | #define SNAPPY_MINOR 1 49 | #define SNAPPY_PATCHLEVEL 1 50 | #define SNAPPY_VERSION \ 51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 52 | 53 | #include 54 | 55 | namespace snappy { 56 | 57 | #if 0 58 | typedef int8_t int8; 59 | typedef uint8_t uint8; 60 | typedef int16_t int16; 61 | typedef uint16_t uint16; 62 | typedef int32_t int32; 63 | typedef uint32_t uint32; 64 | typedef int64_t int64; 65 | typedef uint64_t uint64; 66 | #else 67 | typedef signed char int8; 68 | typedef unsigned char uint8; 69 | typedef short int16; 70 | typedef unsigned short uint16; 71 | typedef int int32; 72 | typedef unsigned int uint32; 73 | typedef long long int64; 74 | typedef unsigned long long uint64; 75 | #endif 76 | 77 | typedef std::string string; 78 | 79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 80 | TypeName(const TypeName&); \ 81 | void operator=(const TypeName&) 82 | 83 | } // namespace snappy 84 | 85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 86 | -------------------------------------------------------------------------------- /iterator.js: -------------------------------------------------------------------------------- 1 | const util = require('util') 2 | const AbstractIterator = require('abstract-leveldown').AbstractIterator 3 | 4 | function Iterator (db, options) { 5 | AbstractIterator.call(this, db) 6 | 7 | this.binding = db.binding.iterator(options) 8 | this.cache = null 9 | this.finished = false 10 | this.fastFuture = require('fast-future')() 11 | } 12 | 13 | util.inherits(Iterator, AbstractIterator) 14 | 15 | Iterator.prototype.seek = function (target) { 16 | if (this._ended) { 17 | throw new Error('cannot call seek() after end()') 18 | } 19 | if (this._nexting) { 20 | throw new Error('cannot call seek() before next() has completed') 21 | } 22 | if (typeof target !== 'string' && !Buffer.isBuffer(target)) { 23 | throw new Error('seek() requires a string or buffer key') 24 | } 25 | if (target.length === 0) { 26 | throw new Error('cannot seek() to an empty key') 27 | } 28 | 29 | this.cache = null 30 | this.binding.seek(target) 31 | this.finished = false 32 | } 33 | 34 | Iterator.prototype._next = function (callback) { 35 | var that = this 36 | var key 37 | var value 38 | 39 | if (this.cache && this.cache.length) { 40 | key = this.cache.pop() 41 | value = this.cache.pop() 42 | 43 | this.fastFuture(function () { 44 | callback(null, key, value) 45 | }) 46 | } else if (this.finished) { 47 | this.fastFuture(function () { 48 | callback() 49 | }) 50 | } else { 51 | this.binding.next(function (err, array, finished) { 52 | if (err) return callback(err) 53 | 54 | that.cache = array 55 | that.finished = finished 56 | that._next(callback) 57 | }) 58 | } 59 | 60 | return this 61 | } 62 | 63 | Iterator.prototype._end = function (callback) { 64 | delete this.cache 65 | this.binding.end(callback) 66 | } 67 | 68 | module.exports = Iterator 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leveldown-hyper", 3 | "version": "2.0.0", 4 | "description": "A Node.js LevelDB binding, primary backend for LevelUP (HyperDex fork)", 5 | "license": "MIT", 6 | "main": "leveldown-hyper.js", 7 | "scripts": { 8 | "install": "prebuild-install || node-gyp rebuild", 9 | "test": "standard && hallmark && (nyc -s tape test/*-test.js | faucet) && nyc report && prebuild-ci", 10 | "coverage": "nyc report --reporter=text-lcov | coveralls", 11 | "rebuild": "node-gyp rebuild", 12 | "prebuild": "prebuild --all --verbose --strip", 13 | "hallmark": "hallmark --fix", 14 | "dependency-check": "dependency-check . test/*.js bench/*.js", 15 | "prepublishOnly": "npm run dependency-check" 16 | }, 17 | "dependencies": { 18 | "abstract-leveldown": "~5.0.0", 19 | "bindings": "~1.5.0", 20 | "fast-future": "~1.0.0", 21 | "nan": "^2.6.2", 22 | "prebuild-install": "^5.0.0" 23 | }, 24 | "devDependencies": { 25 | "coveralls": "^3.0.2", 26 | "dependency-check": "^3.3.0", 27 | "du": "^1.0.0", 28 | "faucet": "^0.0.1", 29 | "hallmark": "^2.0.0", 30 | "iota-array": "^1.0.0", 31 | "level-community": "^3.0.0", 32 | "lexicographic-integer": "^1.1.0", 33 | "mkfiletree": "^2.0.0", 34 | "monotonic-timestamp": "~0.0.8", 35 | "node-uuid": "^1.4.3", 36 | "nyc": "^14.0.0", 37 | "optimist": "~0.6.1", 38 | "prebuild": "^9.0.0", 39 | "prebuild-ci": "^3.0.0", 40 | "readfiletree": "^1.0.0", 41 | "rimraf": "^3.0.0", 42 | "slump": "^3.0.0", 43 | "standard": "^14.0.0", 44 | "tape": "^4.9.0" 45 | }, 46 | "hallmark": { 47 | "community": "level-community" 48 | }, 49 | "gypfile": true, 50 | "repository": { 51 | "type": "git", 52 | "url": "https://github.com/Level/leveldown-hyper.git" 53 | }, 54 | "homepage": "https://github.com/Level/leveldown-hyper", 55 | "keywords": [ 56 | "leveldb", 57 | "level" 58 | ], 59 | "engines": { 60 | "node": ">=6" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/async.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_ASYNC_H 2 | #define LD_ASYNC_H 3 | 4 | #include 5 | #include 6 | #include "database.h" 7 | 8 | namespace leveldown { 9 | 10 | class Database; 11 | 12 | /* abstract */ class AsyncWorker : public Nan::AsyncWorker { 13 | public: 14 | AsyncWorker ( 15 | leveldown::Database* database 16 | , Nan::Callback *callback 17 | , const char *resource_name 18 | ) : Nan::AsyncWorker(callback, resource_name), database(database) { } 19 | 20 | protected: 21 | void SetStatus(leveldb::Status status) { 22 | this->status = status; 23 | if (!status.ok()) 24 | SetErrorMessage(status.ToString().c_str()); 25 | } 26 | Database* database; 27 | private: 28 | leveldb::Status status; 29 | }; 30 | 31 | } // namespace leveldown 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/batch_async.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "batch.h" 3 | #include "batch_async.h" 4 | 5 | namespace leveldown { 6 | 7 | /** NEXT WORKER **/ 8 | 9 | BatchWriteWorker::BatchWriteWorker ( 10 | Batch* batch 11 | , Nan::Callback *callback 12 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:batch.write") 13 | , batch(batch) 14 | {}; 15 | 16 | BatchWriteWorker::~BatchWriteWorker () {} 17 | 18 | void BatchWriteWorker::Execute () { 19 | SetStatus(batch->Write()); 20 | } 21 | 22 | } // namespace leveldown 23 | -------------------------------------------------------------------------------- /src/batch_async.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_BATCH_ASYNC_H 2 | #define LD_BATCH_ASYNC_H 3 | 4 | #include 5 | #include 6 | 7 | #include "async.h" 8 | #include "batch.h" 9 | #include "database.h" 10 | 11 | namespace leveldown { 12 | 13 | class BatchWriteWorker : public AsyncWorker { 14 | public: 15 | BatchWriteWorker ( 16 | Batch* batch 17 | , Nan::Callback *callback 18 | ); 19 | 20 | virtual ~BatchWriteWorker (); 21 | virtual void Execute (); 22 | 23 | private: 24 | Batch* batch; 25 | }; 26 | 27 | } // namespace leveldown 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_COMMON_H 2 | #define LD_COMMON_H 3 | 4 | #include 5 | 6 | namespace leveldown { 7 | 8 | NAN_INLINE bool BooleanOptionValue(v8::Local options, 9 | const char* _key, 10 | bool def = false) { 11 | Nan::HandleScope scope; 12 | v8::Local key = Nan::New(_key).ToLocalChecked(); 13 | return !options.IsEmpty() 14 | && options->Has(key) 15 | ? options->Get(key)->BooleanValue() 16 | : def; 17 | } 18 | 19 | NAN_INLINE uint32_t UInt32OptionValue(v8::Local options, 20 | const char* _key, 21 | uint32_t def) { 22 | Nan::HandleScope scope; 23 | v8::Local key = Nan::New(_key).ToLocalChecked(); 24 | return !options.IsEmpty() 25 | && options->Has(key) 26 | && options->Get(key)->IsNumber() 27 | ? options->Get(key)->Uint32Value() 28 | : def; 29 | } 30 | 31 | } // namespace leveldown 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/database.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_DATABASE_H 2 | #define LD_DATABASE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "leveldown.h" 14 | #include "iterator.h" 15 | 16 | namespace leveldown { 17 | 18 | NAN_METHOD(LevelDOWN); 19 | 20 | struct Reference { 21 | Nan::Persistent handle; 22 | leveldb::Slice slice; 23 | 24 | Reference(v8::Local obj, leveldb::Slice slice) : slice(slice) { 25 | v8::Local _obj = Nan::New(); 26 | _obj->Set(Nan::New("obj").ToLocalChecked(), obj); 27 | handle.Reset(_obj); 28 | }; 29 | }; 30 | 31 | static inline void ClearReferences (std::vector *references) { 32 | for (std::vector::iterator it = references->begin() 33 | ; it != references->end() 34 | ; ) { 35 | DisposeStringOrBufferFromSlice((*it)->handle, (*it)->slice); 36 | it = references->erase(it); 37 | } 38 | delete references; 39 | } 40 | 41 | class Database : public Nan::ObjectWrap { 42 | public: 43 | static void Init (); 44 | static v8::Local NewInstance (v8::Local &location); 45 | 46 | leveldb::Status OpenDatabase (leveldb::Options* options); 47 | leveldb::Status PutToDatabase ( 48 | leveldb::WriteOptions* options 49 | , leveldb::Slice key 50 | , leveldb::Slice value 51 | ); 52 | leveldb::Status GetFromDatabase ( 53 | leveldb::ReadOptions* options 54 | , leveldb::Slice key 55 | , std::string& value 56 | ); 57 | leveldb::Status DeleteFromDatabase ( 58 | leveldb::WriteOptions* options 59 | , leveldb::Slice key 60 | ); 61 | leveldb::Status WriteBatchToDatabase ( 62 | leveldb::WriteOptions* options 63 | , leveldb::WriteBatch* batch 64 | ); 65 | uint64_t ApproximateSizeFromDatabase (const leveldb::Range* range); 66 | void GetPropertyFromDatabase (const leveldb::Slice& property, std::string* value); 67 | leveldb::Iterator* NewIterator (leveldb::ReadOptions* options); 68 | leveldb::Status LiveBackup (const leveldb::Slice& name); 69 | const leveldb::Snapshot* NewSnapshot (); 70 | void ReleaseSnapshot (const leveldb::Snapshot* snapshot); 71 | void CloseDatabase (); 72 | void ReleaseIterator (uint32_t id); 73 | 74 | Database (const v8::Local& from); 75 | ~Database (); 76 | 77 | private: 78 | Nan::Utf8String* location; 79 | leveldb::DB* db; 80 | uint32_t currentIteratorId; 81 | void(*pendingCloseWorker); 82 | leveldb::Cache* blockCache; 83 | const leveldb::FilterPolicy* filterPolicy; 84 | 85 | std::map< uint32_t, leveldown::Iterator * > iterators; 86 | 87 | static void WriteDoing(uv_work_t *req); 88 | static void WriteAfter(uv_work_t *req); 89 | 90 | static NAN_METHOD(New); 91 | static NAN_METHOD(Open); 92 | static NAN_METHOD(Close); 93 | static NAN_METHOD(Put); 94 | static NAN_METHOD(Get); 95 | static NAN_METHOD(Delete); 96 | static NAN_METHOD(Batch); 97 | static NAN_METHOD(ApproximateSize); 98 | static NAN_METHOD(GetProperty); 99 | static NAN_METHOD(Write); 100 | static NAN_METHOD(Iterator); 101 | static NAN_METHOD(LiveBackup); 102 | }; 103 | 104 | } // namespace leveldown 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_ITERATOR_H 2 | #define LD_ITERATOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "leveldown.h" 9 | #include "database.h" 10 | #include "async.h" 11 | 12 | namespace leveldown { 13 | 14 | class Database; 15 | class AsyncWorker; 16 | 17 | class Iterator : public Nan::ObjectWrap { 18 | public: 19 | static void Init (); 20 | static v8::Local NewInstance ( 21 | v8::Local database 22 | , v8::Local id 23 | , v8::Local optionsObj 24 | ); 25 | 26 | Iterator ( 27 | Database* database 28 | , uint32_t id 29 | , leveldb::Slice* start 30 | , std::string* end 31 | , bool reverse 32 | , bool keys 33 | , bool values 34 | , int limit 35 | , std::string* lt 36 | , std::string* lte 37 | , std::string* gt 38 | , std::string* gte 39 | , bool fillCache 40 | , bool keyAsBuffer 41 | , bool valueAsBuffer 42 | , size_t highWaterMark 43 | ); 44 | 45 | ~Iterator (); 46 | 47 | bool IteratorNext (std::vector >& result); 48 | leveldb::Status IteratorStatus (); 49 | void IteratorEnd (); 50 | void Release (); 51 | void ReleaseTarget (); 52 | 53 | private: 54 | Database* database; 55 | uint32_t id; 56 | leveldb::Iterator* dbIterator; 57 | leveldb::ReadOptions* options; 58 | leveldb::Slice* start; 59 | leveldb::Slice* target; 60 | std::string* end; 61 | bool seeking; 62 | bool landed; 63 | bool reverse; 64 | bool keys; 65 | bool values; 66 | int limit; 67 | std::string* lt; 68 | std::string* lte; 69 | std::string* gt; 70 | std::string* gte; 71 | int count; 72 | size_t highWaterMark; 73 | 74 | public: 75 | bool keyAsBuffer; 76 | bool valueAsBuffer; 77 | bool nexting; 78 | bool ended; 79 | AsyncWorker* endWorker; 80 | 81 | private: 82 | bool Read (std::string& key, std::string& value); 83 | bool GetIterator (); 84 | bool OutOfRange (leveldb::Slice* target); 85 | 86 | static NAN_METHOD(New); 87 | static NAN_METHOD(Seek); 88 | static NAN_METHOD(Next); 89 | static NAN_METHOD(End); 90 | }; 91 | 92 | } // namespace leveldown 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /src/iterator_async.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "database.h" 5 | #include "leveldown.h" 6 | #include "async.h" 7 | #include "iterator_async.h" 8 | 9 | namespace leveldown { 10 | 11 | /** NEXT-MULTI WORKER **/ 12 | 13 | NextWorker::NextWorker ( 14 | Iterator* iterator 15 | , Nan::Callback *callback 16 | , void (*localCallback)(Iterator*) 17 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:iterator.next") 18 | , iterator(iterator) 19 | , localCallback(localCallback) 20 | {}; 21 | 22 | NextWorker::~NextWorker () {} 23 | 24 | void NextWorker::Execute () { 25 | ok = iterator->IteratorNext(result); 26 | if (!ok) 27 | SetStatus(iterator->IteratorStatus()); 28 | } 29 | 30 | void NextWorker::HandleOKCallback () { 31 | Nan::HandleScope scope; 32 | size_t idx = 0; 33 | 34 | size_t arraySize = result.size() * 2; 35 | v8::Local returnArray = Nan::New(arraySize); 36 | 37 | for(idx = 0; idx < result.size(); ++idx) { 38 | std::pair row = result[idx]; 39 | std::string key = row.first; 40 | std::string value = row.second; 41 | 42 | v8::Local returnKey; 43 | if (iterator->keyAsBuffer) { 44 | //TODO: use NewBuffer, see database_async.cc 45 | returnKey = Nan::CopyBuffer((char*)key.data(), key.size()).ToLocalChecked(); 46 | } else { 47 | returnKey = Nan::New((char*)key.data(), key.size()).ToLocalChecked(); 48 | } 49 | 50 | v8::Local returnValue; 51 | if (iterator->valueAsBuffer) { 52 | //TODO: use NewBuffer, see database_async.cc 53 | returnValue = Nan::CopyBuffer((char*)value.data(), value.size()).ToLocalChecked(); 54 | } else { 55 | returnValue = Nan::New((char*)value.data(), value.size()).ToLocalChecked(); 56 | } 57 | 58 | // put the key & value in a descending order, so that they can be .pop:ed in javascript-land 59 | returnArray->Set(Nan::New(static_cast(arraySize - idx * 2 - 1)), returnKey); 60 | returnArray->Set(Nan::New(static_cast(arraySize - idx * 2 - 2)), returnValue); 61 | } 62 | 63 | // clean up & handle the next/end state see iterator.cc/checkEndCallback 64 | localCallback(iterator); 65 | 66 | v8::Local argv[] = { 67 | Nan::Null() 68 | , returnArray 69 | // when ok === false all data has been read, so it's then finished 70 | , Nan::New(!ok) 71 | }; 72 | callback->Call(3, argv, async_resource); 73 | } 74 | 75 | /** END WORKER **/ 76 | 77 | EndWorker::EndWorker ( 78 | Iterator* iterator 79 | , Nan::Callback *callback 80 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:iterator.end") 81 | , iterator(iterator) 82 | {}; 83 | 84 | EndWorker::~EndWorker () { } 85 | 86 | void EndWorker::Execute () { 87 | iterator->IteratorEnd(); 88 | } 89 | 90 | void EndWorker::HandleOKCallback () { 91 | iterator->Release(); 92 | callback->Call(0, NULL, async_resource); 93 | } 94 | 95 | } // namespace leveldown 96 | -------------------------------------------------------------------------------- /src/iterator_async.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_ITERATOR_ASYNC_H 2 | #define LD_ITERATOR_ASYNC_H 3 | 4 | #include 5 | #include 6 | 7 | #include "async.h" 8 | #include "iterator.h" 9 | 10 | namespace leveldown { 11 | 12 | class NextWorker : public AsyncWorker { 13 | public: 14 | NextWorker ( 15 | Iterator* iterator 16 | , Nan::Callback *callback 17 | , void (*localCallback)(Iterator*) 18 | ); 19 | 20 | virtual ~NextWorker (); 21 | virtual void Execute (); 22 | virtual void HandleOKCallback (); 23 | 24 | private: 25 | Iterator* iterator; 26 | void (*localCallback)(Iterator*); 27 | std::vector > result; 28 | bool ok; 29 | }; 30 | 31 | class EndWorker : public AsyncWorker { 32 | public: 33 | EndWorker ( 34 | Iterator* iterator 35 | , Nan::Callback *callback 36 | ); 37 | 38 | virtual ~EndWorker (); 39 | virtual void Execute (); 40 | virtual void HandleOKCallback (); 41 | 42 | private: 43 | Iterator* iterator; 44 | }; 45 | 46 | } // namespace leveldown 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/leveldown.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "leveldown.h" 4 | #include "database.h" 5 | #include "iterator.h" 6 | #include "batch.h" 7 | #include "leveldown_async.h" 8 | 9 | namespace leveldown { 10 | 11 | NAN_METHOD(DestroyDB) { 12 | Nan::HandleScope scope; 13 | 14 | Nan::Utf8String* location = new Nan::Utf8String(info[0]); 15 | 16 | Nan::Callback* callback = new Nan::Callback( 17 | v8::Local::Cast(info[1])); 18 | 19 | DestroyWorker* worker = new DestroyWorker( 20 | location 21 | , callback 22 | ); 23 | 24 | Nan::AsyncQueueWorker(worker); 25 | 26 | info.GetReturnValue().SetUndefined(); 27 | } 28 | 29 | NAN_METHOD(RepairDB) { 30 | Nan::HandleScope scope; 31 | 32 | Nan::Utf8String* location = new Nan::Utf8String(info[0]); 33 | 34 | Nan::Callback* callback = new Nan::Callback( 35 | v8::Local::Cast(info[1])); 36 | 37 | RepairWorker* worker = new RepairWorker( 38 | location 39 | , callback 40 | ); 41 | 42 | Nan::AsyncQueueWorker(worker); 43 | 44 | info.GetReturnValue().SetUndefined(); 45 | } 46 | 47 | void Init (v8::Local target) { 48 | Database::Init(); 49 | leveldown::Iterator::Init(); 50 | leveldown::Batch::Init(); 51 | 52 | v8::Local leveldown = 53 | Nan::New(LevelDOWN)->GetFunction(); 54 | 55 | leveldown->Set( 56 | Nan::New("destroy").ToLocalChecked() 57 | , Nan::New(DestroyDB)->GetFunction() 58 | ); 59 | 60 | leveldown->Set( 61 | Nan::New("repair").ToLocalChecked() 62 | , Nan::New(RepairDB)->GetFunction() 63 | ); 64 | 65 | target->Set(Nan::New("leveldown").ToLocalChecked(), leveldown); 66 | } 67 | 68 | NODE_MODULE(leveldownhyper, Init) 69 | 70 | } // namespace leveldown 71 | -------------------------------------------------------------------------------- /src/leveldown_async.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "leveldown.h" 4 | #include "leveldown_async.h" 5 | 6 | namespace leveldown { 7 | 8 | /** DESTROY WORKER **/ 9 | 10 | DestroyWorker::DestroyWorker ( 11 | Nan::Utf8String* location 12 | , Nan::Callback *callback 13 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:destroy") 14 | , location(location) 15 | {}; 16 | 17 | DestroyWorker::~DestroyWorker () { 18 | delete location; 19 | } 20 | 21 | void DestroyWorker::Execute () { 22 | leveldb::Options options; 23 | SetStatus(leveldb::DestroyDB(**location, options)); 24 | } 25 | 26 | /** REPAIR WORKER **/ 27 | 28 | RepairWorker::RepairWorker ( 29 | Nan::Utf8String* location 30 | , Nan::Callback *callback 31 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:repair") 32 | , location(location) 33 | {}; 34 | 35 | RepairWorker::~RepairWorker () { 36 | delete location; 37 | } 38 | 39 | void RepairWorker::Execute () { 40 | leveldb::Options options; 41 | SetStatus(leveldb::RepairDB(**location, options)); 42 | } 43 | 44 | } // namespace leveldown 45 | -------------------------------------------------------------------------------- /src/leveldown_async.h: -------------------------------------------------------------------------------- 1 | #ifndef LD_LEVELDOWN_ASYNC_H 2 | #define LD_LEVELDOWN_ASYNC_H 3 | 4 | #include 5 | 6 | #include "async.h" 7 | 8 | namespace leveldown { 9 | 10 | class DestroyWorker : public AsyncWorker { 11 | public: 12 | DestroyWorker ( 13 | Nan::Utf8String* location 14 | , Nan::Callback *callback 15 | ); 16 | 17 | virtual ~DestroyWorker (); 18 | virtual void Execute (); 19 | 20 | private: 21 | Nan::Utf8String* location; 22 | }; 23 | 24 | class RepairWorker : public AsyncWorker { 25 | public: 26 | RepairWorker ( 27 | Nan::Utf8String* location 28 | , Nan::Callback *callback 29 | ); 30 | 31 | virtual ~RepairWorker (); 32 | virtual void Execute (); 33 | 34 | private: 35 | Nan::Utf8String* location; 36 | }; 37 | 38 | } // namespace leveldown 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/batch-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('../') 3 | const abstract = require('abstract-leveldown/abstract/batch-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/chained-batch-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/chained-batch-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/cleanup-hanging-iterators-test.js: -------------------------------------------------------------------------------- 1 | const makeTest = require('./make') 2 | 3 | makeTest('test ended iterator', function (db, t, done) { 4 | // standard iterator with an end() properly called, easy 5 | 6 | var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) 7 | it.next(function (err, key, value) { 8 | t.notOk(err, 'no error from next()') 9 | t.equal(key, 'one', 'correct key') 10 | t.equal(value, '1', 'correct value') 11 | it.end(function (err) { 12 | t.notOk(err, 'no error from next()') 13 | done() 14 | }) 15 | }) 16 | }) 17 | 18 | makeTest('test non-ended iterator', function (db, t, done) { 19 | // no end() call on our iterator, cleanup should crash Node if not handled properly 20 | var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) 21 | it.next(function (err, key, value) { 22 | t.notOk(err, 'no error from next()') 23 | t.equal(key, 'one', 'correct key') 24 | t.equal(value, '1', 'correct value') 25 | done() 26 | }) 27 | }) 28 | 29 | makeTest('test multiple non-ended iterators', function (db, t, done) { 30 | // no end() call on our iterator, cleanup should crash Node if not handled properly 31 | db.iterator() 32 | db.iterator().next(function () {}) 33 | db.iterator().next(function () {}) 34 | db.iterator().next(function () {}) 35 | setTimeout(done, 50) 36 | }) 37 | 38 | makeTest('test ending iterators', function (db, t, done) { 39 | // at least one end() should be in progress when we try to close the db 40 | var it1 = db.iterator().next(function () { 41 | it1.end(function () {}) 42 | }) 43 | var it2 = db.iterator().next(function () { 44 | it2.end(function () {}) 45 | done() 46 | }) 47 | }) 48 | -------------------------------------------------------------------------------- /test/close-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const testCommon = require('abstract-leveldown/testCommon') 3 | const leveldown = require('../') 4 | const 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 | -------------------------------------------------------------------------------- /test/data/testdata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/test/data/testdata.bin -------------------------------------------------------------------------------- /test/del-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/del-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/destroy-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const fs = require('fs') 3 | const path = require('path') 4 | const mkfiletree = require('mkfiletree') 5 | const readfiletree = require('readfiletree') 6 | const leveldown = require('../') 7 | const makeTest = require('./make') 8 | 9 | test('test argument-less destroy() throws', function (t) { 10 | t.throws(leveldown.destroy, { 11 | name: 'Error', 12 | message: 'destroy() requires `location` and `callback` arguments' 13 | }, 'no-arg destroy() throws') 14 | t.end() 15 | }) 16 | 17 | test('test callback-less, 1-arg, destroy() throws', function (t) { 18 | t.throws(leveldown.destroy.bind(null, 'foo'), { 19 | name: 'Error', 20 | message: 'destroy() requires `location` and `callback` arguments' 21 | }, 'callback-less, 1-arg destroy() throws') 22 | t.end() 23 | }) 24 | 25 | test('test destroy non-existant directory', function (t) { 26 | leveldown.destroy('/1/2/3/4', function () { 27 | t.equal(arguments.length, 0, 'no arguments returned on callback') 28 | t.end() 29 | }) 30 | }) 31 | 32 | test('test destroy non leveldb directory', function (t) { 33 | var tree = { 34 | foo: 'FOO', 35 | bar: { one: 'ONE', two: 'TWO', three: 'THREE' } 36 | } 37 | mkfiletree.makeTemp('destroy-test', tree, function (err, dir) { 38 | t.notOk(err, 'no error') 39 | leveldown.destroy(dir, function () { 40 | t.ok(arguments, 'no arguments') 41 | readfiletree(dir, function (err, actual) { 42 | t.notOk(err, 'no error') 43 | t.deepEqual(actual, tree, 'directory remains untouched') 44 | mkfiletree.cleanUp(function (err) { 45 | t.notOk(err, 'no error') 46 | t.end() 47 | }) 48 | }) 49 | }) 50 | }) 51 | }) 52 | 53 | makeTest('test destroy() cleans and removes leveldb-only dir', function (db, t, done, location) { 54 | db.close(function (err) { 55 | t.notOk(err, 'no error') 56 | leveldown.destroy(location, function () { 57 | t.notOk(fs.existsSync(), 'directory completely removed') 58 | done(false) 59 | }) 60 | }) 61 | }) 62 | 63 | makeTest('test destroy() cleans and removes only leveldb parts of a dir', function (db, t, done, location) { 64 | fs.writeFileSync(path.join(location, 'foo'), 'FOO') 65 | db.close(function (err) { 66 | t.notOk(err, 'no error') 67 | leveldown.destroy(location, function () { 68 | readfiletree(location, function (err, tree) { 69 | t.notOk(err, 'no error') 70 | t.deepEqual(tree, { foo: 'FOO' }, 'non-leveldb files left intact') 71 | done(false) 72 | }) 73 | }) 74 | }) 75 | }) 76 | -------------------------------------------------------------------------------- /test/get-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/get-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/getproperty-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const testCommon = require('abstract-leveldown/testCommon') 3 | const 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(db.getProperty.bind(db), { 16 | name: 'Error', 17 | message: 'getProperty() requires a valid `property` argument' 18 | }, 'no-arg getProperty() throws') 19 | t.end() 20 | }) 21 | 22 | test('test non-string getProperty() throws', function (t) { 23 | t.throws(db.getProperty.bind(db, {}), { 24 | name: 'Error', 25 | message: 'getProperty() requires a valid `property` argument' 26 | }, 'no-arg getProperty() throws') 27 | t.end() 28 | }) 29 | 30 | test('test invalid getProperty() returns empty string', function (t) { 31 | t.equal(db.getProperty('foo'), '', 'invalid property') 32 | t.equal(db.getProperty('leveldb.foo'), '', 'invalid leveldb.* property') 33 | t.end() 34 | }) 35 | 36 | test('test invalid getProperty("leveldb.num-files-at-levelN") returns numbers', function (t) { 37 | for (var i = 0; i < 7; i++) { 38 | t.equal(db.getProperty('leveldb.num-files-at-level' + i), '0', '"leveldb.num-files-at-levelN" === "0"') 39 | } 40 | t.end() 41 | }) 42 | 43 | test('test invalid getProperty("leveldb.stats")', function (t) { 44 | t.ok(db.getProperty('leveldb.stats').split('\n').length > 3, 'leveldb.stats has > 3 newlines') 45 | t.end() 46 | }) 47 | 48 | test('test invalid getProperty("leveldb.sstables")', function (t) { 49 | var expected = [0, 1, 2, 3, 4, 5, 6].map(function (l) { 50 | return '--- level ' + l + ' ---' 51 | }).join('\n') + '\n' 52 | t.equal(db.getProperty('leveldb.sstables'), expected, 'leveldb.sstables') 53 | t.end() 54 | }) 55 | 56 | test('tearDown', function (t) { 57 | db.close(testCommon.tearDown.bind(null, t)) 58 | }) 59 | -------------------------------------------------------------------------------- /test/iterator-range-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/iterator-range-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/iterator-recursion-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const path = require('path') 3 | const testCommon = require('abstract-leveldown/testCommon') 4 | const leveldown = require('../') 5 | const fork = require('child_process').fork 6 | 7 | var db 8 | var sourceData = (function () { 9 | var d = [] 10 | var i = 0 11 | var k 12 | for (; i < 100000; i++) { 13 | k = (i < 10 ? '0' : '') + i 14 | d.push({ 15 | type: 'put', 16 | key: k, 17 | value: Math.random() 18 | }) 19 | } 20 | return d 21 | }()) 22 | 23 | test('setUp common', testCommon.setUp) 24 | 25 | test('setUp db', function (t) { 26 | db = leveldown(testCommon.location()) 27 | db.open(function () { 28 | db.batch(sourceData, t.end.bind(t)) 29 | }) 30 | }) 31 | 32 | test('try to create an iterator with a blown stack', function (t) { 33 | // Reducing the stack size down from the default 984 for the child node 34 | // process makes it easier to trigger the bug condition. But making it too low 35 | // causes the child process to die for other reasons. 36 | var opts = { execArgv: ['--stack-size=128'] } 37 | var child = fork(path.join(__dirname, 'stack-blower.js'), ['run'], opts) 38 | 39 | t.plan(2) 40 | 41 | child.on('message', function (m) { 42 | t.ok(true, m) 43 | child.disconnect() 44 | }) 45 | 46 | child.on('exit', function (code, sig) { 47 | t.equal(code, 0, 'child exited normally') 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 | var read = function () { 56 | iterator.next(function () { 57 | if (!arguments.length) { 58 | t.end() 59 | } else { 60 | read() 61 | } 62 | }) 63 | } 64 | 65 | read() 66 | }) 67 | 68 | test('tearDown', function (t) { 69 | db.close(testCommon.tearDown.bind(null, t)) 70 | }) 71 | -------------------------------------------------------------------------------- /test/leak-tester-batch.js: -------------------------------------------------------------------------------- 1 | const BUFFERS = false 2 | const CHAINED = false 3 | 4 | var leveldown = require('..') 5 | var crypto = require('crypto') 6 | var assert = require('assert') 7 | var writeCount = 0 8 | var rssBase 9 | var db 10 | 11 | function print () { 12 | if (writeCount % 100 === 0) { 13 | if (typeof global.gc !== 'undefined') global.gc() 14 | 15 | console.log('writeCount =', writeCount, ', rss =', 16 | Math.round(process.memoryUsage().rss / rssBase * 100) + '%', 17 | Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M', 18 | JSON.stringify([0, 1, 2, 3, 4, 5, 6].map(function (l) { 19 | return db.getProperty('leveldb.num-files-at-level' + l) 20 | }))) 21 | } 22 | } 23 | 24 | var run = CHAINED 25 | ? function () { 26 | var batch = db.batch() 27 | var i = 0 28 | var key 29 | var value 30 | 31 | for (i = 0; i < 100; i++) { 32 | key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000)) 33 | if (BUFFERS) { 34 | key = Buffer.from(key) 35 | } 36 | value = crypto.randomBytes(1024) 37 | if (!BUFFERS) { 38 | value = value.toString('hex') 39 | } 40 | batch.put(key, value) 41 | } 42 | 43 | batch.write(function (err) { 44 | assert(!err) 45 | process.nextTick(run) 46 | }) 47 | 48 | writeCount++ 49 | 50 | print() 51 | } 52 | : function () { 53 | var batch = [] 54 | var i 55 | var key 56 | var value 57 | 58 | for (i = 0; i < 100; i++) { 59 | key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000)) 60 | if (BUFFERS) { 61 | key = Buffer.from(key) 62 | } 63 | value = crypto.randomBytes(1024) 64 | if (!BUFFERS) { 65 | value = value.toString('hex') 66 | } 67 | batch.push({ type: 'put', key: key, value: value }) 68 | } 69 | 70 | db.batch(batch, function (err) { 71 | assert(!err) 72 | process.nextTick(run) 73 | }) 74 | 75 | writeCount++ 76 | 77 | print() 78 | } 79 | 80 | leveldown.destroy('./leakydb', function () { 81 | db = leveldown('./leakydb') 82 | db.open({ xcacheSize: 0, xmaxOpenFiles: 10 }, function () { 83 | rssBase = process.memoryUsage().rss 84 | run() 85 | }) 86 | }) 87 | -------------------------------------------------------------------------------- /test/leak-tester.js: -------------------------------------------------------------------------------- 1 | const BUFFERS = false 2 | 3 | var leveldown = require('..') 4 | var crypto = require('crypto') 5 | var putCount = 0 6 | var getCount = 0 7 | var rssBase 8 | var 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 = Buffer.from(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 global.gc !== 'undefined') global.gc() 33 | console.log('getCount =', getCount, ', putCount = ', putCount, ', rss =', 34 | Math.round(process.memoryUsage().rss / rssBase * 100) + '%', 35 | Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M', 36 | JSON.stringify([0, 1, 2, 3, 4, 5, 6].map(function (l) { 37 | return db.getProperty('leveldb.num-files-at-level' + l) 38 | }))) 39 | } 40 | } 41 | 42 | leveldown.destroy('./leakydb', function () { 43 | db = leveldown('./leakydb') 44 | db.open({ xcacheSize: 0, xmaxOpenFiles: 10 }, function () { 45 | rssBase = process.memoryUsage().rss 46 | run() 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /test/leveldown-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('../') 3 | const abstract = require('abstract-leveldown/abstract/leveldown-test') 4 | 5 | abstract.args(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/livebackup-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const testCommon = require('abstract-leveldown/testCommon') 3 | const leveldown = require('../') 4 | const fs = require('fs') 5 | const join = require('path').join 6 | 7 | var db 8 | var location 9 | 10 | test('setUp common', testCommon.setUp) 11 | 12 | test('setUp db', function (t) { 13 | location = testCommon.location() 14 | db = leveldown(location) 15 | db.open(function (err) { 16 | t.ok(!err, 'no error') 17 | var key = 'beep' 18 | var value = 'boop' 19 | db.put(key, value, function (err) { 20 | t.ok(!err, 'no put error') 21 | db.get(key, function (err, _value) { 22 | t.ok(!err, 'no put error') 23 | t.equal(_value.toString(), value) 24 | t.end() 25 | }) 26 | }) 27 | }) 28 | }) 29 | 30 | test('liveBackup', function (t) { 31 | t.throws(db.liveBackup.bind(db), /requires `name` and `callback` arguments/) 32 | t.throws(db.liveBackup.bind(db, null, null), /requires a name string argument/) 33 | t.throws(db.liveBackup.bind(db, 'astring'), /requires `name` and `callback`/) 34 | t.throws(db.liveBackup.bind(db, 'astring', null), /requires a callback function argument/) 35 | var now = String(Date.now()) 36 | db.liveBackup(now, function (err) { 37 | t.ok(!err, 'no liveBackup error') 38 | var backup = join(location, 'backup-' + now) 39 | fs.stat(backup, function (err, stats) { 40 | t.ok(!err, 'no error') 41 | t.ok(stats.isDirectory(), 'backup dir should exist') 42 | fs.readdir(backup, function (err, files) { 43 | t.ok(!err, 'no error') 44 | t.ok(files.length > 0, 'should contain some files') 45 | t.end() 46 | }) 47 | }) 48 | }) 49 | }) 50 | 51 | test('tearDown', function (t) { 52 | db.close(testCommon.tearDown.bind(null, t)) 53 | }) 54 | -------------------------------------------------------------------------------- /test/make.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const testCommon = require('abstract-leveldown/testCommon') 3 | const cleanup = testCommon.cleanup 4 | const location = testCommon.location 5 | const leveldown = require('../') 6 | 7 | function makeTest (name, testFn) { 8 | test(name, function (t) { 9 | cleanup(function () { 10 | var loc = location() 11 | var db = leveldown(loc) 12 | var done = function (close) { 13 | if (close === false) { return cleanup(t.end.bind(t)) } 14 | db.close(function (err) { 15 | t.notOk(err, 'no error from close()') 16 | cleanup(t.end.bind(t)) 17 | }) 18 | } 19 | db.open(function (err) { 20 | t.notOk(err, 'no error from open()') 21 | db.batch([ 22 | { type: 'put', key: 'one', value: '1' }, 23 | { type: 'put', key: 'two', value: '2' }, 24 | { type: 'put', key: 'three', value: '3' } 25 | ], function (err) { 26 | t.notOk(err, 'no error from batch()') 27 | testFn(db, t, done, loc) 28 | }) 29 | }) 30 | }) 31 | }) 32 | } 33 | 34 | module.exports = makeTest 35 | -------------------------------------------------------------------------------- /test/open-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/open-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/port-libuv-fix-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const path = require('path') 3 | const 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 | t.equal(version, 'hyper', 'matched current leveldb version') 9 | 10 | // TODO 'deps/leveldb/leveldb-hyper/port/port.h does not include 'port_uv.h' 11 | // so we do not have support for windows at the moment (@ralphtheninja) 12 | 13 | // porth = fs.readFileSync(path.join(__dirname, '../deps/leveldb/leveldb-' + version + '/port/port.h'), 'utf8') 14 | // t.ok(/"port_uv\.h"/.test(porth), 'port.h includes reference to port_uv.h') 15 | 16 | t.end() 17 | }) 18 | -------------------------------------------------------------------------------- /test/put-get-del-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/put-get-del-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/put-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const leveldown = require('..') 3 | const abstract = require('abstract-leveldown/abstract/put-test') 4 | 5 | abstract.all(leveldown, test) 6 | -------------------------------------------------------------------------------- /test/repair-test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const fs = require('fs') 3 | const leveldown = require('../') 4 | const makeTest = require('./make') 5 | 6 | test('test argument-less repair() throws', function (t) { 7 | t.throws(leveldown.repair, { 8 | name: 'Error', 9 | message: 'repair() requires `location` and `callback` arguments' 10 | }, 'no-arg repair() throws') 11 | t.end() 12 | }) 13 | 14 | test('test callback-less, 1-arg, repair() throws', function (t) { 15 | t.throws(leveldown.repair.bind(null, 'foo'), { 16 | name: 'Error', 17 | message: 'repair() requires `location` and `callback` arguments' 18 | }, 'callback-less, 1-arg repair() throws') 19 | t.end() 20 | }) 21 | 22 | test('test repair non-existant directory returns error', function (t) { 23 | leveldown.repair('/1/2/3/4', function (err) { 24 | t.ok(/no such/i.test(err), 'error on callback') 25 | t.end() 26 | }) 27 | }) 28 | 29 | // a proxy indicator that RepairDB is being called and doing its thing 30 | makeTest('test repair() compacts', function (db, t, done, location) { 31 | db.close(function (err) { 32 | t.notOk(err, 'no error') 33 | var files = fs.readdirSync(location) 34 | t.ok(files.some(function (f) { return (/\.log$/).test(f) }), 'directory contains log file(s)') 35 | t.notOk(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory does not contain sst file(s)') 36 | leveldown.repair(location, function () { 37 | files = fs.readdirSync(location) 38 | t.notOk(files.some(function (f) { return (/\.log$/).test(f) }), 'directory does not contain log file(s)') 39 | t.ok(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory contains sst file(s)') 40 | done(false) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /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 | const leveldown = require('../') 10 | 11 | if (process.argv[2] === 'run') { 12 | testCommon.cleanup(function () { 13 | var db = leveldown(testCommon.location()) 14 | var 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 | --------------------------------------------------------------------------------