Skip to content

Add 'Fail' mode when no shard selected #859

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions pgcat.toml
Original file line number Diff line number Diff line change
@@ -179,6 +179,7 @@ primary_reads_enabled = true
# `random`: picks a shard at random
# `random_healthy`: picks a shard at random favoring shards with the least number of recent errors
# `shard_<number>`: e.g. shard_0, shard_4, etc. picks a specific shard, everytime
# `fail`: fails to pick up shard. (require explicit shard setup)
# default_shard = "shard_0"

# So what if you wanted to implement a different hashing function,
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -773,6 +773,7 @@ pub enum DefaultShard {
Shard(usize),
Random,
RandomHealthy,
Fail,
}
impl Default for DefaultShard {
fn default() -> Self {
@@ -787,6 +788,7 @@ impl serde::Serialize for DefaultShard {
}
DefaultShard::Random => serializer.serialize_str("random"),
DefaultShard::RandomHealthy => serializer.serialize_str("random_healthy"),
DefaultShard::Fail => serializer.serialize_str("fail"),
}
}
}
@@ -804,6 +806,7 @@ impl<'de> serde::Deserialize<'de> for DefaultShard {
match s.as_str() {
"random" => Ok(DefaultShard::Random),
"random_healthy" => Ok(DefaultShard::RandomHealthy),
"fail" => Ok(DefaultShard::Fail),
_ => Err(serde::de::Error::custom(
"invalid value for no_shard_specified_behavior",
)),
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ pub enum Error {
QueryRouterError(String),
InvalidShardId(usize),
PreparedStatementError,
NoShardSelected,
}

#[derive(Clone, PartialEq, Debug)]
1 change: 1 addition & 0 deletions src/pool.rs
Original file line number Diff line number Diff line change
@@ -720,6 +720,7 @@ impl ConnectionPool {
.unwrap()
});
}
DefaultShard::Fail => return Err(Error::NoShardSelected),
},
};