Skip to content

Commit deb068b

Browse files
committed
sharding: introduce error variant for cassandra cluster
I added a new error variant to distinguish between a scenario where we (most likely) connect to Cassandra cluster (all params missing) and where Scylla has a bug (some params are present, some not).
1 parent 2b92d27 commit deb068b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

scylla/src/routing/sharding.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ impl Sharder {
9797

9898
#[derive(Clone, Error, Debug)]
9999
pub enum ShardingError {
100+
/// This indicates that we are most likely connected to a Cassandra cluster.
101+
/// Unless, there is some serious bug in Scylla.
102+
#[error("Server did not provide any sharding information")]
103+
NoShardInfo,
100104
#[error("ShardInfo parameters missing")]
101105
MissingShardInfoParameter,
102106
#[error("ShardInfo parameters missing after unwrapping")]
@@ -119,11 +123,16 @@ impl<'a> TryFrom<&'a HashMap<String, Vec<String>>> for ShardInfo {
119123
let msb_ignore_entry = options.get(MSB_IGNORE_ENTRY);
120124

121125
// Unwrap entries.
122-
let (Some(shard_entry), Some(nr_shards_entry), Some(msb_ignore_entry)) =
123-
(shard_entry, nr_shards_entry, msb_ignore_entry)
124-
else {
125-
return Err(ShardingError::MissingShardInfoParameter);
126-
};
126+
let (shard_entry, nr_shards_entry, msb_ignore_entry) =
127+
match (shard_entry, nr_shards_entry, msb_ignore_entry) {
128+
(Some(shard_entry), Some(nr_shards_entry), Some(msb_ignore_entry)) => {
129+
(shard_entry, nr_shards_entry, msb_ignore_entry)
130+
}
131+
// All parameters are missing - most likely a Cassandra cluster.
132+
(None, None, None) => return Err(ShardingError::NoShardInfo),
133+
// At least one of the parameters is present, but some are missing. A bug in Scylla.
134+
_ => return Err(ShardingError::MissingShardInfoParameter),
135+
};
127136

128137
// Further unwrap entries (they should be the first entries of their corresponding Vecs).
129138
let (Some(shard_entry), Some(nr_shards_entry), Some(msb_ignore_entry)) = (

0 commit comments

Comments
 (0)