use crate::metrics::{
sink::{CacheKind, CacheMissReason, CacheOutcome},
state as metrics,
};
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_cache_outcome(
ops: &mut metrics::EventOps,
kind: CacheKind,
outcome: CacheOutcome,
) {
#[remain::sorted]
match kind {
CacheKind::SharedQueryPlan => {
record_global_shared_query_plan_cache_outcome(ops, outcome);
}
CacheKind::SqlCompiledCommand => {
record_global_sql_compiled_command_cache_outcome(ops, outcome);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_shared_query_plan_cache_outcome(
ops: &mut metrics::EventOps,
outcome: CacheOutcome,
) {
#[remain::sorted]
match outcome {
CacheOutcome::Hit => {
ops.cache_shared_query_plan_hits = ops.cache_shared_query_plan_hits.saturating_add(1);
}
CacheOutcome::Insert => {
ops.cache_shared_query_plan_inserts =
ops.cache_shared_query_plan_inserts.saturating_add(1);
}
CacheOutcome::Miss => {
ops.cache_shared_query_plan_misses =
ops.cache_shared_query_plan_misses.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_sql_compiled_command_cache_outcome(
ops: &mut metrics::EventOps,
outcome: CacheOutcome,
) {
#[remain::sorted]
match outcome {
CacheOutcome::Hit => {
ops.cache_sql_compiled_command_hits =
ops.cache_sql_compiled_command_hits.saturating_add(1);
}
CacheOutcome::Insert => {
ops.cache_sql_compiled_command_inserts =
ops.cache_sql_compiled_command_inserts.saturating_add(1);
}
CacheOutcome::Miss => {
ops.cache_sql_compiled_command_misses =
ops.cache_sql_compiled_command_misses.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_cache_entries(
ops: &mut metrics::EventOps,
kind: CacheKind,
entries: u64,
) {
#[remain::sorted]
match kind {
CacheKind::SharedQueryPlan => {
ops.cache_shared_query_plan_entries = entries;
}
CacheKind::SqlCompiledCommand => {
ops.cache_sql_compiled_command_entries = entries;
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_cache_miss_reason(
ops: &mut metrics::EventOps,
kind: CacheKind,
reason: CacheMissReason,
) {
#[remain::sorted]
match kind {
CacheKind::SharedQueryPlan => {
record_global_shared_query_plan_miss_reason(ops, reason);
}
CacheKind::SqlCompiledCommand => {
record_global_sql_compiled_command_miss_reason(ops, reason);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_shared_query_plan_miss_reason(
ops: &mut metrics::EventOps,
reason: CacheMissReason,
) {
#[remain::sorted]
match reason {
CacheMissReason::Cold => {
ops.cache_shared_query_plan_miss_cold =
ops.cache_shared_query_plan_miss_cold.saturating_add(1);
}
CacheMissReason::DistinctKey | CacheMissReason::Surface => {
ops.cache_shared_query_plan_miss_distinct_key = ops
.cache_shared_query_plan_miss_distinct_key
.saturating_add(1);
}
CacheMissReason::MethodVersion => {
ops.cache_shared_query_plan_miss_method_version = ops
.cache_shared_query_plan_miss_method_version
.saturating_add(1);
}
CacheMissReason::SchemaFingerprint | CacheMissReason::SchemaVersion => {
ops.cache_shared_query_plan_miss_schema_fingerprint = ops
.cache_shared_query_plan_miss_schema_fingerprint
.saturating_add(1);
}
CacheMissReason::Visibility => {
ops.cache_shared_query_plan_miss_visibility = ops
.cache_shared_query_plan_miss_visibility
.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_global_sql_compiled_command_miss_reason(
ops: &mut metrics::EventOps,
reason: CacheMissReason,
) {
#[remain::sorted]
match reason {
CacheMissReason::Cold => {
ops.cache_sql_compiled_command_miss_cold =
ops.cache_sql_compiled_command_miss_cold.saturating_add(1);
}
CacheMissReason::DistinctKey | CacheMissReason::Visibility => {
ops.cache_sql_compiled_command_miss_distinct_key = ops
.cache_sql_compiled_command_miss_distinct_key
.saturating_add(1);
}
CacheMissReason::MethodVersion => {
ops.cache_sql_compiled_command_miss_method_version = ops
.cache_sql_compiled_command_miss_method_version
.saturating_add(1);
}
CacheMissReason::SchemaFingerprint | CacheMissReason::SchemaVersion => {
ops.cache_sql_compiled_command_miss_schema_fingerprint = ops
.cache_sql_compiled_command_miss_schema_fingerprint
.saturating_add(1);
}
CacheMissReason::Surface => {
ops.cache_sql_compiled_command_miss_surface = ops
.cache_sql_compiled_command_miss_surface
.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_cache_outcome(
ops: &mut metrics::EntityCounters,
kind: CacheKind,
outcome: CacheOutcome,
) {
#[remain::sorted]
match kind {
CacheKind::SharedQueryPlan => {
record_entity_shared_query_plan_cache_outcome(ops, outcome);
}
CacheKind::SqlCompiledCommand => {
record_entity_sql_compiled_command_cache_outcome(ops, outcome);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_shared_query_plan_cache_outcome(
ops: &mut metrics::EntityCounters,
outcome: CacheOutcome,
) {
#[remain::sorted]
match outcome {
CacheOutcome::Hit => {
ops.cache_shared_query_plan_hits = ops.cache_shared_query_plan_hits.saturating_add(1);
}
CacheOutcome::Insert => {
ops.cache_shared_query_plan_inserts =
ops.cache_shared_query_plan_inserts.saturating_add(1);
}
CacheOutcome::Miss => {
ops.cache_shared_query_plan_misses =
ops.cache_shared_query_plan_misses.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_sql_compiled_command_cache_outcome(
ops: &mut metrics::EntityCounters,
outcome: CacheOutcome,
) {
#[remain::sorted]
match outcome {
CacheOutcome::Hit => {
ops.cache_sql_compiled_command_hits =
ops.cache_sql_compiled_command_hits.saturating_add(1);
}
CacheOutcome::Insert => {
ops.cache_sql_compiled_command_inserts =
ops.cache_sql_compiled_command_inserts.saturating_add(1);
}
CacheOutcome::Miss => {
ops.cache_sql_compiled_command_misses =
ops.cache_sql_compiled_command_misses.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_cache_miss_reason(
ops: &mut metrics::EntityCounters,
kind: CacheKind,
reason: CacheMissReason,
) {
#[remain::sorted]
match kind {
CacheKind::SharedQueryPlan => {
record_entity_shared_query_plan_miss_reason(ops, reason);
}
CacheKind::SqlCompiledCommand => {
record_entity_sql_compiled_command_miss_reason(ops, reason);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_shared_query_plan_miss_reason(
ops: &mut metrics::EntityCounters,
reason: CacheMissReason,
) {
#[remain::sorted]
match reason {
CacheMissReason::Cold => {
ops.cache_shared_query_plan_miss_cold =
ops.cache_shared_query_plan_miss_cold.saturating_add(1);
}
CacheMissReason::DistinctKey | CacheMissReason::Surface => {
ops.cache_shared_query_plan_miss_distinct_key = ops
.cache_shared_query_plan_miss_distinct_key
.saturating_add(1);
}
CacheMissReason::MethodVersion => {
ops.cache_shared_query_plan_miss_method_version = ops
.cache_shared_query_plan_miss_method_version
.saturating_add(1);
}
CacheMissReason::SchemaFingerprint | CacheMissReason::SchemaVersion => {
ops.cache_shared_query_plan_miss_schema_fingerprint = ops
.cache_shared_query_plan_miss_schema_fingerprint
.saturating_add(1);
}
CacheMissReason::Visibility => {
ops.cache_shared_query_plan_miss_visibility = ops
.cache_shared_query_plan_miss_visibility
.saturating_add(1);
}
}
}
#[remain::check]
pub(in crate::metrics::sink) const fn record_entity_sql_compiled_command_miss_reason(
ops: &mut metrics::EntityCounters,
reason: CacheMissReason,
) {
#[remain::sorted]
match reason {
CacheMissReason::Cold => {
ops.cache_sql_compiled_command_miss_cold =
ops.cache_sql_compiled_command_miss_cold.saturating_add(1);
}
CacheMissReason::DistinctKey | CacheMissReason::Visibility => {
ops.cache_sql_compiled_command_miss_distinct_key = ops
.cache_sql_compiled_command_miss_distinct_key
.saturating_add(1);
}
CacheMissReason::MethodVersion => {
ops.cache_sql_compiled_command_miss_method_version = ops
.cache_sql_compiled_command_miss_method_version
.saturating_add(1);
}
CacheMissReason::SchemaFingerprint | CacheMissReason::SchemaVersion => {
ops.cache_sql_compiled_command_miss_schema_fingerprint = ops
.cache_sql_compiled_command_miss_schema_fingerprint
.saturating_add(1);
}
CacheMissReason::Surface => {
ops.cache_sql_compiled_command_miss_surface = ops
.cache_sql_compiled_command_miss_surface
.saturating_add(1);
}
}
}