TickerType.BLOCK_CACHE_COMPRESSED_ADD returns 0
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
The following C++ example works fine `block_cache_compressed_integration.cc`:
```C++
#include
#include
#include "rocksdb/db.h"
#include "rocksdb/cache.h"
#include "rocksdb/options.h"
#include "rocksdb/statistics.h"
#include "rocksdb/slice.h"
#include "rocksdb/table.h"
using namespace rocksdb;
int main() {
Slice key1("some-key1");
Slice key2("some-key2");
Slice key3("some-key3");
Slice key4("some-key4");
Slice value("some-value");
auto compressed_cache = NewLRUCache(8 * 1024 * 1024);
auto statistics = CreateDBStatistics();
BlockBasedTableOptions block_table_opts;
block_table_opts.block_cache = nullptr;
block_table_opts.no_block_cache = true;
block_table_opts.block_cache_compressed = compressed_cache;
block_table_opts.format_version = 4;
auto block_table_factory = NewBlockBasedTableFactory(block_table_opts);
Options opts;
opts.create_if_missing = true;
opts.statistics = statistics;
opts.table_factory.reset(block_table_factory);
for (size_t shard = 0; shard < 8; shard++) {
std::string db_path("test_db-");
db_path.append(std::to_string(shard));
DB* db;
Status s = DB::Open(opts, db_path, &db);
if (!s.ok()) {
std::cerr << s.ToString() << std::endl;
}
assert(s.ok());
WriteOptions write_opts;
db->Put(write_opts, key1, value);
db->Put(write_opts, key2, value);
db->Put(write_opts, key3, value);
db->Put(write_opts, key4, value);
FlushOptions flush_opts;
//flush_opts.WaitForFlush(true);
db->Flush(flush_opts);
std::string retrieved;
ReadOptions read_opts;
db->Get(read_opts, key1, &retrieved);
db->Get(read_opts, key2, &retrieved);
db->Get(read_opts, key3, &retrieved);
db->Get(read_opts, key4, &retrieved);
assert(statistics->getTickerCount(rocksdb::Tickers::BLOCK_CACHE_COMPRESSED_ADD) == shard + 1);
db->Close();
delete db;
}
}
```
Run:
```
$ DEBUG_LEVEL=2 make -j4 shared_lib
$ clang++ -std=c++11 -stdlib=libc++ -fpic -I include/ -o block_cache_compressed_integration librocksdb.dylib block_cache_compressed_integration.cc
```
But the Java equivalent (`BlockBasedTableConfigTest.java`) always fails with `TickerType.BLOCK_CACHE_COMPRESSED_ADD` returning 0:
```java
@Test
public void blockCacheCompressedIntegration() throws RocksDBException {
final byte[] key1 = "some-key1".getBytes(StandardCharsets.UTF_8);
final byte[] key2 = "some-key1".getBytes(StandardCharsets.UTF_8);
final byte[] key3 = "some-key1".getBytes(StandardCharsets.UTF_8);
final byte[] key4 = "some-key1".getBytes(StandardCharsets.UTF_8);
final byte[] value = "some-value".getBytes(StandardCharsets.UTF_8);
try (final Cache compressedCache = new LRUCache(8 * 1024 * 1024);
final Statistics statistics = new Statistics()) {
final BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig()
.setNoBlockCache(true)
.setBlockCache(null)
.setBlockCacheCompressed(compressedCache)
.setFormatVersion(4);
try (final Options options = new Options()
.setCreateIfMissing(true)
.setStatistics(statistics)
.setTableFormatConfig(blockBasedTableConfig)) {
for (int shard = 0; shard < 8; shard++) {
try (final FlushOptions flushOptions = new FlushOptions();
final WriteOptions writeOptions = new WriteOptions();
final ReadOptions readOptions = new ReadOptions();
final RocksDB db =
RocksDB.open(options, dbFolder.getRoot().getAbsolutePath() + "/" + shard)) {
db.put(writeOptions, key1, value);
db.put(writeOptions, key2, value);
db.put(writeOptions, key3, value);
db.put(writeOptions, key4, value);
db.flush(flushOptions);
db.get(readOptions, key1);
db.get(readOptions, key2);
db.get(readOptions, key3);
db.get(readOptions, key4);
assertThat(statistics.getTickerCount(TickerType.BLOCK_CACHE_COMPRESSED_ADD)).isEqualTo(shard + 1);
}
}
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.