ClickHouse/docs/en/engines/table-engines/integrations/embedded-rocksdb.md
Lloyd-Pottiger c5d81e160c add functionality test
Signed-off-by: Lloyd-Pottiger <yan1579196623@gamil.com>
2022-08-10 23:10:52 +08:00

2.6 KiB
Raw Blame History

sidebar_position sidebar_label
9 EmbeddedRocksDB

EmbeddedRocksDB Engine

This engine allows integrating ClickHouse with rocksdb.

Creating a Table

CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
    name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1],
    name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2],
    ...
) ENGINE = EmbeddedRocksDB([ttl, read_only]) PRIMARY KEY(primary_key_name)

Engine parameters:

  • ttl - time to live for values. TTL is accepted in seconds. If TTL is 0, regular RocksDB instance is used (without TTL).
  • read_only - when read_only is set to true, read-only mode is used. For storage with TTL, compaction will not be triggered (neither manual nor automatic), so no expired entries are removed.
  • primary_key_name any column name in the column list.
  • primary key must be specified, it supports only one column in the primary key. The primary key will be serialized in binary as a rocksdb key.
  • columns other than the primary key will be serialized in binary as rocksdb value in corresponding order.
  • queries with key equals or in filtering will be optimized to multi keys lookup from rocksdb.

Example:

CREATE TABLE test
(
    `key` String,
    `v1` UInt32,
    `v2` String,
    `v3` Float32
)
ENGINE = EmbeddedRocksDB
PRIMARY KEY key

Metrics

There is also system.rocksdb table, that expose rocksdb statistics:

SELECT
    name,
    value
FROM system.rocksdb

┌─name──────────────────────┬─value─┐
 no.file.opens                  1 
 number.block.decompressed      1 
└───────────────────────────┴───────┘

Configuration

You can also change any rocksdb options using config:

<rocksdb>
    <options>
        <max_background_jobs>8</max_background_jobs>
    </options>
    <column_family_options>
        <num_levels>2</num_levels>
    </column_family_options>
    <tables>
        <table>
            <name>TABLE</name>
            <options>
                <max_background_jobs>8</max_background_jobs>
            </options>
            <column_family_options>
                <num_levels>2</num_levels>
            </column_family_options>
        </table>
    </tables>
</rocksdb>

Original article