feat: Add ShardConfig to DatabaseRules proto

pull/24376/head
Marko Mikulicic 2021-03-26 11:10:25 +01:00 committed by kodiakhq[bot]
parent 790e5d3348
commit 98fe75c989
4 changed files with 29 additions and 2 deletions

View File

@ -118,6 +118,7 @@ impl From<DatabaseRules> for management::DatabaseRules {
partition_template: Some(rules.partition_template.into()), partition_template: Some(rules.partition_template.into()),
wal_buffer_config: rules.wal_buffer_config.map(Into::into), wal_buffer_config: rules.wal_buffer_config.map(Into::into),
mutable_buffer_config: rules.mutable_buffer_config.map(Into::into), mutable_buffer_config: rules.mutable_buffer_config.map(Into::into),
shard_config: rules.shard_config.map(Into::into),
} }
} }
} }
@ -139,12 +140,17 @@ impl TryFrom<management::DatabaseRules> for DatabaseRules {
.optional("partition_template")? .optional("partition_template")?
.unwrap_or_default(); .unwrap_or_default();
let shard_config = proto
.shard_config
.optional("shard_config")
.unwrap_or_default();
Ok(Self { Ok(Self {
name: proto.name, name: proto.name,
partition_template, partition_template,
wal_buffer_config, wal_buffer_config,
mutable_buffer_config, mutable_buffer_config,
shard_config: None, shard_config,
}) })
} }
} }
@ -1152,6 +1158,7 @@ mod tests {
// These should be none as preserved on non-protobuf DatabaseRules // These should be none as preserved on non-protobuf DatabaseRules
assert!(back.wal_buffer_config.is_none()); assert!(back.wal_buffer_config.is_none());
assert!(back.mutable_buffer_config.is_none()); assert!(back.mutable_buffer_config.is_none());
assert!(back.shard_config.is_none());
} }
#[test] #[test]
@ -1542,4 +1549,20 @@ mod tests {
assert_eq!(shard_config.ignore_errors, false); assert_eq!(shard_config.ignore_errors, false);
assert_eq!(protobuf.ignore_errors, back.ignore_errors); assert_eq!(protobuf.ignore_errors, back.ignore_errors);
} }
#[test]
fn test_database_rules_shard_config() {
let protobuf = management::DatabaseRules {
name: "database".to_string(),
shard_config: Some(management::ShardConfig {
..Default::default()
}),
..Default::default()
};
let rules: DatabaseRules = protobuf.try_into().unwrap();
let back: management::DatabaseRules = rules.into();
assert!(back.shard_config.is_some());
}
} }

View File

@ -4,6 +4,7 @@ package influxdata.iox.management.v1;
import "google/protobuf/duration.proto"; import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto"; import "google/protobuf/empty.proto";
import "influxdata/iox/management/v1/base_types.proto"; import "influxdata/iox/management/v1/base_types.proto";
import "influxdata/iox/management/v1/shard.proto";
// `PartitionTemplate` is used to compute the partition key of each row that // `PartitionTemplate` is used to compute the partition key of each row that
// gets written. It can consist of the table name, a column name and its value, // gets written. It can consist of the table name, a column name and its value,
@ -152,4 +153,7 @@ message DatabaseRules {
// Mutable buffer configuration for this database // Mutable buffer configuration for this database
MutableBufferConfig mutable_buffer_config = 7; MutableBufferConfig mutable_buffer_config = 7;
// Shard config
ShardConfig shard_config = 8;
} }

View File

@ -65,4 +65,3 @@ message HashRing {
// ring of node groups. Each group holds a shard // ring of node groups. Each group holds a shard
repeated NodeGroup node_groups = 3; repeated NodeGroup node_groups = 3;
} }

View File

@ -196,6 +196,7 @@ async fn test_create_get_database() {
}), }),
persist_after_cold_seconds: 34, persist_after_cold_seconds: 34,
}), }),
shard_config: None,
}; };
client client