use std::sync::Arc;
use tracing::debug;
use crate::control::security::catalog::{StoredCollection, StoredOwner};
use crate::control::state::SharedState;
pub fn put_owner_sync(stored: &StoredCollection, shared: Arc<SharedState>) {
shared.permissions.install_replicated_owner(&StoredOwner {
object_type: "collection".into(),
object_name: stored.name.clone(),
tenant_id: stored.tenant_id,
owner_username: stored.owner.clone(),
});
}
pub async fn put_async(stored: StoredCollection, shared: Arc<SharedState>) {
match crate::control::server::pgwire::ddl::collection::create::dispatch_register_from_stored(
&shared, &stored,
)
.await
{
Ok(()) => {
debug!(
collection = %stored.name,
"catalog_entry: Register dispatched to all Data Plane cores"
);
}
Err(e) => {
tracing::error!(
collection = %stored.name,
error = %e,
"catalog_entry: Register barrier failed — one or more Data Plane cores \
did not acknowledge the schema update; this node may serve stale schema"
);
}
}
}
pub fn purge_sync(tenant_id: u64, name: String, shared: Arc<SharedState>) {
let owner_removed =
shared
.permissions
.install_replicated_remove_owner("collection", tenant_id, &name);
let grant_target = format!("collection:{tenant_id}:{name}");
let grants_removed = shared.permissions.remove_grants_for_target(&grant_target);
debug!(
collection = %name,
tenant = tenant_id,
owner_removed,
grants_removed,
"catalog_entry: PurgeCollection post-apply sync (owner + grants evicted)"
);
}
pub fn deactivate(tenant_id: u64, name: String, _shared: Arc<SharedState>) {
debug!(
collection = %name,
tenant = tenant_id,
"catalog_entry: DeactivateCollection post-apply (owner retained for undrop; Data Plane Unregister deferred)"
);
}