nsmcp::AccessCardinalityStore method flush (public)

 <instance of nsmcp::AccessCardinalityStore[i]> flush

Defined in /usr/local/ns/tcl/nsmcp/log-traffic-aggregate.tcl

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 "([dict get $row kind],[${:db} quote [dict get $row k]],[${:db} quote [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.
        :disconnect true
        set disk [expr {$message eq "aggregation-disk-limit" || [string match -nocase {*full*} $exception]}]
        dict set :data status [expr {$disk ? "limited" : "unavailable"}]
        dict set :data reason [expr {$disk ? "aggregation-disk-limit" : "sqlite-write-failed"}]
        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
[ hide source ] | [ make this the default ]
Show another procedure: