Skip to content

Commit 71486c1

Browse files
committed
rest: only show field with custom sharding method
1 parent bb33a83 commit 71486c1

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

docs/redoc/master/openapi.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16007,15 +16007,14 @@
1600716007
},
1600816008
"ShardKeysResponse": {
1600916009
"type": "object",
16010-
"required": [
16011-
"shard_keys"
16012-
],
1601316010
"properties": {
1601416011
"shard_keys": {
16012+
"description": "The existing shard keys. Only available when sharding method is `custom`",
1601516013
"type": "array",
1601616014
"items": {
1601716015
"$ref": "#/components/schemas/ShardKeyDescription"
16018-
}
16016+
},
16017+
"nullable": true
1601916018
}
1602016019
}
1602116020
},

lib/api/src/grpc/conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl From<(Instant, ShardKeysResponse)> for ListShardKeysResponse {
134134
let ShardKeysResponse { shard_keys } = response;
135135
let shard_keys = shard_keys
136136
.into_iter()
137+
.flatten()
137138
.map(|key_desc| {
138139
let key = Some(convert_shard_key_to_grpc(key_desc.key));
139140
ShardKeyDescription { key }

lib/api/src/rest/models.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,7 @@ pub struct ShardKeyDescription {
171171
#[derive(Debug, Serialize, JsonSchema)]
172172
#[serde(rename_all = "snake_case")]
173173
pub struct ShardKeysResponse {
174-
pub shard_keys: Vec<ShardKeyDescription>,
174+
/// The existing shard keys. Only available when sharding method is `custom`
175+
#[serde(skip_serializing_if = "Option::is_none")]
176+
pub shard_keys: Option<Vec<ShardKeyDescription>>,
175177
}

src/common/collections.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@ pub async fn do_get_collection_shard_keys(
100100
let collection = toc.get_collection(&collection_pass).await?;
101101

102102
let state = collection.state().await;
103-
let shard_keys = state
104-
.shards_key_mapping
105-
.iter_shard_keys()
106-
.map(|k| ShardKeyDescription { key: k.clone() })
107-
.collect();
103+
let shard_keys = match state.config.params.sharding_method.unwrap_or_default() {
104+
ShardingMethod::Auto => None,
105+
ShardingMethod::Custom => Some(
106+
state
107+
.shards_key_mapping
108+
.iter_shard_keys()
109+
.map(|k| ShardKeyDescription { key: k.clone() })
110+
.collect(),
111+
),
112+
};
108113

109114
Ok(ShardKeysResponse { shard_keys })
110115
}

0 commit comments

Comments
 (0)