|
|
@ -28,7 +28,7 @@ use {
|
|
|
|
super::{Field, IWModel, Layer, Model},
|
|
|
|
super::{Field, IWModel, Layer, Model},
|
|
|
|
crate::{
|
|
|
|
crate::{
|
|
|
|
engine::{
|
|
|
|
engine::{
|
|
|
|
core::GlobalNS,
|
|
|
|
core::{util::EntityLocator, GlobalNS},
|
|
|
|
data::{
|
|
|
|
data::{
|
|
|
|
tag::{DataTag, TagClass},
|
|
|
|
tag::{DataTag, TagClass},
|
|
|
|
DictEntryGeneric,
|
|
|
|
DictEntryGeneric,
|
|
|
@ -43,6 +43,7 @@ use {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
lex::Ident,
|
|
|
|
lex::Ident,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
txn::gns as gnstxn,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
util,
|
|
|
|
util,
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -247,8 +248,14 @@ impl<'a> AlterPlan<'a> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Model {
|
|
|
|
impl Model {
|
|
|
|
pub fn exec_alter(gns: &GlobalNS, alter: AlterModel) -> DatabaseResult<()> {
|
|
|
|
pub fn transactional_exec_alter<GI: gnstxn::GNSTransactionDriverLLInterface>(
|
|
|
|
gns.with_model(alter.model, |model| {
|
|
|
|
gns: &GlobalNS,
|
|
|
|
|
|
|
|
txn_driver: &mut gnstxn::GNSTransactionDriverAnyFS<GI>,
|
|
|
|
|
|
|
|
alter: AlterModel,
|
|
|
|
|
|
|
|
) -> DatabaseResult<()> {
|
|
|
|
|
|
|
|
let (space_name, model_name) = EntityLocator::parse_entity(alter.model)?;
|
|
|
|
|
|
|
|
gns.with_space(space_name, |space| {
|
|
|
|
|
|
|
|
space.with_model(model_name, |model| {
|
|
|
|
// make intent
|
|
|
|
// make intent
|
|
|
|
let iwm = model.intent_write_model();
|
|
|
|
let iwm = model.intent_write_model();
|
|
|
|
// prepare plan
|
|
|
|
// prepare plan
|
|
|
@ -265,6 +272,15 @@ impl Model {
|
|
|
|
AlterAction::Add(new_fields) => {
|
|
|
|
AlterAction::Add(new_fields) => {
|
|
|
|
let mut guard = model.delta_state().wguard();
|
|
|
|
let mut guard = model.delta_state().wguard();
|
|
|
|
// TODO(@ohsayan): this impacts lockdown duration; fix it
|
|
|
|
// TODO(@ohsayan): this impacts lockdown duration; fix it
|
|
|
|
|
|
|
|
if GI::NONNULL {
|
|
|
|
|
|
|
|
// prepare txn
|
|
|
|
|
|
|
|
let txn = gnstxn::AlterModelAddTxn::new(
|
|
|
|
|
|
|
|
gnstxn::ModelIDRef::new_ref(space_name, space, model_name, model),
|
|
|
|
|
|
|
|
&new_fields,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// commit txn
|
|
|
|
|
|
|
|
txn_driver.try_commit(txn)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
new_fields
|
|
|
|
new_fields
|
|
|
|
.stseq_ord_kv()
|
|
|
|
.stseq_ord_kv()
|
|
|
|
.map(|(x, y)| (x.clone(), y.clone()))
|
|
|
|
.map(|(x, y)| (x.clone(), y.clone()))
|
|
|
@ -275,22 +291,46 @@ impl Model {
|
|
|
|
iwm.fields_mut().st_insert(field_id, field);
|
|
|
|
iwm.fields_mut().st_insert(field_id, field);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AlterAction::Remove(remove) => {
|
|
|
|
AlterAction::Remove(removed) => {
|
|
|
|
let mut guard = model.delta_state().wguard();
|
|
|
|
let mut guard = model.delta_state().wguard();
|
|
|
|
remove.iter().for_each(|field_id| {
|
|
|
|
if GI::NONNULL {
|
|
|
|
|
|
|
|
// prepare txn
|
|
|
|
|
|
|
|
let txn = gnstxn::AlterModelRemoveTxn::new(
|
|
|
|
|
|
|
|
gnstxn::ModelIDRef::new_ref(space_name, space, model_name, model),
|
|
|
|
|
|
|
|
&removed,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// commit txn
|
|
|
|
|
|
|
|
txn_driver.try_commit(txn)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removed.iter().for_each(|field_id| {
|
|
|
|
model
|
|
|
|
model
|
|
|
|
.delta_state()
|
|
|
|
.delta_state()
|
|
|
|
.append_unresolved_wl_field_rem(&mut guard, field_id.as_str());
|
|
|
|
.append_unresolved_wl_field_rem(&mut guard, field_id.as_str());
|
|
|
|
iwm.fields_mut().st_delete(field_id.as_str());
|
|
|
|
iwm.fields_mut().st_delete(field_id.as_str());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AlterAction::Update(u) => {
|
|
|
|
AlterAction::Update(updated) => {
|
|
|
|
u.into_iter().for_each(|(field_id, field)| {
|
|
|
|
if GI::NONNULL {
|
|
|
|
|
|
|
|
// prepare txn
|
|
|
|
|
|
|
|
let txn = gnstxn::AlterModelUpdateTxn::new(
|
|
|
|
|
|
|
|
gnstxn::ModelIDRef::new_ref(space_name, space, model_name, model),
|
|
|
|
|
|
|
|
&updated,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// commit txn
|
|
|
|
|
|
|
|
txn_driver.try_commit(txn)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updated.into_iter().for_each(|(field_id, field)| {
|
|
|
|
iwm.fields_mut().st_update(&field_id, field);
|
|
|
|
iwm.fields_mut().st_update(&field_id, field);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn exec_alter(gns: &GlobalNS, stmt: AlterModel) -> DatabaseResult<()> {
|
|
|
|
|
|
|
|
gnstxn::GNSTransactionDriverNullZero::nullzero_create_exec(gns, |driver| {
|
|
|
|
|
|
|
|
Self::transactional_exec_alter(gns, driver, stmt)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|