Skip to content

Commit 0a8f4cb

Browse files
committed
feat scylla: LWT transactions, sample service and docs
1 parent 8725c12 commit 0a8f4cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5257
-765
lines changed

samples/scylla_service/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ project(userver-samples-scylla_service CXX)
44
find_package(userver COMPONENTS scylla REQUIRED)
55
userver_setup_environment()
66

7-
add_executable(${PROJECT_NAME} main.cpp)
7+
add_executable(${PROJECT_NAME} src/main.cpp src/helpers.cpp)
88
target_link_libraries(${PROJECT_NAME} userver::scylla)
9+
10+
userver_testsuite_add_simple()

samples/scylla_service/README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# scylla_service demo
2+
3+
Enter the ScyllaDB container and open cqlsh
4+
5+
```shell
6+
docker exec -it scylla cqlsh
7+
```
8+
9+
Create the keyspace and table
10+
11+
```sql
12+
CREATE KEYSPACE IF NOT EXISTS examples
13+
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
14+
15+
CREATE TABLE IF NOT EXISTS examples.basic (
16+
key text PRIMARY KEY,
17+
bln boolean,
18+
flt float,
19+
dbl double,
20+
i32 int,
21+
i64 bigint
22+
);
23+
```
24+
25+
26+
---
27+
28+
```shell
29+
docker exec -it scylla-dev-1 bash
30+
```
31+
32+
## Operations
33+
34+
35+
### InsertOne
36+
37+
```bash
38+
curl -sS -X POST "http://localhost:8080/v1/kv" \
39+
-H 'Content-Type: application/json' \
40+
-d '{"key":"alpha","bln":true,"i32":1,"i64":42,"flt":1.5,"dbl":2.5}'
41+
```
42+
43+
### 2. SelectOne
44+
45+
```bash
46+
curl -sS "http://localhost:8080/v1/kv?key=alpha"
47+
48+
# should return 404
49+
curl -sS -w '\n%{http_code}\n' "http://localhost:8080/v1/kv?key=does-not-exist"
50+
```
51+
52+
### 3. UpdateOne
53+
54+
```bash
55+
curl -sS -X PATCH "http://localhost:8080/v1/kv?key=alpha" \
56+
-H 'Content-Type: application/json' \
57+
-d '{"bln":false,"i32":99}'
58+
59+
curl -sS "http://localhost:8080/v1/kv?key=alpha"
60+
```
61+
62+
### 4. DeleteOne
63+
64+
```bash
65+
curl -sS -X DELETE "http://localhost:8080/v1/kv?key=alpha"
66+
```
67+
68+
### 5. InsertMany
69+
70+
```bash
71+
curl -sS -X POST "http://localhost:8080/v1/kv/bulk" \
72+
-H 'Content-Type: application/json' \
73+
-d '[
74+
{"key":"bulk-1","i32":1,"bln":true},
75+
{"key":"bulk-2","i32":2,"bln":true},
76+
{"key":"bulk-3","i32":3,"bln":false}
77+
]'
78+
```
79+
80+
### 6. SelectMany
81+
82+
```bash
83+
curl -sS "http://localhost:8080/v1/kv/list"
84+
85+
curl -sS "http://localhost:8080/v1/kv/list?limit=2"
86+
```
87+
88+
### 7. Count
89+
90+
```bash
91+
curl -sS "http://localhost:8080/v1/kv/count"
92+
93+
curl -sS "http://localhost:8080/v1/kv/count?key=bulk-1"
94+
```
95+
96+
### 8. Truncate
97+
98+
```bash
99+
curl -sS -X POST "http://localhost:8080/v1/kv/truncate"
100+
101+
curl -sS "http://localhost:8080/v1/kv/count"
102+
```
103+
104+
### 9. InsertOne IF NOT EXISTS (LWT)
105+
106+
```bash
107+
curl -sS -X POST "http://localhost:8080/v1/kv/create_if_absent" \
108+
-H 'Content-Type: application/json' \
109+
-d '{"key":"lwt-1","i32":100}'
110+
111+
curl -sS -w '\n%{http_code}\n' -X POST "http://localhost:8080/v1/kv/create_if_absent" \
112+
-H 'Content-Type: application/json' \
113+
-d '{"key":"lwt-1","i32":999}'
114+
```
115+
116+
### 10. UpdateOne IF col = ? (Compare-And-Set)
117+
118+
```bash
119+
curl -sS -X POST "http://localhost:8080/v1/kv/cas?key=lwt-1" \
120+
-H 'Content-Type: application/json' \
121+
-d '{"expect":{"i32":100},"set":{"i32":101}}'
122+
123+
curl -sS -w '\n%{http_code}\n' -X POST "http://localhost:8080/v1/kv/cas?key=lwt-1" \
124+
-H 'Content-Type: application/json' \
125+
-d '{"expect":{"i32":100},"set":{"i32":200}}'
126+
```
127+
128+
### 11. DeleteOne IF EXISTS
129+
130+
```bash
131+
curl -sS -X DELETE "http://localhost:8080/v1/kv/delete_if_exists?key=lwt-1"
132+
133+
curl -sS -w '\n%{http_code}\n' -X DELETE "http://localhost:8080/v1/kv/delete_if_exists?key=lwt-1"
134+
```
135+
136+
137+
---
138+
139+
Current `static_config.yaml`
140+
141+
```yaml
142+
scylla-db:
143+
dbconnection: scylla
144+
consistency: local_quorum
145+
serial_consistency: local_serial
146+
request_timeout: 10s
147+
pool_size: 16
148+
app_name: scylla_sample
149+
shard_awareness: true
150+
retry_policy: default
151+
load_balancing_policy: round_robin
152+
speculative_execution:
153+
enabled: false
154+
max_attempts: 2
155+
delay: 100ms
156+
default_keyspace: examples
157+
```

samples/scylla_service/main.cpp

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scylla_settings": {
3+
"scylla_example": {
4+
"hosts": "scylla"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)