2021-12-15 12:02:08 +08: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 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-15 12:02:08 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-12-15 12:02:08 +08: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 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-18 16:38:28 +08:00
|
|
|
|
|
|
|
import (
|
2021-12-17 14:41:33 +08:00
|
|
|
"fmt"
|
2020-11-18 16:38:28 +08:00
|
|
|
"sync"
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2022-03-30 22:07:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-11-26 16:15:16 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2022-03-30 22:07:28 +08:00
|
|
|
"go.uber.org/zap"
|
2020-11-18 16:38:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type tSafeWatcher struct {
|
|
|
|
notifyChan chan bool
|
2021-11-26 01:33:16 +08:00
|
|
|
closeCh chan struct{}
|
2020-11-18 16:38:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTSafeWatcher() *tSafeWatcher {
|
|
|
|
return &tSafeWatcher{
|
2020-11-28 19:06:48 +08:00
|
|
|
notifyChan: make(chan bool, 1),
|
2021-11-26 01:33:16 +08:00
|
|
|
closeCh: make(chan struct{}, 1),
|
2020-11-18 16:38:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (watcher *tSafeWatcher) notify() {
|
|
|
|
if len(watcher.notifyChan) == 0 {
|
|
|
|
watcher.notifyChan <- true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:37:55 +08:00
|
|
|
func (watcher *tSafeWatcher) watcherChan() <-chan bool {
|
|
|
|
return watcher.notifyChan
|
|
|
|
}
|
|
|
|
|
2021-11-26 01:33:16 +08:00
|
|
|
func (watcher *tSafeWatcher) close() {
|
|
|
|
watcher.closeCh <- struct{}{}
|
|
|
|
}
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
type tSafe struct {
|
2021-12-17 14:41:33 +08:00
|
|
|
channel Channel
|
|
|
|
tSafeMu sync.Mutex // guards all fields
|
|
|
|
tSafe Timestamp
|
|
|
|
watcher *tSafeWatcher
|
2020-11-18 16:38:28 +08:00
|
|
|
}
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
func newTSafe(channel Channel) *tSafe {
|
|
|
|
return &tSafe{
|
|
|
|
channel: channel,
|
|
|
|
tSafe: typeutil.ZeroTimestamp,
|
2021-09-28 12:28:03 +08:00
|
|
|
}
|
2021-09-24 13:57:54 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 12:28:03 +08:00
|
|
|
func (ts *tSafe) registerTSafeWatcher(t *tSafeWatcher) error {
|
2021-01-12 18:03:24 +08:00
|
|
|
ts.tSafeMu.Lock()
|
|
|
|
defer ts.tSafeMu.Unlock()
|
2021-12-17 14:41:33 +08:00
|
|
|
if ts.watcher != nil {
|
2022-03-30 22:07:28 +08:00
|
|
|
log.Warn("tSafeWatcher register more than once", zap.String("channel", ts.channel))
|
2021-12-17 20:12:42 +08:00
|
|
|
return fmt.Errorf("tSafeWatcher has been existed, channel = %s", ts.channel)
|
2021-12-17 14:41:33 +08:00
|
|
|
}
|
|
|
|
ts.watcher = t
|
2021-09-28 12:28:03 +08:00
|
|
|
return nil
|
2020-11-18 16:38:28 +08:00
|
|
|
}
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
func (ts *tSafe) get() Timestamp {
|
2020-11-18 16:38:28 +08:00
|
|
|
ts.tSafeMu.Lock()
|
|
|
|
defer ts.tSafeMu.Unlock()
|
|
|
|
return ts.tSafe
|
|
|
|
}
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
func (ts *tSafe) set(t Timestamp) {
|
2020-11-18 16:38:28 +08:00
|
|
|
ts.tSafeMu.Lock()
|
2021-01-12 18:03:24 +08:00
|
|
|
defer ts.tSafeMu.Unlock()
|
2021-12-17 14:41:33 +08:00
|
|
|
ts.tSafe = t
|
|
|
|
if ts.watcher != nil {
|
|
|
|
ts.watcher.notify()
|
2020-11-18 16:38:28 +08:00
|
|
|
}
|
2021-12-17 14:41:33 +08:00
|
|
|
//log.Debug("set tSafe done",
|
|
|
|
// zap.Any("channel", ts.channel),
|
|
|
|
// zap.Any("t", m.t))
|
2021-03-22 16:36:10 +08:00
|
|
|
}
|