-
Notifications
You must be signed in to change notification settings - Fork 378
Introduce a ScyllaDB driver for userver #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gearonixx
wants to merge
6
commits into
userver-framework:develop
Choose a base branch
from
gearonixx:scylladb-driver
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34c4874
feat scylla: add initial driver skeleton
gearonixx d7e0c8c
feat scylla: add select operation
gearonixx b51705c
refactor scylla: rework exception handling
gearonixx 6be55ed
feat scylla: SSL, secdist and speculative execution
gearonixx 8725c12
refactor scylla: optimize statements and cql builder
gearonixx 0a8f4cb
feat scylla: LWT transactions, sample service and docs
gearonixx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "scylla_settings": { | ||
| "scylla_example": { | ||
| "hosts": "scylla" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vibe coding detected :)