From cf2bf740140040e36fae4ac80f2b006c8adfe270 Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Mon, 20 May 2024 16:34:28 -0400 Subject: [PATCH] adapter: adjust error codes based on severity This ensures that the emitted error codes match the behavior in PostgreSQL. `notice` and higher severity should emit `SUCCESSFUL_COMPLETION` instead of `WARNING`. --- src/adapter/src/notice.rs | 35 ++++++++++++++----------- src/environmentd/tests/testdata/http/ws | 2 +- test/pgtest-mz/notice.pt | 22 ++++++++-------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/adapter/src/notice.rs b/src/adapter/src/notice.rs index c9b02b6438462..06c870fd0a21f 100644 --- a/src/adapter/src/notice.rs +++ b/src/adapter/src/notice.rs @@ -259,24 +259,27 @@ impl AdapterNotice { AdapterNotice::ExplicitTransactionControlInImplicitTransaction => { SqlState::NO_ACTIVE_SQL_TRANSACTION } - AdapterNotice::UserRequested { .. } => SqlState::WARNING, - AdapterNotice::ClusterReplicaStatusChanged { .. } => SqlState::WARNING, + AdapterNotice::UserRequested { severity } => match severity { + NoticeSeverity::Warning => SqlState::WARNING, + _ => SqlState::SUCCESSFUL_COMPLETION, + }, + AdapterNotice::ClusterReplicaStatusChanged { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::CascadeDroppedObject { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::DroppedActiveDatabase { .. } => SqlState::from_code("MZ002"), AdapterNotice::DroppedActiveCluster { .. } => SqlState::from_code("MZ003"), - AdapterNotice::QueryTimestamp { .. } => SqlState::WARNING, - AdapterNotice::EqualSubscribeBounds { .. } => SqlState::WARNING, - AdapterNotice::QueryTrace { .. } => SqlState::WARNING, - AdapterNotice::UnimplementedIsolationLevel { .. } => SqlState::WARNING, - AdapterNotice::StrongSessionSerializable => SqlState::WARNING, - AdapterNotice::BadStartupSetting { .. } => SqlState::WARNING, - AdapterNotice::RbacUserDisabled => SqlState::WARNING, - AdapterNotice::RoleMembershipAlreadyExists { .. } => SqlState::WARNING, + AdapterNotice::QueryTimestamp { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::EqualSubscribeBounds { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::QueryTrace { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::UnimplementedIsolationLevel { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::StrongSessionSerializable => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::BadStartupSetting { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::RbacUserDisabled => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::RoleMembershipAlreadyExists { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::RoleMembershipDoesNotExists { .. } => SqlState::WARNING, - AdapterNotice::AutoRunOnIntrospectionCluster => SqlState::WARNING, + AdapterNotice::AutoRunOnIntrospectionCluster => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::AlterIndexOwner { .. } => SqlState::WARNING, - AdapterNotice::CannotRevoke { .. } => SqlState::WARNING, - AdapterNotice::NonApplicablePrivilegeTypes { .. } => SqlState::WARNING, + AdapterNotice::CannotRevoke { .. } => SqlState::WARNING_PRIVILEGE_NOT_REVOKED, + AdapterNotice::NonApplicablePrivilegeTypes { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::PlanNotice(plan) => match plan { PlanNotice::ObjectDoesNotExist { .. } => SqlState::UNDEFINED_OBJECT, PlanNotice::UpsertSinkKeyNotEnforced { .. } => SqlState::WARNING, @@ -284,9 +287,9 @@ impl AdapterNotice { AdapterNotice::UnknownSessionDatabase(_) => SqlState::from_code("MZ004"), AdapterNotice::DefaultClusterDoesNotExist { .. } => SqlState::from_code("MZ005"), AdapterNotice::OptimizerNotice { .. } => SqlState::SUCCESSFUL_COMPLETION, - AdapterNotice::DroppedInUseIndex { .. } => SqlState::WARNING, - AdapterNotice::WebhookSourceCreated { .. } => SqlState::WARNING, - AdapterNotice::PerReplicaLogRead { .. } => SqlState::WARNING, + AdapterNotice::DroppedInUseIndex { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::WebhookSourceCreated { .. } => SqlState::SUCCESSFUL_COMPLETION, + AdapterNotice::PerReplicaLogRead { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::VarDefaultUpdated { .. } => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::Welcome(_) => SqlState::SUCCESSFUL_COMPLETION, AdapterNotice::PlanInsights(_) => SqlState::from_code("MZ001"), diff --git a/src/environmentd/tests/testdata/http/ws b/src/environmentd/tests/testdata/http/ws index 1619761130bf2..45569a5417736 100644 --- a/src/environmentd/tests/testdata/http/ws +++ b/src/environmentd/tests/testdata/http/ws @@ -355,7 +355,7 @@ ws-text ws-text {"query":"SELECT 1 FROM mz_sources LIMIT 1"} ---- -{"type":"Notice","payload":{"message":"query was automatically run on the \"mz_introspection\" cluster","code":"01000","severity":"debug"}} +{"type":"Notice","payload":{"message":"query was automatically run on the \"mz_introspection\" cluster","code":"00000","severity":"debug"}} {"type":"CommandStarting","payload":{"has_rows":true,"is_streaming":false}} {"type":"Rows","payload":{"columns":[{"name":"?column?","type_oid":23,"type_len":4,"type_mod":-1}]}} {"type":"Row","payload":["1"]} diff --git a/test/pgtest-mz/notice.pt b/test/pgtest-mz/notice.pt index 902da4fc0dc0b..51e4474a6a775 100644 --- a/test/pgtest-mz/notice.pt +++ b/test/pgtest-mz/notice.pt @@ -70,7 +70,7 @@ CommandComplete {"tag":"CREATE INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"DROP INDEX"} ReadyForQuery {"status":"I"} -NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]} +NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]} CommandComplete {"tag":"DROP INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"DROP MATERIALIZED VIEW"} @@ -87,14 +87,14 @@ CommandComplete {"tag":"CREATE INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"CREATE MATERIALIZED VIEW"} ReadyForQuery {"status":"I"} -NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]} +NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]} CommandComplete {"tag":"DROP INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"CREATE INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"CREATE INDEX"} ReadyForQuery {"status":"I"} -NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]} +NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]} CommandComplete {"tag":"DROP INDEX"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"DROP INDEX"} @@ -323,10 +323,10 @@ CommandComplete {"tag":"CREATE DATABASE"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"SET"} ReadyForQuery {"status":"I"} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]} NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"MZ002"},{"typ":"M","value":"active database \"d4\" has been dropped"}]} CommandComplete {"tag":"DROP OWNED"} ReadyForQuery {"status":"I"} @@ -388,10 +388,10 @@ CommandComplete {"tag":"CREATE CLUSTER"} ReadyForQuery {"status":"I"} CommandComplete {"tag":"SET"} ReadyForQuery {"status":"I"} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]} -NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]} +NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]} NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"MZ003"},{"typ":"M","value":"active cluster \"c4\" has been dropped"}]} CommandComplete {"tag":"DROP OWNED"} ReadyForQuery {"status":"I"}