From 07fad0a4f66a03e5dddc336923cb2aa288151d82 Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com> Date: Mon, 20 Nov 2023 15:33:20 +0300 Subject: [PATCH] rename: IndexDef::space_id -> table_id Follow-up for bfe0831394 Also fix some docstrings --- src/schema.rs | 24 ++++++++++-------------- src/storage.rs | 8 ++++---- src/traft/node.rs | 4 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/schema.rs b/src/schema.rs index 072dfd6b8a..c71bf24654 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -35,9 +35,9 @@ use crate::util::effective_user_id; // TableDef //////////////////////////////////////////////////////////////////////////////// -/// Space definition. +/// Database table definition. /// -/// Describes a user-defined space. +/// Describes a user-defined table. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct TableDef { pub id: SpaceId, @@ -52,9 +52,7 @@ pub struct TableDef { impl Encode for TableDef {} impl TableDef { - /// Index of field "operable" in the space _pico_table format. - /// - /// Index of first field is 0. + /// Index (0-based) of field "operable" in the _pico_table table format. pub const FIELD_OPERABLE: usize = 5; /// Format of the _pico_table global table. @@ -127,7 +125,7 @@ impl TableDef { // Distribution //////////////////////////////////////////////////////////////////////////////// -/// Defines how to distribute tuples in a space across replicasets. +/// Defines how to distribute tuples in a table across replicasets. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, LuaRead)] #[serde(rename_all = "snake_case")] #[serde(tag = "kind")] @@ -171,12 +169,12 @@ fn default_bucket_id_field() -> String { // IndexDef //////////////////////////////////////////////////////////////////////////////// -/// Index definition. +/// Database index definition. /// /// Describes a user-defined index. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct IndexDef { - pub space_id: SpaceId, + pub table_id: SpaceId, pub id: IndexId, pub name: String, pub local: bool, @@ -189,9 +187,7 @@ pub struct IndexDef { impl Encode for IndexDef {} impl IndexDef { - /// Index of field "operable" in the space _pico_index format. - /// - /// Index of first field is 0. + /// Index (0-based) of field "operable" in _pico_index table format. pub const FIELD_OPERABLE: usize = 6; /// Format of the _pico_index global table. @@ -199,7 +195,7 @@ impl IndexDef { pub fn format() -> Vec<tarantool::space::Field> { use tarantool::space::Field; vec![ - Field::from(("space_id", FieldType::Unsigned)), + Field::from(("table_id", FieldType::Unsigned)), Field::from(("id", FieldType::Unsigned)), Field::from(("name", FieldType::String)), Field::from(("local", FieldType::Boolean)), @@ -214,7 +210,7 @@ impl IndexDef { #[inline(always)] pub fn for_tests() -> Self { Self { - space_id: 10569, + table_id: 10569, id: 1, name: "secondary".into(), local: true, @@ -231,7 +227,7 @@ impl IndexDef { let mut opts = BTreeMap::new(); opts.insert(Cow::from("unique"), Value::Bool(self.unique)); let index_meta = IndexMetadata { - space_id: self.space_id, + space_id: self.table_id, index_id: self.id, name: self.name.as_str().into(), r#type: IndexType::Tree, diff --git a/src/storage.rs b/src/storage.rs index 64cbf9e12c..d5c6bb1fea 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1785,7 +1785,7 @@ impl Indexes { let index_id = space .index_builder("id") .unique(true) - .part("space_id") + .part("table_id") .part("id") .if_not_exists(true) .create()?; @@ -1793,7 +1793,7 @@ impl Indexes { let index_name = space .index_builder("name") .unique(true) - .part("space_id") + .part("table_id") .part("name") .if_not_exists(true) .create()?; @@ -1881,7 +1881,7 @@ pub fn ddl_meta_space_update_operable( for index in iter { storage .indexes - .update_operable(index.space_id, index.id, operable)?; + .update_operable(index.table_id, index.id, operable)?; } Ok(()) } @@ -1897,7 +1897,7 @@ pub fn ddl_meta_drop_space(storage: &Clusterwide, space_id: SpaceId) -> traft::R } let iter = storage.indexes.by_space_id(space_id)?; for index in iter { - storage.indexes.delete(index.space_id, index.id)?; + storage.indexes.delete(index.table_id, index.id)?; } storage.tables.delete(space_id)?; Ok(()) diff --git a/src/traft/node.rs b/src/traft/node.rs index 46a0af03ef..b4cc4a42d1 100644 --- a/src/traft/node.rs +++ b/src/traft/node.rs @@ -1009,7 +1009,7 @@ impl NodeImpl { let primary_key_def = IndexDef { id: 0, name: "primary_key".into(), - space_id: id, + table_id: id, schema_version, parts: primary_key, operable: false, @@ -1046,7 +1046,7 @@ impl NodeImpl { let bucket_id_def = IndexDef { id: 1, name: "bucket_id".into(), - space_id: id, + table_id: id, schema_version, parts: vec![Part::field(bucket_id_index) .field_type(IFT::Unsigned) -- GitLab