2021-12-29 09:48:04 +00: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
|
2021-04-19 05:42:47 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-29 09:48:04 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 05:42:47 +00:00
|
|
|
//
|
2021-12-29 09:48:04 +00:00
|
|
|
// 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.
|
2021-04-19 05:42:47 +00:00
|
|
|
|
2022-03-03 13:57:56 +00:00
|
|
|
package server
|
2021-01-26 01:38:40 +00:00
|
|
|
|
2021-02-09 07:57:10 +00:00
|
|
|
import (
|
2021-06-26 04:28:07 +00:00
|
|
|
"os"
|
2021-02-09 07:57:10 +00:00
|
|
|
"sync"
|
|
|
|
|
2023-02-26 03:31:49 +00:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-04-06 11:14:32 +00:00
|
|
|
"go.uber.org/zap"
|
2023-02-26 03:31:49 +00:00
|
|
|
|
2023-04-06 11:14:32 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
2021-02-09 07:57:10 +00:00
|
|
|
)
|
|
|
|
|
2021-09-26 10:29:56 +00:00
|
|
|
// Rmq is global rocksmq instance that will be initialized only once
|
2021-03-19 11:33:21 +00:00
|
|
|
var Rmq *rocksmq
|
2021-09-24 13:45:56 +00:00
|
|
|
|
|
|
|
// once is used to init global rocksmq
|
2021-02-09 07:57:10 +00:00
|
|
|
var once sync.Once
|
2021-09-24 13:45:56 +00:00
|
|
|
|
|
|
|
// InitRocksMQ init global rocksmq single instance
|
2022-04-07 14:05:32 +00:00
|
|
|
func InitRocksMQ(path string) error {
|
2021-12-02 02:27:32 +00:00
|
|
|
var finalErr error
|
2021-02-09 07:57:10 +00:00
|
|
|
once.Do(func() {
|
2022-04-07 14:05:32 +00:00
|
|
|
log.Debug("initializing global rmq", zap.String("path", path))
|
2021-12-02 02:27:32 +00:00
|
|
|
var fi os.FileInfo
|
2022-04-07 14:05:32 +00:00
|
|
|
fi, finalErr = os.Stat(path)
|
2021-12-02 02:27:32 +00:00
|
|
|
if os.IsNotExist(finalErr) {
|
2022-04-07 14:05:32 +00:00
|
|
|
finalErr = os.MkdirAll(path, os.ModePerm)
|
2021-12-02 02:27:32 +00:00
|
|
|
if finalErr != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if !fi.IsDir() {
|
|
|
|
errMsg := "can't create a directory because there exists a file with the same name"
|
|
|
|
finalErr = errors.New(errMsg)
|
|
|
|
return
|
2021-06-26 04:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-26 11:11:30 +00:00
|
|
|
Rmq, finalErr = NewRocksMQ(path, nil)
|
2021-02-09 07:57:10 +00:00
|
|
|
})
|
2021-12-02 02:27:32 +00:00
|
|
|
return finalErr
|
2021-02-09 07:57:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 13:45:56 +00:00
|
|
|
// CloseRocksMQ is used to close global rocksmq
|
2021-02-09 07:57:10 +00:00
|
|
|
func CloseRocksMQ() {
|
2021-08-16 10:46:10 +00:00
|
|
|
log.Debug("Close Rocksmq!")
|
2021-09-22 09:21:00 +00:00
|
|
|
if Rmq != nil && Rmq.store != nil {
|
|
|
|
Rmq.Close()
|
2021-02-09 07:57:10 +00:00
|
|
|
}
|
2021-01-26 01:38:40 +00:00
|
|
|
}
|