Staging database

The staging database is a global database that you can use to store keys and value pairs under key spaces. This database supports creating and deleting key spaces and keys, reading and updating values of keys.

This database is shared between threads. To avoid locking issues, a queue based producer-consumer model is built. In this model, the staging database is controlled by a thread and reads requests from a queue. Each request has a callback that is called when the request is completed. The thread is an operating system thread and not a Cloverleaf engine thread.

By default all keys are written to the global key space. DTC creates a new key space for each transaction.

Staging database access from TCL is through the stageXXX TCL API.

This table shows the key/value pairs of the staging database:

Field Name Type Notes
1 Row ID rowid INTEGER SQLite default
2 Timestamp timestamp INTEGER Use SQLite’s strftime('%Y-%m-%d %H:%M:%f', ‘now’) function to store value.

%f stores milliseconds.

3 Value type datatype INTEGER This field can take these values:
  • DTC for (key,value) DTC protocol writes:
    • Data field contains Message Content
    • Metadata field contains Message’s Metadata
  • MSG for user (key,value) when value is a message:
    • Data field contains Message Content
    • Metadata field contains Message’s Metadata
  • DAT for user (key,value). Data field contains value.
  • Metadata field is NULL
4 Key space keyspace VARCHAR "Global," or user-defined key space.

For DTC, this is "thread^XID."

5 Key key VARCHAR User-defined key. For DTC, this is "step^state." These SQLite functions can be used for DTC:
  • instr(X,Y)

    This returns offset of string Y in X.

  • substr(X,Y,Z)
  • CAST(X as TYPE)

    This casts one type into another. For example, CAST(‘1000’ as Integer).This returns substring in X starting in Y of Z length. Z is optional.

  • nullif(X,Y)

    If nullif(X,Y) returns 0 (Y was not found in X), Null is returned.

To get the state, use: select(substring(key, 0, instr(key,”$”) + 1)

To get the step: This returns substring in X starting in select(CAST(substring(key, instr(key,”$”) + 1) as INTEGER)

6 Data data BLOB Message or user-defined data.
7 Meta Data metadata VARCHAR Message metadata.