From 5fe8affb180f46ba0d289a71b5d64ed039c09511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaya=20G=C3=B6kalp?= Date: Mon, 15 May 2023 03:03:55 -0700 Subject: [PATCH] refactor: accept NamespaceName with Namespace create (#7774) Co-authored-by: Dom --- garbage_collector/src/objectstore/checker.rs | 9 +- .../aggregate_tsm_schema/update_catalog.rs | 10 +- .../buffer_tree/partition/resolver/catalog.rs | 3 +- ingester/src/test_util.rs | 8 +- ingester_test_ctx/src/lib.rs | 5 +- iox_catalog/src/interface.rs | 120 ++++++++++++------ iox_catalog/src/lib.rs | 4 +- iox_catalog/src/mem.rs | 14 +- iox_catalog/src/metrics.rs | 8 +- iox_catalog/src/postgres.rs | 20 +-- iox_catalog/src/sqlite.rs | 20 +-- iox_tests/src/catalog.rs | 8 +- ioxd_router/src/lib.rs | 6 +- .../src/namespace_resolver/ns_autocreation.rs | 2 +- router/tests/http.rs | 10 +- service_grpc_catalog/src/lib.rs | 8 +- service_grpc_object_store/src/lib.rs | 6 +- service_grpc_schema/src/lib.rs | 4 +- 18 files changed, 176 insertions(+), 89 deletions(-) diff --git a/garbage_collector/src/objectstore/checker.rs b/garbage_collector/src/objectstore/checker.rs index 2913fc458f..a820f0a498 100644 --- a/garbage_collector/src/objectstore/checker.rs +++ b/garbage_collector/src/objectstore/checker.rs @@ -137,8 +137,8 @@ mod tests { use super::*; use chrono::TimeZone; use data_types::{ - ColumnId, ColumnSet, CompactionLevel, NamespaceId, ParquetFile, ParquetFileParams, - PartitionId, TableId, Timestamp, + ColumnId, ColumnSet, CompactionLevel, NamespaceId, NamespaceName, ParquetFile, + ParquetFileParams, PartitionId, TableId, Timestamp, }; use iox_catalog::{interface::Catalog, mem::MemCatalog}; use object_store::path::Path; @@ -157,7 +157,10 @@ mod tests { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_parquet_file_test", None) + .create( + &NamespaceName::new("namespace_parquet_file_test").unwrap(), + None, + ) .await .unwrap(); let table = repos diff --git a/import/src/aggregate_tsm_schema/update_catalog.rs b/import/src/aggregate_tsm_schema/update_catalog.rs index 173c5bcfa1..0813baadfd 100644 --- a/import/src/aggregate_tsm_schema/update_catalog.rs +++ b/import/src/aggregate_tsm_schema/update_catalog.rs @@ -87,7 +87,9 @@ async fn create_namespace(name: &str, repos: &mut R) -> Result Ok(ns), Err(iox_catalog::interface::Error::NameExists { .. }) => { // presumably it got created in the meantime? @@ -428,7 +430,7 @@ mod tests { // create namespace, table and columns for weather measurement let namespace = txn .namespaces() - .create("1234_5678", None) + .create(&NamespaceName::new("1234_5678").unwrap(), None) .await .expect("namespace created"); let mut table = txn @@ -520,7 +522,7 @@ mod tests { // create namespace, table and columns for weather measurement let namespace = txn .namespaces() - .create("1234_5678", None) + .create(&NamespaceName::new("1234_5678").unwrap(), None) .await .expect("namespace created"); let mut table = txn @@ -585,7 +587,7 @@ mod tests { // create namespace, table and columns for weather measurement let namespace = txn .namespaces() - .create("1234_5678", None) + .create(&NamespaceName::new("1234_5678").unwrap(), None) .await .expect("namespace created"); let mut table = txn diff --git a/ingester/src/buffer_tree/partition/resolver/catalog.rs b/ingester/src/buffer_tree/partition/resolver/catalog.rs index ff76eaf3ff..86aa2767d4 100644 --- a/ingester/src/buffer_tree/partition/resolver/catalog.rs +++ b/ingester/src/buffer_tree/partition/resolver/catalog.rs @@ -114,9 +114,10 @@ mod tests { let (namespace_id, table_id) = { let mut repos = catalog.repositories().await; + let table_ns_name = data_types::NamespaceName::new(TABLE_NAME).unwrap(); let ns = repos .namespaces() - .create(TABLE_NAME, None) + .create(&table_ns_name, None) .await .unwrap(); diff --git a/ingester/src/test_util.rs b/ingester/src/test_util.rs index 4eada1b052..6920ab7c08 100644 --- a/ingester/src/test_util.rs +++ b/ingester/src/test_util.rs @@ -298,7 +298,13 @@ pub(crate) async fn populate_catalog( table: &str, ) -> (NamespaceId, TableId) { let mut c = catalog.repositories().await; - let ns_id = c.namespaces().create(namespace, None).await.unwrap().id; + let namespace_name = data_types::NamespaceName::new(namespace).unwrap(); + let ns_id = c + .namespaces() + .create(&namespace_name, None) + .await + .unwrap() + .id; let table_id = c.tables().create_or_get(table, ns_id).await.unwrap().id; (ns_id, table_id) diff --git a/ingester_test_ctx/src/lib.rs b/ingester_test_ctx/src/lib.rs index 83a7ab5b7e..3f486e672a 100644 --- a/ingester_test_ctx/src/lib.rs +++ b/ingester_test_ctx/src/lib.rs @@ -17,7 +17,8 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; use arrow::record_batch::RecordBatch; use arrow_flight::{decode::FlightRecordBatchStream, flight_service_server::FlightService, Ticket}; use data_types::{ - Namespace, NamespaceId, NamespaceSchema, ParquetFile, PartitionKey, SequenceNumber, TableId, + Namespace, NamespaceId, NamespaceName, NamespaceSchema, ParquetFile, PartitionKey, + SequenceNumber, TableId, }; use dml::{DmlMeta, DmlWrite}; use futures::{stream::FuturesUnordered, FutureExt, StreamExt, TryStreamExt}; @@ -207,7 +208,7 @@ where .repositories() .await .namespaces() - .create(name, None) + .create(&NamespaceName::new(name).unwrap(), None) .await .expect("failed to create test namespace"); diff --git a/iox_catalog/src/interface.rs b/iox_catalog/src/interface.rs index 02a51c4633..ccba28e803 100644 --- a/iox_catalog/src/interface.rs +++ b/iox_catalog/src/interface.rs @@ -2,9 +2,9 @@ use async_trait::async_trait; use data_types::{ - Column, ColumnType, ColumnsByName, CompactionLevel, Namespace, NamespaceId, NamespaceSchema, - ParquetFile, ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, - SkippedCompaction, Table, TableId, TableSchema, Timestamp, + Column, ColumnType, ColumnsByName, CompactionLevel, Namespace, NamespaceId, NamespaceName, + NamespaceSchema, ParquetFile, ParquetFileId, ParquetFileParams, Partition, PartitionId, + PartitionKey, SkippedCompaction, Table, TableId, TableSchema, Timestamp, }; use iox_time::TimeProvider; use snafu::{OptionExt, Snafu}; @@ -35,6 +35,9 @@ pub enum CasFailure { #[allow(missing_copy_implementations, missing_docs)] #[snafu(visibility(pub(crate)))] pub enum Error { + #[snafu(display("invalid name: {}", name))] + InvalidName { name: String }, + #[snafu(display("name {} already exists", name))] NameExists { name: String }, @@ -307,7 +310,11 @@ pub trait NamespaceRepo: Send + Sync { /// Creates the namespace in the catalog. If one by the same name already exists, an /// error is returned. /// Specify `None` for `retention_period_ns` to get infinite retention. - async fn create(&mut self, name: &str, retention_period_ns: Option) -> Result; + async fn create( + &mut self, + name: &NamespaceName, + retention_period_ns: Option, + ) -> Result; /// Update retention period for a namespace async fn update_retention_period( @@ -787,14 +794,14 @@ pub(crate) mod test_helpers { async fn test_namespace(catalog: Arc) { let mut repos = catalog.repositories().await; - let namespace_name = "test_namespace"; + let namespace_name = NamespaceName::new("test_namespace").unwrap(); let namespace = repos .namespaces() - .create(namespace_name, None) + .create(&namespace_name, None) .await .unwrap(); assert!(namespace.id > NamespaceId::new(0)); - assert_eq!(namespace.name, namespace_name); + assert_eq!(namespace.name, namespace_name.as_str()); // Assert default values for service protection limits. assert_eq!(namespace.max_tables, DEFAULT_MAX_TABLES); @@ -803,7 +810,7 @@ pub(crate) mod test_helpers { DEFAULT_MAX_COLUMNS_PER_TABLE ); - let conflict = repos.namespaces().create(namespace_name, None).await; + let conflict = repos.namespaces().create(&namespace_name, None).await; assert!(matches!( conflict.unwrap_err(), Error::NameExists { name: _ } @@ -826,7 +833,7 @@ pub(crate) mod test_helpers { let found = repos .namespaces() - .get_by_name(namespace_name, SoftDeletedRows::ExcludeDeleted) + .get_by_name(&namespace_name, SoftDeletedRows::ExcludeDeleted) .await .unwrap() .expect("namespace should be there"); @@ -839,10 +846,10 @@ pub(crate) mod test_helpers { .unwrap(); assert!(not_found.is_none()); - let namespace2_name = "test_namespace2"; + let namespace2_name = NamespaceName::new("test_namespace2").unwrap(); let namespace2 = repos .namespaces() - .create(namespace2_name, None) + .create(&namespace2_name, None) .await .unwrap(); let mut namespaces = repos @@ -856,7 +863,7 @@ pub(crate) mod test_helpers { const NEW_TABLE_LIMIT: i32 = 15000; let modified = repos .namespaces() - .update_table_limit(namespace_name, NEW_TABLE_LIMIT) + .update_table_limit(namespace_name.as_str(), NEW_TABLE_LIMIT) .await .expect("namespace should be updateable"); assert_eq!(NEW_TABLE_LIMIT, modified.max_tables); @@ -864,7 +871,7 @@ pub(crate) mod test_helpers { const NEW_COLUMN_LIMIT: i32 = 1500; let modified = repos .namespaces() - .update_column_limit(namespace_name, NEW_COLUMN_LIMIT) + .update_column_limit(namespace_name.as_str(), NEW_COLUMN_LIMIT) .await .expect("namespace should be updateable"); assert_eq!(NEW_COLUMN_LIMIT, modified.max_columns_per_table); @@ -872,7 +879,7 @@ pub(crate) mod test_helpers { const NEW_RETENTION_PERIOD_NS: i64 = 5 * 60 * 60 * 1000 * 1000 * 1000; let modified = repos .namespaces() - .update_retention_period(namespace_name, Some(NEW_RETENTION_PERIOD_NS)) + .update_retention_period(namespace_name.as_str(), Some(NEW_RETENTION_PERIOD_NS)) .await .expect("namespace should be updateable"); assert_eq!( @@ -882,25 +889,25 @@ pub(crate) mod test_helpers { let modified = repos .namespaces() - .update_retention_period(namespace_name, None) + .update_retention_period(namespace_name.as_str(), None) .await .expect("namespace should be updateable"); assert!(modified.retention_period_ns.is_none()); // create namespace with retention period NULL - let namespace3_name = "test_namespace3"; + let namespace3_name = NamespaceName::new("test_namespace3").unwrap(); let namespace3 = repos .namespaces() - .create(namespace3_name, None) + .create(&namespace3_name, None) .await .expect("namespace with NULL retention should be created"); assert!(namespace3.retention_period_ns.is_none()); // create namespace with retention period - let namespace4_name = "test_namespace4"; + let namespace4_name = NamespaceName::new("test_namespace4").unwrap(); let namespace4 = repos .namespaces() - .create(namespace4_name, Some(NEW_RETENTION_PERIOD_NS)) + .create(&namespace4_name, Some(NEW_RETENTION_PERIOD_NS)) .await .expect("namespace with 5-hour retention should be created"); assert_eq!( @@ -910,7 +917,7 @@ pub(crate) mod test_helpers { // reset retention period to NULL to avoid affecting later tests repos .namespaces() - .update_retention_period(namespace4_name, None) + .update_retention_period(&namespace4_name, None) .await .expect("namespace should be updateable"); @@ -947,8 +954,16 @@ pub(crate) mod test_helpers { async fn test_namespace_soft_deletion(catalog: Arc) { let mut repos = catalog.repositories().await; - let deleted_ns = repos.namespaces().create("deleted-ns", None).await.unwrap(); - let active_ns = repos.namespaces().create("active-ns", None).await.unwrap(); + let deleted_ns = repos + .namespaces() + .create(&"deleted-ns".try_into().unwrap(), None) + .await + .unwrap(); + let active_ns = repos + .namespaces() + .create(&"active-ns".try_into().unwrap(), None) + .await + .unwrap(); // Mark "deleted-ns" as soft-deleted. repos.namespaces().soft_delete("deleted-ns").await.unwrap(); @@ -1104,7 +1119,7 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_table_test", None) + .create(&NamespaceName::new("namespace_table_test").unwrap(), None) .await .unwrap(); @@ -1139,7 +1154,11 @@ pub(crate) mod test_helpers { assert_eq!(vec![t.clone()], tables); // test we can create a table of the same name in a different namespace - let namespace2 = repos.namespaces().create("two", None).await.unwrap(); + let namespace2 = repos + .namespaces() + .create(&NamespaceName::new("two").unwrap(), None) + .await + .unwrap(); assert_ne!(namespace, namespace2); let test_table = repos .tables() @@ -1237,7 +1256,7 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_column_test", None) + .create(&NamespaceName::new("namespace_column_test").unwrap(), None) .await .unwrap(); let table = repos @@ -1370,7 +1389,10 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_partition_test", None) + .create( + &NamespaceName::new("namespace_partition_test").unwrap(), + None, + ) .await .unwrap(); let table = repos @@ -1652,7 +1674,10 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_parquet_file_test", None) + .create( + &NamespaceName::new("namespace_parquet_file_test").unwrap(), + None, + ) .await .unwrap(); let table = repos @@ -1837,7 +1862,10 @@ pub(crate) mod test_helpers { // test list_by_namespace_not_to_delete let namespace2 = repos .namespaces() - .create("namespace_parquet_file_test1", None) + .create( + &NamespaceName::new("namespace_parquet_file_test1").unwrap(), + None, + ) .await .unwrap(); let table2 = repos @@ -2060,12 +2088,12 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace_1 = repos .namespaces() - .create("retention_broken_1", None) + .create(&NamespaceName::new("retention_broken_1").unwrap(), None) .await .unwrap(); let namespace_2 = repos .namespaces() - .create("retention_broken_2", Some(1)) + .create(&NamespaceName::new("retention_broken_2").unwrap(), Some(1)) .await .unwrap(); let table_1 = repos @@ -2140,7 +2168,10 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("test_partitions_new_file_between", None) + .create( + &NamespaceName::new("test_partitions_new_file_between").unwrap(), + None, + ) .await .unwrap(); let table = repos @@ -2507,7 +2538,8 @@ pub(crate) mod test_helpers { let namespace = repos .namespaces() .create( - "namespace_parquet_file_test_list_by_partiton_not_to_delete", + &NamespaceName::new("namespace_parquet_file_test_list_by_partiton_not_to_delete") + .unwrap(), None, ) .await @@ -2616,7 +2648,10 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_update_to_compaction_level_1_test", None) + .create( + &NamespaceName::new("namespace_update_to_compaction_level_1_test").unwrap(), + None, + ) .await .unwrap(); let table = repos @@ -2702,7 +2737,10 @@ pub(crate) mod test_helpers { let mut repos = catalog.repositories().await; let namespace_1 = repos .namespaces() - .create("namespace_test_delete_namespace_1", None) + .create( + &NamespaceName::new("namespace_test_delete_namespace_1").unwrap(), + None, + ) .await .unwrap(); let table_1 = repos @@ -2757,7 +2795,10 @@ pub(crate) mod test_helpers { // it, let's create another so we can ensure that doesn't get deleted. let namespace_2 = repos .namespaces() - .create("namespace_test_delete_namespace_2", None) + .create( + &NamespaceName::new("namespace_test_delete_namespace_2").unwrap(), + None, + ) .await .unwrap(); let table_2 = repos @@ -2943,7 +2984,7 @@ pub(crate) mod test_helpers { let mut txn = catalog_captured.start_transaction().await.unwrap(); txn.namespaces() - .create("test_txn_isolation", None) + .create(&NamespaceName::new("test_txn_isolation").unwrap(), None) .await .unwrap(); @@ -2980,7 +3021,7 @@ pub(crate) mod test_helpers { let capture = TracingCapture::new(); let mut txn = catalog.start_transaction().await.unwrap(); txn.namespaces() - .create("test_txn_drop", None) + .create(&NamespaceName::new("test_txn_drop").unwrap(), None) .await .unwrap(); drop(txn); @@ -3009,7 +3050,10 @@ pub(crate) mod test_helpers { where R: RepoCollection + ?Sized, { - let namespace = repos.namespaces().create(namespace_name, None).await; + let namespace = repos + .namespaces() + .create(&NamespaceName::new(namespace_name).unwrap(), None) + .await; let namespace = match namespace { Ok(v) => v, diff --git a/iox_catalog/src/lib.rs b/iox_catalog/src/lib.rs index 880e98e1f6..fa4cd9de9c 100644 --- a/iox_catalog/src/lib.rs +++ b/iox_catalog/src/lib.rs @@ -210,6 +210,7 @@ mod tests { interface::{get_schema_by_name, SoftDeletedRows}, mem::MemCatalog, }; + use data_types::NamespaceName; // Generate a test that simulates multiple, sequential writes in `lp` and // asserts the resulting schema. @@ -231,6 +232,7 @@ mod tests { use std::ops::DerefMut; use pretty_assertions::assert_eq; const NAMESPACE_NAME: &str = "bananas"; + let ns_name = NamespaceName::new(NAMESPACE_NAME).unwrap(); let metrics = Arc::new(metric::Registry::default()); let repo = MemCatalog::new(metrics); @@ -238,7 +240,7 @@ mod tests { let namespace = txn .namespaces() - .create(NAMESPACE_NAME, None) + .create(&ns_name, None) .await .unwrap(); diff --git a/iox_catalog/src/mem.rs b/iox_catalog/src/mem.rs index a67c21f1e1..ba889d080a 100644 --- a/iox_catalog/src/mem.rs +++ b/iox_catalog/src/mem.rs @@ -12,9 +12,9 @@ use crate::{ }; use async_trait::async_trait; use data_types::{ - Column, ColumnId, ColumnType, CompactionLevel, Namespace, NamespaceId, ParquetFile, - ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, - Table, TableId, Timestamp, + Column, ColumnId, ColumnType, CompactionLevel, Namespace, NamespaceId, NamespaceName, + ParquetFile, ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, + SkippedCompaction, Table, TableId, Timestamp, }; use iox_time::{SystemProvider, TimeProvider}; use observability_deps::tracing::warn; @@ -217,10 +217,14 @@ impl RepoCollection for MemTxn { #[async_trait] impl NamespaceRepo for MemTxn { - async fn create(&mut self, name: &str, retention_period_ns: Option) -> Result { + async fn create( + &mut self, + name: &NamespaceName, + retention_period_ns: Option, + ) -> Result { let stage = self.stage(); - if stage.namespaces.iter().any(|n| n.name == name) { + if stage.namespaces.iter().any(|n| n.name == name.as_str()) { return Err(Error::NameExists { name: name.to_string(), }); diff --git a/iox_catalog/src/metrics.rs b/iox_catalog/src/metrics.rs index d4a899718d..988e321e82 100644 --- a/iox_catalog/src/metrics.rs +++ b/iox_catalog/src/metrics.rs @@ -6,9 +6,9 @@ use crate::interface::{ }; use async_trait::async_trait; use data_types::{ - Column, ColumnType, CompactionLevel, Namespace, NamespaceId, ParquetFile, ParquetFileId, - ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, Table, TableId, - Timestamp, + Column, ColumnType, CompactionLevel, Namespace, NamespaceId, NamespaceName, ParquetFile, + ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, + Table, TableId, Timestamp, }; use iox_time::{SystemProvider, TimeProvider}; use metric::{DurationHistogram, Metric}; @@ -145,7 +145,7 @@ macro_rules! decorate { decorate!( impl_trait = NamespaceRepo, methods = [ - "namespace_create" = create(&mut self, name: &str, retention_period_ns: Option) -> Result; + "namespace_create" = create(&mut self, name: &NamespaceName, retention_period_ns: Option) -> Result; "namespace_update_retention_period" = update_retention_period(&mut self, name: &str, retention_period_ns: Option) -> Result; "namespace_list" = list(&mut self, deleted: SoftDeletedRows) -> Result>; "namespace_get_by_id" = get_by_id(&mut self, id: NamespaceId, deleted: SoftDeletedRows) -> Result>; diff --git a/iox_catalog/src/postgres.rs b/iox_catalog/src/postgres.rs index 9b83420963..b470aff6cd 100644 --- a/iox_catalog/src/postgres.rs +++ b/iox_catalog/src/postgres.rs @@ -16,9 +16,9 @@ use crate::{ }; use async_trait::async_trait; use data_types::{ - Column, ColumnType, CompactionLevel, Namespace, NamespaceId, ParquetFile, ParquetFileId, - ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, Table, TableId, - Timestamp, + Column, ColumnType, CompactionLevel, Namespace, NamespaceId, NamespaceName, ParquetFile, + ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, + Table, TableId, Timestamp, }; use iox_time::{SystemProvider, TimeProvider}; use observability_deps::tracing::{debug, info, warn}; @@ -578,7 +578,11 @@ impl RepoCollection for PostgresTxn { #[async_trait] impl NamespaceRepo for PostgresTxn { - async fn create(&mut self, name: &str, retention_period_ns: Option) -> Result { + async fn create( + &mut self, + name: &NamespaceName, + retention_period_ns: Option, + ) -> Result { let rec = sqlx::query_as::<_, Namespace>( r#" INSERT INTO namespace ( name, topic_id, query_pool_id, retention_period_ns, max_tables ) @@ -586,7 +590,7 @@ impl NamespaceRepo for PostgresTxn { RETURNING id, name, retention_period_ns, max_tables, max_columns_per_table, deleted_at; "#, ) - .bind(name) // $1 + .bind(name.as_str()) // $1 .bind(SHARED_TOPIC_ID) // $2 .bind(SHARED_QUERY_POOL_ID) // $3 .bind(retention_period_ns) // $4 @@ -1822,7 +1826,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; @@ -1960,7 +1964,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; @@ -2123,7 +2127,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; diff --git a/iox_catalog/src/sqlite.rs b/iox_catalog/src/sqlite.rs index 8bed76f556..c7ff0ea9d8 100644 --- a/iox_catalog/src/sqlite.rs +++ b/iox_catalog/src/sqlite.rs @@ -16,9 +16,9 @@ use crate::{ }; use async_trait::async_trait; use data_types::{ - Column, ColumnId, ColumnSet, ColumnType, CompactionLevel, Namespace, NamespaceId, ParquetFile, - ParquetFileId, ParquetFileParams, Partition, PartitionId, PartitionKey, SkippedCompaction, - Table, TableId, Timestamp, + Column, ColumnId, ColumnSet, ColumnType, CompactionLevel, Namespace, NamespaceId, + NamespaceName, ParquetFile, ParquetFileId, ParquetFileParams, Partition, PartitionId, + PartitionKey, SkippedCompaction, Table, TableId, Timestamp, }; use serde::{Deserialize, Serialize}; use std::ops::Deref; @@ -340,7 +340,11 @@ impl RepoCollection for SqliteTxn { #[async_trait] impl NamespaceRepo for SqliteTxn { - async fn create(&mut self, name: &str, retention_period_ns: Option) -> Result { + async fn create( + &mut self, + name: &NamespaceName, + retention_period_ns: Option, + ) -> Result { let rec = sqlx::query_as::<_, Namespace>( r#" INSERT INTO namespace ( name, topic_id, query_pool_id, retention_period_ns, max_tables ) @@ -348,7 +352,7 @@ VALUES ( $1, $2, $3, $4, $5 ) RETURNING id, name, retention_period_ns, max_tables, max_columns_per_table, deleted_at; "#, ) - .bind(name) // $1 + .bind(name.as_str()) // $1 .bind(SHARED_TOPIC_ID) // $2 .bind(SHARED_QUERY_POOL_ID) // $3 .bind(retention_period_ns) // $4 @@ -1552,7 +1556,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; @@ -1605,7 +1609,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; @@ -1767,7 +1771,7 @@ mod tests { .repositories() .await .namespaces() - .create("ns4", None) + .create(&NamespaceName::new("ns4").unwrap(), None) .await .expect("namespace create failed") .id; diff --git a/iox_tests/src/catalog.rs b/iox_tests/src/catalog.rs index eaa6140484..859826caed 100644 --- a/iox_tests/src/catalog.rs +++ b/iox_tests/src/catalog.rs @@ -5,8 +5,9 @@ use arrow::{ record_batch::RecordBatch, }; use data_types::{ - Column, ColumnSet, ColumnType, ColumnsByName, CompactionLevel, Namespace, NamespaceSchema, - ParquetFile, ParquetFileParams, Partition, PartitionId, Table, TableId, TableSchema, Timestamp, + Column, ColumnSet, ColumnType, ColumnsByName, CompactionLevel, Namespace, NamespaceName, + NamespaceSchema, ParquetFile, ParquetFileParams, Partition, PartitionId, Table, TableId, + TableSchema, Timestamp, }; use datafusion::physical_plan::metrics::Count; use datafusion_util::MemoryStream; @@ -143,9 +144,10 @@ impl TestCatalog { retention_period_ns: Option, ) -> Arc { let mut repos = self.catalog.repositories().await; + let namespace_name = NamespaceName::new(name).unwrap(); let namespace = repos .namespaces() - .create(name, retention_period_ns) + .create(&namespace_name, retention_period_ns) .await .unwrap(); diff --git a/ioxd_router/src/lib.rs b/ioxd_router/src/lib.rs index 9a2e98d14b..aba7a9e3bf 100644 --- a/ioxd_router/src/lib.rs +++ b/ioxd_router/src/lib.rs @@ -391,7 +391,11 @@ mod tests { let catalog = Arc::new(MemCatalog::new(Default::default())); let mut repos = catalog.repositories().await; - let namespace = repos.namespaces().create("test_ns", None).await.unwrap(); + let namespace = repos + .namespaces() + .create(&NamespaceName::new("test_ns").unwrap(), None) + .await + .unwrap(); let table = repos .tables() diff --git a/router/src/namespace_resolver/ns_autocreation.rs b/router/src/namespace_resolver/ns_autocreation.rs index 36d42099e7..0a1f16fe50 100644 --- a/router/src/namespace_resolver/ns_autocreation.rs +++ b/router/src/namespace_resolver/ns_autocreation.rs @@ -107,7 +107,7 @@ where .repositories() .await .namespaces() - .create(namespace.as_str(), retention_period_ns) + .create(namespace, retention_period_ns) .await { Ok(_) => { diff --git a/router/tests/http.rs b/router/tests/http.rs index 264c0b1a36..226a664735 100644 --- a/router/tests/http.rs +++ b/router/tests/http.rs @@ -270,7 +270,10 @@ async fn test_write_propagate_ids() { .repositories() .await .namespaces() - .create("bananas_test", None) + .create( + &data_types::NamespaceName::new("bananas_test").unwrap(), + None, + ) .await .expect("failed to update table limit"); @@ -352,7 +355,10 @@ async fn test_delete_unsupported() { .repositories() .await .namespaces() - .create("bananas_test", None) + .create( + &data_types::NamespaceName::new("bananas_test").unwrap(), + None, + ) .await .expect("failed to update table limit"); diff --git a/service_grpc_catalog/src/lib.rs b/service_grpc_catalog/src/lib.rs index 1ee97856c4..bdbb2a5334 100644 --- a/service_grpc_catalog/src/lib.rs +++ b/service_grpc_catalog/src/lib.rs @@ -197,7 +197,9 @@ fn to_partition(p: data_types::Partition) -> Partition { #[cfg(test)] mod tests { use super::*; - use data_types::{ColumnId, ColumnSet, CompactionLevel, ParquetFileParams, Timestamp}; + use data_types::{ + ColumnId, ColumnSet, CompactionLevel, NamespaceName, ParquetFileParams, Timestamp, + }; use generated_types::influxdata::iox::catalog::v1::catalog_service_server::CatalogService; use iox_catalog::mem::MemCatalog; use uuid::Uuid; @@ -214,7 +216,7 @@ mod tests { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("catalog_partition_test", None) + .create(&NamespaceName::new("catalog_partition_test").unwrap(), None) .await .unwrap(); let table = repos @@ -277,7 +279,7 @@ mod tests { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("catalog_partition_test", None) + .create(&NamespaceName::new("catalog_partition_test").unwrap(), None) .await .unwrap(); let table = repos diff --git a/service_grpc_object_store/src/lib.rs b/service_grpc_object_store/src/lib.rs index 8a92ac2ba9..293ea31ff3 100644 --- a/service_grpc_object_store/src/lib.rs +++ b/service_grpc_object_store/src/lib.rs @@ -96,7 +96,9 @@ impl object_store_service_server::ObjectStoreService for ObjectStoreService { mod tests { use super::*; use bytes::Bytes; - use data_types::{ColumnId, ColumnSet, CompactionLevel, ParquetFileParams, Timestamp}; + use data_types::{ + ColumnId, ColumnSet, CompactionLevel, NamespaceName, ParquetFileParams, Timestamp, + }; use generated_types::influxdata::iox::object_store::v1::object_store_service_server::ObjectStoreService; use iox_catalog::mem::MemCatalog; use object_store::{memory::InMemory, ObjectStore}; @@ -112,7 +114,7 @@ mod tests { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("catalog_partition_test", None) + .create(&NamespaceName::new("catalog_partition_test").unwrap(), None) .await .unwrap(); let table = repos diff --git a/service_grpc_schema/src/lib.rs b/service_grpc_schema/src/lib.rs index f359e57224..318417c473 100644 --- a/service_grpc_schema/src/lib.rs +++ b/service_grpc_schema/src/lib.rs @@ -81,7 +81,7 @@ fn schema_to_proto(schema: Arc) -> GetSchemaRespons #[cfg(test)] mod tests { use super::*; - use data_types::ColumnType; + use data_types::{ColumnType, NamespaceName}; use generated_types::influxdata::iox::schema::v1::schema_service_server::SchemaService; use iox_catalog::mem::MemCatalog; use std::sync::Arc; @@ -95,7 +95,7 @@ mod tests { let mut repos = catalog.repositories().await; let namespace = repos .namespaces() - .create("namespace_schema_test", None) + .create(&NamespaceName::new("namespace_schema_test").unwrap(), None) .await .unwrap(); let table = repos