Skip to content
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

Introduce support for Tablets #937

Merged
merged 16 commits into from
May 9, 2024
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ jobs:
run: cargo fmt --verbose --all -- --check
- name: Clippy check
run: cargo clippy --verbose --all-targets
- name: Clippy check with all features
run: cargo clippy --verbose --all-targets --all-features
- name: Cargo check without features
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features ""
- name: Cargo check with all serialization features
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "full-serialization"
- name: Cargo check with all features
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --all-features
Lorak-mmk marked this conversation as resolved.
Show resolved Hide resolved
- name: Cargo check with secret feature
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "secret"
- name: Cargo check with chrono feature
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/tablets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tablets

on:
push:
branches:
- main
- 'branch-*'
pull_request:
branches:
- main
- 'branch-*'

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- name: Install scylla-ccm
run: pip3 install https://github.com/scylladb/scylla-ccm/archive/master.zip

- name: Create cluster with tablets enabled
run: |
ccm create tablets -i 127.0.1. -n 3 --scylla -v 'unstable/master:2024-05-01T18:26:10Z'
ccm updateconf 'experimental_features: [consistent-topology-changes, tablets]'
ccm start

- name: Check
run: cargo check --verbose
- name: Run tablets tests
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

- name: Remove tablets cluster
run: ccm remove tablets
85 changes: 69 additions & 16 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ COMPOSE := docker compose -f test/cluster/docker-compose.yml
all: test

.PHONY: ci
ci: fmt-check check check-without-features clippy test build
ci: fmt-check check check-without-features check-all-features clippy clippy-all-features test build

.PHONY: dockerized-ci
dockerized-ci: fmt-check check check-without-features clippy dockerized-test build
dockerized-ci: fmt-check check check-without-features check-all-features clippy clippy-all-features dockerized-test build

.PHONY: fmt
fmt:
Expand All @@ -25,10 +25,18 @@ check:
check-without-features:
cargo check --manifest-path "scylla/Cargo.toml" --features "" --all-targets

.PHONY: check-all-features
check-all-features:
cargo check --all-targets --all-features

.PHONY: clippy
clippy:
RUSTFLAGS=-Dwarnings cargo clippy --all-targets

.PHONY: clippy-all-features
clippy-all-features:
RUSTFLAGS=-Dwarnings cargo clippy --all-targets --all-features

.PHONY: test
test: up
SCYLLA_URI=172.42.0.2:9042 \
Expand Down
2 changes: 1 addition & 1 deletion examples/compare-tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn main() -> Result<()> {
"Token endpoints for query: {:?}",
session
.get_cluster_data()
.get_token_endpoints("examples_ks", Token::new(t))
.get_token_endpoints("examples_ks", "compare_tokens", Token::new(t))
.iter()
.map(|(node, _shard)| node.address)
.collect::<Vec<NodeAddr>>()
Expand Down
15 changes: 9 additions & 6 deletions scylla-cql/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use thiserror::Error;
use tokio::io::{AsyncRead, AsyncReadExt};
use uuid::Uuid;

use std::convert::TryFrom;
use std::{collections::HashMap, convert::TryFrom};

use request::SerializableRequest;
use response::ResponseOpcode;
Expand Down Expand Up @@ -169,6 +169,7 @@ pub struct ResponseBodyWithExtensions {
pub trace_id: Option<Uuid>,
pub warnings: Vec<String>,
pub body: Bytes,
pub custom_payload: Option<HashMap<String, Vec<u8>>>,
}

pub fn parse_response_body_extensions(
Expand Down Expand Up @@ -204,20 +205,22 @@ pub fn parse_response_body_extensions(
Vec::new()
};

if flags & FLAG_CUSTOM_PAYLOAD != 0 {
// TODO: Do something useful with the custom payload map
// For now, just skip it
let custom_payload = if flags & FLAG_CUSTOM_PAYLOAD != 0 {
let body_len = body.len();
let buf = &mut &*body;
types::read_bytes_map(buf)?;
let payload_map = types::read_bytes_map(buf)?;
let buf_len = buf.len();
body.advance(body_len - buf_len);
}
Some(payload_map)
} else {
None
};
Lorak-mmk marked this conversation as resolved.
Show resolved Hide resolved

Ok(ResponseBodyWithExtensions {
trace_id,
warnings,
body,
custom_payload,
})
}

Expand Down
12 changes: 12 additions & 0 deletions scylla-cql/src/frame/protocol_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use std::collections::HashMap;
const RATE_LIMIT_ERROR_EXTENSION: &str = "SCYLLA_RATE_LIMIT_ERROR";
pub const SCYLLA_LWT_ADD_METADATA_MARK_EXTENSION: &str = "SCYLLA_LWT_ADD_METADATA_MARK";
pub const LWT_OPTIMIZATION_META_BIT_MASK_KEY: &str = "LWT_OPTIMIZATION_META_BIT_MASK";
const TABLETS_ROUTING_V1_KEY: &str = "TABLETS_ROUTING_V1";

#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ProtocolFeatures {
pub rate_limit_error: Option<i32>,
pub lwt_optimization_meta_bit_mask: Option<u32>,
pub tablets_v1_supported: bool,
}

// TODO: Log information about options which failed to parse
Expand All @@ -19,6 +22,7 @@ impl ProtocolFeatures {
lwt_optimization_meta_bit_mask: Self::maybe_parse_lwt_optimization_meta_bit_mask(
supported,
),
tablets_v1_supported: Self::check_tablets_routing_v1_support(supported),
}
}

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

fn check_tablets_routing_v1_support(supported: &HashMap<String, Vec<String>>) -> bool {
supported.contains_key(TABLETS_ROUTING_V1_KEY)
}

// Looks up a field which starts with `key=` and returns the rest
fn get_cql_extension_field<'a>(vals: &'a [String], key: &str) -> Option<&'a str> {
vals.iter()
Expand All @@ -53,6 +61,10 @@ impl ProtocolFeatures {
format!("{}={}", LWT_OPTIMIZATION_META_BIT_MASK_KEY, mask),
);
}

if self.tablets_v1_supported {
options.insert(TABLETS_ROUTING_V1_KEY.to_string(), String::new());
}
}

pub fn prepared_flags_contain_lwt_mark(&self, flags: u32) -> bool {
Expand Down
Loading
Loading