Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Improve handling of context cancel in DBWorkManager to be more responsive #276

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions pkg/goDB/DBWorkManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,38 +473,37 @@ func (w *DBWorkManager) grabAndProcessWorkload(ctx context.Context, wg *sync.Wai
}
}()

var workload DBWorkload
for chanOpen := true; chanOpen; {
select {
case <-ctx.Done():
// query was cancelled, exit
logger.Infof("Query cancelled (workload %d / %d)...", w.nWorkloadsProcessed.Load(), w.nWorkloads)
return
case workload, chanOpen = <-workloadChan:
if chanOpen {
resultMap := hashmap.NewAggFlowMapWithMetadata()
for _, workDir := range workload.workDirs {

if memPool != nil {
workDir.SetMemPool(memPool)
}

// if there is an error during one of the read jobs, throw a syslog message and terminate
err := w.readBlocksAndEvaluate(workDir, enc, &resultMap)
if err != nil {
logger.Error(err)
mapChan <- hashmap.NilAggFlowMapWithMetadata
return
}
for workload := range workloadChan {
resultMap := hashmap.NewAggFlowMapWithMetadata()
for _, workDir := range workload.workDirs {
select {
case <-ctx.Done():

// query was cancelled, exit
logger.Infof("Query cancelled (workload %d / %d)...", w.nWorkloadsProcessed.Load(), w.nWorkloads)
fako1024 marked this conversation as resolved.
Show resolved Hide resolved
return
default:

// check if a memory pool is available
if memPool != nil {
workDir.SetMemPool(memPool)
}

// Workload is counted, but we only add it to the final result if we got any entries
w.nWorkloadsProcessed.Add(1)
if resultMap.Len() > 0 {
mapChan <- resultMap
// if there is an error during one of the read jobs, throw a syslog message and terminate
err := w.readBlocksAndEvaluate(workDir, enc, &resultMap)
if err != nil {
logger.Error(err)
mapChan <- hashmap.NilAggFlowMapWithMetadata
return
}
}
}

// Workload is counted, but we only add it to the final result if we got any entries
w.nWorkloadsProcessed.Add(1)
if resultMap.Len() > 0 {
mapChan <- resultMap
}
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/goDB/engine/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (qr *QueryRunner) RunStatement(ctx context.Context, stmt *query.Statement)
result.Summary.Last = tSpanLast

// If enabled, run a live query in the background / parallel to the DB query and put the results on the same output channel
liveQueryWG := qr.runLiveQuery(ctx, mapChan, stmt)
liveQueryWG := qr.runLiveQuery(queryCtx, mapChan, stmt)

// spawn reader processing units and make them work on the individual DB blocks
// processing by interface is sequential, e.g. for multi-interface queries
Expand Down
Loading