From 908258a4f2361d2c01cecbe75dfc4dcf7f9d8857 Mon Sep 17 00:00:00 2001 From: fyrz Date: Fri, 16 Jan 2015 23:00:30 +0100 Subject: [PATCH] [RocksJava] BlockBasedTableConfig 3.10 - Added support for format version in BlockBasedTableConfig --- java/org/rocksdb/BlockBasedTableConfig.java | 47 ++++++++++++++++++- .../test/BlockBasedTableConfigTest.java | 21 +++++++++ java/rocksjni/table.cc | 5 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/java/org/rocksdb/BlockBasedTableConfig.java b/java/org/rocksdb/BlockBasedTableConfig.java index 76e930204..0798be2b8 100644 --- a/java/org/rocksdb/BlockBasedTableConfig.java +++ b/java/org/rocksdb/BlockBasedTableConfig.java @@ -26,6 +26,7 @@ public class BlockBasedTableConfig extends TableFormatConfig { blockCacheCompressedNumShardBits_ = 0; checksumType_ = ChecksumType.kCRC32c; indexType_ = IndexType.kBinarySearch; + formatVersion_ = 0; } /** @@ -335,6 +336,46 @@ public class BlockBasedTableConfig extends TableFormatConfig { return indexType_; } + /** + *

For more details on BlockBasedTable's formats, see FORMAT-CHANGES.md + * We currently have three versions:

+ * + * + *

This option only affects newly written tables. When reading existing + * tables, the information about version is read from the footer.

+ * + * @param formatVersion integer representing the version to be used. + * @return the reference to the current option. + */ + public BlockBasedTableConfig setFormatVersion(int formatVersion) { + assert(formatVersion>=0 && formatVersion <=2); + formatVersion_ = formatVersion; + return this; + } + + /** + * + * @return the currently configured format version. + * See also: {@link #setFormatVersion(int)}. + */ + public int formatVersion() { + return formatVersion_; + } + + + @Override protected long newTableFactoryHandle() { long filterHandle = 0; if (filter_ != null) { @@ -347,7 +388,8 @@ public class BlockBasedTableConfig extends TableFormatConfig { filterHandle, cacheIndexAndFilterBlocks_, hashIndexAllowCollision_, blockCacheCompressedSize_, blockCacheCompressedNumShardBits_, - checksumType_.getValue(), indexType_.getValue()); + checksumType_.getValue(), indexType_.getValue(), + formatVersion_); } private native long newTableFactoryHandle( @@ -356,7 +398,7 @@ public class BlockBasedTableConfig extends TableFormatConfig { boolean wholeKeyFiltering, long filterPolicyHandle, boolean cacheIndexAndFilterBlocks, boolean hashIndexAllowCollision, long blockCacheCompressedSize, int blockCacheCompressedNumShardBits, - byte checkSumType, byte indexType); + byte checkSumType, byte indexType, int formatVersion); private boolean cacheIndexAndFilterBlocks_; private IndexType indexType_; @@ -372,4 +414,5 @@ public class BlockBasedTableConfig extends TableFormatConfig { private int blockRestartInterval_; private Filter filter_; private boolean wholeKeyFiltering_; + private int formatVersion_; } diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java index 5e0b96f29..1172effc8 100644 --- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java +++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java @@ -162,4 +162,25 @@ public class BlockBasedTableConfigTest { } } } + + @Test + public void blockBasedTableFormatVersion() { + BlockBasedTableConfig config = new BlockBasedTableConfig(); + for (int version=0; version<=2; version++) { + config.setFormatVersion(version); + assertThat(config.formatVersion()).isEqualTo(version); + } + } + + @Test(expected = AssertionError.class) + public void blockBasedTableFormatVersionFailNegative() { + BlockBasedTableConfig config = new BlockBasedTableConfig(); + config.setFormatVersion(-1); + } + + @Test(expected = AssertionError.class) + public void blockBasedTableFormatVersionFailIllegalVersion() { + BlockBasedTableConfig config = new BlockBasedTableConfig(); + config.setFormatVersion(3); + } } diff --git a/java/rocksjni/table.cc b/java/rocksjni/table.cc index 1b576a754..e78e7e0d7 100644 --- a/java/rocksjni/table.cc +++ b/java/rocksjni/table.cc @@ -38,7 +38,7 @@ jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle( /* * Class: org_rocksdb_BlockBasedTableConfig * Method: newTableFactoryHandle - * Signature: (ZJIJIIZIZZJIBB)J + * Signature: (ZJIJIIZIZZJIBBI)J */ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( JNIEnv* env, jobject jobj, jboolean no_block_cache, jlong block_cache_size, @@ -47,7 +47,7 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( jlong jfilterPolicy, jboolean cache_index_and_filter_blocks, jboolean hash_index_allow_collision, jlong block_cache_compressed_size, jint block_cache_compressd_num_shard_bits, jbyte jchecksum_type, - jbyte jindex_type) { + jbyte jindex_type, jint jformat_version) { rocksdb::BlockBasedTableOptions options; options.no_block_cache = no_block_cache; @@ -83,6 +83,7 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( options.checksum = static_cast(jchecksum_type); options.index_type = static_cast< rocksdb::BlockBasedTableOptions::IndexType>(jindex_type); + options.format_version = jformat_version; return reinterpret_cast(rocksdb::NewBlockBasedTableFactory(options)); }