Skip to content

This documentation is for the end of life version of Percona Server for MongoDB and is no longer supported. You may want to see the current documentation.

MongoRocks

Important

MongoRocks is deprecated in Percona Server for MongoDB 3.6.

MongoRocks is deprecated in Percona Server for MongoDB 3.6 and it will be fully removed in the next major version of Percona Server for MongoDB. Feature compatibility version is set to 3.4 when using Percona Server for MongoDB 3.6 with MongoRocks, so 3.6 features, such as retryable writes and causal consistency, cannot be used. Additionally, read concern majority may produce unreliable results.

If you are using MongoRocks with Percona Server for MongoDB 3.4 or older, we strongly encourage you to migrate from MongoRocks to WiredTiger before upgrading to Percona Server for MongoDB 3.6. Instructions on how to change storage engines are located in this Percona blog post: https://www.percona.com/blog/2017/03/07/how-to-change-mongodb-storage-engines-without-downtime/.

If you install Percona Server for MongoDB 3.6 with the RocksDB storage engine, you will receive the following error message when trying to start mongod:

[ERROR] There are known issues with MongoDB 3.6 and MongoRocks. To learn about these issues and how to enable MongoRocks with Percona Server for MongoDB 3.6, please read https://www.percona.com/doc/percona-server-for-mongodb/3.6/mongorocks.html, terminating

Note

changing feature compatibility version to 3.6 when using MongoRocks will produce the following error: storage engine does not support upgrading featureCompatibilityVersion to 3.6

To continue using Percona Server for MongoDB 3.6 with MongoRocks, use one of the following two methods:

Add --useDeprecatedMongoRocks to mongod startup options Update the config file with the following parameter:

storage:
engine: rocksdb
useDeprecatedMongoRocks: true

MongoRocks is a storage engine for MongoDB based on the RocksDB key-value store optimized for fast storage. It is developed by Facebook and designed to handle write-intensive workloads.

The MongoRocks storage engine is available in Percona Server for MongoDB along with the standard MongoDB engines (the original MMAPv1 and the default WiredTiger), as well as Percona Memory Engine.

Using MongoRocks

As of version 3.2, Percona Server for MongoDB runs with WiredTiger by default. If you still would like to use the deprecated MongoRocks storage engine, please use the --storageEngine rocksdb command-line option accompanied by --useDeprecatedMongoRocks when you start mongod. Alternatively, you can set the storage.engine and useDeprecatedMongoRocks variables in the configuration file (by default, /etc/mongod.conf) as shown below.

Data created by one storage engine is not compatible with other storage engines, because each one has its own data model. When changing the storage engine, you have to do one of the following:

  • If you simply want to temporarily test MongoRocks, change to a different data directory with the --dbpath command-line option:

    $ service mongod stop
    $ mongod --storageEngine rocksdb --useDeprecatedMongoRocks --dbpath <newDataDir>
    

    Note

    Make sure that the user running mongod has read and write permissions for the new data directory.

  • If you want to permanently switch to MongoRocks and do not have any valuable data in your database, clean out the default data directory and edit the configuration file:

    $ service mongod stop
    $ rm -rf /var/lib/mongodb/*
    $ sed -i '/engine: .*rocksdb/s/#//g' /etc/mongod.conf
    $ service mongod start
    
  • If there is data that you want to migrate and make compatible with MongoRocks, use the mongodump and mongorestore utilities:

    $ mongodump --out <dumpDir>
    $ service mongod stop
    $ rm -rf /var/lib/mongodb/*
    $ sed -i '/engine: .*rocksdb/s/#//g' /etc/mongod.conf
    $ service mongod start
    $ mongorestore <dumpDir>
    

Configuring MongoRocks

You can configure MongoRocks using either command-line options or corresponding parameters in the /etc/mongod.conf file. The configuration file is formatted in YAML. For example, the following sample configuration is suggested as the default for running Percona Server for MongoDB with MongoRocks:

storage:
  engine: rocksdb
  useDeprecatedMongoRocks: true
  rocksdb:
    cacheSizeGB: 1
    compression: snappy
    maxWriteMBPerSec: 1024
    crashSafeCounters: false
    counters: true
    singleDeleteIndex: false

Setting parameters in the previous example configuration file is the same as starting the mongod daemon with the following options:

mongod --storageEngine=rocksdb \
  --useDeprecatedMongoRocks \
  --rocksdbCacheSizeGB=1 \
  --rocksdbCompression=snappy \
  --rocksdbMaxWriteMBPerSec=1024 \
  --rocksdbCrashSafeCounters=false \
  --rocksdbCounters=true \
  --rocksdbSingleDeleteIndex=false

The following options are available (with corresponding YAML configuration file parameters):

--rocksdbCacheSizeGB
Variable

storage.rocksdb.cacheSizeGB

Type

Integer

Default

30% of physical memory

Specifies the amount of memory (in gigabytes) to allocate for block cache. Block cache is used to store uncompressed pages. Compressed pages are stored in kernel’s page cache.

To configure block cache size dynamically, set the rocksdbRuntimeConfigCacheSizeGB parameter at runtime:

db.adminCommand({setParameter:1, rocksdbRuntimeConfigCacheSizeGB: 10})
--rocksdbCompression
Variable

storage.rocksdb.compression

Type

String

Default

snappy

Specifies the block compression algorithm for data collection. Possible values: none, snappy, zlib, lz4, lz4hc.

--rocksdbMaxWriteMBPerSec
Variable

storage.rocksdb.maxWriteMBPerSec

Type

Integer

Default

1024 (1 GB/sec)

Specifies the maximum speed at which MongoRocks writes to storage (in megabytes per second). Decrease this value to reduce read latency spikes during compactions. However, reducing it too much might slow down writes.

To configure write speed dynamically, set the rocksdbRuntimeConfigMaxWriteMBPerSec parameter at runtime:

db.adminCommand({setParameter:1, rocksdbRuntimeConfigMaxWriteMBPerSec:30})
--rocksdbCrashSafeCounters
Variable

storage.rocksdb.crashSafeCounters

Type

Boolean

Default

false

Specifies whether to correct counters after a crash. Enabling this can affect write performance.

--rocksdbCounters
Variable

storage.rocksdb.counters

Type

Boolean

Default

true

Specifies whether to use advanced counters for MongoRocks. You can disable them to improve write performance.

--rocksdbSingleDeleteIndex
Variable

storage.rocksdb.singleDeleteIndex

Type

Boolean

Default

false

This is an experimental feature. Enable it only if you know what you are doing.