[bug](scanner) Fix memory out of bound in scanner scheduler (#24840)

This commit is contained in:
xy720
2023-09-25 09:58:26 +08:00
committed by GitHub
parent ec93ea22b3
commit 39e6512a21
2 changed files with 3 additions and 4 deletions

View File

@ -150,9 +150,7 @@ Status ScannerScheduler::submit(ScannerContext* ctx) {
if (ctx->done()) {
return Status::EndOfFile("ScannerContext is done");
}
if (ctx->queue_idx == -1) {
ctx->queue_idx = (_queue_idx++ % QUEUE_NUM);
}
ctx->queue_idx = (_queue_idx++ % QUEUE_NUM);
if (!_pending_queues[ctx->queue_idx]->blocking_put(ctx)) {
return Status::InternalError("failed to submit scanner context to scheduler");
}

View File

@ -92,10 +92,11 @@ private:
static const int QUEUE_NUM = 4;
// The ScannerContext will be submitted to the pending queue roundrobin.
// _queue_idx pointer to the current queue.
// Use std::atomic_uint to prevent numerical overflow from memory out of bound.
// The scheduler thread will take ctx from pending queue, schedule it,
// and put it to the _scheduling_map.
// If any scanner finish, it will take ctx from and put it to pending queue again.
std::atomic_int _queue_idx = {0};
std::atomic_uint _queue_idx = {0};
BlockingQueue<ScannerContext*>** _pending_queues;
// scheduling thread pool