Skip to content
Snippets Groups Projects
Commit ddddd65d authored by Bingyi Sun 【孙秉义】's avatar Bingyi Sun 【孙秉义】 Committed by yefu.chen
Browse files

Delete internal/errors package


Signed-off-by: default avatarsunby <bingyi.sun@zilliz.com>
parent 447a1520
No related branches found
No related tags found
No related merge requests found
Showing
with 56 additions and 640 deletions
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"syscall" "syscall"
"github.com/zilliztech/milvus-distributed/cmd/distributed/roles" "github.com/zilliztech/milvus-distributed/cmd/distributed/roles"
"github.com/zilliztech/milvus-distributed/internal/errors"
) )
const ( const (
...@@ -34,7 +33,7 @@ func run(serverType string) error { ...@@ -34,7 +33,7 @@ func run(serverType string) error {
_, _ = fd.WriteString(fmt.Sprintf("%d", os.Getpid())) _, _ = fd.WriteString(fmt.Sprintf("%d", os.Getpid()))
} else { } else {
return errors.Errorf("service %s is running", serverType) return fmt.Errorf("service %s is running", serverType)
} }
role := roles.MilvusRoles{} role := roles.MilvusRoles{}
...@@ -62,7 +61,7 @@ func run(serverType string) error { ...@@ -62,7 +61,7 @@ func run(serverType string) error {
case "standalone": case "standalone":
role.EnableStandalone = true role.EnableStandalone = true
default: default:
return errors.Errorf("unknown server type = %s", serverType) return fmt.Errorf("unknown server type = %s", serverType)
} }
role.Run(false) role.Run(false)
return nil return nil
......
...@@ -17,14 +17,12 @@ require ( ...@@ -17,14 +17,12 @@ require (
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2
github.com/google/btree v1.0.0 github.com/google/btree v1.0.0
github.com/klauspost/compress v1.10.11 // indirect github.com/klauspost/compress v1.10.11 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/minio/minio-go/v7 v7.0.5 github.com/minio/minio-go/v7 v7.0.5
github.com/mitchellh/mapstructure v1.1.2 github.com/mitchellh/mapstructure v1.1.2
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/gomega v1.10.5 // indirect
github.com/opentracing-contrib/go-grpc v0.0.0-20200813121455-4a6760c71486 github.com/opentracing-contrib/go-grpc v0.0.0-20200813121455-4a6760c71486
github.com/opentracing/opentracing-go v1.2.0 github.com/opentracing/opentracing-go v1.2.0
github.com/pierrec/lz4 v2.5.2+incompatible // indirect github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0 // indirect github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 github.com/spaolacci/murmur3 v1.1.0
github.com/spf13/cast v1.3.0 github.com/spf13/cast v1.3.0
...@@ -41,11 +39,10 @@ require ( ...@@ -41,11 +39,10 @@ require (
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d // indirect golang.org/x/tools v0.0.0-20200825202427-b303f430e36d // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150 // indirect google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150 // indirect
google.golang.org/grpc v1.31.0 google.golang.org/grpc v1.31.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.3.0 // indirect
honnef.co/go/tools v0.0.1-2020.1.4 // indirect honnef.co/go/tools v0.0.1-2020.1.4 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
) )
......
This diff is collapsed.
...@@ -2,9 +2,10 @@ package allocator ...@@ -2,9 +2,10 @@ package allocator
import ( import (
"context" "context"
"errors"
"sync" "sync"
"time" "time"
"errors"
) )
const ( const (
......
...@@ -2,10 +2,10 @@ package allocator ...@@ -2,10 +2,10 @@ package allocator
import ( import (
"context" "context"
"errors"
"log" "log"
"time" "time"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb" "github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
"github.com/zilliztech/milvus-distributed/internal/util/retry" "github.com/zilliztech/milvus-distributed/internal/util/retry"
...@@ -147,7 +147,7 @@ func (ta *TimestampAllocator) Alloc(count uint32) ([]Timestamp, error) { ...@@ -147,7 +147,7 @@ func (ta *TimestampAllocator) Alloc(count uint32) ([]Timestamp, error) {
req.Wait() req.Wait()
if !req.IsValid() { if !req.IsValid() {
return nil, errors.Errorf("alloc time stamp request failed") return nil, errors.New("alloc time stamp request failed")
} }
start, count := req.timestamp, req.count start, count := req.timestamp, req.count
......
package datanode package datanode
import ( import (
"github.com/zilliztech/milvus-distributed/internal/errors" "errors"
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb" "github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
) )
...@@ -27,7 +28,7 @@ func (c *Collection) GetSchema() *schemapb.CollectionSchema { ...@@ -27,7 +28,7 @@ func (c *Collection) GetSchema() *schemapb.CollectionSchema {
func newCollection(collectionID UniqueID, schema *schemapb.CollectionSchema) (*Collection, error) { func newCollection(collectionID UniqueID, schema *schemapb.CollectionSchema) (*Collection, error) {
if schema == nil { if schema == nil {
return nil, errors.Errorf("Invalid schema") return nil, errors.New("invalid schema")
} }
var newCollection = &Collection{ var newCollection = &Collection{
......
package datanode package datanode
import ( import (
"fmt"
"sync" "sync"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/log" "github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2" "github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb" "github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
...@@ -71,7 +71,7 @@ func (replica *ReplicaImpl) getSegmentByID(segmentID UniqueID) (*Segment, error) ...@@ -71,7 +71,7 @@ func (replica *ReplicaImpl) getSegmentByID(segmentID UniqueID) (*Segment, error)
return segment, nil return segment, nil
} }
} }
return nil, errors.Errorf("Cannot find segment, id = %v", segmentID) return nil, fmt.Errorf("Cannot find segment, id = %v", segmentID)
} }
func (replica *ReplicaImpl) addSegment( func (replica *ReplicaImpl) addSegment(
...@@ -114,7 +114,7 @@ func (replica *ReplicaImpl) removeSegment(segmentID UniqueID) error { ...@@ -114,7 +114,7 @@ func (replica *ReplicaImpl) removeSegment(segmentID UniqueID) error {
return nil return nil
} }
} }
return errors.Errorf("Error, there's no segment %v", segmentID) return fmt.Errorf("Error, there's no segment %v", segmentID)
} }
func (replica *ReplicaImpl) hasSegment(segmentID UniqueID) bool { func (replica *ReplicaImpl) hasSegment(segmentID UniqueID) bool {
...@@ -141,7 +141,7 @@ func (replica *ReplicaImpl) updateStatistics(segmentID UniqueID, numRows int64) ...@@ -141,7 +141,7 @@ func (replica *ReplicaImpl) updateStatistics(segmentID UniqueID, numRows int64)
return nil return nil
} }
} }
return errors.Errorf("Error, there's no segment %v", segmentID) return fmt.Errorf("Error, there's no segment %v", segmentID)
} }
func (replica *ReplicaImpl) getSegmentStatisticsUpdates(segmentID UniqueID) (*internalpb2.SegmentStatisticsUpdates, error) { func (replica *ReplicaImpl) getSegmentStatisticsUpdates(segmentID UniqueID) (*internalpb2.SegmentStatisticsUpdates, error) {
...@@ -165,7 +165,7 @@ func (replica *ReplicaImpl) getSegmentStatisticsUpdates(segmentID UniqueID) (*in ...@@ -165,7 +165,7 @@ func (replica *ReplicaImpl) getSegmentStatisticsUpdates(segmentID UniqueID) (*in
return updates, nil return updates, nil
} }
} }
return nil, errors.Errorf("Error, there's no segment %v", segmentID) return nil, fmt.Errorf("Error, there's no segment %v", segmentID)
} }
// --- collection --- // --- collection ---
...@@ -181,7 +181,7 @@ func (replica *ReplicaImpl) addCollection(collectionID UniqueID, schema *schemap ...@@ -181,7 +181,7 @@ func (replica *ReplicaImpl) addCollection(collectionID UniqueID, schema *schemap
defer replica.mu.Unlock() defer replica.mu.Unlock()
if _, ok := replica.collections[collectionID]; ok { if _, ok := replica.collections[collectionID]; ok {
return errors.Errorf("Create an existing collection=%s", schema.GetName()) return fmt.Errorf("Create an existing collection=%s", schema.GetName())
} }
newCollection, err := newCollection(collectionID, schema) newCollection, err := newCollection(collectionID, schema)
...@@ -210,7 +210,7 @@ func (replica *ReplicaImpl) getCollectionByID(collectionID UniqueID) (*Collectio ...@@ -210,7 +210,7 @@ func (replica *ReplicaImpl) getCollectionByID(collectionID UniqueID) (*Collectio
coll, ok := replica.collections[collectionID] coll, ok := replica.collections[collectionID]
if !ok { if !ok {
return nil, errors.Errorf("Cannot get collection %d by ID: not exist", collectionID) return nil, fmt.Errorf("Cannot get collection %d by ID: not exist", collectionID)
} }
return coll, nil return coll, nil
......
...@@ -9,7 +9,8 @@ import ( ...@@ -9,7 +9,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"github.com/zilliztech/milvus-distributed/internal/errors" "errors"
"github.com/zilliztech/milvus-distributed/internal/log" "github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/msgstream" "github.com/zilliztech/milvus-distributed/internal/msgstream"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
...@@ -128,7 +129,7 @@ func (node *DataNode) Init() error { ...@@ -128,7 +129,7 @@ func (node *DataNode) Init() error {
resp, err := node.dataService.RegisterNode(ctx, req) resp, err := node.dataService.RegisterNode(ctx, req)
if err != nil { if err != nil {
return errors.Errorf("Register node failed: %v", err) return fmt.Errorf("Register node failed: %v", err)
} }
select { select {
...@@ -149,7 +150,7 @@ func (node *DataNode) Init() error { ...@@ -149,7 +150,7 @@ func (node *DataNode) Init() error {
case "CompleteFlushChannelName": case "CompleteFlushChannelName":
Params.CompleteFlushChannelName = kv.Value Params.CompleteFlushChannelName = kv.Value
default: default:
return errors.Errorf("Invalid key: %v", kv.Key) return fmt.Errorf("Invalid key: %v", kv.Key)
} }
} }
......
...@@ -2,7 +2,7 @@ package datanode ...@@ -2,7 +2,7 @@ package datanode
import ( import (
"context" "context"
"errors" "fmt"
"path" "path"
"sort" "sort"
"strconv" "strconv"
...@@ -217,7 +217,7 @@ func (ddNode *ddNode) createCollection(msg *msgstream.CreateCollectionMsg) { ...@@ -217,7 +217,7 @@ func (ddNode *ddNode) createCollection(msg *msgstream.CreateCollectionMsg) {
// add collection // add collection
if _, ok := ddNode.ddRecords.collectionRecords[collectionID]; ok { if _, ok := ddNode.ddRecords.collectionRecords[collectionID]; ok {
err := errors.New("collection " + strconv.FormatInt(collectionID, 10) + " is already exists") err := fmt.Errorf("collection %d is already exists", collectionID)
log.Error("String conversion wrong", zap.Error(err)) log.Error("String conversion wrong", zap.Error(err))
return return
} }
......
...@@ -4,13 +4,13 @@ import ( ...@@ -4,13 +4,13 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/binary" "encoding/binary"
"fmt"
"path" "path"
"strconv" "strconv"
"unsafe" "unsafe"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/kv" "github.com/zilliztech/milvus-distributed/internal/kv"
miniokv "github.com/zilliztech/milvus-distributed/internal/kv/minio" miniokv "github.com/zilliztech/milvus-distributed/internal/kv/minio"
"github.com/zilliztech/milvus-distributed/internal/log" "github.com/zilliztech/milvus-distributed/internal/log"
...@@ -481,7 +481,7 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI ...@@ -481,7 +481,7 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI
collSch, err := ibNode.getCollectionSchemaByID(collID) collSch, err := ibNode.getCollectionSchemaByID(collID)
if err != nil { if err != nil {
return errors.Errorf("Get collection by ID wrong, %v", err) return fmt.Errorf("Get collection by ID wrong, %v", err)
} }
collMeta := &etcdpb.CollectionMeta{ collMeta := &etcdpb.CollectionMeta{
...@@ -496,7 +496,7 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI ...@@ -496,7 +496,7 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI
segID, ibNode.insertBuffer.insertData[segID]) segID, ibNode.insertBuffer.insertData[segID])
if err != nil { if err != nil {
return errors.Errorf("generate binlog wrong: %v", err) return fmt.Errorf("generate binlog wrong: %v", err)
} }
// clear buffer // clear buffer
...@@ -513,18 +513,18 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI ...@@ -513,18 +513,18 @@ func (ibNode *insertBufferNode) flushSegment(segID UniqueID, partitionID UniqueI
for index, blob := range binLogs { for index, blob := range binLogs {
uid, err := ibNode.idAllocator.allocID() uid, err := ibNode.idAllocator.allocID()
if err != nil { if err != nil {
return errors.Errorf("Allocate Id failed, %v", err) return fmt.Errorf("Allocate Id failed, %v", err)
} }
key := path.Join(keyPrefix, blob.Key, strconv.FormatInt(uid, 10)) key := path.Join(keyPrefix, blob.Key, strconv.FormatInt(uid, 10))
err = ibNode.minIOKV.Save(key, string(blob.Value[:])) err = ibNode.minIOKV.Save(key, string(blob.Value[:]))
if err != nil { if err != nil {
return errors.Errorf("Save to MinIO failed, %v", err) return fmt.Errorf("Save to MinIO failed, %v", err)
} }
fieldID, err := strconv.ParseInt(blob.Key, 10, 32) fieldID, err := strconv.ParseInt(blob.Key, 10, 32)
if err != nil { if err != nil {
return errors.Errorf("string to fieldID wrong, %v", err) return fmt.Errorf("string to fieldID wrong, %v", err)
} }
log.Debug("... Appending binlog paths ...", zap.Int("number", index)) log.Debug("... Appending binlog paths ...", zap.Int("number", index))
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/log" "github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/etcdpb" "github.com/zilliztech/milvus-distributed/internal/proto/etcdpb"
...@@ -65,7 +64,7 @@ func (mService *metaService) getCollectionNames(ctx context.Context) ([]string, ...@@ -65,7 +64,7 @@ func (mService *metaService) getCollectionNames(ctx context.Context) ([]string,
response, err := mService.masterClient.ShowCollections(ctx, req) response, err := mService.masterClient.ShowCollections(ctx, req)
if err != nil { if err != nil {
return nil, errors.Errorf("Get collection names from master service wrong: %v", err) return nil, fmt.Errorf("Get collection names from master service wrong: %v", err)
} }
return response.GetCollectionNames(), nil return response.GetCollectionNames(), nil
} }
...@@ -85,12 +84,12 @@ func (mService *metaService) createCollection(ctx context.Context, name string) ...@@ -85,12 +84,12 @@ func (mService *metaService) createCollection(ctx context.Context, name string)
response, err := mService.masterClient.DescribeCollection(ctx, req) response, err := mService.masterClient.DescribeCollection(ctx, req)
if err != nil { if err != nil {
return errors.Errorf("Describe collection %v from master service wrong: %v", name, err) return fmt.Errorf("Describe collection %v from master service wrong: %v", name, err)
} }
err = mService.replica.addCollection(response.GetCollectionID(), response.GetSchema()) err = mService.replica.addCollection(response.GetCollectionID(), response.GetSchema())
if err != nil { if err != nil {
return errors.Errorf("Add collection %v into collReplica wrong: %v", name, err) return fmt.Errorf("Add collection %v into collReplica wrong: %v", name, err)
} }
return nil return nil
......
package datanode package datanode
import ( import (
"fmt"
"path" "path"
"strconv" "strconv"
"sync" "sync"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/kv" "github.com/zilliztech/milvus-distributed/internal/kv"
"github.com/zilliztech/milvus-distributed/internal/proto/datapb" "github.com/zilliztech/milvus-distributed/internal/proto/datapb"
) )
...@@ -72,7 +72,7 @@ func (mt *metaTable) CompleteFlush(segmentID UniqueID) error { ...@@ -72,7 +72,7 @@ func (mt *metaTable) CompleteFlush(segmentID UniqueID) error {
defer mt.lock.Unlock() defer mt.lock.Unlock()
meta, ok := mt.segID2FlushMeta[segmentID] meta, ok := mt.segID2FlushMeta[segmentID]
if !ok { if !ok {
return errors.Errorf("segment not exists with ID = %v", segmentID) return fmt.Errorf("segment not exists with ID = %v", segmentID)
} }
meta.IsFlushed = true meta.IsFlushed = true
...@@ -132,7 +132,7 @@ func (mt *metaTable) checkFlushComplete(segmentID UniqueID) (bool, error) { ...@@ -132,7 +132,7 @@ func (mt *metaTable) checkFlushComplete(segmentID UniqueID) (bool, error) {
defer mt.lock.RUnlock() defer mt.lock.RUnlock()
meta, ok := mt.segID2FlushMeta[segmentID] meta, ok := mt.segID2FlushMeta[segmentID]
if !ok { if !ok {
return false, errors.Errorf("segment not exists with ID = %v", segmentID) return false, fmt.Errorf("segment not exists with ID = %v", segmentID)
} }
return meta.IsFlushed, nil return meta.IsFlushed, nil
} }
...@@ -142,7 +142,7 @@ func (mt *metaTable) getSegBinlogPaths(segmentID UniqueID) (map[int64][]string, ...@@ -142,7 +142,7 @@ func (mt *metaTable) getSegBinlogPaths(segmentID UniqueID) (map[int64][]string,
defer mt.lock.RUnlock() defer mt.lock.RUnlock()
meta, ok := mt.segID2FlushMeta[segmentID] meta, ok := mt.segID2FlushMeta[segmentID]
if !ok { if !ok {
return nil, errors.Errorf("segment not exists with ID = %v", segmentID) return nil, fmt.Errorf("segment not exists with ID = %v", segmentID)
} }
ret := make(map[int64][]string) ret := make(map[int64][]string)
for _, field := range meta.Fields { for _, field := range meta.Fields {
...@@ -211,7 +211,7 @@ func (mt *metaTable) getDDLBinlogPaths(collID UniqueID) (map[UniqueID][]string, ...@@ -211,7 +211,7 @@ func (mt *metaTable) getDDLBinlogPaths(collID UniqueID) (map[UniqueID][]string,
defer mt.lock.RUnlock() defer mt.lock.RUnlock()
meta, ok := mt.collID2DdlMeta[collID] meta, ok := mt.collID2DdlMeta[collID]
if !ok { if !ok {
return nil, errors.Errorf("collection not exists with ID = %v", collID) return nil, fmt.Errorf("collection not exists with ID = %v", collID)
} }
ret := make(map[UniqueID][]string) ret := make(map[UniqueID][]string)
ret[meta.CollectionID] = meta.BinlogPaths ret[meta.CollectionID] = meta.BinlogPaths
......
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb" "github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/kv" "github.com/zilliztech/milvus-distributed/internal/kv"
) )
...@@ -319,7 +318,7 @@ func (meta *meta) AddPartition(collectionID UniqueID, partitionID UniqueID) erro ...@@ -319,7 +318,7 @@ func (meta *meta) AddPartition(collectionID UniqueID, partitionID UniqueID) erro
for _, t := range coll.Partitions { for _, t := range coll.Partitions {
if t == partitionID { if t == partitionID {
return errors.Errorf("partition %d already exists.", partitionID) return fmt.Errorf("partition %d already exists", partitionID)
} }
} }
coll.Partitions = append(coll.Partitions, partitionID) coll.Partitions = append(coll.Partitions, partitionID)
......
...@@ -2,6 +2,7 @@ package dataservice ...@@ -2,6 +2,7 @@ package dataservice
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"path" "path"
"strconv" "strconv"
...@@ -297,7 +298,7 @@ func (s *Server) checkMasterIsHealthy() error { ...@@ -297,7 +298,7 @@ func (s *Server) checkMasterIsHealthy() error {
var err error var err error
select { select {
case <-ctx.Done(): case <-ctx.Done():
return fmt.Errorf("master is not healthy") return errors.New("master is not healthy")
case <-ticker.C: case <-ticker.C:
resp, err = s.masterClient.GetComponentStates(ctx) resp, err = s.masterClient.GetComponentStates(ctx)
if err = VerifyResponse(resp, err); err != nil { if err = VerifyResponse(resp, err); err != nil {
......
...@@ -2,6 +2,7 @@ package grpcdatanode ...@@ -2,6 +2,7 @@ package grpcdatanode
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
...@@ -19,7 +20,6 @@ import ( ...@@ -19,7 +20,6 @@ import (
dsc "github.com/zilliztech/milvus-distributed/internal/distributed/dataservice/client" dsc "github.com/zilliztech/milvus-distributed/internal/distributed/dataservice/client"
msc "github.com/zilliztech/milvus-distributed/internal/distributed/masterservice/client" msc "github.com/zilliztech/milvus-distributed/internal/distributed/masterservice/client"
"github.com/zilliztech/milvus-distributed/internal/errors"
"github.com/zilliztech/milvus-distributed/internal/log" "github.com/zilliztech/milvus-distributed/internal/log"
"github.com/zilliztech/milvus-distributed/internal/msgstream" "github.com/zilliztech/milvus-distributed/internal/msgstream"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
...@@ -235,7 +235,7 @@ func (s *Server) FlushSegments(ctx context.Context, in *datapb.FlushSegRequest) ...@@ -235,7 +235,7 @@ func (s *Server) FlushSegments(ctx context.Context, in *datapb.FlushSegRequest)
return &commonpb.Status{ return &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR, ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
Reason: "DataNode isn't healthy.", Reason: "DataNode isn't healthy.",
}, errors.Errorf("DataNode is not ready yet") }, errors.New("DataNode is not ready yet")
} }
return &commonpb.Status{ return &commonpb.Status{
ErrorCode: commonpb.ErrorCode_SUCCESS, ErrorCode: commonpb.ErrorCode_SUCCESS,
......
...@@ -4,7 +4,8 @@ import ( ...@@ -4,7 +4,8 @@ import (
"path" "path"
"strconv" "strconv"
"github.com/zilliztech/milvus-distributed/internal/errors" "errors"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/datapb" "github.com/zilliztech/milvus-distributed/internal/proto/datapb"
"github.com/zilliztech/milvus-distributed/internal/proto/indexpb" "github.com/zilliztech/milvus-distributed/internal/proto/indexpb"
......
package errors
import (
"fmt"
"io"
)
// New returns an error with the supplied message.
// New also records the stack trace at the point it was called.
func New(message string) error {
return &fundamental{
msg: message,
stack: callers(),
}
}
// Errorf formats according to a format specifier and returns the string
// as a value that satisfies error.
// Errorf also records the stack trace at the point it was called.
func Errorf(format string, args ...interface{}) error {
return &fundamental{
msg: fmt.Sprintf(format, args...),
stack: callers(),
}
}
// StackTraceAware is an optimization to avoid repetitive traversals of an error chain.
// HasStack checks for this marker first.
// Annotate/Wrap and Annotatef/Wrapf will produce this marker.
type StackTraceAware interface {
HasStack() bool
}
// HasStack tells whether a StackTracer exists in the error chain
func HasStack(err error) bool {
if errWithStack, ok := err.(StackTraceAware); ok {
return errWithStack.HasStack()
}
return GetStackTracer(err) != nil
}
// fundamental is an error that has a message and a stack, but no caller.
type fundamental struct {
msg string
*stack
}
func (f *fundamental) Error() string { return f.msg }
func (f *fundamental) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
io.WriteString(s, f.msg)
f.stack.Format(s, verb)
return
}
fallthrough
case 's':
io.WriteString(s, f.msg)
case 'q':
fmt.Fprintf(s, "%q", f.msg)
}
}
// WithStack annotates err with a stack trace at the point WithStack was called.
// If err is nil, WithStack returns nil.
//
// For most use cases this is deprecated and AddStack should be used (which will ensure just one stack trace).
// However, one may want to use this in some situations, for example to create a 2nd trace across a goroutine.
func WithStack(err error) error {
if err == nil {
return nil
}
return &withStack{
err,
callers(),
}
}
// AddStack is similar to WithStack.
// However, it will first check with HasStack to see if a stack trace already exists in the causer chain before creating another one.
func AddStack(err error) error {
if HasStack(err) {
return err
}
return WithStack(err)
}
type withStack struct {
error
*stack
}
func (w *withStack) Cause() error { return w.error }
func (w *withStack) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v", w.Cause())
w.stack.Format(s, verb)
return
}
fallthrough
case 's':
io.WriteString(s, w.Error())
case 'q':
fmt.Fprintf(s, "%q", w.Error())
}
}
// Wrap returns an error annotating err with a stack trace
// at the point Wrap is called, and the supplied message.
// If err is nil, Wrap returns nil.
//
// For most use cases this is deprecated in favor of Annotate.
// Annotate avoids creating duplicate stack traces.
func Wrap(err error, message string) error {
if err == nil {
return nil
}
hasStack := HasStack(err)
err = &withMessage{
cause: err,
msg: message,
causeHasStack: hasStack,
}
return &withStack{
err,
callers(),
}
}
// Wrapf returns an error annotating err with a stack trace
// at the point Wrapf is call, and the format specifier.
// If err is nil, Wrapf returns nil.
//
// For most use cases this is deprecated in favor of Annotatef.
// Annotatef avoids creating duplicate stack traces.
func Wrapf(err error, format string, args ...interface{}) error {
if err == nil {
return nil
}
hasStack := HasStack(err)
err = &withMessage{
cause: err,
msg: fmt.Sprintf(format, args...),
causeHasStack: hasStack,
}
return &withStack{
err,
callers(),
}
}
// WithMessage annotates err with a new message.
// If err is nil, WithMessage returns nil.
func WithMessage(err error, message string) error {
if err == nil {
return nil
}
return &withMessage{
cause: err,
msg: message,
causeHasStack: HasStack(err),
}
}
type withMessage struct {
cause error
msg string
causeHasStack bool
}
func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
func (w *withMessage) Cause() error { return w.cause }
func (w *withMessage) HasStack() bool { return w.causeHasStack }
func (w *withMessage) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v\n", w.Cause())
io.WriteString(s, w.msg)
return
}
fallthrough
case 's', 'q':
io.WriteString(s, w.Error())
}
}
// Cause returns the underlying cause of the error, if possible.
// An error value has a cause if it implements the following
// interface:
//
// type causer interface {
// Cause() error
// }
//
// If the error does not implement Cause, the original error will
// be returned. If the error is nil, nil will be returned without further
// investigation.
func Cause(err error) error {
cause := Unwrap(err)
if cause == nil {
return err
}
return Cause(cause)
}
// Unwrap uses causer to return the next error in the chain or nil.
// This goes one-level deeper, whereas Cause goes as far as possible
func Unwrap(err error) error {
type causer interface {
Cause() error
}
if unErr, ok := err.(causer); ok {
return unErr.Cause()
}
return nil
}
// Find an error in the chain that matches a test function.
// returns nil if no error is found.
func Find(origErr error, test func(error) bool) error {
var foundErr error
WalkDeep(origErr, func(err error) bool {
if test(err) {
foundErr = err
return true
}
return false
})
return foundErr
}
package errors
// ErrorGroup is an interface for multiple errors that are not a chain.
// This happens for example when executing multiple operations in parallel.
type ErrorGroup interface {
Errors() []error
}
// Errors uses the ErrorGroup interface to return a slice of errors.
// If the ErrorGroup interface is not implemented it returns an array containing just the given error.
func Errors(err error) []error {
if eg, ok := err.(ErrorGroup); ok {
return eg.Errors()
}
return []error{err}
}
// WalkDeep does a depth-first traversal of all errors.
// Any ErrorGroup is traversed (after going deep).
// The visitor function can return true to end the traversal early
// In that case, WalkDeep will return true, otherwise false.
func WalkDeep(err error, visitor func(err error) bool) bool {
// Go deep
unErr := err
for unErr != nil {
if done := visitor(unErr); done {
return true
}
unErr = Unwrap(unErr)
}
// Go wide
if group, ok := err.(ErrorGroup); ok {
for _, err := range group.Errors() {
if early := WalkDeep(err, visitor); early {
return true
}
}
}
return false
}
package errors
import (
"bytes"
"fmt"
"io"
"path"
"runtime"
"strconv"
"strings"
)
// StackTracer retrieves the StackTrace
// Generally you would want to use the GetStackTracer function to do that.
type StackTracer interface {
StackTrace() StackTrace
}
// GetStackTracer will return the first StackTracer in the causer chain.
// This function is used by AddStack to avoid creating redundant stack traces.
//
// You can also use the StackTracer interface on the returned error to get the stack trace.
func GetStackTracer(origErr error) StackTracer {
var stacked StackTracer
WalkDeep(origErr, func(err error) bool {
if stackTracer, ok := err.(StackTracer); ok {
stacked = stackTracer
return true
}
return false
})
return stacked
}
// Frame represents a program counter inside a stack frame.
type Frame uintptr
// pc returns the program counter for this frame;
// multiple frames may have the same PC value.
func (f Frame) pc() uintptr { return uintptr(f) - 1 }
// file returns the full path to the file that contains the
// function for this Frame's pc.
func (f Frame) file() string {
fn := runtime.FuncForPC(f.pc())
if fn == nil {
return "unknown"
}
file, _ := fn.FileLine(f.pc())
return file
}
// line returns the line number of source code of the
// function for this Frame's pc.
func (f Frame) line() int {
fn := runtime.FuncForPC(f.pc())
if fn == nil {
return 0
}
_, line := fn.FileLine(f.pc())
return line
}
// Format formats the frame according to the fmt.Formatter interface.
//
// %s source file
// %d source line
// %n function name
// %v equivalent to %s:%d
//
// Format accepts flags that alter the printing of some verbs, as follows:
//
// %+s function name and path of source file relative to the compile time
// GOPATH separated by \n\t (<funcname>\n\t<path>)
// %+v equivalent to %+s:%d
func (f Frame) Format(s fmt.State, verb rune) {
f.format(s, s, verb)
}
// format allows stack trace printing calls to be made with a bytes.Buffer.
func (f Frame) format(w io.Writer, s fmt.State, verb rune) {
switch verb {
case 's':
switch {
case s.Flag('+'):
pc := f.pc()
fn := runtime.FuncForPC(pc)
if fn == nil {
io.WriteString(w, "unknown")
} else {
file, _ := fn.FileLine(pc)
io.WriteString(w, fn.Name())
io.WriteString(w, "\n\t")
io.WriteString(w, file)
}
default:
io.WriteString(w, path.Base(f.file()))
}
case 'd':
io.WriteString(w, strconv.Itoa(f.line()))
case 'n':
name := runtime.FuncForPC(f.pc()).Name()
io.WriteString(w, funcname(name))
case 'v':
f.format(w, s, 's')
io.WriteString(w, ":")
f.format(w, s, 'd')
}
}
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
type StackTrace []Frame
// Format formats the stack of Frames according to the fmt.Formatter interface.
//
// %s lists source files for each Frame in the stack
// %v lists the source file and line number for each Frame in the stack
//
// Format accepts flags that alter the printing of some verbs, as follows:
//
// %+v Prints filename, function, and line number for each Frame in the stack.
func (st StackTrace) Format(s fmt.State, verb rune) {
var b bytes.Buffer
switch verb {
case 'v':
switch {
case s.Flag('+'):
b.Grow(len(st) * stackMinLen)
for _, fr := range st {
b.WriteByte('\n')
fr.format(&b, s, verb)
}
case s.Flag('#'):
fmt.Fprintf(&b, "%#v", []Frame(st))
default:
st.formatSlice(&b, s, verb)
}
case 's':
st.formatSlice(&b, s, verb)
}
io.Copy(s, &b)
}
// formatSlice will format this StackTrace into the given buffer as a slice of
// Frame, only valid when called with '%s' or '%v'.
func (st StackTrace) formatSlice(b *bytes.Buffer, s fmt.State, verb rune) {
b.WriteByte('[')
if len(st) == 0 {
b.WriteByte(']')
return
}
b.Grow(len(st) * (stackMinLen / 4))
st[0].format(b, s, verb)
for _, fr := range st[1:] {
b.WriteByte(' ')
fr.format(b, s, verb)
}
b.WriteByte(']')
}
// stackMinLen is a best-guess at the minimum length of a stack trace. It
// doesn't need to be exact, just give a good enough head start for the buffer
// to avoid the expensive early growth.
const stackMinLen = 96
// stack represents a stack of program counters.
type stack []uintptr
func (s *stack) Format(st fmt.State, verb rune) {
switch verb {
case 'v':
switch {
case st.Flag('+'):
var b bytes.Buffer
b.Grow(len(*s) * stackMinLen)
for _, pc := range *s {
f := Frame(pc)
b.WriteByte('\n')
f.format(&b, st, 'v')
}
io.Copy(st, &b)
}
}
}
func (s *stack) StackTrace() StackTrace {
f := make([]Frame, len(*s))
for i := 0; i < len(f); i++ {
f[i] = Frame((*s)[i])
}
return f
}
func callers() *stack {
return callersSkip(4)
}
func callersSkip(skip int) *stack {
const depth = 32
var pcs [depth]uintptr
n := runtime.Callers(skip, pcs[:])
var st stack = pcs[0:n]
return &st
}
// funcname removes the path prefix component of a function's name reported by func.Name().
func funcname(name string) string {
i := strings.LastIndex(name, "/")
name = name[i+1:]
i = strings.Index(name, ".")
return name[i+1:]
}
// NewStack is for library implementers that want to generate a stack trace.
// Normally you should insted use AddStack to get an error with a stack trace.
//
// The result of this function can be turned into a stack trace by calling .StackTrace()
//
// This function takes an argument for the number of stack frames to skip.
// This avoids putting stack generation function calls like this one in the stack trace.
// A value of 0 will give you the line that called NewStack(0)
// A library author wrapping this in their own function will want to use a value of at least 1.
func NewStack(skip int) StackTracer {
return callersSkip(skip + 3)
}
...@@ -14,11 +14,11 @@ package indexnode ...@@ -14,11 +14,11 @@ package indexnode
import "C" import "C"
import ( import (
"errors"
"fmt" "fmt"
"strconv"
"unsafe" "unsafe"
"errors"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb" "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/indexcgopb" "github.com/zilliztech/milvus-distributed/internal/proto/indexcgopb"
...@@ -49,7 +49,7 @@ func TryCatch(fn CFunc) error { ...@@ -49,7 +49,7 @@ func TryCatch(fn CFunc) error {
if errorCode != 0 { if errorCode != 0 {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return errors.New("error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return fmt.Errorf("error code = %d, error msg = %s", errorCode, errorMsg)
} }
return nil return nil
} }
...@@ -138,7 +138,7 @@ func (index *CIndex) Serialize() ([]*Blob, error) { ...@@ -138,7 +138,7 @@ func (index *CIndex) Serialize() ([]*Blob, error) {
if errorCode != 0 { if errorCode != 0 {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return nil, errors.New("SerializeToSlicedBuffer failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return nil, fmt.Errorf("SerializeToSlicedBuffer failed, C runtime error detected, error code = %d, err msg = %s", errorCode, errorMsg)
} }
binarySize := C.GetCBinarySize(cBinary) binarySize := C.GetCBinarySize(cBinary)
...@@ -179,7 +179,7 @@ func (index *CIndex) Load(blobs []*Blob) error { ...@@ -179,7 +179,7 @@ func (index *CIndex) Load(blobs []*Blob) error {
if errorCode != 0 { if errorCode != 0 {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return errors.New("BuildFloatVecIndexWithoutIds failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return fmt.Errorf("BuildFloatVecIndexWithoutIds failed, C runtime error detected, error code = %d, err msg = %s", errorCode, errorMsg)
} }
return nil return nil
} }
...@@ -197,7 +197,7 @@ func (index *CIndex) BuildFloatVecIndexWithoutIds(vectors []float32) error { ...@@ -197,7 +197,7 @@ func (index *CIndex) BuildFloatVecIndexWithoutIds(vectors []float32) error {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
fmt.Println("BuildFloatVecIndexWithoutIds error msg: ", errorMsg) fmt.Println("BuildFloatVecIndexWithoutIds error msg: ", errorMsg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return errors.New("BuildFloatVecIndexWithoutIds failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return fmt.Errorf("BuildFloatVecIndexWithoutIds failed, C runtime error detected, error code = %d, err msg = %s", errorCode, errorMsg)
} }
return nil return nil
} }
...@@ -212,7 +212,7 @@ func (index *CIndex) BuildBinaryVecIndexWithoutIds(vectors []byte) error { ...@@ -212,7 +212,7 @@ func (index *CIndex) BuildBinaryVecIndexWithoutIds(vectors []byte) error {
if errorCode != 0 { if errorCode != 0 {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return errors.New(" failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return fmt.Errorf("BuildBinaryVecIndexWithoutIds failed, C runtime error detected, error code = %d, err msg = %s", errorCode, errorMsg)
} }
return nil return nil
} }
...@@ -266,7 +266,7 @@ func NewCIndex(typeParams, indexParams map[string]string) (Index, error) { ...@@ -266,7 +266,7 @@ func NewCIndex(typeParams, indexParams map[string]string) (Index, error) {
errorMsg := C.GoString(status.error_msg) errorMsg := C.GoString(status.error_msg)
fmt.Println("EEEEEEEEEEEEEEEEEEEEEEEEEE error msg: ", errorMsg) fmt.Println("EEEEEEEEEEEEEEEEEEEEEEEEEE error msg: ", errorMsg)
defer C.free(unsafe.Pointer(status.error_msg)) defer C.free(unsafe.Pointer(status.error_msg))
return nil, errors.New(" failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg) return nil, fmt.Errorf(" failed, C runtime error detected, error code = %d, err msg = %s", errorCode, errorMsg)
} }
return &CIndex{ return &CIndex{
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment