fix java sample typo and replace deprecated code with latest (#7906)
Summary: 1. replace deprecated code in sample java with latest api 2. fix optimistictransaction sample code typo Pull Request resolved: https://github.com/facebook/rocksdb/pull/7906 Reviewed By: ajkr Differential Revision: D26127429 Pulled By: jay-zhuang fbshipit-source-id: f015ad1435f565cffb8798a4fb5afc44c72d73d7
This commit is contained in:
parent
87983d442c
commit
bf6795aea0
@ -111,7 +111,7 @@ public class OptimisticTransactionSample {
|
|||||||
// Read a key using the snapshot.
|
// Read a key using the snapshot.
|
||||||
readOptions.setSnapshot(snapshot);
|
readOptions.setSnapshot(snapshot);
|
||||||
final byte[] value = txn.getForUpdate(readOptions, key1, true);
|
final byte[] value = txn.getForUpdate(readOptions, key1, true);
|
||||||
assert(value == value1);
|
assert (value == null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Attempt to commit transaction
|
// Attempt to commit transaction
|
||||||
|
@ -53,8 +53,8 @@ public class RocksDBColumnFamilySample {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// put and get from non-default column family
|
// put and get from non-default column family
|
||||||
db.put(columnFamilyHandles.get(0), new WriteOptions(),
|
db.put(
|
||||||
"key".getBytes(), "value".getBytes());
|
columnFamilyHandles.get(1), new WriteOptions(), "key".getBytes(), "value".getBytes());
|
||||||
|
|
||||||
// atomic write
|
// atomic write
|
||||||
try (final WriteBatch wb = new WriteBatch()) {
|
try (final WriteBatch wb = new WriteBatch()) {
|
||||||
@ -62,7 +62,7 @@ public class RocksDBColumnFamilySample {
|
|||||||
"value2".getBytes());
|
"value2".getBytes());
|
||||||
wb.put(columnFamilyHandles.get(1), "key3".getBytes(),
|
wb.put(columnFamilyHandles.get(1), "key3".getBytes(),
|
||||||
"value3".getBytes());
|
"value3".getBytes());
|
||||||
wb.remove(columnFamilyHandles.get(0), "key".getBytes());
|
wb.delete(columnFamilyHandles.get(1), "key".getBytes());
|
||||||
db.write(new WriteOptions(), wb);
|
db.write(new WriteOptions(), wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class RocksDBSample {
|
|||||||
.setStatistics(stats)
|
.setStatistics(stats)
|
||||||
.setWriteBufferSize(8 * SizeUnit.KB)
|
.setWriteBufferSize(8 * SizeUnit.KB)
|
||||||
.setMaxWriteBufferNumber(3)
|
.setMaxWriteBufferNumber(3)
|
||||||
.setMaxBackgroundCompactions(10)
|
.setMaxBackgroundJobs(10)
|
||||||
.setCompressionType(CompressionType.SNAPPY_COMPRESSION)
|
.setCompressionType(CompressionType.SNAPPY_COMPRESSION)
|
||||||
.setCompactionStyle(CompactionStyle.UNIVERSAL);
|
.setCompactionStyle(CompactionStyle.UNIVERSAL);
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
@ -55,7 +55,7 @@ public class RocksDBSample {
|
|||||||
assert (options.createIfMissing() == true);
|
assert (options.createIfMissing() == true);
|
||||||
assert (options.writeBufferSize() == 8 * SizeUnit.KB);
|
assert (options.writeBufferSize() == 8 * SizeUnit.KB);
|
||||||
assert (options.maxWriteBufferNumber() == 3);
|
assert (options.maxWriteBufferNumber() == 3);
|
||||||
assert (options.maxBackgroundCompactions() == 10);
|
assert (options.maxBackgroundJobs() == 10);
|
||||||
assert (options.compressionType() == CompressionType.SNAPPY_COMPRESSION);
|
assert (options.compressionType() == CompressionType.SNAPPY_COMPRESSION);
|
||||||
assert (options.compactionStyle() == CompactionStyle.UNIVERSAL);
|
assert (options.compactionStyle() == CompactionStyle.UNIVERSAL);
|
||||||
|
|
||||||
@ -87,24 +87,17 @@ public class RocksDBSample {
|
|||||||
options.setRateLimiter(rateLimiter);
|
options.setRateLimiter(rateLimiter);
|
||||||
|
|
||||||
final BlockBasedTableConfig table_options = new BlockBasedTableConfig();
|
final BlockBasedTableConfig table_options = new BlockBasedTableConfig();
|
||||||
table_options.setBlockCacheSize(64 * SizeUnit.KB)
|
Cache cache = new LRUCache(64 * 1024, 6);
|
||||||
.setFilter(bloomFilter)
|
table_options.setBlockCache(cache)
|
||||||
.setCacheNumShardBits(6)
|
.setFilterPolicy(bloomFilter)
|
||||||
.setBlockSizeDeviation(5)
|
.setBlockSizeDeviation(5)
|
||||||
.setBlockRestartInterval(10)
|
.setBlockRestartInterval(10)
|
||||||
.setCacheIndexAndFilterBlocks(true)
|
.setCacheIndexAndFilterBlocks(true)
|
||||||
.setHashIndexAllowCollision(false)
|
.setBlockCacheCompressed(new LRUCache(64 * 1000, 10));
|
||||||
.setBlockCacheCompressedSize(64 * SizeUnit.KB)
|
|
||||||
.setBlockCacheCompressedNumShardBits(10);
|
|
||||||
|
|
||||||
assert (table_options.blockCacheSize() == 64 * SizeUnit.KB);
|
|
||||||
assert (table_options.cacheNumShardBits() == 6);
|
|
||||||
assert (table_options.blockSizeDeviation() == 5);
|
assert (table_options.blockSizeDeviation() == 5);
|
||||||
assert (table_options.blockRestartInterval() == 10);
|
assert (table_options.blockRestartInterval() == 10);
|
||||||
assert (table_options.cacheIndexAndFilterBlocks() == true);
|
assert (table_options.cacheIndexAndFilterBlocks() == true);
|
||||||
assert (table_options.hashIndexAllowCollision() == false);
|
|
||||||
assert (table_options.blockCacheCompressedSize() == 64 * SizeUnit.KB);
|
|
||||||
assert (table_options.blockCacheCompressedNumShardBits() == 10);
|
|
||||||
|
|
||||||
options.setTableFormatConfig(table_options);
|
options.setTableFormatConfig(table_options);
|
||||||
assert (options.tableFactoryName().equals("BlockBasedTable"));
|
assert (options.tableFactoryName().equals("BlockBasedTable"));
|
||||||
@ -203,7 +196,7 @@ public class RocksDBSample {
|
|||||||
len = db.get(readOptions, testKey, enoughArray);
|
len = db.get(readOptions, testKey, enoughArray);
|
||||||
assert (len == testValue.length);
|
assert (len == testValue.length);
|
||||||
|
|
||||||
db.remove(testKey);
|
db.delete(testKey);
|
||||||
len = db.get(testKey, enoughArray);
|
len = db.get(testKey, enoughArray);
|
||||||
assert (len == RocksDB.NOT_FOUND);
|
assert (len == RocksDB.NOT_FOUND);
|
||||||
|
|
||||||
@ -284,15 +277,15 @@ public class RocksDBSample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<byte[], byte[]> values = db.multiGet(keys);
|
List<byte[]> values = db.multiGetAsList(keys);
|
||||||
assert (values.size() == keys.size());
|
assert (values.size() == keys.size());
|
||||||
for (final byte[] value1 : values.values()) {
|
for (final byte[] value1 : values) {
|
||||||
assert (value1 != null);
|
assert (value1 != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
values = db.multiGet(new ReadOptions(), keys);
|
values = db.multiGetAsList(new ReadOptions(), keys);
|
||||||
assert (values.size() == keys.size());
|
assert (values.size() == keys.size());
|
||||||
for (final byte[] value1 : values.values()) {
|
for (final byte[] value1 : values) {
|
||||||
assert (value1 != null);
|
assert (value1 != null);
|
||||||
}
|
}
|
||||||
} catch (final RocksDBException e) {
|
} catch (final RocksDBException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user