nsmcp::AccessCardinalityStore method flush (public)
<instance of nsmcp::AccessCardinalityStore> flush
Defined in /usr/local/ns/tcl/nsmcp/log-traffic-aggregate.tcl
Persist buffered cardinality observations. Write pending observations to the optional cache and retain explicit capacity or storage failure state.
- Returns:
- The flush result, or an empty result when no observations are pending.
- Testcases:
- No testcase defined.
Source code: if {${:events}==0} { return } if {${:buffer} ne "" && ${:db} ne "" && [dict get ${:data} status] eq "active"} { set values {} dict for {id row} ${:buffer} { lappend values "([ns_dbquotelist [list [dict get $row kind] [dict get $row k] [dict get $row label] [dict get $row clipped] [dict get $row redacted] [dict get $row n]]])" } try { ns_db dml ${:handle} BEGIN # Values are quoted individually. Do not cache this bounded # batch as a distinct SQL template in DatabaseSession. ns_db dml ${:handle} "INSERT INTO nsmcp_access_aggregate.counts VALUES [join $values ,] ON CONFLICT(kind,k) DO UPDATE SET n=n+excluded.n" if {[:diskBytes]>[dict get ${:data} maxBytes]} { error "aggregation-disk-limit" } ns_db dml ${:handle} COMMIT } on error {message options} { set exception [ns_db exception ${:handle}] # Closing the native connection rolls back atomically even # when SQLite FULL has already ended the transaction. Avoid a # speculative ROLLBACK that logs a second spurious error. set disk [expr {$message eq "aggregation-disk-limit" || [string match -nocase {*full*} $exception]}] :fail write-batch [expr {$disk ? "aggregation-disk-limit" : "sqlite-write-failed"}] $message $options [expr {$disk ? "limited" : "unavailable"}] :disconnect true dict incr :data peerOmitted ${:peerPending} dict incr :data agentOmitted ${:agentPending} } } set :buffer {} set :events 0 set :peerPending 0 set :agentPending 0 dict set :data diskBytes [:diskBytes]XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)