2021-10-29 13:15:04 +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 11:13:52 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-29 13:15:04 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:13:52 +08:00
|
|
|
//
|
2021-10-29 13:15:04 +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 11:13:52 +08:00
|
|
|
|
2020-11-16 21:10:43 +08:00
|
|
|
package kv
|
2020-09-07 21:07:36 +08:00
|
|
|
|
2021-05-18 14:18:02 +08:00
|
|
|
import (
|
2021-08-24 09:45:51 +08:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
2023-01-04 21:37:35 +08:00
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2021-05-18 14:18:02 +08:00
|
|
|
)
|
|
|
|
|
2022-03-07 18:01:58 +08:00
|
|
|
// CompareFailedError is a helper type for checking MetaKv CompareAndSwap series func error type
|
|
|
|
type CompareFailedError struct {
|
|
|
|
internalError error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error implements error interface
|
|
|
|
func (e *CompareFailedError) Error() string {
|
|
|
|
return e.internalError.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewCompareFailedError wraps error into NewCompareFailedError
|
|
|
|
func NewCompareFailedError(err error) error {
|
|
|
|
return &CompareFailedError{internalError: err}
|
|
|
|
}
|
|
|
|
|
2022-02-25 14:47:52 +08:00
|
|
|
// BaseKV contains base operations of kv. Include save, load and remove.
|
2021-04-12 18:09:28 +08:00
|
|
|
type BaseKV interface {
|
2020-09-07 21:07:36 +08:00
|
|
|
Load(key string) (string, error)
|
2020-11-03 15:08:50 +08:00
|
|
|
MultiLoad(keys []string) ([]string, error)
|
2020-11-06 16:47:18 +08:00
|
|
|
LoadWithPrefix(key string) ([]string, []string, error)
|
2020-09-07 21:07:36 +08:00
|
|
|
Save(key, value string) error
|
2020-11-03 15:08:50 +08:00
|
|
|
MultiSave(kvs map[string]string) error
|
2020-09-07 21:07:36 +08:00
|
|
|
Remove(key string) error
|
2020-11-03 15:08:50 +08:00
|
|
|
MultiRemove(keys []string) error
|
2021-04-09 09:55:04 +08:00
|
|
|
RemoveWithPrefix(key string) error
|
2023-07-10 19:40:27 +08:00
|
|
|
Has(key string) (bool, error)
|
2020-12-07 14:37:42 +08:00
|
|
|
Close()
|
2020-12-05 17:39:58 +08:00
|
|
|
}
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2021-09-29 18:39:59 +08:00
|
|
|
// TxnKV contains extra txn operations of kv. The extra operations is transactional.
|
2023-02-26 11:31:49 +08:00
|
|
|
//
|
|
|
|
//go:generate mockery --name=TxnKV --with-expecter
|
2021-04-12 18:09:28 +08:00
|
|
|
type TxnKV interface {
|
|
|
|
BaseKV
|
2020-12-07 15:22:20 +08:00
|
|
|
MultiSaveAndRemove(saves map[string]string, removals []string) error
|
2021-03-06 16:00:41 +08:00
|
|
|
MultiRemoveWithPrefix(keys []string) error
|
|
|
|
MultiSaveAndRemoveWithPrefix(saves map[string]string, removals []string) error
|
2020-12-07 15:22:20 +08:00
|
|
|
}
|
2021-05-18 14:18:02 +08:00
|
|
|
|
2022-02-22 13:15:51 +08:00
|
|
|
// MetaKv is TxnKV for metadata. It should save data with lease.
|
2023-02-26 11:31:49 +08:00
|
|
|
//
|
|
|
|
//go:generate mockery --name=MetaKv --with-expecter
|
2021-08-24 09:45:51 +08:00
|
|
|
type MetaKv interface {
|
|
|
|
TxnKV
|
|
|
|
GetPath(key string) string
|
|
|
|
LoadWithPrefix(key string) ([]string, []string, error)
|
2023-06-26 09:20:44 +08:00
|
|
|
CompareVersionAndSwap(key string, version int64, target string) (bool, error)
|
|
|
|
WalkWithPrefix(prefix string, paginationSize int, fn func([]byte, []byte) error) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// WatchKV is watchable MetaKv. As of today(2023/06/24), it's coupled with etcd.
|
|
|
|
//
|
|
|
|
//go:generate mockery --name=WatchKV --with-expecter
|
|
|
|
type WatchKV interface {
|
|
|
|
MetaKv
|
2021-08-24 09:45:51 +08:00
|
|
|
Watch(key string) clientv3.WatchChan
|
|
|
|
WatchWithPrefix(key string) clientv3.WatchChan
|
|
|
|
WatchWithRevision(key string, revision int64) clientv3.WatchChan
|
|
|
|
}
|
|
|
|
|
2021-09-29 18:39:59 +08:00
|
|
|
// SnapShotKV is TxnKV for snapshot data. It must save timestamp.
|
2023-02-26 11:31:49 +08:00
|
|
|
//
|
|
|
|
//go:generate mockery --name=SnapShotKV --with-expecter
|
2021-05-18 14:18:02 +08:00
|
|
|
type SnapShotKV interface {
|
2021-08-18 14:36:10 +08:00
|
|
|
Save(key string, value string, ts typeutil.Timestamp) error
|
2021-05-18 14:18:02 +08:00
|
|
|
Load(key string, ts typeutil.Timestamp) (string, error)
|
2021-10-13 15:54:33 +08:00
|
|
|
MultiSave(kvs map[string]string, ts typeutil.Timestamp) error
|
2021-05-18 14:18:02 +08:00
|
|
|
LoadWithPrefix(key string, ts typeutil.Timestamp) ([]string, []string, error)
|
2021-10-13 15:54:33 +08:00
|
|
|
MultiSaveAndRemoveWithPrefix(saves map[string]string, removals []string, ts typeutil.Timestamp) error
|
2021-05-18 14:18:02 +08:00
|
|
|
}
|