Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TickerType.BLOCK_CACHE_COMPRESSED_ADD returns 0 #4822

Open
adamretter opened this issue Dec 28, 2018 · 1 comment
Open

TickerType.BLOCK_CACHE_COMPRESSED_ADD returns 0 #4822

adamretter opened this issue Dec 28, 2018 · 1 comment
Labels
bug Confirmed RocksDB bugs java-api

Comments

@adamretter
Copy link
Collaborator

The following C++ example works fine block_cache_compressed_integration.cc:

#include <iostream>
#include <string>

#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:

  @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);
          }
        }
      }
    }
  }
@adamretter adamretter added bug Confirmed RocksDB bugs java-api labels Dec 28, 2018
@adamretter
Copy link
Collaborator Author

I have debugged this as far as possible. From the Java side it appears that the compressed cache is setup correctly on the options. I can't figure out why the BLOCK_CACHE_COMPRESSED_ADD is not being incremented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed RocksDB bugs java-api
Projects
None yet
Development

No branches or pull requests

1 participant