Skip to content

RonDB REST API#

RonDB 21.04.15 introduces a new REST API, version 0.1.0, to retrieve data from RonDB databases. The new REST API improves the flexibility of the RonDB platform by allowing users to retrieve data from a more diverse set of languages/framework clients. Users can now easily retrieve data from Python, Julia or golang applications and are no longer limited to the C++/Java ecosystem.

REST API#

Currently, RonDB REST API only supports single and batched primary key read operations. In the future, we plan to extend the REST API to support write operations, scan operations, and transactions.

Supported Data Types#

Default mappings of MySQL data types to JSON data types are as follows:


 MySQL Data Types                            JSON Data Type

 TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT   number
 FLOAT, DOUBLE, DECIMAL                      number
 CHAR, VARCHAR escaped                       string
 BINARY, VARBINARY base64 encoded            string
 DATE, DATETIME, TIME, TIMESTAMP, YEAR       string
 YEAR                                        number
 BIT base64 encoded                          string

Primary Key Read Operations#

It is used to perform a primary key read operation. Assume we have the following table.

CREATE TABLE `my_table` (                                            
  `id0` int NOT NULL,                                                 
  `id1` int unsigned NOT NULL,                                        
  `col0` int DEFAULT NULL,                                            
  `col1` int unsigned DEFAULT NULL,                                   
  PRIMARY KEY (`id0`,`id1`)                                           
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Primary Key Read Request#

A primary key read request would look something like this

POST /{api-version}/test_db/my_table/pk-read
Body:
{
  "filters": [
    {
      "column": "id0",
      "value": 0
    },
    {
      "column": "id1",
      "value": 0
    }
  ],
  "readColumns": [
    {
      "column": "col0",
      "dataReturnType": "default"
    },
    {
      "column": "col1",
      "dataReturnType": "default"
    }
  ],
  "operationId": "ABC123"
}

Parameters:

  • filters: (required) This is an array of objects one for each column that forms the primary key.

  • readColumns: (optional) This is used to perform projections. If it is omitted, all the columns of the table will be read

  • dataReturnType: (optional) This can be used to control in which format the data is returned, for example, hex, base64, etc. However, in this version (0.1.0) we only support the default return type.

  • operationId: (optional) It is a string parameter and it can be up to 64 characters long.

Primary Key Read Response#

Body:
{
  "operationId": "ABC123",
  "data": {
    "col0": 123,
    "col1": 456
  }
}

Primary Key Read Error Handling#


 Code   Error Message

 200    OK
 400    Bad Request. The error message will contain more information about which part of the request is invalid. For example, if incomplete primary key is specified
 401    Access denied due to invalid API KEY
 500    Server Error. For example, database failure

Batched Primary Key#

You can use this to batch multiple primary key operations across different databases.

Batched Primary Key Request#

POST /{api-version}/batch
{
  "operations": [
    {
      "method": "POST",
      "relative-url": "my_database_1/my_table_1/pk-read",
      "body": {
        "filters": [
          {
            "column": "id0",
            "value": 0
          },
          {
            "column": "id1",
            "value": 0
          }
        ],
        "readColumns": [
          {
            "column": "col0",
            "dataReturnType": "default"
          },
          {
            "column": "col1",
            "dataReturnType": "default"
          }
        ],
        "operationId": "1"
      },
    },
    {
      "method": "POST",
      "relative-url": "my_database_2/my_table_2/pk-read",
      "body": {
        "filters": [
          {
            "column": "id0",
            "value": 1
          },
          {
            "column": "id1",
            "value": 1
          }
        ],
      },
    },
  ]
}

Parameters:

  • relative-url: (required) This represents the url the given pk-read would have in a single request (omitting the api-version).

Batched Primary Key Request#

Body: 
[
  {
    "code": 200,
    "body": {
      "operationId": "1",
      "data": {
        "col0": 0,
        "col1": 0
      }
    }
  },
  {
    "code": 200,
    "body": {
      "data": {
        "col0": 1,
        "col1": 1
      }
    }
  }
]

Batch Key Read Error Handling#


 Code   Error Message

 200    OK. The batch operation was executed and an array of sub-responses is returned. Each sub response contains its own status code. For example, some suboperations may return code 200 while other may return code 404
 400    Bad Batch Request. Server fails for unmarshal the request
 401    Access denied due to invalid API KEY
 500    Server Error. For example, database failure

Configuration Parameters#

{
        "Internal": {
                "APIVersion": "0.1.0",
                "BufferSize": 327680,
                "PreAllocatedBuffers": 1024,
                "GOMAXPROCS": -1,
                "BatchMaxSize": 256,
                "OperationIDMaxSize": 256
        },
        "REST": {
                "Enable": true,
                "ServerIP": "localhost",
                "ServerPort": 4406
        },
        "GRPC": {
                "Enable": true,
                "ServerIP": "localhost",
                "ServerPort": 5406
        },
        "RonDB": {
                "Mgmds": [
                        {
                                "IP": "localhost",
                                "Port": 1186
                        }
                ],
                "ConnectionPoolSize": 1,
                "NodeIDs": [],
                "ConnectionRetries": 5,
                "ConnectionRetryDelayInSec": 5,
                "OpRetryOnTransientErrorsCount": 3,
                "OpRetryInitialDelayInMS": 500,
                "OpRetryJitterInMS": 100
        },
        "RonDBMetadataCluster": {
                "Mgmds": [
                        {
                                "IP": "localhost",
                                "Port": 1186
                        }
                ],
                "ConnectionPoolSize": 1,
                "NodeIDs": [],
                "ConnectionRetries": 5,
                "ConnectionRetryDelayInSec": 5,
                "OpRetryOnTransientErrorsCount": 3,
                "OpRetryInitialDelayInMS": 500,
                "OpRetryJitterInMS": 100
        },
        "Security": {
                 "TLS": {
                         "EnableTLS": true,
                         "RequireAndVerifyClientCert": false,
                         "CertificateFile": "",
                         "PrivateKeyFile": "",
                         "RootCACertFile": ""
                 }
                 "APIKey": {
                         "UseHopsworksAPIKeys": true,
                         "CacheRefreshIntervalMS": 10000,
                         "CacheUnusedEntriesEvictionMS": 60000,
                         "CacheRefreshIntervalJitterMS": 1000
                 }
        },
        "Log": {
                "Level": "info",
                "FilePath": "",
                "MaxSizeMB": 100,
                "MaxBackups": 10,
                "MaxAge": 30
        },
        "Testing": {
                "MySQL": {
                        "User": "rondb",
                        "Password": "rondb",
                        "Servers": [
                                {
                                        "IP": "localhost",
                                        "Port": 3306
                                }
                        ],
                },
                "MySQLMetadataCluster": {
                        "User": "rondb",
                        "Password": "rondb",
                        "Servers": [
                                {
                                        "IP": "localhost",
                                        "Port": 3306
                                }
                        ],
                }
        },
}

Configuration Parameters

Internal

  • APIVersion: Current version of the REST API. Current version is 0.1.0. Users are not expected to change versions manually.

  • BufferSize: Size of the buffers that are used to pass requests/responses between the Go and C++ layers. The buffers should be large enough to accommodate any request/response. The default size is 327680 (32 KB).

  • PreAllocatedBuffers: Numbers of buffers to preallocate. The default value is 1024.

  • GOMAXPROCS: The GOMAXPROCS variable limits the number of operating system threads that can execute user-level Go code simultaneously. The default value is -1, that is it does not change the current settings.

  • BatchMaxSize: Max number of suboperations in a batch operation. Default is 256.

  • OperationIDMaxSize: Max length of operation ID. Default is 256 characters.

REST

  • Enable: Enable/Disable REST Server Interface

  • ServerIP: Binds the REST server to this IP. The default value is localhost

  • ServerPort: REST server port. The default port is 4406

GRPC

  • Enable: Enable/Disable GRPC Server Interface

  • ServerIP: Binds the GRPC server to this IP. The default value is localhost

  • ServerPort: GRPC server port. The default port is 5406

RonDB

  • Mgmds:

    • IP: RonDB management node IP. The default value is localhost.

    • Port: RonDB management node port. The default value is 1186.

  • ConnectionPoolSize: Connection pool size. Default 1. Note current implementation only supports 1 cluster connection

  • NodeIDs: This is an optional list of node ids to force the connections to be assigned to specific node ids. If this property is specified and connection pool size is not the default, the number of node ids must match the connection pool size

  • ConnectionRetries: Connection retries

  • ConnectionRetryDelayInSec: Connection retry delay in sec

  • OpRetryOnTransientErrorsCount: Number of times retry failed operations due to transient errors.

  • OpRetryInitialDelayInMS: Initial delay used in exponential backoff for retrying failed operations.

  • OpRetryJitterInMS: Jitter is added (or subtracted) from the retry delay to prevent multiple failed operations from being retried at the same time

RonDBMetadataCluster

This is an optional parameter. In normal operations the user data and metadata data (API Keys) are stored in the same RonDB cluster. It is possible to store data and metadata in separate clusters. Use the RonDBMetadataCluster parameter to configure a dedicated RonDB cluster containing user metadata. For example, if RonDB and RonDBMetadataCluster parameters are set then pk-read and batch operations will be performed on a cluster defined in the RonDB parameter and metadata operations will be performed on a cluster defined in RonDBMetadataCluster parameter.

Security:

  • TLS:

    • EnableTLS: Enable/Disable TLS. The default value is true.

    • RequireAndVerifyClientCert: Enable/Disable TLS client certificate requirement. The default value is true.

    • RootCACertFile: Root CA file. Used in testing that use self-signed certificates. The default value is not set.

    • CertificateFile: Server certificate file. The default value is not set.

    • PrivateKeyFile: Server private key file. The default value is not set.

  • APIKey:

    • UseHopsworksAPIKeys: Enable/Disable Hopsworks API Key for authentication

    • CacheRefreshIntervalMS: The API Keys are cached and refreshed periodically. CacheRefreshIntervalMS can not be set to zero.

    • CacheUnusedEntriesEvictionMS: Unused API Keys are automatically evicted from the cache. Eviction time can not be less than cache refersh time (CacheRefreshIntervalMS).

    • CacheRefreshIntervalJitterMS: It prevents simultaneously updates to the cached API Keys if the keys were added to the cache in a very short interval

Log

  • Level: log level, Supported levels are panic, error, warn, info, debug, and trace. The default value is info.

  • FilePath: log file location. The default value is stdout.

  • MaxSizeMB: max log file size. The default value is 100.

  • MaxBackups: max number of log files to store. The default value is 10.

  • MaxAge: max-age of log files in days. The default value is 30.

Testing

MySQL server is only used for testing

  • MySQL: MySQL server is only used for testing

    • Servers:

      • IP: MySQL Server IP. The default value is localhost.

      • Port: MySQL Server port. The default value is 3306.

    • User: MySQL Server user. The default value is rondb.

    • Password: MySQL Server user password. The default value is rondb.

  • MySQLMetadataCluster: Similar to RonDBMetadataCluster this is an optional parameter used to connect to cluster containing user metadata.

Running RonDB REST Server#

The REST Server binary is named rdrs and it is packaged in the bin of the RonDB tar ball. You can run the REST server follows

$./rdrs -config /path/to/config.json

The REST server is also compatible with NDB. The REST Server is built on RonDB native API which is identical to NDB native API, except for the version number. As REST API server dynamically loads the native API, it is possible to use the REST server with a NDB cluster. Copy the rdrs binary to ndb cluster bin folder, and librdrclient.so and librdrs_string.a libraries to lib folder of NDB cluster install dir. After copying these files you will be able to use the REST server with a NDB Cluster.

Security and Authentication#

Currently, the REST API server only supports Hopsworks API Keys for authentication and authorization. In the future, we plan to extend MySQL server users and privileges to the REST API. Add the API key to the HTTP request using the X-API-KEY header. Of course, you should enable TLS when using API Keys to ensure that eavesdroppers do not steal your API Key

RonDB REST API at Hopsworks AB#

Using RonDB REST API Hopsworks has built REST API for Feature Stores. Feature Store is a platform that connects enterprise data to analytical and operational ML systems. The REST API is used to retrieve data for real-time inference from the online feature store and RonDB databases.