nsmcp::AccessDiagnosticTool method scanBounds (protected)

 <instance of nsmcp::AccessDiagnosticTool[i]> scanBounds context \
    options

Defined in /usr/local/ns/tcl/nsmcp/traffic-tools.tcl

Parameters:
context (required)
options (required)

Testcases:
No testcase defined.
Source code:
set path [:source [$context server] $options]
file stat $path before
set size $before(size)
set bounds [dict create from 0 to $size sourceBytes $size strategy full reason {Full scan requested or source below seek threshold.} probeBytes 0]
if {[dict get $options scanStrategy] eq "full" || $size<${:seekMinimumBytes}} {return $bounds}
set f [open $path rb]
set samples {}; set probeBytes 0
try {
    set prefix [read $f [expr {min(256,$size)}]]
    set identity [ns_crypto::md string -digest sha256 -- [list [file normalize $path] $before(dev) $before(ino) $prefix]]
    set first [:seekSample $f 0 $size samples probeBytes]
    set last [:seekSample $f [expr {max(0,$size-65536)}] $size samples probeBytes]
    # Spread probes across the file before assuming monotonicity.
    for {set i 1} {$i<16} {incr i} {
        :seekSample $f [expr {$size*$i/16}] $size samples probeBytes
    }
    foreach {key target} [list from [expr {[dict get $options from]-300}] to [expr {[dict get $options to]+300}]] {
        if {$target<=[lindex $first 2]} {dict set bounds $key 0; continue}
        if {$target>=[lindex $last 2]} {dict set bounds $key $size; continue}
        set low $first; set high $last
        for {set i 0} {$i<40 && [lindex $high 0]-[lindex $low 0]>131072} {incr i} {
            set middle [:seekSample $f [expr {([lindex $low 0]+[lindex $high 0])/2}] $size samples probeBytes]
            if {[lindex $middle 2]<$target} {set low $middle} else {set high $middle}
        }
        dict set bounds $key [expr {$key eq "from" ? [lindex $low 0] : [lindex $high 1]}]
    }
    # A lower bound beyond the final sample still examines its tail.
    if {[dict get $bounds from]==$size} {dict set bounds from [lindex $last 0]}
    file stat $path after
    if {$before(dev)!=$after(dev) || $before(ino)!=$after(ino) || $after(size)<$size} {error "Source changed during seek"}
    dict set bounds identity $identity
    dict set bounds strategy completion-window
    dict set bounds reason {Sampled completion timestamps were ordered; unsampled disorder and requests completing more than 300s outside the start-time window may be missed. Use scanStrategy full to avoid seek assumptions.}
} on error {message} {
    dict set bounds from 0
    dict set bounds to $size
    dict set bounds reason "Seek unavailable; full-file fallback: $message"
} finally {close $f}
dict set bounds probeBytes $probeBytes
return $bounds
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: