Product tutorials, how-tos, and fully-documented APIs.

Innostore

    Warning

    As of Riak version 1.2, the Innostore backend is deprecated and no longer supported.

    Overview

    Innostore is an Erlang application that provides an API for storing and retrieving key/value data using the InnoDB storage system. This storage system is the same one used by MySQL for reliable, transactional data storage. It’s a proven, fast system and perfect for use with Riak if you have a large amount of data to store. Let’s take a look at how you can use Innostore as a backend for Riak.

    Strengths:

    Weaknesses:

    Installing Innostore

    Unlike the other storage engines, Innostore is distributed separately from Riak. We recommend using a pre-packaged binary distribution but you can also build it from source code.

    Installing from pre-built packages

    Determine your system and architecture (such as “Ubuntu” and “64bit Intel”) and then find the latest download package. http://downloads.basho.com/ Use your browser or a tool such as wget or curl to download the package and then install the package using the proper package manager.

    # Example: Ubuntu x64 or other Debian-based Linux distributions:
    $ cd /tmp
    $ wget http://downloads.basho.com/innostore/innostore-1.0.3/innostore-1.0.3-1-deb-x86_64.tar.gz
    $ cd /usr/lib/riak/lib
    $ sudo tar -xvzf /tmp/innostore-1.0.3-1-deb-x86_64.tar.gz
    $ sudo chown -R riak.riak innostore-1.0.3
    $ rm /tmp/innostore-1.0.3-1-deb-x86_64.tar.gz
    
    # Example: RedHat x64 or other RedHat-based Linux distributions:
    $ cd /tmp
    $ wget http://downloads.basho.com/innostore/innostore-1.0.3/innostore-1.0.3-1-rh-x86_64.tar.gz
    $ cd /usr/lib/riak/lib
    $ sudo tar -xvzf /tmp/innostore-1.0.3-1-rh-x86_64.tar.gz
    $ sudo chown -R riak.riak innostore-1.0.3
    $ rm /tmp/innostore-1.0.3-1-rh-x86_64.tar.gz
    
    # Example: Fedora Core x64 and related Linux distributions:
    $ cd /tmp
    $ sudo wget http://downloads.basho.com/innostore/innostore-1.0.3/innostore-1.0.3-1-fedora-x86_64.tar.gz
    $ cd /var/lib/riak/lib
    $ sudo tar -xvzf /tmp/innostore-1.0.3-1-fedora-x86_64.tar.gz
    $ sudo chown -R riak.riak innostore
    $ rm /tmp/innostore-1.0.3-1-fedora-x86_64.tar.gz
    
    # etc...
    

    Building and installing from source code

    If your compile passed all the tests you are now ready to install Innostore into your Riak distribution.

       $ make install
    
       $ RIAK=/usr/lib/riak make install
    

    Which would result in the following files being installed into /usr/lib/riak/lib/innostore-1.0.3

       innostore-1.0.3/
       |-- ebin
       |   |-- innostore.app
       |   |-- innostore.beam
       |   |-- innostore_riak.beam
       |   `-- riak_kv_innostore_backend.beam
       |-- priv
       |   |-- innodump
       |   |-- innoload
       |   |-- innostore_drv.so
       |   `-- riak-innostore
       `-- src
           |-- innostore.erl
           |-- innostore_riak.erl
           `-- riak_kv_innostore_backend.erl
    

    Configuring Innostore

    There are two steps to configure Riak to use Innostore.

    1. Edit your Riak installation's app.config file Change the storage_backend setting to riak_kv_innostore_backend.

      {storage_backend, riak_kv_innostore_backend}
      
    2. While the defaults should work just fine you may want to modify the location of the Innostore database files. To do that you first add an innostore application section to the riak/etc/app.config file. Modify your data_home_dir and log_group_home_dir paths as needed.

      {innostore, [
          {data_home_dir, "/var/lib/riak/innodb"}, %% Where data files reside
          {log_group_home_dir, "/var/lib/riak/innodb/logs"}, %% Where log files reside
          {buffer_pool_size, 2147483648} %% 2GB of buffer
      ]}
      
    3. Now that you have configured Innostore you can test your install by connecting to the Riak console and watching for messages about Innostore sudo /usr/sbin/riak console. If the install was successful you will see something similar to:

       100220 16:36:58 InnoDB: highest supported file format is Barracuda.
       100220 16:36:58 Embedded InnoDB 1.0.3.5325 started; log sequence number 45764
      

    Tuning Innostore

    While InnoDB can be extremely fast for a durable store, its performance is highly dependent on tuning the configuration to match the hardware and dataset. All the configuration is available as application variables in the innostore application scope.

    Tips & Tricks:

    Innostore Implementation Details

    The Innostore backend creates separate tables for each bucket. These tables have two columns; key and value. The key is a VARBINARY limited to 255 bytes. This means that keys must be no larger than 255 bytes when you use the Innostore backend. The value column is a BLOB, it can store data of any size. One clustered primary key index is created on the key column to speed up access to data.

    All operations are performed within transactions but the degree of serialization differs across operations. Gets (reads) are performed within the context of a repeatable read (IB_TRX_REPEATABLE_READ). Puts (insert or update) are within a serializable transaction (IB_TRX_SERIALIZABLE). Delete also occurs within a serializable transaction.

    Innostore Database Files

    Here's what you can expect to see on disk when running Innostore. First, let's agree on the following as our configuration for Innostore in our app.config file.

    %% Innostore Config
    {innostore, [
        {data_home_dir, "/var/lib/riak/innodb"}, %% Where data files go
        {log_group_home_dir, "/var/lib/riak/innodb/logs"}, %% Where log files go
        {flush_method, "O_DIRECT"}, %% Prevent double buffering of filesystem blocks
        {buffer_pool_size, 1073741824}, %% 2GiB
        {log_files_in_group, 6},  %% How many files you need, usually 3 < x < 6
        {log_file_size, 268435456},  %% No bigger than 256MB, otherwise recovery takes too long
        {open_files, 2048}, %% Restrict the number of open file handles available to Innostore
        {adaptive_flushing, true}  %% Enable adaptive flushing
        {format, compressed}, %% Use compressed, dynamic format tables.
    ]},
    

    When you first start up Riak (riak start) there will be no evidence of the Innostore/InnoDB database files. It isn't until the first access to Riak that the files are created. Once that happens you can expect a short lag as the Innostore backend initializes the data and log files resulting in the following layout:

    innodb/
    |-- ibdata1
    |-- innokeystore
    `-- logs
        |-- ib_logfile0
        |-- ib_logfile1
        |-- ib_logfile2
        |-- ib_logfile3
        |-- ib_logfile4
        `-- ib_logfile5
    

    Every time thereafter you will experience a short delay (generally a few seconds) at startup while InnoDB runs recovery to ensure that the database files are up to date and consistent on disk according to the latest information in the log files.

    Conceptually, there are three categories of data being stored for each bucket managed by Innostore; the keys, the values and the index into the keys to speed lookup.

    The file ibdata1 is the first in a set of files with names such as ibdata1, ibdata2, and so on, that make up the InnoDB system tablespace. These files contain metadata about InnoDB tables, and can contain some or all of the table data also (depending on whether the file-per-table option is in effect when each table is created). Innostore index and value date along with InnoDB metadata all end up in the ibdata1..n files. This is where all values and indexes live for all buckets.

    The file innokeystore contains the keys. They are in a separate database file to improve the cache hit rate on sequential key access.

    More documentation on the Embedded InnoDB library can be found here.