Class ::nsmcp::BufferedResultReader (public)

 ::nx::Class ::nsmcp::BufferedResultReader[i]

Defined in /usr/local/ns/tcl/nsmcp/log-01-scanner.tcl

Testcases:
No testcase defined.
Source code:
    :property channel:required
    :property limit:required
    :property offset:required
    :property {maxBytes:integer 2097152}
    :variable buffer {}
    :variable index 0
    :variable readMicroseconds 0
    :variable readBytes 0
    :variable readCalls 0

    :method init {} {
        seek ${:channel} ${:offset}
    }

    :public method next {} {
        #
        # Read one complete JSONL record inside the published snapshot.
        #
        # Keep unused channel bytes for the next record. Reject oversized or
        # incomplete records without reading beyond the fixed published limit.
        #
        # @return A dictionary with start, end and raw, or empty at exhaustion.
        #

        if {${:offset}>=${:limit}} {
            return {}
        }
        set start ${:offset}
        set raw {}
        while {${:offset}<${:limit}} {
            if {${:index}>=[string length ${:buffer}]} {
                set started [clock clicks -microseconds]
                set :buffer [read ${:channel} [expr {min(65536,${:limit}-${:offset})}]]
                incr :readMicroseconds [expr {max(0,[clock clicks -microseconds]-$started)}]
                incr :readBytes [string length ${:buffer}]
                incr :readCalls
                set :index 0
                if {${:buffer} eq ""} {
                    error "incomplete result cache"
                }
            }
            set newline [string first \n ${:buffer} ${:index}]
            set end [expr {$newline<0 ? [string length ${:buffer}] : $newline}]
            set count [expr {$end-${:index}}]
            set consumed [expr {$count+($newline>=0)}]
            if {${:offset}-$start+$consumed>${:maxBytes}} {
                error "cached record exceeds the page byte limit"
            }
            append raw [string range ${:buffer} ${:index} [expr {$end-1}]]
            incr :index $consumed
            incr :offset $consumed
            if {$newline>=0} {
                return [dict create start $start end ${:offset} raw $raw]
            }
        }
        error "incomplete result cache"
    }

    :public method statistics {} {
        #
        # Report channel work for this result page.
        #
        # Buffered bytes can include the next record in this published snapshot;
        # they are not a count of physical disk bytes or returned JSON bytes.
        #
        # @return Read time in microseconds and channel byte/call counts.
        #

        return [dict create readMicroseconds ${:readMicroseconds}  readBytes ${:readBytes} readCalls ${:readCalls}]
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: