Skip to content

Getting Started with MyRocks

Yoshinori Matsunobu edited this page Nov 12, 2015 · 12 revisions

Download Facebook MySQL 5.6

Build from source

Set up my.cnf

To enable RocksDB storage engine, you need to set at least the following parameters in my.cnf.

[mysqld]
rocksdb
default-storage-engine=rocksdb
skip-innodb
default-tmp-storage-engine=MyISAM

log-bin
binlog-format=ROW

Currently, it is not allowed to enable both InnoDB and RocksDB storage engines at the same time, because it is hard to make it work in production.

Statement based binary logging is allowed on replication slave, but not on master. This is because MyRocks does not support next-key locking.

Initialize database with mysql_install_db

mysql_install_db --defaults-file=/path/to/my.cnf

Start mysqld

mysqld_safe --defaults-file=/path/to/my.cnf

Create RocksDB table

Here is an example.

    CREATE TABLE `linktable` (
      `id1` bigint(20) unsigned NOT NULL DEFAULT '0',
      `id1_type` int(10) unsigned NOT NULL DEFAULT '0',
      `id2` bigint(20) unsigned NOT NULL DEFAULT '0',
      `id2_type` int(10) unsigned NOT NULL DEFAULT '0',
      `link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
      `visibility` tinyint(3) NOT NULL DEFAULT '0',
      `data` varchar(255) NOT NULL DEFAULT '',
      `time` bigint(20) unsigned NOT NULL DEFAULT '0',
      `version` int(11) unsigned NOT NULL DEFAULT '0',
      PRIMARY KEY (link_type, `id1`,`id2`) COMMENT 'cf_link_pk',
      KEY `id1_type` (`id1`,`link_type`,`visibility`,`time`,`version`,`data`) COMMENT 'rev:cf_link_id1_type'
    ) ENGINE=RocksDB DEFAULT COLLATE=latin1_bin; 

The example shows some important features and limitations in MyRocks.

  • Tables must have Primary Key.
  • Case sensitive collation has to be used. Currently binary, latin1_bin or utf8_bin has to be used for indexed CHAR/VARCHAR columns. This is for performance reason. If you want to use case insensitive collation, you can set exceptions by setting the following parameter in my.cnf.
rocksdb_strict_collation_exceptions='linktable,nodetable,counttable'
  • MyRocks data is stored in RocksDB, per index basis. RocksDB internally allocates "Column Family" to store indexes. By default, all data is stored into "default" column family. You can change column family by setting index comment. In this example, Primary Key is stored into "cf_link_pk" column family, and id1_type index data is stored into 'rev:cf_link_id1_type' column family.
  • MyRocks has a feature called "Reverse Column Family". Reverse Column Family is useful if the index is mainly used for descending scan (ORDER BY .. DESC). You can configure Reverse Column Family by setting "rev:" before the column family name. In this example, id1_type belongs to Reverse Column Family.
Clone this wiki locally