2021-01-26 09:38:40 +08:00
|
|
|
package rocksmq
|
|
|
|
|
2021-02-09 15:57:10 +08:00
|
|
|
import (
|
2021-02-20 15:58:19 +08:00
|
|
|
"os"
|
2021-02-09 15:57:10 +08:00
|
|
|
"sync"
|
|
|
|
|
2021-02-24 17:12:06 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/allocator"
|
|
|
|
|
2021-02-09 15:57:10 +08:00
|
|
|
rocksdbkv "github.com/zilliztech/milvus-distributed/internal/kv/rocksdb"
|
|
|
|
)
|
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
var Rmq *RocksMQ
|
2021-02-09 15:57:10 +08:00
|
|
|
var once sync.Once
|
2021-02-03 17:30:10 +08:00
|
|
|
|
|
|
|
type Consumer struct {
|
|
|
|
GroupName string
|
|
|
|
ChannelName string
|
|
|
|
MsgNum chan int
|
|
|
|
}
|
2021-01-26 09:38:40 +08:00
|
|
|
|
2021-02-24 17:12:06 +08:00
|
|
|
func InitRmq(rocksdbName string, idAllocator allocator.GIDAllocator) error {
|
2021-01-26 09:38:40 +08:00
|
|
|
var err error
|
2021-02-03 17:30:10 +08:00
|
|
|
Rmq, err = NewRocksMQ(rocksdbName, idAllocator)
|
2021-01-26 09:38:40 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-09 15:57:10 +08:00
|
|
|
func InitRocksMQ(rocksdbName string) error {
|
|
|
|
var err error
|
|
|
|
once.Do(func() {
|
|
|
|
kvname := rocksdbName + "_kv"
|
2021-02-20 15:58:19 +08:00
|
|
|
if _, err := os.Stat(kvname); !os.IsNotExist(err) {
|
|
|
|
_ = os.RemoveAll(kvname)
|
|
|
|
}
|
2021-02-09 15:57:10 +08:00
|
|
|
rocksdbKV, err := rocksdbkv.NewRocksdbKV(kvname)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-02-24 17:12:06 +08:00
|
|
|
idAllocator := allocator.NewGlobalIDAllocator("rmq_id", rocksdbKV)
|
2021-02-09 15:57:10 +08:00
|
|
|
_ = idAllocator.Initialize()
|
|
|
|
|
2021-02-20 15:58:19 +08:00
|
|
|
if _, err := os.Stat(rocksdbName); !os.IsNotExist(err) {
|
|
|
|
_ = os.RemoveAll(rocksdbName)
|
|
|
|
}
|
2021-02-09 15:57:10 +08:00
|
|
|
Rmq, err = NewRocksMQ(rocksdbName, idAllocator)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func CloseRocksMQ() {
|
|
|
|
if Rmq != nil && Rmq.store != nil {
|
|
|
|
Rmq.store.Close()
|
2021-02-20 15:58:19 +08:00
|
|
|
rocksdbName := Rmq.store.Name()
|
|
|
|
_ = os.RemoveAll(rocksdbName)
|
|
|
|
kvname := rocksdbName + "_kv"
|
|
|
|
os.RemoveAll(kvname)
|
2021-02-09 15:57:10 +08:00
|
|
|
}
|
2021-01-26 09:38:40 +08:00
|
|
|
}
|