2021-11-10 19:03:38 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package datacoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
2024-01-18 22:06:31 +08:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2024-03-21 11:15:20 +08:00
|
|
|
"os"
|
2021-11-10 19:03:38 +08:00
|
|
|
"path"
|
2022-05-31 16:36:03 +08:00
|
|
|
"strconv"
|
2021-11-10 19:03:38 +08:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2024-03-04 16:56:59 +08:00
|
|
|
"github.com/minio/minio-go/v7"
|
2023-01-06 14:33:36 +08:00
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-01-04 19:37:36 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2023-01-06 14:33:36 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-12-14 19:26:39 +08:00
|
|
|
"github.com/stretchr/testify/suite"
|
2023-01-04 19:37:36 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2024-08-28 10:11:05 +08:00
|
|
|
broker2 "github.com/milvus-io/milvus/internal/datacoord/broker"
|
2023-01-06 14:33:36 +08:00
|
|
|
kvmocks "github.com/milvus-io/milvus/internal/kv/mocks"
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore"
|
2023-01-04 19:37:36 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metastore/kv/datacoord"
|
2023-01-06 14:33:36 +08:00
|
|
|
catalogmocks "github.com/milvus-io/milvus/internal/metastore/mocks"
|
2023-01-04 19:37:36 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
2023-03-04 23:21:50 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mocks"
|
2021-11-10 19:03:38 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2024-09-02 14:19:03 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/workerpb"
|
2022-07-22 22:10:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
2024-05-15 16:33:34 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/lock"
|
2024-04-25 20:41:27 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-09-05 10:31:48 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2021-11-10 19:03:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_garbageCollector_basic(t *testing.T) {
|
|
|
|
bucketName := `datacoord-ut` + strings.ToLower(funcutil.RandomString(8))
|
|
|
|
rootPath := `gc` + funcutil.RandomString(8)
|
2023-09-21 09:45:27 +08:00
|
|
|
// TODO change to Params
|
2021-11-24 09:55:15 +08:00
|
|
|
cli, _, _, _, _, err := initUtOSSEnv(bucketName, rootPath, 0)
|
2021-11-10 19:03:38 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-03 14:41:35 +08:00
|
|
|
meta, err := newMemoryMeta()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-10 19:03:38 +08:00
|
|
|
|
|
|
|
t.Run("normal gc", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
gc.start()
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 20)
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with nil cli", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: nil,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
gc.start()
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
})
|
2023-04-12 19:38:28 +08:00
|
|
|
}
|
2021-11-10 19:03:38 +08:00
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
func validateMinioPrefixElements(t *testing.T, manager *storage.RemoteChunkManager, bucketName string, prefix string, elements []string) {
|
|
|
|
cli := manager.UnderlyingObjectStorage().(*storage.MinioObjectStorage).Client
|
2021-11-24 09:55:15 +08:00
|
|
|
var current []string
|
|
|
|
for info := range cli.ListObjects(context.TODO(), bucketName, minio.ListObjectsOptions{Prefix: prefix, Recursive: true}) {
|
|
|
|
current = append(current, info.Key)
|
|
|
|
}
|
|
|
|
assert.ElementsMatch(t, elements, current)
|
|
|
|
}
|
|
|
|
|
2021-11-10 19:03:38 +08:00
|
|
|
func Test_garbageCollector_scan(t *testing.T) {
|
|
|
|
bucketName := `datacoord-ut` + strings.ToLower(funcutil.RandomString(8))
|
2024-01-18 22:06:31 +08:00
|
|
|
rootPath := paramtable.Get().MinioCfg.RootPath.GetValue()
|
2023-09-21 09:45:27 +08:00
|
|
|
// TODO change to Params
|
2021-11-24 09:55:15 +08:00
|
|
|
cli, inserts, stats, delta, others, err := initUtOSSEnv(bucketName, rootPath, 4)
|
2021-11-10 19:03:38 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-03 14:41:35 +08:00
|
|
|
meta, err := newMemoryMeta()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-10 19:03:38 +08:00
|
|
|
|
2022-05-31 16:36:03 +08:00
|
|
|
t.Run("key is reference", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2022-05-31 16:36:03 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2022-05-31 16:36:03 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedBinlogFiles(context.TODO())
|
2022-05-31 16:36:03 +08:00
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2022-05-31 16:36:03 +08:00
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
|
2021-11-10 19:03:38 +08:00
|
|
|
t.Run("missing all but save tolerance", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedBinlogFiles(context.TODO())
|
2021-11-10 19:03:38 +08:00
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2021-11-24 09:55:15 +08:00
|
|
|
|
|
|
|
gc.close()
|
2021-11-10 19:03:38 +08:00
|
|
|
})
|
2021-11-16 14:23:21 +08:00
|
|
|
t.Run("hit, no gc", func(t *testing.T) {
|
2024-03-22 15:29:09 +08:00
|
|
|
segment := buildSegment(1, 10, 100, "ch")
|
2021-11-10 19:03:38 +08:00
|
|
|
segment.State = commonpb.SegmentState_Flushed
|
2021-12-19 20:00:42 +08:00
|
|
|
segment.Binlogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, inserts[0])}
|
|
|
|
segment.Statslogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, stats[0])}
|
|
|
|
segment.Deltalogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, delta[0])}
|
2023-09-18 09:53:22 +08:00
|
|
|
err = meta.AddSegment(context.TODO(), segment)
|
2021-11-10 19:03:38 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
gc.start()
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedBinlogFiles(context.TODO())
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta)
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2021-11-10 19:03:38 +08:00
|
|
|
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dropped gc one", func(t *testing.T) {
|
2024-03-22 15:29:09 +08:00
|
|
|
segment := buildSegment(1, 10, 100, "ch")
|
2021-11-10 19:03:38 +08:00
|
|
|
segment.State = commonpb.SegmentState_Dropped
|
2021-11-16 14:23:21 +08:00
|
|
|
segment.DroppedAt = uint64(time.Now().Add(-time.Hour).UnixNano())
|
2021-12-19 20:00:42 +08:00
|
|
|
segment.Binlogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, inserts[0])}
|
|
|
|
segment.Statslogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, stats[0])}
|
|
|
|
segment.Deltalogs = []*datapb.FieldBinlog{getFieldBinlogPaths(0, delta[0])}
|
|
|
|
|
2023-09-18 09:53:22 +08:00
|
|
|
err = meta.AddSegment(context.TODO(), segment)
|
2021-11-10 19:03:38 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: 0,
|
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleDroppedSegments(context.TODO())
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts[1:])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats[1:])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta[1:])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2021-11-10 19:03:38 +08:00
|
|
|
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
t.Run("missing gc all", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2021-11-10 19:03:38 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2021-11-10 19:03:38 +08:00
|
|
|
missingTolerance: 0,
|
|
|
|
dropTolerance: 0,
|
|
|
|
})
|
|
|
|
gc.start()
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedBinlogFiles(context.TODO())
|
|
|
|
gc.recycleDroppedSegments(context.TODO())
|
2022-09-26 18:06:54 +08:00
|
|
|
|
|
|
|
// bad path shall remains since datacoord cannot determine file is garbage or not if path is not valid
|
2024-04-25 20:41:27 +08:00
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2022-09-26 18:06:54 +08:00
|
|
|
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list object with error", func(t *testing.T) {
|
2023-01-04 19:37:36 +08:00
|
|
|
gc := newGarbageCollector(meta, newMockHandler(), GcOption{
|
2022-09-26 18:06:54 +08:00
|
|
|
cli: cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Minute * 30,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2022-09-26 18:06:54 +08:00
|
|
|
missingTolerance: 0,
|
|
|
|
dropTolerance: 0,
|
|
|
|
})
|
|
|
|
gc.start()
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedBinlogFiles(context.TODO())
|
2022-09-26 18:06:54 +08:00
|
|
|
|
2022-07-26 19:32:30 +08:00
|
|
|
// bad path shall remains since datacoord cannot determine file is garbage or not if path is not valid
|
2024-04-25 20:41:27 +08:00
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentInsertLogPath), inserts[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentStatslogPath), stats[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, common.SegmentDeltaLogPath), delta[1:2])
|
|
|
|
validateMinioPrefixElements(t, cli, bucketName, path.Join(rootPath, `indexes`), others)
|
2021-11-10 19:03:38 +08:00
|
|
|
|
|
|
|
gc.close()
|
|
|
|
})
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
cleanupOSS(cli, bucketName, rootPath)
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialize unit test sso env
|
2024-04-25 20:41:27 +08:00
|
|
|
func initUtOSSEnv(bucket, root string, n int) (mcm *storage.RemoteChunkManager, inserts []string, stats []string, delta []string, other []string, err error) {
|
2023-09-05 10:31:48 +08:00
|
|
|
paramtable.Init()
|
2024-03-21 11:15:20 +08:00
|
|
|
|
|
|
|
if Params.MinioCfg.UseSSL.GetAsBool() && len(Params.MinioCfg.SslCACert.GetValue()) > 0 {
|
|
|
|
err := os.Setenv("SSL_CERT_FILE", Params.MinioCfg.SslCACert.GetValue())
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
cli, err := minio.New(Params.MinioCfg.Address.GetValue(), &minio.Options{
|
|
|
|
Creds: credentials.NewStaticV4(Params.MinioCfg.AccessKeyID.GetValue(), Params.MinioCfg.SecretAccessKey.GetValue(), ""),
|
|
|
|
Secure: Params.MinioCfg.UseSSL.GetAsBool(),
|
2021-11-10 19:03:38 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-24 09:55:15 +08:00
|
|
|
return nil, nil, nil, nil, nil, err
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
|
|
|
has, err := cli.BucketExists(context.TODO(), bucket)
|
|
|
|
if err != nil {
|
2021-11-24 09:55:15 +08:00
|
|
|
return nil, nil, nil, nil, nil, err
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
|
|
|
if !has {
|
|
|
|
err = cli.MakeBucket(context.TODO(), bucket, minio.MakeBucketOptions{})
|
|
|
|
if err != nil {
|
2021-11-24 09:55:15 +08:00
|
|
|
return nil, nil, nil, nil, nil, err
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-24 09:55:15 +08:00
|
|
|
inserts = make([]string, 0, n)
|
|
|
|
stats = make([]string, 0, n)
|
|
|
|
delta = make([]string, 0, n)
|
|
|
|
other = make([]string, 0, n)
|
|
|
|
|
2021-11-10 19:03:38 +08:00
|
|
|
content := []byte("test")
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
reader := bytes.NewReader(content)
|
2022-07-26 19:32:30 +08:00
|
|
|
// collID/partID/segID/fieldID/fileName
|
|
|
|
// [str]/id/id/string/string
|
2022-09-30 14:18:55 +08:00
|
|
|
|
|
|
|
var token string
|
2022-05-31 16:36:03 +08:00
|
|
|
if i == 1 {
|
2024-01-18 22:06:31 +08:00
|
|
|
token = path.Join(strconv.Itoa(i), strconv.Itoa(i), "error-seg-id", strconv.Itoa(i), fmt.Sprint(rand.Int63()))
|
2022-09-30 14:18:55 +08:00
|
|
|
} else {
|
2024-01-18 22:06:31 +08:00
|
|
|
token = path.Join(strconv.Itoa(1+i), strconv.Itoa(10+i), strconv.Itoa(100+i), strconv.Itoa(i), fmt.Sprint(rand.Int63()))
|
2022-05-31 16:36:03 +08:00
|
|
|
}
|
2021-11-24 09:55:15 +08:00
|
|
|
// insert
|
2023-09-19 10:01:23 +08:00
|
|
|
filePath := path.Join(root, common.SegmentInsertLogPath, token)
|
2021-11-24 09:55:15 +08:00
|
|
|
info, err := cli.PutObject(context.TODO(), bucket, filePath, reader, int64(len(content)), minio.PutObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
inserts = append(inserts, info.Key)
|
|
|
|
// stats
|
2023-09-19 10:01:23 +08:00
|
|
|
filePath = path.Join(root, common.SegmentStatslogPath, token)
|
2021-11-24 09:55:15 +08:00
|
|
|
info, err = cli.PutObject(context.TODO(), bucket, filePath, reader, int64(len(content)), minio.PutObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
stats = append(stats, info.Key)
|
|
|
|
|
|
|
|
// delta
|
2022-09-30 14:18:55 +08:00
|
|
|
if i == 1 {
|
2024-01-18 22:06:31 +08:00
|
|
|
token = path.Join(strconv.Itoa(i), strconv.Itoa(i), "error-seg-id", fmt.Sprint(rand.Int63()))
|
2022-09-30 14:18:55 +08:00
|
|
|
} else {
|
2024-01-18 22:06:31 +08:00
|
|
|
token = path.Join(strconv.Itoa(1+i), strconv.Itoa(10+i), strconv.Itoa(100+i), fmt.Sprint(rand.Int63()))
|
2022-09-30 14:18:55 +08:00
|
|
|
}
|
2023-09-19 10:01:23 +08:00
|
|
|
filePath = path.Join(root, common.SegmentDeltaLogPath, token)
|
2021-11-24 09:55:15 +08:00
|
|
|
info, err = cli.PutObject(context.TODO(), bucket, filePath, reader, int64(len(content)), minio.PutObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
delta = append(delta, info.Key)
|
|
|
|
|
|
|
|
// other
|
|
|
|
filePath = path.Join(root, `indexes`, token)
|
|
|
|
info, err = cli.PutObject(context.TODO(), bucket, filePath, reader, int64(len(content)), minio.PutObjectOptions{})
|
2021-11-10 19:03:38 +08:00
|
|
|
if err != nil {
|
2021-11-24 09:55:15 +08:00
|
|
|
return nil, nil, nil, nil, nil, err
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
2021-11-24 09:55:15 +08:00
|
|
|
other = append(other, info.Key)
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
2024-04-25 20:41:27 +08:00
|
|
|
mcm = storage.NewRemoteChunkManagerForTesting(
|
|
|
|
cli,
|
|
|
|
bucket,
|
|
|
|
root,
|
|
|
|
)
|
2022-07-22 22:10:28 +08:00
|
|
|
return mcm, inserts, stats, delta, other, nil
|
2021-11-10 19:03:38 +08:00
|
|
|
}
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
func cleanupOSS(chunkManager *storage.RemoteChunkManager, bucket, root string) {
|
|
|
|
cli := chunkManager.UnderlyingObjectStorage().(*storage.MinioObjectStorage).Client
|
2021-11-10 19:03:38 +08:00
|
|
|
ch := cli.ListObjects(context.TODO(), bucket, minio.ListObjectsOptions{Prefix: root, Recursive: true})
|
|
|
|
cli.RemoveObjects(context.TODO(), bucket, ch, minio.RemoveObjectsOptions{})
|
|
|
|
cli.RemoveBucket(context.TODO(), bucket)
|
|
|
|
}
|
2023-01-04 19:37:36 +08:00
|
|
|
|
2023-01-06 14:33:36 +08:00
|
|
|
func createMetaForRecycleUnusedIndexes(catalog metastore.DataCoordCatalog) *meta {
|
2023-01-04 19:37:36 +08:00
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
collID = UniqueID(100)
|
2023-09-21 09:45:27 +08:00
|
|
|
// partID = UniqueID(200)
|
2023-01-04 19:37:36 +08:00
|
|
|
fieldID = UniqueID(300)
|
|
|
|
indexID = UniqueID(400)
|
|
|
|
)
|
|
|
|
return &meta{
|
2024-05-15 16:33:34 +08:00
|
|
|
RWMutex: lock.RWMutex{},
|
2023-01-04 19:37:36 +08:00
|
|
|
ctx: ctx,
|
|
|
|
catalog: catalog,
|
|
|
|
collections: nil,
|
|
|
|
segments: nil,
|
2024-03-07 20:39:02 +08:00
|
|
|
channelCPs: newChannelCps(),
|
2023-01-04 19:37:36 +08:00
|
|
|
chunkManager: nil,
|
2024-03-04 16:56:59 +08:00
|
|
|
indexMeta: &indexMeta{
|
|
|
|
catalog: catalog,
|
|
|
|
indexes: map[UniqueID]map[UniqueID]*model.Index{
|
|
|
|
collID: {
|
|
|
|
indexID: {
|
|
|
|
TenantID: "",
|
|
|
|
CollectionID: collID,
|
|
|
|
FieldID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
IndexName: "_default_idx",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
IsAutoIndex: false,
|
|
|
|
UserIndexParams: nil,
|
|
|
|
},
|
|
|
|
indexID + 1: {
|
|
|
|
TenantID: "",
|
|
|
|
CollectionID: collID,
|
|
|
|
FieldID: fieldID + 1,
|
|
|
|
IndexID: indexID + 1,
|
|
|
|
IndexName: "_default_idx_101",
|
|
|
|
IsDeleted: true,
|
|
|
|
CreateTime: 0,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
IsAutoIndex: false,
|
|
|
|
UserIndexParams: nil,
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-03-04 16:56:59 +08:00
|
|
|
collID + 1: {
|
|
|
|
indexID + 10: {
|
|
|
|
TenantID: "",
|
|
|
|
CollectionID: collID + 1,
|
|
|
|
FieldID: fieldID + 10,
|
|
|
|
IndexID: indexID + 10,
|
|
|
|
IndexName: "index",
|
|
|
|
IsDeleted: true,
|
|
|
|
CreateTime: 10,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
IsAutoIndex: false,
|
|
|
|
UserIndexParams: nil,
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
2024-10-28 10:13:29 +08:00
|
|
|
segmentBuildInfo: newSegmentIndexBuildInfo(),
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGarbageCollector_recycleUnusedIndexes(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
|
|
|
catalog.On("DropIndex",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil)
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(createMetaForRecycleUnusedIndexes(catalog), nil, GcOption{})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexes(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("fail", func(t *testing.T) {
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
|
|
|
catalog.On("DropIndex",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(errors.New("fail"))
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(createMetaForRecycleUnusedIndexes(catalog), nil, GcOption{})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexes(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-06 14:33:36 +08:00
|
|
|
func createMetaForRecycleUnusedSegIndexes(catalog metastore.DataCoordCatalog) *meta {
|
2023-01-04 19:37:36 +08:00
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
collID = UniqueID(100)
|
|
|
|
partID = UniqueID(200)
|
2023-09-21 09:45:27 +08:00
|
|
|
// fieldID = UniqueID(300)
|
2023-01-04 19:37:36 +08:00
|
|
|
indexID = UniqueID(400)
|
|
|
|
segID = UniqueID(500)
|
|
|
|
)
|
2024-05-08 21:37:29 +08:00
|
|
|
segments := map[int64]*SegmentInfo{
|
|
|
|
segID: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "",
|
|
|
|
NumOfRows: 1026,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
2024-05-28 19:17:43 +08:00
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "",
|
|
|
|
NumOfRows: 1026,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
meta := &meta{
|
2024-05-15 16:33:34 +08:00
|
|
|
RWMutex: lock.RWMutex{},
|
2023-01-04 19:37:36 +08:00
|
|
|
ctx: ctx,
|
|
|
|
catalog: catalog,
|
|
|
|
collections: nil,
|
2024-05-08 21:37:29 +08:00
|
|
|
segments: NewSegmentsInfo(),
|
2024-03-04 16:56:59 +08:00
|
|
|
indexMeta: &indexMeta{
|
|
|
|
catalog: catalog,
|
|
|
|
segmentIndexes: map[UniqueID]map[UniqueID]*model.SegmentIndex{
|
|
|
|
segID: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-10-28 10:13:29 +08:00
|
|
|
indexes: map[UniqueID]map[UniqueID]*model.Index{},
|
|
|
|
segmentBuildInfo: newSegmentIndexBuildInfo(),
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-03-04 16:56:59 +08:00
|
|
|
channelCPs: nil,
|
|
|
|
chunkManager: nil,
|
2023-01-04 19:37:36 +08:00
|
|
|
}
|
2024-10-28 10:13:29 +08:00
|
|
|
|
|
|
|
meta.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
meta.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
})
|
|
|
|
|
2024-05-08 21:37:29 +08:00
|
|
|
for id, segment := range segments {
|
|
|
|
meta.segments.SetSegment(id, segment)
|
|
|
|
}
|
|
|
|
return meta
|
2023-01-04 19:37:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGarbageCollector_recycleUnusedSegIndexes(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
2024-04-25 20:41:27 +08:00
|
|
|
mockChunkManager := mocks.NewChunkManager(t)
|
|
|
|
mockChunkManager.EXPECT().RootPath().Return("root")
|
|
|
|
mockChunkManager.EXPECT().Remove(mock.Anything, mock.Anything).Return(nil)
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
|
|
|
catalog.On("DropSegmentIndex",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil)
|
2024-04-25 20:41:27 +08:00
|
|
|
gc := newGarbageCollector(createMetaForRecycleUnusedSegIndexes(catalog), nil, GcOption{
|
|
|
|
cli: mockChunkManager,
|
|
|
|
})
|
|
|
|
gc.recycleUnusedSegIndexes(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("fail", func(t *testing.T) {
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
2024-04-25 20:41:27 +08:00
|
|
|
mockChunkManager := mocks.NewChunkManager(t)
|
|
|
|
mockChunkManager.EXPECT().RootPath().Return("root")
|
|
|
|
mockChunkManager.EXPECT().Remove(mock.Anything, mock.Anything).Return(nil)
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog.On("DropSegmentIndex",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(errors.New("fail"))
|
2024-04-25 20:41:27 +08:00
|
|
|
gc := newGarbageCollector(createMetaForRecycleUnusedSegIndexes(catalog), nil, GcOption{
|
|
|
|
cli: mockChunkManager,
|
|
|
|
})
|
|
|
|
gc.recycleUnusedSegIndexes(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func createMetaTableForRecycleUnusedIndexFiles(catalog *datacoord.Catalog) *meta {
|
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
collID = UniqueID(100)
|
|
|
|
partID = UniqueID(200)
|
2023-09-21 09:45:27 +08:00
|
|
|
// fieldID = UniqueID(300)
|
2023-01-04 19:37:36 +08:00
|
|
|
indexID = UniqueID(400)
|
|
|
|
segID = UniqueID(500)
|
|
|
|
buildID = UniqueID(600)
|
|
|
|
)
|
2024-05-08 21:37:29 +08:00
|
|
|
segments := map[UniqueID]*SegmentInfo{
|
|
|
|
segID: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "",
|
|
|
|
NumOfRows: 1026,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "",
|
|
|
|
NumOfRows: 1026,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
meta := &meta{
|
2024-05-15 16:33:34 +08:00
|
|
|
RWMutex: lock.RWMutex{},
|
2023-01-04 19:37:36 +08:00
|
|
|
ctx: ctx,
|
|
|
|
catalog: catalog,
|
|
|
|
collections: nil,
|
2024-05-08 21:37:29 +08:00
|
|
|
segments: NewSegmentsInfo(),
|
2024-03-04 16:56:59 +08:00
|
|
|
indexMeta: &indexMeta{
|
|
|
|
catalog: catalog,
|
|
|
|
segmentIndexes: map[UniqueID]map[UniqueID]*model.SegmentIndex{
|
|
|
|
segID: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_InProgress,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: nil,
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
2024-03-04 16:56:59 +08:00
|
|
|
indexes: map[UniqueID]map[UniqueID]*model.Index{
|
|
|
|
collID: {
|
|
|
|
indexID: {
|
|
|
|
TenantID: "",
|
|
|
|
CollectionID: collID,
|
|
|
|
FieldID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
IndexName: "_default_idx",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
IsAutoIndex: false,
|
|
|
|
UserIndexParams: nil,
|
|
|
|
},
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-10-28 10:13:29 +08:00
|
|
|
segmentBuildInfo: newSegmentIndexBuildInfo(),
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
}
|
2024-10-28 10:13:29 +08:00
|
|
|
meta.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
})
|
|
|
|
meta.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 1026,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 1,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_InProgress,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 10,
|
|
|
|
IndexFileKeys: nil,
|
|
|
|
IndexSize: 0,
|
|
|
|
WriteHandoff: false,
|
|
|
|
})
|
2024-05-08 21:37:29 +08:00
|
|
|
for id, segment := range segments {
|
|
|
|
meta.segments.SetSegment(id, segment)
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta
|
2023-01-04 19:37:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGarbageCollector_recycleUnusedIndexFiles(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
cm := &mocks.ChunkManager{}
|
|
|
|
cm.EXPECT().RootPath().Return("root")
|
2024-04-25 20:41:27 +08:00
|
|
|
cm.EXPECT().WalkWithPrefix(mock.Anything, mock.Anything, mock.Anything, mock.Anything).RunAndReturn(
|
|
|
|
func(ctx context.Context, s string, b bool, cowf storage.ChunkObjectWalkFunc) error {
|
|
|
|
for _, file := range []string{"a/b/c/", "a/b/600/", "a/b/601/", "a/b/602/"} {
|
|
|
|
cowf(&storage.ChunkObjectInfo{FilePath: file})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
cm.EXPECT().RemoveWithPrefix(mock.Anything, mock.Anything).Return(nil)
|
|
|
|
cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(nil)
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
createMetaTableForRecycleUnusedIndexFiles(&datacoord.Catalog{MetaKv: kvmocks.NewMetaKv(t)}),
|
|
|
|
nil,
|
|
|
|
GcOption{
|
2023-01-04 19:37:36 +08:00
|
|
|
cli: cm,
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexFiles(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list fail", func(t *testing.T) {
|
|
|
|
cm := &mocks.ChunkManager{}
|
|
|
|
cm.EXPECT().RootPath().Return("root")
|
2024-04-25 20:41:27 +08:00
|
|
|
cm.EXPECT().WalkWithPrefix(mock.Anything, mock.Anything, mock.Anything, mock.Anything).RunAndReturn(
|
|
|
|
func(ctx context.Context, s string, b bool, cowf storage.ChunkObjectWalkFunc) error {
|
|
|
|
return errors.New("error")
|
|
|
|
})
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
createMetaTableForRecycleUnusedIndexFiles(&datacoord.Catalog{MetaKv: kvmocks.NewMetaKv(t)}),
|
|
|
|
nil,
|
|
|
|
GcOption{
|
2023-01-04 19:37:36 +08:00
|
|
|
cli: cm,
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexFiles(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("remove fail", func(t *testing.T) {
|
|
|
|
cm := &mocks.ChunkManager{}
|
|
|
|
cm.EXPECT().RootPath().Return("root")
|
|
|
|
cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(errors.New("error"))
|
2024-04-25 20:41:27 +08:00
|
|
|
cm.EXPECT().WalkWithPrefix(mock.Anything, mock.Anything, mock.Anything, mock.Anything).RunAndReturn(
|
|
|
|
func(ctx context.Context, s string, b bool, cowf storage.ChunkObjectWalkFunc) error {
|
|
|
|
for _, file := range []string{"a/b/c/", "a/b/600/", "a/b/601/", "a/b/602/"} {
|
|
|
|
cowf(&storage.ChunkObjectInfo{FilePath: file})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2023-01-04 19:37:36 +08:00
|
|
|
cm.EXPECT().RemoveWithPrefix(mock.Anything, mock.Anything).Return(nil)
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
createMetaTableForRecycleUnusedIndexFiles(&datacoord.Catalog{MetaKv: kvmocks.NewMetaKv(t)}),
|
|
|
|
nil,
|
|
|
|
GcOption{
|
2023-01-04 19:37:36 +08:00
|
|
|
cli: cm,
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexFiles(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("remove with prefix fail", func(t *testing.T) {
|
|
|
|
cm := &mocks.ChunkManager{}
|
|
|
|
cm.EXPECT().RootPath().Return("root")
|
|
|
|
cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(errors.New("error"))
|
2024-04-25 20:41:27 +08:00
|
|
|
cm.EXPECT().WalkWithPrefix(mock.Anything, mock.Anything, mock.Anything, mock.Anything).RunAndReturn(
|
|
|
|
func(ctx context.Context, s string, b bool, cowf storage.ChunkObjectWalkFunc) error {
|
|
|
|
for _, file := range []string{"a/b/c/", "a/b/600/", "a/b/601/", "a/b/602/"} {
|
|
|
|
cowf(&storage.ChunkObjectInfo{FilePath: file})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2023-01-04 19:37:36 +08:00
|
|
|
cm.EXPECT().RemoveWithPrefix(mock.Anything, mock.Anything).Return(errors.New("error"))
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
createMetaTableForRecycleUnusedIndexFiles(&datacoord.Catalog{MetaKv: kvmocks.NewMetaKv(t)}),
|
|
|
|
nil,
|
|
|
|
GcOption{
|
2023-01-04 19:37:36 +08:00
|
|
|
cli: cm,
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleUnusedIndexFiles(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGarbageCollector_clearETCD(t *testing.T) {
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
2023-03-09 14:13:52 +08:00
|
|
|
catalog.On("ChannelExists",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
2023-08-09 19:39:15 +08:00
|
|
|
).Return(true)
|
2023-03-09 14:13:52 +08:00
|
|
|
catalog.On("DropChannelCheckpoint",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
2023-08-09 19:39:15 +08:00
|
|
|
).Return(nil).Maybe()
|
2023-01-06 14:33:36 +08:00
|
|
|
catalog.On("CreateSegmentIndex",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil)
|
|
|
|
catalog.On("AlterSegmentIndexes",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil)
|
|
|
|
catalog.On("DropSegment",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil)
|
|
|
|
|
2024-03-07 20:39:02 +08:00
|
|
|
channelCPs := newChannelCps()
|
|
|
|
channelCPs.checkpoints["dmlChannel"] = &msgpb.MsgPosition{
|
|
|
|
Timestamp: 1000,
|
|
|
|
}
|
|
|
|
|
2024-05-08 21:37:29 +08:00
|
|
|
segments := map[UniqueID]*SegmentInfo{
|
|
|
|
segID: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 5000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 0,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
Binlogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
2024-01-03 13:16:57 +08:00
|
|
|
{
|
2024-05-08 21:37:29 +08:00
|
|
|
LogPath: "log1",
|
|
|
|
LogSize: 1024,
|
2024-01-03 13:16:57 +08:00
|
|
|
},
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 2,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
2024-01-03 13:16:57 +08:00
|
|
|
{
|
2024-05-08 21:37:29 +08:00
|
|
|
LogPath: "log2",
|
|
|
|
LogSize: 1024,
|
2024-01-03 13:16:57 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Deltalogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
2024-01-03 13:16:57 +08:00
|
|
|
{
|
2024-05-08 21:37:29 +08:00
|
|
|
LogPath: "del_log1",
|
|
|
|
LogSize: 1024,
|
2024-01-03 13:16:57 +08:00
|
|
|
},
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 2,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
2024-01-03 13:16:57 +08:00
|
|
|
{
|
2024-05-08 21:37:29 +08:00
|
|
|
LogPath: "del_log2",
|
|
|
|
LogSize: 1024,
|
2024-01-03 13:16:57 +08:00
|
|
|
},
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
Statslogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "stats_log1",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
2023-08-09 19:39:15 +08:00
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 5000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 0,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 2: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 2,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 10000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
CompactionFrom: []int64{segID, segID + 1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 3: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 3,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
CompactionFrom: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 4: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 4,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 12000,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
2023-01-06 21:33:36 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
CompactionFrom: []int64{segID + 2, segID + 3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 5: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 5,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: 0,
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 1200,
|
2023-08-09 19:39:15 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 6: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 6,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: uint64(time.Now().Add(time.Hour).UnixNano()),
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
2023-08-09 19:39:15 +08:00
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
Compacted: true,
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
2024-05-08 21:37:29 +08:00
|
|
|
// compacted and child is GCed, dml pos is big than channel cp
|
|
|
|
segID + 7: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 7,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: 0,
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 1200,
|
|
|
|
},
|
|
|
|
Compacted: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
m := &meta{
|
|
|
|
catalog: catalog,
|
|
|
|
channelCPs: channelCPs,
|
|
|
|
segments: NewSegmentsInfo(),
|
2024-03-04 16:56:59 +08:00
|
|
|
indexMeta: &indexMeta{
|
|
|
|
catalog: catalog,
|
|
|
|
segmentIndexes: map[UniqueID]map[UniqueID]*model.SegmentIndex{
|
|
|
|
segID: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 5000,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 0,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 0,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 1024,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
indexID: {
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 5000,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 0,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 0,
|
|
|
|
IndexFileKeys: []string{"file3", "file4"},
|
|
|
|
IndexSize: 1024,
|
|
|
|
WriteHandoff: false,
|
|
|
|
},
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
2024-10-28 10:13:29 +08:00
|
|
|
segmentBuildInfo: newSegmentIndexBuildInfo(),
|
2024-03-04 16:56:59 +08:00
|
|
|
indexes: map[UniqueID]map[UniqueID]*model.Index{
|
|
|
|
collID: {
|
|
|
|
indexID: {
|
|
|
|
TenantID: "",
|
|
|
|
CollectionID: collID,
|
|
|
|
FieldID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
IndexName: indexName,
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 0,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
IsAutoIndex: false,
|
|
|
|
UserIndexParams: nil,
|
|
|
|
},
|
2023-01-04 19:37:36 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-04 16:56:59 +08:00
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
collections: map[UniqueID]*collectionInfo{
|
|
|
|
collID: {
|
|
|
|
ID: collID,
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "",
|
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: fieldID,
|
|
|
|
Name: "",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "",
|
|
|
|
DataType: schemapb.DataType_FloatVector,
|
|
|
|
TypeParams: nil,
|
|
|
|
IndexParams: nil,
|
|
|
|
AutoID: false,
|
|
|
|
State: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Partitions: nil,
|
|
|
|
StartPositions: nil,
|
|
|
|
Properties: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-03-05 10:04:59 +08:00
|
|
|
|
2024-10-28 10:13:29 +08:00
|
|
|
m.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 5000,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
NodeID: 0,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 0,
|
|
|
|
IndexFileKeys: []string{"file1", "file2"},
|
|
|
|
IndexSize: 1024,
|
|
|
|
WriteHandoff: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
m.indexMeta.segmentBuildInfo.Add(&model.SegmentIndex{
|
|
|
|
SegmentID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 5000,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 1,
|
|
|
|
NodeID: 0,
|
|
|
|
IndexVersion: 1,
|
|
|
|
IndexState: commonpb.IndexState_Finished,
|
|
|
|
FailReason: "",
|
|
|
|
IsDeleted: false,
|
|
|
|
CreateTime: 0,
|
|
|
|
IndexFileKeys: []string{"file3", "file4"},
|
|
|
|
IndexSize: 1024,
|
|
|
|
WriteHandoff: false,
|
|
|
|
})
|
|
|
|
|
2024-05-08 21:37:29 +08:00
|
|
|
for id, segment := range segments {
|
|
|
|
m.segments.SetSegment(id, segment)
|
|
|
|
}
|
|
|
|
|
2024-03-05 10:04:59 +08:00
|
|
|
for segID, segment := range map[UniqueID]*SegmentInfo{
|
|
|
|
segID: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 5000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 0,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
Binlogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "log1",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 2,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "log2",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Deltalogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "del_log1",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 2,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "del_log2",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Statslogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: "stats_log1",
|
|
|
|
LogSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 1: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 1,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 5000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 0,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 2: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 2,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 10000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
CompactionFrom: []int64{segID, segID + 1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 3: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 3,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
CompactionFrom: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 4: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 4,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 12000,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
|
|
|
MaxRowNum: 65536,
|
|
|
|
DroppedAt: 10,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
CompactionFrom: []int64{segID + 2, segID + 3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
segID + 5: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 5,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: 0,
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 1200,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-06 20:29:30 +08:00
|
|
|
// cannot dropped for not expired.
|
2024-03-05 10:04:59 +08:00
|
|
|
segID + 6: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 6,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: uint64(time.Now().Add(time.Hour).UnixNano()),
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
Compacted: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// compacted and child is GCed, dml pos is big than channel cp
|
|
|
|
segID + 7: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 7,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: 0,
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 1200,
|
|
|
|
},
|
|
|
|
Compacted: true,
|
|
|
|
},
|
|
|
|
},
|
2024-05-06 20:29:30 +08:00
|
|
|
// can be dropped for expired and compacted
|
|
|
|
segID + 8: {
|
|
|
|
SegmentInfo: &datapb.SegmentInfo{
|
|
|
|
ID: segID + 8,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
InsertChannel: "dmlChannel",
|
|
|
|
NumOfRows: 2000,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
MaxRowNum: 65535,
|
|
|
|
DroppedAt: uint64(time.Now().Add(-7 * 24 * time.Hour).UnixNano()),
|
|
|
|
CompactionFrom: nil,
|
|
|
|
DmlPosition: &msgpb.MsgPosition{
|
|
|
|
Timestamp: 900,
|
|
|
|
},
|
|
|
|
Compacted: true,
|
|
|
|
},
|
|
|
|
},
|
2024-03-05 10:04:59 +08:00
|
|
|
} {
|
|
|
|
m.segments.SetSegment(segID, segment)
|
|
|
|
}
|
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
cm := &mocks.ChunkManager{}
|
|
|
|
cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(nil)
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
m,
|
|
|
|
newMockHandlerWithMeta(m),
|
|
|
|
GcOption{
|
|
|
|
cli: cm,
|
2023-01-04 19:37:36 +08:00
|
|
|
dropTolerance: 1,
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleDroppedSegments(context.TODO())
|
2023-01-04 19:37:36 +08:00
|
|
|
|
2023-08-09 19:39:15 +08:00
|
|
|
/*
|
|
|
|
A B
|
|
|
|
\ /
|
|
|
|
C D
|
|
|
|
\ /
|
|
|
|
E
|
|
|
|
|
|
|
|
E: flushed, not indexed, should not be GCed
|
|
|
|
D: dropped, not indexed, should not be GCed, since E is not GCed
|
|
|
|
C: dropped, not indexed, should not be GCed, since E is not GCed
|
|
|
|
A: dropped, indexed, should not be GCed, since C is not indexed
|
|
|
|
B: dropped, indexed, should not be GCed, since C is not indexed
|
|
|
|
|
|
|
|
F: dropped, compcated is false, should not be GCed, since dml position is larger than channel cp
|
|
|
|
G: dropped, compacted is true, missing child info, should be GCed since dml pos is less than channel cp, FAST GC do not wait drop tolerance
|
|
|
|
H: dropped, compacted is true, missing child info, should not be GCed since dml pos is larger than channel cp
|
|
|
|
|
|
|
|
conclusion: only G is GCed.
|
|
|
|
*/
|
2023-03-03 14:13:49 +08:00
|
|
|
segA := gc.meta.GetSegment(segID)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.NotNil(t, segA)
|
2023-03-03 14:13:49 +08:00
|
|
|
segB := gc.meta.GetSegment(segID + 1)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.NotNil(t, segB)
|
2023-03-03 14:13:49 +08:00
|
|
|
segC := gc.meta.GetSegment(segID + 2)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.NotNil(t, segC)
|
2023-03-03 14:13:49 +08:00
|
|
|
segD := gc.meta.GetSegment(segID + 3)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.NotNil(t, segD)
|
2023-03-03 14:13:49 +08:00
|
|
|
segE := gc.meta.GetSegment(segID + 4)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.NotNil(t, segE)
|
2023-03-03 14:13:49 +08:00
|
|
|
segF := gc.meta.GetSegment(segID + 5)
|
2023-08-09 19:39:15 +08:00
|
|
|
assert.NotNil(t, segF)
|
|
|
|
segG := gc.meta.GetSegment(segID + 6)
|
2024-05-06 20:29:30 +08:00
|
|
|
assert.NotNil(t, segG)
|
2023-08-09 19:39:15 +08:00
|
|
|
segH := gc.meta.GetSegment(segID + 7)
|
|
|
|
assert.NotNil(t, segH)
|
2024-05-06 20:29:30 +08:00
|
|
|
segG = gc.meta.GetSegment(segID + 8)
|
|
|
|
assert.Nil(t, segG)
|
2024-03-04 16:56:59 +08:00
|
|
|
err := gc.meta.indexMeta.AddSegmentIndex(&model.SegmentIndex{
|
2023-01-04 19:37:36 +08:00
|
|
|
SegmentID: segID + 4,
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
NumRows: 12000,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID + 4,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2024-09-02 14:19:03 +08:00
|
|
|
err = gc.meta.indexMeta.FinishTask(&workerpb.IndexTaskInfo{
|
2023-01-04 19:37:36 +08:00
|
|
|
BuildID: buildID + 4,
|
|
|
|
State: commonpb.IndexState_Finished,
|
|
|
|
IndexFileKeys: []string{"file1", "file2", "file3", "file4"},
|
|
|
|
SerializedSize: 10240,
|
|
|
|
FailReason: "",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleDroppedSegments(context.TODO())
|
2023-08-09 19:39:15 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
A: processed prior to C, C is not GCed yet and C is not indexed, A is not GCed in this turn
|
|
|
|
B: processed prior to C, C is not GCed yet and C is not indexed, B is not GCed in this turn
|
|
|
|
|
|
|
|
E: flushed, indexed, should not be GCed
|
|
|
|
C: dropped, not indexed, should be GCed since E is indexed
|
|
|
|
D: dropped, not indexed, should be GCed since E is indexed
|
|
|
|
*/
|
|
|
|
|
2023-03-03 14:13:49 +08:00
|
|
|
segC = gc.meta.GetSegment(segID + 2)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.Nil(t, segC)
|
2023-03-03 14:13:49 +08:00
|
|
|
segD = gc.meta.GetSegment(segID + 3)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.Nil(t, segD)
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
gc.recycleDroppedSegments(context.TODO())
|
2023-08-09 19:39:15 +08:00
|
|
|
/*
|
|
|
|
A: compacted became false due to C is GCed already, A should be GCed since dropTolernace is meet
|
|
|
|
B: compacted became false due to C is GCed already, B should be GCed since dropTolerance is meet
|
|
|
|
*/
|
2023-03-03 14:13:49 +08:00
|
|
|
segA = gc.meta.GetSegment(segID)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.Nil(t, segA)
|
2023-03-03 14:13:49 +08:00
|
|
|
segB = gc.meta.GetSegment(segID + 1)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.Nil(t, segB)
|
|
|
|
}
|
2023-12-14 19:26:39 +08:00
|
|
|
|
2024-07-11 23:01:35 +08:00
|
|
|
func TestGarbageCollector_recycleChannelMeta(t *testing.T) {
|
|
|
|
catalog := catalogmocks.NewDataCoordCatalog(t)
|
|
|
|
|
|
|
|
m := &meta{
|
|
|
|
catalog: catalog,
|
|
|
|
channelCPs: newChannelCps(),
|
|
|
|
}
|
|
|
|
|
|
|
|
m.channelCPs.checkpoints = map[string]*msgpb.MsgPosition{
|
|
|
|
"cluster-id-rootcoord-dm_0_123v0": nil,
|
2024-08-28 10:11:05 +08:00
|
|
|
"cluster-id-rootcoord-dm_1_123v0": nil,
|
2024-07-11 23:01:35 +08:00
|
|
|
"cluster-id-rootcoord-dm_0_124v0": nil,
|
|
|
|
}
|
|
|
|
|
2024-08-28 10:11:05 +08:00
|
|
|
broker := broker2.NewMockBroker(t)
|
|
|
|
broker.EXPECT().HasCollection(mock.Anything, mock.Anything).Return(true, nil).Twice()
|
|
|
|
|
|
|
|
gc := newGarbageCollector(m, newMockHandlerWithMeta(m), GcOption{broker: broker})
|
2024-07-11 23:01:35 +08:00
|
|
|
|
|
|
|
t.Run("list channel cp fail", func(t *testing.T) {
|
|
|
|
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Return(nil, errors.New("mock error")).Once()
|
|
|
|
gc.recycleChannelCPMeta(context.TODO())
|
2024-08-28 10:11:05 +08:00
|
|
|
assert.Equal(t, 3, len(m.channelCPs.checkpoints))
|
2024-07-11 23:01:35 +08:00
|
|
|
})
|
|
|
|
|
2024-08-28 10:11:05 +08:00
|
|
|
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Unset()
|
2024-07-11 23:01:35 +08:00
|
|
|
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Return(map[string]*msgpb.MsgPosition{
|
|
|
|
"cluster-id-rootcoord-dm_0_123v0": nil,
|
2024-08-28 10:11:05 +08:00
|
|
|
"cluster-id-rootcoord-dm_1_123v0": nil,
|
2024-07-11 23:01:35 +08:00
|
|
|
"cluster-id-rootcoord-dm_0_invalidedCollectionIDv0": nil,
|
|
|
|
"cluster-id-rootcoord-dm_0_124v0": nil,
|
2024-08-28 10:11:05 +08:00
|
|
|
}, nil).Times(3)
|
2024-07-11 23:01:35 +08:00
|
|
|
|
|
|
|
catalog.EXPECT().GcConfirm(mock.Anything, mock.Anything, mock.Anything).
|
|
|
|
RunAndReturn(func(ctx context.Context, collectionID int64, i2 int64) bool {
|
|
|
|
if collectionID == 123 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2024-08-28 10:11:05 +08:00
|
|
|
}).Maybe()
|
|
|
|
|
|
|
|
t.Run("skip drop channel due to collection is available", func(t *testing.T) {
|
|
|
|
gc.recycleChannelCPMeta(context.TODO())
|
|
|
|
assert.Equal(t, 3, len(m.channelCPs.checkpoints))
|
|
|
|
})
|
2024-07-11 23:01:35 +08:00
|
|
|
|
2024-08-28 10:11:05 +08:00
|
|
|
broker.EXPECT().HasCollection(mock.Anything, mock.Anything).Return(false, nil).Times(4)
|
2024-07-11 23:01:35 +08:00
|
|
|
t.Run("drop channel cp fail", func(t *testing.T) {
|
2024-08-28 10:11:05 +08:00
|
|
|
catalog.EXPECT().DropChannelCheckpoint(mock.Anything, mock.Anything).Return(errors.New("mock error")).Twice()
|
2024-07-11 23:01:35 +08:00
|
|
|
gc.recycleChannelCPMeta(context.TODO())
|
2024-08-28 10:11:05 +08:00
|
|
|
assert.Equal(t, 3, len(m.channelCPs.checkpoints))
|
2024-07-11 23:01:35 +08:00
|
|
|
})
|
|
|
|
|
2024-08-28 10:11:05 +08:00
|
|
|
t.Run("channel cp gc ok", func(t *testing.T) {
|
|
|
|
catalog.EXPECT().DropChannelCheckpoint(mock.Anything, mock.Anything).Return(nil).Twice()
|
2024-07-11 23:01:35 +08:00
|
|
|
gc.recycleChannelCPMeta(context.TODO())
|
|
|
|
assert.Equal(t, 1, len(m.channelCPs.checkpoints))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
func TestGarbageCollector_removeObjectPool(t *testing.T) {
|
2024-01-03 13:16:57 +08:00
|
|
|
paramtable.Init()
|
2024-04-25 20:41:27 +08:00
|
|
|
cm := mocks.NewChunkManager(t)
|
2024-01-03 13:16:57 +08:00
|
|
|
gc := newGarbageCollector(
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
GcOption{
|
|
|
|
cli: cm,
|
|
|
|
dropTolerance: 1,
|
|
|
|
})
|
2024-04-25 20:41:27 +08:00
|
|
|
logs := make(map[string]struct{})
|
2024-01-03 13:16:57 +08:00
|
|
|
for i := 0; i < 50; i++ {
|
2024-04-25 20:41:27 +08:00
|
|
|
logs[fmt.Sprintf("log%d", i)] = struct{}{}
|
2024-01-03 13:16:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
call := cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(nil)
|
|
|
|
defer call.Unset()
|
2024-04-25 20:41:27 +08:00
|
|
|
b := gc.removeObjectFiles(context.TODO(), logs)
|
|
|
|
assert.NoError(t, b)
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
t.Run("oss not found error", func(t *testing.T) {
|
|
|
|
call := cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(merr.WrapErrIoKeyNotFound("not found"))
|
2024-01-03 13:16:57 +08:00
|
|
|
defer call.Unset()
|
2024-04-25 20:41:27 +08:00
|
|
|
b := gc.removeObjectFiles(context.TODO(), logs)
|
|
|
|
assert.NoError(t, b)
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
t.Run("oss server error", func(t *testing.T) {
|
|
|
|
call := cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(merr.WrapErrIoFailed("server error", errors.New("err")))
|
2024-01-03 13:16:57 +08:00
|
|
|
defer call.Unset()
|
2024-04-25 20:41:27 +08:00
|
|
|
b := gc.removeObjectFiles(context.TODO(), logs)
|
|
|
|
assert.Error(t, b)
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("other type error", func(t *testing.T) {
|
|
|
|
call := cm.EXPECT().Remove(mock.Anything, mock.Anything).Return(errors.New("other error"))
|
|
|
|
defer call.Unset()
|
2024-04-25 20:41:27 +08:00
|
|
|
b := gc.removeObjectFiles(context.TODO(), logs)
|
|
|
|
assert.Error(t, b)
|
2024-01-03 13:16:57 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-14 19:26:39 +08:00
|
|
|
type GarbageCollectorSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
bucketName string
|
|
|
|
rootPath string
|
|
|
|
|
2024-04-25 20:41:27 +08:00
|
|
|
cli *storage.RemoteChunkManager
|
2023-12-14 19:26:39 +08:00
|
|
|
inserts []string
|
|
|
|
stats []string
|
|
|
|
delta []string
|
|
|
|
others []string
|
|
|
|
|
|
|
|
meta *meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *GarbageCollectorSuite) SetupTest() {
|
|
|
|
s.bucketName = `datacoord-ut` + strings.ToLower(funcutil.RandomString(8))
|
|
|
|
s.rootPath = `gc` + funcutil.RandomString(8)
|
|
|
|
|
|
|
|
var err error
|
|
|
|
s.cli, s.inserts, s.stats, s.delta, s.others, err = initUtOSSEnv(s.bucketName, s.rootPath, 4)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.meta, err = newMemoryMeta()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *GarbageCollectorSuite) TearDownTest() {
|
2024-04-25 20:41:27 +08:00
|
|
|
cleanupOSS(s.cli, s.bucketName, s.rootPath)
|
2023-12-14 19:26:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *GarbageCollectorSuite) TestPauseResume() {
|
|
|
|
s.Run("not_enabled", func() {
|
|
|
|
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
|
|
|
|
cli: s.cli,
|
|
|
|
enabled: false,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 24 * 7,
|
2023-12-14 19:26:39 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
|
|
|
|
gc.start()
|
|
|
|
defer gc.close()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := gc.Pause(ctx, time.Second)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
err = gc.Resume(ctx)
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("pause_then_resume", func() {
|
|
|
|
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
|
|
|
|
cli: s.cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2023-12-14 19:26:39 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
|
|
|
|
gc.start()
|
|
|
|
defer gc.close()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := gc.Pause(ctx, time.Minute)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.NotZero(gc.pauseUntil.Load())
|
|
|
|
|
|
|
|
err = gc.Resume(ctx)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.Zero(gc.pauseUntil.Load())
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("pause_before_until", func() {
|
|
|
|
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
|
|
|
|
cli: s.cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2023-12-14 19:26:39 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
|
|
|
|
gc.start()
|
|
|
|
defer gc.close()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := gc.Pause(ctx, time.Minute)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
until := gc.pauseUntil.Load()
|
|
|
|
s.NotZero(until)
|
|
|
|
|
|
|
|
err = gc.Pause(ctx, time.Second)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
second := gc.pauseUntil.Load()
|
|
|
|
|
|
|
|
s.Equal(until, second)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("pause_resume_timeout", func() {
|
|
|
|
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
|
|
|
|
cli: s.cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
2024-03-19 11:27:06 +08:00
|
|
|
scanInterval: time.Hour * 7 * 24,
|
2023-12-14 19:26:39 +08:00
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
|
|
|
|
defer cancel()
|
|
|
|
err := gc.Pause(ctx, time.Minute)
|
|
|
|
s.Error(err)
|
|
|
|
|
|
|
|
s.Zero(gc.pauseUntil.Load())
|
|
|
|
|
|
|
|
err = gc.Resume(ctx)
|
|
|
|
s.Error(err)
|
|
|
|
|
|
|
|
s.Zero(gc.pauseUntil.Load())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-30 14:19:27 +08:00
|
|
|
func (s *GarbageCollectorSuite) TestRunRecycleTaskWithPauser() {
|
|
|
|
gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{
|
|
|
|
cli: s.cli,
|
|
|
|
enabled: true,
|
|
|
|
checkInterval: time.Millisecond * 10,
|
|
|
|
scanInterval: time.Hour * 7 * 24,
|
|
|
|
missingTolerance: time.Hour * 24,
|
|
|
|
dropTolerance: time.Hour * 24,
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*2500)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
cnt := 0
|
|
|
|
gc.runRecycleTaskWithPauser(ctx, "test", time.Second, func(ctx context.Context) {
|
|
|
|
cnt++
|
|
|
|
})
|
|
|
|
s.Equal(cnt, 2)
|
|
|
|
}
|
|
|
|
|
2023-12-14 19:26:39 +08:00
|
|
|
func TestGarbageCollector(t *testing.T) {
|
|
|
|
suite.Run(t, new(GarbageCollectorSuite))
|
|
|
|
}
|