kv-write
The kv-write
subcommand writes the user specified key-value pair to the key-value database.
The workflow of KV write is as follows:
The user defines the storage node (or indexer) which he/she wants the key-value data to be stored.
The user sets the key-value pairs.
The SDK will stream the key-value data and encode it to be the same format of a file data.
The process is the same as file upload.
The KV node will replay the log in on-chain contract, parse out the transaction that operates the KV database. If the KV operation contained in the transaction is legal and there is no version conflict, the update will be committed to the local KV database.
Explanation:
--stream-id
is the stream id defined by the user. A stream id can be considered as a separate key-value db. Data in different stream ids do not share with each other. It mainly serves as a channel for various applications. For example, a user can define its own stream id and use that stream as kv database for its own application.Use either
--node
or--indexer
to define the storage location.--stream-keys
and--stream-values
should match the position of a key-value pair.--version
is the version number for each key to control the parallel access to the key. For example, a user is updating a keyb
using the value from keya
. While updating, he reads thata
has version number10
. Also, during the update, another user is updatinga
, and the version number is updated to20
. Both transactions are submitted on chain with the tx to updatea
before the tx to updatec
. When the kv instance is replaying the onchain logs, it will first update a and set its version number to20
. Then when it executes the second transaction, it finds that the version ofa
is10
which is smaller than20
. So the second transaction is discarded.--skip-tx
is the flag for skipping tx if the data is already uploaded before (has same data root)
Example:
From the console output it is shown that the log of the kv-write
operation is similar to upload
except that kv-write
is for key-values pairs while upload
is for files.
Last updated