2022-01-04 09:15:30 +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:42:47 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-04 09:15:30 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:42:47 +08:00
|
|
|
//
|
2022-01-04 09:15:30 +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:42:47 +08:00
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
package funcutil
|
|
|
|
|
|
|
|
import (
|
2022-03-30 21:11:28 +08:00
|
|
|
"bytes"
|
2021-01-29 09:27:26 +08:00
|
|
|
"context"
|
2022-03-30 21:11:28 +08:00
|
|
|
"encoding/binary"
|
2021-02-07 21:32:37 +08:00
|
|
|
"encoding/json"
|
2021-03-12 14:22:09 +08:00
|
|
|
"errors"
|
2021-01-29 17:08:31 +08:00
|
|
|
"fmt"
|
2021-09-27 23:18:02 +08:00
|
|
|
"io/ioutil"
|
2022-01-14 21:17:34 +08:00
|
|
|
"net"
|
2021-09-27 23:18:02 +08:00
|
|
|
"net/http"
|
2022-03-25 14:27:25 +08:00
|
|
|
"reflect"
|
2022-01-14 21:17:34 +08:00
|
|
|
"strconv"
|
2022-06-17 10:22:11 +08:00
|
|
|
"strings"
|
2021-01-29 09:27:26 +08:00
|
|
|
"time"
|
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
"github.com/go-basic/ipv4"
|
2022-02-08 21:57:46 +08:00
|
|
|
"go.uber.org/zap"
|
2022-09-21 20:16:51 +08:00
|
|
|
grpcStatus "google.golang.org/grpc/status"
|
2022-02-08 21:57:46 +08:00
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2021-09-27 23:18:02 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-09-21 20:16:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
2021-01-29 09:27:26 +08:00
|
|
|
)
|
|
|
|
|
2021-09-27 23:18:02 +08:00
|
|
|
// CheckGrpcReady wait for context timeout, or wait 100ms then send nil to targetCh
|
2021-01-29 09:27:26 +08:00
|
|
|
func CheckGrpcReady(ctx context.Context, targetCh chan error) {
|
|
|
|
select {
|
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
targetCh <- nil
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:18:02 +08:00
|
|
|
// GetLocalIP return the local ip address
|
2021-01-29 09:27:26 +08:00
|
|
|
func GetLocalIP() string {
|
|
|
|
return ipv4.LocalIP()
|
|
|
|
}
|
2021-01-29 17:08:31 +08:00
|
|
|
|
2021-09-27 23:18:02 +08:00
|
|
|
// WaitForComponentStates wait for component's state to be one of the specific states
|
2022-10-10 15:55:22 +08:00
|
|
|
func WaitForComponentStates(ctx context.Context, service types.Component, serviceName string, states []commonpb.StateCode, attempts uint, sleep time.Duration) error {
|
2021-01-29 17:08:31 +08:00
|
|
|
checkFunc := func() error {
|
2021-02-26 17:44:24 +08:00
|
|
|
resp, err := service.GetComponentStates(ctx)
|
2021-01-29 17:08:31 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-10 22:06:22 +08:00
|
|
|
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2021-01-29 17:08:31 +08:00
|
|
|
return errors.New(resp.Status.Reason)
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
meet := false
|
|
|
|
for _, state := range states {
|
|
|
|
if resp.State.StateCode == state {
|
|
|
|
meet = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !meet {
|
2021-12-15 10:23:10 +08:00
|
|
|
return fmt.Errorf(
|
|
|
|
"WaitForComponentStates, not meet, %s current state: %s",
|
|
|
|
serviceName,
|
|
|
|
resp.State.StateCode.String())
|
2021-01-29 17:08:31 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-23 09:24:10 +08:00
|
|
|
return retry.Do(ctx, checkFunc, retry.Attempts(attempts), retry.Sleep(sleep))
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
|
|
|
|
2021-09-27 23:18:02 +08:00
|
|
|
// WaitForComponentInitOrHealthy wait for component's state to be initializing or healthy
|
2021-06-23 09:24:10 +08:00
|
|
|
func WaitForComponentInitOrHealthy(ctx context.Context, service types.Component, serviceName string, attempts uint, sleep time.Duration) error {
|
2022-10-10 15:55:22 +08:00
|
|
|
return WaitForComponentStates(ctx, service, serviceName, []commonpb.StateCode{commonpb.StateCode_Initializing, commonpb.StateCode_Healthy}, attempts, sleep)
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
|
|
|
|
2021-10-04 23:40:01 +08:00
|
|
|
// WaitForComponentInit wait for component's state to be initializing
|
2021-06-23 09:24:10 +08:00
|
|
|
func WaitForComponentInit(ctx context.Context, service types.Component, serviceName string, attempts uint, sleep time.Duration) error {
|
2022-10-10 15:55:22 +08:00
|
|
|
return WaitForComponentStates(ctx, service, serviceName, []commonpb.StateCode{commonpb.StateCode_Initializing}, attempts, sleep)
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
|
|
|
|
2021-10-04 23:40:01 +08:00
|
|
|
// WaitForComponentHealthy wait for component's state to be healthy
|
2021-06-23 09:24:10 +08:00
|
|
|
func WaitForComponentHealthy(ctx context.Context, service types.Component, serviceName string, attempts uint, sleep time.Duration) error {
|
2022-10-10 15:55:22 +08:00
|
|
|
return WaitForComponentStates(ctx, service, serviceName, []commonpb.StateCode{commonpb.StateCode_Healthy}, attempts, sleep)
|
2021-01-29 17:08:31 +08:00
|
|
|
}
|
2021-02-07 21:32:37 +08:00
|
|
|
|
2021-09-27 23:18:02 +08:00
|
|
|
// ParseIndexParamsMap parse the jsonic index parameters to map
|
2021-02-07 21:32:37 +08:00
|
|
|
func ParseIndexParamsMap(mStr string) (map[string]string, error) {
|
|
|
|
buffer := make(map[string]interface{})
|
|
|
|
err := json.Unmarshal([]byte(mStr), &buffer)
|
|
|
|
if err != nil {
|
2022-10-14 17:51:24 +08:00
|
|
|
return nil, fmt.Errorf("unmarshal params failed, %w", err)
|
2021-02-07 21:32:37 +08:00
|
|
|
}
|
|
|
|
ret := make(map[string]string)
|
|
|
|
for key, value := range buffer {
|
|
|
|
valueStr := fmt.Sprintf("%v", value)
|
|
|
|
ret[key] = valueStr
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
2021-09-27 23:18:02 +08:00
|
|
|
|
|
|
|
const (
|
2021-10-04 23:40:01 +08:00
|
|
|
// PulsarMaxMessageSizeKey is the key of config item
|
2021-09-27 23:18:02 +08:00
|
|
|
PulsarMaxMessageSizeKey = "maxMessageSize"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetPulsarConfig get pulsar configuration using pulsar admin api
|
|
|
|
func GetPulsarConfig(protocol, ip, port, url string, args ...int64) (map[string]interface{}, error) {
|
|
|
|
var resp *http.Response
|
|
|
|
var err error
|
|
|
|
|
|
|
|
getResp := func() error {
|
|
|
|
log.Debug("function util", zap.String("url", protocol+"://"+ip+":"+port+url))
|
|
|
|
resp, err = http.Get(protocol + "://" + ip + ":" + port + url)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var attempt uint = 10
|
2021-12-14 15:31:07 +08:00
|
|
|
var interval = time.Second
|
2021-09-27 23:18:02 +08:00
|
|
|
if len(args) > 0 && args[0] > 0 {
|
|
|
|
attempt = uint(args[0])
|
|
|
|
}
|
|
|
|
if len(args) > 1 && args[1] > 0 {
|
|
|
|
interval = time.Duration(args[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
err = retry.Do(context.TODO(), getResp, retry.Attempts(attempt), retry.Sleep(interval))
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("failed to get config", zap.String("error", err.Error()))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
log.Debug("get config", zap.String("config", string(body)))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := make(map[string]interface{})
|
|
|
|
err = json.Unmarshal(body, &ret)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAttrByKeyFromRepeatedKV return the value corresponding to key in kv pair
|
|
|
|
func GetAttrByKeyFromRepeatedKV(key string, kvs []*commonpb.KeyValuePair) (string, error) {
|
|
|
|
for _, kv := range kvs {
|
|
|
|
if kv.Key == key {
|
|
|
|
return kv.Value, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 15:03:28 +08:00
|
|
|
return "", fmt.Errorf("key %s not found", key)
|
2021-09-27 23:18:02 +08:00
|
|
|
}
|
2021-11-18 11:17:12 +08:00
|
|
|
|
2021-12-10 21:59:30 +08:00
|
|
|
// CheckCtxValid check if the context is valid
|
2021-11-18 11:17:12 +08:00
|
|
|
func CheckCtxValid(ctx context.Context) bool {
|
|
|
|
return ctx.Err() != context.DeadlineExceeded && ctx.Err() != context.Canceled
|
|
|
|
}
|
2022-01-14 21:17:34 +08:00
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
func GetVecFieldIDs(schema *schemapb.CollectionSchema) []int64 {
|
|
|
|
var vecFieldIDs []int64
|
|
|
|
for _, field := range schema.Fields {
|
|
|
|
if field.DataType == schemapb.DataType_BinaryVector || field.DataType == schemapb.DataType_FloatVector {
|
|
|
|
vecFieldIDs = append(vecFieldIDs, field.FieldID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vecFieldIDs
|
|
|
|
}
|
|
|
|
|
|
|
|
func Map2KeyValuePair(datas map[string]string) []*commonpb.KeyValuePair {
|
|
|
|
results := make([]*commonpb.KeyValuePair, len(datas))
|
|
|
|
offset := 0
|
|
|
|
for key, value := range datas {
|
|
|
|
results[offset] = &commonpb.KeyValuePair{
|
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
}
|
|
|
|
offset++
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
func KeyValuePair2Map(datas []*commonpb.KeyValuePair) map[string]string {
|
|
|
|
results := make(map[string]string)
|
|
|
|
for _, pair := range datas {
|
|
|
|
results[pair.Key] = pair.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:12:38 +08:00
|
|
|
func ConvertToKeyValuePairPointer(datas []commonpb.KeyValuePair) []*commonpb.KeyValuePair {
|
|
|
|
var kvs []*commonpb.KeyValuePair
|
|
|
|
for i := 0; i < len(datas); i++ {
|
|
|
|
kvs = append(kvs, &datas[i])
|
|
|
|
}
|
|
|
|
return kvs
|
|
|
|
}
|
|
|
|
|
2022-01-17 17:37:37 +08:00
|
|
|
// GenChannelSubName generate subName to watch channel
|
|
|
|
func GenChannelSubName(prefix string, collectionID int64, nodeID int64) string {
|
|
|
|
return fmt.Sprintf("%s-%d-%d", prefix, collectionID, nodeID)
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:17:34 +08:00
|
|
|
// CheckPortAvailable check if a port is available to be listened on
|
|
|
|
func CheckPortAvailable(port int) bool {
|
|
|
|
addr := ":" + strconv.Itoa(port)
|
|
|
|
listener, err := net.Listen("tcp", addr)
|
|
|
|
if listener != nil {
|
|
|
|
listener.Close()
|
|
|
|
}
|
|
|
|
return err == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAvailablePort return an available port that can be listened on
|
|
|
|
func GetAvailablePort() int {
|
|
|
|
listener, err := net.Listen("tcp", ":0")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer listener.Close()
|
|
|
|
|
|
|
|
return listener.Addr().(*net.TCPAddr).Port
|
|
|
|
}
|
2022-03-15 21:51:21 +08:00
|
|
|
|
|
|
|
// ToPhysicalChannel get physical channel name from virtual channel name
|
|
|
|
func ToPhysicalChannel(vchannel string) string {
|
2022-06-17 10:22:11 +08:00
|
|
|
index := strings.LastIndex(vchannel, "_")
|
|
|
|
if index < 0 {
|
2022-03-15 21:51:21 +08:00
|
|
|
return vchannel
|
|
|
|
}
|
2022-06-17 10:22:11 +08:00
|
|
|
return vchannel[:index]
|
2022-03-15 21:51:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertChannelName assembles channel name according to parameters.
|
|
|
|
func ConvertChannelName(chanName string, tokenFrom string, tokenTo string) (string, error) {
|
2022-06-17 10:22:11 +08:00
|
|
|
if tokenFrom == "" {
|
|
|
|
return "", fmt.Errorf("the tokenFrom is empty")
|
2022-03-15 21:51:21 +08:00
|
|
|
}
|
2022-06-17 10:22:11 +08:00
|
|
|
if !strings.Contains(chanName, tokenFrom) {
|
|
|
|
return "", fmt.Errorf("cannot find token '%s' in '%s'", tokenFrom, chanName)
|
2022-03-15 21:51:21 +08:00
|
|
|
}
|
2022-06-17 10:22:11 +08:00
|
|
|
return strings.Replace(chanName, tokenFrom, tokenTo, 1), nil
|
2022-03-15 21:51:21 +08:00
|
|
|
}
|
2022-03-25 14:27:25 +08:00
|
|
|
|
|
|
|
func getNumRowsOfScalarField(datas interface{}) uint64 {
|
|
|
|
realTypeDatas := reflect.ValueOf(datas)
|
|
|
|
return uint64(realTypeDatas.Len())
|
|
|
|
}
|
|
|
|
|
|
|
|
func getNumRowsOfFloatVectorField(fDatas []float32, dim int64) (uint64, error) {
|
|
|
|
if dim <= 0 {
|
|
|
|
return 0, fmt.Errorf("dim(%d) should be greater than 0", dim)
|
|
|
|
}
|
|
|
|
l := len(fDatas)
|
|
|
|
if int64(l)%dim != 0 {
|
|
|
|
return 0, fmt.Errorf("the length(%d) of float data should divide the dim(%d)", l, dim)
|
|
|
|
}
|
|
|
|
return uint64(int64(l) / dim), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getNumRowsOfBinaryVectorField(bDatas []byte, dim int64) (uint64, error) {
|
|
|
|
if dim <= 0 {
|
|
|
|
return 0, fmt.Errorf("dim(%d) should be greater than 0", dim)
|
|
|
|
}
|
|
|
|
if dim%8 != 0 {
|
|
|
|
return 0, fmt.Errorf("dim(%d) should divide 8", dim)
|
|
|
|
}
|
|
|
|
l := len(bDatas)
|
|
|
|
if (8*int64(l))%dim != 0 {
|
|
|
|
return 0, fmt.Errorf("the num(%d) of all bits should divide the dim(%d)", 8*l, dim)
|
|
|
|
}
|
|
|
|
return uint64((8 * int64(l)) / dim), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNumRowOfFieldData return num rows of the field data
|
|
|
|
func GetNumRowOfFieldData(fieldData *schemapb.FieldData) (uint64, error) {
|
|
|
|
var fieldNumRows uint64
|
|
|
|
var err error
|
|
|
|
switch fieldType := fieldData.Field.(type) {
|
|
|
|
case *schemapb.FieldData_Scalars:
|
|
|
|
scalarField := fieldData.GetScalars()
|
|
|
|
switch scalarType := scalarField.Data.(type) {
|
|
|
|
case *schemapb.ScalarField_BoolData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetBoolData().Data)
|
|
|
|
case *schemapb.ScalarField_IntData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetIntData().Data)
|
|
|
|
case *schemapb.ScalarField_LongData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetLongData().Data)
|
|
|
|
case *schemapb.ScalarField_FloatData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetFloatData().Data)
|
|
|
|
case *schemapb.ScalarField_DoubleData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetDoubleData().Data)
|
|
|
|
case *schemapb.ScalarField_StringData:
|
|
|
|
fieldNumRows = getNumRowsOfScalarField(scalarField.GetStringData().Data)
|
|
|
|
default:
|
|
|
|
return 0, fmt.Errorf("%s is not supported now", scalarType)
|
|
|
|
}
|
|
|
|
case *schemapb.FieldData_Vectors:
|
|
|
|
vectorField := fieldData.GetVectors()
|
|
|
|
switch vectorFieldType := vectorField.Data.(type) {
|
|
|
|
case *schemapb.VectorField_FloatVector:
|
|
|
|
dim := vectorField.GetDim()
|
|
|
|
fieldNumRows, err = getNumRowsOfFloatVectorField(vectorField.GetFloatVector().Data, dim)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
case *schemapb.VectorField_BinaryVector:
|
|
|
|
dim := vectorField.GetDim()
|
|
|
|
fieldNumRows, err = getNumRowsOfBinaryVectorField(vectorField.GetBinaryVector(), dim)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0, fmt.Errorf("%s is not supported now", vectorFieldType)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0, fmt.Errorf("%s is not supported now", fieldType)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fieldNumRows, nil
|
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
// ReadBinary read byte slice as receiver.
|
|
|
|
func ReadBinary(endian binary.ByteOrder, bs []byte, receiver interface{}) error {
|
|
|
|
buf := bytes.NewReader(bs)
|
|
|
|
return binary.Read(buf, endian, receiver)
|
|
|
|
}
|
2022-06-02 12:16:03 +08:00
|
|
|
|
2022-06-07 12:20:06 +08:00
|
|
|
// IsGrpcErr checks whether err is instance of grpc status error.
|
2022-06-02 12:16:03 +08:00
|
|
|
func IsGrpcErr(err error) bool {
|
2022-06-14 17:10:10 +08:00
|
|
|
for {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_, ok := grpcStatus.FromError(err)
|
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
err = errors.Unwrap(err)
|
2022-06-02 12:16:03 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-04 11:04:34 +08:00
|
|
|
|
|
|
|
func IsEmptyString(str string) bool {
|
|
|
|
return strings.TrimSpace(str) == ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleTenantForEtcdKey(prefix string, tenant string, key string) string {
|
|
|
|
res := prefix
|
|
|
|
if tenant != "" {
|
|
|
|
res += "/" + tenant
|
|
|
|
}
|
|
|
|
if key != "" {
|
|
|
|
res += "/" + key
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsRevoke(operateType milvuspb.OperatePrivilegeType) bool {
|
|
|
|
return operateType == milvuspb.OperatePrivilegeType_Revoke
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsGrant(operateType milvuspb.OperatePrivilegeType) bool {
|
|
|
|
return operateType == milvuspb.OperatePrivilegeType_Grant
|
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUserRoleCache(user string, role string) string {
|
|
|
|
return fmt.Sprintf("%s/%s", user, role)
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:28:35 +08:00
|
|
|
func DecodeUserRoleCache(cache string) (string, string, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
index := strings.LastIndex(cache, "/")
|
2022-08-05 16:28:35 +08:00
|
|
|
if index == -1 {
|
|
|
|
return "", "", fmt.Errorf("invalid param, cache: [%s]", cache)
|
|
|
|
}
|
2022-08-04 11:04:34 +08:00
|
|
|
user := cache[:index]
|
|
|
|
role := cache[index+1:]
|
2022-08-05 16:28:35 +08:00
|
|
|
return user, role, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-09-21 20:16:51 +08:00
|
|
|
|
|
|
|
func GetFieldSizeFromFieldBinlog(fieldBinlog *datapb.FieldBinlog) int64 {
|
|
|
|
fieldSize := int64(0)
|
|
|
|
for _, binlog := range fieldBinlog.Binlogs {
|
|
|
|
fieldSize += binlog.LogSize
|
|
|
|
}
|
|
|
|
|
|
|
|
return fieldSize
|
|
|
|
}
|