Skip to content

Commit

Permalink
fix FallbackOldAndSetNewAction by rearranging the order
Browse files Browse the repository at this point in the history
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
  • Loading branch information
YangKeao committed Aug 22, 2022
1 parent 9af0f03 commit a1359a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,20 @@ func TestSortSpillDisk(t *testing.T) {
}
}
// Test only 1 partition but spill disk.
require.Len(t, exec.partitionList, 1)
require.Equal(t, true, exec.partitionList[0].AlreadySpilledSafeForTest())
require.Equal(t, 2048, exec.partitionList[0].NumRow())
// Now spilling is in parallel.
// Maybe the second add() will be called after spilling, depends on
// Golang goroutine scheduling. So the result has two possibilities.
if len(exec.partitionList) == 1 {
require.Len(t, exec.partitionList, 1)
require.Equal(t, true, exec.partitionList[0].AlreadySpilledSafeForTest())
require.Equal(t, 2048, exec.partitionList[0].NumRow())
} else {
require.Len(t, exec.partitionList, 2)
require.Equal(t, true, exec.partitionList[0].AlreadySpilledSafeForTest())
require.Equal(t, true, exec.partitionList[1].AlreadySpilledSafeForTest())
require.Equal(t, 1024, exec.partitionList[0].NumRow())
require.Equal(t, 1024, exec.partitionList[1].NumRow())
}
err = exec.Close()
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ func (t *Tracker) SetActionOnExceed(a ActionOnExceed) {
func (t *Tracker) FallbackOldAndSetNewAction(a ActionOnExceed) {
t.actionMuForHardLimit.Lock()
defer t.actionMuForHardLimit.Unlock()
t.actionMuForHardLimit.actionOnExceed = reArrangeFallback(t.actionMuForHardLimit.actionOnExceed, a)
t.actionMuForHardLimit.actionOnExceed = reArrangeFallback(a, t.actionMuForHardLimit.actionOnExceed)
}

// FallbackOldAndSetNewActionForSoftLimit sets the action when memory usage exceeds bytesSoftLimit
// and set the original action as its fallback.
func (t *Tracker) FallbackOldAndSetNewActionForSoftLimit(a ActionOnExceed) {
t.actionMuForSoftLimit.Lock()
defer t.actionMuForSoftLimit.Unlock()
t.actionMuForSoftLimit.actionOnExceed = reArrangeFallback(t.actionMuForSoftLimit.actionOnExceed, a)
t.actionMuForSoftLimit.actionOnExceed = reArrangeFallback(a, t.actionMuForSoftLimit.actionOnExceed)
}

// GetFallbackForTest get the oom action used by test.
Expand Down

0 comments on commit a1359a6

Please sign in to comment.