Skip to content
Snippets Groups Projects
Commit 79267b4e authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

refactor: extract function ddl_meta_space_update_operable

parent e9b1b821
No related branches found
No related tags found
1 merge request!555Feat/ddl drop space
...@@ -1670,6 +1670,29 @@ impl ToEntryIter for Indexes { ...@@ -1670,6 +1670,29 @@ impl ToEntryIter for Indexes {
} }
} }
////////////////////////////////////////////////////////////////////////////////
// ddl meta
////////////////////////////////////////////////////////////////////////////////
/// Updates the field `"operable"` for a space with id `space_id` and any
/// necessary entities (currently all existing indexes).
///
/// This function is called when applying the different ddl operations.
pub fn ddl_meta_space_update_operable(
storage: &Clusterwide,
space_id: SpaceId,
operable: bool,
) -> traft::Result<()> {
storage.spaces.update_operable(space_id, operable)?;
let iter = storage.indexes.by_space_id(space_id)?;
for index in iter {
storage
.indexes
.update_operable(index.space_id, index.id, operable)?;
}
Ok(())
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ddl // ddl
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -13,10 +13,10 @@ use crate::loop_start; ...@@ -13,10 +13,10 @@ use crate::loop_start;
use crate::r#loop::FlowControl; use crate::r#loop::FlowControl;
use crate::rpc; use crate::rpc;
use crate::schema::{Distribution, IndexDef, SpaceDef}; use crate::schema::{Distribution, IndexDef, SpaceDef};
use crate::storage::ddl_abort_on_master;
use crate::storage::local_schema_version; use crate::storage::local_schema_version;
use crate::storage::SnapshotData; use crate::storage::SnapshotData;
use crate::storage::ToEntryIter as _; use crate::storage::ToEntryIter as _;
use crate::storage::{ddl_abort_on_master, ddl_meta_space_update_operable};
use crate::storage::{Clusterwide, ClusterwideSpaceId, PropertyName}; use crate::storage::{Clusterwide, ClusterwideSpaceId, PropertyName};
use crate::stringify_cfunc; use crate::stringify_cfunc;
use crate::sync; use crate::sync;
...@@ -881,21 +881,8 @@ impl NodeImpl { ...@@ -881,21 +881,8 @@ impl NodeImpl {
// Update pico metadata. // Update pico metadata.
match ddl { match ddl {
Ddl::CreateSpace { id, .. } => { Ddl::CreateSpace { id, .. } => {
self.storage ddl_meta_space_update_operable(&self.storage, id, true)
.spaces .expect("storage shouldn't fail");
.update_operable(id, true)
.expect("storage error");
self.storage
.indexes
.update_operable(id, 0, true)
.expect("storage error");
// For now we just assume that during space creation index with id 1
// exists if and only if it is a bucket_id index.
let res = self.storage.indexes.update_operable(id, 1, true);
// TODO: maybe we should first check if this index
// exists or check the space definition if this should
// be done, but for now we just ignore the error "no such index"
let _ = res;
} }
Ddl::DropSpace { id } => { Ddl::DropSpace { id } => {
...@@ -962,21 +949,8 @@ impl NodeImpl { ...@@ -962,21 +949,8 @@ impl NodeImpl {
} }
Ddl::DropSpace { id } => { Ddl::DropSpace { id } => {
self.storage ddl_meta_space_update_operable(&self.storage, id, true)
.spaces .expect("storage shouldn't fail");
.update_operable(id, true)
.expect("storage should never fail");
let iter = self
.storage
.indexes
.by_space_id(id)
.expect("storage should never fail");
for index in iter {
self.storage
.indexes
.update_operable(index.space_id, index.id, true)
.expect("storage should never fail");
}
} }
_ => { _ => {
...@@ -1159,21 +1133,8 @@ impl NodeImpl { ...@@ -1159,21 +1133,8 @@ impl NodeImpl {
} }
Ddl::DropSpace { id } => { Ddl::DropSpace { id } => {
self.storage ddl_meta_space_update_operable(&self.storage, id, false)
.spaces .expect("storage shouldn't fail");
.update_operable(id, false)
.expect("storage should never fail");
let iter = self
.storage
.indexes
.by_space_id(id)
.expect("storage should never fail");
for index in iter {
self.storage
.indexes
.update_operable(index.space_id, index.id, false)
.expect("storage should never fail");
}
} }
Ddl::DropIndex { index_id, space_id } => { Ddl::DropIndex { index_id, space_id } => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment