2022-09-05 13:29:11 +08:00
|
|
|
package rootcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGarbageCollectorCtx_ReDropCollection(t *testing.T) {
|
|
|
|
t.Run("failed to release collection", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
broker.ReleaseCollectionFunc = func(ctx context.Context, collectionID UniqueID) error {
|
|
|
|
return errors.New("error mock ReleaseCollection")
|
|
|
|
}
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
|
|
|
core := newTestCore(withBroker(broker), withTtSynchronizer(ticker))
|
2022-09-21 15:46:51 +08:00
|
|
|
gc := newBgGarbageCollector(core)
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.ReDropCollection(&model.Collection{}, 1000)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to DropCollectionIndex", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
releaseCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.ReleaseCollectionFunc = func(ctx context.Context, collectionID UniqueID) error {
|
|
|
|
releaseCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
2022-09-23 09:36:51 +08:00
|
|
|
broker.DropCollectionIndexFunc = func(ctx context.Context, collID UniqueID, partIDs []UniqueID) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
return errors.New("error mock DropCollectionIndex")
|
|
|
|
}
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
|
|
|
core := newTestCore(withBroker(broker), withTtSynchronizer(ticker))
|
2022-09-21 15:46:51 +08:00
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.ReDropCollection(&model.Collection{}, 1000)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-releaseCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, releaseCollectionCalled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to GcCollectionData", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
releaseCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.ReleaseCollectionFunc = func(ctx context.Context, collectionID UniqueID) error {
|
|
|
|
releaseCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dropCollectionIndexCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan := make(chan struct{}, 1)
|
2022-09-23 09:36:51 +08:00
|
|
|
broker.DropCollectionIndexFunc = func(ctx context.Context, collID UniqueID, partIDs []UniqueID) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
dropCollectionIndexCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ticker := newTickerWithMockFailStream() // failed to broadcast drop msg.
|
2022-09-21 15:46:51 +08:00
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
|
|
|
core := newTestCore(withBroker(broker), withTtSynchronizer(ticker), withTsoAllocator(tsoAllocator))
|
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
2022-09-05 13:29:11 +08:00
|
|
|
shardsNum := 2
|
|
|
|
pchans := ticker.getDmlChannelNames(shardsNum)
|
|
|
|
gc.ReDropCollection(&model.Collection{PhysicalChannelNames: pchans}, 1000)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-releaseCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, releaseCollectionCalled)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-dropCollectionIndexChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, dropCollectionIndexCalled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to remove collection", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
releaseCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.ReleaseCollectionFunc = func(ctx context.Context, collectionID UniqueID) error {
|
|
|
|
releaseCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dropCollectionIndexCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan := make(chan struct{}, 1)
|
2022-09-23 09:36:51 +08:00
|
|
|
broker.DropCollectionIndexFunc = func(ctx context.Context, collID UniqueID, partIDs []UniqueID) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
dropCollectionIndexCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.RemoveCollectionFunc = func(ctx context.Context, collectionID UniqueID, ts Timestamp) error {
|
|
|
|
return errors.New("error mock RemoveCollection")
|
|
|
|
}
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
2022-09-21 15:46:51 +08:00
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
2022-09-05 13:29:11 +08:00
|
|
|
core := newTestCore(withBroker(broker),
|
|
|
|
withTtSynchronizer(ticker),
|
2022-09-21 15:46:51 +08:00
|
|
|
withTsoAllocator(tsoAllocator),
|
2022-09-05 13:29:11 +08:00
|
|
|
withMeta(meta))
|
2022-09-21 15:46:51 +08:00
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.ReDropCollection(&model.Collection{}, 1000)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-releaseCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, releaseCollectionCalled)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-dropCollectionIndexChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, dropCollectionIndexCalled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
releaseCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.ReleaseCollectionFunc = func(ctx context.Context, collectionID UniqueID) error {
|
|
|
|
releaseCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
releaseCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dropCollectionIndexCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan := make(chan struct{}, 1)
|
2022-09-23 09:36:51 +08:00
|
|
|
broker.DropCollectionIndexFunc = func(ctx context.Context, collID UniqueID, partIDs []UniqueID) error {
|
2022-09-05 13:29:11 +08:00
|
|
|
dropCollectionIndexCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
dropCollectionIndexChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
removeCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
removeCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
meta.RemoveCollectionFunc = func(ctx context.Context, collectionID UniqueID, ts Timestamp) error {
|
|
|
|
removeCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
removeCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
2022-09-21 15:46:51 +08:00
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
2022-09-05 13:29:11 +08:00
|
|
|
core := newTestCore(withBroker(broker),
|
|
|
|
withTtSynchronizer(ticker),
|
2022-09-21 15:46:51 +08:00
|
|
|
withTsoAllocator(tsoAllocator),
|
2022-09-05 13:29:11 +08:00
|
|
|
withMeta(meta))
|
2022-09-21 15:46:51 +08:00
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.ReDropCollection(&model.Collection{}, 1000)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-releaseCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, releaseCollectionCalled)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-dropCollectionIndexChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, dropCollectionIndexCalled)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-removeCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, removeCollectionCalled)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGarbageCollectorCtx_RemoveCreatingCollection(t *testing.T) {
|
|
|
|
t.Run("failed to UnwatchChannels", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
broker.UnwatchChannelsFunc = func(ctx context.Context, info *watchInfo) error {
|
|
|
|
return errors.New("error mock UnwatchChannels")
|
|
|
|
}
|
|
|
|
core := newTestCore(withBroker(broker))
|
2022-09-21 15:46:51 +08:00
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.RemoveCreatingCollection(&model.Collection{})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to RemoveCollection", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
unwatchChannelsCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
unwatchChannelsChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.UnwatchChannelsFunc = func(ctx context.Context, info *watchInfo) error {
|
|
|
|
unwatchChannelsCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
unwatchChannelsChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.RemoveCollectionFunc = func(ctx context.Context, collectionID UniqueID, ts Timestamp) error {
|
|
|
|
return errors.New("error mock RemoveCollection")
|
|
|
|
}
|
|
|
|
core := newTestCore(withBroker(broker), withMeta(meta))
|
2022-09-21 15:46:51 +08:00
|
|
|
gc := newBgGarbageCollector(core)
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.RemoveCreatingCollection(&model.Collection{})
|
2022-09-21 15:46:51 +08:00
|
|
|
<-unwatchChannelsChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, unwatchChannelsCalled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
broker := newMockBroker()
|
|
|
|
unwatchChannelsCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
unwatchChannelsChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
broker.UnwatchChannelsFunc = func(ctx context.Context, info *watchInfo) error {
|
|
|
|
unwatchChannelsCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
unwatchChannelsChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
removeCollectionCalled := false
|
2022-09-21 15:46:51 +08:00
|
|
|
removeCollectionChan := make(chan struct{}, 1)
|
2022-09-05 13:29:11 +08:00
|
|
|
meta.RemoveCollectionFunc = func(ctx context.Context, collectionID UniqueID, ts Timestamp) error {
|
|
|
|
removeCollectionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
removeCollectionChan <- struct{}{}
|
2022-09-05 13:29:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
core := newTestCore(withBroker(broker), withMeta(meta))
|
2022-09-21 15:46:51 +08:00
|
|
|
gc := newBgGarbageCollector(core)
|
2022-09-05 13:29:11 +08:00
|
|
|
gc.RemoveCreatingCollection(&model.Collection{})
|
2022-09-21 15:46:51 +08:00
|
|
|
<-unwatchChannelsChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, unwatchChannelsCalled)
|
2022-09-21 15:46:51 +08:00
|
|
|
<-removeCollectionChan
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.True(t, removeCollectionCalled)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func TestGarbageCollectorCtx_ReDropPartition(t *testing.T) {
|
|
|
|
t.Run("failed to GcPartitionData", func(t *testing.T) {
|
|
|
|
ticker := newTickerWithMockFailStream() // failed to broadcast drop msg.
|
|
|
|
shardsNum := 2
|
|
|
|
pchans := ticker.getDmlChannelNames(shardsNum)
|
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
2022-09-23 09:36:51 +08:00
|
|
|
core := newTestCore(withTtSynchronizer(ticker), withTsoAllocator(tsoAllocator), withDropIndex())
|
2022-09-21 15:46:51 +08:00
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
|
|
|
gc.ReDropPartition(pchans, &model.Partition{}, 100000)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to RemovePartition", func(t *testing.T) {
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
|
|
|
shardsNum := 2
|
|
|
|
pchans := ticker.getDmlChannelNames(shardsNum)
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.RemovePartitionFunc = func(ctx context.Context, collectionID UniqueID, partitionID UniqueID, ts Timestamp) error {
|
|
|
|
return errors.New("error mock RemovePartition")
|
|
|
|
}
|
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
2022-09-23 09:36:51 +08:00
|
|
|
core := newTestCore(withMeta(meta), withTtSynchronizer(ticker), withTsoAllocator(tsoAllocator), withDropIndex())
|
2022-09-21 15:46:51 +08:00
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
|
|
|
gc.ReDropPartition(pchans, &model.Partition{}, 100000)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
ticker := newTickerWithMockNormalStream()
|
|
|
|
shardsNum := 2
|
|
|
|
pchans := ticker.getDmlChannelNames(shardsNum)
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
removePartitionCalled := false
|
|
|
|
removePartitionChan := make(chan struct{}, 1)
|
|
|
|
meta.RemovePartitionFunc = func(ctx context.Context, collectionID UniqueID, partitionID UniqueID, ts Timestamp) error {
|
|
|
|
removePartitionCalled = true
|
|
|
|
removePartitionChan <- struct{}{}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
tsoAllocator := newMockTsoAllocator()
|
|
|
|
tsoAllocator.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
2022-09-23 09:36:51 +08:00
|
|
|
core := newTestCore(withMeta(meta), withTtSynchronizer(ticker), withTsoAllocator(tsoAllocator), withDropIndex())
|
2022-09-21 15:46:51 +08:00
|
|
|
core.ddlTsLockManager = newDdlTsLockManagerV2(core.tsoAllocator)
|
|
|
|
gc := newBgGarbageCollector(core)
|
|
|
|
core.garbageCollector = gc
|
|
|
|
gc.ReDropPartition(pchans, &model.Partition{}, 100000)
|
|
|
|
<-removePartitionChan
|
|
|
|
assert.True(t, removePartitionCalled)
|
|
|
|
})
|
|
|
|
}
|