Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ if(USERVER_FEATURE_GRPC)
list(APPEND USERVER_AVAILABLE_COMPONENTS grpc)
endif()

if(USERVER_FEATURE_SCYLLADB)
_require_userver_core("USERVER_FEATURE_SCYLLADB")
add_subdirectory(scylla)
list(APPEND USERVER_AVAILABLE_COMPONENTS scylla)
endif()


if(USERVER_FEATURE_OTLP)
if(NOT USERVER_FEATURE_GRPC)
message(FATAL_ERROR "'USERVER_FEATURE_OTLP' requires 'USERVER_FEATURE_GRPC=ON'")
Expand Down
16 changes: 16 additions & 0 deletions cmake/SetupScyllaDeps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_guard(GLOBAL)

find_library(SCYLLA_CPP_DRIVER_LIB scylla-cpp-driver)
find_path(SCYLLA_CPP_DRIVER_INCLUDE cassandra.h)

if(NOT SCYLLA_CPP_DRIVER_LIB OR NOT SCYLLA_CPP_DRIVER_INCLUDE)
message(FATAL_ERROR "ScyllaDB cpp-driver not found")
endif()

message(STATUS "ScyllaDB cpp-driver: ${SCYLLA_CPP_DRIVER_LIB}")

add_library(scylla_cpp_driver SHARED IMPORTED)
set_target_properties(scylla_cpp_driver PROPERTIES
IMPORTED_LOCATION "${SCYLLA_CPP_DRIVER_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${SCYLLA_CPP_DRIVER_INCLUDE}"
)
11 changes: 11 additions & 0 deletions cmake/install/userver-scylla-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include_guard(GLOBAL)

if(userver_scylla_FOUND)
return()
endif()

find_package(userver REQUIRED COMPONENTS core)

include("${USERVER_CMAKE_DIR}/SetupScyllaDeps.cmake")

set(userver_scylla_FOUND TRUE)
12 changes: 3 additions & 9 deletions mongo/src/storages/mongo/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ void OperationStopwatch::Account(ErrorType error_type) noexcept {
UASSERT(ms >= 0);
stats_item->timings.GetCurrentCounter().Account(ms);
stats_item->timings_sum += utils::statistics::Rate{static_cast<utils::statistics::Rate::ValueType>(ms)};
} catch (const std::exception&) {
// ignore
}
} catch (const std::exception&) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vibe coding detected :)

}

ConnectionWaitStopwatch::ConnectionWaitStopwatch(std::shared_ptr<PoolConnectStatistics> stats_ptr)
Expand All @@ -201,9 +199,7 @@ ConnectionWaitStopwatch::~ConnectionWaitStopwatch() {
try {
++stats_ptr_->requested;
stats_ptr_->request_timings_agg.GetCurrentCounter().Account(GetMilliseconds(scope_time_.Reset()));
} catch (const std::exception&) {
// ignore
}
} catch (const std::exception&) {}
}

ConnectionThrottleStopwatch::ConnectionThrottleStopwatch(std::shared_ptr<PoolConnectStatistics> stats_ptr)
Expand All @@ -225,9 +221,7 @@ void ConnectionThrottleStopwatch::Stop() noexcept {

try {
stats_ptr->queue_wait_timings_agg.GetCurrentCounter().Account(GetMilliseconds(scope_time_.Reset()));
} catch (const std::exception&) {
// ignore
}
} catch (const std::exception&) {}
}

} // namespace storages::mongo::stats
Expand Down
10 changes: 10 additions & 0 deletions samples/scylla_service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.14)
project(userver-samples-scylla_service CXX)

find_package(userver COMPONENTS scylla REQUIRED)
userver_setup_environment()

add_executable(${PROJECT_NAME} src/main.cpp src/helpers.cpp)
target_link_libraries(${PROJECT_NAME} userver::scylla)

userver_testsuite_add_simple()
157 changes: 157 additions & 0 deletions samples/scylla_service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# scylla_service demo

Enter the ScyllaDB container and open cqlsh

```shell
docker exec -it scylla cqlsh
```

Create the keyspace and table

```sql
CREATE KEYSPACE IF NOT EXISTS examples
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

CREATE TABLE IF NOT EXISTS examples.basic (
key text PRIMARY KEY,
bln boolean,
flt float,
dbl double,
i32 int,
i64 bigint
);
```


---

```shell
docker exec -it scylla-dev-1 bash
```

## Operations


### InsertOne

```bash
curl -sS -X POST "http://localhost:8080/v1/kv" \
-H 'Content-Type: application/json' \
-d '{"key":"alpha","bln":true,"i32":1,"i64":42,"flt":1.5,"dbl":2.5}'
```

### 2. SelectOne

```bash
curl -sS "http://localhost:8080/v1/kv?key=alpha"

# should return 404
curl -sS -w '\n%{http_code}\n' "http://localhost:8080/v1/kv?key=does-not-exist"
```

### 3. UpdateOne

```bash
curl -sS -X PATCH "http://localhost:8080/v1/kv?key=alpha" \
-H 'Content-Type: application/json' \
-d '{"bln":false,"i32":99}'

curl -sS "http://localhost:8080/v1/kv?key=alpha"
```

### 4. DeleteOne

```bash
curl -sS -X DELETE "http://localhost:8080/v1/kv?key=alpha"
```

### 5. InsertMany

```bash
curl -sS -X POST "http://localhost:8080/v1/kv/bulk" \
-H 'Content-Type: application/json' \
-d '[
{"key":"bulk-1","i32":1,"bln":true},
{"key":"bulk-2","i32":2,"bln":true},
{"key":"bulk-3","i32":3,"bln":false}
]'
```

### 6. SelectMany

```bash
curl -sS "http://localhost:8080/v1/kv/list"

curl -sS "http://localhost:8080/v1/kv/list?limit=2"
```

### 7. Count

```bash
curl -sS "http://localhost:8080/v1/kv/count"

curl -sS "http://localhost:8080/v1/kv/count?key=bulk-1"
```

### 8. Truncate

```bash
curl -sS -X POST "http://localhost:8080/v1/kv/truncate"

curl -sS "http://localhost:8080/v1/kv/count"
```

### 9. InsertOne IF NOT EXISTS (LWT)

```bash
curl -sS -X POST "http://localhost:8080/v1/kv/create_if_absent" \
-H 'Content-Type: application/json' \
-d '{"key":"lwt-1","i32":100}'

curl -sS -w '\n%{http_code}\n' -X POST "http://localhost:8080/v1/kv/create_if_absent" \
-H 'Content-Type: application/json' \
-d '{"key":"lwt-1","i32":999}'
```

### 10. UpdateOne IF col = ? (Compare-And-Set)

```bash
curl -sS -X POST "http://localhost:8080/v1/kv/cas?key=lwt-1" \
-H 'Content-Type: application/json' \
-d '{"expect":{"i32":100},"set":{"i32":101}}'

curl -sS -w '\n%{http_code}\n' -X POST "http://localhost:8080/v1/kv/cas?key=lwt-1" \
-H 'Content-Type: application/json' \
-d '{"expect":{"i32":100},"set":{"i32":200}}'
```

### 11. DeleteOne IF EXISTS

```bash
curl -sS -X DELETE "http://localhost:8080/v1/kv/delete_if_exists?key=lwt-1"

curl -sS -w '\n%{http_code}\n' -X DELETE "http://localhost:8080/v1/kv/delete_if_exists?key=lwt-1"
```


---

Current `static_config.yaml`

```yaml
scylla-db:
dbconnection: scylla
consistency: local_quorum
serial_consistency: local_serial
request_timeout: 10s
pool_size: 16
app_name: scylla_sample
shard_awareness: true
retry_policy: default
load_balancing_policy: round_robin
speculative_execution:
enabled: false
max_attempts: 2
delay: 100ms
default_keyspace: examples
```
7 changes: 7 additions & 0 deletions samples/scylla_service/secdist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"scylla_settings": {
"scylla_example": {
"hosts": "scylla"
}
}
}
Loading