Cassandra as Backing Store - learn-tibco-cep/tutorials GitHub Wiki

Apache Cassandra is an open source NoSQL database that can be used as the backing store for Apache Ignite cluster.

As shown in BooksCas.cdd, you can select Apache Cassandra as the Persistence Option for the data store, and specify the Cassandra server connection and key space name in the CDD.

Object Management

In the CDD, you may check the Preload Entities flag in the Domain Object default settings, and so the Ignite cluster will automatically load data from the backing store when a server node starts.

For each concept of Cache Only mode in the CDD, you may also check the Has Backing Store flag, and so all data in the cache cluster will be persisted in the Cassandra database.

Generate Database Schema

You may generate database schema for Cassandra from the CDD and EAR file of the application. For example, the following script will generate the Cassandra schema for this tutorial, and write generated files in the specified scriptFolder with file name prefix of perf.

$BE_HOME/bin/be-storedeploy --propFile $BE_HOME/bin/be-storedeploy.tra -o /path/to/scriptsFolder/perf -c BooksCas.cdd -s CASSANDRA Books.ear

The database table and index definitions will be written to a file as /path/to/scriptFolder/perf.cql. To support direct queries on the backing store, we also added the following indexes to the schema definition.

DROP INDEX IF EXISTS ix_d_Author_revision;
CREATE INDEX IF NOT EXISTS ix_d_Author_revision on d_Author(revision);
DROP INDEX IF EXISTS ix_d_Author_last_modified;
CREATE INDEX IF NOT EXISTS ix_d_Author_last_modified on d_Author(last_modified);
DROP INDEX IF EXISTS ix_d_Book_revision;
CREATE INDEX IF NOT EXISTS ix_d_Book_revision on d_Book(revision);
DROP INDEX IF EXISTS ix_d_Book_last_modified;
CREATE INDEX IF NOT EXISTS ix_d_Book_last_modified on d_Book(last_modified);

The updated schema definition can be viewed at perf.cql.

Install and Configure Cassandra Server

We use the following steps to install and configure a Cassandra 4.1.1 on a RHEL 8 Linux server. This version supports Java 11 and Python 3, which matches with Java version installed by TIBCO BusinessEvents.

curl -OL https://dlcdn.apache.org/cassandra/4.1.1/apache-cassandra-4.1.1-bin.tar.gz
tar -xvfz apache-cassandra-4.1.1-bin.tar.gz

This creates Cassandra executables in CASSANDRA_HOME = ./apache-cassandra-4.1.1. We need to edit the configuration file $CASSANDRA_HOME/conf/cassandra.yaml, so the server is accessible by remote clients, and it can process large transactions required by the performance tests of this tutorial.

seed_provider:
  - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
      - seeds: "cashostname:7000"
listen_address: cashostname
rpc_address: cashostname
batch_size_warn_threshold: 50MiB
batch_size_fail_threshold: 100MiB
commitlog_segment_size: 200MiB
write_request_timeout: 60000ms

Start Cassandra server and check its status.

JAVA_HOME=$TIBCO_HOME/tibcojre64/11 $CASSANDRA_HOME/bin/cassandra > cassandra.log 2>&1 &
$CASSANDRA_HOME/bin/nodetool status

Create schema for tutorial application

The schema definition files for the tutorial application are $BE_HOME/bin/create_tables_cassandra.cql and perf.cql, so copy these 2 files to a working folder, and add a line at the beginning of both files to specify the name of a key space, i.e.,

USE perf;

Create the key space and define tutorial schema using these 2 scripts.

$CASSANDRA_HOME/bin/cqlsh cashostname
cqlsh> CREATE KEYSPACE perf
  WITH REPLICATION = {
   'class' : 'SimpleStrategy',
   'replication_factor' : 1
  };

$CASSANDRA_HOME/bin/cqlsh -f create_tables_cassandra.cql
$CASSANDRA_HOME/bin/cqlsh -f perf.cql

Verify that tables are created successfully.

$CASSANDRA_HOME/bin/cqlsh cashostname
cqlsh> select * from system_schema.keyspaces;
cqlsh> select table_name from system_schema.tables where keyspace_name = 'perf';
cqlsh> select column_name, kind, type from system_schema.columns where keyspace_name = 'perf' and table_name='d_author';
cqlsh> select count(*) from perf.bealiases;

Configure Cassandra Connection

The Cassandra connection and key space name in this tutorial can be configured in BooksCas.cdd by setting the following variables.

Property Name Value
tibco.clientVar.CASSA/server cashostname:9042
tibco.clientVar.CASSA/key_space perf

Start Cache and Inference Nodes

You can then start cache and inference nodes that will store data in Cassandra on the specified database host.

# start a cache node
$BE_HOME/bin/be-engine --propFile $BE_HOME/bin/be-engine.tra -n cache-0 -u cache -c BooksCas.cdd Books.ear

# start an inference node
$BE_HOME/bin/be-engine --propFile $BE_HOME/bin/be-engine.tra -n default-0 -u default -c BooksCas.cdd Books.ear