Skip to content

Commit dbaf3df

Browse files
fix TestAppend2 (#21831)
fix TestAppend2, not GC Approved by: @XuPeng-SH
1 parent 0fe4011 commit dbaf3df

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

pkg/vm/engine/tae/catalog/table_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package catalog
1717
import (
1818
"testing"
1919

20+
"github.com/stretchr/testify/assert"
2021
"github.com/stretchr/testify/require"
2122

2223
"github.com/matrixorigin/matrixone/pkg/container/types"
@@ -95,3 +96,48 @@ func TestGetSoftdeleteObjects(t *testing.T) {
9596
objs = tbl.GetSoftdeleteObjects(types.BuildTS(1, 0), types.BuildTS(3, 0))
9697
require.Equal(t, 2, len(objs))
9798
}
99+
100+
func TestGetSoftdeleteObjects2(t *testing.T) {
101+
db := MockDBEntryWithAccInfo(0, 0)
102+
tbl := MockTableEntryWithDB(db, 1)
103+
104+
addActiveObject := func(create int64) *ObjectEntry {
105+
object := MockObjEntryWithTbl(tbl, 10, false)
106+
object.CreatedAt = types.BuildTS(create, 0)
107+
object.ObjectState = ObjectState_Create_ApplyCommit
108+
object.CreateNode = txnbase.TxnMVCCNode{
109+
Start: types.BuildTS(create-1, 0),
110+
Prepare: types.BuildTS(create, 0),
111+
End: types.BuildTS(create, 0),
112+
}
113+
tbl.dataObjects.modify(nil, object, nil)
114+
return object
115+
}
116+
117+
addSoftDeleteObject := func(create, delete int64) *ObjectEntry {
118+
createEntry := addActiveObject(create)
119+
dropEntry := createEntry.Clone()
120+
dropEntry.DeletedAt = types.BuildTS(delete, 0)
121+
dropEntry.ObjectState = ObjectState_Delete_ApplyCommit
122+
dropEntry.CreateNode = txnbase.TxnMVCCNode{
123+
Start: types.BuildTS(delete-1, 0),
124+
Prepare: types.BuildTS(delete, 0),
125+
End: types.BuildTS(delete, 0),
126+
}
127+
tbl.dataObjects.modify(nil, dropEntry, nil)
128+
return dropEntry
129+
}
130+
131+
addActiveObject(1)
132+
objs := tbl.GetSoftdeleteObjects(types.BuildTS(1, 0), types.BuildTS(2, 0))
133+
assert.Equal(t, 0, len(objs))
134+
addSoftDeleteObject(1, 2)
135+
objs = tbl.GetSoftdeleteObjects(types.BuildTS(1, 0), types.BuildTS(2, 0))
136+
assert.Equal(t, 1, len(objs))
137+
addSoftDeleteObject(1, 3)
138+
objs = tbl.GetSoftdeleteObjects(types.BuildTS(1, 0), types.BuildTS(3, 0))
139+
assert.Equal(t, 2, len(objs))
140+
addActiveObject(4)
141+
objs = tbl.GetSoftdeleteObjects(types.BuildTS(2, 0), types.BuildTS(5, 0))
142+
assert.Equal(t, 2, len(objs))
143+
}

pkg/vm/engine/tae/db/test/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func TestAppend2(t *testing.T) {
229229
testutils.EnsureNoLeak(t)
230230
ctx := context.Background()
231231

232-
opts := config.WithQuickScanAndCKPOpts(nil)
232+
opts := config.WithQuickScanCKPAndLongGCOpts(nil)
233233
db := testutil.NewTestEngine(ctx, ModuleName, t, opts)
234234
defer db.Close()
235235

pkg/vm/engine/tae/testutils/config/options.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ func WithQuickScanAndCKPOpts(
6565
return opts
6666
}
6767

68+
func WithQuickScanCKPAndLongGCOpts(
69+
in *options.Options,
70+
ops ...func(*options.Options),
71+
) (opts *options.Options) {
72+
if in == nil {
73+
opts = new(options.Options)
74+
} else {
75+
opts = in
76+
}
77+
opts.CheckpointCfg = new(options.CheckpointCfg)
78+
opts.CheckpointCfg.ScanInterval = time.Millisecond * 10
79+
opts.CheckpointCfg.FlushInterval = time.Millisecond * 10
80+
opts.CheckpointCfg.MinCount = 1
81+
opts.CheckpointCfg.IncrementalInterval = time.Millisecond * 20
82+
opts.CheckpointCfg.GlobalMinCount = 1
83+
opts.CheckpointCfg.GCCheckpointInterval = time.Millisecond * 10
84+
opts.CheckpointCfg.BlockRows = 10
85+
opts.CheckpointCfg.GlobalVersionInterval = time.Millisecond * 10
86+
opts.Ctx = context.Background()
87+
for _, op := range ops {
88+
op(opts)
89+
}
90+
return opts
91+
}
92+
6893
func WithQuickScanAndCKPAndGCOpts(
6994
in *options.Options,
7095
ops ...func(*options.Options),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2024 Matrix Origin
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
import (
18+
"testing"
19+
"time"
20+
21+
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/options"
22+
)
23+
24+
func TestWithQuickScanAndLongCKPOpts(t *testing.T) {
25+
opts := WithLongScanAndCKPOpts(nil)
26+
WithQuickScanCKPAndLongGCOpts(opts, options.WithCatalogGCInterval(time.Millisecond*10))
27+
}

0 commit comments

Comments
 (0)