milvus/internal/util/rocksmq/global_rmq.go
yukun 0d499a9f99 Fix search waiting for seconds in singlenode
Signed-off-by: yukun <kun.yu@zilliz.com>
2021-03-09 17:42:13 +08:00

61 lines
1.2 KiB
Go

package rocksmq
import (
"os"
"sync"
"github.com/zilliztech/milvus-distributed/internal/allocator"
rocksdbkv "github.com/zilliztech/milvus-distributed/internal/kv/rocksdb"
)
var Rmq *RocksMQ
var once sync.Once
type Consumer struct {
GroupName string
ChannelName string
MsgMutex chan struct{}
}
func InitRmq(rocksdbName string, idAllocator allocator.GIDAllocator) error {
var err error
Rmq, err = NewRocksMQ(rocksdbName, idAllocator)
return err
}
func InitRocksMQ(rocksdbName string) error {
var err error
once.Do(func() {
kvname := rocksdbName + "_kv"
if _, err := os.Stat(kvname); !os.IsNotExist(err) {
_ = os.RemoveAll(kvname)
}
rocksdbKV, err := rocksdbkv.NewRocksdbKV(kvname)
if err != nil {
panic(err)
}
idAllocator := allocator.NewGlobalIDAllocator("rmq_id", rocksdbKV)
_ = idAllocator.Initialize()
if _, err := os.Stat(rocksdbName); !os.IsNotExist(err) {
_ = os.RemoveAll(rocksdbName)
}
Rmq, err = NewRocksMQ(rocksdbName, idAllocator)
if err != nil {
panic(err)
}
})
return err
}
func CloseRocksMQ() {
if Rmq != nil && Rmq.store != nil {
Rmq.store.Close()
rocksdbName := Rmq.store.Name()
_ = os.RemoveAll(rocksdbName)
kvname := rocksdbName + "_kv"
os.RemoveAll(kvname)
}
}