Repository: cmu-db/noisepage

Issue #1245: Race in CompilerTest.SimpleAggregateTest.
Created: 2020-10-20T01:17:15Z
Bug Report
Summary
CompilerTest.SimpleAggregateTest sometimes fails,
Environment
OS: Ubuntu 20.04 (LTS), CI.
Compiler: GCC 9.3.0, Clang 8.0.
Description
noisepage/build [master●] » LSAN_OPTIONS=suppressions=../build-support/data/lsan_suppressions.txt ./debug/compiler_test
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from CompilerTest
[ RUN      ] CompilerTest.SimpleAggregateTest
/home/kapi/git/noisepage/test/include/execution/compiler/output_checker.h:98: Failure
      Expected: curr_count_
      Which is: 9
To be equal to: expected_count_
      Which is: 10
/home/kapi/git/noisepage/test/include/execution/compiler/output_checker.h:186: Failure
      Expected: curr_sum_
      Which is: 444068
To be equal to: expected_
      Which is: 499500
[  FAILED  ] CompilerTest.SimpleAggregateTest (1503 ms)
[----------] 1 test from CompilerTest (1503 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (1503 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] CompilerTest.SimpleAggregateTest

 1 FAILED TEST
-----------------------------------------------------
Suppressions used:
  count      bytes template
      3       6168 libtbb.so
-----------------------------------------------------

struct OutputStruct {
    out0: Integer
    out1: Integer
}
struct AggPayload {
    gb_term_attr0 : Integer
    agg_term_attr0: IntegerSumAggregate
}
struct AggValues {
    gb_term_attr0 : Integer
    agg_term_attr0: Integer
}
struct QueryState {
    execCtx     : *ExecutionContext
    aggHashTable: AggregationHashTable
}
struct P2_State {
    filterManager: FilterManager
    aggHashTable1: AggregationHashTable
}
struct P1_State {
    
}
fun Query0_Pipeline1_KeyCheckPartial(lhs: *AggPayload, rhs: *AggPayload) -> bool {
    if (SqlBoolToBool(lhs.gb_term_attr0 != rhs.gb_term_attr0)) {
        return false
    }
    return true
}

fun Query0_Pipeline1_MergePartitions(queryState: *QueryState, aggHashTable: *AggregationHashTable, ahtOvfIter: *AHTOverflowPartitionIterator) -> nil {
    for (; @aggPartIterHasNext(ahtOvfIter); @aggPartIterNext(ahtOvfIter)) {
        var hashVal = @aggPartIterGetHash(ahtOvfIter)
        var partialRow = @ptrCast(*AggPayload, @aggPartIterGetRow(ahtOvfIter))
        var aggPayload = @ptrCast(*AggPayload, @aggHTLookup(aggHashTable, hashVal, Query0_Pipeline1_KeyCheckPartial, partialRow))
        if (aggPayload == nil) {
            @aggHTLink(aggHashTable, @aggPartIterGetRowEntry(ahtOvfIter))
        } else {
            @aggMerge(&aggPayload.agg_term_attr0, &partialRow.agg_term_attr0)
        }
    }
    return
}

fun Query0_Pipeline1_KeyCheck(aggPayload: *AggPayload, aggValues: *AggValues) -> bool {
    if (SqlBoolToBool(aggPayload.gb_term_attr0 != aggValues.gb_term_attr0)) {
        return false
    }
    return true
}

fun Query0_Pipeline2_FilterClause(execCtx: *ExecutionContext, vp: *VectorProjection, tids: *TupleIdList, context: *uint8) -> nil {
    @filterLt(execCtx, vp, 0, @intToSql(1000), tids)
    return
}

fun Query0_Init(queryState: *QueryState) -> nil {
    @aggHTInit(&queryState.aggHashTable, queryState.execCtx, @execCtxGetMem(queryState.execCtx), @sizeOf(AggPayload))
    return
}

fun Query0_Pipeline2_InitPipelineState(queryState: *QueryState, pipelineState: *P2_State) -> nil {
    @aggHTInit(&pipelineState.aggHashTable1, queryState.execCtx, @execCtxGetMem(queryState.execCtx), @sizeOf(AggPayload))
    @filterManagerInit(&pipelineState.filterManager, queryState.execCtx)
    @filterManagerInsertFilter(&pipelineState.filterManager, Query0_Pipeline2_FilterClause)
    return
}

fun Query0_Pipeline2_TearDownPipelineState(queryState: *QueryState, pipelineState: *P2_State) -> nil {
    @aggHTFree(&pipelineState.aggHashTable1)
    @filterManagerFree(&pipelineState.filterManager)
    return
}

fun Query0_Pipeline2_ParallelWork(queryState: *QueryState, pipelineState: *P2_State, tvi: *TableVectorIterator) -> nil {
    var slot: TupleSlot
    for (@tableIterAdvance(tvi)) {
        var vpi = @tableIterGetVPI(tvi)
        @filterManagerRunFilters(&pipelineState.filterManager, vpi, queryState.execCtx)
        for (; @vpiHasNextFiltered(vpi); @vpiAdvanceFiltered(vpi)) {
            slot = @vpiGetSlot(vpi)
            var aggValues: AggValues
            aggValues.gb_term_attr0 = @vpiGetInt(vpi, 1)
            aggValues.agg_term_attr0 = @vpiGetInt(vpi, 0)
            var hashVal = @hash(aggValues.gb_term_attr0)
            var aggPayload = @ptrCast(*AggPayload, @aggHTLookup(&pipelineState.aggHashTable1, hashVal, Query0_Pipeline1_KeyCheck, &aggValues))
            if (aggPayload == nil) {
                aggPayload = @ptrCast(*AggPayload, @aggHTInsert(&pipelineState.aggHashTable1, hashVal, true))
                aggPayload.gb_term_attr0 = aggValues.gb_term_attr0
                @aggInit(&aggPayload.agg_term_attr0)
            }
            @aggAdvance(&aggPayload.agg_term_attr0, &aggValues.agg_term_attr0)
        }
        var vpi_num_tuples = @tableIterGetVPINumTuples(tvi)
    }
    return
}

fun Query0_Pipeline2_Init(queryState: *QueryState) -> nil {
    var threadStateContainer = @execCtxGetTLS(queryState.execCtx)
    @tlsReset(threadStateContainer, @sizeOf(P2_State), Query0_Pipeline2_InitPipelineState, Query0_Pipeline2_TearDownPipelineState, queryState)
    return
}

fun Query0_Pipeline2_Run(queryState: *QueryState) -> nil {
    var pipelineState = @ptrCast(*P2_State, @tlsGetCurrentThreadState(@execCtxGetTLS(queryState.execCtx)))
    @execCtxStartPipelineTracker(queryState.execCtx, 2)
    var col_oids: [2]uint32
    col_oids[0] = 1
    col_oids[1] = 2
    @iterateTableParallel(1002, col_oids, queryState, queryState.execCtx, Query0_Pipeline2_ParallelWork)
    @aggHTMoveParts(&queryState.aggHashTable, @execCtxGetTLS(queryState.execCtx), @offsetOf(P2_State, aggHashTable1), Query0_Pipeline1_MergePartitions)
    @execCtxEndPipelineTracker(queryState.execCtx, 0, 2)
    return
}

fun Query0_Pipeline2_TearDown(queryState: *QueryState) -> nil {
    @tlsClear(@execCtxGetTLS(queryState.execCtx))
    return
}

fun Query0_Pipeline1_InitPipelineState(queryState: *QueryState, pipelineState: *P1_State) -> nil {
    return
}

fun Query0_Pipeline1_TearDownPipelineState(queryState: *QueryState, pipelineState: *P1_State) -> nil {
    return
}

fun Query0_Pipeline1_ParallelWork(queryState: *QueryState, pipelineState: *P1_State, aggHashTable: *AggregationHashTable) -> nil {
    var iterBase: AHTIterator
    var iter = &iterBase
    for (@aggHTIterInit(iter, aggHashTable); @aggHTIterHasNext(iter); @aggHTIterNext(iter)) {
        var aggRow = @ptrCast(*AggPayload, @aggHTIterGetRow(iter))
        var outRow = @ptrCast(*OutputStruct, @resultBufferAllocRow(queryState.execCtx))
        outRow.out0 = aggRow.gb_term_attr0
        outRow.out1 = @aggResult(&aggRow.agg_term_attr0)
    }
    @aggHTIterClose(iter)
    return
}

fun Query0_Pipeline1_Init(queryState: *QueryState) -> nil {
    var threadStateContainer = @execCtxGetTLS(queryState.execCtx)
    @tlsReset(threadStateContainer, @sizeOf(P1_State), Query0_Pipeline1_InitPipelineState, Query0_Pipeline1_TearDownPipelineState, queryState)
    return
}

fun Query0_Pipeline1_Run(queryState: *QueryState) -> nil {
    var pipelineState = @ptrCast(*P1_State, @tlsGetCurrentThreadState(@execCtxGetTLS(queryState.execCtx)))
    @execCtxStartPipelineTracker(queryState.execCtx, 1)
    @aggHTParallelPartScan(&queryState.aggHashTable, queryState, @execCtxGetTLS(queryState.execCtx), Query0_Pipeline1_ParallelWork)
    @resultBufferFinalize(queryState.execCtx)
    @execCtxEndPipelineTracker(queryState.execCtx, 0, 1)
    return
}

fun Query0_Pipeline1_TearDown(queryState: *QueryState) -> nil {
    @tlsClear(@execCtxGetTLS(queryState.execCtx))
    return
}

fun Query0_TearDown(queryState: *QueryState) -> nil {
    @aggHTFree(&queryState.aggHashTable)
    return
}

Other notes
I can't get it to reproduce reliably. I actually suspect that fixing #1116 might fix it.

Duplicate issue #1086: compiler_test Suspected Race Condition
Created: 2020-08-14T17:23:18Z
It looks like compiler_test is occasionally failing on various open branches as well as master. An investigation into where the race condition arises from is necessary. See the following Jenkins runs for details:

http://jenkins.db.cs.cmu.edu:8080/blue/organizations/jenkins/terrier/detail/master/642/tests
http://jenkins.db.cs.cmu.edu:8080/blue/organizations/jenkins/terrier/detail/PR-1081/4/pipeline
http://jenkins.db.cs.cmu.edu:8080/blue/organizations/jenkins/terrier/detail/PR-1067/22/pipeline

Closing comment (2020-10-20T02:41:51Z): The Jenkins data got deleted for being too old. I think it is the same as #1245 but I don't remember. Closing.