Skip to content

Commit 1166cc7

Browse files
authored
Merge pull request #937 from Lorak-mmk/tablets
Introduce support for Tablets
2 parents 729fa50 + 426db65 commit 1166cc7

File tree

32 files changed

+2792
-261
lines changed

32 files changed

+2792
-261
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ jobs:
3030
run: cargo fmt --verbose --all -- --check
3131
- name: Clippy check
3232
run: cargo clippy --verbose --all-targets
33+
- name: Clippy check with all features
34+
run: cargo clippy --verbose --all-targets --all-features
3335
- name: Cargo check without features
3436
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features ""
3537
- name: Cargo check with all serialization features
3638
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "full-serialization"
39+
- name: Cargo check with all features
40+
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --all-features
3741
- name: Cargo check with secret feature
3842
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "secret"
3943
- name: Cargo check with chrono feature

.github/workflows/tablets.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tablets
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'branch-*'
8+
pull_request:
9+
branches:
10+
- main
11+
- 'branch-*'
12+
13+
env:
14+
CARGO_TERM_COLOR: always
15+
RUST_BACKTRACE: full
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 60
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Install scylla-ccm
24+
run: pip3 install https://github.com/scylladb/scylla-ccm/archive/master.zip
25+
26+
- name: Create cluster with tablets enabled
27+
run: |
28+
ccm create tablets -i 127.0.1. -n 3 --scylla -v 'unstable/master:2024-05-01T18:26:10Z'
29+
ccm updateconf 'experimental_features: [consistent-topology-changes, tablets]'
30+
ccm start
31+
32+
- name: Check
33+
run: cargo check --verbose
34+
- name: Run tablets tests
35+
run: SCYLLA_URI=127.0.1.1:9042 SCYLLA_URI2=127.0.1.2:9042 SCYLLA_URI3=127.0.1.3:9042 cargo test --verbose
36+
37+
- name: Remove tablets cluster
38+
run: ccm remove tablets

Cargo.lock.msrv

Lines changed: 69 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ COMPOSE := docker compose -f test/cluster/docker-compose.yml
44
all: test
55

66
.PHONY: ci
7-
ci: fmt-check check check-without-features clippy test build
7+
ci: fmt-check check check-without-features check-all-features clippy clippy-all-features test build
88

99
.PHONY: dockerized-ci
10-
dockerized-ci: fmt-check check check-without-features clippy dockerized-test build
10+
dockerized-ci: fmt-check check check-without-features check-all-features clippy clippy-all-features dockerized-test build
1111

1212
.PHONY: fmt
1313
fmt:
@@ -25,10 +25,18 @@ check:
2525
check-without-features:
2626
cargo check --manifest-path "scylla/Cargo.toml" --features "" --all-targets
2727

28+
.PHONY: check-all-features
29+
check-all-features:
30+
cargo check --all-targets --all-features
31+
2832
.PHONY: clippy
2933
clippy:
3034
RUSTFLAGS=-Dwarnings cargo clippy --all-targets
3135

36+
.PHONY: clippy-all-features
37+
clippy-all-features:
38+
RUSTFLAGS=-Dwarnings cargo clippy --all-targets --all-features
39+
3240
.PHONY: test
3341
test: up
3442
SCYLLA_URI=172.42.0.2:9042 \

examples/compare-tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async fn main() -> Result<()> {
3939
"Token endpoints for query: {:?}",
4040
session
4141
.get_cluster_data()
42-
.get_token_endpoints("examples_ks", Token::new(t))
42+
.get_token_endpoints("examples_ks", "compare_tokens", Token::new(t))
4343
.iter()
4444
.map(|(node, _shard)| node.address)
4545
.collect::<Vec<NodeAddr>>()

scylla-cql/src/frame/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use thiserror::Error;
1515
use tokio::io::{AsyncRead, AsyncReadExt};
1616
use uuid::Uuid;
1717

18-
use std::convert::TryFrom;
18+
use std::{collections::HashMap, convert::TryFrom};
1919

2020
use request::SerializableRequest;
2121
use response::ResponseOpcode;
@@ -169,6 +169,7 @@ pub struct ResponseBodyWithExtensions {
169169
pub trace_id: Option<Uuid>,
170170
pub warnings: Vec<String>,
171171
pub body: Bytes,
172+
pub custom_payload: Option<HashMap<String, Vec<u8>>>,
172173
}
173174

174175
pub fn parse_response_body_extensions(
@@ -204,20 +205,22 @@ pub fn parse_response_body_extensions(
204205
Vec::new()
205206
};
206207

207-
if flags & FLAG_CUSTOM_PAYLOAD != 0 {
208-
// TODO: Do something useful with the custom payload map
209-
// For now, just skip it
208+
let custom_payload = if flags & FLAG_CUSTOM_PAYLOAD != 0 {
210209
let body_len = body.len();
211210
let buf = &mut &*body;
212-
types::read_bytes_map(buf)?;
211+
let payload_map = types::read_bytes_map(buf)?;
213212
let buf_len = buf.len();
214213
body.advance(body_len - buf_len);
215-
}
214+
Some(payload_map)
215+
} else {
216+
None
217+
};
216218

217219
Ok(ResponseBodyWithExtensions {
218220
trace_id,
219221
warnings,
220222
body,
223+
custom_payload,
221224
})
222225
}
223226

scylla-cql/src/frame/protocol_features.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use std::collections::HashMap;
33
const RATE_LIMIT_ERROR_EXTENSION: &str = "SCYLLA_RATE_LIMIT_ERROR";
44
pub const SCYLLA_LWT_ADD_METADATA_MARK_EXTENSION: &str = "SCYLLA_LWT_ADD_METADATA_MARK";
55
pub const LWT_OPTIMIZATION_META_BIT_MASK_KEY: &str = "LWT_OPTIMIZATION_META_BIT_MASK";
6+
const TABLETS_ROUTING_V1_KEY: &str = "TABLETS_ROUTING_V1";
7+
68
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
79
#[non_exhaustive]
810
pub struct ProtocolFeatures {
911
pub rate_limit_error: Option<i32>,
1012
pub lwt_optimization_meta_bit_mask: Option<u32>,
13+
pub tablets_v1_supported: bool,
1114
}
1215

1316
// TODO: Log information about options which failed to parse
@@ -19,6 +22,7 @@ impl ProtocolFeatures {
1922
lwt_optimization_meta_bit_mask: Self::maybe_parse_lwt_optimization_meta_bit_mask(
2023
supported,
2124
),
25+
tablets_v1_supported: Self::check_tablets_routing_v1_support(supported),
2226
}
2327
}
2428

@@ -37,6 +41,10 @@ impl ProtocolFeatures {
3741
mask_str.parse::<u32>().ok()
3842
}
3943

44+
fn check_tablets_routing_v1_support(supported: &HashMap<String, Vec<String>>) -> bool {
45+
supported.contains_key(TABLETS_ROUTING_V1_KEY)
46+
}
47+
4048
// Looks up a field which starts with `key=` and returns the rest
4149
fn get_cql_extension_field<'a>(vals: &'a [String], key: &str) -> Option<&'a str> {
4250
vals.iter()
@@ -53,6 +61,10 @@ impl ProtocolFeatures {
5361
format!("{}={}", LWT_OPTIMIZATION_META_BIT_MASK_KEY, mask),
5462
);
5563
}
64+
65+
if self.tablets_v1_supported {
66+
options.insert(TABLETS_ROUTING_V1_KEY.to_string(), String::new());
67+
}
5668
}
5769

5870
pub fn prepared_flags_contain_lwt_mark(&self, flags: u32) -> bool {

0 commit comments

Comments
 (0)