MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / drop_sequence

Function drop_sequence

nodedb/src/control/server/pgwire/ddl/sequence/drop.rs:13–59  ·  view source on GitHub ↗
(
    state: &SharedState,
    identity: &AuthenticatedIdentity,
    parts: &[&str],
)

Source from the content-addressed store, hash-verified

11use super::parse::parse_drop_target;
12
13pub fn drop_sequence(
14 state: &SharedState,
15 identity: &AuthenticatedIdentity,
16 parts: &[&str],
17) -> PgWireResult<Vec<Response>> {
18 let tenant_id = identity.tenant_id.as_u64();
19
20 let (name, if_exists) = parse_drop_target(parts, 2);
21
22 if !state.sequence_registry.exists(tenant_id, &name) {
23 if if_exists {
24 return Ok(vec![Response::Execution(Tag::new("DROP SEQUENCE"))]);
25 }
26 return Err(PgWireError::UserError(Box::new(ErrorInfo::new(
27 "ERROR".to_owned(),
28 "42P01".to_owned(),
29 format!("sequence \"{name}\" does not exist"),
30 ))));
31 }
32
33 // Propose the delete through the metadata raft group. Every
34 // node's applier removes the record from local redb and from
35 // its in-memory `sequence_registry`.
36 let entry = crate::control::catalog_entry::CatalogEntry::DeleteSequence {
37 tenant_id,
38 name: name.clone(),
39 };
40 let log_index = crate::control::metadata_proposer::propose_catalog_entry(state, &entry)
41 .map_err(|e| {
42 PgWireError::UserError(Box::new(ErrorInfo::new(
43 "ERROR".to_owned(),
44 "XX000".to_owned(),
45 e.to_string(),
46 )))
47 })?;
48 if log_index == 0 {
49 // Single-node / no-cluster fallback.
50 if let Some(catalog) = state.credentials.catalog() {
51 let _ = catalog.delete_sequence(tenant_id, &name);
52 }
53 let _ = state.sequence_registry.remove(tenant_id, &name);
54 }
55
56 state.schema_version.bump();
57
58 Ok(vec![Response::Execution(Tag::new("DROP SEQUENCE"))])
59}

Callers 1

dispatchFunction · 0.85

Calls 10

parse_drop_targetFunction · 0.85
propose_catalog_entryFunction · 0.85
to_stringMethod · 0.80
delete_sequenceMethod · 0.80
as_u64Method · 0.45
existsMethod · 0.45
cloneMethod · 0.45
catalogMethod · 0.45
removeMethod · 0.45
bumpMethod · 0.45

Tested by

no test coverage detected