@@ -28,7 +28,7 @@ use restate_types::net::connect_opts::GrpcConnectionOptions;
2828use restate_core:: network:: net_util:: { DNSResolution , create_tonic_channel} ;
2929use restate_core:: protobuf:: node_ctl_svc:: node_ctl_svc_server:: { NodeCtlSvc , NodeCtlSvcServer } ;
3030use restate_core:: protobuf:: node_ctl_svc:: {
31- ClusterHealthResponse , DatabaseCompactionResult , DatabaseKind , EmbeddedMetadataClusterHealth ,
31+ ClusterHealthResponse , DatabaseCompactionResult , EmbeddedMetadataClusterHealth ,
3232 GetMetadataRequest , GetMetadataResponse , IdentResponse , ProvisionClusterRequest ,
3333 ProvisionClusterResponse , TriggerCompactionRequest , TriggerCompactionResponse ,
3434} ;
@@ -43,28 +43,12 @@ use restate_types::logs::metadata::{NodeSetSize, ProviderConfiguration};
4343use restate_types:: metadata:: VersionedValue ;
4444use restate_types:: nodes_config:: Role ;
4545use restate_types:: protobuf:: cluster:: ClusterConfiguration as ProtoClusterConfiguration ;
46+ use restate_types:: protobuf:: common:: DatabaseKind ;
4647use restate_types:: replication:: ReplicationProperty ;
4748use restate_types:: storage:: StorageCodec ;
4849
4950use crate :: { ClusterConfiguration , provision_cluster_metadata} ;
5051
51- /// Maps database names to their corresponding DatabaseKind.
52- /// Returns None for unrecognized names so they are skipped rather than
53- /// accidentally compacted if new databases are added without updating this mapping.
54- fn db_name_to_kind ( name : & str ) -> Option < DatabaseKind > {
55- if name == "log-server" {
56- Some ( DatabaseKind :: LogServer )
57- } else if name == "replicated-metadata-server" {
58- Some ( DatabaseKind :: MetadataServer )
59- } else if name == "local-loglet" {
60- Some ( DatabaseKind :: LocalLoglet )
61- } else if name == "db" || name. starts_with ( "db-" ) {
62- Some ( DatabaseKind :: PartitionStore )
63- } else {
64- None
65- }
66- }
67-
6852pub struct NodeCtlSvcHandler {
6953 metadata_writer : MetadataWriter ,
7054}
@@ -306,12 +290,10 @@ impl NodeCtlSvc for NodeCtlSvcHandler {
306290 // concurrent I/O from multiple databases.
307291 for db in all_dbs {
308292 let db_name = db. name ( ) . to_string ( ) ;
293+ let kind = db. kind ( ) ;
309294
310- // Check if this database should be compacted. Skip databases whose names
311- // are not recognized so newly added databases are not accidentally compacted.
312- let should_compact = compact_all || {
313- db_name_to_kind ( & db_name) . is_some_and ( |kind| requested_kinds. contains ( & kind) )
314- } ;
295+ let should_compact = compact_all
296+ || ( kind != DatabaseKind :: Unspecified && requested_kinds. contains ( & kind) ) ;
315297
316298 if !should_compact {
317299 continue ;
@@ -471,27 +453,16 @@ fn write_err_to_status(err: WriteError) -> Status {
471453
472454#[ cfg( test) ]
473455mod tests {
474- use super :: * ;
456+ use restate_types :: protobuf :: common :: DatabaseKind ;
475457
476458 #[ test]
477- fn test_db_name_to_kind ( ) {
478- assert_eq ! ( db_name_to_kind( "db" ) , Some ( DatabaseKind :: PartitionStore ) ) ;
479- assert_eq ! ( db_name_to_kind( "db-0" ) , Some ( DatabaseKind :: PartitionStore ) ) ;
480- assert_eq ! (
481- db_name_to_kind( "db-123" ) ,
482- Some ( DatabaseKind :: PartitionStore )
483- ) ;
484- assert_eq ! ( db_name_to_kind( "log-server" ) , Some ( DatabaseKind :: LogServer ) ) ;
485- assert_eq ! (
486- db_name_to_kind( "replicated-metadata-server" ) ,
487- Some ( DatabaseKind :: MetadataServer )
488- ) ;
459+ fn test_database_kind_db_names ( ) {
460+ assert_eq ! ( DatabaseKind :: LogServer . db_name( ) , "log-server" ) ;
489461 assert_eq ! (
490- db_name_to_kind ( "local-loglet" ) ,
491- Some ( DatabaseKind :: LocalLoglet )
462+ DatabaseKind :: MetadataServer . db_name ( ) ,
463+ "replicated-metadata-server"
492464 ) ;
493- // Unknown names return None so they are safely skipped
494- assert_eq ! ( db_name_to_kind( "unknown" ) , None ) ;
495- assert_eq ! ( db_name_to_kind( "random-name" ) , None ) ;
465+ assert_eq ! ( DatabaseKind :: LocalLoglet . db_name( ) , "local-loglet" ) ;
466+ assert_eq ! ( DatabaseKind :: PartitionStore . db_name( ) , "db" ) ;
496467 }
497468}
0 commit comments