The message box is used to store messages sent between PuzzleDB nodes in the cluster to notify any node and store status changes using the message key-value store.
Logical clocks, such as the Lamport Clock, are important in distributed systems because they can order events across different nodes; in PuzzleDB, to manage the message clock for the coordinator service, the conceptual Lamport Clock algorithm:
In practice, the coordinator node acts as a virtual message relay node between PuzzleDB nodes. The coordinator service uses the message clock to provide the total order of messages at all nodes in the system. To manage the message clock, PuzzleDB uses the Lamport Clock algorithm, which assigns a unique timestamp to each message sent by a node.
When sending a message, a PuzzleDB node obtains the latest logical clock from the coordinator node and uses it to timestamp the message. When a PuzzleDB node receives or retrieves a message from a coordinator node, it updates its own logical clock with the logical clock included in the message.
The message object is encoded as a CBOR object and stored as the value of the message key-value record.
The message object has the following required header fields:
Field Name | Data Type | Description |
---|---|---|
type |
int |
Message type |
timestamp |
time.Time |
Generated phisical time |
The type field is used to identify messages and the timestamp field is used to discard old messages.
The message value object is encoded as a CBOR object and stored as the value of the message key-value record to the coordinator service. The message object has a message type, an event type and a CBOR encoded message object, and the standard message object is defined as follows:
Field | Type | Value |
---|---|---|
ID |
UUID |
Destination node ID |
Host |
string |
Destination host name |
Clock |
uint64 |
Destination logical clock |
Message Type |
byte |
Message type |
Event Type |
byte |
Event type |
Object |
[]byte |
Message object (CBOR) |
The message value object has a defined object for each type of message, and the object is stored as a simple byte sequence encoded in CBOR in the message value.
The message types and the event types are reserved as follows:
Message Type | Event Type | Occurrence Condition | Note |
---|---|---|---|
Object (O) |
Created © |
Object created |
|
Update (U) |
Object updated |
||
Delete (D) |
Object deleted |
||
Database (D) |
Created © |
Database created |
|
Update (U) |
Database updated |
||
Delete (D) |
Database deleted |
||
Collection © |
Created © |
Schema created |
|
Update (U) |
Shcema updated |
||
Delete (D) |
Schema deleted |
||
User Defined (U) |
- |
- |
User-defined message. Event types are not defined. |
The object (O) message is notified when a store object is created, updated, or deleted in the coordinator store. The database (D) and collection © messages are notified by query services such as Redis, MySQL, and MongoDB.
The user (U) message preserves only the message type, and the event type and message value object are defined by the user.