Fix release collection bug

Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
pull/4973/head^2
XuanYang-cn 2021-03-11 18:42:25 +08:00 committed by yefu.chen
parent ddb37fe498
commit 7dd531d159
5 changed files with 55 additions and 9 deletions

View File

@ -117,6 +117,10 @@ singlenode: build-cpp
@echo "Building singlenode ..."
@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/singlenode $(PWD)/cmd/singlenode/main.go 1>/dev/null
queryservice: build-cpp
@echo "Building each component's binary to './bin'"
@echo "Building distributed queryservice ..."
@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/queryservice $(PWD)/cmd/queryservice/queryservice.go 1>/dev/null
# Builds various components locally.
build-go: build-cpp

View File

@ -204,13 +204,13 @@ func (mp *metaReplica) getPartitionStates(dbID UniqueID,
func (mp *metaReplica) releaseCollection(dbID UniqueID, collectionID UniqueID) error {
if collections, ok := mp.db2collections[dbID]; ok {
for i, collection := range collections {
if collectionID == collection.id {
if i+1 < len(collections) {
collections = append(collections[:i], collections[i+1:]...)
} else {
collections = collections[:i]
}
for i, coll := range collections {
if collectionID == coll.id {
newSize := len(collections) - 1
newColls := make([]*collection, 0, newSize)
collections[i] = collections[newSize]
newColls = append(newColls, collections[:newSize]...)
mp.db2collections[dbID] = newColls
return nil
}
}

View File

@ -0,0 +1,40 @@
package queryservice
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReplica_Release(t *testing.T) {
replica := newMetaReplica()
err := replica.addCollection(0, 1, nil)
require.NoError(t, err)
colls, err := replica.getCollections(0)
assert.NoError(t, err)
assert.Equal(t, 1, len(colls))
err = replica.addPartition(0, 1, 100)
assert.NoError(t, err)
partitions, err := replica.getPartitions(0, 1)
assert.NoError(t, err)
assert.Equal(t, 1, len(partitions))
err = replica.releasePartition(0, 1, 100)
assert.NoError(t, err)
partitions, err = replica.getPartitions(0, 1)
assert.NoError(t, err)
assert.Equal(t, 0, len(partitions))
err = replica.releasePartition(0, 1, 100)
assert.Error(t, err)
err = replica.releaseCollection(0, 1)
assert.NoError(t, err)
colls, err = replica.getCollections(0)
assert.NoError(t, err)
assert.Equal(t, 0, len(colls))
err = replica.releaseCollection(0, 1)
assert.Error(t, err)
}

View File

@ -128,4 +128,6 @@ install(TARGETS wrapper DESTINATION ${CMAKE_INSTALL_PREFIX})
install(
FILES ${ARROW_LIB} ${PARQUET_LIB} ${THRIFT_LIB} ${UTF8PROC_LIB} DESTINATION ${CMAKE_INSTALL_PREFIX})
add_subdirectory(test)
if (BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@ -21,7 +21,7 @@ default_flush_interval = 1
big_flush_interval = 1000
default_drop_interval = 3
default_dim = 128
default_nb = 1200
default_nb = 3000
default_top_k = 10
max_top_k = 16384
# max_partition_num = 256