aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-01-28 16:59:07 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-01-28 16:59:07 +0100
commit66480821b36c839ab7615cb9309850015bceadb0 (patch)
tree52dde68beb13b70f6d5f2b1935c783db89087fc9 /include
parent4f2e6c8b881b7ccda36233332dfd1bd231389a8e (diff)
downloadbitcoin-66480821b36c839ab7615cb9309850015bceadb0.tar.xz
Squashed 'src/leveldb/' changes from f545dfabff4c2e9836efed094dba99a34fbc6b88..f8ae182c1e5176d12e816fb2217ae33a5472fdd7
f8ae182c1e5176d12e816fb2217ae33a5472fdd7 Adds unicode support to Windows environment. 92ae82c78f225de84040c51e07fd0b4a61caed99 Increase maximum read-only mmap()s used from 1000 to 4096 on 64-bit systems d42e63d49d9df05b12cd00af4ffc5f2b3edf7e21 Do not crash if filesystem can't fsync bf2c2090b7ee12c5d85b85f08649b6e685f8715f Add filename to corruption errors 0c40829872a9f00f38e11dc370ff8adb3e19f25b Remove redundant PROJECT_SOURCE_DIR usage from CMake config. 5abdf4c019e51fce59d34c21b13bf4e0a948828a Fix installed target definition. cf4d9ab23de7ec36b8e00536b7450f02c639cd87 Test CMake installation on Travis. 95d0ba1cb046bfd76619b8b80e14ee1b2897d219 Renamed local variable in DBImpl::Write. 657ba514298a726c7533f3106d3778062b59d75f Added return in Version::Get::State::Match to quiet warning. 370d532a00581ca79c87af7d7811e56de0ca52a8 Using CMake's check_cxx_compiler_flag to check support for -Wthread-safety. 45ee61579c1eb3accd6c88c922ec468dd61beea8 Update Travis CI configuration. 60db170a43a373d734c5b9f19693d36c75251c39 Fix tsan problem in env_test. 21304d41f77990b8edabbdab33b222bd5ceb5f18 Merge pull request #698 from neal-zhu:master 5e921896eedf87b0fb06bc8a1fd0991b9ac64131 drop fileds in State that are duplicates of fileds in Saver and fix typo 53e280b56866ac4c90a9f5fcfe02ebdfd4a19832 Simplify unlocking in DeleteObsoleteFiles. 046216a7ca6fb17a40cf8aa5598d90c825212a3d Add "leveldb" subdirectory to public include paths. 9ee91ac747ddf26f484d54f9aa474ccc4a2e0359 Ending sentences with periods in README.md. e0d5f83a4f80060fe5b5d80025f0ad049bca430e Align EnvPosix and EnvWindows. 69061b464ab1da287da9b7ffec1ed911b754403b Disable exceptions and RTTI in CMake configuration. 107a75b62c19cce901ce10619b63c4b7acc9a0be cache Saver in State object 76ca1162768e5c89f1a49946a1f286c702ae27ae fix bug(uninitialized options pointer in State) f668239bb262609146496b854e1ec3cea9cd1a83 remove TODO in Version::ForEachOverlapping 177cd08629883c409f7a01f90f7084bc5518f1ef format 8fa7a937ee8f38d8869357b0f27f120c5c58f4c9 fix bug 6a90bb91ee72642241fdbeefa673f88370c7b245 use ForEachOverlapping to impl Get 4cb80b7ddce6ff6089b15d8cfebf746fc1572477 Merge pull request #386 from ivanabc:master 72a38ff7f206b3924ac009a12a1838d6a0bdab03 Replace "> >" with ">>" 863f185970eff21e826e5fe1164a6215a515c23b unsigned char -> uint8_t a3b71c1ff65e30ced00e85ebbca9ae5786af6626 Use GCC 9 on Travis CI ae49533210e96bdee9c9479a7fa547f375a39c8b Add explicit typecasts to avoid compiler warning. 63d5315e1c224e52da8ec68d118c5b73ba2a63fc Merge branch 'master' into master c00e177f3613068eda4bff4abfbd3bd4165a86e8 Guard DBImpl::versions_ by mutex_. 1d0b101165ddd34f26cc5c62b76f2a2e0d622483 Converted two for-loops to while-loops. 28e6d238be73e743c963fc0a26395b783a7565e2 Switch to using C++ 11 override specifier. 85cd40d108d8f8d91f58fd263c0f8428d11c34d5 Added unit test for InternalKey::DecodeFrom with empty string. 1aae5c9f29ea43ceca745efae012c4aa731e9374 Merge pull request #411 from proller:assert1 b7b86baec9ce47569affc5db54a20a6cc520e0f0 Using std::ostringstream in key DebugString. 3e6c000e18519cb22e0a44d0dea45b34daee4ee1 Merge pull request #457 from jellor:patch-2 1d94fe2f4d1dfdf1a6312bf4b36efcbe0c1bf576 Merge branch 'master' into patch-2 27dc99fb2642cadc87c9aaec82c54a2c725ee0d6 Fix EnvPosix tests on Travis CI. 9521545b062841409cf66eff0655feff09d9fd82 Formatting changes for prior O_CLOEXEC fix. 900f7d37eb3224059dd37afc6614d3158ddaeb8d Merge pull request #624 from adam-azarchs:master a7528a5d2bd29126b60a277b528ed606b67c1771 Clean up util/coding.{h,cc}. 142035edd4b1ab431c0ecbd547d4a77f1eca0667 Initialize Stats::start_ before first use in Stats::Start(). e22b1cec6e1e0e2dec4c93b658acbfc56fb692c0 Merge pull request #365 from allangj:c-strict-prototypes cd1ec032cd276409ba403cab4d0b2548dd26b890 Add argument definition for void c functions. 4bd052d7e8b0469b2b87664388e2a99cb212ecdb Consolidate benchmark code to benchmarks/. 506b1722ef1a58d87325575d9bbcd3c8869381c7 Convert missed virtual -> override in db_test.cc. 24424a1ef2c284f4ec30544a3458023362cbeacd Style cleanup. 9a56c49ed415df1b72ba1c84c8e7ed00de497f68 Merge pull request #679 from smartxworks:optimize-readseq abf441b657c7e75091e2bd59449df6849358b812 Merge pull request #278 from wankai:master 78b39d68c15ba020c0d60a3906fb66dbf1697595 Bump the version number from 1.21 to 1.22. 9bd23c767601a2420478eec158927882b879bada Correct class/structure declaration order. c784d63b931d07895833fb80185b10d44ad63cce Moved port/README to port/README.md. 297e66afc1dda3f3d7a7cc2022030164c302cb7a Format all files IAW the Google C++ Style Guide. 3724030179716fd8d95cf79339884c49afade8f9 Update Travis CI configuration. d3d1c8a0f40a7eaa12a5bb702fa01786b7c3a646 don't check current key in DBIter::Next() 3dc9202f78a3eb30ee8c0267e4e4be2e3f986e45 [leveldb] Specifically export the WriteBatch::Handler inner class for Windows link 2ccb45c33aecd8b15000c0c622f45eb119b6b478 Check for possibly invalid offset in test. 7b1174519044339f07a023dc445b0d36425bd6db Changed Windows specific highlighting from bash to cmd. 2f008ac19ec783e4d0ba2161320241c99e9897e1 Initialize class members to default values in constructors. ffabb1ae86cc4eb4516a7c0824c878c3b2d19e5d Merge pull request #665 from cheng-chang:coding 7da571cf2b954a107fa060698bfbfbba8e8318f8 Merge pull request #669 from pavel-pimenov:fix-readme-windows-mkdir df4a323aafbf65996fec23de8b2dbb9d7e27ae11 Merge pull request #472 from zhoudayang:patch-1 5a2a472741f36ecf5b994439da5a64c6ab90c47f Fixed missing std namespaces and make_unique. 08e771901f454ac32643bd8e8cb2bcfa08026c0c Simplify issue320_test. 65e86f75ea30e44bc65327f92a16328684269acb Fix formatting of recent snapshot compaction fix. 7711e76766231bf93e0487c4530b2655e8c4c0b1 Merge pull request #339 from richcole-at-amazon:master 71ed7c401ec1b1e38d6f7cb9eb2fcff93c24d1f1 Fixed typo in comment in version_set.h. 09fa8868dbe0cb2701f0560c59ebb63cc17f1271 Align version/soversion CMake setup closer with other repositories. 20fb601aa9f68ff0aa147df22524b7d01758552b Fix snapshot compaction bug 37300aa54b8256dd2edfd504942eb2bd20823647 Restore soname versioning with CMake build 952be04df6edb936b8f7d0f652861100a7f61e97 Fix mkdir (windows) 56178ddaf4d3ba6c8d1cfb218610b1be3f5aa710 Update the version to 1.21 in preparation for a new release. 35619d248d909b197f68226c7d0a9ff947b82e8a Project import generated by Copybara. 416344de2fdffb3f17c565b984885d0122bfa1e9 leveldb: Register in copybara whitelist. da94ac67e91679842a56a876f0b19b429d72de25 leveldb: Minor cleanup in ports. bd24b963060861518c6648925f9708178562c992 leveldb: Silence unused argument warnings in MSVC. 6188a54ce95b47cc6bd398d7f2eb45d061857e45 leveldb: Add tests for empty keys and values. cf1b5f473259e46c667f3fb5a28bcd884ee3a102 Remove unnecessary bit operation. 7035af5fc36657447054617759854a726d31dbe0 Two small fixes for the Windows implementation (#661) 6571279d6de21fe33caa31b2ea4170d34b15b10e fix a typo in the comment of skiplist_test.cc (#664) 15e227896621d01ebad4c5d4b3cc82a7a9b5b30b Use override consistently in leveldb::test::ErrorEnv. ea49b27d062c4bc998616cef7944f7f9088a327d Switch corruption_test to use InMemEnv. ce399ac28af7023b1aff0ede4986cb6d89b3c0b5 Always copy bytes to scratch buffer when reading w/MemEnv. 201f77d137f30ea46e789a2ad60e9119b6f990fc Inline defaults in options. 9ce30510d482f5b2fa2965201453f0fc914f700c Deleted dangling reference to deleted atomic_pointer.h. 7d8e41e49b8fddda66a2c5f0a6a47f1a916e8d26 leveldb: Replace AtomicPointer with std::atomic. dd906262fd364c08a652dfa914f9995f6b7608a9 Make InMemoryEnv more consistent with filesystem based Env's. cf1d1ab255de2a741695aec53d83e4f808f9e819 leveldb: Remove unused file port/win/stdint.h. a20508dc6a18a34e05a6fc476a8d587fa9bb6608 Fix typo (#565) 04470825ac96cab0d9d16e4ed410349d082fbf82 Add AppVeyor (Windows CI) badge to README. ed76289b259d42d0a57c147e791e2c235ed28805 Align windows_logger with posix_logger. 808e59ec6a160244960cda64b393968ffbdae72c Improve CI configuration. c69d33b0ec3dad2a8063ad66da9d51a1d6309f4e Added native support for Windows. 75fceae7003e217e16b04433831da7528ae56881 Add O_CLOEXEC to open calls. fe4494804f5e3a2e25485d32aeb0eb7d2f25732e leveldb: Make WriteBatch::ApproximateSize() const. 296de8d5b8e4e57bd1e46c981114dfbe58a8c4fa leveldb: Fix PosixWritableFile::Sync() on Apple systems. b70493ca8586285b49e9888e2b528f71806bdc6e Fix fdatasync() feature detection in opensource build. af7abf06ea061222c2c34d98e1995c5a901f374f Add back space to POSIX Logger. 58d70545af9ec7f30821f973b604f8e2a2f9ebdb Update Travis CI configuration. 1cb384088184be9840bd59b4040503a9fa9aee66 Clean up env_posix.cc. a7dc502e9f11c2e5c911ba45b999676c43eaa51f Rework once initialization in env_posix.cc. c43565dd398b2233db8eb49ba05234d62fb42e03 C++11 cleanup for util/mutexlock.h. 0145a94ab6bec48e596df499e8f6103e138a74ab Update .gitignore. 73d5834eceee8efa9a8ccfec77dc096a9e8ba18a Rework threading in env_posix.cc. 05709fb43eea34936c9f535edcb74d5e91a0b495 Remove InitOnce from the port API. bb88f25115d20a6d73dfb6b16cc298db2f66948b Clean up PosixWritableFile in env_posix.cc. 7b945f200339aa47c24788d3ee9910c09c513843 Clean up posix_logger.h. 89af27bde59fbbb3025653812b45fec10a655cb7 Remove ssize_t from code that is not POSIX-specific. 03064cbbb2c00c3e6e41a78e8111d14a020f7d6f Simplify Limiter in env_posix.cc. 9b44da73d9b1d839c437e3fdaaa14ea08260dce4 Clarify comments for leveldb::Env file reading methods. 0ef2310f67f0c0b4ba3e6ad86d8138440af30d67 Remove GCC on OSX from the Travis CI matrix. 16a2b8bb3af5b1f54676256e55a5d3f0ec02da42 Expose WriteBatch::Append in the C API. f7b0e1d901da26ac5ce6ad7f0a9806ce1440197e Expose WriteBatch::Append(). 6caf73ad9dae0ee91873bcb39554537b85163770 Clean up Iterator. 6a6bdafcf10f5d4bef1ca52697c38d10c28b1a8b Corrected typo in docs: "cache" to "block_cache". 18683981505dc374ce29211c80a9552f8f2f4571 Clean up SnapshotImpl. e7840de9f3db1a5eddedfecbbbc1ff72a4c2631a Fix documentation for log file growth. bc23e00f955eadb9e26f8ce07c1c664e7b985ff0 Update default log file size in doc. 4de9594f6fbfd69043239a5705b5f32065f02d34 Add move constructor to Status. d177a0263cce4344d05188521ad53459c369b940 Replace port_posix with port_stdcxx. 14cce848e7b8a040a8f457d5a796722a55e19597 Fix sign mismatch warnings in GCC. 8046a51b21114d3575421bfc78b1d98b1678720a Add forgotten <limits> header to util/logging.cc. a0008deb679480fd30e845d7e52421af72160c2c Reimplement ConsumeDecimalNumber. 1f7dd5d5f6822f2b0b9f9e4c7d87d4535c122c0e Add tests for ConsumeDecimalNumber. 1cc8b10b8232e174d5bd1313959825727e03faa7 Document the building process. 09217fd0677a4fd9713c7a4d774c494a7d3c1f15 Replace NULL with nullptr in C++ files. 6a3b915166fce75aaf9ac209114a3ad9caa34171 Remove PLATFORM_IS_LITTLE_ENDIAN from port/posix.h. 260655b4c294991fe03bf6ab8b6d722ccfc41d32 Define LEVELDB_HAS_PORT_CONFIG_H for old compilers. 6fa45666703add49f77652b2eadd874d49aedaf6 Rename CMake project / targets from Leveldb to leveldb. 0db30413a4cfa8c980e675ba5cb96717d688af92 leveldb: Add more thread safety annotations. 04f39105c5a418905da8b7657ca244d672c99d3b Take <atomic> for granted in port/atomic_pointer.h. 74f032ff6f2465160366d865b1bb89a45dc2046b leveldb: Require C++11. 8e75db8623703cdc25ec3cd06f82129296672489 Remove build configuration for make. df9a841a4fc9a04c7713542d75f50e749fb64b7b Add export.h to CMakeLists.txt 50fbc87e8c62a816d6afd4740e0652a13ac6dc3e Replace SIZE_MAX with std::numeric_limits. 739c25100e46576cdcdfff2d6f43f9f7008103c7 Add CMake build support. 0fa5a4f7b1ad9dc16b705bcad1f3ca913f187325 Extend thread safety annotations. 8143c12f3fc483b1ba61cdce11f9c1faf6d01bea Fix includes in util/testharness.h. aece2068d7375f987685b8b145288c5557f9ce50 Remove extern from function declarations. ddab751002588fe58955357d68d12b062e038d0d Add tests for {Old}InfoLogFileName(). 7fd7c0072159abbca2660d91fc0667d5c17c4d16 Remove unused function ExtractValueType. 594cc987af2e0af6417c4ac2b947ee8cdad59e5e Bypass OSMemoryBarrier() warning on Mac. 49f35d3fc940a1e2d599d6ee3306eeb31a205e4b leveldb: Update Travis CI configuration for open source build. 623d014a54f8cf9b74ad6aaba9181ca1e65c43a1 Expose Env::GetTempDirectory() for use in C test. 8c8024ea33d8efc8c415597fb7fa1745002961d6 Switch HAVE_ library detection macros to 0/1. 41172a24016bc29fc795ed504737392587f54e3d Enable thread safety annotations in open source version. 47cb9e2a211e1d7157078ba7bab536beb29e56dc Add leveldb_options_set_max_file_size to the C API. b5d4a22e64c7a6615b412f464026c808b58b1d34 Fixed style guide link in CONTRIBUTING.md 3da4d8b9899257386aeb5ffa345a6477c62ff7bf Deleted unused assignments in Reader. 0509414f858ae7c7225e29f3659a709afb324355 leveldb::DestroyDB will now delete empty directories. 23162ca1c6d891a9c5fe0e0fab1193cd54ed1b4f Fix typo (forgotten reference operator) in test. 5c39524f3639e6bf6ab49215152d24273e662986 Replace SSE-optimized CRC32C in POSIX port with external library. ca216e493f32278f50a823811ab95f64cf0f839b leveldb: Rename SNAPPY to HAVE_SNAPPY. 25767d066ca995c055f04b78a31a6e518087e667 leveldb: Remove *_unlocked feature detection from POSIX port. 4a7e7f50dcf661cfffe71737650b0fb18e195d18 Add LEVELDB_EXPORT macro to export public symbols. 542590d2a8eee3838f40b01405baa6d2f6f8c700 leveldb: Include <algorithm> in util/env_test.cc. 8ae7998aabae4f208d77afcb930dafabade1b28d Fix FD leak in POSIX Env. d9a9e02edf2b8187aa481416b36c49710026ab37 leveldb: Add tests for CL 170769101. 4447f9caced2bd09585c90f1b203c3aa8f4bbc40 Remove handling for unused LRUHandle representation special case. 2372ac574fdeb1235e70cdd86a2681d1ce05cf65 Fix file writing bug in CL 170738066. 1c75e88055e06da2939f9f4bd294625b76792815 Fix use of uninitialized value in LRUHandle. 7e12c00ecf1bb725e212618e7026e4d34d6cd3bb Fix issue 474: a race between the f*_unlocked() STDIO calls in env_posix.cc and concurrent application calls to fflush(NULL). bcd9a8ea4a8aad23a3e101a23c61615bab2a093f Use portable CRC32C from google/crc32c. ea0a7586b8615fd39c6b8f5a8a21a1f242129c2f Remove confusing and unnecessary if. 141e7671359d5e6c65ff70460774b53b94371df1 Simplify Table::Open() flow and remove a delete call. 09a3c8e7417547829b94bcdaa62cdf9e896f29a9 Switched variable type from int to uint64_t in ConsumeDecimalNumber. 2964b803b857932ff7499d7bebb61dc5514dab7c leveldb: Fix alignment code in SSE4.2-optimized CRC32C. 02f43c0fcde39823830493503e8a3f72fed43d24 Remove dead code. 0b402e96a76b19cd98e82402de636449a2613228 Use __APPLE__ instead of OS_MACOS. The former is compiler-provided. 8415f00eeedd96934d3578572d3802900e61a556 leveldb: Report missing CURRENT manifest file as database corruption. 69e2bd224b7f11e021527cb95bab18f1ee6e1b3b LevelDB: Add WriteBatch::ApproximateSize(). 471f0b84ec3420c7565511eb6e2fee8e0a0550e8 fix comment 5b817400a0a5afe3badbb8859706a571882ababc fix comment 7d060117fa0d5cab7cb15b0cf127533bea9ffbc7 broken db: fix assertion in leveldb::InternalKey::Encode, mark base as corrupt 2883fcd849ca7b479d8a2f4fc929f0b6c7b9e372 set const property e5f0a51fa44115fb083c1e71d5ddcd07a7aba719 reduce lock's range in DeleteObsoleteFiles dd598676cd655dc2a2aaef47715ce18175d4a550 block_builder header file dependency fixed REVERT: f545dfabff4c2e9836efed094dba99a34fbc6b88 Merge #18: Use utf-8 to decode filename REVERT: f8e797a058b7a3993314e985dfdff8124214ba99 Use utf-8 to decode filename REVERT: 2fc114812a04e6b88852fa37eedc556a464241f7 Merge #14: Fixes to allow building with msvc. REVERT: 524b7e36a8e3bce6fcbcd1b5df09024283f325ba Merge #19: Increase maximum read-only mmap()s used from 1000 to 4096 on 64-bit systems REVERT: 4874cb8d3e1dc7b9026b9faf51b9282c91f8ef40 Increase maximum number of read-only mmap()s used from 1000 to 4096 on 64 bit systems. REVERT: 64052c76c567cff3dad32d1db0ef969d97b5882f Merge #15: Add filename to corruption errors REVERT: 135ed0fb4e5d6440b174c4b80c147e915dd58969 Add filename to corruption errors REVERT: d6eab93138884ee6c466fad5dadf2a1bfeb7cffd Fixes to allow building with msvc. REVERT: c521b3ac654cfbe009c575eacf7e5a6e189bb5bb Merge #11: fixup define checks. Cleans up some oopses from #5. REVERT: 8b1cd3753b184341e837b30383832645135d3d73 fixup define checks. Cleans up some oopses from #5. REVERT: 6b1508d6d58caabf76cec2688b3428c9070b7bc9 Merge #6: Fixes typo REVERT: fceb805426c66c8b79e2d75b83b4a35c57ad3a6e Merge #10: Clean up compile-time warnings (gcc 7.1) REVERT: 0ec2a343f3be66ef6e25f9b9badc0256ac0911b7 Clean up compile-time warnings (gcc 7.1) REVERT: d4c268a3571a66b3712ad24dfaf4b9f9671bcdf2 Merge #5: Move helper functions out of sse4.2 object REVERT: 8d4eb0847041a26377dc99b1c4fb5c22d4841d5e Add HasAcceleratedCRC32C to port_win.h REVERT: 77cfbfd250a690978a3b81d364054039467ed549 crc32: move helper functions out of port_posix_sse.cc REVERT: 4c1e9e01688864a32217e541102fa8d2df9a3d59 silence compiler warnings about uninitialized variables REVERT: 4953164851d1bc2fc653f60a98df5aa5c1dfcebd Merge #2: Prefer std::atomic over MemoryBarrier REVERT: 2953978ef8cd8f0babcac86a52f5c688a5ad8fa8 Fixes typo REVERT: f134284a1ce6e8e3ccc375a0a44300d9a87c51ab Merge #1: Merge upstream LevelDB 1.20 REVERT: 196962ff01c39b4705d8117df5c3f8c205349950 Add AcceleratedCRC32C to port_win.h REVERT: ba8a445fdaa7cf3cb888a151e055330483b946f6 Prefer std::atomic over MemoryBarrier REVERT: 1bdf1c34c5d903e466673a15103124568d995db4 Merge upstream LevelDB v1.20 REVERT: d31721eb0a115ac55506bb6735034bf915adc914 Merge #17: Fixed file sharing errors REVERT: fecd449021504dc647c1a1226d72ab0d5efb84ad Fixed file sharing error in Win32Env::GetFileSize(), Win32SequentialFile::_Init(), Win32RandomAccessFile::_Init() Fixed error checking in Win32SequentialFile::_Init() REVERT: 5b7510f1b79d9af1c5fe272a4587517a2579d3b7 Merge #14: Merge upstream LevelDB 1.19 REVERT: 0d969fd5708c9fd559d63be28664e1e840beb8ca Merge #16: [LevelDB] Do no crash if filesystem can't fsync REVERT: c8c029b5b5793d3c9afef34afa53d10a910adf4e [LevelDB] Do no crash if filesystem can't fsync REVERT: a31c8aa408d5594830f7cb20ead1ef1dff51b79e Add NewAppendableFile for win32 environment REVERT: d40bc3fa5aaa5438d4d8f55ee83e6b3cd161ce02 Merge #13: Typo REVERT: ebbd772d33d8596e5765a4d1251308d732d61355 Typo REVERT: 1913d718ef8b07288229a75553862fcb343bf3ab Merge upstream LevelDB 1.19 REVERT: 20ca81f08fb7fa108923a091668e447dcf5c6b9d Merge pull request #9 REVERT: 7aa105e1a34e6e52b1e0de16d9d659a2af26fa0a leveldb: Win32WritableFile without memory mapping REVERT: 7d41e6f89ff04ce9e6a742932924796f69c6e23d Merge upstream LevelDB 1.18 REVERT: 42dcc7edfc98c50038e4604fa630c626db17bf42 Merge upstream LevelDB 1.17. REVERT: e991315d7fe4ca84a98902578106cbffa3dcccfd Merge upstream LevelDB 1.15. REVERT: 02ac9f170b1c47e2c613cd47b8d7da45743af575 Merge upstream LevelDB 1.14. REVERT: 936b4613ea4551992e6096b1e05eeefc09a20e3b Merge upstream LevelDB 1.13. REVERT: be1b0ff1fcd6ad820a7fd111ac671fb51cc68001 On Mac OS X fsync does not guarantee write to disk. Use fcntl F_FULLFSYNC instead. REVERT: a02ddf9b14d145e88185ee209ab8b01d8826663a Added GNU/kFreeBSD kernel name (TARGET_OS) REVERT: 848746862caf337254a8a3e3a6bd3fa355db4fc8 CondVar::SignalAll was broken, leading to deadlocks on Windows builds. http://code.google.com/p/leveldb/issues/detail?id=149 REVERT: f6d84d1baf74a15ee8a0f73a81c647058bf816e9 Allow files to be opened for reading multiple times REVERT: cb8e3f7adfaa48e09fb7a467086d69e4b6f948bd Checking whether closing succeeds REVERT: d5317e8eda06d8dbbf04f08866c92323ccdbb43f Print actual Win32 error that occurred on file creation failure. REVERT: 907f3084998fa4ce96b7abc6d9b12c7aa7b81c8c Port leveldb to MinGW32 REVERT: 9def2bfbf18dfbc0c3c95e90c91f043a6de3c1cb Mingw support for Windows LevelDB port REVERT: 0a7b0748c71e64fd920eed94c26d69bc9ae77870 Pre-Vista leveldb::port::InitOnce implementation REVERT: 31a2b09985842c833fbbd81e17f207c377217754 Native Windows LevelDB port REVERT: 058a0357cd9650b214a199f81669a07d3eb4a298 Remove Snappy support git-subtree-dir: src/leveldb git-subtree-split: f8ae182c1e5176d12e816fb2217ae33a5472fdd7
Diffstat (limited to 'include')
-rw-r--r--include/leveldb/c.h320
-rw-r--r--include/leveldb/cache.h21
-rw-r--r--include/leveldb/comparator.h11
-rw-r--r--include/leveldb/db.h58
-rw-r--r--include/leveldb/dumpfile.h5
-rw-r--r--include/leveldb/env.h220
-rw-r--r--include/leveldb/export.h33
-rw-r--r--include/leveldb/filter_policy.h12
-rw-r--r--include/leveldb/iterator.h34
-rw-r--r--include/leveldb/options.h100
-rw-r--r--include/leveldb/slice.h38
-rw-r--r--include/leveldb/status.h52
-rw-r--r--include/leveldb/table.h33
-rw-r--r--include/leveldb/table_builder.h11
-rw-r--r--include/leveldb/write_batch.h37
15 files changed, 533 insertions, 452 deletions
diff --git a/include/leveldb/c.h b/include/leveldb/c.h
index 1048fe3b86..02c79ba72e 100644
--- a/include/leveldb/c.h
+++ b/include/leveldb/c.h
@@ -32,7 +32,7 @@
On failure, leveldb frees the old value of *errptr and
set *errptr to a malloc()ed error message.
- (4) Bools have the type unsigned char (0 == false; rest == true)
+ (4) Bools have the type uint8_t (0 == false; rest == true)
(5) All of the pointer arguments must be non-NULL.
*/
@@ -48,225 +48,205 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>
+#include "leveldb/export.h"
+
/* Exported types */
-typedef struct leveldb_t leveldb_t;
-typedef struct leveldb_cache_t leveldb_cache_t;
-typedef struct leveldb_comparator_t leveldb_comparator_t;
-typedef struct leveldb_env_t leveldb_env_t;
-typedef struct leveldb_filelock_t leveldb_filelock_t;
-typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t;
-typedef struct leveldb_iterator_t leveldb_iterator_t;
-typedef struct leveldb_logger_t leveldb_logger_t;
-typedef struct leveldb_options_t leveldb_options_t;
-typedef struct leveldb_randomfile_t leveldb_randomfile_t;
-typedef struct leveldb_readoptions_t leveldb_readoptions_t;
-typedef struct leveldb_seqfile_t leveldb_seqfile_t;
-typedef struct leveldb_snapshot_t leveldb_snapshot_t;
-typedef struct leveldb_writablefile_t leveldb_writablefile_t;
-typedef struct leveldb_writebatch_t leveldb_writebatch_t;
-typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
+typedef struct leveldb_t leveldb_t;
+typedef struct leveldb_cache_t leveldb_cache_t;
+typedef struct leveldb_comparator_t leveldb_comparator_t;
+typedef struct leveldb_env_t leveldb_env_t;
+typedef struct leveldb_filelock_t leveldb_filelock_t;
+typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t;
+typedef struct leveldb_iterator_t leveldb_iterator_t;
+typedef struct leveldb_logger_t leveldb_logger_t;
+typedef struct leveldb_options_t leveldb_options_t;
+typedef struct leveldb_randomfile_t leveldb_randomfile_t;
+typedef struct leveldb_readoptions_t leveldb_readoptions_t;
+typedef struct leveldb_seqfile_t leveldb_seqfile_t;
+typedef struct leveldb_snapshot_t leveldb_snapshot_t;
+typedef struct leveldb_writablefile_t leveldb_writablefile_t;
+typedef struct leveldb_writebatch_t leveldb_writebatch_t;
+typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
/* DB operations */
-extern leveldb_t* leveldb_open(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
+LEVELDB_EXPORT leveldb_t* leveldb_open(const leveldb_options_t* options,
+ const char* name, char** errptr);
-extern void leveldb_close(leveldb_t* db);
+LEVELDB_EXPORT void leveldb_close(leveldb_t* db);
-extern void leveldb_put(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- const char* key, size_t keylen,
- const char* val, size_t vallen,
- char** errptr);
+LEVELDB_EXPORT void leveldb_put(leveldb_t* db,
+ const leveldb_writeoptions_t* options,
+ const char* key, size_t keylen, const char* val,
+ size_t vallen, char** errptr);
-extern void leveldb_delete(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- const char* key, size_t keylen,
- char** errptr);
+LEVELDB_EXPORT void leveldb_delete(leveldb_t* db,
+ const leveldb_writeoptions_t* options,
+ const char* key, size_t keylen,
+ char** errptr);
-extern void leveldb_write(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- leveldb_writebatch_t* batch,
- char** errptr);
+LEVELDB_EXPORT void leveldb_write(leveldb_t* db,
+ const leveldb_writeoptions_t* options,
+ leveldb_writebatch_t* batch, char** errptr);
/* Returns NULL if not found. A malloc()ed array otherwise.
Stores the length of the array in *vallen. */
-extern char* leveldb_get(
- leveldb_t* db,
- const leveldb_readoptions_t* options,
- const char* key, size_t keylen,
- size_t* vallen,
- char** errptr);
+LEVELDB_EXPORT char* leveldb_get(leveldb_t* db,
+ const leveldb_readoptions_t* options,
+ const char* key, size_t keylen, size_t* vallen,
+ char** errptr);
-extern leveldb_iterator_t* leveldb_create_iterator(
- leveldb_t* db,
- const leveldb_readoptions_t* options);
+LEVELDB_EXPORT leveldb_iterator_t* leveldb_create_iterator(
+ leveldb_t* db, const leveldb_readoptions_t* options);
-extern const leveldb_snapshot_t* leveldb_create_snapshot(
- leveldb_t* db);
+LEVELDB_EXPORT const leveldb_snapshot_t* leveldb_create_snapshot(leveldb_t* db);
-extern void leveldb_release_snapshot(
- leveldb_t* db,
- const leveldb_snapshot_t* snapshot);
+LEVELDB_EXPORT void leveldb_release_snapshot(
+ leveldb_t* db, const leveldb_snapshot_t* snapshot);
/* Returns NULL if property name is unknown.
Else returns a pointer to a malloc()-ed null-terminated value. */
-extern char* leveldb_property_value(
- leveldb_t* db,
- const char* propname);
-
-extern void leveldb_approximate_sizes(
- leveldb_t* db,
- int num_ranges,
- const char* const* range_start_key, const size_t* range_start_key_len,
- const char* const* range_limit_key, const size_t* range_limit_key_len,
- uint64_t* sizes);
-
-extern void leveldb_compact_range(
- leveldb_t* db,
- const char* start_key, size_t start_key_len,
- const char* limit_key, size_t limit_key_len);
+LEVELDB_EXPORT char* leveldb_property_value(leveldb_t* db,
+ const char* propname);
+
+LEVELDB_EXPORT void leveldb_approximate_sizes(
+ leveldb_t* db, int num_ranges, const char* const* range_start_key,
+ const size_t* range_start_key_len, const char* const* range_limit_key,
+ const size_t* range_limit_key_len, uint64_t* sizes);
+
+LEVELDB_EXPORT void leveldb_compact_range(leveldb_t* db, const char* start_key,
+ size_t start_key_len,
+ const char* limit_key,
+ size_t limit_key_len);
/* Management operations */
-extern void leveldb_destroy_db(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
+LEVELDB_EXPORT void leveldb_destroy_db(const leveldb_options_t* options,
+ const char* name, char** errptr);
-extern void leveldb_repair_db(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
+LEVELDB_EXPORT void leveldb_repair_db(const leveldb_options_t* options,
+ const char* name, char** errptr);
/* Iterator */
-extern void leveldb_iter_destroy(leveldb_iterator_t*);
-extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
-extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
-extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
-extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
-extern void leveldb_iter_next(leveldb_iterator_t*);
-extern void leveldb_iter_prev(leveldb_iterator_t*);
-extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
-extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
-extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
+LEVELDB_EXPORT void leveldb_iter_destroy(leveldb_iterator_t*);
+LEVELDB_EXPORT uint8_t leveldb_iter_valid(const leveldb_iterator_t*);
+LEVELDB_EXPORT void leveldb_iter_seek_to_first(leveldb_iterator_t*);
+LEVELDB_EXPORT void leveldb_iter_seek_to_last(leveldb_iterator_t*);
+LEVELDB_EXPORT void leveldb_iter_seek(leveldb_iterator_t*, const char* k,
+ size_t klen);
+LEVELDB_EXPORT void leveldb_iter_next(leveldb_iterator_t*);
+LEVELDB_EXPORT void leveldb_iter_prev(leveldb_iterator_t*);
+LEVELDB_EXPORT const char* leveldb_iter_key(const leveldb_iterator_t*,
+ size_t* klen);
+LEVELDB_EXPORT const char* leveldb_iter_value(const leveldb_iterator_t*,
+ size_t* vlen);
+LEVELDB_EXPORT void leveldb_iter_get_error(const leveldb_iterator_t*,
+ char** errptr);
/* Write batch */
-extern leveldb_writebatch_t* leveldb_writebatch_create();
-extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
-extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
-extern void leveldb_writebatch_put(
- leveldb_writebatch_t*,
- const char* key, size_t klen,
- const char* val, size_t vlen);
-extern void leveldb_writebatch_delete(
- leveldb_writebatch_t*,
- const char* key, size_t klen);
-extern void leveldb_writebatch_iterate(
- leveldb_writebatch_t*,
- void* state,
+LEVELDB_EXPORT leveldb_writebatch_t* leveldb_writebatch_create(void);
+LEVELDB_EXPORT void leveldb_writebatch_destroy(leveldb_writebatch_t*);
+LEVELDB_EXPORT void leveldb_writebatch_clear(leveldb_writebatch_t*);
+LEVELDB_EXPORT void leveldb_writebatch_put(leveldb_writebatch_t*,
+ const char* key, size_t klen,
+ const char* val, size_t vlen);
+LEVELDB_EXPORT void leveldb_writebatch_delete(leveldb_writebatch_t*,
+ const char* key, size_t klen);
+LEVELDB_EXPORT void leveldb_writebatch_iterate(
+ const leveldb_writebatch_t*, void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen));
+LEVELDB_EXPORT void leveldb_writebatch_append(
+ leveldb_writebatch_t* destination, const leveldb_writebatch_t* source);
/* Options */
-extern leveldb_options_t* leveldb_options_create();
-extern void leveldb_options_destroy(leveldb_options_t*);
-extern void leveldb_options_set_comparator(
- leveldb_options_t*,
- leveldb_comparator_t*);
-extern void leveldb_options_set_filter_policy(
- leveldb_options_t*,
- leveldb_filterpolicy_t*);
-extern void leveldb_options_set_create_if_missing(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_error_if_exists(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_paranoid_checks(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
-extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
-extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
-extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
-extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
-extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
-extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
-
-enum {
- leveldb_no_compression = 0,
- leveldb_snappy_compression = 1
-};
-extern void leveldb_options_set_compression(leveldb_options_t*, int);
+LEVELDB_EXPORT leveldb_options_t* leveldb_options_create(void);
+LEVELDB_EXPORT void leveldb_options_destroy(leveldb_options_t*);
+LEVELDB_EXPORT void leveldb_options_set_comparator(leveldb_options_t*,
+ leveldb_comparator_t*);
+LEVELDB_EXPORT void leveldb_options_set_filter_policy(leveldb_options_t*,
+ leveldb_filterpolicy_t*);
+LEVELDB_EXPORT void leveldb_options_set_create_if_missing(leveldb_options_t*,
+ uint8_t);
+LEVELDB_EXPORT void leveldb_options_set_error_if_exists(leveldb_options_t*,
+ uint8_t);
+LEVELDB_EXPORT void leveldb_options_set_paranoid_checks(leveldb_options_t*,
+ uint8_t);
+LEVELDB_EXPORT void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
+LEVELDB_EXPORT void leveldb_options_set_info_log(leveldb_options_t*,
+ leveldb_logger_t*);
+LEVELDB_EXPORT void leveldb_options_set_write_buffer_size(leveldb_options_t*,
+ size_t);
+LEVELDB_EXPORT void leveldb_options_set_max_open_files(leveldb_options_t*, int);
+LEVELDB_EXPORT void leveldb_options_set_cache(leveldb_options_t*,
+ leveldb_cache_t*);
+LEVELDB_EXPORT void leveldb_options_set_block_size(leveldb_options_t*, size_t);
+LEVELDB_EXPORT void leveldb_options_set_block_restart_interval(
+ leveldb_options_t*, int);
+LEVELDB_EXPORT void leveldb_options_set_max_file_size(leveldb_options_t*,
+ size_t);
+
+enum { leveldb_no_compression = 0, leveldb_snappy_compression = 1 };
+LEVELDB_EXPORT void leveldb_options_set_compression(leveldb_options_t*, int);
/* Comparator */
-extern leveldb_comparator_t* leveldb_comparator_create(
- void* state,
- void (*destructor)(void*),
- int (*compare)(
- void*,
- const char* a, size_t alen,
- const char* b, size_t blen),
+LEVELDB_EXPORT leveldb_comparator_t* leveldb_comparator_create(
+ void* state, void (*destructor)(void*),
+ int (*compare)(void*, const char* a, size_t alen, const char* b,
+ size_t blen),
const char* (*name)(void*));
-extern void leveldb_comparator_destroy(leveldb_comparator_t*);
+LEVELDB_EXPORT void leveldb_comparator_destroy(leveldb_comparator_t*);
/* Filter policy */
-extern leveldb_filterpolicy_t* leveldb_filterpolicy_create(
- void* state,
- void (*destructor)(void*),
- char* (*create_filter)(
- void*,
- const char* const* key_array, const size_t* key_length_array,
- int num_keys,
- size_t* filter_length),
- unsigned char (*key_may_match)(
- void*,
- const char* key, size_t length,
- const char* filter, size_t filter_length),
+LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create(
+ void* state, void (*destructor)(void*),
+ char* (*create_filter)(void*, const char* const* key_array,
+ const size_t* key_length_array, int num_keys,
+ size_t* filter_length),
+ uint8_t (*key_may_match)(void*, const char* key, size_t length,
+ const char* filter, size_t filter_length),
const char* (*name)(void*));
-extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
+LEVELDB_EXPORT void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
-extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
+LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
int bits_per_key);
/* Read options */
-extern leveldb_readoptions_t* leveldb_readoptions_create();
-extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
-extern void leveldb_readoptions_set_verify_checksums(
- leveldb_readoptions_t*,
- unsigned char);
-extern void leveldb_readoptions_set_fill_cache(
- leveldb_readoptions_t*, unsigned char);
-extern void leveldb_readoptions_set_snapshot(
- leveldb_readoptions_t*,
- const leveldb_snapshot_t*);
+LEVELDB_EXPORT leveldb_readoptions_t* leveldb_readoptions_create(void);
+LEVELDB_EXPORT void leveldb_readoptions_destroy(leveldb_readoptions_t*);
+LEVELDB_EXPORT void leveldb_readoptions_set_verify_checksums(
+ leveldb_readoptions_t*, uint8_t);
+LEVELDB_EXPORT void leveldb_readoptions_set_fill_cache(leveldb_readoptions_t*,
+ uint8_t);
+LEVELDB_EXPORT void leveldb_readoptions_set_snapshot(leveldb_readoptions_t*,
+ const leveldb_snapshot_t*);
/* Write options */
-extern leveldb_writeoptions_t* leveldb_writeoptions_create();
-extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
-extern void leveldb_writeoptions_set_sync(
- leveldb_writeoptions_t*, unsigned char);
+LEVELDB_EXPORT leveldb_writeoptions_t* leveldb_writeoptions_create(void);
+LEVELDB_EXPORT void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
+LEVELDB_EXPORT void leveldb_writeoptions_set_sync(leveldb_writeoptions_t*,
+ uint8_t);
/* Cache */
-extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
-extern void leveldb_cache_destroy(leveldb_cache_t* cache);
+LEVELDB_EXPORT leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
+LEVELDB_EXPORT void leveldb_cache_destroy(leveldb_cache_t* cache);
/* Env */
-extern leveldb_env_t* leveldb_create_default_env();
-extern void leveldb_env_destroy(leveldb_env_t*);
+LEVELDB_EXPORT leveldb_env_t* leveldb_create_default_env(void);
+LEVELDB_EXPORT void leveldb_env_destroy(leveldb_env_t*);
+
+/* If not NULL, the returned buffer must be released using leveldb_free(). */
+LEVELDB_EXPORT char* leveldb_env_get_test_directory(leveldb_env_t*);
/* Utility */
@@ -275,16 +255,16 @@ extern void leveldb_env_destroy(leveldb_env_t*);
in this file. Note that in certain cases (typically on Windows), you
may need to call this routine instead of free(ptr) to dispose of
malloc()-ed memory returned by this library. */
-extern void leveldb_free(void* ptr);
+LEVELDB_EXPORT void leveldb_free(void* ptr);
/* Return the major version number for this release. */
-extern int leveldb_major_version();
+LEVELDB_EXPORT int leveldb_major_version(void);
/* Return the minor version number for this release. */
-extern int leveldb_minor_version();
+LEVELDB_EXPORT int leveldb_minor_version(void);
#ifdef __cplusplus
-} /* end extern "C" */
+} /* end extern "C" */
#endif
-#endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */
+#endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */
diff --git a/include/leveldb/cache.h b/include/leveldb/cache.h
index 6819d5bc49..7d1a221193 100644
--- a/include/leveldb/cache.h
+++ b/include/leveldb/cache.h
@@ -19,26 +19,31 @@
#define STORAGE_LEVELDB_INCLUDE_CACHE_H_
#include <stdint.h>
+
+#include "leveldb/export.h"
#include "leveldb/slice.h"
namespace leveldb {
-class Cache;
+class LEVELDB_EXPORT Cache;
// Create a new cache with a fixed size capacity. This implementation
// of Cache uses a least-recently-used eviction policy.
-extern Cache* NewLRUCache(size_t capacity);
+LEVELDB_EXPORT Cache* NewLRUCache(size_t capacity);
-class Cache {
+class LEVELDB_EXPORT Cache {
public:
- Cache() { }
+ Cache() = default;
+
+ Cache(const Cache&) = delete;
+ Cache& operator=(const Cache&) = delete;
// Destroys all existing entries by calling the "deleter"
// function that was passed to the constructor.
virtual ~Cache();
// Opaque handle to an entry stored in the cache.
- struct Handle { };
+ struct Handle {};
// Insert a mapping from key->value into the cache and assign it
// the specified charge against the total cache capacity.
@@ -52,7 +57,7 @@ class Cache {
virtual Handle* Insert(const Slice& key, void* value, size_t charge,
void (*deleter)(const Slice& key, void* value)) = 0;
- // If the cache has no mapping for "key", returns NULL.
+ // If the cache has no mapping for "key", returns nullptr.
//
// Else return a handle that corresponds to the mapping. The caller
// must call this->Release(handle) when the returned mapping is no
@@ -99,10 +104,6 @@ class Cache {
struct Rep;
Rep* rep_;
-
- // No copying allowed
- Cache(const Cache&);
- void operator=(const Cache&);
};
} // namespace leveldb
diff --git a/include/leveldb/comparator.h b/include/leveldb/comparator.h
index 556b984c76..a85b51ebd8 100644
--- a/include/leveldb/comparator.h
+++ b/include/leveldb/comparator.h
@@ -7,6 +7,8 @@
#include <string>
+#include "leveldb/export.h"
+
namespace leveldb {
class Slice;
@@ -15,7 +17,7 @@ class Slice;
// used as keys in an sstable or a database. A Comparator implementation
// must be thread-safe since leveldb may invoke its methods concurrently
// from multiple threads.
-class Comparator {
+class LEVELDB_EXPORT Comparator {
public:
virtual ~Comparator();
@@ -43,9 +45,8 @@ class Comparator {
// If *start < limit, changes *start to a short string in [start,limit).
// Simple comparator implementations may return with *start unchanged,
// i.e., an implementation of this method that does nothing is correct.
- virtual void FindShortestSeparator(
- std::string* start,
- const Slice& limit) const = 0;
+ virtual void FindShortestSeparator(std::string* start,
+ const Slice& limit) const = 0;
// Changes *key to a short string >= *key.
// Simple comparator implementations may return with *key unchanged,
@@ -56,7 +57,7 @@ class Comparator {
// Return a builtin comparator that uses lexicographic byte-wise
// ordering. The result remains the property of this module and
// must not be deleted.
-extern const Comparator* BytewiseComparator();
+LEVELDB_EXPORT const Comparator* BytewiseComparator();
} // namespace leveldb
diff --git a/include/leveldb/db.h b/include/leveldb/db.h
index bfab10a0b7..b73014a221 100644
--- a/include/leveldb/db.h
+++ b/include/leveldb/db.h
@@ -7,14 +7,16 @@
#include <stdint.h>
#include <stdio.h>
+
+#include "leveldb/export.h"
#include "leveldb/iterator.h"
#include "leveldb/options.h"
namespace leveldb {
-// Update Makefile if you change these
+// Update CMakeLists.txt if you change these
static const int kMajorVersion = 1;
-static const int kMinorVersion = 20;
+static const int kMinorVersion = 22;
struct Options;
struct ReadOptions;
@@ -24,42 +26,44 @@ class WriteBatch;
// Abstract handle to particular state of a DB.
// A Snapshot is an immutable object and can therefore be safely
// accessed from multiple threads without any external synchronization.
-class Snapshot {
+class LEVELDB_EXPORT Snapshot {
protected:
virtual ~Snapshot();
};
// A range of keys
-struct Range {
- Slice start; // Included in the range
- Slice limit; // Not included in the range
+struct LEVELDB_EXPORT Range {
+ Range() = default;
+ Range(const Slice& s, const Slice& l) : start(s), limit(l) {}
- Range() { }
- Range(const Slice& s, const Slice& l) : start(s), limit(l) { }
+ Slice start; // Included in the range
+ Slice limit; // Not included in the range
};
// A DB is a persistent ordered map from keys to values.
// A DB is safe for concurrent access from multiple threads without
// any external synchronization.
-class DB {
+class LEVELDB_EXPORT DB {
public:
// Open the database with the specified "name".
// Stores a pointer to a heap-allocated database in *dbptr and returns
// OK on success.
- // Stores NULL in *dbptr and returns a non-OK status on error.
+ // Stores nullptr in *dbptr and returns a non-OK status on error.
// Caller should delete *dbptr when it is no longer needed.
- static Status Open(const Options& options,
- const std::string& name,
+ static Status Open(const Options& options, const std::string& name,
DB** dbptr);
- DB() { }
+ DB() = default;
+
+ DB(const DB&) = delete;
+ DB& operator=(const DB&) = delete;
+
virtual ~DB();
// Set the database entry for "key" to "value". Returns OK on success,
// and a non-OK status on error.
// Note: consider setting options.sync = true.
- virtual Status Put(const WriteOptions& options,
- const Slice& key,
+ virtual Status Put(const WriteOptions& options, const Slice& key,
const Slice& value) = 0;
// Remove the database entry (if any) for "key". Returns OK on
@@ -80,8 +84,8 @@ class DB {
// a status for which Status::IsNotFound() returns true.
//
// May return some other Status on an error.
- virtual Status Get(const ReadOptions& options,
- const Slice& key, std::string* value) = 0;
+ virtual Status Get(const ReadOptions& options, const Slice& key,
+ std::string* value) = 0;
// Return a heap-allocated iterator over the contents of the database.
// The result of NewIterator() is initially invalid (caller must
@@ -136,27 +140,27 @@ class DB {
// needed to access the data. This operation should typically only
// be invoked by users who understand the underlying implementation.
//
- // begin==NULL is treated as a key before all keys in the database.
- // end==NULL is treated as a key after all keys in the database.
+ // begin==nullptr is treated as a key before all keys in the database.
+ // end==nullptr is treated as a key after all keys in the database.
// Therefore the following call will compact the entire database:
- // db->CompactRange(NULL, NULL);
+ // db->CompactRange(nullptr, nullptr);
virtual void CompactRange(const Slice* begin, const Slice* end) = 0;
-
- private:
- // No copying allowed
- DB(const DB&);
- void operator=(const DB&);
};
// Destroy the contents of the specified database.
// Be very careful using this method.
-Status DestroyDB(const std::string& name, const Options& options);
+//
+// Note: For backwards compatibility, if DestroyDB is unable to list the
+// database files, Status::OK() will still be returned masking this failure.
+LEVELDB_EXPORT Status DestroyDB(const std::string& name,
+ const Options& options);
// If a DB cannot be opened, you may attempt to call this method to
// resurrect as much of the contents of the database as possible.
// Some data may be lost, so be careful when calling this function
// on a database that contains important information.
-Status RepairDB(const std::string& dbname, const Options& options);
+LEVELDB_EXPORT Status RepairDB(const std::string& dbname,
+ const Options& options);
} // namespace leveldb
diff --git a/include/leveldb/dumpfile.h b/include/leveldb/dumpfile.h
index 3f97fda16b..a58bc6b36c 100644
--- a/include/leveldb/dumpfile.h
+++ b/include/leveldb/dumpfile.h
@@ -6,7 +6,9 @@
#define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_
#include <string>
+
#include "leveldb/env.h"
+#include "leveldb/export.h"
#include "leveldb/status.h"
namespace leveldb {
@@ -18,7 +20,8 @@ namespace leveldb {
//
// Returns a non-OK result if fname does not name a leveldb storage
// file, or if the file cannot be read.
-Status DumpFile(Env* env, const std::string& fname, WritableFile* dst);
+LEVELDB_EXPORT Status DumpFile(Env* env, const std::string& fname,
+ WritableFile* dst);
} // namespace leveldb
diff --git a/include/leveldb/env.h b/include/leveldb/env.h
index 275d441eae..96c21b3966 100644
--- a/include/leveldb/env.h
+++ b/include/leveldb/env.h
@@ -13,12 +13,36 @@
#ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_
#define STORAGE_LEVELDB_INCLUDE_ENV_H_
-#include <string>
-#include <vector>
#include <stdarg.h>
#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "leveldb/export.h"
#include "leveldb/status.h"
+#if defined(_WIN32)
+// The leveldb::Env class below contains a DeleteFile method.
+// At the same time, <windows.h>, a fairly popular header
+// file for Windows applications, defines a DeleteFile macro.
+//
+// Without any intervention on our part, the result of this
+// unfortunate coincidence is that the name of the
+// leveldb::Env::DeleteFile method seen by the compiler depends on
+// whether <windows.h> was included before or after the LevelDB
+// headers.
+//
+// To avoid headaches, we undefined DeleteFile (if defined) and
+// redefine it at the bottom of this file. This way <windows.h>
+// can be included before this file (or not at all) and the
+// exported method will always be leveldb::Env::DeleteFile.
+#if defined(DeleteFile)
+#undef DeleteFile
+#define LEVELDB_DELETEFILE_UNDEFINED
+#endif // defined(DeleteFile)
+#endif // defined(_WIN32)
+
namespace leveldb {
class FileLock;
@@ -28,9 +52,13 @@ class SequentialFile;
class Slice;
class WritableFile;
-class Env {
+class LEVELDB_EXPORT Env {
public:
- Env() { }
+ Env() = default;
+
+ Env(const Env&) = delete;
+ Env& operator=(const Env&) = delete;
+
virtual ~Env();
// Return a default environment suitable for the current operating
@@ -40,20 +68,22 @@ class Env {
// The result of Default() belongs to leveldb and must never be deleted.
static Env* Default();
- // Create a brand new sequentially-readable file with the specified name.
+ // Create an object that sequentially reads the file with the specified name.
// On success, stores a pointer to the new file in *result and returns OK.
- // On failure stores NULL in *result and returns non-OK. If the file does
- // not exist, returns a non-OK status.
+ // On failure stores nullptr in *result and returns non-OK. If the file does
+ // not exist, returns a non-OK status. Implementations should return a
+ // NotFound status when the file does not exist.
//
// The returned file will only be accessed by one thread at a time.
virtual Status NewSequentialFile(const std::string& fname,
SequentialFile** result) = 0;
- // Create a brand new random access read-only file with the
+ // Create an object supporting random-access reads from the file with the
// specified name. On success, stores a pointer to the new file in
- // *result and returns OK. On failure stores NULL in *result and
+ // *result and returns OK. On failure stores nullptr in *result and
// returns non-OK. If the file does not exist, returns a non-OK
- // status.
+ // status. Implementations should return a NotFound status when the file does
+ // not exist.
//
// The returned file may be concurrently accessed by multiple threads.
virtual Status NewRandomAccessFile(const std::string& fname,
@@ -62,7 +92,7 @@ class Env {
// Create an object that writes to a new file with the specified
// name. Deletes any existing file with the same name and creates a
// new file. On success, stores a pointer to the new file in
- // *result and returns OK. On failure stores NULL in *result and
+ // *result and returns OK. On failure stores nullptr in *result and
// returns non-OK.
//
// The returned file will only be accessed by one thread at a time.
@@ -72,7 +102,7 @@ class Env {
// Create an object that either appends to an existing file, or
// writes to a new file (if the file does not exist to begin with).
// On success, stores a pointer to the new file in *result and
- // returns OK. On failure stores NULL in *result and returns
+ // returns OK. On failure stores nullptr in *result and returns
// non-OK.
//
// The returned file will only be accessed by one thread at a time.
@@ -110,7 +140,7 @@ class Env {
const std::string& target) = 0;
// Lock the specified file. Used to prevent concurrent access to
- // the same db by multiple processes. On failure, stores NULL in
+ // the same db by multiple processes. On failure, stores nullptr in
// *lock and returns non-OK.
//
// On success, stores a pointer to the object that represents the
@@ -136,16 +166,14 @@ class Env {
// added to the same Env may run concurrently in different threads.
// I.e., the caller may not assume that background work items are
// serialized.
- virtual void Schedule(
- void (*function)(void* arg),
- void* arg) = 0;
+ virtual void Schedule(void (*function)(void* arg), void* arg) = 0;
// Start a new thread, invoking "function(arg)" within the new thread.
// When "function(arg)" returns, the thread will be destroyed.
virtual void StartThread(void (*function)(void* arg), void* arg) = 0;
// *path is set to a temporary directory that can be used for testing. It may
- // or many not have just been created. The directory may or may not differ
+ // or may not have just been created. The directory may or may not differ
// between runs of the same process, but subsequent calls will return the
// same directory.
virtual Status GetTestDirectory(std::string* path) = 0;
@@ -159,17 +187,16 @@ class Env {
// Sleep/delay the thread for the prescribed number of micro-seconds.
virtual void SleepForMicroseconds(int micros) = 0;
-
- private:
- // No copying allowed
- Env(const Env&);
- void operator=(const Env&);
};
// A file abstraction for reading sequentially through a file
-class SequentialFile {
+class LEVELDB_EXPORT SequentialFile {
public:
- SequentialFile() { }
+ SequentialFile() = default;
+
+ SequentialFile(const SequentialFile&) = delete;
+ SequentialFile& operator=(const SequentialFile&) = delete;
+
virtual ~SequentialFile();
// Read up to "n" bytes from the file. "scratch[0..n-1]" may be
@@ -193,17 +220,16 @@ class SequentialFile {
// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
-
- private:
- // No copying allowed
- SequentialFile(const SequentialFile&);
- void operator=(const SequentialFile&);
};
// A file abstraction for randomly reading the contents of a file.
-class RandomAccessFile {
+class LEVELDB_EXPORT RandomAccessFile {
public:
- RandomAccessFile() { }
+ RandomAccessFile() = default;
+
+ RandomAccessFile(const RandomAccessFile&) = delete;
+ RandomAccessFile& operator=(const RandomAccessFile&) = delete;
+
virtual ~RandomAccessFile();
// Read up to "n" bytes from the file starting at "offset".
@@ -220,19 +246,18 @@ class RandomAccessFile {
// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
-
- private:
- // No copying allowed
- RandomAccessFile(const RandomAccessFile&);
- void operator=(const RandomAccessFile&);
};
// A file abstraction for sequential writing. The implementation
// must provide buffering since callers may append small fragments
// at a time to the file.
-class WritableFile {
+class LEVELDB_EXPORT WritableFile {
public:
- WritableFile() { }
+ WritableFile() = default;
+
+ WritableFile(const WritableFile&) = delete;
+ WritableFile& operator=(const WritableFile&) = delete;
+
virtual ~WritableFile();
virtual Status Append(const Slice& data) = 0;
@@ -242,119 +267,130 @@ class WritableFile {
// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
-
- private:
- // No copying allowed
- WritableFile(const WritableFile&);
- void operator=(const WritableFile&);
};
// An interface for writing log messages.
-class Logger {
+class LEVELDB_EXPORT Logger {
public:
- Logger() { }
+ Logger() = default;
+
+ Logger(const Logger&) = delete;
+ Logger& operator=(const Logger&) = delete;
+
virtual ~Logger();
// Write an entry to the log file with the specified format.
virtual void Logv(const char* format, va_list ap) = 0;
-
- private:
- // No copying allowed
- Logger(const Logger&);
- void operator=(const Logger&);
};
-
// Identifies a locked file.
-class FileLock {
+class LEVELDB_EXPORT FileLock {
public:
- FileLock() { }
+ FileLock() = default;
+
+ FileLock(const FileLock&) = delete;
+ FileLock& operator=(const FileLock&) = delete;
+
virtual ~FileLock();
- private:
- // No copying allowed
- FileLock(const FileLock&);
- void operator=(const FileLock&);
};
-// Log the specified data to *info_log if info_log is non-NULL.
-extern void Log(Logger* info_log, const char* format, ...)
-# if defined(__GNUC__) || defined(__clang__)
- __attribute__((__format__ (__printf__, 2, 3)))
-# endif
+// Log the specified data to *info_log if info_log is non-null.
+void Log(Logger* info_log, const char* format, ...)
+#if defined(__GNUC__) || defined(__clang__)
+ __attribute__((__format__(__printf__, 2, 3)))
+#endif
;
// A utility routine: write "data" to the named file.
-extern Status WriteStringToFile(Env* env, const Slice& data,
- const std::string& fname);
+LEVELDB_EXPORT Status WriteStringToFile(Env* env, const Slice& data,
+ const std::string& fname);
// A utility routine: read contents of named file into *data
-extern Status ReadFileToString(Env* env, const std::string& fname,
- std::string* data);
+LEVELDB_EXPORT Status ReadFileToString(Env* env, const std::string& fname,
+ std::string* data);
// An implementation of Env that forwards all calls to another Env.
// May be useful to clients who wish to override just part of the
// functionality of another Env.
-class EnvWrapper : public Env {
+class LEVELDB_EXPORT EnvWrapper : public Env {
public:
- // Initialize an EnvWrapper that delegates all calls to *t
- explicit EnvWrapper(Env* t) : target_(t) { }
+ // Initialize an EnvWrapper that delegates all calls to *t.
+ explicit EnvWrapper(Env* t) : target_(t) {}
virtual ~EnvWrapper();
- // Return the target to which this Env forwards all calls
+ // Return the target to which this Env forwards all calls.
Env* target() const { return target_; }
- // The following text is boilerplate that forwards all methods to target()
- Status NewSequentialFile(const std::string& f, SequentialFile** r) {
+ // The following text is boilerplate that forwards all methods to target().
+ Status NewSequentialFile(const std::string& f, SequentialFile** r) override {
return target_->NewSequentialFile(f, r);
}
- Status NewRandomAccessFile(const std::string& f, RandomAccessFile** r) {
+ Status NewRandomAccessFile(const std::string& f,
+ RandomAccessFile** r) override {
return target_->NewRandomAccessFile(f, r);
}
- Status NewWritableFile(const std::string& f, WritableFile** r) {
+ Status NewWritableFile(const std::string& f, WritableFile** r) override {
return target_->NewWritableFile(f, r);
}
- Status NewAppendableFile(const std::string& f, WritableFile** r) {
+ Status NewAppendableFile(const std::string& f, WritableFile** r) override {
return target_->NewAppendableFile(f, r);
}
- bool FileExists(const std::string& f) { return target_->FileExists(f); }
- Status GetChildren(const std::string& dir, std::vector<std::string>* r) {
+ bool FileExists(const std::string& f) override {
+ return target_->FileExists(f);
+ }
+ Status GetChildren(const std::string& dir,
+ std::vector<std::string>* r) override {
return target_->GetChildren(dir, r);
}
- Status DeleteFile(const std::string& f) { return target_->DeleteFile(f); }
- Status CreateDir(const std::string& d) { return target_->CreateDir(d); }
- Status DeleteDir(const std::string& d) { return target_->DeleteDir(d); }
- Status GetFileSize(const std::string& f, uint64_t* s) {
+ Status DeleteFile(const std::string& f) override {
+ return target_->DeleteFile(f);
+ }
+ Status CreateDir(const std::string& d) override {
+ return target_->CreateDir(d);
+ }
+ Status DeleteDir(const std::string& d) override {
+ return target_->DeleteDir(d);
+ }
+ Status GetFileSize(const std::string& f, uint64_t* s) override {
return target_->GetFileSize(f, s);
}
- Status RenameFile(const std::string& s, const std::string& t) {
+ Status RenameFile(const std::string& s, const std::string& t) override {
return target_->RenameFile(s, t);
}
- Status LockFile(const std::string& f, FileLock** l) {
+ Status LockFile(const std::string& f, FileLock** l) override {
return target_->LockFile(f, l);
}
- Status UnlockFile(FileLock* l) { return target_->UnlockFile(l); }
- void Schedule(void (*f)(void*), void* a) {
+ Status UnlockFile(FileLock* l) override { return target_->UnlockFile(l); }
+ void Schedule(void (*f)(void*), void* a) override {
return target_->Schedule(f, a);
}
- void StartThread(void (*f)(void*), void* a) {
+ void StartThread(void (*f)(void*), void* a) override {
return target_->StartThread(f, a);
}
- virtual Status GetTestDirectory(std::string* path) {
+ Status GetTestDirectory(std::string* path) override {
return target_->GetTestDirectory(path);
}
- virtual Status NewLogger(const std::string& fname, Logger** result) {
+ Status NewLogger(const std::string& fname, Logger** result) override {
return target_->NewLogger(fname, result);
}
- uint64_t NowMicros() {
- return target_->NowMicros();
- }
- void SleepForMicroseconds(int micros) {
+ uint64_t NowMicros() override { return target_->NowMicros(); }
+ void SleepForMicroseconds(int micros) override {
target_->SleepForMicroseconds(micros);
}
+
private:
Env* target_;
};
} // namespace leveldb
+// Redefine DeleteFile if necessary.
+#if defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED)
+#if defined(UNICODE)
+#define DeleteFile DeleteFileW
+#else
+#define DeleteFile DeleteFileA
+#endif // defined(UNICODE)
+#endif // defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED)
+
#endif // STORAGE_LEVELDB_INCLUDE_ENV_H_
diff --git a/include/leveldb/export.h b/include/leveldb/export.h
new file mode 100644
index 0000000000..6ba9b183da
--- /dev/null
+++ b/include/leveldb/export.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2017 The LevelDB Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file. See the AUTHORS file for names of contributors.
+
+#ifndef STORAGE_LEVELDB_INCLUDE_EXPORT_H_
+#define STORAGE_LEVELDB_INCLUDE_EXPORT_H_
+
+#if !defined(LEVELDB_EXPORT)
+
+#if defined(LEVELDB_SHARED_LIBRARY)
+#if defined(_WIN32)
+
+#if defined(LEVELDB_COMPILE_LIBRARY)
+#define LEVELDB_EXPORT __declspec(dllexport)
+#else
+#define LEVELDB_EXPORT __declspec(dllimport)
+#endif // defined(LEVELDB_COMPILE_LIBRARY)
+
+#else // defined(_WIN32)
+#if defined(LEVELDB_COMPILE_LIBRARY)
+#define LEVELDB_EXPORT __attribute__((visibility("default")))
+#else
+#define LEVELDB_EXPORT
+#endif
+#endif // defined(_WIN32)
+
+#else // defined(LEVELDB_SHARED_LIBRARY)
+#define LEVELDB_EXPORT
+#endif
+
+#endif // !defined(LEVELDB_EXPORT)
+
+#endif // STORAGE_LEVELDB_INCLUDE_EXPORT_H_
diff --git a/include/leveldb/filter_policy.h b/include/leveldb/filter_policy.h
index 1fba08001f..49c8eda776 100644
--- a/include/leveldb/filter_policy.h
+++ b/include/leveldb/filter_policy.h
@@ -18,11 +18,13 @@
#include <string>
+#include "leveldb/export.h"
+
namespace leveldb {
class Slice;
-class FilterPolicy {
+class LEVELDB_EXPORT FilterPolicy {
public:
virtual ~FilterPolicy();
@@ -38,8 +40,8 @@ class FilterPolicy {
//
// Warning: do not change the initial contents of *dst. Instead,
// append the newly constructed filter to *dst.
- virtual void CreateFilter(const Slice* keys, int n, std::string* dst)
- const = 0;
+ virtual void CreateFilter(const Slice* keys, int n,
+ std::string* dst) const = 0;
// "filter" contains the data appended by a preceding call to
// CreateFilter() on this class. This method must return true if
@@ -63,8 +65,8 @@ class FilterPolicy {
// ignores trailing spaces, it would be incorrect to use a
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys.
-extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
+LEVELDB_EXPORT const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
-}
+} // namespace leveldb
#endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
diff --git a/include/leveldb/iterator.h b/include/leveldb/iterator.h
index da631ed9d8..bb9a5df8f5 100644
--- a/include/leveldb/iterator.h
+++ b/include/leveldb/iterator.h
@@ -15,14 +15,19 @@
#ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
#define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
+#include "leveldb/export.h"
#include "leveldb/slice.h"
#include "leveldb/status.h"
namespace leveldb {
-class Iterator {
+class LEVELDB_EXPORT Iterator {
public:
Iterator();
+
+ Iterator(const Iterator&) = delete;
+ Iterator& operator=(const Iterator&) = delete;
+
virtual ~Iterator();
// An iterator is either positioned at a key/value pair, or
@@ -72,28 +77,35 @@ class Iterator {
//
// Note that unlike all of the preceding methods, this method is
// not abstract and therefore clients should not override it.
- typedef void (*CleanupFunction)(void* arg1, void* arg2);
+ using CleanupFunction = void (*)(void* arg1, void* arg2);
void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2);
private:
- struct Cleanup {
+ // Cleanup functions are stored in a single-linked list.
+ // The list's head node is inlined in the iterator.
+ struct CleanupNode {
+ // True if the node is not used. Only head nodes might be unused.
+ bool IsEmpty() const { return function == nullptr; }
+ // Invokes the cleanup function.
+ void Run() {
+ assert(function != nullptr);
+ (*function)(arg1, arg2);
+ }
+
+ // The head node is used if the function pointer is not null.
CleanupFunction function;
void* arg1;
void* arg2;
- Cleanup* next;
+ CleanupNode* next;
};
- Cleanup cleanup_;
-
- // No copying allowed
- Iterator(const Iterator&);
- void operator=(const Iterator&);
+ CleanupNode cleanup_head_;
};
// Return an empty iterator (yields nothing).
-extern Iterator* NewEmptyIterator();
+LEVELDB_EXPORT Iterator* NewEmptyIterator();
// Return an empty iterator with the specified status.
-extern Iterator* NewErrorIterator(const Status& status);
+LEVELDB_EXPORT Iterator* NewErrorIterator(const Status& status);
} // namespace leveldb
diff --git a/include/leveldb/options.h b/include/leveldb/options.h
index 976e38122a..b7487726bc 100644
--- a/include/leveldb/options.h
+++ b/include/leveldb/options.h
@@ -7,6 +7,8 @@
#include <stddef.h>
+#include "leveldb/export.h"
+
namespace leveldb {
class Cache;
@@ -23,12 +25,15 @@ class Snapshot;
enum CompressionType {
// NOTE: do not change the values of existing entries, as these are
// part of the persistent format on disk.
- kNoCompression = 0x0,
+ kNoCompression = 0x0,
kSnappyCompression = 0x1
};
// Options to control the behavior of a database (passed to DB::Open)
-struct Options {
+struct LEVELDB_EXPORT Options {
+ // Create an Options object with default values for all fields.
+ Options();
+
// -------------------
// Parameters that affect behavior
@@ -41,20 +46,17 @@ struct Options {
const Comparator* comparator;
// If true, the database will be created if it is missing.
- // Default: false
- bool create_if_missing;
+ bool create_if_missing = false;
// If true, an error is raised if the database already exists.
- // Default: false
- bool error_if_exists;
+ bool error_if_exists = false;
// If true, the implementation will do aggressive checking of the
// data it is processing and will stop early if it detects any
// errors. This may have unforeseen ramifications: for example, a
// corruption of one DB entry may cause a large number of entries to
// become unreadable or for the entire DB to become unopenable.
- // Default: false
- bool paranoid_checks;
+ bool paranoid_checks = false;
// Use the specified object to interact with the environment,
// e.g. to read/write files, schedule background work, etc.
@@ -62,10 +64,9 @@ struct Options {
Env* env;
// Any internal progress/error information generated by the db will
- // be written to info_log if it is non-NULL, or to a file stored
- // in the same directory as the DB contents if info_log is NULL.
- // Default: NULL
- Logger* info_log;
+ // be written to info_log if it is non-null, or to a file stored
+ // in the same directory as the DB contents if info_log is null.
+ Logger* info_log = nullptr;
// -------------------
// Parameters that affect performance
@@ -78,39 +79,30 @@ struct Options {
// so you may wish to adjust this parameter to control memory usage.
// Also, a larger write buffer will result in a longer recovery time
// the next time the database is opened.
- //
- // Default: 4MB
- size_t write_buffer_size;
+ size_t write_buffer_size = 4 * 1024 * 1024;
// Number of open files that can be used by the DB. You may need to
// increase this if your database has a large working set (budget
// one open file per 2MB of working set).
- //
- // Default: 1000
- int max_open_files;
+ int max_open_files = 1000;
// Control over blocks (user data is stored in a set of blocks, and
// a block is the unit of reading from disk).
- // If non-NULL, use the specified cache for blocks.
- // If NULL, leveldb will automatically create and use an 8MB internal cache.
- // Default: NULL
- Cache* block_cache;
+ // If non-null, use the specified cache for blocks.
+ // If null, leveldb will automatically create and use an 8MB internal cache.
+ Cache* block_cache = nullptr;
// Approximate size of user data packed per block. Note that the
// block size specified here corresponds to uncompressed data. The
// actual size of the unit read from disk may be smaller if
// compression is enabled. This parameter can be changed dynamically.
- //
- // Default: 4K
- size_t block_size;
+ size_t block_size = 4 * 1024;
// Number of keys between restart points for delta encoding of keys.
// This parameter can be changed dynamically. Most clients should
// leave this parameter alone.
- //
- // Default: 16
- int block_restart_interval;
+ int block_restart_interval = 16;
// Leveldb will write up to this amount of bytes to a file before
// switching to a new one.
@@ -120,9 +112,7 @@ struct Options {
// compactions and hence longer latency/performance hiccups.
// Another reason to increase this parameter might be when you are
// initially populating a large database.
- //
- // Default: 2MB
- size_t max_file_size;
+ size_t max_file_size = 2 * 1024 * 1024;
// Compress blocks using the specified compression algorithm. This
// parameter can be changed dynamically.
@@ -138,53 +128,43 @@ struct Options {
// worth switching to kNoCompression. Even if the input data is
// incompressible, the kSnappyCompression implementation will
// efficiently detect that and will switch to uncompressed mode.
- CompressionType compression;
+ CompressionType compression = kSnappyCompression;
// EXPERIMENTAL: If true, append to existing MANIFEST and log files
// when a database is opened. This can significantly speed up open.
//
// Default: currently false, but may become true later.
- bool reuse_logs;
+ bool reuse_logs = false;
- // If non-NULL, use the specified filter policy to reduce disk reads.
+ // If non-null, use the specified filter policy to reduce disk reads.
// Many applications will benefit from passing the result of
// NewBloomFilterPolicy() here.
- //
- // Default: NULL
- const FilterPolicy* filter_policy;
-
- // Create an Options object with default values for all fields.
- Options();
+ const FilterPolicy* filter_policy = nullptr;
};
// Options that control read operations
-struct ReadOptions {
+struct LEVELDB_EXPORT ReadOptions {
+ ReadOptions() = default;
+
// If true, all data read from underlying storage will be
// verified against corresponding checksums.
- // Default: false
- bool verify_checksums;
+ bool verify_checksums = false;
// Should the data read for this iteration be cached in memory?
// Callers may wish to set this field to false for bulk scans.
- // Default: true
- bool fill_cache;
+ bool fill_cache = true;
- // If "snapshot" is non-NULL, read as of the supplied snapshot
+ // If "snapshot" is non-null, read as of the supplied snapshot
// (which must belong to the DB that is being read and which must
- // not have been released). If "snapshot" is NULL, use an implicit
+ // not have been released). If "snapshot" is null, use an implicit
// snapshot of the state at the beginning of this read operation.
- // Default: NULL
- const Snapshot* snapshot;
-
- ReadOptions()
- : verify_checksums(false),
- fill_cache(true),
- snapshot(NULL) {
- }
+ const Snapshot* snapshot = nullptr;
};
// Options that control write operations
-struct WriteOptions {
+struct LEVELDB_EXPORT WriteOptions {
+ WriteOptions() = default;
+
// If true, the write will be flushed from the operating system
// buffer cache (by calling WritableFile::Sync()) before the write
// is considered complete. If this flag is true, writes will be
@@ -199,13 +179,7 @@ struct WriteOptions {
// crash semantics as the "write()" system call. A DB write
// with sync==true has similar crash semantics to a "write()"
// system call followed by "fsync()".
- //
- // Default: false
- bool sync;
-
- WriteOptions()
- : sync(false) {
- }
+ bool sync = false;
};
} // namespace leveldb
diff --git a/include/leveldb/slice.h b/include/leveldb/slice.h
index bc367986f7..2df417dc31 100644
--- a/include/leveldb/slice.h
+++ b/include/leveldb/slice.h
@@ -18,23 +18,30 @@
#include <assert.h>
#include <stddef.h>
#include <string.h>
+
#include <string>
+#include "leveldb/export.h"
+
namespace leveldb {
-class Slice {
+class LEVELDB_EXPORT Slice {
public:
// Create an empty slice.
- Slice() : data_(""), size_(0) { }
+ Slice() : data_(""), size_(0) {}
// Create a slice that refers to d[0,n-1].
- Slice(const char* d, size_t n) : data_(d), size_(n) { }
+ Slice(const char* d, size_t n) : data_(d), size_(n) {}
// Create a slice that refers to the contents of "s"
- Slice(const std::string& s) : data_(s.data()), size_(s.size()) { }
+ Slice(const std::string& s) : data_(s.data()), size_(s.size()) {}
// Create a slice that refers to s[0,strlen(s)-1]
- Slice(const char* s) : data_(s), size_(strlen(s)) { }
+ Slice(const char* s) : data_(s), size_(strlen(s)) {}
+
+ // Intentionally copyable.
+ Slice(const Slice&) = default;
+ Slice& operator=(const Slice&) = default;
// Return a pointer to the beginning of the referenced data
const char* data() const { return data_; }
@@ -53,7 +60,10 @@ class Slice {
}
// Change this slice to refer to an empty array
- void clear() { data_ = ""; size_ = 0; }
+ void clear() {
+ data_ = "";
+ size_ = 0;
+ }
// Drop the first "n" bytes from this slice.
void remove_prefix(size_t n) {
@@ -73,15 +83,12 @@ class Slice {
// Return true iff "x" is a prefix of "*this"
bool starts_with(const Slice& x) const {
- return ((size_ >= x.size_) &&
- (memcmp(data_, x.data_, x.size_) == 0));
+ return ((size_ >= x.size_) && (memcmp(data_, x.data_, x.size_) == 0));
}
private:
const char* data_;
size_t size_;
-
- // Intentionally copyable
};
inline bool operator==(const Slice& x, const Slice& y) {
@@ -89,21 +96,20 @@ inline bool operator==(const Slice& x, const Slice& y) {
(memcmp(x.data(), y.data(), x.size()) == 0));
}
-inline bool operator!=(const Slice& x, const Slice& y) {
- return !(x == y);
-}
+inline bool operator!=(const Slice& x, const Slice& y) { return !(x == y); }
inline int Slice::compare(const Slice& b) const {
const size_t min_len = (size_ < b.size_) ? size_ : b.size_;
int r = memcmp(data_, b.data_, min_len);
if (r == 0) {
- if (size_ < b.size_) r = -1;
- else if (size_ > b.size_) r = +1;
+ if (size_ < b.size_)
+ r = -1;
+ else if (size_ > b.size_)
+ r = +1;
}
return r;
}
} // namespace leveldb
-
#endif // STORAGE_LEVELDB_INCLUDE_SLICE_H_
diff --git a/include/leveldb/status.h b/include/leveldb/status.h
index d9575f9753..e3273144e4 100644
--- a/include/leveldb/status.h
+++ b/include/leveldb/status.h
@@ -13,20 +13,25 @@
#ifndef STORAGE_LEVELDB_INCLUDE_STATUS_H_
#define STORAGE_LEVELDB_INCLUDE_STATUS_H_
+#include <algorithm>
#include <string>
+
+#include "leveldb/export.h"
#include "leveldb/slice.h"
namespace leveldb {
-class Status {
+class LEVELDB_EXPORT Status {
public:
// Create a success status.
- Status() : state_(NULL) { }
+ Status() noexcept : state_(nullptr) {}
~Status() { delete[] state_; }
- // Copy the specified status.
- Status(const Status& s);
- void operator=(const Status& s);
+ Status(const Status& rhs);
+ Status& operator=(const Status& rhs);
+
+ Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
+ Status& operator=(Status&& rhs) noexcept;
// Return a success status.
static Status OK() { return Status(); }
@@ -49,7 +54,7 @@ class Status {
}
// Returns true iff the status indicates success.
- bool ok() const { return (state_ == NULL); }
+ bool ok() const { return (state_ == nullptr); }
// Returns true iff the status indicates a NotFound error.
bool IsNotFound() const { return code() == kNotFound; }
@@ -71,13 +76,6 @@ class Status {
std::string ToString() const;
private:
- // OK status has a NULL state_. Otherwise, state_ is a new[] array
- // of the following form:
- // state_[0..3] == length of message
- // state_[4] == code
- // state_[5..] == message
- const char* state_;
-
enum Code {
kOk = 0,
kNotFound = 1,
@@ -88,23 +86,35 @@ class Status {
};
Code code() const {
- return (state_ == NULL) ? kOk : static_cast<Code>(state_[4]);
+ return (state_ == nullptr) ? kOk : static_cast<Code>(state_[4]);
}
Status(Code code, const Slice& msg, const Slice& msg2);
static const char* CopyState(const char* s);
+
+ // OK status has a null state_. Otherwise, state_ is a new[] array
+ // of the following form:
+ // state_[0..3] == length of message
+ // state_[4] == code
+ // state_[5..] == message
+ const char* state_;
};
-inline Status::Status(const Status& s) {
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
+inline Status::Status(const Status& rhs) {
+ state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_);
}
-inline void Status::operator=(const Status& s) {
- // The following condition catches both aliasing (when this == &s),
- // and the common case where both s and *this are ok.
- if (state_ != s.state_) {
+inline Status& Status::operator=(const Status& rhs) {
+ // The following condition catches both aliasing (when this == &rhs),
+ // and the common case where both rhs and *this are ok.
+ if (state_ != rhs.state_) {
delete[] state_;
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
+ state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_);
}
+ return *this;
+}
+inline Status& Status::operator=(Status&& rhs) noexcept {
+ std::swap(state_, rhs.state_);
+ return *this;
}
} // namespace leveldb
diff --git a/include/leveldb/table.h b/include/leveldb/table.h
index a9746c3f5e..25c6013116 100644
--- a/include/leveldb/table.h
+++ b/include/leveldb/table.h
@@ -6,6 +6,8 @@
#define STORAGE_LEVELDB_INCLUDE_TABLE_H_
#include <stdint.h>
+
+#include "leveldb/export.h"
#include "leveldb/iterator.h"
namespace leveldb {
@@ -21,7 +23,7 @@ class TableCache;
// A Table is a sorted map from strings to strings. Tables are
// immutable and persistent. A Table may be safely accessed from
// multiple threads without external synchronization.
-class Table {
+class LEVELDB_EXPORT Table {
public:
// Attempt to open the table that is stored in bytes [0..file_size)
// of "file", and read the metadata entries necessary to allow
@@ -30,15 +32,16 @@ class Table {
// If successful, returns ok and sets "*table" to the newly opened
// table. The client should delete "*table" when no longer needed.
// If there was an error while initializing the table, sets "*table"
- // to NULL and returns a non-ok status. Does not take ownership of
+ // to nullptr and returns a non-ok status. Does not take ownership of
// "*source", but the client must ensure that "source" remains live
// for the duration of the returned table's lifetime.
//
// *file must remain live while this Table is in use.
- static Status Open(const Options& options,
- RandomAccessFile* file,
- uint64_t file_size,
- Table** table);
+ static Status Open(const Options& options, RandomAccessFile* file,
+ uint64_t file_size, Table** table);
+
+ Table(const Table&) = delete;
+ Table& operator=(const Table&) = delete;
~Table();
@@ -56,28 +59,24 @@ class Table {
uint64_t ApproximateOffsetOf(const Slice& key) const;
private:
+ friend class TableCache;
struct Rep;
- Rep* rep_;
- explicit Table(Rep* rep) { rep_ = rep; }
static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
+ explicit Table(Rep* rep) : rep_(rep) {}
+
// Calls (*handle_result)(arg, ...) with the entry found after a call
// to Seek(key). May not make such a call if filter policy says
// that key is not present.
- friend class TableCache;
- Status InternalGet(
- const ReadOptions&, const Slice& key,
- void* arg,
- void (*handle_result)(void* arg, const Slice& k, const Slice& v));
-
+ Status InternalGet(const ReadOptions&, const Slice& key, void* arg,
+ void (*handle_result)(void* arg, const Slice& k,
+ const Slice& v));
void ReadMeta(const Footer& footer);
void ReadFilter(const Slice& filter_handle_value);
- // No copying allowed
- Table(const Table&);
- void operator=(const Table&);
+ Rep* const rep_;
};
} // namespace leveldb
diff --git a/include/leveldb/table_builder.h b/include/leveldb/table_builder.h
index 5fd1dc71f1..7d8896bb89 100644
--- a/include/leveldb/table_builder.h
+++ b/include/leveldb/table_builder.h
@@ -14,6 +14,8 @@
#define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
#include <stdint.h>
+
+#include "leveldb/export.h"
#include "leveldb/options.h"
#include "leveldb/status.h"
@@ -23,13 +25,16 @@ class BlockBuilder;
class BlockHandle;
class WritableFile;
-class TableBuilder {
+class LEVELDB_EXPORT TableBuilder {
public:
// Create a builder that will store the contents of the table it is
// building in *file. Does not close the file. It is up to the
// caller to close the file after calling Finish().
TableBuilder(const Options& options, WritableFile* file);
+ TableBuilder(const TableBuilder&) = delete;
+ TableBuilder& operator=(const TableBuilder&) = delete;
+
// REQUIRES: Either Finish() or Abandon() has been called.
~TableBuilder();
@@ -81,10 +86,6 @@ class TableBuilder {
struct Rep;
Rep* rep_;
-
- // No copying allowed
- TableBuilder(const TableBuilder&);
- void operator=(const TableBuilder&);
};
} // namespace leveldb
diff --git a/include/leveldb/write_batch.h b/include/leveldb/write_batch.h
index ee9aab68e0..94d4115fed 100644
--- a/include/leveldb/write_batch.h
+++ b/include/leveldb/write_batch.h
@@ -22,15 +22,29 @@
#define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
#include <string>
+
+#include "leveldb/export.h"
#include "leveldb/status.h"
namespace leveldb {
class Slice;
-class WriteBatch {
+class LEVELDB_EXPORT WriteBatch {
public:
+ class LEVELDB_EXPORT Handler {
+ public:
+ virtual ~Handler();
+ virtual void Put(const Slice& key, const Slice& value) = 0;
+ virtual void Delete(const Slice& key) = 0;
+ };
+
WriteBatch();
+
+ // Intentionally copyable.
+ WriteBatch(const WriteBatch&) = default;
+ WriteBatch& operator=(const WriteBatch&) = default;
+
~WriteBatch();
// Store the mapping "key->value" in the database.
@@ -42,21 +56,26 @@ class WriteBatch {
// Clear all updates buffered in this batch.
void Clear();
+ // The size of the database changes caused by this batch.
+ //
+ // This number is tied to implementation details, and may change across
+ // releases. It is intended for LevelDB usage metrics.
+ size_t ApproximateSize() const;
+
+ // Copies the operations in "source" to this batch.
+ //
+ // This runs in O(source size) time. However, the constant factor is better
+ // than calling Iterate() over the source batch with a Handler that replicates
+ // the operations into this batch.
+ void Append(const WriteBatch& source);
+
// Support for iterating over the contents of a batch.
- class Handler {
- public:
- virtual ~Handler();
- virtual void Put(const Slice& key, const Slice& value) = 0;
- virtual void Delete(const Slice& key) = 0;
- };
Status Iterate(Handler* handler) const;
private:
friend class WriteBatchInternal;
std::string rep_; // See comment in write_batch.cc for the format of rep_
-
- // Intentionally copyable
};
} // namespace leveldb