├── .arcconfig ├── .clang-format ├── .gitignore ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── CONTRIBUTING.md ├── DUMP_FORMAT.md ├── HISTORY.md ├── INSTALL.md ├── LICENSE ├── Makefile ├── PATENTS ├── README.md ├── ROCKSDB_LITE.md ├── USERS.md ├── Vagrantfile ├── WINDOWS_PORT.md ├── appveyor.yml ├── appveyordailytests.yml ├── arcanist_util ├── __phutil_library_init__.php ├── __phutil_library_map__.php ├── config │ └── FacebookArcanistConfiguration.php ├── cpp_linter │ ├── ArcanistCpplintLinter.php │ ├── BaseDirectoryScopedFormatLinter.php │ ├── FacebookHowtoevenLinter.php │ ├── FbcodeClangFormatLinter.php │ ├── FbcodeCppLinter.php │ └── cpplint.py ├── lint_engine │ ├── FacebookFbcodeLintEngine.php │ └── FacebookHowtoevenLintEngine.php └── unit_engine │ └── FacebookFbcodeUnitTestEngine.php ├── benchmark.sh ├── benchmark_nvm.sh ├── build_tools ├── amalgamate.py ├── build_detect_platform ├── dockerbuild.sh ├── fb_compile_mongo.sh ├── fbcode_config.sh ├── fbcode_config4.8.1.sh ├── format-diff.sh ├── make_new_version.sh ├── make_package.sh ├── regression_build_test.sh ├── rocksdb-lego-determinator ├── run_ci_db_test.ps1 └── version.sh ├── copy_to_vm.sh ├── coverage ├── coverage_test.sh └── parse_gcov_output.py ├── create_test.sh ├── db ├── builder.cc ├── builder.h ├── c.cc ├── c_test.c ├── column_family.cc ├── column_family.h ├── column_family_test.cc ├── compact_files_test.cc ├── compacted_db_impl.cc ├── compacted_db_impl.h ├── compaction.cc ├── compaction.h ├── compaction_iterator.cc ├── compaction_iterator.h ├── compaction_iterator_test.cc ├── compaction_job.cc ├── compaction_job.h ├── compaction_job_stats_test.cc ├── compaction_job_test.cc ├── compaction_picker.cc ├── compaction_picker.h ├── compaction_picker_test.cc ├── comparator_db_test.cc ├── convenience.cc ├── corruption_test.cc ├── cuckoo_table_db_test.cc ├── db_bench.cc ├── db_compaction_filter_test.cc ├── db_compaction_test.cc ├── db_dynamic_level_test.cc ├── db_filesnapshot.cc ├── db_impl.cc ├── db_impl.h ├── db_impl_debug.cc ├── db_impl_experimental.cc ├── db_impl_readonly.cc ├── db_impl_readonly.h ├── db_inplace_update_test.cc ├── db_iter.cc ├── db_iter.h ├── db_iter_test.cc ├── db_log_iter_test.cc ├── db_tailing_iter_test.cc ├── db_test.cc ├── db_test_util.cc ├── db_test_util.h ├── db_universal_compaction_test.cc ├── db_wal_test.cc ├── dbformat.cc ├── dbformat.h ├── dbformat_test.cc ├── deletefile_test.cc ├── event_helpers.cc ├── event_helpers.h ├── experimental.cc ├── fault_injection_test.cc ├── file_indexer.cc ├── file_indexer.h ├── file_indexer_test.cc ├── filename.cc ├── filename.h ├── filename_test.cc ├── flush_job.cc ├── flush_job.h ├── flush_job_test.cc ├── flush_scheduler.cc ├── flush_scheduler.h ├── forward_iterator.cc ├── forward_iterator.h ├── internal_stats.cc ├── internal_stats.h ├── job_context.h ├── listener_test.cc ├── log_format.h ├── log_reader.cc ├── log_reader.h ├── log_test.cc ├── log_writer.cc ├── log_writer.h ├── managed_iterator.cc ├── managed_iterator.h ├── memtable.cc ├── memtable.h ├── memtable_allocator.cc ├── memtable_allocator.h ├── memtable_list.cc ├── memtable_list.h ├── memtable_list_test.cc ├── memtablerep_bench.cc ├── merge_context.h ├── merge_helper.cc ├── merge_helper.h ├── merge_helper_test.cc ├── merge_operator.cc ├── merge_test.cc ├── nvm_bench.cc ├── perf_context_test.cc ├── plain_table_db_test.cc ├── prefix_test.cc ├── repair.cc ├── skiplist.h ├── skiplist_test.cc ├── slice.cc ├── snapshot_impl.cc ├── snapshot_impl.h ├── table_cache.cc ├── table_cache.h ├── table_properties_collector.cc ├── table_properties_collector.h ├── table_properties_collector_test.cc ├── transaction_log_impl.cc ├── transaction_log_impl.h ├── version_builder.cc ├── version_builder.h ├── version_builder_test.cc ├── version_edit.cc ├── version_edit.h ├── version_edit_test.cc ├── version_set.cc ├── version_set.h ├── version_set_test.cc ├── wal_manager.cc ├── wal_manager.h ├── wal_manager_test.cc ├── write_batch.cc ├── write_batch_base.cc ├── write_batch_internal.h ├── write_batch_test.cc ├── write_callback.h ├── write_callback_test.cc ├── write_controller.cc ├── write_controller.h ├── write_controller_test.cc ├── write_thread.cc ├── write_thread.h └── writebuffer.h ├── doc ├── doc.css ├── index.html ├── log_format.txt ├── rockslogo.jpg └── rockslogo.png ├── examples ├── .gitignore ├── Makefile ├── README.md ├── c_simple_example.c ├── column_families_example.cc ├── compact_files_example.cc ├── compaction_filter_example.cc ├── nvm_example.cc ├── optimistic_transaction_example.cc ├── rocksdb_option_file_example.ini ├── simple_example.cc └── transaction_example.cc ├── hdfs ├── README ├── env_hdfs.h └── setup.sh ├── include ├── nvm │ ├── nvm.h │ ├── nvm_compile_flags.h │ ├── nvm_debug.h │ ├── nvm_directory.h │ ├── nvm_files.h │ ├── nvm_ioctl.h │ ├── nvm_mem.h │ ├── nvm_threading.h │ └── nvm_typedefs.h └── rocksdb │ ├── c.h │ ├── cache.h │ ├── compaction_filter.h │ ├── compaction_job_stats.h │ ├── comparator.h │ ├── convenience.h │ ├── db.h │ ├── db_dump_tool.h │ ├── delete_scheduler.h │ ├── env.h │ ├── experimental.h │ ├── filter_policy.h │ ├── flush_block_policy.h │ ├── immutable_options.h │ ├── iostats_context.h │ ├── iterator.h │ ├── ldb_tool.h │ ├── listener.h │ ├── memtablerep.h │ ├── merge_operator.h │ ├── metadata.h │ ├── options.h │ ├── perf_context.h │ ├── perf_level.h │ ├── rate_limiter.h │ ├── slice.h │ ├── slice_transform.h │ ├── snapshot.h │ ├── sst_dump_tool.h │ ├── sst_file_writer.h │ ├── statistics.h │ ├── status.h │ ├── table.h │ ├── table_properties.h │ ├── thread_status.h │ ├── transaction_log.h │ ├── types.h │ ├── universal_compaction.h │ ├── utilities │ ├── backupable_db.h │ ├── checkpoint.h │ ├── convenience.h │ ├── db_ttl.h │ ├── document_db.h │ ├── flashcache.h │ ├── geo_db.h │ ├── info_log_finder.h │ ├── json_document.h │ ├── leveldb_options.h │ ├── optimistic_transaction_db.h │ ├── spatial_db.h │ ├── stackable_db.h │ ├── table_properties_collectors.h │ ├── transaction.h │ ├── transaction_db.h │ ├── transaction_db_mutex.h │ ├── utility_db.h │ └── write_batch_with_index.h │ ├── version.h │ ├── write_batch.h │ └── write_batch_base.h ├── java ├── HISTORY-JAVA.md ├── Makefile ├── RELEASE.md ├── benchmark │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── rocksdb │ │ └── benchmark │ │ └── DbBenchmark.java ├── crossbuild │ ├── Vagrantfile │ ├── build-linux-centos.sh │ └── build-linux.sh ├── jdb_bench.sh ├── rocksjni.pom ├── rocksjni │ ├── backupablejni.cc │ ├── backupenginejni.cc │ ├── checkpoint.cc │ ├── columnfamilyhandle.cc │ ├── compaction_filter.cc │ ├── comparator.cc │ ├── comparatorjnicallback.cc │ ├── comparatorjnicallback.h │ ├── env.cc │ ├── filter.cc │ ├── iterator.cc │ ├── loggerjnicallback.cc │ ├── loggerjnicallback.h │ ├── memtablejni.cc │ ├── merge_operator.cc │ ├── options.cc │ ├── portal.h │ ├── ratelimiterjni.cc │ ├── remove_emptyvalue_compactionfilterjni.cc │ ├── restorejni.cc │ ├── rocksjni.cc │ ├── slice.cc │ ├── snapshot.cc │ ├── statistics.cc │ ├── table.cc │ ├── transaction_log.cc │ ├── ttl.cc │ ├── write_batch.cc │ ├── write_batch_test.cc │ ├── write_batch_with_index.cc │ ├── writebatchhandlerjnicallback.cc │ └── writebatchhandlerjnicallback.h ├── samples │ └── src │ │ └── main │ │ └── java │ │ ├── RocksDBColumnFamilySample.java │ │ └── RocksDBSample.java └── src │ ├── main │ └── java │ │ └── org │ │ └── rocksdb │ │ ├── AbstractCompactionFilter.java │ │ ├── AbstractComparator.java │ │ ├── AbstractRocksIterator.java │ │ ├── AbstractSlice.java │ │ ├── AbstractWriteBatch.java │ │ ├── BackupEngine.java │ │ ├── BackupInfo.java │ │ ├── BackupableDB.java │ │ ├── BackupableDBOptions.java │ │ ├── BlockBasedTableConfig.java │ │ ├── BloomFilter.java │ │ ├── BuiltinComparator.java │ │ ├── Checkpoint.java │ │ ├── ChecksumType.java │ │ ├── ColumnFamilyDescriptor.java │ │ ├── ColumnFamilyHandle.java │ │ ├── ColumnFamilyOptions.java │ │ ├── ColumnFamilyOptionsInterface.java │ │ ├── CompactionStyle.java │ │ ├── Comparator.java │ │ ├── ComparatorOptions.java │ │ ├── CompressionType.java │ │ ├── DBOptions.java │ │ ├── DBOptionsInterface.java │ │ ├── DirectComparator.java │ │ ├── DirectSlice.java │ │ ├── EncodingType.java │ │ ├── Env.java │ │ ├── Filter.java │ │ ├── FlushOptions.java │ │ ├── GenericRateLimiterConfig.java │ │ ├── HashLinkedListMemTableConfig.java │ │ ├── HashSkipListMemTableConfig.java │ │ ├── HistogramData.java │ │ ├── HistogramType.java │ │ ├── IndexType.java │ │ ├── InfoLogLevel.java │ │ ├── Logger.java │ │ ├── MemTableConfig.java │ │ ├── MergeOperator.java │ │ ├── NativeLibraryLoader.java │ │ ├── Options.java │ │ ├── PlainTableConfig.java │ │ ├── RateLimiterConfig.java │ │ ├── ReadOptions.java │ │ ├── RemoveEmptyValueCompactionFilter.java │ │ ├── RestoreBackupableDB.java │ │ ├── RestoreOptions.java │ │ ├── RocksDB.java │ │ ├── RocksDBException.java │ │ ├── RocksEnv.java │ │ ├── RocksIterator.java │ │ ├── RocksIteratorInterface.java │ │ ├── RocksMemEnv.java │ │ ├── RocksObject.java │ │ ├── SkipListMemTableConfig.java │ │ ├── Slice.java │ │ ├── Snapshot.java │ │ ├── Statistics.java │ │ ├── StatisticsCollector.java │ │ ├── StatisticsCollectorCallback.java │ │ ├── StatsCollectorInput.java │ │ ├── StringAppendOperator.java │ │ ├── TableFormatConfig.java │ │ ├── TickerType.java │ │ ├── TransactionLogIterator.java │ │ ├── TtlDB.java │ │ ├── VectorMemTableConfig.java │ │ ├── WBWIRocksIterator.java │ │ ├── WriteBatch.java │ │ ├── WriteBatchInterface.java │ │ ├── WriteBatchWithIndex.java │ │ ├── WriteOptions.java │ │ └── util │ │ ├── Environment.java │ │ └── SizeUnit.java │ └── test │ └── java │ └── org │ └── rocksdb │ ├── AbstractComparatorTest.java │ ├── BackupEngineTest.java │ ├── BackupableDBOptionsTest.java │ ├── BackupableDBTest.java │ ├── BlockBasedTableConfigTest.java │ ├── CheckPointTest.java │ ├── ColumnFamilyOptionsTest.java │ ├── ColumnFamilyTest.java │ ├── ComparatorOptionsTest.java │ ├── ComparatorTest.java │ ├── CompressionOptionsTest.java │ ├── DBOptionsTest.java │ ├── DirectComparatorTest.java │ ├── DirectSliceTest.java │ ├── FilterTest.java │ ├── FlushTest.java │ ├── InfoLogLevelTest.java │ ├── KeyMayExistTest.java │ ├── LoggerTest.java │ ├── MemTableTest.java │ ├── MergeTest.java │ ├── MixedOptionsTest.java │ ├── NativeLibraryLoaderTest.java │ ├── OptionsTest.java │ ├── PlainTableConfigTest.java │ ├── PlatformRandomHelper.java │ ├── ReadOnlyTest.java │ ├── ReadOptionsTest.java │ ├── RocksDBTest.java │ ├── RocksEnvTest.java │ ├── RocksIteratorTest.java │ ├── RocksMemEnvTest.java │ ├── RocksMemoryResource.java │ ├── SliceTest.java │ ├── SnapshotTest.java │ ├── StatisticsCollectorTest.java │ ├── StatsCallbackMock.java │ ├── TransactionLogIteratorTest.java │ ├── TtlDBTest.java │ ├── Types.java │ ├── WriteBatchHandlerTest.java │ ├── WriteBatchTest.java │ ├── WriteBatchWithIndexTest.java │ ├── WriteOptionsTest.java │ ├── test │ └── RocksJunitRunner.java │ └── util │ ├── EnvironmentTest.java │ └── SizeUnitTest.java ├── port ├── README ├── dirent.h ├── likely.h ├── port.h ├── port_example.h ├── port_nvm.cc ├── port_nvm.h ├── port_posix.cc ├── port_posix.h ├── stack_trace.cc ├── stack_trace.h ├── sys_time.h ├── util_logger.h └── win │ ├── env_win.cc │ ├── port_win.cc │ ├── port_win.h │ ├── win_logger.cc │ └── win_logger.h ├── src.mk ├── table ├── adaptive_table_factory.cc ├── adaptive_table_factory.h ├── block.cc ├── block.h ├── block_based_filter_block.cc ├── block_based_filter_block.h ├── block_based_filter_block_test.cc ├── block_based_table_builder.cc ├── block_based_table_builder.h ├── block_based_table_factory.cc ├── block_based_table_factory.h ├── block_based_table_reader.cc ├── block_based_table_reader.h ├── block_builder.cc ├── block_builder.h ├── block_hash_index.cc ├── block_hash_index.h ├── block_hash_index_test.cc ├── block_prefix_index.cc ├── block_prefix_index.h ├── block_test.cc ├── bloom_block.cc ├── bloom_block.h ├── cuckoo_table_builder.cc ├── cuckoo_table_builder.h ├── cuckoo_table_builder_test.cc ├── cuckoo_table_factory.cc ├── cuckoo_table_factory.h ├── cuckoo_table_reader.cc ├── cuckoo_table_reader.h ├── cuckoo_table_reader_test.cc ├── filter_block.h ├── flush_block_policy.cc ├── format.cc ├── format.h ├── full_filter_block.cc ├── full_filter_block.h ├── full_filter_block_test.cc ├── get_context.cc ├── get_context.h ├── internal_iterator.h ├── iter_heap.h ├── iterator.cc ├── iterator_wrapper.h ├── merger.cc ├── merger.h ├── merger_test.cc ├── meta_blocks.cc ├── meta_blocks.h ├── mock_table.cc ├── mock_table.h ├── plain_table_builder.cc ├── plain_table_builder.h ├── plain_table_factory.cc ├── plain_table_factory.h ├── plain_table_index.cc ├── plain_table_index.h ├── plain_table_key_coding.cc ├── plain_table_key_coding.h ├── plain_table_reader.cc ├── plain_table_reader.h ├── scoped_arena_iterator.h ├── sst_file_writer.cc ├── table_builder.h ├── table_properties.cc ├── table_properties_internal.h ├── table_reader.h ├── table_reader_bench.cc ├── table_test.cc ├── two_level_iterator.cc └── two_level_iterator.h ├── third-party ├── fbson │ ├── COMMIT.md │ ├── FbsonDocument.h │ ├── FbsonJsonParser.h │ ├── FbsonStream.h │ ├── FbsonUtil.h │ └── FbsonWriter.h ├── flashcache │ └── flashcache_ioctl.h └── gtest-1.7.0 │ └── fused-src │ └── gtest │ ├── CMakeLists.txt │ ├── gtest-all.cc │ └── gtest.h ├── thirdparty.inc ├── tools ├── Dockerfile ├── auto_sanity_test.sh ├── benchmark.sh ├── benchmark_leveldb.sh ├── check_format_compatible.sh ├── db_crash_test.cc ├── db_crashtest.py ├── db_crashtest2.py ├── db_durability.cc ├── db_repl_stress.cc ├── db_sanity_test.cc ├── db_stress.cc ├── dbench_monitor ├── dump │ ├── db_dump_tool.cc │ ├── rocksdb_dump.cc │ └── rocksdb_undump.cc ├── generate_random_db.sh ├── ldb.cc ├── ldb_test.py ├── pflag ├── rdb │ ├── .gitignore │ ├── API.md │ ├── README.md │ ├── binding.gyp │ ├── db_wrapper.cc │ ├── db_wrapper.h │ ├── rdb │ ├── rdb.cc │ └── unit_test.js ├── reduce_levels_test.cc ├── rocksdb_dump_test.sh ├── run_flash_bench.sh ├── run_leveldb.sh ├── sample-dump.dmp ├── sst_dump.cc └── verify_random_db.sh ├── unit_tests ├── nvm_file_manager_test.cc ├── nvm_ftl_save_test.cc ├── nvm_random_access_file_test.cc ├── nvm_rw_tests.cc ├── nvm_sequential_file_test.cc └── nvm_write_test.cc ├── util ├── aligned_buffer.h ├── allocator.h ├── arena.cc ├── arena.h ├── arena_test.cc ├── auto_roll_logger.cc ├── auto_roll_logger.h ├── auto_roll_logger_test.cc ├── autovector.h ├── autovector_test.cc ├── bloom.cc ├── bloom_test.cc ├── build_version.h ├── cache.cc ├── cache_bench.cc ├── cache_test.cc ├── channel.h ├── coding.cc ├── coding.h ├── coding_test.cc ├── compaction_job_stats_impl.cc ├── comparator.cc ├── compression.h ├── crc32c.cc ├── crc32c.h ├── crc32c_test.cc ├── db_info_dumper.cc ├── db_info_dumper.h ├── delete_scheduler_impl.cc ├── delete_scheduler_impl.h ├── delete_scheduler_test.cc ├── dynamic_bloom.cc ├── dynamic_bloom.h ├── dynamic_bloom_test.cc ├── env.cc ├── env_hdfs.cc ├── env_nvm.cc ├── env_posix.cc ├── env_test.cc ├── event_logger.cc ├── event_logger.h ├── event_logger_test.cc ├── file_reader_writer.cc ├── file_reader_writer.h ├── file_reader_writer_test.cc ├── file_util.cc ├── file_util.h ├── filelock_test.cc ├── filter_policy.cc ├── hash.cc ├── hash.h ├── hash_cuckoo_rep.cc ├── hash_cuckoo_rep.h ├── hash_linklist_rep.cc ├── hash_linklist_rep.h ├── hash_skiplist_rep.cc ├── hash_skiplist_rep.h ├── heap.h ├── heap_test.cc ├── histogram.cc ├── histogram.h ├── histogram_test.cc ├── instrumented_mutex.cc ├── instrumented_mutex.h ├── iostats_context.cc ├── iostats_context_imp.h ├── ldb_cmd.cc ├── ldb_cmd.h ├── ldb_cmd_execute_result.h ├── ldb_cmd_test.cc ├── ldb_tool.cc ├── log_buffer.cc ├── log_buffer.h ├── log_write_bench.cc ├── logger.h ├── logging.cc ├── logging.h ├── manual_compaction_test.cc ├── memenv.cc ├── memenv_test.cc ├── mock_env.cc ├── mock_env.h ├── mock_env_test.cc ├── murmurhash.cc ├── murmurhash.h ├── mutable_cf_options.cc ├── mutable_cf_options.h ├── mutexlock.h ├── nvm.cc ├── nvm_directory.cc ├── nvm_files.cc ├── nvm_logger.h ├── nvm_threading.cc ├── options.cc ├── options_builder.cc ├── options_helper.cc ├── options_helper.h ├── options_parser.cc ├── options_parser.h ├── options_test.cc ├── perf_context.cc ├── perf_context_imp.h ├── perf_level.cc ├── perf_level_imp.h ├── perf_step_timer.h ├── posix_logger.h ├── random.h ├── rate_limiter.cc ├── rate_limiter.h ├── rate_limiter_test.cc ├── skiplistrep.cc ├── slice.cc ├── slice_transform_test.cc ├── sst_dump_test.cc ├── sst_dump_tool.cc ├── sst_dump_tool_imp.h ├── statistics.cc ├── statistics.h ├── status.cc ├── status_message.cc ├── stl_wrappers.h ├── stop_watch.h ├── string_util.cc ├── string_util.h ├── sync_point.cc ├── sync_point.h ├── testharness.cc ├── testharness.h ├── testutil.cc ├── testutil.h ├── thread_list_test.cc ├── thread_local.cc ├── thread_local.h ├── thread_local_test.cc ├── thread_operation.h ├── thread_status_impl.cc ├── thread_status_updater.cc ├── thread_status_updater.h ├── thread_status_updater_debug.cc ├── thread_status_util.cc ├── thread_status_util.h ├── thread_status_util_debug.cc ├── vectorrep.cc ├── xfunc.cc ├── xfunc.h ├── xxhash.cc └── xxhash.h └── utilities ├── backupable ├── backupable_db.cc └── backupable_db_test.cc ├── checkpoint ├── checkpoint.cc └── checkpoint_test.cc ├── compaction_filters ├── remove_emptyvalue_compactionfilter.cc └── remove_emptyvalue_compactionfilter.h ├── convenience └── info_log_finder.cc ├── document ├── document_db.cc ├── document_db_test.cc ├── json_document.cc ├── json_document_builder.cc └── json_document_test.cc ├── flashcache ├── flashcache.cc └── flashcache.h ├── geodb ├── geodb_impl.cc ├── geodb_impl.h └── geodb_test.cc ├── leveldb_options └── leveldb_options.cc ├── merge_operators.h ├── merge_operators ├── put.cc ├── string_append │ ├── stringappend.cc │ ├── stringappend.h │ ├── stringappend2.cc │ ├── stringappend2.h │ └── stringappend_test.cc └── uint64add.cc ├── redis ├── README ├── redis_list_exception.h ├── redis_list_iterator.h ├── redis_lists.cc ├── redis_lists.h └── redis_lists_test.cc ├── spatialdb ├── spatial_db.cc ├── spatial_db_test.cc └── utils.h ├── table_properties_collectors ├── compact_on_deletion_collector.cc ├── compact_on_deletion_collector.h └── compact_on_deletion_collector_test.cc ├── transactions ├── optimistic_transaction_db_impl.cc ├── optimistic_transaction_db_impl.h ├── optimistic_transaction_impl.cc ├── optimistic_transaction_impl.h ├── optimistic_transaction_test.cc ├── transaction_base.cc ├── transaction_base.h ├── transaction_db_impl.cc ├── transaction_db_impl.h ├── transaction_db_mutex_impl.cc ├── transaction_db_mutex_impl.h ├── transaction_impl.cc ├── transaction_impl.h ├── transaction_lock_mgr.cc ├── transaction_lock_mgr.h ├── transaction_test.cc ├── transaction_util.cc └── transaction_util.h ├── ttl ├── db_ttl_impl.cc ├── db_ttl_impl.h └── ttl_test.cc └── write_batch_with_index ├── write_batch_with_index.cc ├── write_batch_with_index_internal.cc ├── write_batch_with_index_internal.h └── write_batch_with_index_test.cc /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "project_id" : "rocksdb", 3 | "conduit_uri" : "https://reviews.facebook.net/", 4 | "copyright_holder" : "Facebook", 5 | "load" : [ 6 | "arcanist_util" 7 | ], 8 | "lint.engine" : "FacebookFbcodeLintEngine", 9 | "lint.engine.single.linter" : "FbcodeCppLinter", 10 | "unit.engine" : "FacebookFbcodeUnitTestEngine", 11 | "arcanist_configuration" : "FacebookArcanistConfiguration", 12 | "base" : "git:HEAD^, hg:.^", 13 | "git.default-relative-commit" : "HEAD^", 14 | "git:arc.feature.start.default" : "origin/master", 15 | "arc.feature.start.default" : "master", 16 | "history.immutable" : false 17 | } 18 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Complete list of style options can be found at: 2 | # http://clang.llvm.org/docs/ClangFormatStyleOptions.html 3 | --- 4 | BasedOnStyle: Google 5 | ... 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | TARGETS 2 | make_config.mk 3 | 4 | *.a 5 | *.arc 6 | *.d 7 | *.dylib* 8 | *.gcda 9 | *.gcno 10 | *.o 11 | *.so 12 | *.so.* 13 | *_test 14 | *_bench 15 | *_stress 16 | *.out 17 | *.class 18 | *.jar 19 | *.*jnilib* 20 | *.d-e 21 | *.o-* 22 | *.swp 23 | *~ 24 | *.vcxproj 25 | *.vcxproj.filters 26 | *.sln 27 | *.cmake 28 | CMakeCache.txt 29 | CMakeFiles/ 30 | build/ 31 | 32 | ldb 33 | manifest_dump 34 | sst_dump 35 | util/build_version.cc 36 | build_tools/VALGRIND_LOGS/ 37 | coverage/COVERAGE_REPORT 38 | .gdbhistory 39 | package/ 40 | .phutil_module_cache 41 | unity.a 42 | tags 43 | rocksdb_dump 44 | rocksdb_undump 45 | 46 | java/out 47 | java/target 48 | java/test-libs 49 | java/*.log 50 | java/include/org_rocksdb_*.h 51 | 52 | .idea/ 53 | *.iml 54 | 55 | rocksdb.cc 56 | rocksdb.h 57 | unity.cc 58 | java/crossbuild/.vagrant 59 | .vagrant/ 60 | java/**.asc 61 | java/javadoc 62 | 63 | scan_build_report/ 64 | t 65 | LOG 66 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Facebook Inc. 2 | Facebook Engineering Team 3 | 4 | Google Inc. 5 | # Initial version authors: 6 | Jeffrey Dean 7 | Sanjay Ghemawat 8 | 9 | # Partial list of contributors: 10 | Kevin Regan 11 | Johan Bilien 12 | 13 | # LightNVM support contributors: 14 | Florin Petriuc 15 | Javier Gonzalez 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to RocksDB 2 | 3 | ## Contributor License Agreement ("CLA") 4 | 5 | In order to accept your pull request, we need you to submit a CLA. You 6 | only need to do this once, so if you've done this for another Facebook 7 | open source project, you're good to go. If you are submitting a pull 8 | request for the first time, just let us know that you have completed 9 | the CLA and we can cross-check with your GitHub username. 10 | 11 | Complete your CLA here: 12 | 13 | If you prefer to sign a paper copy, we can send you a PDF. Send us an 14 | e-mail or create a new github issue to request the CLA in PDF format. 15 | 16 | ## License 17 | 18 | By contributing to RocksDB, you agree that your contributions will be 19 | licensed under the [BSD License](LICENSE). 20 | -------------------------------------------------------------------------------- /DUMP_FORMAT.md: -------------------------------------------------------------------------------- 1 | ## RocksDB dump format 2 | 3 | The version 1 RocksDB dump format is fairly simple: 4 | 5 | 1) The dump starts with the magic 8 byte identifier "ROCKDUMP" 6 | 7 | 2) The magic is followed by an 8 byte big-endian version which is 0x00000001. 8 | 9 | 3) Next are arbitrarily sized chunks of bytes prepended by 4 byte little endian number indicating how large each chunk is. 10 | 11 | 4) The first chunk is special and is a json string indicating some things about the creation of this dump. It contains the following keys: 12 | * database-path: The path of the database this dump was created from. 13 | * hostname: The hostname of the machine where the dump was created. 14 | * creation-time: Unix seconds since epoc when this dump was created. 15 | 16 | 5) Following the info dump the slices paired into are key/value pairs. 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For rocksdb software 4 | 5 | Copyright (c) 2014, Facebook, Inc. 6 | All rights reserved. 7 | --------------------------------------------------------------------- 8 | 9 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above 18 | copyright notice, this list of conditions and the following disclaimer 19 | in the documentation and/or other materials provided with the 20 | distribution. 21 | * Neither the name of Google Inc. nor the names of its 22 | contributors may be used to endorse or promote products derived from 23 | this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## RocksDB: A Persistent Key-Value Store for Flash, RAM and Open channel SSDs on LightNVM 2 | 3 | [![Build Status](https://travis-ci.org/facebook/rocksdb.svg?branch=master)](https://travis-ci.org/facebook/rocksdb) 4 | 5 | RocksDB is developed and maintained by Facebook Database Engineering Team. 6 | It is built on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) 7 | and Jeff Dean (jeff@google.com) 8 | 9 | This code is a library that forms the core building block for a fast 10 | key value server, especially suited for storing data on flash drives. 11 | It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs 12 | between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) 13 | and Space-Amplification-Factor (SAF). It has multi-threaded compactions, 14 | making it specially suitable for storing multiple terabytes of data in a 15 | single database. 16 | 17 | For OCSSD 2 integration, please use the v5.4.6_ocssd_v0.1.7 branch. 18 | 19 | Contact: 20 | 21 | Matias Bjørling 22 | -------------------------------------------------------------------------------- /ROCKSDB_LITE.md: -------------------------------------------------------------------------------- 1 | # RocksDBLite 2 | 3 | RocksDBLite is a project focused on mobile use cases, which don't need a lot of fancy things we've built for server workloads and they are very sensitive to binary size. For that reason, we added a compile flag ROCKSDB_LITE that comments out a lot of the nonessential code and keeps the binary lean. 4 | 5 | Some examples of the features disabled by ROCKSDB_LITE: 6 | * compiled-in support for LDB tool 7 | * No backupable DB 8 | * No support for replication (which we provide in form of TrasactionalIterator) 9 | * No advanced monitoring tools 10 | * No special-purpose memtables that are highly optimized for specific use cases 11 | * No Transactions 12 | 13 | When adding a new big feature to RocksDB, please add ROCKSDB_LITE compile guard if: 14 | * Nobody from mobile really needs your feature, 15 | * Your feature is adding a lot of weight to the binary. 16 | 17 | Don't add ROCKSDB_LITE compile guard if: 18 | * It would introduce a lot of code complexity. Compile guards make code harder to read. It's a trade-off. 19 | * Your feature is not adding a lot of weight. 20 | 21 | If unsure, ask. :) 22 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | 3 | config.vm.provider "virtualbox" do |v| 4 | v.memory = 4096 5 | v.cpus = 2 6 | end 7 | 8 | config.vm.define "ubuntu14" do |box| 9 | box.vm.box = "ubuntu/trusty64" 10 | end 11 | 12 | config.vm.define "centos65" do |box| 13 | box.vm.box = "chef/centos-6.5" 14 | end 15 | 16 | config.vm.define "FreeBSD10" do |box| 17 | box.vm.guest = :freebsd 18 | box.vm.box = "robin/freebsd-10" 19 | # FreeBSD does not support 'mount_virtualbox_shared_folder', use NFS 20 | box.vm.synced_folder ".", "/vagrant", :nfs => true, id: "vagrant-root" 21 | box.vm.network "private_network", ip: "10.0.1.10" 22 | 23 | # build everything after creating VM, skip using --no-provision 24 | box.vm.provision "shell", inline: <<-SCRIPT 25 | pkg install -y gmake clang35 26 | export CXX=/usr/local/bin/clang++35 27 | cd /vagrant 28 | gmake clean 29 | gmake all OPT=-g 30 | SCRIPT 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /WINDOWS_PORT.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenChannelSSD/rocksdb/ceb4f09f139465787709934fd44807693f5ac2f3/WINDOWS_PORT.md -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | before_build: 3 | - md %APPVEYOR_BUILD_FOLDER%\build 4 | - cd %APPVEYOR_BUILD_FOLDER%\build 5 | - cmake -G "Visual Studio 12 Win64" .. 6 | - cd .. 7 | build: 8 | project: build\ALL_BUILD.vcxproj 9 | parallel: true 10 | verbosity: minimal 11 | test: off 12 | -------------------------------------------------------------------------------- /appveyordailytests.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | before_build: 3 | - md %APPVEYOR_BUILD_FOLDER%\build 4 | - cd %APPVEYOR_BUILD_FOLDER%\build 5 | - cmake -G "Visual Studio 12 Win64" -DOPTDBG=1 .. 6 | - cd .. 7 | build: 8 | project: build\ALL_BUILD.vcxproj 9 | parallel: true 10 | verbosity: minimal 11 | test: 12 | test_script: 13 | - ps: build_tools\run_ci_db_test.ps1 14 | notifications: 15 | - provider: Email 16 | to: 17 | - svmtrocksdb@microsoft.com 18 | subject: "Build {{status}}" 19 | message: "{{message}}, {{commitId}}, ..." 20 | on_build_success: false 21 | on_build_failure: true 22 | on_build_status_changed: true 23 | -------------------------------------------------------------------------------- /arcanist_util/__phutil_library_init__.php: -------------------------------------------------------------------------------- 1 | 2, 11 | 'class' => 12 | array( 13 | 'ArcanistCpplintLinter' => 'cpp_linter/ArcanistCpplintLinter.php', 14 | 'BaseDirectoryScopedFormatLinter' => 'cpp_linter/BaseDirectoryScopedFormatLinter.php', 15 | 'FacebookArcanistConfiguration' => 'config/FacebookArcanistConfiguration.php', 16 | 'FacebookFbcodeLintEngine' => 'lint_engine/FacebookFbcodeLintEngine.php', 17 | 'FacebookFbcodeUnitTestEngine' => 'unit_engine/FacebookFbcodeUnitTestEngine.php', 18 | 'FacebookHowtoevenLintEngine' => 'lint_engine/FacebookHowtoevenLintEngine.php', 19 | 'FacebookHowtoevenLinter' => 'cpp_linter/FacebookHowtoevenLinter.php', 20 | 'FbcodeClangFormatLinter' => 'cpp_linter/FbcodeClangFormatLinter.php', 21 | 'FbcodeCppLinter' => 'cpp_linter/FbcodeCppLinter.php', 22 | ), 23 | 'function' => 24 | array( 25 | ), 26 | 'xmap' => 27 | array( 28 | 'ArcanistCpplintLinter' => 'ArcanistLinter', 29 | 'BaseDirectoryScopedFormatLinter' => 'ArcanistLinter', 30 | 'FacebookArcanistConfiguration' => 'ArcanistConfiguration', 31 | 'FacebookFbcodeLintEngine' => 'ArcanistLintEngine', 32 | 'FacebookFbcodeUnitTestEngine' => 'ArcanistBaseUnitTestEngine', 33 | 'FacebookHowtoevenLintEngine' => 'ArcanistLintEngine', 34 | 'FacebookHowtoevenLinter' => 'ArcanistLinter', 35 | 'FbcodeClangFormatLinter' => 'BaseDirectoryScopedFormatLinter', 36 | 'FbcodeCppLinter' => 'ArcanistLinter', 37 | ), 38 | )); 39 | -------------------------------------------------------------------------------- /arcanist_util/config/FacebookArcanistConfiguration.php: -------------------------------------------------------------------------------- 1 | isRawDiffSource()) { 13 | $this->maybePushToJenkins($workflow); 14 | } 15 | } 16 | 17 | ////////////////////////////////////////////////////////////////////// 18 | /* Send off builds to jenkins */ 19 | function maybePushToJenkins($workflow) { 20 | $diffID = $workflow->getDiffID(); 21 | if ($diffID === null) { 22 | return; 23 | } 24 | 25 | $results = $workflow->getTestResults(); 26 | if (!$results) { 27 | return; 28 | } 29 | 30 | $url = "https://ci-builds.fb.com/view/rocksdb/job/rocksdb_diff_check/" 31 | ."buildWithParameters?token=AUTH&DIFF_ID=$diffID"; 32 | system("curl --noproxy '*' \"$url\" > /dev/null 2>&1"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /arcanist_util/cpp_linter/FbcodeClangFormatLinter.php: -------------------------------------------------------------------------------- 1 | ArcanistLintSeverity::SEVERITY_ADVICE, 23 | ); 24 | } 25 | 26 | public function getLintNameMap() { 27 | return array( 28 | self::LINT_FORMATTING => pht('Changes are not clang-formatted'), 29 | ); 30 | } 31 | 32 | protected function getFormatFuture($path, array $changed) { 33 | $args = ""; 34 | foreach ($changed as $key => $value) { 35 | $args .= " --lines=$key:$key"; 36 | } 37 | 38 | $binary = self::CLANG_FORMAT_BINARY; 39 | if (!file_exists($binary)) { 40 | // trust the $PATH 41 | $binary = "clang-format"; 42 | } 43 | 44 | return new ExecFuture( 45 | "%s %s $args", 46 | $binary, 47 | $this->getEngine()->getFilePathOnDisk($path)); 48 | } 49 | 50 | protected function getLintMessage($diff) { 51 | $link_to_clang_format = 52 | "[[ http://fburl.com/clang-format | clang-format ]]"; 53 | return <<getPaths() as $path) { 13 | // Don't try to lint deleted files or changed directories. 14 | if (!Filesystem::pathExists($path) || is_dir($path)) { 15 | continue; 16 | } 17 | 18 | if (preg_match('/\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)) { 19 | $paths[] = $path; 20 | } 21 | } 22 | 23 | $howtoeven = new FacebookHowtoevenLinter(); 24 | $howtoeven->setPaths($paths); 25 | return array($howtoeven); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /arcanist_util/unit_engine/FacebookFbcodeUnitTestEngine.php: -------------------------------------------------------------------------------- 1 | setName("jenkins_async_test"); 18 | $result->setResult(ArcanistUnitTestResult::RESULT_POSTPONED); 19 | return array($result); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /build_tools/dockerbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker run -v $PWD:/rocks -w /rocks buildpack-deps make 3 | -------------------------------------------------------------------------------- /build_tools/fb_compile_mongo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # fail early 4 | set -e 5 | 6 | if test -z $ROCKSDB_PATH; then 7 | ROCKSDB_PATH=~/rocksdb 8 | fi 9 | source $ROCKSDB_PATH/build_tools/fbcode_config4.8.1.sh 10 | 11 | EXTRA_LDFLAGS="" 12 | 13 | if test -z $ALLOC; then 14 | # default 15 | ALLOC=tcmalloc 16 | elif [[ $ALLOC == "jemalloc" ]]; then 17 | ALLOC=system 18 | EXTRA_LDFLAGS+=" -Wl,--whole-archive $JEMALLOC_LIB -Wl,--no-whole-archive" 19 | fi 20 | 21 | # we need to force mongo to use static library, not shared 22 | STATIC_LIB_DEP_DIR='build/static_library_dependencies' 23 | test -d $STATIC_LIB_DEP_DIR || mkdir $STATIC_LIB_DEP_DIR 24 | test -h $STATIC_LIB_DEP_DIR/`basename $SNAPPY_LIBS` || ln -s $SNAPPY_LIBS $STATIC_LIB_DEP_DIR 25 | test -h $STATIC_LIB_DEP_DIR/`basename $LZ4_LIBS` || ln -s $LZ4_LIBS $STATIC_LIB_DEP_DIR 26 | 27 | EXTRA_LDFLAGS+=" -L $STATIC_LIB_DEP_DIR" 28 | 29 | set -x 30 | 31 | EXTRA_CMD="" 32 | if ! test -e version.json; then 33 | # this is Mongo 3.0 34 | EXTRA_CMD="--rocksdb \ 35 | --variant-dir=linux2/norm 36 | --cxx=${CXX} \ 37 | --cc=${CC} \ 38 | --use-system-zlib" # add this line back to normal code path 39 | # when https://jira.mongodb.org/browse/SERVER-19123 is resolved 40 | fi 41 | 42 | scons \ 43 | LINKFLAGS="$EXTRA_LDFLAGS $EXEC_LDFLAGS $PLATFORM_LDFLAGS" \ 44 | CCFLAGS="$CXXFLAGS -L $STATIC_LIB_DEP_DIR" \ 45 | LIBS="lz4 gcc stdc++" \ 46 | LIBPATH="$ROCKSDB_PATH" \ 47 | CPPPATH="$ROCKSDB_PATH/include" \ 48 | -j32 \ 49 | --allocator=$ALLOC \ 50 | --nostrip \ 51 | --opt=on \ 52 | --disable-minimum-compiler-version-enforcement \ 53 | --use-system-snappy \ 54 | --disable-warnings-as-errors \ 55 | $EXTRA_CMD $* 56 | -------------------------------------------------------------------------------- /build_tools/make_new_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2013, Facebook, Inc. All rights reserved. 3 | # This source code is licensed under the BSD-style license found in the 4 | # LICENSE file in the root directory of this source tree. An additional grant 5 | # of patent rights can be found in the PATENTS file in the same directory. 6 | 7 | set -e 8 | if [ -z "$GIT" ] 9 | then 10 | GIT="git" 11 | fi 12 | 13 | # Print out the colored progress info so that it can be brainlessly 14 | # distinguished by users. 15 | function title() { 16 | echo -e "\033[1;32m$*\033[0m" 17 | } 18 | 19 | usage="Create new RocksDB version and prepare it for the release process\n" 20 | usage+="USAGE: ./make_new_version.sh " 21 | 22 | # -- Pre-check 23 | if [[ $# < 1 ]]; then 24 | echo -e $usage 25 | exit 1 26 | fi 27 | 28 | ROCKSDB_VERSION=$1 29 | 30 | GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` 31 | echo $GIT_BRANCH 32 | 33 | if [ $GIT_BRANCH != "master" ]; then 34 | echo "Error: Current branch is '$GIT_BRANCH', Please switch to master branch." 35 | exit 1 36 | fi 37 | 38 | title "Adding new tag for this release ..." 39 | BRANCH="$ROCKSDB_VERSION.fb" 40 | $GIT checkout -b $BRANCH 41 | 42 | # Setting up the proxy for remote repo access 43 | title "Pushing new branch to remote repo ..." 44 | git push origin --set-upstream $BRANCH 45 | 46 | title "Branch $BRANCH is pushed to github;" 47 | -------------------------------------------------------------------------------- /build_tools/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ "$#" = "0" ]; then 3 | echo "Usage: $0 major|minor|patch" 4 | exit 1 5 | fi 6 | if [ "$1" = "major" ]; then 7 | cat include/rocksdb/version.h | grep MAJOR | head -n1 | awk '{print $3}' 8 | fi 9 | if [ "$1" = "minor" ]; then 10 | cat include/rocksdb/version.h | grep MINOR | head -n1 | awk '{print $3}' 11 | fi 12 | if [ "$1" = "patch" ]; then 13 | cat include/rocksdb/version.h | grep PATCH | head -n1 | awk '{print $3}' 14 | fi 15 | -------------------------------------------------------------------------------- /copy_to_vm.sh: -------------------------------------------------------------------------------- 1 | scp -P 2022 -r * raven@localhost:~/thesis/rocksdb 2 | -------------------------------------------------------------------------------- /create_test.sh: -------------------------------------------------------------------------------- 1 | echo "nba test 0:0" > /sys/block/nvme0n1/nvm/configure -------------------------------------------------------------------------------- /db/convenience.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2012 Facebook. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. 9 | 10 | #ifndef ROCKSDB_LITE 11 | 12 | #include "rocksdb/convenience.h" 13 | 14 | #include "db/db_impl.h" 15 | 16 | namespace rocksdb { 17 | 18 | void CancelAllBackgroundWork(DB* db, bool wait) { 19 | (dynamic_cast(db))->CancelAllBackgroundWork(wait); 20 | } 21 | } // namespace rocksdb 22 | 23 | #endif // ROCKSDB_LITE 24 | -------------------------------------------------------------------------------- /db/event_helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "db/column_family.h" 12 | #include "db/version_edit.h" 13 | #include "rocksdb/listener.h" 14 | #include "rocksdb/table_properties.h" 15 | #include "util/event_logger.h" 16 | 17 | namespace rocksdb { 18 | 19 | class EventHelpers { 20 | public: 21 | static void AppendCurrentTime(JSONWriter* json_writer); 22 | static void LogAndNotifyTableFileCreation( 23 | EventLogger* event_logger, 24 | const std::vector>& listeners, 25 | const FileDescriptor& fd, const TableFileCreationInfo& info); 26 | static void LogAndNotifyTableFileDeletion( 27 | EventLogger* event_logger, int job_id, 28 | uint64_t file_number, const std::string& file_path, 29 | const Status& status, const std::string& db_name, 30 | const std::vector>& listeners); 31 | }; 32 | 33 | } // namespace rocksdb 34 | -------------------------------------------------------------------------------- /db/experimental.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include "rocksdb/experimental.h" 7 | 8 | #include "db/db_impl.h" 9 | 10 | namespace rocksdb { 11 | namespace experimental { 12 | 13 | #ifndef ROCKSDB_LITE 14 | 15 | Status SuggestCompactRange(DB* db, ColumnFamilyHandle* column_family, 16 | const Slice* begin, const Slice* end) { 17 | auto dbimpl = dynamic_cast(db); 18 | if (dbimpl == nullptr) { 19 | return Status::InvalidArgument("Didn't recognize DB object"); 20 | } 21 | 22 | return dbimpl->SuggestCompactRange(column_family, begin, end); 23 | } 24 | 25 | Status PromoteL0(DB* db, ColumnFamilyHandle* column_family, int target_level) { 26 | auto dbimpl = dynamic_cast(db); 27 | if (dbimpl == nullptr) { 28 | return Status::InvalidArgument("Didn't recognize DB object"); 29 | } 30 | return dbimpl->PromoteL0(column_family, target_level); 31 | } 32 | 33 | #else // ROCKSDB_LITE 34 | 35 | Status SuggestCompactRange(DB* db, ColumnFamilyHandle* column_family, 36 | const Slice* begin, const Slice* end) { 37 | return Status::NotSupported("Not supported in RocksDB LITE"); 38 | } 39 | 40 | Status PromoteL0(DB* db, ColumnFamilyHandle* column_family, int target_level) { 41 | return Status::NotSupported("Not supported in RocksDB LITE"); 42 | } 43 | 44 | #endif // ROCKSDB_LITE 45 | 46 | Status SuggestCompactRange(DB* db, const Slice* begin, const Slice* end) { 47 | return SuggestCompactRange(db, db->DefaultColumnFamily(), begin, end); 48 | } 49 | 50 | } // namespace experimental 51 | } // namespace rocksdb 52 | -------------------------------------------------------------------------------- /db/flush_scheduler.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include "db/flush_scheduler.h" 7 | 8 | #include 9 | 10 | #include "db/column_family.h" 11 | 12 | namespace rocksdb { 13 | 14 | void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) { 15 | #ifndef NDEBUG 16 | assert(column_families_set_.find(cfd) == column_families_set_.end()); 17 | column_families_set_.insert(cfd); 18 | #endif // NDEBUG 19 | cfd->Ref(); 20 | column_families_.push_back(cfd); 21 | } 22 | 23 | ColumnFamilyData* FlushScheduler::GetNextColumnFamily() { 24 | ColumnFamilyData* cfd = nullptr; 25 | while (column_families_.size() > 0) { 26 | cfd = column_families_.front(); 27 | column_families_.pop_front(); 28 | if (cfd->IsDropped()) { 29 | if (cfd->Unref()) { 30 | delete cfd; 31 | cfd = nullptr; 32 | } 33 | } else { 34 | break; 35 | } 36 | } 37 | #ifndef NDEBUG 38 | if (cfd != nullptr) { 39 | auto itr = column_families_set_.find(cfd); 40 | assert(itr != column_families_set_.end()); 41 | column_families_set_.erase(itr); 42 | } 43 | #endif // NDEBUG 44 | return cfd; 45 | } 46 | 47 | bool FlushScheduler::Empty() { return column_families_.empty(); } 48 | 49 | void FlushScheduler::Clear() { 50 | for (auto cfd : column_families_) { 51 | #ifndef NDEBUG 52 | auto itr = column_families_set_.find(cfd); 53 | assert(itr != column_families_set_.end()); 54 | column_families_set_.erase(itr); 55 | #endif // NDEBUG 56 | if (cfd->Unref()) { 57 | delete cfd; 58 | } 59 | } 60 | column_families_.clear(); 61 | } 62 | 63 | } // namespace rocksdb 64 | -------------------------------------------------------------------------------- /db/flush_scheduler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace rocksdb { 14 | 15 | class ColumnFamilyData; 16 | 17 | // This class is thread-compatible. It's should only be accessed from single 18 | // write thread (between BeginWrite() and EndWrite()) 19 | class FlushScheduler { 20 | public: 21 | FlushScheduler() = default; 22 | ~FlushScheduler() = default; 23 | 24 | void ScheduleFlush(ColumnFamilyData* cfd); 25 | // Returns Ref()-ed column family. Client needs to Unref() 26 | // REQUIRES: db mutex is held (exception is single-threaded recovery) 27 | ColumnFamilyData* GetNextColumnFamily(); 28 | 29 | bool Empty(); 30 | 31 | void Clear(); 32 | 33 | private: 34 | std::deque column_families_; 35 | #ifndef NDEBUG 36 | std::set column_families_set_; 37 | #endif // NDEBUG 38 | }; 39 | 40 | } // namespace rocksdb 41 | -------------------------------------------------------------------------------- /db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | // Log format information shared by reader and writer. 11 | // See ../doc/log_format.txt for more detail. 12 | 13 | #pragma once 14 | namespace rocksdb { 15 | namespace log { 16 | 17 | enum RecordType { 18 | // Zero is reserved for preallocated files 19 | kZeroType = 0, 20 | kFullType = 1, 21 | 22 | // For fragments 23 | kFirstType = 2, 24 | kMiddleType = 3, 25 | kLastType = 4 26 | }; 27 | static const int kMaxRecordType = kLastType; 28 | 29 | static const unsigned int kBlockSize = 32768; 30 | 31 | // Header is checksum (4 bytes), type (1 byte), length (2 bytes). 32 | static const int kHeaderSize = 4 + 1 + 2; 33 | 34 | } // namespace log 35 | } // namespace rocksdb 36 | -------------------------------------------------------------------------------- /db/memtable_allocator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | 10 | #include 11 | 12 | #include "db/memtable_allocator.h" 13 | #include "db/writebuffer.h" 14 | #include "util/arena.h" 15 | 16 | namespace rocksdb { 17 | 18 | MemTableAllocator::MemTableAllocator(Arena* arena, WriteBuffer* write_buffer) 19 | : arena_(arena), write_buffer_(write_buffer), bytes_allocated_(0) { 20 | } 21 | 22 | MemTableAllocator::~MemTableAllocator() { 23 | DoneAllocating(); 24 | } 25 | 26 | char* MemTableAllocator::Allocate(size_t bytes) { 27 | assert(write_buffer_ != nullptr); 28 | bytes_allocated_ += bytes; 29 | write_buffer_->ReserveMem(bytes); 30 | return arena_->Allocate(bytes); 31 | } 32 | 33 | char* MemTableAllocator::AllocateAligned(size_t bytes, size_t huge_page_size, 34 | Logger* logger) { 35 | assert(write_buffer_ != nullptr); 36 | bytes_allocated_ += bytes; 37 | write_buffer_->ReserveMem(bytes); 38 | return arena_->AllocateAligned(bytes, huge_page_size, logger); 39 | } 40 | 41 | void MemTableAllocator::DoneAllocating() { 42 | if (write_buffer_ != nullptr) { 43 | write_buffer_->FreeMem(bytes_allocated_); 44 | write_buffer_ = nullptr; 45 | } 46 | } 47 | 48 | size_t MemTableAllocator::BlockSize() const { 49 | return arena_->BlockSize(); 50 | } 51 | 52 | } // namespace rocksdb 53 | -------------------------------------------------------------------------------- /db/memtable_allocator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | // This is used by the MemTable to allocate write buffer memory. It connects 11 | // to WriteBuffer so we can track and enforce overall write buffer limits. 12 | 13 | #pragma once 14 | #include "util/allocator.h" 15 | 16 | namespace rocksdb { 17 | 18 | class Arena; 19 | class Logger; 20 | class WriteBuffer; 21 | 22 | class MemTableAllocator : public Allocator { 23 | public: 24 | explicit MemTableAllocator(Arena* arena, WriteBuffer* write_buffer); 25 | ~MemTableAllocator(); 26 | 27 | // Allocator interface 28 | char* Allocate(size_t bytes) override; 29 | char* AllocateAligned(size_t bytes, size_t huge_page_size = 0, 30 | Logger* logger = nullptr) override; 31 | size_t BlockSize() const override; 32 | 33 | // Call when we're finished allocating memory so we can free it from 34 | // the write buffer's limit. 35 | void DoneAllocating(); 36 | 37 | private: 38 | Arena* arena_; 39 | WriteBuffer* write_buffer_; 40 | size_t bytes_allocated_; 41 | 42 | // No copying allowed 43 | MemTableAllocator(const MemTableAllocator&); 44 | void operator=(const MemTableAllocator&); 45 | }; 46 | 47 | } // namespace rocksdb 48 | -------------------------------------------------------------------------------- /db/nvm_bench.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "rocksdb/c.h" 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | const char DBPath[] = "rocksdb"; 14 | 15 | int main(int argc, char **argv) { 16 | char key[8]; 17 | char value[8]; 18 | char *err = NULL; 19 | long cpus = sysconf(_SC_NPROCESSORS_ONLN); 20 | 21 | rocksdb_t *db; 22 | rocksdb_options_t *options; 23 | rocksdb_writeoptions_t *writeoptions; 24 | 25 | options = rocksdb_options_create(); 26 | 27 | rocksdb_options_increase_parallelism(options, (int)(cpus)); 28 | rocksdb_options_optimize_level_style_compaction(options, 0); 29 | rocksdb_options_set_create_if_missing(options, 1); 30 | 31 | db = rocksdb_open(options, DBPath, &err); 32 | if (err) { 33 | cout << "OPEN ERROR: " << err << endl << flush; 34 | return EXIT_FAILURE; 35 | } 36 | 37 | writeoptions = rocksdb_writeoptions_create(); 38 | 39 | for (int i = 0; i < 1000; ++i) { 40 | sprintf(key, "k%06d", i); 41 | sprintf(value, "v%06d", i); 42 | 43 | rocksdb_put(db, writeoptions, key, strlen(key), value, strlen(value) + 1, &err); 44 | if (err) { 45 | cout << "WRITE ERROR: " << err << endl << flush; 46 | return EXIT_FAILURE; 47 | } 48 | } 49 | 50 | rocksdb_writeoptions_destroy(writeoptions); 51 | rocksdb_garbage_collect(db, &err); 52 | if (err) { 53 | cout << "GARBAGE COLLECTION FAILED " << err << endl << flush; 54 | return EXIT_FAILURE; 55 | } 56 | 57 | rocksdb_options_destroy(options); 58 | rocksdb_close(db); 59 | 60 | cout << "DONE\n" << flush; 61 | 62 | return EXIT_SUCCESS; 63 | } 64 | -------------------------------------------------------------------------------- /db/slice.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include "rocksdb/slice.h" 7 | 8 | namespace rocksdb { 9 | 10 | Slice::Slice(const SliceParts& parts, std::string* buf) { 11 | size_t length = 0; 12 | for (int i = 0; i < parts.num_parts; ++i) { 13 | length += parts.parts[i].size(); 14 | } 15 | buf->reserve(length); 16 | 17 | for (int i = 0; i < parts.num_parts; ++i) { 18 | buf->append(parts.parts[i].data(), parts.parts[i].size()); 19 | } 20 | data_ = buf->data(); 21 | size_ = buf->size(); 22 | } 23 | 24 | } // namespace rocksdb 25 | -------------------------------------------------------------------------------- /db/snapshot_impl.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include "rocksdb/snapshot.h" 7 | 8 | #include "rocksdb/db.h" 9 | 10 | namespace rocksdb { 11 | 12 | ManagedSnapshot::ManagedSnapshot(DB* db) : db_(db), 13 | snapshot_(db->GetSnapshot()) {} 14 | 15 | ManagedSnapshot::~ManagedSnapshot() { 16 | if (snapshot_) { 17 | db_->ReleaseSnapshot(snapshot_); 18 | } 19 | } 20 | 21 | const Snapshot* ManagedSnapshot::snapshot() { return snapshot_;} 22 | 23 | } // namespace rocksdb 24 | -------------------------------------------------------------------------------- /db/version_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | #pragma once 11 | #include "rocksdb/env.h" 12 | 13 | namespace rocksdb { 14 | 15 | class TableCache; 16 | class VersionStorageInfo; 17 | class VersionEdit; 18 | struct FileMetaData; 19 | class InternalStats; 20 | 21 | // A helper class so we can efficiently apply a whole sequence 22 | // of edits to a particular state without creating intermediate 23 | // Versions that contain full copies of the intermediate state. 24 | class VersionBuilder { 25 | public: 26 | VersionBuilder(const EnvOptions& env_options, TableCache* table_cache, 27 | VersionStorageInfo* base_vstorage); 28 | ~VersionBuilder(); 29 | void CheckConsistency(VersionStorageInfo* vstorage); 30 | void CheckConsistencyForDeletes(VersionEdit* edit, uint64_t number, 31 | int level); 32 | void Apply(VersionEdit* edit); 33 | void SaveTo(VersionStorageInfo* vstorage); 34 | void LoadTableHandlers(InternalStats* internal_stats, int max_threads = 1); 35 | void MaybeAddFile(VersionStorageInfo* vstorage, int level, FileMetaData* f); 36 | 37 | private: 38 | class Rep; 39 | Rep* rep_; 40 | }; 41 | 42 | extern bool NewestFirstBySeqNo(FileMetaData* a, FileMetaData* b); 43 | } // namespace rocksdb 44 | -------------------------------------------------------------------------------- /db/write_callback.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include "rocksdb/status.h" 9 | 10 | namespace rocksdb { 11 | 12 | class DB; 13 | 14 | class WriteCallback { 15 | public: 16 | virtual ~WriteCallback() {} 17 | 18 | // Will be called while on the write thread before the write executes. If 19 | // this function returns a non-OK status, the write will be aborted and this 20 | // status will be returned to the caller of DB::Write(). 21 | virtual Status Callback(DB* db) = 0; 22 | }; 23 | 24 | } // namespace rocksdb 25 | -------------------------------------------------------------------------------- /db/writebuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | // WriteBuffer is for managing memory allocation for one or more MemTables. 11 | 12 | #pragma once 13 | 14 | namespace rocksdb { 15 | 16 | class WriteBuffer { 17 | public: 18 | explicit WriteBuffer(size_t _buffer_size) 19 | : buffer_size_(_buffer_size), memory_used_(0) {} 20 | 21 | ~WriteBuffer() {} 22 | 23 | size_t memory_usage() const { return memory_used_; } 24 | size_t buffer_size() const { return buffer_size_; } 25 | 26 | // Should only be called from write thread 27 | bool ShouldFlush() const { 28 | return buffer_size() > 0 && memory_usage() >= buffer_size(); 29 | } 30 | 31 | // Should only be called from write thread 32 | void ReserveMem(size_t mem) { memory_used_ += mem; } 33 | void FreeMem(size_t mem) { memory_used_ -= mem; } 34 | 35 | private: 36 | const size_t buffer_size_; 37 | size_t memory_used_; 38 | 39 | // No copying allowed 40 | WriteBuffer(const WriteBuffer&); 41 | void operator=(const WriteBuffer&); 42 | }; 43 | 44 | } // namespace rocksdb 45 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /doc/rockslogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenChannelSSD/rocksdb/ceb4f09f139465787709934fd44807693f5ac2f3/doc/rockslogo.jpg -------------------------------------------------------------------------------- /doc/rockslogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenChannelSSD/rocksdb/ceb4f09f139465787709934fd44807693f5ac2f3/doc/rockslogo.png -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | c_simple_example 2 | column_families_example 3 | compact_files_example 4 | compaction_filter_example 5 | optimistic_transaction_example 6 | simple_example 7 | transaction_example 8 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | Compile RocksDB first by executing `make static_lib` in parent dir 2 | -------------------------------------------------------------------------------- /examples/simple_example.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #include 6 | #include 7 | 8 | #include "rocksdb/db.h" 9 | #include "rocksdb/slice.h" 10 | #include "rocksdb/options.h" 11 | 12 | using namespace rocksdb; 13 | 14 | std::string kDBPath = "/tmp/rocksdb_simple_example"; 15 | 16 | int main() { 17 | DB* db; 18 | Options options; 19 | // Optimize RocksDB. This is the easiest way to get RocksDB to perform well 20 | options.IncreaseParallelism(); 21 | options.OptimizeLevelStyleCompaction(); 22 | // create the DB if it's not already present 23 | options.create_if_missing = true; 24 | 25 | // open DB 26 | Status s = DB::Open(options, kDBPath, &db); 27 | assert(s.ok()); 28 | 29 | // Put key-value 30 | s = db->Put(WriteOptions(), "key1", "value"); 31 | assert(s.ok()); 32 | std::string value; 33 | // get value 34 | s = db->Get(ReadOptions(), "key1", &value); 35 | assert(s.ok()); 36 | assert(value == "value"); 37 | 38 | // atomically apply a set of updates 39 | { 40 | WriteBatch batch; 41 | batch.Delete("key1"); 42 | batch.Put("key2", value); 43 | s = db->Write(WriteOptions(), &batch); 44 | } 45 | 46 | s = db->Get(ReadOptions(), "key1", &value); 47 | assert(s.IsNotFound()); 48 | 49 | db->Get(ReadOptions(), "key2", &value); 50 | assert(value == "value"); 51 | 52 | delete db; 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /hdfs/README: -------------------------------------------------------------------------------- 1 | This directory contains the hdfs extensions needed to make rocksdb store 2 | files in HDFS. 3 | 4 | It has been compiled and testing against CDH 4.4 (2.0.0+1475-1.cdh4.4.0.p0.23~precise-cdh4.4.0). 5 | 6 | The configuration assumes that packages libhdfs0, libhdfs0-dev are 7 | installed which basically means that hdfs.h is in /usr/include and libhdfs in /usr/lib 8 | 9 | The env_hdfs.h file defines the rocksdb objects that are needed to talk to an 10 | underlying filesystem. 11 | 12 | If you want to compile rocksdb with hdfs support, please set the following 13 | enviroment variables appropriately (also defined in setup.sh for convenience) 14 | USE_HDFS=1 15 | JAVA_HOME=/usr/local/jdk-6u22-64 16 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/jdk-6u22-64/jre/lib/amd64/server:/usr/local/jdk-6u22-64/jre/lib/amd64/:./snappy/libs 17 | make clean all db_bench 18 | 19 | To run dbbench, 20 | set CLASSPATH to include your hadoop distribution 21 | db_bench --hdfs="hdfs://hbaseudbperf001.snc1.facebook.com:9000" 22 | 23 | 24 | -------------------------------------------------------------------------------- /hdfs/setup.sh: -------------------------------------------------------------------------------- 1 | export USE_HDFS=1 2 | export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64/server:$JAVA_HOME/jre/lib/amd64:/usr/lib/hadoop/lib/native 3 | 4 | export CLASSPATH= 5 | for f in `find /usr/lib/hadoop-hdfs | grep jar`; do export CLASSPATH=$CLASSPATH:$f; done 6 | for f in `find /usr/lib/hadoop | grep jar`; do export CLASSPATH=$CLASSPATH:$f; done 7 | for f in `find /usr/lib/hadoop/client | grep jar`; do export CLASSPATH=$CLASSPATH:$f; done 8 | -------------------------------------------------------------------------------- /include/nvm/nvm_compile_flags.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVM_COMPILE_FLAGS_H_ 2 | #define _NVM_COMPILE_FLAGS_H_ 3 | 4 | #define NVM_ALLOCATE_BLOCKS 5 | //#define NVM_ALLOCATE_PAGES 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/nvm/nvm_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVM_DEBUG_H_ 2 | #define _NVM_DEBUG_H_ 3 | 4 | #include 5 | 6 | #define NVM_DEBUG_ENABLED 7 | 8 | #define NVM_ASSERT(c, x, ...) if(!(c)){printf("%s:%s - %d %s" x "\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno), ##__VA_ARGS__);fflush(stdout);exit(EXIT_FAILURE);} 9 | #define NVM_ERROR(x, ...) printf("%s:%s - %d %s" x "\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno), ##__VA_ARGS__);fflush(stdout); 10 | #define NVM_FATAL(x, ...) printf("%s:%s - %d %s" x "\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno), ##__VA_ARGS__);fflush(stdout);exit(EXIT_FAILURE) 11 | 12 | #ifdef NVM_DEBUG_ENABLED 13 | 14 | #define NVM_DEBUG(x, ...) printf("%s:%s - %d " x "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);fflush(stdout); 15 | 16 | 17 | #else 18 | 19 | #define NVM_DEBUG(x, ...) 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/nvm/nvm_ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVM_IOCTL_H_ 2 | #define _NVM_IOCTL_H_ 3 | 4 | //TODO: Javier: Assign new magic numbers to ioctls 5 | 6 | #define NVMBLOCKPUT 21525 7 | #define NVMBLOCKRRGET 21526 8 | #define NVMLUNSNRGET 21527 9 | #define NVMBLOCKSNRGET 21528 10 | #define NVMBLOCKERASE 21529 11 | #define NVMPAGESNRGET 21530 12 | #define NVMBLOCKGETBYADDR 21531 13 | #define NVMBLOCKGETBYID 21532 14 | #define NVMPAGESIZEGET 21533 15 | #define NVMCHANNELSNRGET 21534 16 | 17 | #define NVM_DEVSECTSIZE_GET 21535 18 | #define NVM_DEVMAXSECT_GET 21536 19 | 20 | #define NVM_GET_BLOCK 21526 21 | #define NVM_PUT_BLOCK 21525 22 | #define NVM_GET_BLOCK_META 21537 23 | 24 | #endif //_NVM_IOCTL_H_ 25 | -------------------------------------------------------------------------------- /include/nvm/nvm_mem.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVM_MEM_H_ 2 | #define _NVM_MEM_H_ 3 | 4 | #define ALLOC_CLASS(x, y) \ 5 | x = new y;\ 6 | if(!(x))\ 7 | {\ 8 | printf("out of memory\n");\ 9 | exit(EXIT_FAILURE);\ 10 | } 11 | 12 | #define ALLOC_STRUCT(x, y, z) \ 13 | (x) = (z *)malloc((y) * sizeof(z));\ 14 | if(!(x))\ 15 | {\ 16 | printf("out of memory\n");\ 17 | exit(EXIT_FAILURE);\ 18 | } 19 | 20 | #define SAFE_ALLOC(x, y) \ 21 | x = new y;\ 22 | if(!(x))\ 23 | {\ 24 | printf("out of memory\n");\ 25 | exit(EXIT_FAILURE);\ 26 | } 27 | 28 | #define SAFE_MALLOC(x, y, z) ALLOC_STRUCT(x, y, z) 29 | 30 | #endif /* _NVM_MEM_H_ */ 31 | -------------------------------------------------------------------------------- /include/rocksdb/db_dump_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | #ifndef ROCKSDB_LITE 8 | 9 | #include 10 | 11 | #include "rocksdb/db.h" 12 | 13 | namespace rocksdb { 14 | 15 | struct DumpOptions { 16 | // Database that will be dumped 17 | std::string db_path; 18 | // File location that will contain dump output 19 | std::string dump_location; 20 | // Dont include db information header in the dump 21 | bool anonymous = false; 22 | }; 23 | 24 | class DbDumpTool { 25 | public: 26 | bool Run(const DumpOptions& dump_options, 27 | rocksdb::Options options = rocksdb::Options()); 28 | }; 29 | 30 | struct UndumpOptions { 31 | // Database that we will load the dumped file into 32 | std::string db_path; 33 | // File location of the dumped file that will be loaded 34 | std::string dump_location; 35 | // Compact the db after loading the dumped file 36 | bool compact_db = false; 37 | }; 38 | 39 | class DbUndumpTool { 40 | public: 41 | bool Run(const UndumpOptions& undump_options, 42 | rocksdb::Options options = rocksdb::Options()); 43 | }; 44 | } // namespace rocksdb 45 | #endif // ROCKSDB_LITE 46 | -------------------------------------------------------------------------------- /include/rocksdb/experimental.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include "rocksdb/db.h" 9 | #include "rocksdb/status.h" 10 | 11 | namespace rocksdb { 12 | namespace experimental { 13 | 14 | // Supported only for Leveled compaction 15 | Status SuggestCompactRange(DB* db, ColumnFamilyHandle* column_family, 16 | const Slice* begin, const Slice* end); 17 | Status SuggestCompactRange(DB* db, const Slice* begin, const Slice* end); 18 | 19 | // Move all L0 files to target_level skipping compaction. 20 | // This operation succeeds only if the files in L0 have disjoint ranges; this 21 | // is guaranteed to happen, for instance, if keys are inserted in sorted 22 | // order. Furthermore, all levels between 1 and target_level must be empty. 23 | // If any of the above condition is violated, InvalidArgument will be 24 | // returned. 25 | Status PromoteL0(DB* db, ColumnFamilyHandle* column_family, 26 | int target_level = 1); 27 | 28 | } // namespace experimental 29 | } // namespace rocksdb 30 | -------------------------------------------------------------------------------- /include/rocksdb/iostats_context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "rocksdb/perf_level.h" 11 | 12 | // A thread local context for gathering io-stats efficiently and transparently. 13 | // Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats. 14 | 15 | namespace rocksdb { 16 | 17 | struct IOStatsContext { 18 | // reset all io-stats counter to zero 19 | void Reset(); 20 | 21 | std::string ToString() const; 22 | 23 | // the thread pool id 24 | uint64_t thread_pool_id; 25 | 26 | // number of bytes that has been written. 27 | uint64_t bytes_written; 28 | // number of bytes that has been read. 29 | uint64_t bytes_read; 30 | 31 | // time spent in open() and fopen(). 32 | uint64_t open_nanos; 33 | // time spent in fallocate(). 34 | uint64_t allocate_nanos; 35 | // time spent in write() and pwrite(). 36 | uint64_t write_nanos; 37 | // time spent in read() and pread() 38 | uint64_t read_nanos; 39 | // time spent in sync_file_range(). 40 | uint64_t range_sync_nanos; 41 | // time spent in fsync 42 | uint64_t fsync_nanos; 43 | // time spent in preparing write (fallocate etc). 44 | uint64_t prepare_write_nanos; 45 | // time spent in Logger::Logv(). 46 | uint64_t logger_nanos; 47 | }; 48 | 49 | #ifndef IOS_CROSS_COMPILE 50 | # ifdef _WIN32 51 | extern __declspec(thread) IOStatsContext iostats_context; 52 | # else 53 | extern __thread IOStatsContext iostats_context; 54 | # endif 55 | #endif // IOS_CROSS_COMPILE 56 | 57 | } // namespace rocksdb 58 | -------------------------------------------------------------------------------- /include/rocksdb/ldb_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #ifndef ROCKSDB_LITE 6 | #pragma once 7 | #include 8 | #include "rocksdb/options.h" 9 | 10 | namespace rocksdb { 11 | 12 | // An interface for converting a slice to a readable string 13 | class SliceFormatter { 14 | public: 15 | virtual ~SliceFormatter() {} 16 | virtual std::string Format(const Slice& s) const = 0; 17 | }; 18 | 19 | // Options for customizing ldb tool (beyond the DB Options) 20 | struct LDBOptions { 21 | // Create LDBOptions with default values for all fields 22 | LDBOptions(); 23 | 24 | // Key formatter that converts a slice to a readable string. 25 | // Default: Slice::ToString() 26 | std::shared_ptr key_formatter; 27 | }; 28 | 29 | class LDBTool { 30 | public: 31 | void Run(int argc, char** argv, Options db_options= Options(), 32 | const LDBOptions& ldb_options = LDBOptions()); 33 | }; 34 | 35 | } // namespace rocksdb 36 | 37 | #endif // ROCKSDB_LITE 38 | -------------------------------------------------------------------------------- /include/rocksdb/perf_level.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #ifndef INCLUDE_ROCKSDB_PERF_LEVEL_H_ 7 | #define INCLUDE_ROCKSDB_PERF_LEVEL_H_ 8 | 9 | #include 10 | #include 11 | 12 | namespace rocksdb { 13 | 14 | // How much perf stats to collect. Affects perf_context and iostats_context. 15 | 16 | enum PerfLevel { 17 | kDisable = 0, // disable perf stats 18 | kEnableCount = 1, // enable only count stats 19 | kEnableTime = 2 // enable time stats too 20 | }; 21 | 22 | // set the perf stats level for current thread 23 | void SetPerfLevel(PerfLevel level); 24 | 25 | // get current perf stats level for current thread 26 | PerfLevel GetPerfLevel(); 27 | 28 | } // namespace rocksdb 29 | 30 | #endif // INCLUDE_ROCKSDB_PERF_LEVEL_H_ 31 | -------------------------------------------------------------------------------- /include/rocksdb/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include "rocksdb/types.h" 9 | 10 | namespace rocksdb { 11 | 12 | class DB; 13 | 14 | // Abstract handle to particular state of a DB. 15 | // A Snapshot is an immutable object and can therefore be safely 16 | // accessed from multiple threads without any external synchronization. 17 | // 18 | // To Create a Snapshot, call DB::GetSnapshot(). 19 | // To Destroy a Snapshot, call DB::ReleaseSnapshot(snapshot). 20 | class Snapshot { 21 | public: 22 | // returns Snapshot's sequence number 23 | virtual SequenceNumber GetSequenceNumber() const = 0; 24 | 25 | protected: 26 | virtual ~Snapshot(); 27 | }; 28 | 29 | // Simple RAII wrapper class for Snapshot. 30 | // Constructing this object will create a snapshot. Destructing will 31 | // release the snapshot. 32 | class ManagedSnapshot { 33 | public: 34 | explicit ManagedSnapshot(DB* db); 35 | 36 | ~ManagedSnapshot(); 37 | 38 | const Snapshot* snapshot(); 39 | 40 | private: 41 | DB* db_; 42 | const Snapshot* snapshot_; 43 | }; 44 | 45 | } // namespace rocksdb 46 | -------------------------------------------------------------------------------- /include/rocksdb/sst_dump_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #ifndef ROCKSDB_LITE 6 | #pragma once 7 | 8 | namespace rocksdb { 9 | 10 | class SSTDumpTool { 11 | public: 12 | int Run(int argc, char** argv); 13 | }; 14 | 15 | } // namespace rocksdb 16 | 17 | #endif // ROCKSDB_LITE 18 | -------------------------------------------------------------------------------- /include/rocksdb/types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #ifndef STORAGE_ROCKSDB_INCLUDE_TYPES_H_ 7 | #define STORAGE_ROCKSDB_INCLUDE_TYPES_H_ 8 | 9 | #include 10 | 11 | namespace rocksdb { 12 | 13 | // Define all public custom types here. 14 | 15 | // Represents a sequence number in a WAL file. 16 | typedef uint64_t SequenceNumber; 17 | 18 | } // namespace rocksdb 19 | 20 | #endif // STORAGE_ROCKSDB_INCLUDE_TYPES_H_ 21 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/checkpoint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // A checkpoint is an openable snapshot of a database at a point in time. 7 | 8 | #pragma once 9 | #ifndef ROCKSDB_LITE 10 | 11 | #include 12 | #include "rocksdb/status.h" 13 | 14 | namespace rocksdb { 15 | 16 | class DB; 17 | 18 | class Checkpoint { 19 | public: 20 | // Creates a Checkpoint object to be used for creating openable sbapshots 21 | static Status Create(DB* db, Checkpoint** checkpoint_ptr); 22 | 23 | // Builds an openable snapshot of RocksDB on the same disk, which 24 | // accepts an output directory on the same disk, and under the directory 25 | // (1) hard-linked SST files pointing to existing live SST files 26 | // SST files will be copied if output directory is on a different filesystem 27 | // (2) a copied manifest files and other files 28 | // The directory should not already exist and will be created by this API. 29 | // The directory will be an absolute path 30 | virtual Status CreateCheckpoint(const std::string& checkpoint_dir); 31 | 32 | virtual ~Checkpoint() {} 33 | }; 34 | 35 | } // namespace rocksdb 36 | #endif // !ROCKSDB_LITE 37 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/convenience.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | // This file was moved to rocksdb/convenience.h" 9 | 10 | #include "rocksdb/convenience.h" 11 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/flashcache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "rocksdb/env.h" 10 | 11 | namespace rocksdb { 12 | 13 | // This API is experimental. We will mark it stable once we run it in production 14 | // for a while. 15 | // NewFlashcacheAwareEnv() creates and Env that blacklists all background 16 | // threads (used for flush and compaction) from using flashcache to cache their 17 | // reads. Reads from compaction thread don't need to be cached because they are 18 | // going to be soon made obsolete (due to nature of compaction) 19 | // Usually you would pass Env::Default() as base. 20 | // cachedev_fd is a file descriptor of the flashcache device. Caller has to 21 | // open flashcache device before calling this API. 22 | extern std::unique_ptr NewFlashcacheAwareEnv( 23 | Env* base, const int cachedev_fd); 24 | 25 | } // namespace rocksdb 26 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/info_log_finder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "rocksdb/db.h" 12 | #include "rocksdb/options.h" 13 | 14 | namespace rocksdb { 15 | 16 | // This function can be used to list the Information logs, 17 | // given the db pointer. 18 | Status GetInfoLogList(DB* db, std::vector* info_log_list); 19 | } // namespace rocksdb 20 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/table_properties_collectors.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | #ifndef ROCKSDB_LITE 8 | #include 9 | 10 | #include "rocksdb/table_properties.h" 11 | 12 | namespace rocksdb { 13 | 14 | // Creates a factory of a table property collector that marks a SST 15 | // file as need-compaction when it observe at least "D" deletion 16 | // entries in any "N" consecutive entires. 17 | // 18 | // @param sliding_window_size "N". Note that this number will be 19 | // round up to the smallest multiple of 128 that is no less 20 | // than the specified size. 21 | // @param deletion_trigger "D". Note that even when "N" is changed, 22 | // the specified number for "D" will not be changed. 23 | extern std::shared_ptr 24 | NewCompactOnDeletionCollectorFactory( 25 | size_t sliding_window_size, 26 | size_t deletion_trigger); 27 | } // namespace rocksdb 28 | 29 | #endif // !ROCKSDB_LITE 30 | -------------------------------------------------------------------------------- /include/rocksdb/utilities/utility_db.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 | #pragma once 6 | #ifndef ROCKSDB_LITE 7 | #include 8 | #include 9 | 10 | #include "rocksdb/utilities/stackable_db.h" 11 | #include "rocksdb/utilities/db_ttl.h" 12 | #include "rocksdb/db.h" 13 | 14 | namespace rocksdb { 15 | 16 | // Please don't use this class. It's deprecated 17 | class UtilityDB { 18 | public: 19 | // This function is here only for backwards compatibility. Please use the 20 | // functions defined in DBWithTTl (rocksdb/utilities/db_ttl.h) 21 | // (deprecated) 22 | #if defined(__GNUC__) || defined(__clang__) 23 | __attribute__((deprecated)) 24 | #elif _WIN32 25 | __declspec(deprecated) 26 | #endif 27 | static Status OpenTtlDB(const Options& options, 28 | const std::string& name, 29 | StackableDB** dbptr, 30 | int32_t ttl = 0, 31 | bool read_only = false); 32 | }; 33 | 34 | } // namespace rocksdb 35 | #endif // ROCKSDB_LITE 36 | -------------------------------------------------------------------------------- /include/rocksdb/version.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #pragma once 6 | 7 | #define ROCKSDB_MAJOR 4 8 | #define ROCKSDB_MINOR 1 9 | #define ROCKSDB_PATCH 0 10 | 11 | // Do not use these. We made the mistake of declaring macros starting with 12 | // double underscore. Now we have to live with our choice. We'll deprecate these 13 | // at some point 14 | #define __ROCKSDB_MAJOR__ ROCKSDB_MAJOR 15 | #define __ROCKSDB_MINOR__ ROCKSDB_MINOR 16 | #define __ROCKSDB_PATCH__ ROCKSDB_PATCH 17 | -------------------------------------------------------------------------------- /java/crossbuild/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | 9 | config.vm.define "linux32" do |linux32| 10 | linux32.vm.box = "hansode/centos-5.6-i386" 11 | end 12 | 13 | config.vm.define "linux64" do |linux64| 14 | linux64.vm.box = "hansode/centos-5.6-x86_64" 15 | end 16 | 17 | config.vm.provider "virtualbox" do |v| 18 | v.memory = 2048 19 | v.cpus = 4 20 | end 21 | 22 | config.vm.provision :shell, path: "build-linux-centos.sh" 23 | config.vm.synced_folder "../target", "/rocksdb-build" 24 | config.vm.synced_folder "../..", "/rocksdb", type: "rsync" 25 | config.vm.boot_timeout = 1200 26 | end 27 | -------------------------------------------------------------------------------- /java/crossbuild/build-linux-centos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # install all required packages for rocksdb that are available through yum 3 | ARCH=$(uname -i) 4 | sudo yum -y install openssl java-1.7.0-openjdk-devel.$ARCH 5 | 6 | # install gcc/g++ 4.8.2 via CERN (http://linux.web.cern.ch/linux/devtoolset/) 7 | sudo wget -O /etc/yum.repos.d/slc5-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc5-devtoolset.repo 8 | sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-cern http://ftp.mirrorservice.org/sites/ftp.scientificlinux.org/linux/scientific/51/i386/RPM-GPG-KEYs/RPM-GPG-KEY-cern 9 | sudo yum -y install devtoolset-2 10 | 11 | wget http://gflags.googlecode.com/files/gflags-2.0-no-svn-files.tar.gz 12 | tar xvfz gflags-2.0-no-svn-files.tar.gz; cd gflags-2.0; scl enable devtoolset-2 ./configure; scl enable devtoolset-2 make; sudo make install 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib 14 | 15 | # set java home so we can build rocksdb jars 16 | export JAVA_HOME=/usr/lib/jvm/java-1.7.0 17 | 18 | # build rocksdb 19 | cd /rocksdb 20 | scl enable devtoolset-2 'make jclean clean' 21 | scl enable devtoolset-2 'PORTABLE=1 make rocksdbjavastatic' 22 | cp /rocksdb/java/target/librocksdbjni-* /rocksdb-build 23 | cp /rocksdb/java/target/rocksdbjni-* /rocksdb-build 24 | 25 | -------------------------------------------------------------------------------- /java/crossbuild/build-linux.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # install all required packages for rocksdb 3 | sudo apt-get update 4 | sudo apt-get -y install git make gcc g++ libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev default-jdk 5 | 6 | # set java home so we can build rocksdb jars 7 | export JAVA_HOME=$(echo /usr/lib/jvm/java-7-openjdk*) 8 | cd /rocksdb 9 | make jclean clean 10 | make -j 4 rocksdbjavastatic 11 | cp /rocksdb/java/target/librocksdbjni-* /rocksdb-build 12 | cp /rocksdb/java/target/rocksdbjni-* /rocksdb-build 13 | sudo shutdown -h now 14 | 15 | -------------------------------------------------------------------------------- /java/jdb_bench.sh: -------------------------------------------------------------------------------- 1 | PLATFORM=64 2 | if [ `getconf LONG_BIT` != "64" ] 3 | then 4 | PLATFORM=32 5 | fi 6 | 7 | ROCKS_JAR=`find target -name rocksdbjni*.jar` 8 | 9 | echo "Running benchmark in $PLATFORM-Bit mode." 10 | java -server -d$PLATFORM -XX:NewSize=4m -XX:+AggressiveOpts -Djava.library.path=target -cp "${ROCKS_JAR}:benchmark/target/classes" org.rocksdb.benchmark.DbBenchmark $@ 11 | -------------------------------------------------------------------------------- /java/rocksjni/columnfamilyhandle.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ and enables 7 | // calling c++ rocksdb::Iterator methods from Java side. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "include/org_rocksdb_ColumnFamilyHandle.h" 14 | #include "rocksjni/portal.h" 15 | 16 | /* 17 | * Class: org_rocksdb_ColumnFamilyHandle 18 | * Method: disposeInternal 19 | * Signature: (J)V 20 | */ 21 | void Java_org_rocksdb_ColumnFamilyHandle_disposeInternal( 22 | JNIEnv* env, jobject jobj, jlong handle) { 23 | auto it = reinterpret_cast(handle); 24 | delete it; 25 | } 26 | -------------------------------------------------------------------------------- /java/rocksjni/compaction_filter.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ for 7 | // rocksdb::CompactionFilter. 8 | 9 | #include 10 | 11 | #include "rocksdb/compaction_filter.h" 12 | 13 | // 14 | 15 | /* 16 | * Class: org_rocksdb_AbstractCompactionFilter 17 | * Method: disposeInternal 18 | * Signature: (J)V 19 | */ 20 | void Java_org_rocksdb_AbstractCompactionFilter_disposeInternal( 21 | JNIEnv* env, jobject jobj, jlong handle) { 22 | delete reinterpret_cast(handle); 23 | } 24 | // 25 | -------------------------------------------------------------------------------- /java/rocksjni/filter.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ for 7 | // rocksdb::FilterPolicy. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "include/org_rocksdb_Filter.h" 15 | #include "include/org_rocksdb_BloomFilter.h" 16 | #include "rocksjni/portal.h" 17 | #include "rocksdb/filter_policy.h" 18 | 19 | /* 20 | * Class: org_rocksdb_BloomFilter 21 | * Method: createBloomFilter 22 | * Signature: (IZ)V 23 | */ 24 | void Java_org_rocksdb_BloomFilter_createNewBloomFilter( 25 | JNIEnv* env, jobject jobj, jint bits_per_key, 26 | jboolean use_block_base_builder) { 27 | rocksdb::FilterPolicy* fp = const_cast( 28 | rocksdb::NewBloomFilterPolicy(bits_per_key, use_block_base_builder)); 29 | std::shared_ptr *pFilterPolicy = 30 | new std::shared_ptr; 31 | *pFilterPolicy = std::shared_ptr(fp); 32 | rocksdb::FilterJni::setHandle(env, jobj, pFilterPolicy); 33 | } 34 | 35 | /* 36 | * Class: org_rocksdb_Filter 37 | * Method: disposeInternal 38 | * Signature: (J)V 39 | */ 40 | void Java_org_rocksdb_Filter_disposeInternal( 41 | JNIEnv* env, jobject jobj, jlong jhandle) { 42 | 43 | std::shared_ptr *handle = 44 | reinterpret_cast *>(jhandle); 45 | handle->reset(); 46 | } 47 | -------------------------------------------------------------------------------- /java/rocksjni/loggerjnicallback.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the callback "bridge" between Java and C++ for 7 | // rocksdb::Logger 8 | 9 | #ifndef JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_ 10 | #define JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_ 11 | 12 | #include 13 | #include 14 | #include "port/port.h" 15 | #include "rocksdb/env.h" 16 | 17 | namespace rocksdb { 18 | 19 | class LoggerJniCallback : public Logger { 20 | public: 21 | LoggerJniCallback(JNIEnv* env, jobject jLogger); 22 | virtual ~LoggerJniCallback(); 23 | 24 | using Logger::SetInfoLogLevel; 25 | using Logger::GetInfoLogLevel; 26 | // Write an entry to the log file with the specified format. 27 | virtual void Logv(const char* format, va_list ap); 28 | // Write an entry to the log file with the specified log level 29 | // and format. Any log with level under the internal log level 30 | // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be 31 | // printed. 32 | virtual void Logv(const InfoLogLevel log_level, 33 | const char* format, va_list ap); 34 | 35 | protected: 36 | JNIEnv* getJniEnv() const; 37 | private: 38 | JavaVM* m_jvm; 39 | jobject m_jLogger; 40 | jmethodID m_jLogMethodId; 41 | }; 42 | } // namespace rocksdb 43 | 44 | #endif // JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_ 45 | -------------------------------------------------------------------------------- /java/rocksjni/merge_operator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Vlad Balan (vlad.gm@gmail.com). All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ 7 | // for rocksdb::MergeOperator. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "include/org_rocksdb_StringAppendOperator.h" 16 | #include "rocksjni/portal.h" 17 | #include "rocksdb/db.h" 18 | #include "rocksdb/options.h" 19 | #include "rocksdb/statistics.h" 20 | #include "rocksdb/memtablerep.h" 21 | #include "rocksdb/table.h" 22 | #include "rocksdb/slice_transform.h" 23 | #include "rocksdb/merge_operator.h" 24 | #include "utilities/merge_operators.h" 25 | 26 | /* 27 | * Class: org_rocksdb_StringAppendOperator 28 | * Method: newMergeOperatorHandle 29 | * Signature: ()J 30 | */ 31 | jlong Java_org_rocksdb_StringAppendOperator_newMergeOperatorHandleImpl 32 | (JNIEnv* env, jobject jobj) { 33 | std::shared_ptr *op = 34 | new std::shared_ptr(); 35 | *op = rocksdb::MergeOperators::CreateFromStringId("stringappend"); 36 | return reinterpret_cast(op); 37 | } 38 | -------------------------------------------------------------------------------- /java/rocksjni/ratelimiterjni.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ for RateLimiter. 7 | 8 | #include "rocksjni/portal.h" 9 | #include "include/org_rocksdb_GenericRateLimiterConfig.h" 10 | #include "rocksdb/rate_limiter.h" 11 | 12 | /* 13 | * Class: org_rocksdb_GenericRateLimiterConfig 14 | * Method: newRateLimiterHandle 15 | * Signature: (JJI)J 16 | */ 17 | jlong Java_org_rocksdb_GenericRateLimiterConfig_newRateLimiterHandle( 18 | JNIEnv* env, jobject jobj, jlong jrate_bytes_per_second, 19 | jlong jrefill_period_micros, jint jfairness) { 20 | return reinterpret_cast(rocksdb::NewGenericRateLimiter( 21 | static_cast(jrate_bytes_per_second), 22 | static_cast(jrefill_period_micros), 23 | static_cast(jfairness))); 24 | } 25 | -------------------------------------------------------------------------------- /java/rocksjni/remove_emptyvalue_compactionfilterjni.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include 7 | 8 | #include "include/org_rocksdb_RemoveEmptyValueCompactionFilter.h" 9 | #include "utilities/compaction_filters/remove_emptyvalue_compactionfilter.h" 10 | 11 | 12 | /* 13 | * Class: org_rocksdb_RemoveEmptyValueCompactionFilter 14 | * Method: createNewRemoveEmptyValueCompactionFilter0 15 | * Signature: ()V 16 | */ 17 | void Java_org_rocksdb_RemoveEmptyValueCompactionFilter_createNewRemoveEmptyValueCompactionFilter0( 18 | JNIEnv* env, jobject jobj) { 19 | const rocksdb::RemoveEmptyValueCompactionFilter* compaction_filter = 20 | new rocksdb::RemoveEmptyValueCompactionFilter(); 21 | 22 | // set the native handle to our native compaction filter 23 | static jclass jclazz = 24 | env->FindClass("org/rocksdb/RemoveEmptyValueCompactionFilter"); 25 | static jfieldID fid = env->GetFieldID(jclazz, "nativeHandle_", "J"); 26 | env->SetLongField(jobj, fid, reinterpret_cast(compaction_filter)); 27 | } 28 | -------------------------------------------------------------------------------- /java/rocksjni/snapshot.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++. 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "include/org_rocksdb_Snapshot.h" 13 | #include "rocksdb/db.h" 14 | #include "rocksjni/portal.h" 15 | 16 | /* 17 | * Class: org_rocksdb_Snapshot 18 | * Method: getSequenceNumber 19 | * Signature: (J)J 20 | */ 21 | jlong Java_org_rocksdb_Snapshot_getSequenceNumber(JNIEnv* env, 22 | jobject jobj, jlong jsnapshot_handle) { 23 | auto* snapshot = reinterpret_cast( 24 | jsnapshot_handle); 25 | return snapshot->GetSequenceNumber(); 26 | } 27 | -------------------------------------------------------------------------------- /java/rocksjni/statistics.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the "bridge" between Java and C++ and enables 7 | // calling c++ rocksdb::Statistics methods from Java side. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "include/org_rocksdb_Statistics.h" 14 | #include "rocksjni/portal.h" 15 | #include "rocksdb/statistics.h" 16 | 17 | /* 18 | * Class: org_rocksdb_Statistics 19 | * Method: getTickerCount0 20 | * Signature: (IJ)J 21 | */ 22 | jlong Java_org_rocksdb_Statistics_getTickerCount0( 23 | JNIEnv* env, jobject jobj, int tickerType, jlong handle) { 24 | auto st = reinterpret_cast(handle); 25 | assert(st != nullptr); 26 | 27 | return st->getTickerCount(static_cast(tickerType)); 28 | } 29 | 30 | /* 31 | * Class: org_rocksdb_Statistics 32 | * Method: geHistogramData0 33 | * Signature: (IJ)Lorg/rocksdb/HistogramData; 34 | */ 35 | jobject Java_org_rocksdb_Statistics_geHistogramData0( 36 | JNIEnv* env, jobject jobj, int histogramType, jlong handle) { 37 | auto st = reinterpret_cast(handle); 38 | assert(st != nullptr); 39 | 40 | rocksdb::HistogramData data; 41 | st->histogramData(static_cast(histogramType), 42 | &data); 43 | 44 | // Don't reuse class pointer 45 | jclass jclazz = env->FindClass("org/rocksdb/HistogramData"); 46 | jmethodID mid = rocksdb::HistogramDataJni::getConstructorMethodId( 47 | env, jclazz); 48 | return env->NewObject(jclazz, mid, data.median, data.percentile95, 49 | data.percentile99, data.average, data.standard_deviation); 50 | } 51 | -------------------------------------------------------------------------------- /java/rocksjni/writebatchhandlerjnicallback.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // This file implements the callback "bridge" between Java and C++ for 7 | // rocksdb::WriteBatch::Handler. 8 | 9 | #ifndef JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_ 10 | #define JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_ 11 | 12 | #include 13 | #include "rocksdb/write_batch.h" 14 | 15 | namespace rocksdb { 16 | /** 17 | * This class acts as a bridge between C++ 18 | * and Java. The methods in this class will be 19 | * called back from the RocksDB storage engine (C++) 20 | * which calls the appropriate Java method. 21 | * This enables Write Batch Handlers to be implemented in Java. 22 | */ 23 | class WriteBatchHandlerJniCallback : public WriteBatch::Handler { 24 | public: 25 | WriteBatchHandlerJniCallback( 26 | JNIEnv* env, jobject jWriteBackHandler); 27 | ~WriteBatchHandlerJniCallback(); 28 | void Put(const Slice& key, const Slice& value); 29 | void Merge(const Slice& key, const Slice& value); 30 | void Delete(const Slice& key); 31 | void LogData(const Slice& blob); 32 | bool Continue(); 33 | 34 | private: 35 | JNIEnv* m_env; 36 | jobject m_jWriteBatchHandler; 37 | jbyteArray sliceToJArray(const Slice& s); 38 | jmethodID m_jPutMethodId; 39 | jmethodID m_jMergeMethodId; 40 | jmethodID m_jDeleteMethodId; 41 | jmethodID m_jLogDataMethodId; 42 | jmethodID m_jContinueMethodId; 43 | }; 44 | } // namespace rocksdb 45 | 46 | #endif // JAVA_ROCKSJNI_WRITEBATCHHANDLERJNICALLBACK_H_ 47 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/AbstractCompactionFilter.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | /** 8 | * A CompactionFilter allows an application to modify/delete a key-value at 9 | * the time of compaction. 10 | * 11 | * At present we just permit an overriding Java class to wrap a C++ implementation 12 | */ 13 | public abstract class AbstractCompactionFilter> 14 | extends RocksObject { 15 | 16 | /** 17 | * Deletes underlying C++ comparator pointer. 18 | * 19 | * Note that this function should be called only after all 20 | * RocksDB instances referencing the comparator are closed. 21 | * Otherwise an undefined behavior will occur. 22 | */ 23 | @Override protected void disposeInternal() { 24 | assert(isInitialized()); 25 | disposeInternal(nativeHandle_); 26 | } 27 | 28 | private native void disposeInternal(long handle); 29 | } 30 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/BackupInfo.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | /** 8 | * Instances of this class describe a Backup made by 9 | * {@link org.rocksdb.BackupableDB}. 10 | */ 11 | public class BackupInfo { 12 | 13 | /** 14 | * Package private constructor used to create instances 15 | * of BackupInfo by {@link org.rocksdb.BackupableDB} and 16 | * {@link org.rocksdb.RestoreBackupableDB}. 17 | * 18 | * @param backupId id of backup 19 | * @param timestamp timestamp of backup 20 | * @param size size of backup 21 | * @param numberFiles number of files related to this backup. 22 | */ 23 | BackupInfo(final int backupId, final long timestamp, final long size, 24 | final int numberFiles) { 25 | backupId_ = backupId; 26 | timestamp_ = timestamp; 27 | size_ = size; 28 | numberFiles_ = numberFiles; 29 | } 30 | 31 | /** 32 | * 33 | * @return the backup id. 34 | */ 35 | public int backupId() { 36 | return backupId_; 37 | } 38 | 39 | /** 40 | * 41 | * @return the timestamp of the backup. 42 | */ 43 | public long timestamp() { 44 | return timestamp_; 45 | } 46 | 47 | /** 48 | * 49 | * @return the size of the backup 50 | */ 51 | public long size() { 52 | return size_; 53 | } 54 | 55 | /** 56 | * 57 | * @return the number of files of this backup. 58 | */ 59 | public int numberFiles() { 60 | return numberFiles_; 61 | } 62 | 63 | private int backupId_; 64 | private long timestamp_; 65 | private long size_; 66 | private int numberFiles_; 67 | } 68 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/BuiltinComparator.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Builtin RocksDB comparators 10 | * 11 | *
    12 | *
  1. BYTEWISE_COMPARATOR - Sorts all keys in ascending bytewise 13 | * order.
  2. 14 | *
  3. REVERSE_BYTEWISE_COMPARATOR - Sorts all keys in descending bytewise 15 | * order
  4. 16 | *
17 | */ 18 | public enum BuiltinComparator { 19 | BYTEWISE_COMPARATOR, REVERSE_BYTEWISE_COMPARATOR 20 | } 21 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/ChecksumType.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Checksum types used in conjunction with BlockBasedTable. 10 | */ 11 | public enum ChecksumType { 12 | /** 13 | * Not implemented yet. 14 | */ 15 | kNoChecksum((byte) 0), 16 | /** 17 | * CRC32 Checksum 18 | */ 19 | kCRC32c((byte) 1), 20 | /** 21 | * XX Hash 22 | */ 23 | kxxHash((byte) 2); 24 | 25 | /** 26 | * Returns the byte value of the enumerations value 27 | * 28 | * @return byte representation 29 | */ 30 | public byte getValue() { 31 | return value_; 32 | } 33 | 34 | private ChecksumType(byte value) { 35 | value_ = value; 36 | } 37 | 38 | private final byte value_; 39 | } 40 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/ColumnFamilyHandle.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * ColumnFamilyHandle class to hold handles to underlying rocksdb 10 | * ColumnFamily Pointers. 11 | */ 12 | public class ColumnFamilyHandle extends RocksObject { 13 | ColumnFamilyHandle(final RocksDB rocksDB, 14 | final long nativeHandle) { 15 | super(); 16 | nativeHandle_ = nativeHandle; 17 | // rocksDB must point to a valid RocksDB instance; 18 | assert(rocksDB != null); 19 | // ColumnFamilyHandle must hold a reference to the related RocksDB instance 20 | // to guarantee that while a GC cycle starts ColumnFamilyHandle instances 21 | // are freed prior to RocksDB instances. 22 | rocksDB_ = rocksDB; 23 | } 24 | 25 | /** 26 | *

Deletes underlying C++ iterator pointer.

27 | * 28 | *

Note: the underlying handle can only be safely deleted if the RocksDB 29 | * instance related to a certain ColumnFamilyHandle is still valid and initialized. 30 | * Therefore {@code disposeInternal()} checks if the RocksDB is initialized 31 | * before freeing the native handle.

32 | */ 33 | @Override protected void disposeInternal() { 34 | synchronized (rocksDB_) { 35 | assert (isInitialized()); 36 | if (rocksDB_.isInitialized()) { 37 | disposeInternal(nativeHandle_); 38 | } 39 | } 40 | } 41 | 42 | private native void disposeInternal(long handle); 43 | 44 | private final RocksDB rocksDB_; 45 | } 46 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/CompactionStyle.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Enum CompactionStyle 10 | * 11 | * RocksDB supports different styles of compaction. Available 12 | * compaction styles can be chosen using this enumeration. 13 | * 14 | *
    15 | *
  1. LEVEL - Level based Compaction style
  2. 16 | *
  3. UNIVERSAL - Universal Compaction Style is a 17 | * compaction style, targeting the use cases requiring lower write 18 | * amplification, trading off read amplification and space 19 | * amplification.
  4. 20 | *
  5. FIFO - FIFO compaction style is the simplest 21 | * compaction strategy. It is suited for keeping event log data with 22 | * very low overhead (query log for example). It periodically deletes 23 | * the old data, so it's basically a TTL compaction style.
  6. 24 | *
25 | * 26 | * @see 28 | * Universal Compaction 29 | * @see 31 | * FIFO Compaction 32 | */ 33 | public enum CompactionStyle { 34 | LEVEL((byte) 0), 35 | UNIVERSAL((byte) 1), 36 | FIFO((byte) 2); 37 | 38 | private final byte value_; 39 | 40 | private CompactionStyle(byte value) { 41 | value_ = value; 42 | } 43 | 44 | /** 45 | * Returns the byte value of the enumerations value 46 | * 47 | * @return byte representation 48 | */ 49 | public byte getValue() { 50 | return value_; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/Comparator.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Base class for comparators which will receive 10 | * byte[] based access via org.rocksdb.Slice in their 11 | * compare method implementation. 12 | * 13 | * byte[] based slices perform better when small keys 14 | * are involved. When using larger keys consider 15 | * using @see org.rocksdb.DirectComparator 16 | */ 17 | public abstract class Comparator extends AbstractComparator { 18 | public Comparator(final ComparatorOptions copt) { 19 | super(); 20 | createNewComparator0(copt.nativeHandle_); 21 | } 22 | 23 | private native void createNewComparator0(final long comparatorOptionsHandle); 24 | } 25 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/DirectComparator.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Base class for comparators which will receive 10 | * ByteBuffer based access via org.rocksdb.DirectSlice 11 | * in their compare method implementation. 12 | * 13 | * ByteBuffer based slices perform better when large keys 14 | * are involved. When using smaller keys consider 15 | * using @see org.rocksdb.Comparator 16 | */ 17 | public abstract class DirectComparator extends AbstractComparator { 18 | public DirectComparator(final ComparatorOptions copt) { 19 | super(); 20 | createNewDirectComparator0(copt.nativeHandle_); 21 | } 22 | 23 | private native void createNewDirectComparator0(final long comparatorOptionsHandle); 24 | } 25 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/Filter.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Filters are stored in rocksdb and are consulted automatically 10 | * by rocksdb to decide whether or not to read some 11 | * information from disk. In many cases, a filter can cut down the 12 | * number of disk seeks form a handful to a single disk seek per 13 | * DB::Get() call. 14 | */ 15 | public abstract class Filter extends RocksObject { 16 | protected abstract void createNewFilter(); 17 | 18 | /** 19 | * Deletes underlying C++ filter pointer. 20 | * 21 | * Note that this function should be called only after all 22 | * RocksDB instances referencing the filter are closed. 23 | * Otherwise an undefined behavior will occur. 24 | */ 25 | @Override protected void disposeInternal() { 26 | assert(isInitialized()); 27 | disposeInternal(nativeHandle_); 28 | } 29 | 30 | private native void disposeInternal(long handle); 31 | } 32 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/FlushOptions.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb; 2 | 3 | /** 4 | * FlushOptions to be passed to flush operations of 5 | * {@link org.rocksdb.RocksDB}. 6 | */ 7 | public class FlushOptions extends RocksObject { 8 | 9 | /** 10 | * Construct a new instance of FlushOptions. 11 | */ 12 | public FlushOptions(){ 13 | super(); 14 | newFlushOptions(); 15 | } 16 | 17 | /** 18 | * Set if the flush operation shall block until it terminates. 19 | * 20 | * @param waitForFlush boolean value indicating if the flush 21 | * operations waits for termination of the flush process. 22 | * 23 | * @return instance of current FlushOptions. 24 | */ 25 | public FlushOptions setWaitForFlush(final boolean waitForFlush) { 26 | assert(isInitialized()); 27 | setWaitForFlush(nativeHandle_, waitForFlush); 28 | return this; 29 | } 30 | 31 | /** 32 | * Wait for flush to finished. 33 | * 34 | * @return boolean value indicating if the flush operation 35 | * waits for termination of the flush process. 36 | */ 37 | public boolean waitForFlush() { 38 | assert(isInitialized()); 39 | return waitForFlush(nativeHandle_); 40 | } 41 | 42 | @Override protected void disposeInternal() { 43 | disposeInternal(nativeHandle_); 44 | } 45 | 46 | private native void newFlushOptions(); 47 | private native void disposeInternal(long handle); 48 | private native void setWaitForFlush(long handle, 49 | boolean wait); 50 | private native boolean waitForFlush(long handle); 51 | } 52 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/HistogramData.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | public class HistogramData { 9 | private final double median_; 10 | private final double percentile95_; 11 | private final double percentile99_; 12 | private final double average_; 13 | private final double standardDeviation_; 14 | 15 | public HistogramData(final double median, final double percentile95, 16 | final double percentile99, final double average, 17 | final double standardDeviation) { 18 | median_ = median; 19 | percentile95_ = percentile95; 20 | percentile99_ = percentile99; 21 | average_ = average; 22 | standardDeviation_ = standardDeviation; 23 | } 24 | 25 | public double getMedian() { 26 | return median_; 27 | } 28 | 29 | public double getPercentile95() { 30 | return percentile95_; 31 | } 32 | 33 | public double getPercentile99() { 34 | return percentile99_; 35 | } 36 | 37 | public double getAverage() { 38 | return average_; 39 | } 40 | 41 | public double getStandardDeviation() { 42 | return standardDeviation_; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/HistogramType.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | public enum HistogramType { 9 | DB_GET(0), 10 | DB_WRITE(1), 11 | COMPACTION_TIME(2), 12 | TABLE_SYNC_MICROS(3), 13 | COMPACTION_OUTFILE_SYNC_MICROS(4), 14 | WAL_FILE_SYNC_MICROS(5), 15 | MANIFEST_FILE_SYNC_MICROS(6), 16 | // TIME SPENT IN IO DURING TABLE OPEN 17 | TABLE_OPEN_IO_MICROS(7), 18 | DB_MULTIGET(8), 19 | READ_BLOCK_COMPACTION_MICROS(9), 20 | READ_BLOCK_GET_MICROS(10), 21 | WRITE_RAW_BLOCK_MICROS(11), 22 | STALL_L0_SLOWDOWN_COUNT(12), 23 | STALL_MEMTABLE_COMPACTION_COUNT(13), 24 | STALL_L0_NUM_FILES_COUNT(14), 25 | HARD_RATE_LIMIT_DELAY_COUNT(15), 26 | SOFT_RATE_LIMIT_DELAY_COUNT(16), 27 | NUM_FILES_IN_SINGLE_COMPACTION(17), 28 | DB_SEEK(18), 29 | WRITE_STALL(19); 30 | 31 | private final int value_; 32 | 33 | private HistogramType(int value) { 34 | value_ = value; 35 | } 36 | 37 | public int getValue() { 38 | return value_; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/IndexType.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * IndexType used in conjunction with BlockBasedTable. 10 | */ 11 | public enum IndexType { 12 | /** 13 | * A space efficient index block that is optimized for 14 | * binary-search-based index. 15 | */ 16 | kBinarySearch((byte) 0), 17 | /** 18 | * The hash index, if enabled, will do the hash lookup when 19 | * {@code Options.prefix_extractor} is provided. 20 | */ 21 | kHashSearch((byte) 1); 22 | 23 | /** 24 | * Returns the byte value of the enumerations value 25 | * 26 | * @return byte representation 27 | */ 28 | public byte getValue() { 29 | return value_; 30 | } 31 | 32 | private IndexType(byte value) { 33 | value_ = value; 34 | } 35 | 36 | private final byte value_; 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/InfoLogLevel.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb; 2 | 3 | /** 4 | * RocksDB log levels. 5 | */ 6 | public enum InfoLogLevel { 7 | DEBUG_LEVEL((byte)0), 8 | INFO_LEVEL((byte)1), 9 | WARN_LEVEL((byte)2), 10 | ERROR_LEVEL((byte)3), 11 | FATAL_LEVEL((byte)4), 12 | NUM_INFO_LOG_LEVELS((byte)5); 13 | 14 | private final byte value_; 15 | 16 | private InfoLogLevel(byte value) { 17 | value_ = value; 18 | } 19 | 20 | /** 21 | * Returns the byte value of the enumerations value 22 | * 23 | * @return byte representation 24 | */ 25 | public byte getValue() { 26 | return value_; 27 | } 28 | 29 | /** 30 | * Get InfoLogLevel by byte value. 31 | * 32 | * @param value byte representation of InfoLogLevel. 33 | * 34 | * @return {@link org.rocksdb.InfoLogLevel} instance or null. 35 | * @throws java.lang.IllegalArgumentException if an invalid 36 | * value is provided. 37 | */ 38 | public static InfoLogLevel getInfoLogLevel(byte value) { 39 | for (InfoLogLevel infoLogLevel : InfoLogLevel.values()) { 40 | if (infoLogLevel.getValue() == value){ 41 | return infoLogLevel; 42 | } 43 | } 44 | throw new IllegalArgumentException( 45 | "Illegal value provided for InfoLogLevel."); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/MemTableConfig.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | /** 8 | * MemTableConfig is used to config the internal mem-table of a RocksDB. 9 | * It is required for each memtable to have one such sub-class to allow 10 | * Java developers to use it. 11 | * 12 | * To make a RocksDB to use a specific MemTable format, its associated 13 | * MemTableConfig should be properly set and passed into Options 14 | * via Options.setMemTableFactory() and open the db using that Options. 15 | * 16 | * @see Options 17 | */ 18 | public abstract class MemTableConfig { 19 | /** 20 | * This function should only be called by Options.setMemTableConfig(), 21 | * which will create a c++ shared-pointer to the c++ MemTableRepFactory 22 | * that associated with the Java MemTableConfig. 23 | * 24 | * @see Options#setMemTableConfig(MemTableConfig) 25 | * 26 | * @return native handle address to native memory table instance. 27 | */ 28 | abstract protected long newMemTableFactoryHandle(); 29 | } 30 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/MergeOperator.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Vlad Balan (vlad.gm@gmail.com). All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * MergeOperator holds an operator to be applied when compacting 10 | * two merge operands held under the same key in order to obtain a single 11 | * value. 12 | */ 13 | public interface MergeOperator { 14 | long newMergeOperatorHandle(); 15 | } 16 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RateLimiterConfig.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | /** 8 | * Config for rate limiter, which is used to control write rate of flush and 9 | * compaction. 10 | */ 11 | public abstract class RateLimiterConfig { 12 | /** 13 | * This function should only be called by 14 | * {@link org.rocksdb.DBOptions#setRateLimiter(long, long)}, which will 15 | * create a c++ shared-pointer to the c++ {@code RateLimiter} that is associated 16 | * with a Java RateLimiterConfig. 17 | * 18 | * @see org.rocksdb.DBOptions#setRateLimiter(long, long) 19 | * 20 | * @return native handle address to rate limiter instance. 21 | */ 22 | abstract protected long newRateLimiterHandle(); 23 | } 24 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RemoveEmptyValueCompactionFilter.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Just a Java wrapper around EmptyValueCompactionFilter implemented in C++ 10 | */ 11 | public class RemoveEmptyValueCompactionFilter extends AbstractCompactionFilter { 12 | public RemoveEmptyValueCompactionFilter() { 13 | super(); 14 | createNewRemoveEmptyValueCompactionFilter0(); 15 | } 16 | 17 | private native void createNewRemoveEmptyValueCompactionFilter0(); 18 | } 19 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RestoreOptions.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * RestoreOptions to control the behavior of restore. 10 | * 11 | * Note that dispose() must be called before this instance become out-of-scope 12 | * to release the allocated memory in c++. 13 | * 14 | */ 15 | public class RestoreOptions extends RocksObject { 16 | /** 17 | * Constructor 18 | * 19 | * @param keepLogFiles If true, restore won't overwrite the existing log files in wal_dir. It 20 | * will also move all log files from archive directory to wal_dir. Use this 21 | * option in combination with BackupableDBOptions::backup_log_files = false 22 | * for persisting in-memory databases. 23 | * Default: false 24 | */ 25 | public RestoreOptions(final boolean keepLogFiles) { 26 | super(); 27 | nativeHandle_ = newRestoreOptions(keepLogFiles); 28 | } 29 | 30 | /** 31 | * Release the memory allocated for the current instance 32 | * in the c++ side. 33 | */ 34 | @Override public synchronized void disposeInternal() { 35 | assert(isInitialized()); 36 | dispose(nativeHandle_); 37 | } 38 | 39 | private native long newRestoreOptions(boolean keepLogFiles); 40 | private native void dispose(long handle); 41 | } 42 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RocksDBException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * A RocksDBException encapsulates the error of an operation. This exception 10 | * type is used to describe an internal error from the c++ rocksdb library. 11 | */ 12 | public class RocksDBException extends Exception { 13 | /** 14 | * The private construct used by a set of public static factory method. 15 | * 16 | * @param msg the specified error message. 17 | */ 18 | public RocksDBException(final String msg) { 19 | super(msg); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RocksEnv.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | *

A RocksEnv is an interface used by the rocksdb implementation to access 10 | * operating system functionality like the filesystem etc.

11 | * 12 | *

All Env implementations are safe for concurrent access from 13 | * multiple threads without any external synchronization.

14 | */ 15 | public class RocksEnv extends Env { 16 | 17 | /** 18 | *

Package-private constructor that uses the specified native handle 19 | * to construct a RocksEnv.

20 | * 21 | *

Note that the ownership of the input handle 22 | * belongs to the caller, and the newly created RocksEnv will not take 23 | * the ownership of the input handle. As a result, calling 24 | * {@code dispose()} of the created RocksEnv will be no-op.

25 | */ 26 | RocksEnv(final long handle) { 27 | super(); 28 | nativeHandle_ = handle; 29 | disOwnNativeHandle(); 30 | } 31 | 32 | /** 33 | *

The helper function of {@link #dispose()} which all subclasses of 34 | * {@link RocksObject} must implement to release their associated C++ 35 | * resource.

36 | * 37 | *

Note: this class is used to use the default 38 | * RocksEnv with RocksJava. The default env allocation is managed 39 | * by C++.

40 | */ 41 | @Override protected void disposeInternal() { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/RocksMemEnv.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * RocksDB memory environment. 10 | */ 11 | public class RocksMemEnv extends Env { 12 | 13 | /** 14 | *

Creates a new RocksDB environment that stores its data 15 | * in memory and delegates all non-file-storage tasks to 16 | * base_env. The caller must delete the result when it is 17 | * no longer needed.

18 | * 19 | *

{@code *base_env} must remain live while the result is in use.

20 | */ 21 | public RocksMemEnv() { 22 | super(); 23 | nativeHandle_ = createMemEnv(); 24 | } 25 | 26 | @Override 27 | protected void disposeInternal() { 28 | disposeInternal(nativeHandle_); 29 | } 30 | 31 | private static native long createMemEnv(); 32 | private native void disposeInternal(long handle); 33 | } 34 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/SkipListMemTableConfig.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb; 2 | 3 | /** 4 | * The config for skip-list memtable representation. 5 | */ 6 | public class SkipListMemTableConfig extends MemTableConfig { 7 | 8 | public static final long DEFAULT_LOOKAHEAD = 0; 9 | 10 | /** 11 | * SkipListMemTableConfig constructor 12 | */ 13 | public SkipListMemTableConfig() { 14 | lookahead_ = DEFAULT_LOOKAHEAD; 15 | } 16 | 17 | /** 18 | * Sets lookahead for SkipList 19 | * 20 | * @param lookahead If non-zero, each iterator's seek operation 21 | * will start the search from the previously visited record 22 | * (doing at most 'lookahead' steps). This is an 23 | * optimization for the access pattern including many 24 | * seeks with consecutive keys. 25 | * @return the current instance of SkipListMemTableConfig 26 | */ 27 | public SkipListMemTableConfig setLookahead(final long lookahead) { 28 | lookahead_ = lookahead; 29 | return this; 30 | } 31 | 32 | /** 33 | * Returns the currently set lookahead value. 34 | * 35 | * @return lookahead value 36 | */ 37 | public long lookahead() { 38 | return lookahead_; 39 | } 40 | 41 | 42 | @Override protected long newMemTableFactoryHandle() { 43 | return newMemTableFactoryHandle0(lookahead_); 44 | } 45 | 46 | private native long newMemTableFactoryHandle0(long lookahead) 47 | throws IllegalArgumentException; 48 | 49 | private long lookahead_; 50 | } 51 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/Snapshot.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Snapshot of database 10 | */ 11 | public class Snapshot extends RocksObject { 12 | Snapshot(final long nativeHandle) { 13 | super(); 14 | nativeHandle_ = nativeHandle; 15 | } 16 | 17 | /** 18 | * Return the associated sequence number; 19 | * 20 | * @return the associated sequence number of 21 | * this snapshot. 22 | */ 23 | public long getSequenceNumber() { 24 | assert(isInitialized()); 25 | return getSequenceNumber(nativeHandle_); 26 | } 27 | 28 | /** 29 | * Dont release C++ Snapshot pointer. The pointer 30 | * to the snapshot is released by the database 31 | * instance. 32 | */ 33 | @Override protected void disposeInternal() { 34 | } 35 | 36 | private native long getSequenceNumber(long handle); 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/Statistics.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Statistics to analyze the performance of a db. Pointer for statistics object 10 | * is managed by Options class. 11 | */ 12 | public class Statistics { 13 | 14 | private final long statsHandle_; 15 | 16 | public Statistics(final long statsHandle) { 17 | statsHandle_ = statsHandle; 18 | } 19 | 20 | public long getTickerCount(TickerType tickerType) { 21 | assert(isInitialized()); 22 | return getTickerCount0(tickerType.getValue(), statsHandle_); 23 | } 24 | 25 | public HistogramData geHistogramData(final HistogramType histogramType) { 26 | assert(isInitialized()); 27 | return geHistogramData0( 28 | histogramType.getValue(), statsHandle_); 29 | } 30 | 31 | private boolean isInitialized() { 32 | return (statsHandle_ != 0); 33 | } 34 | 35 | private native long getTickerCount0(int tickerType, long handle); 36 | private native HistogramData geHistogramData0(int histogramType, long handle); 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/StatisticsCollectorCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Callback interface provided to StatisticsCollector. 10 | * 11 | * Thread safety: 12 | * StatisticsCollector doesn't make any guarantees about thread safety. 13 | * If the same reference of StatisticsCollectorCallback is passed to multiple 14 | * StatisticsCollector references, then its the responsibility of the 15 | * user to make StatisticsCollectorCallback's implementation thread-safe. 16 | * 17 | */ 18 | public interface StatisticsCollectorCallback { 19 | /** 20 | * Callback function to get ticker values. 21 | * @param tickerType Ticker type. 22 | * @param tickerCount Value of ticker type. 23 | */ 24 | void tickerCallback(TickerType tickerType, long tickerCount); 25 | 26 | /** 27 | * Callback function to get histogram values. 28 | * @param histType Histogram type. 29 | * @param histData Histogram data. 30 | */ 31 | void histogramCallback(HistogramType histType, HistogramData histData); 32 | } 33 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/StatsCollectorInput.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Contains all information necessary to collect statistics from one instance 10 | * of DB statistics. 11 | */ 12 | public class StatsCollectorInput { 13 | private final Statistics _statistics; 14 | private final StatisticsCollectorCallback _statsCallback; 15 | 16 | /** 17 | * Constructor for StatsCollectorInput. 18 | * 19 | * @param statistics Reference of DB statistics. 20 | * @param statsCallback Reference of statistics callback interface. 21 | */ 22 | public StatsCollectorInput(final Statistics statistics, 23 | final StatisticsCollectorCallback statsCallback) { 24 | _statistics = statistics; 25 | _statsCallback = statsCallback; 26 | } 27 | 28 | public Statistics getStatistics() { 29 | return _statistics; 30 | } 31 | 32 | public StatisticsCollectorCallback getCallback() { 33 | return _statsCallback; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/StringAppendOperator.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Vlad Balan (vlad.gm@gmail.com). All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * StringAppendOperator is a merge operator that concatenates 10 | * two strings. 11 | */ 12 | public class StringAppendOperator implements MergeOperator { 13 | @Override public long newMergeOperatorHandle() { 14 | return newMergeOperatorHandleImpl(); 15 | } 16 | private native long newMergeOperatorHandleImpl(); 17 | } 18 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/TableFormatConfig.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | /** 8 | * TableFormatConfig is used to config the internal Table format of a RocksDB. 9 | * To make a RocksDB to use a specific Table format, its associated 10 | * TableFormatConfig should be properly set and passed into Options via 11 | * Options.setTableFormatConfig() and open the db using that Options. 12 | */ 13 | public abstract class TableFormatConfig { 14 | /** 15 | *

This function should only be called by Options.setTableFormatConfig(), 16 | * which will create a c++ shared-pointer to the c++ TableFactory 17 | * that associated with the Java TableFormatConfig.

18 | * 19 | * @return native handle address to native table instance. 20 | */ 21 | abstract protected long newTableFactoryHandle(); 22 | } 23 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/VectorMemTableConfig.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb; 2 | 3 | /** 4 | * The config for vector memtable representation. 5 | */ 6 | public class VectorMemTableConfig extends MemTableConfig { 7 | public static final int DEFAULT_RESERVED_SIZE = 0; 8 | 9 | /** 10 | * VectorMemTableConfig constructor 11 | */ 12 | public VectorMemTableConfig() { 13 | reservedSize_ = DEFAULT_RESERVED_SIZE; 14 | } 15 | 16 | /** 17 | * Set the initial size of the vector that will be used 18 | * by the memtable created based on this config. 19 | * 20 | * @param size the initial size of the vector. 21 | * @return the reference to the current config. 22 | */ 23 | public VectorMemTableConfig setReservedSize(final int size) { 24 | reservedSize_ = size; 25 | return this; 26 | } 27 | 28 | /** 29 | * Returns the initial size of the vector used by the memtable 30 | * created based on this config. 31 | * 32 | * @return the initial size of the vector. 33 | */ 34 | public int reservedSize() { 35 | return reservedSize_; 36 | } 37 | 38 | @Override protected long newMemTableFactoryHandle() { 39 | return newMemTableFactoryHandle(reservedSize_); 40 | } 41 | 42 | private native long newMemTableFactoryHandle(long reservedSize) 43 | throws IllegalArgumentException; 44 | private int reservedSize_; 45 | } 46 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/util/Environment.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb.util; 2 | 3 | public class Environment { 4 | private static String OS = System.getProperty("os.name").toLowerCase(); 5 | private static String ARCH = System.getProperty("os.arch").toLowerCase(); 6 | 7 | public static boolean isWindows() { 8 | return (OS.contains("win")); 9 | } 10 | 11 | public static boolean isMac() { 12 | return (OS.contains("mac")); 13 | } 14 | 15 | public static boolean isUnix() { 16 | return (OS.contains("nix") || 17 | OS.contains("nux") || 18 | OS.contains("aix")); 19 | } 20 | 21 | public static boolean is64Bit() { 22 | return (ARCH.indexOf("64") > 0); 23 | } 24 | 25 | public static String getSharedLibraryName(final String name) { 26 | return name + "jni"; 27 | } 28 | 29 | public static String getSharedLibraryFileName(final String name) { 30 | return appendLibOsSuffix("lib" + getSharedLibraryName(name), true); 31 | } 32 | 33 | public static String getJniLibraryName(final String name) { 34 | if (isUnix()) { 35 | final String arch = (is64Bit()) ? "64" : "32"; 36 | return String.format("%sjni-linux%s", name, arch); 37 | } else if (isMac()) { 38 | return String.format("%sjni-osx", name); 39 | } 40 | throw new UnsupportedOperationException(); 41 | } 42 | 43 | public static String getJniLibraryFileName(final String name) { 44 | return appendLibOsSuffix("lib" + getJniLibraryName(name), false); 45 | } 46 | 47 | private static String appendLibOsSuffix(final String libraryFileName, final boolean shared) { 48 | if (isUnix()) { 49 | return libraryFileName + ".so"; 50 | } else if (isMac()) { 51 | return libraryFileName + (shared ? ".dylib" : ".jnilib"); 52 | } 53 | throw new UnsupportedOperationException(); 54 | } 55 | 56 | public static String getJniLibraryExtension() { 57 | return (isMac()) ? ".jnilib" : ".so"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /java/src/main/java/org/rocksdb/util/SizeUnit.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb.util; 7 | 8 | public class SizeUnit { 9 | public static final long KB = 1024L; 10 | public static final long MB = KB * KB; 11 | public static final long GB = KB * MB; 12 | public static final long TB = KB * GB; 13 | public static final long PB = KB * TB; 14 | 15 | private SizeUnit() {} 16 | } 17 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/ComparatorOptionsTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.ClassRule; 9 | import org.junit.Test; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class ComparatorOptionsTest { 14 | 15 | @ClassRule 16 | public static final RocksMemoryResource rocksMemoryResource = 17 | new RocksMemoryResource(); 18 | 19 | @Test 20 | public void comparatorOptions() { 21 | final ComparatorOptions copt = new ComparatorOptions(); 22 | 23 | assertThat(copt).isNotNull(); 24 | 25 | { // UseAdaptiveMutex test 26 | copt.setUseAdaptiveMutex(true); 27 | assertThat(copt.useAdaptiveMutex()).isTrue(); 28 | 29 | copt.setUseAdaptiveMutex(false); 30 | assertThat(copt.useAdaptiveMutex()).isFalse(); 31 | } 32 | 33 | copt.dispose(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/CompressionOptionsTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.Test; 9 | 10 | 11 | public class CompressionOptionsTest 12 | { 13 | @Test 14 | public void getCompressionType() { 15 | for (CompressionType compressionType : CompressionType.values()) { 16 | String libraryName = compressionType.getLibraryName(); 17 | compressionType.equals(CompressionType.getCompressionType( 18 | libraryName)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/DirectComparatorTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.ClassRule; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.rules.TemporaryFolder; 12 | 13 | import java.io.IOException; 14 | import java.nio.file.FileSystems; 15 | 16 | public class DirectComparatorTest { 17 | @ClassRule 18 | public static final RocksMemoryResource rocksMemoryResource = 19 | new RocksMemoryResource(); 20 | 21 | @Rule 22 | public TemporaryFolder dbFolder = new TemporaryFolder(); 23 | 24 | @Test 25 | public void directComparator() throws IOException, RocksDBException { 26 | 27 | final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() { 28 | @Override 29 | public AbstractComparator getAscendingIntKeyComparator() { 30 | return new DirectComparator(new ComparatorOptions()) { 31 | 32 | @Override 33 | public String name() { 34 | return "test.AscendingIntKeyDirectComparator"; 35 | } 36 | 37 | @Override 38 | public int compare(final DirectSlice a, final DirectSlice b) { 39 | final byte ax[] = new byte[4], bx[] = new byte[4]; 40 | a.data().get(ax); 41 | b.data().get(bx); 42 | return compareIntKeys(ax, bx); 43 | } 44 | }; 45 | } 46 | }; 47 | 48 | // test the round-tripability of keys written and read with the DirectComparator 49 | comparatorTest.testRoundtrip(FileSystems.getDefault().getPath( 50 | dbFolder.getRoot().getAbsolutePath())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/FilterTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.ClassRule; 9 | import org.junit.Test; 10 | 11 | public class FilterTest { 12 | 13 | @ClassRule 14 | public static final RocksMemoryResource rocksMemoryResource = 15 | new RocksMemoryResource(); 16 | 17 | @Test 18 | public void filter() { 19 | Options options = null; 20 | try { 21 | options = new Options(); 22 | // test table config 23 | options.setTableFormatConfig(new BlockBasedTableConfig(). 24 | setFilter(new BloomFilter())); 25 | options.dispose(); 26 | System.gc(); 27 | System.runFinalization(); 28 | // new Bloom filter 29 | options = new Options(); 30 | BlockBasedTableConfig blockConfig = new BlockBasedTableConfig(); 31 | blockConfig.setFilter(new BloomFilter()); 32 | options.setTableFormatConfig(blockConfig); 33 | BloomFilter bloomFilter = new BloomFilter(10); 34 | blockConfig.setFilter(bloomFilter); 35 | options.setTableFormatConfig(blockConfig); 36 | System.gc(); 37 | System.runFinalization(); 38 | blockConfig.setFilter(new BloomFilter(10, false)); 39 | options.setTableFormatConfig(blockConfig); 40 | 41 | } finally { 42 | if (options != null) { 43 | options.dispose(); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/NativeLibraryLoaderTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb; 6 | 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.TemporaryFolder; 10 | import org.rocksdb.util.Environment; 11 | 12 | import java.io.IOException; 13 | import java.nio.file.*; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | 17 | public class NativeLibraryLoaderTest { 18 | 19 | @Rule 20 | public TemporaryFolder temporaryFolder = new TemporaryFolder(); 21 | 22 | @Test 23 | public void tempFolder() throws IOException { 24 | NativeLibraryLoader.getInstance().loadLibraryFromJar( 25 | temporaryFolder.getRoot().getAbsolutePath()); 26 | Path path = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), 27 | Environment.getJniLibraryFileName("rocksdb")); 28 | assertThat(Files.exists(path)).isTrue(); 29 | assertThat(Files.isReadable(path)).isTrue(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/RocksEnvTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.ClassRule; 9 | import org.junit.Test; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class RocksEnvTest { 14 | 15 | @ClassRule 16 | public static final RocksMemoryResource rocksMemoryResource = 17 | new RocksMemoryResource(); 18 | 19 | @Test 20 | public void rocksEnv(){ 21 | Env rocksEnv = RocksEnv.getDefault(); 22 | rocksEnv.setBackgroundThreads(5); 23 | // default rocksenv will always return zero for flush pool 24 | // no matter what was set via setBackgroundThreads 25 | assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.FLUSH_POOL)). 26 | isEqualTo(0); 27 | rocksEnv.setBackgroundThreads(5, RocksEnv.FLUSH_POOL); 28 | // default rocksenv will always return zero for flush pool 29 | // no matter what was set via setBackgroundThreads 30 | assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.FLUSH_POOL)). 31 | isEqualTo(0); 32 | rocksEnv.setBackgroundThreads(5, RocksEnv.COMPACTION_POOL); 33 | // default rocksenv will always return zero for compaction pool 34 | // no matter what was set via setBackgroundThreads 35 | assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.COMPACTION_POOL)). 36 | isEqualTo(0); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/RocksMemoryResource.java: -------------------------------------------------------------------------------- 1 | package org.rocksdb; 2 | 3 | import org.junit.rules.ExternalResource; 4 | 5 | /** 6 | * Resource to trigger garbage collection after each test 7 | * run. 8 | */ 9 | public class RocksMemoryResource extends ExternalResource { 10 | 11 | static { 12 | RocksDB.loadLibrary(); 13 | } 14 | 15 | @Override 16 | protected void after() { 17 | System.gc(); 18 | System.runFinalization(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/StatsCallbackMock.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | public class StatsCallbackMock implements StatisticsCollectorCallback { 9 | public int tickerCallbackCount = 0; 10 | public int histCallbackCount = 0; 11 | 12 | public void tickerCallback(TickerType tickerType, long tickerCount) { 13 | tickerCallbackCount++; 14 | } 15 | 16 | public void histogramCallback(HistogramType histType, 17 | HistogramData histData) { 18 | histCallbackCount++; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/Types.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | /** 9 | * Simple type conversion methods 10 | * for use in tests 11 | */ 12 | public class Types { 13 | 14 | /** 15 | * Convert first 4 bytes of a byte array to an int 16 | * 17 | * @param data The byte array 18 | * 19 | * @return An integer 20 | */ 21 | public static int byteToInt(final byte data[]) { 22 | return (data[0] & 0xff) | 23 | ((data[1] & 0xff) << 8) | 24 | ((data[2] & 0xff) << 16) | 25 | ((data[3] & 0xff) << 24); 26 | } 27 | 28 | /** 29 | * Convert an int to 4 bytes 30 | * 31 | * @param v The int 32 | * 33 | * @return A byte array containing 4 bytes 34 | */ 35 | public static byte[] intToByte(final int v) { 36 | return new byte[] { 37 | (byte)((v >>> 0) & 0xff), 38 | (byte)((v >>> 8) & 0xff), 39 | (byte)((v >>> 16) & 0xff), 40 | (byte)((v >>> 24) & 0xff) 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/WriteOptionsTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | package org.rocksdb; 7 | 8 | import org.junit.ClassRule; 9 | import org.junit.Test; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class WriteOptionsTest { 14 | 15 | @ClassRule 16 | public static final RocksMemoryResource rocksMemoryResource = 17 | new RocksMemoryResource(); 18 | 19 | @Test 20 | public void writeOptions(){ 21 | WriteOptions writeOptions = new WriteOptions(); 22 | writeOptions.setDisableWAL(true); 23 | assertThat(writeOptions.disableWAL()).isTrue(); 24 | writeOptions.setDisableWAL(false); 25 | assertThat(writeOptions.disableWAL()).isFalse(); 26 | writeOptions.setSync(true); 27 | assertThat(writeOptions.sync()).isTrue(); 28 | writeOptions.setSync(false); 29 | assertThat(writeOptions.sync()).isFalse(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/src/test/java/org/rocksdb/util/SizeUnitTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | package org.rocksdb.util; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | public class SizeUnitTest { 12 | 13 | public static final long COMPUTATION_UNIT = 1024L; 14 | 15 | @Test 16 | public void sizeUnit() { 17 | assertThat(SizeUnit.KB).isEqualTo(COMPUTATION_UNIT); 18 | assertThat(SizeUnit.MB).isEqualTo( 19 | SizeUnit.KB * COMPUTATION_UNIT); 20 | assertThat(SizeUnit.GB).isEqualTo( 21 | SizeUnit.MB * COMPUTATION_UNIT); 22 | assertThat(SizeUnit.TB).isEqualTo( 23 | SizeUnit.GB * COMPUTATION_UNIT); 24 | assertThat(SizeUnit.PB).isEqualTo( 25 | SizeUnit.TB * COMPUTATION_UNIT); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /port/dirent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | // See port_example.h for documentation for the following types/functions. 11 | 12 | #ifndef STORAGE_LEVELDB_PORT_DIRENT_H_ 13 | #define STORAGE_LEVELDB_PORT_DIRENT_H_ 14 | 15 | #if defined(ROCKSDB_PLATFORM_POSIX) || defined(ROCKSDB_PLATFORM_NVM) 16 | #include 17 | #include 18 | #elif defined(OS_WIN) 19 | 20 | namespace rocksdb { 21 | namespace port { 22 | 23 | struct dirent { 24 | char d_name[_MAX_PATH]; /* filename */ 25 | }; 26 | 27 | struct DIR; 28 | 29 | DIR* opendir(const char* name); 30 | 31 | dirent* readdir(DIR* dirp); 32 | 33 | int closedir(DIR* dirp); 34 | 35 | } // namespace port 36 | 37 | using port::dirent; 38 | using port::DIR; 39 | using port::opendir; 40 | using port::readdir; 41 | using port::closedir; 42 | 43 | } // namespace rocksdb 44 | 45 | #endif // OS_WIN 46 | 47 | #endif // STORAGE_LEVELDB_PORT_DIRENT_H_ 48 | -------------------------------------------------------------------------------- /port/likely.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | 10 | #ifndef PORT_LIKELY_H_ 11 | #define PORT_LIKELY_H_ 12 | 13 | #if defined(__GNUC__) && __GNUC__ >= 4 14 | #define LIKELY(x) (__builtin_expect((x), 1)) 15 | #define UNLIKELY(x) (__builtin_expect((x), 0)) 16 | #else 17 | #define LIKELY(x) (x) 18 | #define UNLIKELY(x) (x) 19 | #endif 20 | 21 | #endif // PORT_LIKELY_H_ 22 | -------------------------------------------------------------------------------- /port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | // Include the appropriate platform specific file below. If you are 15 | // porting to a new platform, see "port_example.h" for documentation 16 | // of what the new port_.h file must provide. 17 | #if defined(ROCKSDB_PLATFORM_POSIX) 18 | 19 | #include "port/port_posix.h" 20 | 21 | #elif defined (ROCKSDB_PLATFORM_NVM) 22 | 23 | #include "port/port_nvm.h" 24 | 25 | #elif defined(OS_WIN) 26 | 27 | #include "port/win/port_win.h" 28 | 29 | #else 30 | 31 | #error "unknown platform" 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /port/stack_trace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | #pragma once 7 | namespace rocksdb { 8 | namespace port { 9 | 10 | // Install a signal handler to print callstack on the following signals: 11 | // SIGILL SIGSEGV SIGBUS SIGABRT 12 | // Currently supports linux only. No-op otherwise. 13 | void InstallStackTraceHandler(); 14 | 15 | // Prints stack, skips skip_first_frames frames 16 | void PrintStack(int first_frames_to_skip = 0); 17 | 18 | } // namespace port 19 | } // namespace rocksdb 20 | -------------------------------------------------------------------------------- /port/sys_time.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | 10 | // This file is a portable substitute for sys/time.h which does not exist on 11 | // Windows 12 | 13 | #ifndef STORAGE_LEVELDB_PORT_SYS_TIME_H_ 14 | #define STORAGE_LEVELDB_PORT_SYS_TIME_H_ 15 | 16 | #if defined(OS_WIN) && defined(_MSC_VER) 17 | 18 | #include 19 | 20 | namespace rocksdb { 21 | 22 | namespace port { 23 | 24 | // Avoid including winsock2.h for this definition 25 | typedef struct timeval { 26 | long tv_sec; 27 | long tv_usec; 28 | } timeval; 29 | 30 | void gettimeofday(struct timeval* tv, struct timezone* tz); 31 | 32 | inline struct tm* localtime_r(const time_t* timep, struct tm* result) { 33 | errno_t ret = localtime_s(result, timep); 34 | return (ret == 0) ? result : NULL; 35 | } 36 | } 37 | 38 | using port::timeval; 39 | using port::gettimeofday; 40 | using port::localtime_r; 41 | } 42 | 43 | #else 44 | #include 45 | #include 46 | #endif 47 | 48 | #endif // STORAGE_LEVELDB_PORT_SYS_TIME_H_ 49 | -------------------------------------------------------------------------------- /port/util_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | 10 | #ifndef STORAGE_LEVELDB_PORT_UTIL_LOGGER_H_ 11 | #define STORAGE_LEVELDB_PORT_UTIL_LOGGER_H_ 12 | 13 | // Include the appropriate platform specific file below. If you are 14 | // porting to a new platform, see "port_example.h" for documentation 15 | // of what the new port_.h file must provide. 16 | 17 | #if defined(ROCKSDB_PLATFORM_POSIX) 18 | #include "util/posix_logger.h" 19 | #elif defined(OS_WIN) 20 | #include "port/win/win_logger.h" 21 | #endif 22 | 23 | #endif // STORAGE_LEVELDB_PORT_UTIL_LOGGER_H_ 24 | -------------------------------------------------------------------------------- /port/win/win_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style license that can be 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 | // 10 | // Logger implementation that can be shared by all environments 11 | // where enough posix functionality is available. 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "rocksdb/env.h" 18 | 19 | namespace rocksdb { 20 | 21 | class Env; 22 | 23 | const int kDebugLogChunkSize = 128 * 1024; 24 | 25 | class WinLogger : public rocksdb::Logger { 26 | public: 27 | WinLogger(uint64_t (*gettid)(), Env* env, HANDLE file, 28 | const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL); 29 | 30 | virtual ~WinLogger(); 31 | 32 | WinLogger(const WinLogger&) = delete; 33 | 34 | WinLogger& operator=(const WinLogger&) = delete; 35 | 36 | void close(); 37 | 38 | void Flush() override; 39 | 40 | void Logv(const char* format, va_list ap) override; 41 | 42 | size_t GetLogFileSize() const override; 43 | 44 | void DebugWriter(const char* str, int len); 45 | 46 | private: 47 | HANDLE file_; 48 | uint64_t (*gettid_)(); // Return the thread id for the current thread 49 | std::atomic_size_t log_size_; 50 | std::atomic_uint_fast64_t last_flush_micros_; 51 | Env* env_; 52 | bool flush_pending_; 53 | 54 | const static uint64_t flush_every_seconds_ = 5; 55 | }; 56 | 57 | } // namespace rocksdb 58 | -------------------------------------------------------------------------------- /table/bloom_block.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #include "table/bloom_block.h" 7 | 8 | #include 9 | #include "rocksdb/slice.h" 10 | #include "util/dynamic_bloom.h" 11 | 12 | namespace rocksdb { 13 | 14 | void BloomBlockBuilder::AddKeysHashes(const std::vector& keys_hashes) { 15 | for (auto hash : keys_hashes) { 16 | bloom_.AddHash(hash); 17 | } 18 | } 19 | 20 | Slice BloomBlockBuilder::Finish() { return bloom_.GetRawData(); } 21 | 22 | const std::string BloomBlockBuilder::kBloomBlock = "kBloomBlock"; 23 | } // namespace rocksdb 24 | -------------------------------------------------------------------------------- /table/bloom_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include "util/dynamic_bloom.h" 10 | 11 | namespace rocksdb { 12 | class Logger; 13 | 14 | class BloomBlockBuilder { 15 | public: 16 | static const std::string kBloomBlock; 17 | 18 | explicit BloomBlockBuilder(uint32_t num_probes = 6) 19 | : bloom_(num_probes, nullptr) {} 20 | 21 | void SetTotalBits(Allocator* allocator, uint32_t total_bits, 22 | uint32_t locality, size_t huge_page_tlb_size, 23 | Logger* logger) { 24 | bloom_.SetTotalBits(allocator, total_bits, locality, huge_page_tlb_size, 25 | logger); 26 | } 27 | 28 | uint32_t GetNumBlocks() const { return bloom_.GetNumBlocks(); } 29 | 30 | void AddKeysHashes(const std::vector& keys_hashes); 31 | 32 | Slice Finish(); 33 | 34 | private: 35 | DynamicBloom bloom_; 36 | }; 37 | 38 | }; // namespace rocksdb 39 | -------------------------------------------------------------------------------- /table/iter_heap.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // 6 | 7 | #pragma once 8 | 9 | #include "rocksdb/comparator.h" 10 | #include "table/iterator_wrapper.h" 11 | 12 | namespace rocksdb { 13 | 14 | // When used with std::priority_queue, this comparison functor puts the 15 | // iterator with the max/largest key on top. 16 | class MaxIteratorComparator { 17 | public: 18 | MaxIteratorComparator(const Comparator* comparator) : 19 | comparator_(comparator) {} 20 | 21 | bool operator()(IteratorWrapper* a, IteratorWrapper* b) const { 22 | return comparator_->Compare(a->key(), b->key()) < 0; 23 | } 24 | private: 25 | const Comparator* comparator_; 26 | }; 27 | 28 | // When used with std::priority_queue, this comparison functor puts the 29 | // iterator with the min/smallest key on top. 30 | class MinIteratorComparator { 31 | public: 32 | MinIteratorComparator(const Comparator* comparator) : 33 | comparator_(comparator) {} 34 | 35 | bool operator()(IteratorWrapper* a, IteratorWrapper* b) const { 36 | return comparator_->Compare(a->key(), b->key()) > 0; 37 | } 38 | private: 39 | const Comparator* comparator_; 40 | }; 41 | 42 | } // namespace rocksdb 43 | -------------------------------------------------------------------------------- /table/scoped_arena_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style license that can be 7 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 8 | #pragma once 9 | 10 | #include "table/internal_iterator.h" 11 | 12 | namespace rocksdb { 13 | class ScopedArenaIterator { 14 | public: 15 | explicit ScopedArenaIterator(InternalIterator* iter = nullptr) 16 | : iter_(iter) {} 17 | 18 | InternalIterator* operator->() { return iter_; } 19 | 20 | void set(InternalIterator* iter) { iter_ = iter; } 21 | 22 | InternalIterator* get() { return iter_; } 23 | 24 | ~ScopedArenaIterator() { iter_->~InternalIterator(); } 25 | 26 | private: 27 | InternalIterator* iter_; 28 | }; 29 | } // namespace rocksdb 30 | -------------------------------------------------------------------------------- /table/table_properties_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, Facebook, Inc. All rights reserved. 2 | // This source code is licensed under the BSD-style license found in the 3 | // LICENSE file in the root directory of this source tree. An additional grant 4 | // of patent rights can be found in the PATENTS file in the same directory. 5 | 6 | #pragma once 7 | 8 | #include "rocksdb/status.h" 9 | #include "rocksdb/iterator.h" 10 | 11 | namespace rocksdb { 12 | 13 | class InternalIterator; 14 | 15 | // Seek to the properties block. 16 | // If it successfully seeks to the properties block, "is_found" will be 17 | // set to true. 18 | Status SeekToPropertiesBlock(InternalIterator* meta_iter, bool* is_found); 19 | 20 | } // namespace rocksdb 21 | -------------------------------------------------------------------------------- /third-party/fbson/COMMIT.md: -------------------------------------------------------------------------------- 1 | fbson commit: 2 | https://github.com/facebook/mysql-5.6/commit/55ef9ff25c934659a70b4094e9b406c48e9dd43d 3 | 4 | # TODO. 5 | * Had to convert zero sized array to [1] sized arrays due to the fact that MS Compiler complains about it not being standard. At some point need to contribute this change back to MySql where this code was taken from. 6 | -------------------------------------------------------------------------------- /third-party/gtest-1.7.0/fused-src/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(gtest gtest-all.cc) 2 | -------------------------------------------------------------------------------- /tools/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM buildpack-deps:wheezy 2 | 3 | ADD ./ldb /rocksdb/tools/ldb 4 | 5 | CMD /rocksdb/tools/ldb 6 | -------------------------------------------------------------------------------- /tools/generate_random_db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # A shell script to load some pre generated data file to a DB using ldb tool 4 | # ./ldb needs to be avaible to be executed. 5 | # 6 | # Usage: