Skip to content

Commit b4baa86

Browse files
authored
Extended query protocol sharding (#339)
* Prepared stmt sharding s tests * len check * remove python test * latest rust * move that to debug for sure * Add the actual tests * latest image * Update tests/ruby/sharding_spec.rb
1 parent 76e195a commit b4baa86

File tree

7 files changed

+320
-29
lines changed

7 files changed

+320
-29
lines changed

Diff for: .dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ target/
22
tests/
33
tracing/
44
.circleci/
5+
.git/
6+
dev/

Diff for: Dockerfile.ci

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM cimg/rust:1.62.0
1+
FROM cimg/rust:1.67.1
22
RUN sudo apt-get update && \
33
sudo apt-get install -y \
4-
psmisc postgresql-contrib-12 postgresql-client-12 libpq-dev \
4+
psmisc postgresql-contrib-14 postgresql-client-14 libpq-dev \
55
ruby ruby-dev python3 python3-pip \
66
lcov llvm-11 iproute2 && \
77
sudo apt-get upgrade curl && \

Diff for: dev/script/console

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44
export HOST_UID="$(id -u)"
55
export HOST_GID="$(id -g)"
6-
docker-compose -f "${DIR}/../docker-compose.yaml" run --rm pgcat-shell
6+
7+
if [[ "${1}" == "down" ]]; then
8+
docker-compose -f "${DIR}/../docker-compose.yaml" down
9+
exit 0
10+
else
11+
docker-compose -f "${DIR}/../docker-compose.yaml" run --rm pgcat-shell
12+
fi

Diff for: src/client.rs

+31-7
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,42 @@ where
675675
// allocate a connection, we wouldn't be able to send back an error message
676676
// to the client so we buffer them and defer the decision to error out or not
677677
// to when we get the S message
678-
'P' | 'B' | 'D' | 'E' => {
678+
'D' | 'E' => {
679679
self.buffer.put(&message[..]);
680680
continue;
681681
}
682+
683+
'Q' => {
684+
if query_router.query_parser_enabled() {
685+
query_router.infer(&message);
686+
}
687+
}
688+
689+
'P' => {
690+
self.buffer.put(&message[..]);
691+
692+
if query_router.query_parser_enabled() {
693+
query_router.infer(&message);
694+
}
695+
696+
continue;
697+
}
698+
699+
'B' => {
700+
self.buffer.put(&message[..]);
701+
702+
if query_router.query_parser_enabled() {
703+
query_router.infer_shard_from_bind(&message);
704+
}
705+
706+
continue;
707+
}
708+
682709
'X' => {
683710
debug!("Client disconnecting");
684711
return Ok(());
685712
}
713+
686714
_ => (),
687715
}
688716

@@ -711,11 +739,7 @@ where
711739
// Handle all custom protocol commands, if any.
712740
match query_router.try_execute_command(&message) {
713741
// Normal query, not a custom command.
714-
None => {
715-
if query_router.query_parser_enabled() {
716-
query_router.infer(&message);
717-
}
718-
}
742+
None => (),
719743

720744
// SET SHARD TO
721745
Some((Command::SetShard, _)) => {
@@ -727,7 +751,7 @@ where
727751
error_response(
728752
&mut self.write,
729753
&format!(
730-
"shard {} is more than configured {}, staying on shard {}",
754+
"shard {} is more than configured {}, staying on shard {} (shard numbers start at 0)",
731755
query_router.shard(),
732756
pool.shards(),
733757
current_shard,

0 commit comments

Comments
 (0)