|
| 1 | +# Key-Value-Storage |
| 2 | + |
| 3 | +## License |
| 4 | + |
| 5 | +```text |
| 6 | +Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 7 | +
|
| 8 | +See the NOTICE file(s) distributed with this work for additional |
| 9 | +information regarding copyright ownership. |
| 10 | +
|
| 11 | +This program and the accompanying materials are made available under the |
| 12 | +terms of the Apache License Version 2.0 which is available at |
| 13 | +https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +
|
| 15 | +SPDX-License-Identifier: Apache-2.0 |
| 16 | +``` |
| 17 | + |
| 18 | +## Setup |
| 19 | + |
| 20 | +### System dependencies |
| 21 | + |
| 22 | +```bash |
| 23 | +sudo apt-get update |
| 24 | +sudo apt-get install -y curl build-essential protobuf-compiler libclang-dev |
| 25 | +``` |
| 26 | + |
| 27 | +### Rust installation |
| 28 | + |
| 29 | +[Install Rust using rustup](https://www.rust-lang.org/tools/install) |
| 30 | + |
| 31 | +```bash |
| 32 | +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
| 33 | +``` |
| 34 | + |
| 35 | +### Bazel installation |
| 36 | + |
| 37 | +[Install Bazel using Bazelisk](https://bazel.build/install/bazelisk) |
| 38 | + |
| 39 | +```bash |
| 40 | +curl --proto '=https' -sSfOL https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-amd64.deb |
| 41 | +dpkg -i bazelisk-amd64.deb |
| 42 | +rm bazelisk-amd64.deb |
| 43 | +``` |
| 44 | + |
| 45 | +Correct Bazel version will be installed on first run, based on `bazelversion` file. |
| 46 | + |
| 47 | +## Build |
| 48 | + |
| 49 | +List all targets: |
| 50 | + |
| 51 | +```bash |
| 52 | +bazel query //... |
| 53 | +``` |
| 54 | + |
| 55 | +Build selected target: |
| 56 | + |
| 57 | +```bash |
| 58 | +bazel build <TARGET_NAME> |
| 59 | +``` |
| 60 | + |
| 61 | +Build all targets: |
| 62 | + |
| 63 | +```bash |
| 64 | +bazel build //... |
| 65 | +``` |
| 66 | + |
| 67 | +## Run |
| 68 | + |
| 69 | +List all rust library targets: |
| 70 | + |
| 71 | +```bash |
| 72 | +bazel query 'kind(rust_library, //src/...)' |
| 73 | +``` |
| 74 | + |
| 75 | +Run selected target: |
| 76 | + |
| 77 | +```bash |
| 78 | +bazel run <TARGET_NAME> |
| 79 | +``` |
| 80 | + |
| 81 | +## Test |
| 82 | + |
| 83 | +List all test targets: |
| 84 | + |
| 85 | +```bash |
| 86 | +bazel query 'kind(rust_test, //...)' |
| 87 | +``` |
| 88 | + |
| 89 | +Run all tests: |
| 90 | + |
| 91 | +```bash |
| 92 | +bazel test //... |
| 93 | +``` |
| 94 | + |
| 95 | +Run Component Integration Tests (groupped into single Test Suite): |
| 96 | + |
| 97 | +```bash |
| 98 | +bazel test //src/rust/rust_kvs:cit |
| 99 | +``` |
| 100 | + |
| 101 | +Run selected test target: |
| 102 | + |
| 103 | +```bash |
| 104 | +bazel test <TARGET_NAME> |
| 105 | +``` |
| 106 | + |
| 107 | +## Cargo-based operations |
| 108 | + |
| 109 | +Please use Bazel whenever possible. |
| 110 | + |
| 111 | +### Build with Cargo |
| 112 | + |
| 113 | +Build using `cargo` directly: |
| 114 | + |
| 115 | +```bash |
| 116 | +cargo build |
| 117 | +``` |
| 118 | + |
| 119 | +### Run CLI tool with Cargo |
| 120 | + |
| 121 | +```bash |
| 122 | +cargo run --help |
| 123 | +``` |
| 124 | + |
| 125 | +```text |
| 126 | +--------------------------------------- |
| 127 | +KVS Tool - Command Line Interface |
| 128 | +--------------------------------------- |
| 129 | +
|
| 130 | +Version 0.1.0 |
| 131 | +Author: Joshua Licht, Continental Automotive Technologies GmbH - Contributors to the Eclipse Foundation |
| 132 | +
|
| 133 | +--------------------------------------- |
| 134 | +
|
| 135 | +Options: |
| 136 | +-h, --help Show this help message and exit |
| 137 | +-o, --operation Specify the operation to perform (setkey, getkey, removekey, listkeys, reset, snapshotcount, snapshotmaxcount, snapshotrestore, getkvsfilename, gethashfilename, createtestdata) |
| 138 | +-k, --key Specify the key to operate on (for key operations) |
| 139 | +-p, --payload Specify the value to write (for set operations) |
| 140 | +-t, --type Specify the value type for get operations (number, bool, string, null, array, object or first letter as a short form: n = number (except NULL)) |
| 141 | +-s, --snapshotid Specify the snapshot ID for Snapshot operations |
| 142 | +
|
| 143 | +--------------------------------------- |
| 144 | +
|
| 145 | +Usage Examples: |
| 146 | +
|
| 147 | +Read a Key and show value: |
| 148 | + kvs_tool -o getkey -k MyKey [optional: -t for type, if not specified, String is used. Panic if not correct type!] |
| 149 | + kvs_tool -o getkey -k MyKey -t number (or -t n) |
| 150 | + kvs_tool -o getkey -k MyKey -t bool (or -t b) |
| 151 | + kvs_tool -o getkey -k MyKey -t array (or -t a) |
| 152 | + kvs_tool -o getkey -k MyKey -t object (or -t o) |
| 153 | + kvs_tool -o getkey -k MyKey -t string (or -t s or no type specification => string is default) |
| 154 | + kvs_tool -o getkey -k MyKey -t null |
| 155 | +
|
| 156 | +Write a Key and use the <payload> as the data source: |
| 157 | + kvs_tool -o setkey -k MyKey -p 'Hello World' (automatically detects following types: Number, Boolean, String, Null, Object, Array) |
| 158 | + kvs_tool -o setkey -k MyKey -p 'true' |
| 159 | + kvs_tool -o setkey -k MyKey -p 15 |
| 160 | + kvs_tool -o setkey -k MyKey -p '[456,false,"Second"]' |
| 161 | + kvs_tool -o setkey -k MyKey -p '{"sub-number":789,"sub-string":"Third","sub-bool":true,"sub-array":[1246,false,"Fourth"],"sub-null":null}' |
| 162 | +
|
| 163 | +Delete a key: |
| 164 | + kvs_tool -o removekey -k MyKey |
| 165 | +
|
| 166 | +List Keys: |
| 167 | + kvs_tool -o listkeys |
| 168 | +
|
| 169 | +Reset KVS: |
| 170 | + kvs_tool -o reset |
| 171 | +
|
| 172 | +Snapshot Count: |
| 173 | + kvs_tool -o snapshotcount |
| 174 | +
|
| 175 | +Snapshot Restore: |
| 176 | + kvs_tool -o snapshotrestore -s 1 |
| 177 | +
|
| 178 | +Get KVS Filename: |
| 179 | + kvs_tool -o getkvsfilename -s 1 |
| 180 | +
|
| 181 | +Get Hash Filename: |
| 182 | + kvs_tool -o gethashfilename -s 1 |
| 183 | +
|
| 184 | +--------------------------------------- |
| 185 | +
|
| 186 | +Create Test Data: |
| 187 | + kvs_tool -o createtestdata (Creates Data provided by the example code in the KVS API) |
| 188 | + |
| 189 | +--------------------------------------- |
| 190 | +``` |
| 191 | + |
| 192 | +### Run tests with Cargo |
| 193 | + |
| 194 | +Using `cargo test`: |
| 195 | + |
| 196 | +```bash |
| 197 | +cargo test |
| 198 | +``` |
0 commit comments