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

Interrupt handling #26

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 10 additions & 3 deletions src/quack_heap_seq_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ PostgresHeapSeqScan::PreparePageRead(PostgresHeapSeqScanThreadInfo &threadScanIn

void
PostgresHeapSeqScan::InitParallelScanState(duckdb::TableFunctionInitInput &input) {
(void) GetRelation();
(void)GetRelation();
m_parallel_scan_state.m_nblocks = RelationGetNumberOfBlocks(m_rel);

/* SELECT COUNT(*) FROM */
Expand Down Expand Up @@ -111,7 +111,9 @@ PostgresHeapSeqScan::ReadPageTuples(duckdb::DataChunk &output, PostgresHeapSeqSc
threadScanInfo.m_read_next_page = true;
} else {
block = threadScanInfo.m_block_number;
page = BufferGetPage(threadScanInfo.m_buffer);
if (block != InvalidBlockNumber) {
page = BufferGetPage(threadScanInfo.m_buffer);
}
}

while (block != InvalidBlockNumber) {
Expand Down Expand Up @@ -159,7 +161,12 @@ PostgresHeapSeqScan::ReadPageTuples(duckdb::DataChunk &output, PostgresHeapSeqSc
UnlockReleaseBuffer(threadScanInfo.m_buffer);
m_parallel_scan_state.m_lock.unlock();
threadScanInfo.m_read_next_page = true;
block = threadScanInfo.m_block_number = m_parallel_scan_state.AssignNextBlockNumber();
/* Handle cancel request */
if (QueryCancelPending) {
block = threadScanInfo.m_block_number = InvalidBlockNumber;
} else {
block = threadScanInfo.m_block_number = m_parallel_scan_state.AssignNextBlockNumber();
}
}

/* We have collected STANDARD_VECTOR_SIZE */
Expand Down
3 changes: 2 additions & 1 deletion src/quack_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ void
Quack_BeginCustomScan(CustomScanState *cscanstate, EState *estate, int eflags) {
QuackScanState *quackScanState = (QuackScanState *)cscanstate;
quackScanState->css.ss.ps.ps_ResultTupleDesc = quackScanState->css.ss.ss_ScanTupleSlot->tts_tupleDescriptor;
HOLD_CANCEL_INTERRUPTS();
Copy link
Collaborator

@Mytherin Mytherin May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could in the future e.g. have a background thread here:

void CheckForInterrupts() {
    while(!finished) {
        if (QueryCancelPending) {
               connection->Interrupt();
               break;
        }
        sleep(10ms);
    }
}

}

static TupleTableSlot *
Quack_ExecCustomScan(CustomScanState *node) {
QuackScanState *quackScanState = (QuackScanState *)node;
TupleTableSlot *slot = quackScanState->css.ss.ss_ScanTupleSlot;
MemoryContext oldContext;


if (!quackScanState->is_executed) {
quackScanState->queryResult = quackScanState->preparedStatement->Execute();
Expand Down Expand Up @@ -107,6 +107,7 @@ Quack_EndCustomScan(CustomScanState *node) {
quackScanState->queryResult.reset();
delete quackScanState->preparedStatement;
delete quackScanState->duckdb;
RESUME_CANCEL_INTERRUPTS();
}

void
Expand Down