From 91d40fa5580f34b4f08d3372a67e2069171dbd8c Mon Sep 17 00:00:00 2001 From: SimFG Date: Wed, 23 Apr 2025 10:52:38 +0800 Subject: [PATCH] fix: Update logging context and upgrade dependencies (#41318) - issue: #41291 --------- Signed-off-by: SimFG Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .env | 4 +- client/go.mod | 12 ++-- client/go.sum | 20 +++---- client/milvusclient/client.go | 3 +- client/row/schema.go | 2 +- cmd/tools/migration/backend/backup_restore.go | 9 +-- cmd/tools/migration/backend/etcd210.go | 17 +++--- cmd/tools/migration/migration/runner.go | 3 +- go.mod | 33 +++++------ go.sum | 59 +++++++++---------- internal/datacoord/channel_manager_test.go | 6 +- internal/datacoord/index_meta.go | 3 +- internal/datacoord/index_service.go | 3 +- internal/datacoord/index_service_test.go | 3 +- internal/datacoord/server.go | 3 +- .../datacoord/session/datanode_manager.go | 2 +- internal/datacoord/stats_task_meta_test.go | 14 ++--- internal/datacoord/task_stats.go | 3 +- internal/datacoord/task_stats_test.go | 14 ++--- internal/datanode/compactor/segment_writer.go | 7 ++- internal/datanode/index/scheduler_test.go | 5 +- internal/datanode/index/task.go | 5 +- internal/datanode/index/task_stats_test.go | 4 +- internal/datanode/index_services.go | 5 +- .../distributed/datanode/client/client.go | 5 +- .../datanode/client/client_test.go | 2 +- internal/distributed/datanode/service_test.go | 4 +- .../distributed/mixcoord/client/client.go | 5 +- internal/distributed/mixcoord/service_test.go | 3 +- internal/distributed/proxy/client/client.go | 5 +- .../proxy/httpserver/handler_v2_test.go | 11 ++-- .../distributed/proxy/httpserver/utils.go | 7 ++- .../proxy/httpserver/utils_test.go | 11 ++-- .../distributed/proxy/listener_manager.go | 3 +- internal/distributed/proxy/service.go | 3 +- internal/distributed/proxy/service_test.go | 4 +- .../distributed/querynode/client/client.go | 5 +- .../pipeline/flow_graph_embedding_node.go | 5 +- .../flushcommon/pipeline/testutils_test.go | 5 +- .../flushcommon/syncmgr/pack_writer_v2.go | 3 +- internal/flushcommon/syncmgr/sync_manager.go | 3 +- internal/kv/tikv/txn_tikv.go | 2 +- internal/kv/tikv/txn_tikv_test.go | 4 +- internal/metastore/kv/rootcoord/kv_catalog.go | 8 +-- .../metastore/kv/rootcoord/kv_catalog_test.go | 8 +-- internal/mocks/util/mock_segcore/mock_data.go | 12 ++-- .../convert_field_data_to_generic_value.go | 4 +- .../parser/planparserv2/error_listener.go | 3 +- .../planparserv2/fill_expression_value.go | 8 ++- internal/parser/planparserv2/operators.go | 33 ++++++----- .../parser/planparserv2/parser_visitor.go | 43 +++++++------- internal/parser/planparserv2/utils.go | 24 ++++---- .../proxy/accesslog/info/grpc_info_test.go | 3 +- internal/proxy/accesslog/info/util.go | 3 +- internal/proxy/accesslog/writer.go | 5 +- internal/proxy/connection/util.go | 5 +- internal/proxy/impl.go | 10 ++-- internal/proxy/impl_test.go | 3 +- internal/proxy/meta_cache_test.go | 8 +-- internal/proxy/proxy.go | 2 +- internal/proxy/search_util.go | 4 +- internal/proxy/segment.go | 2 +- internal/proxy/segment_test.go | 4 +- internal/proxy/task.go | 2 +- internal/proxy/task_delete.go | 4 +- internal/proxy/task_delete_test.go | 9 ++- internal/proxy/task_index.go | 10 ++-- internal/proxy/task_policies_test.go | 4 +- internal/proxy/task_query_test.go | 4 +- internal/proxy/task_scheduler_test.go | 5 +- internal/proxy/task_search_test.go | 12 ++-- internal/proxy/timestamp.go | 4 +- internal/proxy/util.go | 42 ++++++------- internal/proxy/util_test.go | 2 +- .../querycoordv2/meta/coordinator_broker.go | 3 +- internal/querycoordv2/server.go | 3 +- internal/querycoordv2/utils/util.go | 2 +- .../querynodev2/delegator/delegator_data.go | 2 +- .../delegator/delegator_data_test.go | 4 +- internal/querynodev2/delegator/idf_oracle.go | 4 +- .../querynodev2/pipeline/embedding_node.go | 7 ++- .../pipeline/embedding_node_test.go | 4 +- .../querynodev2/segments/index_attr_cache.go | 4 +- internal/querynodev2/segments/segment.go | 2 +- .../segments/segment_loader_test.go | 3 +- internal/querynodev2/segments/utils.go | 3 +- internal/querynodev2/server.go | 7 ++- internal/rootcoord/alter_alias_task_test.go | 4 +- internal/rootcoord/alter_collection_task.go | 7 +-- internal/rootcoord/alter_database_task.go | 3 +- internal/rootcoord/broker.go | 2 +- internal/rootcoord/create_collection_task.go | 2 +- internal/rootcoord/drop_alias_task_test.go | 4 +- internal/rootcoord/drop_db_task.go | 5 +- internal/rootcoord/drop_partition_task.go | 4 +- internal/rootcoord/garbage_collector_test.go | 7 +-- internal/rootcoord/meta_table.go | 46 +++++++-------- internal/rootcoord/quota_center_test.go | 4 +- .../rootcoord/rename_collection_task_test.go | 4 +- internal/rootcoord/root_coord.go | 2 +- internal/rootcoord/root_coord_test.go | 7 +-- internal/rootcoord/scheduler_test.go | 3 +- internal/rootcoord/timeticksync.go | 3 +- internal/rootcoord/undo.go | 4 +- internal/storage/binlog_test.go | 9 +-- internal/storage/binlog_writer.go | 21 +++---- internal/storage/data_codec.go | 21 +++---- internal/storage/event_reader.go | 6 +- internal/storage/field_stats.go | 5 +- internal/storage/field_value.go | 20 ++++--- internal/storage/index_data_codec.go | 2 +- internal/storage/payload_reader.go | 4 +- internal/storage/primary_key.go | 14 +++-- internal/storage/serde_events.go | 5 +- internal/storage/serde_events_v2.go | 3 +- internal/storage/stats.go | 4 +- internal/storage/utils.go | 4 +- internal/storagev2/packed/packed_writer.go | 4 +- .../alitext_embedding_provider_test.go | 4 +- .../function/bedrock_embedding_provider.go | 3 +- .../bedrock_text_embedding_provider_test.go | 4 +- internal/util/function/bm25_function.go | 7 ++- .../cohere_embedding_provider_test.go | 4 +- internal/util/function/function_executor.go | 3 +- .../ali/ali_dashscope_text_embedding.go | 6 +- .../models/cohere/cohere_text_embedding.go | 6 +- .../models/openai/openai_embedding.go | 6 +- .../siliconflow/siliconflow_text_embedding.go | 6 +- .../vertexai/vertexai_text_embedding.go | 7 ++- .../voyageai/voyageai_text_embedding.go | 6 +- .../openai_text_embedding_provider_test.go | 4 +- .../siliconflow_embedding_provider_test.go | 4 +- .../util/function/tei_embedding_provider.go | 4 +- .../function/tei_embedding_provider_test.go | 4 +- .../util/function/text_embedding_function.go | 16 ++--- .../function/vertexai_embedding_provider.go | 4 +- .../voyageai_embedding_provider_test.go | 4 +- internal/util/funcutil/count_util.go | 14 ++--- internal/util/grpcclient/client_test.go | 18 +++--- internal/util/grpcclient/local_grpc_client.go | 3 +- internal/util/hookutil/hook.go | 5 +- internal/util/idalloc/basic_allocator.go | 4 +- internal/util/importutilv2/csv/row_parser.go | 7 ++- internal/util/importutilv2/json/row_parser.go | 5 +- .../util/importutilv2/json/row_parser_test.go | 2 +- .../util/importutilv2/parquet/field_reader.go | 3 +- internal/util/indexcgowrapper/helper.go | 6 +- .../indexparamcheck/bitmap_index_checker.go | 8 +-- .../indexparamcheck/hybrid_index_checker.go | 6 +- .../util/indexparamcheck/stl_sort_checker.go | 4 +- internal/util/indexparamcheck/trie_checker.go | 4 +- .../indexparamcheck/vector_index_checker.go | 5 +- .../proxyutil/proxy_client_manager_test.go | 5 +- internal/util/segcore/reduce.go | 10 ++-- internal/util/sessionutil/session_util.go | 2 +- pkg/common/common.go | 2 +- pkg/go.mod | 20 +++---- pkg/go.sum | 36 +++++------ pkg/log/zap_log_test.go | 4 +- pkg/mq/common/message.go | 5 +- .../mqimpl/rocksmq/client/client_impl_test.go | 4 +- pkg/mq/mqimpl/rocksmq/client/util.go | 7 +-- pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go | 2 +- pkg/mq/msgstream/mq_msgstream.go | 6 +- .../mqwrapper/kafka/kafka_producer.go | 6 +- pkg/mq/msgstream/mqwrapper/nmq/nmq_client.go | 4 +- pkg/mq/msgstream/msgstream.go | 16 ++--- pkg/util/contextutil/context_util.go | 3 +- pkg/util/expr/expr.go | 9 +-- pkg/util/funcutil/func.go | 2 +- pkg/util/funcutil/policy.go | 8 +-- pkg/util/indexparams/index_params.go | 16 ++--- pkg/util/retry/retry_test.go | 6 +- pkg/util/typeutil/field_schema.go | 6 +- pkg/util/typeutil/float_util.go | 10 ++-- pkg/util/typeutil/schema.go | 22 +++---- tests/go_client/Dockerfile | 2 +- tests/go_client/go.mod | 14 ++--- tests/go_client/go.sum | 20 +++---- tests/integration/import/util_test.go | 3 +- tests/integration/upsert/upsert_test.go | 5 +- 181 files changed, 708 insertions(+), 643 deletions(-) diff --git a/.env b/.env index 1975e50506..c37bc7c87f 100644 --- a/.env +++ b/.env @@ -5,8 +5,8 @@ IMAGE_ARCH=amd64 OS_NAME=ubuntu22.04 # for services.builder.image in docker-compose.yml -DATE_VERSION=20250120-cb959cd -LATEST_DATE_VERSION=20250120-cb959cd +DATE_VERSION=20250421-ac1e043 +LATEST_DATE_VERSION=20250421-ac1e043 # for services.gpubuilder.image in docker-compose.yml GPU_DATE_VERSION=20240806-d8668fe LATEST_GPU_DATE_VERSION=20240806-d8668fe diff --git a/client/go.mod b/client/go.mod index 70cfc4e38c..b8b3376da5 100644 --- a/client/go.mod +++ b/client/go.mod @@ -1,6 +1,6 @@ module github.com/milvus-io/milvus/client/v2 -go 1.21 +go 1.24.1 require ( github.com/blang/semver/v4 v4.0.0 @@ -97,12 +97,12 @@ require ( go.uber.org/automaxprocs v1.5.3 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.31.0 // indirect + golang.org/x/crypto v0.35.0 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/net v0.36.0 // indirect + golang.org/x/sync v0.11.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect diff --git a/client/go.sum b/client/go.sum index f5805acbcf..73b3b34ad7 100644 --- a/client/go.sum +++ b/client/go.sum @@ -579,8 +579,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= +golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -634,8 +634,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= +golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -650,8 +650,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -698,8 +698,8 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -708,8 +708,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/client/milvusclient/client.go b/client/milvusclient/client.go index a8e58b0fc3..0d2c2581ee 100644 --- a/client/milvusclient/client.go +++ b/client/milvusclient/client.go @@ -26,6 +26,7 @@ import ( "sync" "time" + "github.com/cockroachdb/errors" grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -162,7 +163,7 @@ func (c *Client) setIdentifier(identifier string) { func (c *Client) connect(ctx context.Context, addr string, options ...grpc.DialOption) error { if addr == "" { - return fmt.Errorf("address is empty") + return errors.New("address is empty") } conn, err := grpc.DialContext(ctx, addr, options...) if err != nil { diff --git a/client/row/schema.go b/client/row/schema.go index bd0ee77256..5c410cef54 100644 --- a/client/row/schema.go +++ b/client/row/schema.go @@ -39,7 +39,7 @@ func ParseSchema(r interface{}) (*entity.Schema, error) { // MapRow is not supported for schema definition // TODO add PrimaryKey() interface later if t.Kind() == reflect.Map { - return nil, fmt.Errorf("map row is not supported for schema definition") + return nil, errors.New("map row is not supported for schema definition") } if t.Kind() != reflect.Struct { diff --git a/cmd/tools/migration/backend/backup_restore.go b/cmd/tools/migration/backend/backup_restore.go index 59678a3437..5181827dc8 100644 --- a/cmd/tools/migration/backend/backup_restore.go +++ b/cmd/tools/migration/backend/backup_restore.go @@ -5,6 +5,7 @@ import ( "fmt" "io" + "github.com/cockroachdb/errors" "google.golang.org/protobuf/proto" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -67,11 +68,11 @@ func (f *BackupFile) WriteEntry(k, v string) error { func (f *BackupFile) ReadHeader() (header *BackupHeader, headerLength uint64, err error) { if len(*f) < 8 { - return nil, 0, fmt.Errorf("invalid backup file, cannot read header length") + return nil, 0, errors.New("invalid backup file, cannot read header length") } headerLength = binary.LittleEndian.Uint64((*f)[:8]) if uint64(len(*f)) < 8+headerLength { - return nil, 0, fmt.Errorf("invalid backup file, cannot read header") + return nil, 0, errors.New("invalid backup file, cannot read header") } header = &BackupHeader{} if err := proto.Unmarshal((*f)[8:headerLength+8], header); err != nil { @@ -85,11 +86,11 @@ func (f *BackupFile) ReadEntryFromPos(pos uint64) (entryLength uint64, entry *co return 0, nil, io.EOF } if uint64(len(*f)) < pos+8 { - return 0, nil, fmt.Errorf("invalid backup file, cannot read entry length") + return 0, nil, errors.New("invalid backup file, cannot read entry length") } entryLength = binary.LittleEndian.Uint64((*f)[pos : pos+8]) if uint64(len(*f)) < pos+8+entryLength { - return 0, nil, fmt.Errorf("invalid backup file, cannot read entry") + return 0, nil, errors.New("invalid backup file, cannot read entry") } entry = &commonpb.KeyDataPair{} if err := proto.Unmarshal((*f)[pos+8:pos+8+entryLength], entry); err != nil { diff --git a/cmd/tools/migration/backend/etcd210.go b/cmd/tools/migration/backend/etcd210.go index 7b2d2b0733..6436259599 100644 --- a/cmd/tools/migration/backend/etcd210.go +++ b/cmd/tools/migration/backend/etcd210.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/cockroachdb/errors" clientv3 "go.etcd.io/etcd/client/v3" "google.golang.org/protobuf/proto" @@ -47,7 +48,7 @@ func (b etcd210) loadTtAliases() (meta.TtAliasesMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -79,7 +80,7 @@ func (b etcd210) loadAliases() (meta.AliasesMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -107,7 +108,7 @@ func (b etcd210) loadTtCollections() (meta.TtCollectionsMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -149,7 +150,7 @@ func (b etcd210) loadCollections() (meta.CollectionsMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -204,7 +205,7 @@ func (b etcd210) loadCollectionIndexes() (meta.CollectionIndexesMeta210, error) return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -232,7 +233,7 @@ func (b etcd210) loadSegmentIndexes() (meta.SegmentIndexesMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -255,7 +256,7 @@ func (b etcd210) loadIndexBuildMeta() (meta.IndexBuildMeta210, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } l := len(keys) for i := 0; i < l; i++ { @@ -284,7 +285,7 @@ func (b etcd210) loadLastDDLRecords() (meta.LastDDLRecords, error) { return nil, err } if len(keys) != len(values) { - return nil, fmt.Errorf("length mismatch") + return nil, errors.New("length mismatch") } for i, k := range keys { records.AddRecord(k, values[i]) diff --git a/cmd/tools/migration/migration/runner.go b/cmd/tools/migration/migration/runner.go index 0b19551cb0..555799f17a 100644 --- a/cmd/tools/migration/migration/runner.go +++ b/cmd/tools/migration/migration/runner.go @@ -8,6 +8,7 @@ import ( "time" "github.com/blang/semver/v4" + "github.com/cockroachdb/errors" clientv3 "go.etcd.io/etcd/client/v3" "go.uber.org/atomic" @@ -143,7 +144,7 @@ func (r *Runner) checkMySelf() error { } for _, session := range sessions { if session.Address != r.address { - return fmt.Errorf("other migration is running") + return errors.New("other migration is running") } } return nil diff --git a/go.mod b/go.mod index 74c77fab16..1ccd1741e5 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/milvus-io/milvus -go 1.22 - -toolchain go1.22.7 +go 1.24.1 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 @@ -10,7 +8,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.1.0 github.com/aliyun/credentials-go v1.2.7 // indirect github.com/apache/arrow/go/v17 v17.0.0 - github.com/bits-and-blooms/bloom/v3 v3.0.1 + github.com/bits-and-blooms/bloom/v3 v3.3.1 github.com/blang/semver/v4 v4.0.0 github.com/casbin/casbin/v2 v2.44.2 github.com/casbin/json-adapter/v2 v2.0.0 @@ -46,12 +44,12 @@ require ( go.uber.org/atomic v1.11.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.31.0 + golang.org/x/crypto v0.35.0 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 - golang.org/x/net v0.33.0 - golang.org/x/oauth2 v0.21.0 - golang.org/x/sync v0.10.0 - golang.org/x/text v0.21.0 + golang.org/x/net v0.36.0 + golang.org/x/oauth2 v0.27.0 + golang.org/x/sync v0.11.0 + golang.org/x/text v0.22.0 google.golang.org/grpc v1.65.0 google.golang.org/grpc/examples v0.0.0-20220617181431-3e7b97febc7f ) @@ -64,7 +62,7 @@ require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.47 github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.23.0 github.com/bits-and-blooms/bitset v1.10.0 - github.com/bytedance/sonic v1.12.2 + github.com/bytedance/sonic v1.13.2 github.com/cenkalti/backoff/v4 v4.2.1 github.com/cockroachdb/redact v1.1.3 github.com/goccy/go-json v0.10.3 @@ -121,12 +119,11 @@ require ( github.com/aws/smithy-go v1.22.1 // indirect github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/campoy/embedmd v1.0.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cilium/ebpf v0.11.0 // indirect - github.com/cloudwego/base64x v0.1.4 // indirect - github.com/cloudwego/iasm v0.2.0 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect github.com/confluentinc/confluent-kafka-go v1.9.1 // indirect github.com/containerd/cgroups/v3 v3.0.3 // indirect @@ -208,7 +205,6 @@ require ( github.com/panjf2000/ants/v2 v2.7.2 // indirect github.com/pelletier/go-toml v1.9.3 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pierrec/lz4 v2.5.2+incompatible // indirect github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c // indirect @@ -224,7 +220,6 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/xid v1.5.0 // indirect - github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/shirou/gopsutil v3.20.11+incompatible // indirect github.com/shirou/gopsutil/v3 v3.23.7 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect @@ -246,7 +241,7 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/twmb/murmur3 v1.1.3 // indirect + github.com/twmb/murmur3 v1.1.6 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect @@ -273,8 +268,8 @@ require ( go.uber.org/automaxprocs v1.5.3 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/mod v0.18.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/term v0.27.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/term v0.29.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.22.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect @@ -296,7 +291,7 @@ replace ( github.com/apache/arrow/go/v17 => github.com/milvus-io/arrow/go/v17 v17.0.0 github.com/apache/pulsar-client-go => github.com/milvus-io/pulsar-client-go v0.12.1 github.com/bketelsen/crypt => github.com/bketelsen/crypt v0.0.4 // Fix security alert for core-os/etcd - github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8 + github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9 github.com/go-kit/kit => github.com/go-kit/kit v0.1.0 github.com/greatroar/blobloom => github.com/milvus-io/blobloom v0.0.0-20240603110411-471ae49f3b93 github.com/ianlancetaylor/cgosymbolizer => github.com/milvus-io/cgosymbolizer v0.0.0-20250318084424-114f4050c3a6 diff --git a/go.sum b/go.sum index 61b3c0fecd..3d16ffbc62 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1 github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= -github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8 h1:boN3QhAWQU9O8EYQWxN7AEYav39PuD29QzZwTiI8Ca0= -github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= +github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9 h1:p/1Prokv2YkGbcyLV/gOD28Gr3VgMXIa0c9ulg5KjOY= +github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/actgardner/gogen-avro/v10 v10.1.0/go.mod h1:o+ybmVjEa27AAr35FRqU98DJu1fXES56uXniYFv4yDA= @@ -164,21 +164,21 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bits-and-blooms/bitset v1.3.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/bits-and-blooms/bloom/v3 v3.0.1 h1:Inlf0YXbgehxVjMPmCGv86iMCKMGPPrPSHtBF5yRHwA= -github.com/bits-and-blooms/bloom/v3 v3.0.1/go.mod h1:MC8muvBzzPOFsrcdND/A7kU7kMhkqb9KI70JlZCP+C8= +github.com/bits-and-blooms/bloom/v3 v3.3.1 h1:K2+A19bXT8gJR5mU7y+1yW6hsKfNCjcP2uNfLFKncjQ= +github.com/bits-and-blooms/bloom/v3 v3.3.1/go.mod h1:bhUUknWd5khVbTe4UgMCSiOOVJzr3tMoijSK3WwvW90= github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg= -github.com/bytedance/sonic v1.12.2/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= -github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= github.com/campoy/embedmd v1.0.0 h1:V4kI2qTJJLf4J29RzI/MAt2c3Bl4dQSYPuflzwFH2hY= github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8= github.com/casbin/casbin/v2 v2.0.0/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= @@ -202,9 +202,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/cilium/ebpf v0.11.0 h1:V8gS/bTCCjX9uUnkUFUpPsksM8n1lXBAvHcpiFk1X2Y= github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUgWsVs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= -github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -818,8 +817,6 @@ github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5d github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY= github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI= @@ -920,8 +917,6 @@ github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFo github.com/samber/lo v1.27.0 h1:GOyDWxsblvqYobqsmUuMddPa2/mMzkKyojlXol4+LaQ= github.com/samber/lo v1.27.0/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= -github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= -github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sbinet/npyio v0.6.0 h1:IyqqQIzRjDym9xnIXsToCKei/qCzxDP+Y74KoMlMgXo= github.com/sbinet/npyio v0.6.0/go.mod h1:/q3BNr6dJOy+t6h7RZchTJ0nwRJO52mivaem29WE1j8= @@ -1034,8 +1029,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1 github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/twmb/murmur3 v1.1.3 h1:D83U0XYKcHRYwYIpBKf3Pks91Z0Byda/9SJ8B6EMRcA= -github.com/twmb/murmur3 v1.1.3/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= +github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg= +github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o= github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= @@ -1197,8 +1192,8 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= +golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1301,8 +1296,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= +golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1315,8 +1310,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= +golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1329,8 +1324,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1416,11 +1411,11 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= -golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= +golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1430,8 +1425,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/datacoord/channel_manager_test.go b/internal/datacoord/channel_manager_test.go index 71cf1332e5..907c56f8bb 100644 --- a/internal/datacoord/channel_manager_test.go +++ b/internal/datacoord/channel_manager_test.go @@ -18,10 +18,10 @@ package datacoord import ( "context" - "errors" "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -673,7 +673,7 @@ func (s *ChannelManagerSuite) TestAdvanceChannelState() { } s.prepareMeta(chNodes, datapb.ChannelWatchState_ToWatch) s.mockCluster.EXPECT().NotifyChannelOperation(mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("mock error")).Twice() + Return(errors.New("mock error")).Twice() m, err := NewChannelManager(s.mockKv, s.mockHandler, s.mockCluster, s.mockAlloc) s.Require().NoError(err) s.checkAssignment(m, 1, "ch1", ToWatch) @@ -706,7 +706,7 @@ func (s *ChannelManagerSuite) TestAdvanceChannelState() { } s.prepareMeta(chNodes, datapb.ChannelWatchState_ToRelease) s.mockCluster.EXPECT().NotifyChannelOperation(mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("mock error")).Twice() + Return(errors.New("mock error")).Twice() m, err := NewChannelManager(s.mockKv, s.mockHandler, s.mockCluster, s.mockAlloc) s.Require().NoError(err) s.checkAssignment(m, 1, "ch1", ToRelease) diff --git a/internal/datacoord/index_meta.go b/internal/datacoord/index_meta.go index 9b0a7801ff..74149d2131 100644 --- a/internal/datacoord/index_meta.go +++ b/internal/datacoord/index_meta.go @@ -24,6 +24,7 @@ import ( "sync" "time" + "github.com/cockroachdb/errors" "github.com/hashicorp/golang-lru/v2/expirable" "github.com/prometheus/client_golang/prometheus" "github.com/samber/lo" @@ -398,7 +399,7 @@ func (m *indexMeta) canCreateIndex(req *indexpb.CreateIndexRequest, isJson bool) // creating multiple indexes on same field is not supported errMsg := "CreateIndex failed: creating multiple indexes on same field is not supported" log.Warn(errMsg) - return 0, fmt.Errorf(errMsg) + return 0, errors.New(errMsg) } } return 0, nil diff --git a/internal/datacoord/index_service.go b/internal/datacoord/index_service.go index 429c57a07e..373cc8b0ed 100644 --- a/internal/datacoord/index_service.go +++ b/internal/datacoord/index_service.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/cockroachdb/errors" "github.com/samber/lo" "go.uber.org/zap" @@ -229,7 +230,7 @@ func (s *Server) parseAndVerifyNestedPath(identifier string, schema *schemapb.Co return "", err } if identifierExpr.GetColumnExpr().GetInfo().GetFieldId() != fieldID { - return "", fmt.Errorf("fieldID not match with field name") + return "", errors.New("fieldID not match with field name") } nestedPath := identifierExpr.GetColumnExpr().GetInfo().GetNestedPath() diff --git a/internal/datacoord/index_service_test.go b/internal/datacoord/index_service_test.go index 1bf799ea47..370e4503ba 100644 --- a/internal/datacoord/index_service_test.go +++ b/internal/datacoord/index_service_test.go @@ -18,7 +18,6 @@ package datacoord import ( "context" - "fmt" "testing" "time" @@ -114,7 +113,7 @@ func TestServer_CreateIndex(t *testing.T) { b := mocks.NewMixCoord(t) t.Run("get field name failed", func(t *testing.T) { - b.EXPECT().DescribeCollectionInternal(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock error")) + b.EXPECT().DescribeCollectionInternal(mock.Anything, mock.Anything).Return(nil, errors.New("mock error")) s.broker = broker.NewCoordinatorBroker(b) resp, err := s.CreateIndex(ctx, req) diff --git a/internal/datacoord/server.go b/internal/datacoord/server.go index 24a2d60d70..9b4bc31a5a 100644 --- a/internal/datacoord/server.go +++ b/internal/datacoord/server.go @@ -27,6 +27,7 @@ import ( "time" "github.com/blang/semver/v4" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/tidwall/gjson" "github.com/tikv/client-go/v2/txnkv" @@ -400,7 +401,7 @@ func (s *Server) SetSession(session sessionutil.SessionInterface) error { s.session = session s.icSession = session if s.session == nil { - return fmt.Errorf("session is nil, the etcd client connection may have failed") + return errors.New("session is nil, the etcd client connection may have failed") } return nil } diff --git a/internal/datacoord/session/datanode_manager.go b/internal/datacoord/session/datanode_manager.go index 113f7f52f4..b38803fd68 100644 --- a/internal/datacoord/session/datanode_manager.go +++ b/internal/datacoord/session/datanode_manager.go @@ -337,7 +337,7 @@ func (c *DataNodeManagerImpl) GetCompactionPlanResult(nodeID int64, planID int64 if resp.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success { log.Info("GetCompactionState state is not", zap.Error(err)) - return nil, fmt.Errorf("GetCopmactionState failed") + return nil, errors.New("GetCopmactionState failed") } var result *datapb.CompactionPlanResult for _, rst := range resp.GetResults() { diff --git a/internal/datacoord/stats_task_meta_test.go b/internal/datacoord/stats_task_meta_test.go index a154d3ad3b..329145c758 100644 --- a/internal/datacoord/stats_task_meta_test.go +++ b/internal/datacoord/stats_task_meta_test.go @@ -18,9 +18,9 @@ package datacoord import ( "context" - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -76,7 +76,7 @@ func (s *statsTaskMetaSuite) Test_Method() { s.Run("failed case", func() { catalog := mocks.NewDataCoordCatalog(s.T()) - catalog.EXPECT().ListStatsTasks(mock.Anything).Return(nil, fmt.Errorf("mock error")) + catalog.EXPECT().ListStatsTasks(mock.Anything).Return(nil, errors.New("mock error")) m, err := newStatsTaskMeta(context.Background(), catalog) s.Error(err) @@ -105,7 +105,7 @@ func (s *statsTaskMetaSuite) Test_Method() { s.Run("AddStatsTask", func() { s.Run("failed case", func() { - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() s.Error(m.AddStatsTask(t)) _, ok := m.tasks.Get(1) @@ -145,7 +145,7 @@ func (s *statsTaskMetaSuite) Test_Method() { }) s.Run("failed case", func() { - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() s.Error(m.UpdateVersion(1, 1180)) task, ok := m.tasks.Get(1) @@ -157,7 +157,7 @@ func (s *statsTaskMetaSuite) Test_Method() { s.Run("UpdateBuildingTask", func() { s.Run("failed case", func() { - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() s.Error(m.UpdateBuildingTask(1)) task, ok := m.tasks.Get(1) @@ -214,7 +214,7 @@ func (s *statsTaskMetaSuite) Test_Method() { NumRows: 2048, } s.Run("failed case", func() { - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() s.Error(m.FinishTask(1, result)) task, ok := m.tasks.Get(1) @@ -265,7 +265,7 @@ func (s *statsTaskMetaSuite) Test_Method() { s.Run("DropStatsTask", func() { s.Run("failed case", func() { - catalog.EXPECT().DropStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + catalog.EXPECT().DropStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() s.Error(m.DropStatsTask(1)) _, ok := m.tasks.Get(1) diff --git a/internal/datacoord/task_stats.go b/internal/datacoord/task_stats.go index 6646b6271e..aa30f3a729 100644 --- a/internal/datacoord/task_stats.go +++ b/internal/datacoord/task_stats.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus/internal/types" @@ -151,7 +152,7 @@ func (st *statsTask) UpdateVersion(ctx context.Context, nodeID int64, meta *meta // reset compacting meta.SetSegmentsCompacting(ctx, []UniqueID{st.segmentID}, false) st.SetStartTime(time.Now()) - return fmt.Errorf("segment is contains by l0 compaction") + return errors.New("segment is contains by l0 compaction") } if err := meta.statsTaskMeta.UpdateVersion(st.taskID, nodeID); err != nil { diff --git a/internal/datacoord/task_stats_test.go b/internal/datacoord/task_stats_test.go index 04f86d519c..36500c91f2 100644 --- a/internal/datacoord/task_stats_test.go +++ b/internal/datacoord/task_stats_test.go @@ -18,10 +18,10 @@ package datacoord import ( "context" - "fmt" "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" "go.uber.org/atomic" @@ -201,7 +201,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { compactionHandler := NewMockCompactionPlanContext(s.T()) compactionHandler.EXPECT().checkAndSetSegmentStating(mock.Anything, mock.Anything).Return(true) - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("error")).Once() s.Error(st.UpdateVersion(context.Background(), 1, s.mt, compactionHandler)) }) }) @@ -216,7 +216,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { }) s.Run("update error", func() { - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("error")).Once() + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("error")).Once() s.Error(st.UpdateMetaBuildingState(s.mt)) }) }) @@ -250,7 +250,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { s.mt.segments.segments[s.segID].IsSorted = false handler := NewNMockHandler(s.T()) - handler.EXPECT().GetCollection(context.Background(), collID).Return(nil, fmt.Errorf("mock error")).Once() + handler.EXPECT().GetCollection(context.Background(), collID).Return(nil, errors.New("mock error")).Once() checkPass := st.PreCheck(context.Background(), &taskScheduler{ meta: s.mt, handler: handler, @@ -298,7 +298,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { s.Run("alloc failed", func() { alloc := allocator.NewMockAllocator(s.T()) - alloc.EXPECT().AllocN(mock.Anything).Return(0, 0, fmt.Errorf("mock error")) + alloc.EXPECT().AllocN(mock.Anything).Return(0, 0, errors.New("mock error")) handler := NewNMockHandler(s.T()) handler.EXPECT().GetCollection(context.Background(), collID).Return(&collectionInfo{ @@ -578,7 +578,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { s.Run("set target segment failed", func() { catalog := catalogmocks.NewDataCoordCatalog(s.T()) s.mt.catalog = catalog - catalog.EXPECT().AlterSegments(mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")) + catalog.EXPECT().AlterSegments(mock.Anything, mock.Anything, mock.Anything).Return(errors.New("mock error")) s.Error(st.SetJobInfo(s.mt)) }) @@ -587,7 +587,7 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { s.mt.catalog = catalog s.mt.statsTaskMeta.catalog = catalog catalog.EXPECT().AlterSegments(mock.Anything, mock.Anything, mock.Anything).Return(nil) - catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")) + catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(errors.New("mock error")) s.Error(st.SetJobInfo(s.mt)) }) diff --git a/internal/datanode/compactor/segment_writer.go b/internal/datanode/compactor/segment_writer.go index e88066762d..9520d47ef1 100644 --- a/internal/datanode/compactor/segment_writer.go +++ b/internal/datanode/compactor/segment_writer.go @@ -22,6 +22,7 @@ import ( "math" "github.com/apache/arrow/go/v17/arrow/array" + "github.com/cockroachdb/errors" "github.com/samber/lo" "go.uber.org/atomic" "go.uber.org/zap" @@ -382,7 +383,7 @@ func (w *SegmentWriter) WriteRecord(r storage.Record) error { for fieldID, stats := range w.bm25Stats { field, ok := r.Column(fieldID).(*array.Binary) if !ok { - return fmt.Errorf("bm25 field value not found") + return errors.New("bm25 field value not found") } stats.AppendBytes(field.Value(i)) } @@ -405,12 +406,12 @@ func (w *SegmentWriter) Write(v *storage.Value) error { for fieldID, stats := range w.bm25Stats { data, ok := v.Value.(map[storage.FieldID]interface{})[fieldID] if !ok { - return fmt.Errorf("bm25 field value not found") + return errors.New("bm25 field value not found") } bytes, ok := data.([]byte) if !ok { - return fmt.Errorf("bm25 field value not sparse bytes") + return errors.New("bm25 field value not sparse bytes") } stats.AppendBytes(bytes) } diff --git a/internal/datanode/index/scheduler_test.go b/internal/datanode/index/scheduler_test.go index 53adb95d10..501484bc24 100644 --- a/internal/datanode/index/scheduler_test.go +++ b/internal/datanode/index/scheduler_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/milvus-io/milvus/pkg/v2/proto/indexpb" @@ -65,7 +66,7 @@ func (s *stagectx) Done() <-chan struct{} { func (s *stagectx) Err() error { select { case <-s.ch: - return fmt.Errorf("canceled") + return errors.New("canceled") default: return nil } @@ -189,7 +190,7 @@ func TestIndexTaskScheduler(t *testing.T) { newTask(fakeTaskPrepared, nil, indexpb.JobState_JobStateRetry), newTask(fakeTaskBuiltIndex, nil, indexpb.JobState_JobStateRetry), newTask(fakeTaskSavedIndexes, nil, indexpb.JobState_JobStateFinished), - newTask(fakeTaskSavedIndexes, map[fakeTaskState]error{fakeTaskSavedIndexes: fmt.Errorf("auth failed")}, indexpb.JobState_JobStateRetry)) + newTask(fakeTaskSavedIndexes, map[fakeTaskState]error{fakeTaskSavedIndexes: errors.New("auth failed")}, indexpb.JobState_JobStateRetry)) for _, task := range tasks { assert.Nil(t, scheduler.TaskQueue.Enqueue(task)) diff --git a/internal/datanode/index/task.go b/internal/datanode/index/task.go index 9c6078326c..6f96cc339b 100644 --- a/internal/datanode/index/task.go +++ b/internal/datanode/index/task.go @@ -18,14 +18,15 @@ package index import ( "context" - "fmt" + + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus/pkg/v2/proto/indexpb" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" ) var ( - errCancel = fmt.Errorf("canceled") + errCancel = errors.New("canceled") DiskUsageRatio = 4.0 ) diff --git a/internal/datanode/index/task_stats_test.go b/internal/datanode/index/task_stats_test.go index 16ae9c78fa..b166f5188d 100644 --- a/internal/datanode/index/task_stats_test.go +++ b/internal/datanode/index/task_stats_test.go @@ -18,10 +18,10 @@ package index import ( "context" - "fmt" "testing" "time" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -145,7 +145,7 @@ func (s *TaskStatsSuite) TestSortSegmentWithBM25() { } return result, nil }) - s.mockBinlogIO.EXPECT().Upload(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")).Once() + s.mockBinlogIO.EXPECT().Upload(mock.Anything, mock.Anything).Return(errors.New("mock error")).Once() ctx, cancel := context.WithCancel(context.Background()) diff --git a/internal/datanode/index_services.go b/internal/datanode/index_services.go index 441dc9ec91..7a2c183828 100644 --- a/internal/datanode/index_services.go +++ b/internal/datanode/index_services.go @@ -21,6 +21,7 @@ import ( "fmt" "strconv" + "github.com/cockroachdb/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -491,7 +492,7 @@ func (node *DataNode) QueryJobsV2(ctx context.Context, req *workerpb.QueryJobsV2 default: log.Warn("DataNode receive querying unknown type jobs") return &workerpb.QueryJobsV2Response{ - Status: merr.Status(fmt.Errorf("DataNode receive querying unknown type jobs")), + Status: merr.Status(errors.New("DataNode receive querying unknown type jobs")), }, nil } } @@ -552,6 +553,6 @@ func (node *DataNode) DropJobsV2(ctx context.Context, req *workerpb.DropJobsV2Re return merr.Success(), nil default: log.Warn("DataNode receive dropping unknown type jobs") - return merr.Status(fmt.Errorf("DataNode receive dropping unknown type jobs")), nil + return merr.Status(errors.New("DataNode receive dropping unknown type jobs")), nil } } diff --git a/internal/distributed/datanode/client/client.go b/internal/distributed/datanode/client/client.go index b8339988e6..2131a01f97 100644 --- a/internal/distributed/datanode/client/client.go +++ b/internal/distributed/datanode/client/client.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "google.golang.org/grpc" @@ -58,11 +59,11 @@ type Client struct { // NewClient creates a client for DataNode. func NewClient(ctx context.Context, addr string, serverID int64, encryption bool) (types.DataNodeClient, error) { if addr == "" { - return nil, fmt.Errorf("address is empty") + return nil, errors.New("address is empty") } sess := sessionutil.NewSession(ctx) if sess == nil { - err := fmt.Errorf("new session error, maybe can not connect to etcd") + err := errors.New("new session error, maybe can not connect to etcd") log.Ctx(ctx).Debug("DataNodeClient New Etcd Session failed", zap.Error(err)) return nil, err } diff --git a/internal/distributed/datanode/client/client_test.go b/internal/distributed/datanode/client/client_test.go index 5469546dc3..0987c43785 100644 --- a/internal/distributed/datanode/client/client_test.go +++ b/internal/distributed/datanode/client/client_test.go @@ -18,9 +18,9 @@ package grpcdatanodeclient import ( "context" - "errors" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "google.golang.org/grpc" diff --git a/internal/distributed/datanode/service_test.go b/internal/distributed/datanode/service_test.go index 2e0839aacb..e0eddb8f63 100644 --- a/internal/distributed/datanode/service_test.go +++ b/internal/distributed/datanode/service_test.go @@ -18,9 +18,9 @@ package grpcdatanode import ( "context" - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -212,7 +212,7 @@ func Test_Run(t *testing.T) { datanode.EXPECT().SetAddress(mock.Anything).Return() datanode.EXPECT().SetMixCoordClient(mock.Anything).Return(nil) datanode.EXPECT().UpdateStateCode(mock.Anything).Return() - datanode.EXPECT().Init().Return(fmt.Errorf("mock err")) + datanode.EXPECT().Init().Return(errors.New("mock err")) server.datanode = datanode err = server.Prepare() diff --git a/internal/distributed/mixcoord/client/client.go b/internal/distributed/mixcoord/client/client.go index f9b85e7ddf..35a03296bf 100644 --- a/internal/distributed/mixcoord/client/client.go +++ b/internal/distributed/mixcoord/client/client.go @@ -18,7 +18,6 @@ package grpcmixcoordclient import ( "context" - "fmt" "github.com/cockroachdb/errors" "go.uber.org/zap" @@ -70,7 +69,7 @@ type Client struct { func NewClient(ctx context.Context) (types.MixCoordClient, error) { sess := sessionutil.NewSession(ctx) if sess == nil { - err := fmt.Errorf("new session error, maybe can not connect to etcd") + err := errors.New("new session error, maybe can not connect to etcd") log.Ctx(ctx).Debug("New MixCoord Client failed", zap.Error(err)) return nil, err } @@ -118,7 +117,7 @@ func (c *Client) getMixCoordAddr() (string, error) { ms, ok := msess[key] if !ok { log.Warn("MixCoordClient mess key not exist", zap.Any("key", key)) - return "", fmt.Errorf("find no available mixcoord, check mixcoord state") + return "", errors.New("find no available mixcoord, check mixcoord state") } log.Debug("MixCoordClient GetSessions success", zap.String("address", ms.Address), diff --git a/internal/distributed/mixcoord/service_test.go b/internal/distributed/mixcoord/service_test.go index 222c5a2ff9..d7f8ad9799 100644 --- a/internal/distributed/mixcoord/service_test.go +++ b/internal/distributed/mixcoord/service_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/tikv/client-go/v2/txnkv" @@ -115,7 +116,7 @@ func (m *mockMix) Start() error { } func (m *mockMix) Stop() error { - return fmt.Errorf("stop error") + return errors.New("stop error") } func (m *mockMix) GracefulStop() { diff --git a/internal/distributed/proxy/client/client.go b/internal/distributed/proxy/client/client.go index 00f8878dea..80918bb226 100644 --- a/internal/distributed/proxy/client/client.go +++ b/internal/distributed/proxy/client/client.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "google.golang.org/grpc" @@ -50,11 +51,11 @@ type Client struct { // NewClient creates a new client instance func NewClient(ctx context.Context, addr string, nodeID int64) (types.ProxyClient, error) { if addr == "" { - return nil, fmt.Errorf("address is empty") + return nil, errors.New("address is empty") } sess := sessionutil.NewSession(ctx) if sess == nil { - err := fmt.Errorf("new session error, maybe can not connect to etcd") + err := errors.New("new session error, maybe can not connect to etcd") log.Ctx(ctx).Debug("Proxy client new session failed", zap.Error(err)) return nil, err } diff --git a/internal/distributed/proxy/httpserver/handler_v2_test.go b/internal/distributed/proxy/httpserver/handler_v2_test.go index b4e62202bd..55b47d8835 100644 --- a/internal/distributed/proxy/httpserver/handler_v2_test.go +++ b/internal/distributed/proxy/httpserver/handler_v2_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cockroachdb/errors" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -2043,9 +2044,9 @@ func validateTestCases(t *testing.T, testEngine *gin.Engine, queryTestCases []re returnBody := &ReturnErrMsg{} err := json.Unmarshal(w.Body.Bytes(), returnBody) assert.Nil(t, err, "case %d: ", i) - assert.Equal(t, testcase.errCode, returnBody.Code, "case %d: ", i, string(testcase.requestBody)) + assert.Equal(t, testcase.errCode, returnBody.Code, "case: %d, request body: %s ", i, string(testcase.requestBody)) if testcase.errCode != 0 { - assert.Equal(t, testcase.errMsg, returnBody.Message, "case %d: ", i, string(testcase.requestBody)) + assert.Contains(t, returnBody.Message, testcase.errMsg, "case: %d, request body: %s", i, string(testcase.requestBody)) } fmt.Println(w.Body.String()) }) @@ -2069,7 +2070,7 @@ func TestDML(t *testing.T) { if matchCountRule(req.OutputFields) { for _, pair := range req.QueryParams { if pair.GetKey() == ParamLimit { - return nil, fmt.Errorf("mock error") + return nil, errors.New("mock error") } } } @@ -2459,7 +2460,7 @@ func TestSearchV2(t *testing.T) { queryTestCases = append(queryTestCases, requestBodyTestCase{ path: SearchAction, requestBody: []byte(`{"collectionName": "book", "data": [["0.1", "0.2"]], "filter": "book_id in [2, 4, 6, 8]", "limit": 4, "outputFields": ["word_count"], "params": {"radius":0.9, "range_filter": 0.1}, "groupingField": "test"}`), - errMsg: "can only accept json format request, error: Mismatch type float32 with value string \"at index 9: mismatched type with value\\n\\n\\t[[\\\"0.1\\\", \\\"0.2\\\"]]\\n\\t.........^......\\n\": invalid parameter[expected=FloatVector][actual=[[\"0.1\", \"0.2\"]]]", + errMsg: "can only accept json format request, error: Mismatch type float32 with value", errCode: 1801, }) queryTestCases = append(queryTestCases, requestBodyTestCase{ @@ -2501,7 +2502,7 @@ func TestSearchV2(t *testing.T) { queryTestCases = append(queryTestCases, requestBodyTestCase{ path: SearchAction, requestBody: []byte(`{"collectionName": "book", "data": [[0.1, 0.2]], "annsField": "binaryVector", "filter": "book_id in [2, 4, 6, 8]", "limit": 4, "outputFields": ["word_count"]}`), - errMsg: "can only accept json format request, error: Mismatch type uint8 with value number \"at index 7: mismatched type with value\\n\\n\\t[[0.1, 0.2]]\\n\\t.......^....\\n\": invalid parameter[expected=BinaryVector][actual=[[0.1, 0.2]]]", + errMsg: "can only accept json format request, error: Mismatch type uint8", errCode: 1801, }) queryTestCases = append(queryTestCases, requestBodyTestCase{ diff --git a/internal/distributed/proxy/httpserver/utils.go b/internal/distributed/proxy/httpserver/utils.go index 1b32098f80..3c216a47d5 100644 --- a/internal/distributed/proxy/httpserver/utils.go +++ b/internal/distributed/proxy/httpserver/utils.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cockroachdb/errors" "github.com/gin-gonic/gin" "github.com/spf13/cast" "github.com/tidwall/gjson" @@ -734,7 +735,7 @@ func convertToIntArray(dataType schemapb.DataType, arr interface{}) []int32 { func anyToColumns(rows []map[string]interface{}, validDataMap map[string][]bool, sch *schemapb.CollectionSchema, inInsert bool) ([]*schemapb.FieldData, error) { rowsLen := len(rows) if rowsLen == 0 { - return []*schemapb.FieldData{}, fmt.Errorf("no row need to be convert to columns") + return []*schemapb.FieldData{}, errors.New("no row need to be convert to columns") } isDynamic := sch.EnableDynamicField @@ -1359,7 +1360,7 @@ func buildQueryResp(rowsNum int64, needFields []string, fieldDataList []*schemap stringPks := ids.GetStrId().GetData() rowsNum = int64(len(stringPks)) default: - return nil, fmt.Errorf("the type of primary key(id) is not supported, use other sdk please") + return nil, errors.New("the type of primary key(id) is not supported, use other sdk please") } } } @@ -1496,7 +1497,7 @@ func buildQueryResp(rowsNum int64, needFields []string, fieldDataList []*schemap stringPks := ids.GetStrId().GetData() row[DefaultPrimaryFieldName] = stringPks[i] default: - return nil, fmt.Errorf("the type of primary key(id) is not supported, use other sdk please") + return nil, errors.New("the type of primary key(id) is not supported, use other sdk please") } } if scores != nil && int64(len(scores)) > i { diff --git a/internal/distributed/proxy/httpserver/utils_test.go b/internal/distributed/proxy/httpserver/utils_test.go index 834ca2e59e..cef21437ba 100644 --- a/internal/distributed/proxy/httpserver/utils_test.go +++ b/internal/distributed/proxy/httpserver/utils_test.go @@ -17,6 +17,7 @@ package httpserver import ( + "fmt" "math" "strconv" "strings" @@ -1087,14 +1088,14 @@ func TestConvertQueries2Placeholder(t *testing.T) { dataType, 0, func() [][]byte { - return [][]byte{nil, nil} + return [][]byte{{}, {}} }, }, { `"{"data": [""]}"`, dataType, 0, func() [][]byte { - return [][]byte{nil} + return [][]byte{{}} }, }, }...) @@ -1159,7 +1160,8 @@ func TestConvertQueries2Placeholder(t *testing.T) { for _, testcase := range testCases { phv, err := convertQueries2Placeholder(testcase.requestBody, testcase.dataType, testcase.dim) assert.Nil(t, err) - assert.Equal(t, testcase.placehoderValue(), phv.GetValues()) + assert.Equal(t, testcase.placehoderValue(), phv.GetValues(), + fmt.Sprintf("check equal fail, data: %s, type: %s, dim: %d", testcase.requestBody, testcase.dataType, testcase.dim)) } for _, testcase := range []testCase{ @@ -1186,7 +1188,8 @@ func TestConvertQueries2Placeholder(t *testing.T) { } { phv, err := convertQueries2Placeholder(testcase.requestBody, testcase.dataType, testcase.dim) assert.Nil(t, err) - assert.NotEqual(t, testcase.placehoderValue(), phv.GetValues()) + assert.NotEqual(t, testcase.placehoderValue(), phv.GetValues(), + fmt.Sprintf("check not equal fail, data: %s, type: %s, dim: %d", testcase.requestBody, testcase.dataType, testcase.dim)) } for _, testcase := range []testCase{ diff --git a/internal/distributed/proxy/listener_manager.go b/internal/distributed/proxy/listener_manager.go index ee2fc15245..3abc097340 100644 --- a/internal/distributed/proxy/listener_manager.go +++ b/internal/distributed/proxy/listener_manager.go @@ -20,7 +20,6 @@ import ( "context" "crypto/tls" "crypto/x509" - "fmt" "net" "github.com/cockroachdb/errors" @@ -136,7 +135,7 @@ func newHTTPListner(ctx context.Context, l *listenerManager) error { } if !certPool.AppendCertsFromPEM(rootBuf) { log.Warn("fail to append ca to cert") - return fmt.Errorf("fail to append ca to cert") + return errors.New("fail to append ca to cert") } tlsConf = &tls.Config{ ClientAuth: tls.RequireAndVerifyClientCert, diff --git a/internal/distributed/proxy/service.go b/internal/distributed/proxy/service.go index af4ab75d3f..6c1d400685 100644 --- a/internal/distributed/proxy/service.go +++ b/internal/distributed/proxy/service.go @@ -29,6 +29,7 @@ import ( "sync" "time" + "github.com/cockroachdb/errors" "github.com/gin-gonic/gin" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/soheilhy/cmux" @@ -297,7 +298,7 @@ func (s *Server) startExternalGrpc(errChan chan error) { } if !certPool.AppendCertsFromPEM(rootBuf) { log.Warn("fail to append ca to cert") - errChan <- fmt.Errorf("fail to append ca to cert") + errChan <- errors.New("fail to append ca to cert") return } diff --git a/internal/distributed/proxy/service_test.go b/internal/distributed/proxy/service_test.go index c55f1e776a..0e26a23815 100644 --- a/internal/distributed/proxy/service_test.go +++ b/internal/distributed/proxy/service_test.go @@ -715,7 +715,7 @@ func TestServer_Check(t *testing.T) { assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, ret.Status) mockProxy.ExpectedCalls = nil - mockProxy.EXPECT().GetComponentStates(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock grpc unexpected error")) + mockProxy.EXPECT().GetComponentStates(mock.Anything, mock.Anything).Return(nil, errors.New("mock grpc unexpected error")) ret, err = server.Check(ctx, req) assert.Error(t, err) @@ -769,7 +769,7 @@ func TestServer_Watch(t *testing.T) { assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, ret.Status) mockProxy.ExpectedCalls = nil - mockProxy.EXPECT().GetComponentStates(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock grpc unexpected error")) + mockProxy.EXPECT().GetComponentStates(mock.Anything, mock.Anything).Return(nil, errors.New("mock grpc unexpected error")) err = server.Watch(req, watchServer) ret = <-resultChan diff --git a/internal/distributed/querynode/client/client.go b/internal/distributed/querynode/client/client.go index 3626fe7e91..0ca588819f 100644 --- a/internal/distributed/querynode/client/client.go +++ b/internal/distributed/querynode/client/client.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "google.golang.org/grpc" @@ -52,11 +53,11 @@ type Client struct { // NewClient creates a new QueryNode client. func NewClient(ctx context.Context, addr string, nodeID int64) (types.QueryNodeClient, error) { if addr == "" { - return nil, fmt.Errorf("addr is empty") + return nil, errors.New("addr is empty") } sess := sessionutil.NewSession(ctx) if sess == nil { - err := fmt.Errorf("new session error, maybe can not connect to etcd") + err := errors.New("new session error, maybe can not connect to etcd") log.Ctx(ctx).Debug("QueryNodeClient NewClient failed", zap.Error(err)) return nil, err } diff --git a/internal/flushcommon/pipeline/flow_graph_embedding_node.go b/internal/flushcommon/pipeline/flow_graph_embedding_node.go index 084598d429..b447d1c1d8 100644 --- a/internal/flushcommon/pipeline/flow_graph_embedding_node.go +++ b/internal/flushcommon/pipeline/flow_graph_embedding_node.go @@ -19,6 +19,7 @@ package pipeline import ( "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -86,7 +87,7 @@ func (eNode *embeddingNode) bm25Embedding(runner function.FunctionRunner, inputF embeddingData, ok := data.Data[inputFieldId].GetDataRows().([]string) if !ok { - return fmt.Errorf("BM25 embedding failed: input field data not varchar/text") + return errors.New("BM25 embedding failed: input field data not varchar/text") } output, err := runner.BatchRun(embeddingData) @@ -96,7 +97,7 @@ func (eNode *embeddingNode) bm25Embedding(runner function.FunctionRunner, inputF sparseArray, ok := output[0].(*schemapb.SparseFloatArray) if !ok { - return fmt.Errorf("BM25 embedding failed: BM25 runner output not sparse map") + return errors.New("BM25 embedding failed: BM25 runner output not sparse map") } meta[outputFieldId].AppendBytes(sparseArray.GetContents()...) diff --git a/internal/flushcommon/pipeline/testutils_test.go b/internal/flushcommon/pipeline/testutils_test.go index cc36a033f2..2b170b45c5 100644 --- a/internal/flushcommon/pipeline/testutils_test.go +++ b/internal/flushcommon/pipeline/testutils_test.go @@ -20,7 +20,6 @@ import ( "bytes" "context" "encoding/binary" - "fmt" "math" "github.com/cockroachdb/errors" @@ -833,7 +832,7 @@ func (m *RootCoordFactory) AllocTimestamp(ctx context.Context, in *rootcoordpb.A v := ctx.Value(ctxKey{}) if v != nil && v.(string) == returnError { resp.Status.ErrorCode = commonpb.ErrorCode_UnexpectedError - return resp, fmt.Errorf("injected error") + return resp, errors.New("injected error") } return resp, nil @@ -876,7 +875,7 @@ func (m *RootCoordFactory) ShowPartitions(ctx context.Context, req *milvuspb.Sho if m.ShowPartitionsErr { return &milvuspb.ShowPartitionsResponse{ Status: merr.Success(), - }, fmt.Errorf("mock show partitions error") + }, errors.New("mock show partitions error") } if m.ShowPartitionsNotSuccess { diff --git a/internal/flushcommon/syncmgr/pack_writer_v2.go b/internal/flushcommon/syncmgr/pack_writer_v2.go index 990c2c455d..e7df64f1b3 100644 --- a/internal/flushcommon/syncmgr/pack_writer_v2.go +++ b/internal/flushcommon/syncmgr/pack_writer_v2.go @@ -23,6 +23,7 @@ import ( "github.com/apache/arrow/go/v17/arrow/array" "github.com/apache/arrow/go/v17/arrow/memory" + "github.com/cockroachdb/errors" "github.com/samber/lo" "go.uber.org/zap" @@ -181,7 +182,7 @@ func (bw *BulkPackWriterV2) splitInsertData(insertData []*storage.InsertData, sp } uniqueRows := lo.Uniq(lo.Values(rowNums)) if len(uniqueRows) != 1 || uniqueRows[0] == 0 { - return nil, fmt.Errorf("row num is not equal for each field") + return nil, errors.New("row num is not equal for each field") } for i, field := range bw.metaCache.Schema().GetFields() { if _, ok := memorySizes[field.FieldID]; !ok { diff --git a/internal/flushcommon/syncmgr/sync_manager.go b/internal/flushcommon/syncmgr/sync_manager.go index f334f625e0..3b5519ba2f 100644 --- a/internal/flushcommon/syncmgr/sync_manager.go +++ b/internal/flushcommon/syncmgr/sync_manager.go @@ -6,6 +6,7 @@ import ( "strconv" "time" + "github.com/cockroachdb/errors" "github.com/hashicorp/golang-lru/v2/expirable" "go.uber.org/zap" @@ -104,7 +105,7 @@ func (mgr *syncManager) resizeHandler(evt *config.Event) { func (mgr *syncManager) SyncData(ctx context.Context, task Task, callbacks ...func(error) error) (*conc.Future[struct{}], error) { if mgr.workerPool.IsClosed() { - return nil, fmt.Errorf("sync manager is closed") + return nil, errors.New("sync manager is closed") } switch t := task.(type) { diff --git a/internal/kv/tikv/txn_tikv.go b/internal/kv/tikv/txn_tikv.go index 6086da9f30..85dee924f0 100644 --- a/internal/kv/tikv/txn_tikv.go +++ b/internal/kv/tikv/txn_tikv.go @@ -747,7 +747,7 @@ func (kv *txnTiKV) removeTiKVMeta(ctx context.Context, key string) error { } func (kv *txnTiKV) CompareVersionAndSwap(ctx context.Context, key string, version int64, target string) (bool, error) { - err := fmt.Errorf("Unimplemented! CompareVersionAndSwap is under deprecation") + err := errors.New("Unimplemented! CompareVersionAndSwap is under deprecation") logWarnOnFailure(&err, "Unimplemented") return false, err } diff --git a/internal/kv/tikv/txn_tikv_test.go b/internal/kv/tikv/txn_tikv_test.go index caabead599..9c6ca62d7f 100644 --- a/internal/kv/tikv/txn_tikv_test.go +++ b/internal/kv/tikv/txn_tikv_test.go @@ -301,7 +301,7 @@ func TestTiKVLoad(te *testing.T) { defer kv.Close() beginTxn = func(txn *txnkv.Client) (*transaction.KVTxn, error) { - return nil, fmt.Errorf("bad txn!") + return nil, errors.New("bad txn!") } defer func() { beginTxn = tiTxnBegin @@ -326,7 +326,7 @@ func TestTiKVLoad(te *testing.T) { defer kv.Close() commitTxn = func(ctx context.Context, txn *transaction.KVTxn) error { - return fmt.Errorf("bad txn commit!") + return errors.New("bad txn commit!") } defer func() { commitTxn = tiTxnCommit diff --git a/internal/metastore/kv/rootcoord/kv_catalog.go b/internal/metastore/kv/rootcoord/kv_catalog.go index a320f6c930..120f6a96ff 100644 --- a/internal/metastore/kv/rootcoord/kv_catalog.go +++ b/internal/metastore/kv/rootcoord/kv_catalog.go @@ -631,7 +631,7 @@ func (kc *Catalog) DropCollection(ctx context.Context, collectionInfo *model.Col func (kc *Catalog) alterModifyCollection(ctx context.Context, oldColl *model.Collection, newColl *model.Collection, ts typeutil.Timestamp) error { if oldColl.TenantID != newColl.TenantID || oldColl.CollectionID != newColl.CollectionID { - return fmt.Errorf("altering tenant id or collection id is forbidden") + return errors.New("altering tenant id or collection id is forbidden") } oldCollClone := oldColl.Clone() oldCollClone.DBID = newColl.DBID @@ -683,7 +683,7 @@ func (kc *Catalog) AlterCollection(ctx context.Context, oldColl *model.Collectio func (kc *Catalog) alterModifyPartition(ctx context.Context, oldPart *model.Partition, newPart *model.Partition, ts typeutil.Timestamp) error { if oldPart.CollectionID != newPart.CollectionID || oldPart.PartitionID != newPart.PartitionID { - return fmt.Errorf("altering collection id or partition id is forbidden") + return errors.New("altering collection id or partition id is forbidden") } oldPartClone := oldPart.Clone() newPartClone := newPart.Clone() @@ -1102,7 +1102,7 @@ func (kc *Catalog) ListRole(ctx context.Context, tenant string, entity *milvuspb } } else { if funcutil.IsEmptyString(entity.Name) { - return results, fmt.Errorf("role name in the role entity is empty") + return results, errors.New("role name in the role entity is empty") } roleKey := funcutil.HandleTenantForEtcdKey(RolePrefix, tenant, entity.Name) _, err := kc.Txn.Load(ctx, roleKey) @@ -1177,7 +1177,7 @@ func (kc *Catalog) ListUser(ctx context.Context, tenant string, entity *milvuspb } } else { if funcutil.IsEmptyString(entity.Name) { - return results, fmt.Errorf("username in the user entity is empty") + return results, errors.New("username in the user entity is empty") } _, err = kc.GetCredential(ctx, entity.Name) if err != nil { diff --git a/internal/metastore/kv/rootcoord/kv_catalog_test.go b/internal/metastore/kv/rootcoord/kv_catalog_test.go index 5da728a256..d149382def 100644 --- a/internal/metastore/kv/rootcoord/kv_catalog_test.go +++ b/internal/metastore/kv/rootcoord/kv_catalog_test.go @@ -1644,7 +1644,7 @@ func TestRBAC_Role(t *testing.T) { notExistKey = "not-exist" errorKey = "error" - otherError = fmt.Errorf("mock load error") + otherError = errors.New("mock load error") ) kvmock.EXPECT().Load(mock.Anything, notExistKey).Return("", merr.WrapErrIoKeyNotFound(notExistKey)).Once() @@ -1688,7 +1688,7 @@ func TestRBAC_Role(t *testing.T) { notExistKey = "not-exist" errorKey = "error" - otherError = fmt.Errorf("mock load error") + otherError = errors.New("mock load error") ) kvmock.EXPECT().Load(mock.Anything, notExistKey).Return("", merr.WrapErrIoKeyNotFound(notExistKey)).Once() @@ -1735,7 +1735,7 @@ func TestRBAC_Role(t *testing.T) { notExistPath = funcutil.HandleTenantForEtcdKey(RolePrefix, tenant, notExistName) errorName = "error" errorPath = funcutil.HandleTenantForEtcdKey(RolePrefix, tenant, errorName) - otherError = fmt.Errorf("mock load error") + otherError = errors.New("mock load error") ) kvmock.EXPECT().Load(mock.Anything, notExistPath).Return("", merr.WrapErrIoKeyNotFound(notExistName)).Once() @@ -3075,7 +3075,7 @@ func TestCatalog_AlterDatabase(t *testing.T) { func TestCatalog_listFunctionError(t *testing.T) { mockSnapshot := newMockSnapshot(t) kc := NewCatalog(nil, mockSnapshot).(*Catalog) - mockSnapshot.EXPECT().LoadWithPrefix(mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("mock error")) + mockSnapshot.EXPECT().LoadWithPrefix(mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, errors.New("mock error")) _, err := kc.listFunctions(context.TODO(), 1, 1) assert.Error(t, err) diff --git a/internal/mocks/util/mock_segcore/mock_data.go b/internal/mocks/util/mock_segcore/mock_data.go index 24e1e920ae..8e7b1903fb 100644 --- a/internal/mocks/util/mock_segcore/mock_data.go +++ b/internal/mocks/util/mock_segcore/mock_data.go @@ -1003,7 +1003,7 @@ func genDSLByIndexType(schema *schemapb.CollectionSchema, indexType string) (str } else if indexType == IndexHNSW { return genHNSWDSL(schema, ef, defaultTopK, defaultRoundDecimal) } - return "", fmt.Errorf("Invalid indexType") + return "", errors.New("Invalid indexType") } func genBruteForceDSL(schema *schemapb.CollectionSchema, topK int64, roundDecimal int64) (string, error) { @@ -1094,7 +1094,7 @@ func CheckSearchResult(ctx context.Context, nq int64, plan *segcore.SearchPlan, return err } if len(blob) == 0 { - return fmt.Errorf("wrong search result data blobs when checkSearchResult") + return errors.New("wrong search result data blobs when checkSearchResult") } result := &schemapb.SearchResultData{} @@ -1104,17 +1104,17 @@ func CheckSearchResult(ctx context.Context, nq int64, plan *segcore.SearchPlan, } if result.TopK != sliceTopKs[i] { - return fmt.Errorf("unexpected topK when checkSearchResult") + return errors.New("unexpected topK when checkSearchResult") } if result.NumQueries != sInfo.SliceNQs[i] { - return fmt.Errorf("unexpected nq when checkSearchResult") + return errors.New("unexpected nq when checkSearchResult") } // search empty segment, return empty result.IDs if len(result.Ids.IdField.(*schemapb.IDs_IntId).IntId.Data) <= 0 { - return fmt.Errorf("unexpected Ids when checkSearchResult") + return errors.New("unexpected Ids when checkSearchResult") } if len(result.Scores) <= 0 { - return fmt.Errorf("unexpected Scores when checkSearchResult") + return errors.New("unexpected Scores when checkSearchResult") } } diff --git a/internal/parser/planparserv2/convert_field_data_to_generic_value.go b/internal/parser/planparserv2/convert_field_data_to_generic_value.go index c9e4f052a0..6168204926 100644 --- a/internal/parser/planparserv2/convert_field_data_to_generic_value.go +++ b/internal/parser/planparserv2/convert_field_data_to_generic_value.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/json" "github.com/milvus-io/milvus/pkg/v2/proto/planpb" @@ -136,7 +138,7 @@ func ConvertToGenericValue(templateName string, templateValue *schemapb.Template case *schemapb.TemplateValue_ArrayVal: return convertArrayValue(templateName, templateValue.GetArrayVal()) default: - return nil, fmt.Errorf("expression elements can only be scalars") + return nil, errors.New("expression elements can only be scalars") } } diff --git a/internal/parser/planparserv2/error_listener.go b/internal/parser/planparserv2/error_listener.go index 87be54cff9..008b18ca67 100644 --- a/internal/parser/planparserv2/error_listener.go +++ b/internal/parser/planparserv2/error_listener.go @@ -2,7 +2,6 @@ package planparserv2 import ( "fmt" - "strconv" "github.com/antlr4-go/antlr/v4" ) @@ -18,7 +17,7 @@ type errorListenerImpl struct { } func (l *errorListenerImpl) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { - l.err = fmt.Errorf("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg) + l.err = fmt.Errorf("line %d:%d %s", line, column, msg) } func (l *errorListenerImpl) Error() error { diff --git a/internal/parser/planparserv2/fill_expression_value.go b/internal/parser/planparserv2/fill_expression_value.go index 2ba36f7ede..282b00c7d6 100644 --- a/internal/parser/planparserv2/fill_expression_value.go +++ b/internal/parser/planparserv2/fill_expression_value.go @@ -3,6 +3,8 @@ package planparserv2 import ( "fmt" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/proto/planpb" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -129,11 +131,11 @@ func FillBinaryRangeExpressionValue(expr *planpb.BinaryRangeExpr, templateValues if !(expr.GetLowerInclusive() && expr.GetUpperInclusive()) { if getGenericValue(GreaterEqual(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } else { if getGenericValue(Greater(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } @@ -168,7 +170,7 @@ func FillBinaryArithOpEvalRangeExpressionValue(expr *planpb.BinaryArithOpEvalRan } if operand.GetArrayVal() != nil { - return fmt.Errorf("can not comparisons array directly") + return errors.New("can not comparisons array directly") } dataType, err = getTargetType(lDataType, rDataType) diff --git a/internal/parser/planparserv2/operators.go b/internal/parser/planparserv2/operators.go index da5890f436..dc1080e328 100644 --- a/internal/parser/planparserv2/operators.go +++ b/internal/parser/planparserv2/operators.go @@ -1,9 +1,10 @@ package planparserv2 import ( - "fmt" "math" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" parser "github.com/milvus-io/milvus/internal/parser/planparserv2/generated" "github.com/milvus-io/milvus/pkg/v2/proto/planpb" @@ -182,21 +183,21 @@ func Divide(a, b *planpb.GenericValue) (*ExprWithType, error) { } if IsBool(a) || IsBool(b) { - return nil, fmt.Errorf("divide cannot apply on bool field") + return nil, errors.New("divide cannot apply on bool field") } if IsString(a) || IsString(b) { - return nil, fmt.Errorf("divide cannot apply on string field") + return nil, errors.New("divide cannot apply on string field") } aFloat, bFloat, aInt, bInt := IsFloating(a), IsFloating(b), IsInteger(a), IsInteger(b) if bFloat && b.GetFloatVal() == 0 { - return nil, fmt.Errorf("cannot divide by zero") + return nil, errors.New("cannot divide by zero") } if bInt && b.GetInt64Val() == 0 { - return nil, fmt.Errorf("cannot divide by zero") + return nil, errors.New("cannot divide by zero") } if aFloat && bFloat { @@ -228,12 +229,12 @@ func Modulo(a, b *planpb.GenericValue) (*ExprWithType, error) { aInt, bInt := IsInteger(a), IsInteger(b) if !aInt || !bInt { - return nil, fmt.Errorf("modulo can only apply on integer") + return nil, errors.New("modulo can only apply on integer") } // aInt && bInt if b.GetInt64Val() == 0 { - return nil, fmt.Errorf("cannot modulo by zero") + return nil, errors.New("cannot modulo by zero") } ret.dataType = schemapb.DataType_Int64 @@ -281,29 +282,29 @@ func Power(a, b *planpb.GenericValue) *ExprWithType { } func BitAnd(a, b *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func BitOr(a, b *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func BitXor(a, b *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func ShiftLeft(a, b *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func ShiftRight(a, b *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func And(a, b *planpb.GenericValue) (*ExprWithType, error) { aBool, bBool := IsBool(a), IsBool(b) if !aBool || !bBool { - return nil, fmt.Errorf("and can only apply on boolean") + return nil, errors.New("and can only apply on boolean") } return &ExprWithType{ dataType: schemapb.DataType_Bool, @@ -320,7 +321,7 @@ func And(a, b *planpb.GenericValue) (*ExprWithType, error) { func Or(a, b *planpb.GenericValue) (*ExprWithType, error) { aBool, bBool := IsBool(a), IsBool(b) if !aBool || !bBool { - return nil, fmt.Errorf("or can only apply on boolean") + return nil, errors.New("or can only apply on boolean") } return &ExprWithType{ dataType: schemapb.DataType_Bool, @@ -335,7 +336,7 @@ func Or(a, b *planpb.GenericValue) (*ExprWithType, error) { } func BitNot(a *planpb.GenericValue) (*ExprWithType, error) { - return nil, fmt.Errorf("todo: unsupported") + return nil, errors.New("todo: unsupported") } func Negative(a *planpb.GenericValue) *ExprWithType { @@ -419,7 +420,7 @@ func less() relationalFn { return a.GetInt64Val() < b.GetInt64Val(), nil } - return false, fmt.Errorf("incompatible data type") + return false, errors.New("incompatible data type") } } diff --git a/internal/parser/planparserv2/parser_visitor.go b/internal/parser/planparserv2/parser_visitor.go index 38eb5a5ddd..f48fbeeecc 100644 --- a/internal/parser/planparserv2/parser_visitor.go +++ b/internal/parser/planparserv2/parser_visitor.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/antlr4-go/antlr/v4" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" parser "github.com/milvus-io/milvus/internal/parser/planparserv2/generated" @@ -157,7 +158,7 @@ func (v *ParserVisitor) VisitString(ctx *parser.StringContext) interface{} { func checkDirectComparisonBinaryField(columnInfo *planpb.ColumnInfo) error { if typeutil.IsArrayType(columnInfo.GetDataType()) && len(columnInfo.GetNestedPath()) == 0 { - return fmt.Errorf("can not comparisons array fields directly") + return errors.New("can not comparisons array fields directly") } return nil } @@ -446,12 +447,12 @@ func (v *ParserVisitor) VisitLike(ctx *parser.LikeContext) interface{} { leftExpr := getExpr(left) if leftExpr == nil { - return fmt.Errorf("the left operand of like is invalid") + return errors.New("the left operand of like is invalid") } column := toColumnInfo(leftExpr) if column == nil { - return fmt.Errorf("like operation on complicated expr is unsupported") + return errors.New("like operation on complicated expr is unsupported") } if err := checkDirectComparisonBinaryField(column); err != nil { return err @@ -459,7 +460,7 @@ func (v *ParserVisitor) VisitLike(ctx *parser.LikeContext) interface{} { if !typeutil.IsStringType(leftExpr.dataType) && !typeutil.IsJSONType(leftExpr.dataType) && !(typeutil.IsArrayType(leftExpr.dataType) && typeutil.IsStringType(column.GetElementType())) { - return fmt.Errorf("like operation on non-string or no-json field is unsupported") + return errors.New("like operation on non-string or no-json field is unsupported") } pattern, err := convertEscapeSingle(ctx.StringLiteral().GetText()) @@ -496,10 +497,10 @@ func (v *ParserVisitor) VisitTextMatch(ctx *parser.TextMatchContext) interface{} return fmt.Errorf("field %v does not enable text match", columnInfo.FieldId) } if !typeutil.IsStringType(column.dataType) { - return fmt.Errorf("text match operation on non-string is unsupported") + return errors.New("text match operation on non-string is unsupported") } if column.dataType == schemapb.DataType_Text { - return fmt.Errorf("text match operation on text field is not supported yet") + return errors.New("text match operation on text field is not supported yet") } queryText, err := convertEscapeSingle(ctx.StringLiteral().GetText()) @@ -527,7 +528,7 @@ func (v *ParserVisitor) VisitPhraseMatch(ctx *parser.PhraseMatchContext) interfa return err } if !typeutil.IsStringType(column.dataType) { - return fmt.Errorf("phrase match operation on non-string is unsupported") + return errors.New("phrase match operation on non-string is unsupported") } queryText, err := convertEscapeSingle(ctx.StringLiteral().GetText()) if err != nil { @@ -770,11 +771,11 @@ func (v *ParserVisitor) VisitRange(ctx *parser.RangeContext) interface{} { if !isTemplateExpr(lowerValueExpr) && !isTemplateExpr(upperValueExpr) { if !(lowerInclusive && upperInclusive) { if getGenericValue(GreaterEqual(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } else { if getGenericValue(Greater(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } } @@ -852,11 +853,11 @@ func (v *ParserVisitor) VisitReverseRange(ctx *parser.ReverseRangeContext) inter if !isTemplateExpr(lowerValueExpr) && !isTemplateExpr(upperValueExpr) { if !(lowerInclusive && upperInclusive) { if getGenericValue(GreaterEqual(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } else { if getGenericValue(Greater(lowerValue, upperValue)).GetBoolVal() { - return fmt.Errorf("invalid range: lowerbound is greater than upperbound") + return errors.New("invalid range: lowerbound is greater than upperbound") } } } @@ -904,10 +905,10 @@ func (v *ParserVisitor) VisitUnary(ctx *parser.UnaryContext) interface{} { childExpr := getExpr(child) if childExpr == nil { - return fmt.Errorf("failed to parse unary expressions") + return errors.New("failed to parse unary expressions") } if isRandomSampleExpr(childExpr) { - return fmt.Errorf("random sample expression cannot be used in unary expression") + return errors.New("random sample expression cannot be used in unary expression") } if err := checkDirectComparisonBinaryField(toColumnInfo(childExpr)); err != nil { @@ -957,7 +958,7 @@ func (v *ParserVisitor) VisitLogicalOr(ctx *parser.LogicalOrContext) interface{} } if leftValue != nil || rightValue != nil { - return fmt.Errorf("'or' can only be used between boolean expressions") + return errors.New("'or' can only be used between boolean expressions") } var leftExpr *ExprWithType @@ -965,11 +966,11 @@ func (v *ParserVisitor) VisitLogicalOr(ctx *parser.LogicalOrContext) interface{} leftExpr = getExpr(left) rightExpr = getExpr(right) if isRandomSampleExpr(leftExpr) || isRandomSampleExpr(rightExpr) { - return fmt.Errorf("random sample expression cannot be used in logical and expression") + return errors.New("random sample expression cannot be used in logical and expression") } if !canBeExecuted(leftExpr) || !canBeExecuted(rightExpr) { - return fmt.Errorf("'or' can only be used between boolean expressions") + return errors.New("'or' can only be used between boolean expressions") } expr := &planpb.Expr{ Expr: &planpb.Expr_BinaryExpr{ @@ -1009,7 +1010,7 @@ func (v *ParserVisitor) VisitLogicalAnd(ctx *parser.LogicalAndContext) interface } if leftValue != nil || rightValue != nil { - return fmt.Errorf("'and' can only be used between boolean expressions") + return errors.New("'and' can only be used between boolean expressions") } var leftExpr *ExprWithType @@ -1017,11 +1018,11 @@ func (v *ParserVisitor) VisitLogicalAnd(ctx *parser.LogicalAndContext) interface leftExpr = getExpr(left) rightExpr = getExpr(right) if isRandomSampleExpr(leftExpr) { - return fmt.Errorf("random sample expression can only be the last expression in the logical and expression") + return errors.New("random sample expression can only be the last expression in the logical and expression") } if !canBeExecuted(leftExpr) || !canBeExecuted(rightExpr) { - return fmt.Errorf("'and' can only be used between boolean expressions") + return errors.New("'and' can only be used between boolean expressions") } var expr *planpb.Expr @@ -1132,7 +1133,7 @@ func (v *ParserVisitor) getColumnInfoFromJSONIdentifier(identifier string) (*pla if field.GetDataType() != schemapb.DataType_JSON && field.GetDataType() != schemapb.DataType_Array { errMsg := fmt.Sprintf("%s data type not supported accessed with []", field.GetDataType()) - return nil, fmt.Errorf(errMsg) + return nil, fmt.Errorf("%s", errMsg) } if fieldName != field.Name { nestedPath = append(nestedPath, fieldName) @@ -1151,7 +1152,7 @@ func (v *ParserVisitor) getColumnInfoFromJSONIdentifier(identifier string) (*pla return nil, fmt.Errorf("invalid identifier: %s", identifier) } if typeutil.IsArrayType(field.DataType) { - return nil, fmt.Errorf("can only access array field with integer index") + return nil, errors.New("can only access array field with integer index") } } else if _, err := strconv.ParseInt(path, 10, 64); err != nil { return nil, fmt.Errorf("json key must be enclosed in double quotes or single quotes: \"%s\"", path) diff --git a/internal/parser/planparserv2/utils.go b/internal/parser/planparserv2/utils.go index 0c399d589f..621f2fa8fd 100644 --- a/internal/parser/planparserv2/utils.go +++ b/internal/parser/planparserv2/utils.go @@ -7,6 +7,8 @@ import ( "strings" "unicode" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/json" "github.com/milvus-io/milvus/pkg/v2/proto/planpb" @@ -294,12 +296,12 @@ func handleBinaryArithExpr(op planpb.OpType, arithExpr *planpb.BinaryArithExpr, if leftExpr != nil && rightExpr != nil { // a + b == 3 - return nil, fmt.Errorf("not supported to do arithmetic operations between multiple fields") + return nil, errors.New("not supported to do arithmetic operations between multiple fields") } if leftValue != nil && rightValue != nil { // 2 + 1 == 3 - return nil, fmt.Errorf("unexpected, should be optimized already") + return nil, errors.New("unexpected, should be optimized already") } if leftExpr != nil && rightValue != nil { @@ -320,11 +322,11 @@ func handleBinaryArithExpr(op planpb.OpType, arithExpr *planpb.BinaryArithExpr, case planpb.ArithOpType_Add, planpb.ArithOpType_Mul: return combineBinaryArithExpr(op, arithOp, arithExprDataType, rightExpr.GetInfo(), leftValue, valueExpr) default: - return nil, fmt.Errorf("module field is not yet supported") + return nil, errors.New("module field is not yet supported") } } else { // (a + b) / 2 == 3 - return nil, fmt.Errorf("complicated arithmetic operations are not supported") + return nil, errors.New("complicated arithmetic operations are not supported") } } @@ -348,7 +350,7 @@ func handleCompareRightValue(op planpb.OpType, left *ExprWithType, right *planpb columnInfo := toColumnInfo(left) if columnInfo == nil { - return nil, fmt.Errorf("not supported to combine multiple fields") + return nil, errors.New("not supported to combine multiple fields") } expr := &planpb.Expr{ Expr: &planpb.Expr_UnaryRangeExpr{ @@ -388,7 +390,7 @@ func handleCompare(op planpb.OpType, left *ExprWithType, right *ExprWithType) (* } if leftColumnInfo == nil || rightColumnInfo == nil { - return nil, fmt.Errorf("only comparison between two fields is supported") + return nil, errors.New("only comparison between two fields is supported") } expr := &planpb.Expr{ @@ -629,7 +631,7 @@ func checkValidModArith(tokenType planpb.ArithOpType, leftType, leftElementType, switch tokenType { case planpb.ArithOpType_Mod: if !canConvertToIntegerType(leftType, leftElementType) || !canConvertToIntegerType(rightType, rightElementType) { - return fmt.Errorf("modulo can only apply on integer types") + return errors.New("modulo can only apply on integer types") } default: } @@ -640,17 +642,17 @@ func castRangeValue(dataType schemapb.DataType, value *planpb.GenericValue) (*pl switch dataType { case schemapb.DataType_String, schemapb.DataType_VarChar: if !IsString(value) { - return nil, fmt.Errorf("invalid range operations") + return nil, errors.New("invalid range operations") } case schemapb.DataType_Bool: - return nil, fmt.Errorf("invalid range operations on boolean expr") + return nil, errors.New("invalid range operations on boolean expr") case schemapb.DataType_Int8, schemapb.DataType_Int16, schemapb.DataType_Int32, schemapb.DataType_Int64: if !IsInteger(value) { - return nil, fmt.Errorf("invalid range operations") + return nil, errors.New("invalid range operations") } case schemapb.DataType_Float, schemapb.DataType_Double: if !IsNumber(value) { - return nil, fmt.Errorf("invalid range operations") + return nil, errors.New("invalid range operations") } if IsInteger(value) { return NewFloat(float64(value.GetInt64Val())), nil diff --git a/internal/proxy/accesslog/info/grpc_info_test.go b/internal/proxy/accesslog/info/grpc_info_test.go index f10619c9e7..3022112ee8 100644 --- a/internal/proxy/accesslog/info/grpc_info_test.go +++ b/internal/proxy/accesslog/info/grpc_info_test.go @@ -22,6 +22,7 @@ import ( "net" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -99,7 +100,7 @@ func (s *GrpcAccessInfoSuite) TestErrorMsg() { s.Equal(merr.ErrChannelLack.Error(), result[0]) // replace line breaks - s.info.resp = merr.Status(fmt.Errorf("test error. stack: 1:\n 2:\n 3:\n")) + s.info.resp = merr.Status(errors.New("test error. stack: 1:\n 2:\n 3:\n")) result = Get(s.info, "$error_msg") s.Equal("test error. stack: 1:\\n 2:\\n 3:\\n", result[0]) diff --git a/internal/proxy/accesslog/info/util.go b/internal/proxy/accesslog/info/util.go index ff119f5b33..0dcfa5e88f 100644 --- a/internal/proxy/accesslog/info/util.go +++ b/internal/proxy/accesslog/info/util.go @@ -21,6 +21,7 @@ import ( "fmt" "strings" + "github.com/cockroachdb/errors" "go.uber.org/atomic" "google.golang.org/grpc/metadata" @@ -35,7 +36,7 @@ var ClusterPrefix atomic.String func getCurUserFromContext(ctx context.Context) (string, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { - return "", fmt.Errorf("fail to get md from the context") + return "", errors.New("fail to get md from the context") } authorization, ok := md[strings.ToLower(util.HeaderAuthorize)] if !ok || len(authorization) < 1 { diff --git a/internal/proxy/accesslog/writer.go b/internal/proxy/accesslog/writer.go index 9b77141275..8540b21029 100644 --- a/internal/proxy/accesslog/writer.go +++ b/internal/proxy/accesslog/writer.go @@ -26,6 +26,7 @@ import ( "sync" "time" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus/pkg/v2/log" @@ -78,7 +79,7 @@ func (l *CacheWriter) Write(p []byte) (n int, err error) { l.mu.Lock() defer l.mu.Unlock() if l.closed { - return 0, fmt.Errorf("write to closed writer") + return 0, errors.New("write to closed writer") } return l.writer.Write(p) @@ -197,7 +198,7 @@ func (l *RotateWriter) Write(p []byte) (n int, err error) { defer l.mu.Unlock() if l.closed { - return 0, fmt.Errorf("write to closed writer") + return 0, errors.New("write to closed writer") } writeLen := int64(len(p)) diff --git a/internal/proxy/connection/util.go b/internal/proxy/connection/util.go index 424aac5525..fae7a592aa 100644 --- a/internal/proxy/connection/util.go +++ b/internal/proxy/connection/util.go @@ -5,6 +5,7 @@ import ( "fmt" "strconv" + "github.com/cockroachdb/errors" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -33,11 +34,11 @@ func ZapClientInfo(info *commonpb.ClientInfo) []zap.Field { func GetIdentifierFromContext(ctx context.Context) (int64, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { - return 0, fmt.Errorf("fail to get metadata from the context") + return 0, errors.New("fail to get metadata from the context") } identifierContent, ok := md[util.IdentifierKey] if !ok || len(identifierContent) < 1 { - return 0, fmt.Errorf("no identifier found in metadata") + return 0, errors.New("no identifier found in metadata") } identifier, err := strconv.ParseInt(identifierContent[0], 10, 64) if err != nil { diff --git a/internal/proxy/impl.go b/internal/proxy/impl.go index 2f5a724a9f..9e9e7032a9 100644 --- a/internal/proxy/impl.go +++ b/internal/proxy/impl.go @@ -5572,19 +5572,19 @@ func (node *Proxy) SelectUser(ctx context.Context, req *milvuspb.SelectUserReque func (node *Proxy) validPrivilegeParams(req *milvuspb.OperatePrivilegeRequest) error { if req.Entity == nil { - return fmt.Errorf("the entity in the request is nil") + return errors.New("the entity in the request is nil") } if req.Entity.Grantor == nil { - return fmt.Errorf("the grantor entity in the grant entity is nil") + return errors.New("the grantor entity in the grant entity is nil") } if req.Entity.Grantor.Privilege == nil { - return fmt.Errorf("the privilege entity in the grantor entity is nil") + return errors.New("the privilege entity in the grantor entity is nil") } if err := ValidatePrivilege(req.Entity.Grantor.Privilege.Name); err != nil { return err } if req.Entity.Object == nil { - return fmt.Errorf("the resource entity in the grant entity is nil") + return errors.New("the resource entity in the grant entity is nil") } if err := ValidateObjectType(req.Entity.Object.Name); err != nil { return err @@ -5593,7 +5593,7 @@ func (node *Proxy) validPrivilegeParams(req *milvuspb.OperatePrivilegeRequest) e return err } if req.Entity.Role == nil { - return fmt.Errorf("the object entity in the grant entity is nil") + return errors.New("the object entity in the grant entity is nil") } if err := ValidateRoleName(req.Entity.Role.Name); err != nil { return err diff --git a/internal/proxy/impl_test.go b/internal/proxy/impl_test.go index e16f7281c9..ea90b18fe6 100644 --- a/internal/proxy/impl_test.go +++ b/internal/proxy/impl_test.go @@ -19,7 +19,6 @@ package proxy import ( "context" "encoding/base64" - "fmt" "math/rand" "net/http" "net/http/httptest" @@ -1262,7 +1261,7 @@ func TestProxy_Delete(t *testing.T) { ).Return(partitionID, nil) cache.On("GetCollectionInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(basicInfo, nil) chMgr.On("getVChannels", mock.Anything).Return(channels, nil) - chMgr.On("getChannels", mock.Anything).Return(nil, fmt.Errorf("mock error")) + chMgr.On("getChannels", mock.Anything).Return(nil, errors.New("mock error")) globalMetaCache = cache rc := mocks.NewMockRootCoordClient(t) tsoAllocator := &mockTsoAllocator{} diff --git a/internal/proxy/meta_cache_test.go b/internal/proxy/meta_cache_test.go index acbc0819b3..2bc8afb29a 100644 --- a/internal/proxy/meta_cache_test.go +++ b/internal/proxy/meta_cache_test.go @@ -196,7 +196,7 @@ func (m *MockMixCoordClientInterface) GetCredential(ctx context.Context, req *ro }, nil } - err := fmt.Errorf("can't find credential: " + req.Username) + err := fmt.Errorf("can't find credential: %s", req.Username) return nil, err } @@ -1489,7 +1489,7 @@ func TestMetaCache_PolicyInfo(t *testing.T) { t.Run("InitMetaCache", func(t *testing.T) { client.listPolicy = func(ctx context.Context, in *internalpb.ListPolicyRequest) (*internalpb.ListPolicyResponse, error) { - return nil, fmt.Errorf("mock error") + return nil, errors.New("mock error") } err := InitMetaCache(context.Background(), client, mgr) assert.Error(t, err) @@ -1772,7 +1772,7 @@ func TestMetaCache_AllocID(t *testing.T) { rootCoord := mocks.NewMockMixCoordClient(t) rootCoord.EXPECT().AllocID(mock.Anything, mock.Anything).Return(&rootcoordpb.AllocIDResponse{ Status: merr.Status(nil), - }, fmt.Errorf("mock error")) + }, errors.New("mock error")) rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{ Status: merr.Success(), PolicyInfos: []string{"policy1", "policy2", "policy3"}, @@ -1790,7 +1790,7 @@ func TestMetaCache_AllocID(t *testing.T) { t.Run("failed", func(t *testing.T) { rootCoord := mocks.NewMockMixCoordClient(t) rootCoord.EXPECT().AllocID(mock.Anything, mock.Anything).Return(&rootcoordpb.AllocIDResponse{ - Status: merr.Status(fmt.Errorf("mock failed")), + Status: merr.Status(errors.New("mock failed")), }, nil) rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{ Status: merr.Success(), diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 12c0f076f5..af0b0cd658 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -550,7 +550,7 @@ func (node *Proxy) SetQueryNodeCreator(f func(ctx context.Context, addr string, // GetRateLimiter returns the rateLimiter in Proxy. func (node *Proxy) GetRateLimiter() (types.Limiter, error) { if node.simpleLimiter == nil { - return nil, fmt.Errorf("nil rate limiter in Proxy") + return nil, errors.New("nil rate limiter in Proxy") } return node.simpleLimiter, nil } diff --git a/internal/proxy/search_util.go b/internal/proxy/search_util.go index 03c8a72cd7..a3f5d96a55 100644 --- a/internal/proxy/search_util.go +++ b/internal/proxy/search_util.go @@ -120,14 +120,14 @@ func parseSearchIteratorV2Info(searchParamsPair []*commonpb.KeyValuePair, groupB } else { // Validate existing token is a valid UUID if _, err := uuid.Parse(token); err != nil { - return nil, fmt.Errorf("invalid token format") + return nil, errors.New("invalid token format") } } // parse batch size, required non-zero value batchSizeStr, _ := funcutil.GetAttrByKeyFromRepeatedKV(SearchIterBatchSizeKey, searchParamsPair) if batchSizeStr == "" { - return nil, fmt.Errorf("batch size is required") + return nil, errors.New("batch size is required") } batchSize, err := strconv.ParseInt(batchSizeStr, 0, 64) if err != nil { diff --git a/internal/proxy/segment.go b/internal/proxy/segment.go index fb38c1b347..cb22a15a6f 100644 --- a/internal/proxy/segment.go +++ b/internal/proxy/segment.go @@ -367,7 +367,7 @@ func (sa *segIDAssigner) syncSegments() (bool, error) { assign.lastInsertTime = now } if !success { - return false, fmt.Errorf(errMsg) + return false, errors.New(errMsg) } return success, nil } diff --git a/internal/proxy/segment_test.go b/internal/proxy/segment_test.go index 1f78c1e59d..e105a8e504 100644 --- a/internal/proxy/segment_test.go +++ b/internal/proxy/segment_test.go @@ -18,12 +18,12 @@ package proxy import ( "context" - "fmt" "math/rand" "sync" "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "google.golang.org/grpc" @@ -237,7 +237,7 @@ func (mockD *mockDataCoord5) AssignSegmentID(ctx context.Context, req *datapb.As ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "Just For Test", }, - }, fmt.Errorf("just for test") + }, errors.New("just for test") } func TestSegmentAllocator5(t *testing.T) { diff --git a/internal/proxy/task.go b/internal/proxy/task.go index ccad9755da..449729ddbf 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -276,7 +276,7 @@ func (t *createCollectionTask) validatePartitionKey(ctx context.Context) error { if idx == -1 { if t.GetNumPartitions() != 0 { - return fmt.Errorf("num_partitions should only be specified with partition key field enabled") + return errors.New("num_partitions should only be specified with partition key field enabled") } } else { log.Ctx(ctx).Info("create collection with partition key mode", diff --git a/internal/proxy/task_delete.go b/internal/proxy/task_delete.go index 07e628ef7f..38139602c1 100644 --- a/internal/proxy/task_delete.go +++ b/internal/proxy/task_delete.go @@ -691,7 +691,7 @@ func getPrimaryKeysFromUnaryRangeExpr(schema *schemapb.CollectionSchema, unaryRa }, } default: - return pks, fmt.Errorf("invalid field data type specifyed in simple delete expr") + return pks, errors.New("invalid field data type specifyed in simple delete expr") } return pks, nil @@ -722,7 +722,7 @@ func getPrimaryKeysFromTermExpr(schema *schemapb.CollectionSchema, termExpr *pla }, } default: - return pks, 0, fmt.Errorf("invalid field data type specifyed in simple delete expr") + return pks, 0, errors.New("invalid field data type specifyed in simple delete expr") } return pks, pkCount, nil diff --git a/internal/proxy/task_delete_test.go b/internal/proxy/task_delete_test.go index e88fb79cbe..46418a8389 100644 --- a/internal/proxy/task_delete_test.go +++ b/internal/proxy/task_delete_test.go @@ -2,7 +2,6 @@ package proxy import ( "context" - "fmt" "testing" "github.com/cockroachdb/errors" @@ -447,7 +446,7 @@ func (s *DeleteRunnerSuite) TestInitFailure() { CollectionName: s.collectionName, }, } - s.mockCache.EXPECT().GetDatabaseInfo(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock error")) + s.mockCache.EXPECT().GetDatabaseInfo(mock.Anything, mock.Anything).Return(nil, errors.New("mock error")) globalMetaCache = s.mockCache s.Error(dr.Init(context.Background())) @@ -460,7 +459,7 @@ func (s *DeleteRunnerSuite) TestInitFailure() { } s.mockCache.EXPECT().GetDatabaseInfo(mock.Anything, mock.Anything).Return(&databaseInfo{dbID: 0}, nil) s.mockCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything). - Return(int64(0), fmt.Errorf("mock get collectionID error")) + Return(int64(0), errors.New("mock get collectionID error")) globalMetaCache = s.mockCache s.Error(dr.Init(context.Background())) @@ -647,7 +646,7 @@ func (s *DeleteRunnerSuite) TestInitFailure() { s.mockCache.EXPECT().GetCollectionInfo(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&collectionInfo{}, nil) s.mockCache.EXPECT().GetPartitionsIndex(mock.Anything, mock.Anything, mock.Anything).Return([]string{"part1", "part2"}, nil) s.mockCache.EXPECT().GetPartitions(mock.Anything, mock.Anything, mock.Anything).Return(map[string]int64{"part1": 100, "part2": 101}, nil) - mockChMgr.EXPECT().getVChannels(mock.Anything).Return(nil, fmt.Errorf("mock error")) + mockChMgr.EXPECT().getVChannels(mock.Anything).Return(nil, errors.New("mock error")) globalMetaCache = s.mockCache s.Error(dr.Init(context.Background())) @@ -735,7 +734,7 @@ func TestDeleteRunner_Run(t *testing.T) { stream := msgstream.NewMockMsgStream(t) mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything, mock.Anything).Return(stream, nil) mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil) - stream.EXPECT().Produce(mock.Anything, mock.Anything).Return(fmt.Errorf("mock error")) + stream.EXPECT().Produce(mock.Anything, mock.Anything).Return(errors.New("mock error")) assert.Error(t, dr.Run(context.Background())) assert.Equal(t, int64(0), dr.result.DeleteCnt) diff --git a/internal/proxy/task_index.go b/internal/proxy/task_index.go index 982c90d505..37cb8f91e3 100644 --- a/internal/proxy/task_index.go +++ b/internal/proxy/task_index.go @@ -138,7 +138,7 @@ func (cit *createIndexTask) parseFunctionParamsToIndex(indexParamsMap map[string switch cit.functionSchema.GetType() { case schemapb.FunctionType_Unknown: - return fmt.Errorf("unknown function type encountered") + return errors.New("unknown function type encountered") case schemapb.FunctionType_BM25: // set default BM25 params if not provided in index params @@ -305,12 +305,12 @@ func (cit *createIndexTask) parseIndexParams(ctx context.Context) error { metricType, metricTypeExist := indexParamsMap[common.MetricTypeKey] if len(indexParamsMap) > numberParams+1 { - return fmt.Errorf("only metric type can be passed when use AutoIndex") + return errors.New("only metric type can be passed when use AutoIndex") } if len(indexParamsMap) == numberParams+1 { if !metricTypeExist { - return fmt.Errorf("only metric type can be passed when use AutoIndex") + return errors.New("only metric type can be passed when use AutoIndex") } // only metric type is passed. @@ -356,7 +356,7 @@ func (cit *createIndexTask) parseIndexParams(ctx context.Context) error { indexType, exist := indexParamsMap[common.IndexTypeKey] if !exist { - return fmt.Errorf("IndexType not specified") + return errors.New("IndexType not specified") } // index parameters defined in the YAML file are merged with the user-provided parameters during create stage if Params.KnowhereConfig.Enable.GetAsBool() { @@ -469,7 +469,7 @@ func fillDimension(field *schemapb.FieldSchema, indexParams map[string]string) e params = append(params, field.GetIndexParams()...) dimensionInSchema, err := funcutil.GetAttrByKeyFromRepeatedKV(DimKey, params) if err != nil { - return fmt.Errorf("dimension not found in schema") + return errors.New("dimension not found in schema") } dimension, exist := indexParams[DimKey] if exist { diff --git a/internal/proxy/task_policies_test.go b/internal/proxy/task_policies_test.go index 98bc97096c..d07a6938b8 100644 --- a/internal/proxy/task_policies_test.go +++ b/internal/proxy/task_policies_test.go @@ -2,12 +2,12 @@ package proxy import ( "context" - "fmt" "sort" "strings" "sync" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/milvus-io/milvus/internal/types" @@ -34,7 +34,7 @@ func TestRoundRobinPolicy(t *testing.T) { assert.NoError(t, err) assert.Equal(t, querier.records(), map[UniqueID][]string{0: {"c0", "c2"}, 1: {"c1", "c3"}}) - mockerr := fmt.Errorf("mock query node error") + mockerr := errors.New("mock query node error") querier.init() querier.failset[0] = mockerr diff --git a/internal/proxy/task_query_test.go b/internal/proxy/task_query_test.go index a5ab928606..c20fdb313e 100644 --- a/internal/proxy/task_query_test.go +++ b/internal/proxy/task_query_test.go @@ -1252,7 +1252,7 @@ func TestQueryTask_CanSkipAllocTimestamp(t *testing.T) { mockMetaCache.ExpectedCalls = nil mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, nil) mockMetaCache.EXPECT().GetCollectionInfo(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - nil, fmt.Errorf("mock error")).Once() + nil, errors.New("mock error")).Once() qt := &queryTask{ request: &milvuspb.QueryRequest{ @@ -1268,7 +1268,7 @@ func TestQueryTask_CanSkipAllocTimestamp(t *testing.T) { assert.False(t, skip) mockMetaCache.ExpectedCalls = nil - mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, fmt.Errorf("mock error")) + mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, errors.New("mock error")) mockMetaCache.EXPECT().GetCollectionInfo(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( &collectionInfo{ collID: collID, diff --git a/internal/proxy/task_scheduler_test.go b/internal/proxy/task_scheduler_test.go index 7c68c57013..103c919e07 100644 --- a/internal/proxy/task_scheduler_test.go +++ b/internal/proxy/task_scheduler_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -593,7 +594,7 @@ func TestTaskScheduler_concurrentPushAndPop(t *testing.T) { assert.NoError(t, err) task := scheduler.scheduleDmTask() scheduler.dmQueue.AddActiveTask(task) - chMgr.EXPECT().getChannels(mock.Anything).Return(nil, fmt.Errorf("mock err")) + chMgr.EXPECT().getChannels(mock.Anything).Return(nil, errors.New("mock err")) scheduler.dmQueue.PopActiveTask(task.ID()) // assert no panic } @@ -659,7 +660,7 @@ func TestTaskScheduler_SkipAllocTimestamp(t *testing.T) { assert.NoError(t, err) }) - mockMetaCache.EXPECT().AllocID(mock.Anything).Return(0, fmt.Errorf("mock error")).Once() + mockMetaCache.EXPECT().AllocID(mock.Anything).Return(0, errors.New("mock error")).Once() t.Run("failed", func(t *testing.T) { st := &searchTask{ SearchRequest: &internalpb.SearchRequest{ diff --git a/internal/proxy/task_search_test.go b/internal/proxy/task_search_test.go index becb487159..b487fdff2e 100644 --- a/internal/proxy/task_search_test.go +++ b/internal/proxy/task_search_test.go @@ -3208,12 +3208,12 @@ func TestSearchTask_Requery(t *testing.T) { schema := newSchemaInfo(collSchema) qn := mocks.NewMockQueryNodeClient(t) qn.EXPECT().Query(mock.Anything, mock.Anything). - Return(nil, fmt.Errorf("mock err 1")) + Return(nil, errors.New("mock err 1")) lb := NewMockLBPolicy(t) lb.EXPECT().Execute(mock.Anything, mock.Anything).Run(func(ctx context.Context, workload CollectionWorkLoad) { _ = workload.exec(ctx, 0, qn, "") - }).Return(fmt.Errorf("mock err 1")) + }).Return(errors.New("mock err 1")) node.lbPolicy = lb qt := &searchTask{ @@ -3242,12 +3242,12 @@ func TestSearchTask_Requery(t *testing.T) { schema := newSchemaInfo(collSchema) qn := mocks.NewMockQueryNodeClient(t) qn.EXPECT().Query(mock.Anything, mock.Anything). - Return(nil, fmt.Errorf("mock err 1")) + Return(nil, errors.New("mock err 1")) lb := NewMockLBPolicy(t) lb.EXPECT().Execute(mock.Anything, mock.Anything).Run(func(ctx context.Context, workload CollectionWorkLoad) { _ = workload.exec(ctx, 0, qn, "") - }).Return(fmt.Errorf("mock err 1")) + }).Return(errors.New("mock err 1")) node.lbPolicy = lb resultIDs := &schemapb.IDs{ @@ -3481,7 +3481,7 @@ func TestSearchTask_CanSkipAllocTimestamp(t *testing.T) { mockMetaCache.ExpectedCalls = nil mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, nil) mockMetaCache.EXPECT().GetCollectionInfo(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - nil, fmt.Errorf("mock error")).Once() + nil, errors.New("mock error")).Once() st := &searchTask{ request: &milvuspb.SearchRequest{ @@ -3497,7 +3497,7 @@ func TestSearchTask_CanSkipAllocTimestamp(t *testing.T) { assert.False(t, skip) mockMetaCache.ExpectedCalls = nil - mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, fmt.Errorf("mock error")) + mockMetaCache.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(collID, errors.New("mock error")) mockMetaCache.EXPECT().GetCollectionInfo(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( &collectionInfo{ collID: collID, diff --git a/internal/proxy/timestamp.go b/internal/proxy/timestamp.go index 5de1084f18..f6c8a5914b 100644 --- a/internal/proxy/timestamp.go +++ b/internal/proxy/timestamp.go @@ -22,6 +22,8 @@ import ( "strconv" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/pkg/v2/metrics" "github.com/milvus-io/milvus/pkg/v2/proto/rootcoordpb" @@ -69,7 +71,7 @@ func (ta *timestampAllocator) alloc(ctx context.Context, count uint32) ([]Timest return nil, fmt.Errorf("syncTimeStamp Failed:%s", resp.GetStatus().GetReason()) } if resp == nil { - return nil, fmt.Errorf("empty AllocTimestampResponse") + return nil, errors.New("empty AllocTimestampResponse") } start, cnt := resp.GetTimestamp(), resp.GetCount() ret := make([]Timestamp, cnt) diff --git a/internal/proxy/util.go b/internal/proxy/util.go index b61582c58f..d5a5d3e0ef 100644 --- a/internal/proxy/util.go +++ b/internal/proxy/util.go @@ -399,7 +399,7 @@ func validateMaxCapacityPerRow(collectionName string, field *schemapb.FieldSchem return fmt.Errorf("the value for %s of field %s must be an integer", common.MaxCapacityKey, field.GetName()) } if maxCapacityPerRow > defaultMaxArrayCapacity || maxCapacityPerRow <= 0 { - return fmt.Errorf("the maximum capacity specified for a Array should be in (0, 4096]") + return errors.New("the maximum capacity specified for a Array should be in (0, 4096]") } exist = true } @@ -540,7 +540,7 @@ func validatePrimaryKey(coll *schemapb.CollectionSchema) error { // If autoID is required, it is recommended to use int64 field as the primary key //if field.DataType == schemapb.DataType_VarChar { // if field.AutoID { - // return fmt.Errorf("autoID is not supported when the VarChar field is the primary key") + // return errors.New("autoID is not supported when the VarChar field is the primary key") // } //} @@ -556,7 +556,7 @@ func validatePrimaryKey(coll *schemapb.CollectionSchema) error { func validateDynamicField(coll *schemapb.CollectionSchema) error { for _, field := range coll.Fields { if field.IsDynamic { - return fmt.Errorf("cannot explicitly set a field as a dynamic field") + return errors.New("cannot explicitly set a field as a dynamic field") } } return nil @@ -621,12 +621,12 @@ func validateSchema(coll *schemapb.CollectionSchema) error { // primary key detector if field.IsPrimaryKey { if autoID { - return fmt.Errorf("autoId forbids primary key") + return errors.New("autoId forbids primary key") } else if primaryIdx != -1 { return fmt.Errorf("there are more than one primary key, field name = %s, %s", coll.Fields[primaryIdx].Name, field.Name) } if field.DataType != schemapb.DataType_Int64 { - return fmt.Errorf("type of primary key should be int64") + return errors.New("type of primary key should be int64") } primaryIdx = idx } @@ -687,7 +687,7 @@ func validateSchema(coll *schemapb.CollectionSchema) error { } if !autoID && primaryIdx == -1 { - return fmt.Errorf("primary key is required for non autoid mode") + return errors.New("primary key is required for non autoid mode") } return nil @@ -779,7 +779,7 @@ func checkFunctionOutputField(fSchema *schemapb.FunctionSchema, fields []*schema return err } default: - return fmt.Errorf("check output field for unknown function type") + return errors.New("check output field for unknown function type") } return nil } @@ -802,21 +802,21 @@ func checkFunctionInputField(function *schemapb.FunctionSchema, fields []*schema } h := typeutil.CreateFieldSchemaHelper(fields[0]) if !h.EnableAnalyzer() { - return fmt.Errorf("BM25 function input field must set enable_analyzer to true") + return errors.New("BM25 function input field must set enable_analyzer to true") } case schemapb.FunctionType_TextEmbedding: if len(fields) != 1 || (fields[0].DataType != schemapb.DataType_VarChar && fields[0].DataType != schemapb.DataType_Text) { - return fmt.Errorf("TextEmbedding function input field must be a VARCHAR/TEXT field") + return errors.New("TextEmbedding function input field must be a VARCHAR/TEXT field") } default: - return fmt.Errorf("check input field with unknown function type") + return errors.New("check input field with unknown function type") } return nil } func checkFunctionBasicParams(function *schemapb.FunctionSchema) error { if function.GetName() == "" { - return fmt.Errorf("function name cannot be empty") + return errors.New("function name cannot be empty") } if len(function.GetInputFieldNames()) == 0 { return fmt.Errorf("function input field names cannot be empty, function: %s", function.GetName()) @@ -847,14 +847,14 @@ func checkFunctionBasicParams(function *schemapb.FunctionSchema) error { switch function.GetType() { case schemapb.FunctionType_BM25: if len(function.GetParams()) != 0 { - return fmt.Errorf("BM25 function accepts no params") + return errors.New("BM25 function accepts no params") } case schemapb.FunctionType_TextEmbedding: if len(function.GetParams()) == 0 { - return fmt.Errorf("TextEmbedding function accepts no params") + return errors.New("TextEmbedding function accepts no params") } default: - return fmt.Errorf("check function params with unknown function type") + return errors.New("check function params with unknown function type") } return nil } @@ -1334,9 +1334,9 @@ func computeRecall(results *schemapb.SearchResultData, gts *schemapb.SearchResul results.Recalls = recalls return nil case *schemapb.IDs_StrId: - return fmt.Errorf("pk type is inconsistent between search results(int64) and ground truth(string)") + return errors.New("pk type is inconsistent between search results(int64) and ground truth(string)") default: - return fmt.Errorf("unsupported pk type") + return errors.New("unsupported pk type") } case *schemapb.IDs_StrId: @@ -1356,12 +1356,12 @@ func computeRecall(results *schemapb.SearchResultData, gts *schemapb.SearchResul results.Recalls = recalls return nil case *schemapb.IDs_IntId: - return fmt.Errorf("pk type is inconsistent between search results(string) and ground truth(int64)") + return errors.New("pk type is inconsistent between search results(string) and ground truth(int64)") default: - return fmt.Errorf("unsupported pk type") + return errors.New("unsupported pk type") } default: - return fmt.Errorf("unsupported pk type") + return errors.New("unsupported pk type") } } @@ -1439,7 +1439,7 @@ func translateOutputFields(outputFields []string, schema *schemaInfo, removePkFi expr.GetColumnExpr().GetInfo().GetNestedPath()[0] == outputFieldName { return nil } - return fmt.Errorf("not support getting subkeys of json field yet") + return errors.New("not support getting subkeys of json field yet") }) if err != nil { log.Info("parse output field name failed", zap.String("field name", outputFieldName)) @@ -2273,7 +2273,7 @@ func GetRequestInfo(ctx context.Context, req proto.Message) (int64, map[int64][] return util.InvalidDBID, map[int64][]int64{}, internalpb.RateType_DDLDB, 1, nil default: // TODO: support more request if req == nil { - return util.InvalidDBID, map[int64][]int64{}, 0, 0, fmt.Errorf("null request") + return util.InvalidDBID, map[int64][]int64{}, 0, 0, errors.New("null request") } log.RatedWarn(60, "not supported request type for rate limiter", zap.String("type", reflect.TypeOf(req).String())) return util.InvalidDBID, map[int64][]int64{}, 0, 0, nil diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index 011cc663ed..ce5694f64f 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -931,7 +931,7 @@ func TestPasswordVerify(t *testing.T) { mockedRootCoord := NewMixCoordMock() mockedRootCoord.GetGetCredentialFunc = func(ctx context.Context, req *rootcoordpb.GetCredentialRequest, opts ...grpc.CallOption) (*rootcoordpb.GetCredentialResponse, error) { invokedCount++ - return nil, fmt.Errorf("get cred not found credential") + return nil, errors.New("get cred not found credential") } metaCache := &MetaCache{ diff --git a/internal/querycoordv2/meta/coordinator_broker.go b/internal/querycoordv2/meta/coordinator_broker.go index bc83447fc6..a63454f120 100644 --- a/internal/querycoordv2/meta/coordinator_broker.go +++ b/internal/querycoordv2/meta/coordinator_broker.go @@ -18,7 +18,6 @@ package meta import ( "context" - "fmt" "math" "time" @@ -275,7 +274,7 @@ func (broker *CoordinatorBroker) GetSegmentInfo(ctx context.Context, ids ...Uniq if len(resp.Infos) == 0 { log.Warn("No such segment in DataCoord") - return nil, fmt.Errorf("no such segment in DataCoord") + return nil, errors.New("no such segment in DataCoord") } err = binlog.DecompressMultiBinLogs(resp.GetInfos()) diff --git a/internal/querycoordv2/server.go b/internal/querycoordv2/server.go index c671e4079d..a072667d39 100644 --- a/internal/querycoordv2/server.go +++ b/internal/querycoordv2/server.go @@ -27,6 +27,7 @@ import ( "time" "github.com/blang/semver/v4" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/tidwall/gjson" "github.com/tikv/client-go/v2/txnkv" @@ -157,7 +158,7 @@ func (s *Server) Register() error { func (s *Server) SetSession(session sessionutil.SessionInterface) error { s.session = session if s.session == nil { - return fmt.Errorf("session is nil, the etcd client connection may have failed") + return errors.New("session is nil, the etcd client connection may have failed") } return nil } diff --git a/internal/querycoordv2/utils/util.go b/internal/querycoordv2/utils/util.go index 5ca6de9c43..93d20ef68f 100644 --- a/internal/querycoordv2/utils/util.go +++ b/internal/querycoordv2/utils/util.go @@ -106,7 +106,7 @@ func GetShardLeadersWithChannels(ctx context.Context, m *meta.Meta, targetMgr me ) ([]*querypb.ShardLeadersList, error) { ret := make([]*querypb.ShardLeadersList, 0) for _, channel := range channels { - log := log.With(zap.String("channel", channel.GetChannelName())) + log := log.Ctx(ctx).With(zap.String("channel", channel.GetChannelName())) var channelErr error leaders := dist.LeaderViewManager.GetByFilter(meta.WithChannelName2LeaderView(channel.GetChannelName())) diff --git a/internal/querynodev2/delegator/delegator_data.go b/internal/querynodev2/delegator/delegator_data.go index 2ed1b271cf..5e36dc074d 100644 --- a/internal/querynodev2/delegator/delegator_data.go +++ b/internal/querynodev2/delegator/delegator_data.go @@ -1093,7 +1093,7 @@ func (sd *shardDelegator) buildBM25IDF(req *internalpb.SearchRequest) (float64, tfArray, ok := output[0].(*schemapb.SparseFloatArray) if !ok { - return 0, fmt.Errorf("functionRunner return unknown data") + return 0, errors.New("functionRunner return unknown data") } idfSparseVector, avgdl, err := sd.idfOracle.BuildIDF(req.GetFieldId(), tfArray) diff --git a/internal/querynodev2/delegator/delegator_data_test.go b/internal/querynodev2/delegator/delegator_data_test.go index ebc2065cc2..b9c65c3c07 100644 --- a/internal/querynodev2/delegator/delegator_data_test.go +++ b/internal/querynodev2/delegator/delegator_data_test.go @@ -611,7 +611,7 @@ func (s *DelegatorDataSuite) TestLoadSegmentsWithBm25() { s.loader.ExpectedCalls = nil }() - s.loader.EXPECT().LoadBM25Stats(mock.Anything, s.collectionID, mock.Anything).Return(nil, fmt.Errorf("mock error")) + s.loader.EXPECT().LoadBM25Stats(mock.Anything, s.collectionID, mock.Anything).Return(nil, errors.New("mock error")) workers := make(map[int64]*cluster.MockWorker) worker1 := &cluster.MockWorker{} @@ -1073,7 +1073,7 @@ func (s *DelegatorDataSuite) TestBuildBM25IDF() { oldRunner := s.delegator.functionRunners mockRunner := function.NewMockFunctionRunner(s.T()) s.delegator.functionRunners = map[int64]function.FunctionRunner{101: mockRunner} - mockRunner.EXPECT().BatchRun(mock.Anything).Return(nil, fmt.Errorf("mock err")) + mockRunner.EXPECT().BatchRun(mock.Anything).Return(nil, errors.New("mock err")) defer func() { s.delegator.functionRunners = oldRunner }() diff --git a/internal/querynodev2/delegator/idf_oracle.go b/internal/querynodev2/delegator/idf_oracle.go index a3ebca8d97..f4a6008c0f 100644 --- a/internal/querynodev2/delegator/idf_oracle.go +++ b/internal/querynodev2/delegator/idf_oracle.go @@ -18,9 +18,9 @@ package delegator import ( "context" - "fmt" "sync" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -75,7 +75,7 @@ func (s *bm25Stats) Minus(stats map[int64]*storage.BM25Stats) { func (s *bm25Stats) GetStats(fieldID int64) (*storage.BM25Stats, error) { stats, ok := s.stats[fieldID] if !ok { - return nil, fmt.Errorf("field not found in idf oracle BM25 stats") + return nil, errors.New("field not found in idf oracle BM25 stats") } return stats, nil } diff --git a/internal/querynodev2/pipeline/embedding_node.go b/internal/querynodev2/pipeline/embedding_node.go index 813be6b943..58b18fbaf0 100644 --- a/internal/querynodev2/pipeline/embedding_node.go +++ b/internal/querynodev2/pipeline/embedding_node.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/msgpb" @@ -104,7 +105,7 @@ func (eNode *embeddingNode) addInsertData(insertDatas map[UniqueID]*delegator.In insertRecord, err := storage.TransferInsertMsgToInsertRecord(collection.Schema(), msg) if err != nil { - err = fmt.Errorf("failed to get primary keys, err = %d", err) + err = fmt.Errorf("failed to get primary keys, err = %v", err) log.Error(err.Error(), zap.String("channel", eNode.channel)) return err } @@ -156,7 +157,7 @@ func (eNode *embeddingNode) bm25Embedding(runner function.FunctionRunner, msg *m sparseArray, ok := output[0].(*schemapb.SparseFloatArray) if !ok { - return fmt.Errorf("BM25 runner return unknown type output") + return errors.New("BM25 runner return unknown type output") } if _, ok := stats[outputFieldID]; !ok { @@ -178,7 +179,7 @@ func (eNode *embeddingNode) embedding(msg *msgstream.InsertMsg, stats map[int64] } default: log.Warn("pipeline embedding with unknown function type", zap.Any("type", functionSchema.GetType())) - return fmt.Errorf("unknown function type") + return errors.New("unknown function type") } } diff --git a/internal/querynodev2/pipeline/embedding_node_test.go b/internal/querynodev2/pipeline/embedding_node_test.go index 5d74afca18..8651291873 100644 --- a/internal/querynodev2/pipeline/embedding_node_test.go +++ b/internal/querynodev2/pipeline/embedding_node_test.go @@ -17,9 +17,9 @@ package pipeline import ( - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" "google.golang.org/protobuf/proto" @@ -252,7 +252,7 @@ func (suite *EmbeddingNodeSuite) TestBM25Embedding() { suite.NoError(err) runner := function.NewMockFunctionRunner(suite.T()) - runner.EXPECT().BatchRun(mock.Anything).Return(nil, fmt.Errorf("mock error")) + runner.EXPECT().BatchRun(mock.Anything).Return(nil, errors.New("mock error")) runner.EXPECT().GetSchema().Return(suite.collectionSchema.GetFunctions()[0]) runner.EXPECT().GetOutputFields().Return([]*schemapb.FieldSchema{nil}) diff --git a/internal/querynodev2/segments/index_attr_cache.go b/internal/querynodev2/segments/index_attr_cache.go index 830b26b698..0e6ae07809 100644 --- a/internal/querynodev2/segments/index_attr_cache.go +++ b/internal/querynodev2/segments/index_attr_cache.go @@ -27,6 +27,8 @@ import ( "fmt" "unsafe" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/indexparamcheck" "github.com/milvus-io/milvus/internal/util/vecindexmgr" "github.com/milvus-io/milvus/pkg/v2/common" @@ -59,7 +61,7 @@ func NewIndexAttrCache() *IndexAttrCache { func (c *IndexAttrCache) GetIndexResourceUsage(indexInfo *querypb.FieldIndexInfo, memoryIndexLoadPredictMemoryUsageFactor float64, fieldBinlog *datapb.FieldBinlog) (memory uint64, disk uint64, err error) { indexType, err := funcutil.GetAttrByKeyFromRepeatedKV(common.IndexTypeKey, indexInfo.IndexParams) if err != nil { - return 0, 0, fmt.Errorf("index type not exist in index params") + return 0, 0, errors.New("index type not exist in index params") } if vecindexmgr.GetVecIndexMgrInstance().IsDiskANN(indexType) { neededMemSize := indexInfo.IndexSize / UsedDiskMemoryRatio diff --git a/internal/querynodev2/segments/segment.go b/internal/querynodev2/segments/segment.go index f2c66a5911..cf414cfbd4 100644 --- a/internal/querynodev2/segments/segment.go +++ b/internal/querynodev2/segments/segment.go @@ -1096,7 +1096,7 @@ func (s *LocalSegment) innerLoadIndex(ctx context.Context, metricType, err := funcutil.GetAttrByKeyFromRepeatedKV(common.MetricTypeKey, indexInfo.IndexParams) if err != nil { - return fmt.Errorf("metric type not exist in index params") + return errors.New("metric type not exist in index params") } if metricType == metric.BM25 { diff --git a/internal/querynodev2/segments/segment_loader_test.go b/internal/querynodev2/segments/segment_loader_test.go index 4dbb1bee9b..4808a1aae1 100644 --- a/internal/querynodev2/segments/segment_loader_test.go +++ b/internal/querynodev2/segments/segment_loader_test.go @@ -582,7 +582,8 @@ func (suite *SegmentLoaderSuite) TestLoadIndexWithLimitedResource() { loadInfo: atomic.NewPointer[querypb.SegmentLoadInfo](loadInfo), }, } - paramtable.Get().QueryNodeCfg.DiskCapacityLimit.SwapTempValue("100000") + paramtable.Get().Save(paramtable.Get().QueryNodeCfg.DiskCapacityLimit.Key, "100000") + defer paramtable.Get().Reset(paramtable.Get().QueryNodeCfg.DiskCapacityLimit.Key) err := suite.loader.LoadIndex(ctx, segment, loadInfo, 0) suite.Error(err) } diff --git a/internal/querynodev2/segments/utils.go b/internal/querynodev2/segments/utils.go index 0ec9feaebd..9254bf295b 100644 --- a/internal/querynodev2/segments/utils.go +++ b/internal/querynodev2/segments/utils.go @@ -20,6 +20,7 @@ import ( "strconv" "time" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -126,7 +127,7 @@ func getPKsFromRowBasedInsertMsg(msg *msgstream.InsertMsg, schema *schemapb.Coll } } case schemapb.DataType_SparseFloatVector: - return nil, fmt.Errorf("SparseFloatVector not support in row based message") + return nil, errors.New("SparseFloatVector not support in row based message") } } diff --git a/internal/querynodev2/server.go b/internal/querynodev2/server.go index 0f74fd9e30..cdadeebbf6 100644 --- a/internal/querynodev2/server.go +++ b/internal/querynodev2/server.go @@ -40,6 +40,7 @@ import ( "time" "unsafe" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/tidwall/gjson" clientv3 "go.etcd.io/etcd/client/v3" @@ -163,7 +164,7 @@ func (node *QueryNode) initSession() error { sessionutil.WithScalarIndexEngineVersion(common.MinimalScalarIndexEngineVersion, common.CurrentScalarIndexEngineVersion), sessionutil.WithIndexNonEncoding()) if node.session == nil { - return fmt.Errorf("session is nil, the etcd client connection may have failed") + return errors.New("session is nil, the etcd client connection may have failed") } node.session.Init(typeutil.QueryNodeRole, node.address, false, true) sessionutil.SaveServerInfo(typeutil.QueryNodeRole, node.session.ServerID) @@ -552,7 +553,7 @@ func (node *QueryNode) initHook() error { log := log.Ctx(node.ctx) path := paramtable.Get().QueryNodeCfg.SoPath.GetValue() if path == "" { - return fmt.Errorf("fail to set the plugin path") + return errors.New("fail to set the plugin path") } log.Info("start to load plugin", zap.String("path", path)) @@ -569,7 +570,7 @@ func (node *QueryNode) initHook() error { hoo, ok := h.(optimizers.QueryHook) if !ok { - return fmt.Errorf("fail to convert the `Hook` interface") + return errors.New("fail to convert the `Hook` interface") } if err = hoo.Init(paramtable.Get().AutoIndexConfig.AutoIndexSearchConfig.GetValue()); err != nil { return fmt.Errorf("fail to init configs for the hook, error: %s", err.Error()) diff --git a/internal/rootcoord/alter_alias_task_test.go b/internal/rootcoord/alter_alias_task_test.go index 1ca9450235..a9579afe25 100644 --- a/internal/rootcoord/alter_alias_task_test.go +++ b/internal/rootcoord/alter_alias_task_test.go @@ -18,9 +18,9 @@ package rootcoord import ( "context" - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -63,7 +63,7 @@ func Test_alterAliasTask_Execute(t *testing.T) { mockMeta := mockrootcoord.NewIMetaTable(t) mockMeta.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(111) mockMeta.EXPECT().AlterAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("failed to alter alias")) + Return(errors.New("failed to alter alias")) core := newTestCore(withValidProxyManager(), withMeta(mockMeta)) task := &alterAliasTask{ baseTask: newBaseTask(context.Background(), core), diff --git a/internal/rootcoord/alter_collection_task.go b/internal/rootcoord/alter_collection_task.go index 7acfbf1de3..e0199b3e70 100644 --- a/internal/rootcoord/alter_collection_task.go +++ b/internal/rootcoord/alter_collection_task.go @@ -18,7 +18,6 @@ package rootcoord import ( "context" - "fmt" "strconv" "github.com/cockroachdb/errors" @@ -44,7 +43,7 @@ type alterCollectionTask struct { func (a *alterCollectionTask) Prepare(ctx context.Context) error { if a.Req.GetCollectionName() == "" { - return fmt.Errorf("alter collection failed, collection name does not exists") + return errors.New("alter collection failed, collection name does not exists") } return nil @@ -244,11 +243,11 @@ type alterCollectionFieldTask struct { func (a *alterCollectionFieldTask) Prepare(ctx context.Context) error { if a.Req.GetCollectionName() == "" { - return fmt.Errorf("alter collection field failed, collection name does not exists") + return errors.New("alter collection field failed, collection name does not exists") } if a.Req.GetFieldName() == "" { - return fmt.Errorf("alter collection field failed, filed name does not exists") + return errors.New("alter collection field failed, filed name does not exists") } return nil diff --git a/internal/rootcoord/alter_database_task.go b/internal/rootcoord/alter_database_task.go index d9589c205b..e3be431ebe 100644 --- a/internal/rootcoord/alter_database_task.go +++ b/internal/rootcoord/alter_database_task.go @@ -18,7 +18,6 @@ package rootcoord import ( "context" - "fmt" "github.com/cockroachdb/errors" "github.com/samber/lo" @@ -44,7 +43,7 @@ type alterDatabaseTask struct { func (a *alterDatabaseTask) Prepare(ctx context.Context) error { if a.Req.GetDbName() == "" { - return fmt.Errorf("alter database failed, database name does not exists") + return errors.New("alter database failed, database name does not exists") } // TODO SimFG maybe it will support to alter the replica.id properties in the future when the database has no collections diff --git a/internal/rootcoord/broker.go b/internal/rootcoord/broker.go index 0481c8d56a..f7562801c7 100644 --- a/internal/rootcoord/broker.go +++ b/internal/rootcoord/broker.go @@ -202,7 +202,7 @@ func (b *ServerBroker) DropCollectionIndex(ctx context.Context, collID UniqueID, return err } if rsp.ErrorCode != commonpb.ErrorCode_Success { - return fmt.Errorf(rsp.Reason) + return fmt.Errorf("%s", rsp.Reason) } log.Ctx(ctx).Info("done to drop collection index", zap.Int64("collection", collID), zap.Int64s("partitions", partIDs)) diff --git a/internal/rootcoord/create_collection_task.go b/internal/rootcoord/create_collection_task.go index 0adffde062..35df045f4e 100644 --- a/internal/rootcoord/create_collection_task.go +++ b/internal/rootcoord/create_collection_task.go @@ -142,7 +142,7 @@ func (t *createCollectionTask) checkMaxCollectionsPerDB(ctx context.Context, db2 if err != nil { log.Ctx(ctx).Warn("parse value of property fail", zap.String("key", common.DatabaseMaxCollectionsKey), zap.String("value", maxColNumPerDBStr), zap.Error(err)) - return fmt.Errorf(fmt.Sprintf("parse value of property fail, key:%s, value:%s", common.DatabaseMaxCollectionsKey, maxColNumPerDBStr)) + return fmt.Errorf("parse value of property fail, key:%s, value:%s", common.DatabaseMaxCollectionsKey, maxColNumPerDBStr) } return check(maxColNumPerDB) } diff --git a/internal/rootcoord/drop_alias_task_test.go b/internal/rootcoord/drop_alias_task_test.go index 03a6e6bca4..6e8c93be09 100644 --- a/internal/rootcoord/drop_alias_task_test.go +++ b/internal/rootcoord/drop_alias_task_test.go @@ -18,9 +18,9 @@ package rootcoord import ( "context" - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -69,7 +69,7 @@ func Test_dropAliasTask_Execute(t *testing.T) { mockMeta := mockrootcoord.NewIMetaTable(t) mockMeta.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(111) mockMeta.EXPECT().DropAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("failed to alter alias")) + Return(errors.New("failed to alter alias")) core := newTestCore(withValidProxyManager(), withMeta(mockMeta)) alias := funcutil.GenRandomStr() task := &dropAliasTask{ diff --git a/internal/rootcoord/drop_db_task.go b/internal/rootcoord/drop_db_task.go index 918a57b65d..cd6832b769 100644 --- a/internal/rootcoord/drop_db_task.go +++ b/internal/rootcoord/drop_db_task.go @@ -18,7 +18,8 @@ package rootcoord import ( "context" - "fmt" + + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" @@ -33,7 +34,7 @@ type dropDatabaseTask struct { func (t *dropDatabaseTask) Prepare(ctx context.Context) error { if t.Req.GetDbName() == util.DefaultDBName { - return fmt.Errorf("can not drop default database") + return errors.New("can not drop default database") } return nil } diff --git a/internal/rootcoord/drop_partition_task.go b/internal/rootcoord/drop_partition_task.go index b66ce77def..378af74a77 100644 --- a/internal/rootcoord/drop_partition_task.go +++ b/internal/rootcoord/drop_partition_task.go @@ -18,8 +18,8 @@ package rootcoord import ( "context" - "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -42,7 +42,7 @@ func (t *dropPartitionTask) Prepare(ctx context.Context) error { return err } if t.Req.GetPartitionName() == Params.CommonCfg.DefaultPartitionName.GetValue() { - return fmt.Errorf("default partition cannot be deleted") + return errors.New("default partition cannot be deleted") } collMeta, err := t.core.meta.GetCollectionByName(ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), t.GetTs()) if err != nil { diff --git a/internal/rootcoord/garbage_collector_test.go b/internal/rootcoord/garbage_collector_test.go index e30422365d..ec498e0cd1 100644 --- a/internal/rootcoord/garbage_collector_test.go +++ b/internal/rootcoord/garbage_collector_test.go @@ -18,7 +18,6 @@ package rootcoord import ( "context" - "fmt" "testing" "github.com/cockroachdb/errors" @@ -283,7 +282,7 @@ func TestGarbageCollectorCtx_RemoveCreatingCollection(t *testing.T) { ).Return(func(ctx context.Context, collectionID UniqueID, ts Timestamp) error { removeCollectionCalled = true removeCollectionChan <- struct{}{} - return fmt.Errorf("error mock RemoveCollection") + return errors.New("error mock RemoveCollection") }) core := newTestCore(withTtSynchronizer(ticker), withMeta(meta), withTsoAllocator(tsoAllocator)) @@ -490,7 +489,7 @@ func TestGarbageCollector_RemoveCreatingPartition(t *testing.T) { qc := mocks.NewMixCoord(t) qc.EXPECT().ReleasePartitions(mock.Anything, mock.Anything). - Return(merr.Success(), fmt.Errorf("mock err")). + Return(merr.Success(), errors.New("mock err")). Run(func(ctx context.Context, req *querypb.ReleasePartitionsRequest) { signal <- struct{}{} }) @@ -517,7 +516,7 @@ func TestGarbageCollector_RemoveCreatingPartition(t *testing.T) { signal := make(chan struct{}, 1) meta := mockrootcoord.NewIMetaTable(t) meta.EXPECT().RemovePartition(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("mock err")). + Return(errors.New("mock err")). Run(func(ctx context.Context, dbID, collectionID int64, partitionID int64, ts uint64) { signal <- struct{}{} }) diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index e2ef8e0b06..98fbeacc33 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -331,7 +331,7 @@ func (mt *MetaTable) AlterDatabase(ctx context.Context, oldDB *model.Database, n defer mt.ddLock.Unlock() if oldDB.Name != newDB.Name || oldDB.ID != newDB.ID || oldDB.State != newDB.State { - return fmt.Errorf("alter database name/id is not supported!") + return errors.New("alter database name/id is not supported!") } ctx1 := contextutil.WithTenantID(ctx, Params.CommonCfg.ClusterName.GetValue()) @@ -348,7 +348,7 @@ func (mt *MetaTable) DropDatabase(ctx context.Context, dbName string, ts typeuti defer mt.ddLock.Unlock() if dbName == util.DefaultDBName { - return fmt.Errorf("can not drop default database") + return errors.New("can not drop default database") } db, err := mt.getDatabaseByNameInternal(ctx, dbName, typeutil.MaxTimestamp) @@ -895,7 +895,7 @@ func (mt *MetaTable) RenameCollection(ctx context.Context, dbName string, oldNam // unsupported rename collection while the collection has aliases aliases := mt.listAliasesByID(oldColl.CollectionID) if len(aliases) > 0 && oldColl.DBID != targetDB.ID { - return fmt.Errorf("fail to rename db name, must drop all aliases of this collection before rename") + return errors.New("fail to rename db name, must drop all aliases of this collection before rename") } newColl := oldColl.Clone() @@ -1063,7 +1063,7 @@ func (mt *MetaTable) CreateAlias(ctx context.Context, dbName string, alias strin if collID, ok := mt.names.get(dbName, alias); ok { coll, ok := mt.collID2Meta[collID] if !ok { - return fmt.Errorf("meta error, name mapped non-exist collection id") + return errors.New("meta error, name mapped non-exist collection id") } // allow alias with dropping&dropped if coll.State != pb.CollectionState_CollectionDropping && coll.State != pb.CollectionState_CollectionDropped { @@ -1318,7 +1318,7 @@ func (mt *MetaTable) GetGeneralCount(ctx context.Context) int { // AddCredential add credential func (mt *MetaTable) AddCredential(ctx context.Context, credInfo *internalpb.CredentialInfo) error { if credInfo.Username == "" { - return fmt.Errorf("username is empty") + return errors.New("username is empty") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1347,7 +1347,7 @@ func (mt *MetaTable) AddCredential(ctx context.Context, credInfo *internalpb.Cre // AlterCredential update credential func (mt *MetaTable) AlterCredential(ctx context.Context, credInfo *internalpb.CredentialInfo) error { if credInfo.Username == "" { - return fmt.Errorf("username is empty") + return errors.New("username is empty") } mt.permissionLock.Lock() @@ -1392,7 +1392,7 @@ func (mt *MetaTable) ListCredentialUsernames(ctx context.Context) (*milvuspb.Lis // CreateRole create role func (mt *MetaTable) CreateRole(ctx context.Context, tenant string, entity *milvuspb.RoleEntity) error { if funcutil.IsEmptyString(entity.Name) { - return fmt.Errorf("the role name in the role info is empty") + return errors.New("the role name in the role info is empty") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1428,10 +1428,10 @@ func (mt *MetaTable) DropRole(ctx context.Context, tenant string, roleName strin // OperateUserRole operate the relationship between a user and a role, including adding a user to a role and removing a user from a role func (mt *MetaTable) OperateUserRole(ctx context.Context, tenant string, userEntity *milvuspb.UserEntity, roleEntity *milvuspb.RoleEntity, operateType milvuspb.OperateUserRoleType) error { if funcutil.IsEmptyString(userEntity.Name) { - return fmt.Errorf("username in the user entity is empty") + return errors.New("username in the user entity is empty") } if funcutil.IsEmptyString(roleEntity.Name) { - return fmt.Errorf("role name in the role entity is empty") + return errors.New("role name in the role entity is empty") } mt.permissionLock.Lock() @@ -1463,25 +1463,25 @@ func (mt *MetaTable) SelectUser(ctx context.Context, tenant string, entity *milv // OperatePrivilege grant or revoke privilege by setting the operateType param func (mt *MetaTable) OperatePrivilege(ctx context.Context, tenant string, entity *milvuspb.GrantEntity, operateType milvuspb.OperatePrivilegeType) error { if funcutil.IsEmptyString(entity.ObjectName) { - return fmt.Errorf("the object name in the grant entity is empty") + return errors.New("the object name in the grant entity is empty") } if entity.Object == nil || funcutil.IsEmptyString(entity.Object.Name) { - return fmt.Errorf("the object entity in the grant entity is invalid") + return errors.New("the object entity in the grant entity is invalid") } if entity.Role == nil || funcutil.IsEmptyString(entity.Role.Name) { - return fmt.Errorf("the role entity in the grant entity is invalid") + return errors.New("the role entity in the grant entity is invalid") } if entity.Grantor == nil { - return fmt.Errorf("the grantor in the grant entity is empty") + return errors.New("the grantor in the grant entity is empty") } if entity.Grantor.Privilege == nil || funcutil.IsEmptyString(entity.Grantor.Privilege.Name) { - return fmt.Errorf("the privilege name in the grant entity is empty") + return errors.New("the privilege name in the grant entity is empty") } if entity.Grantor.User == nil || funcutil.IsEmptyString(entity.Grantor.User.Name) { - return fmt.Errorf("the grantor name in the grant entity is empty") + return errors.New("the grantor name in the grant entity is empty") } if !funcutil.IsRevoke(operateType) && !funcutil.IsGrant(operateType) { - return fmt.Errorf("the operate type in the grant entity is invalid") + return errors.New("the operate type in the grant entity is invalid") } if entity.DbName == "" { entity.DbName = util.DefaultDBName @@ -1499,11 +1499,11 @@ func (mt *MetaTable) OperatePrivilege(ctx context.Context, tenant string, entity func (mt *MetaTable) SelectGrant(ctx context.Context, tenant string, entity *milvuspb.GrantEntity) ([]*milvuspb.GrantEntity, error) { var entities []*milvuspb.GrantEntity if entity == nil { - return entities, fmt.Errorf("the grant entity is nil") + return entities, errors.New("the grant entity is nil") } if entity.Role == nil || funcutil.IsEmptyString(entity.Role.Name) { - return entities, fmt.Errorf("the role entity in the grant entity is invalid") + return entities, errors.New("the role entity in the grant entity is invalid") } if entity.DbName == "" { entity.DbName = util.DefaultDBName @@ -1517,7 +1517,7 @@ func (mt *MetaTable) SelectGrant(ctx context.Context, tenant string, entity *mil func (mt *MetaTable) DropGrant(ctx context.Context, tenant string, role *milvuspb.RoleEntity) error { if role == nil || funcutil.IsEmptyString(role.Name) { - return fmt.Errorf("the role entity is invalid when dropping the grant") + return errors.New("the role entity is invalid when dropping the grant") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1569,7 +1569,7 @@ func (mt *MetaTable) IsCustomPrivilegeGroup(ctx context.Context, groupName strin func (mt *MetaTable) CreatePrivilegeGroup(ctx context.Context, groupName string) error { if funcutil.IsEmptyString(groupName) { - return fmt.Errorf("the privilege group name is empty") + return errors.New("the privilege group name is empty") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1593,7 +1593,7 @@ func (mt *MetaTable) CreatePrivilegeGroup(ctx context.Context, groupName string) func (mt *MetaTable) DropPrivilegeGroup(ctx context.Context, groupName string) error { if funcutil.IsEmptyString(groupName) { - return fmt.Errorf("the privilege group name is empty") + return errors.New("the privilege group name is empty") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1639,7 +1639,7 @@ func (mt *MetaTable) ListPrivilegeGroups(ctx context.Context) ([]*milvuspb.Privi func (mt *MetaTable) OperatePrivilegeGroup(ctx context.Context, groupName string, privileges []*milvuspb.PrivilegeEntity, operateType milvuspb.OperatePrivilegeGroupType) error { if funcutil.IsEmptyString(groupName) { - return fmt.Errorf("the privilege group name is empty") + return errors.New("the privilege group name is empty") } mt.permissionLock.Lock() defer mt.permissionLock.Unlock() @@ -1709,7 +1709,7 @@ func (mt *MetaTable) OperatePrivilegeGroup(ctx context.Context, groupName string func (mt *MetaTable) GetPrivilegeGroupRoles(ctx context.Context, groupName string) ([]*milvuspb.RoleEntity, error) { if funcutil.IsEmptyString(groupName) { - return nil, fmt.Errorf("the privilege group name is empty") + return nil, errors.New("the privilege group name is empty") } mt.permissionLock.RLock() defer mt.permissionLock.RUnlock() diff --git a/internal/rootcoord/quota_center_test.go b/internal/rootcoord/quota_center_test.go index 33b9d01794..d3aa3629a6 100644 --- a/internal/rootcoord/quota_center_test.go +++ b/internal/rootcoord/quota_center_test.go @@ -152,7 +152,7 @@ func TestQuotaCenter(t *testing.T) { assert.Error(t, err) dc.EXPECT().GetDcMetrics(mock.Anything, mock.Anything).Return(nil, errors.New("mock error")) - dc.EXPECT().GetQcMetrics(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock err")) + dc.EXPECT().GetQcMetrics(mock.Anything, mock.Anything).Return(nil, errors.New("mock err")) quotaCenter = NewQuotaCenter(pcm, dc, core.tsoAllocator, meta) err = quotaCenter.collectMetrics() assert.Error(t, err) @@ -454,7 +454,7 @@ func TestQuotaCenter(t *testing.T) { assert.NoError(t, err) alloc := newMockTsoAllocator() alloc.GenerateTSOF = func(count uint32) (typeutil.Timestamp, error) { - return 0, fmt.Errorf("mock tso err") + return 0, errors.New("mock tso err") } quotaCenter.tsoAllocator = alloc quotaCenter.clearMetrics() diff --git a/internal/rootcoord/rename_collection_task_test.go b/internal/rootcoord/rename_collection_task_test.go index 3b12042463..17edf01ac9 100644 --- a/internal/rootcoord/rename_collection_task_test.go +++ b/internal/rootcoord/rename_collection_task_test.go @@ -18,9 +18,9 @@ package rootcoord import ( "context" - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -76,7 +76,7 @@ func Test_renameCollectionTask_Execute(t *testing.T) { mockMeta := mockrootcoord.NewIMetaTable(t) mockMeta.EXPECT().GetCollectionID(mock.Anything, mock.Anything, mock.Anything).Return(111) mockMeta.EXPECT().RenameCollection(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(fmt.Errorf("failed to alter alias")) + Return(errors.New("failed to alter alias")) core := newTestCore(withValidProxyManager(), withMeta(mockMeta)) task := &renameCollectionTask{ baseTask: newBaseTask(context.Background(), core), diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index 6618445f58..e41f970d33 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -282,7 +282,7 @@ func (c *Core) SetTiKVClient(client *txnkv.Client) { func (c *Core) SetSession(session sessionutil.SessionInterface) error { c.session = session if c.session == nil { - return fmt.Errorf("session is nil, the etcd client connection may have failed") + return errors.New("session is nil, the etcd client connection may have failed") } return nil } diff --git a/internal/rootcoord/root_coord_test.go b/internal/rootcoord/root_coord_test.go index 3ab95b404d..c311d727eb 100644 --- a/internal/rootcoord/root_coord_test.go +++ b/internal/rootcoord/root_coord_test.go @@ -18,7 +18,6 @@ package rootcoord import ( "context" - "fmt" "math/rand" "os" "testing" @@ -742,7 +741,7 @@ func TestRootCoord_ShowCollectionIDs(t *testing.T) { ctx := context.Background() // specify db names - meta.EXPECT().GetDatabaseByName(mock.Anything, mock.Anything, typeutil.MaxTimestamp).Return(nil, fmt.Errorf("mock err")) + meta.EXPECT().GetDatabaseByName(mock.Anything, mock.Anything, typeutil.MaxTimestamp).Return(nil, errors.New("mock err")) resp, err := c.ShowCollectionIDs(ctx, &rootcoordpb.ShowCollectionIDsRequest{ DbNames: []string{"db1"}, AllowUnavailable: true, @@ -751,7 +750,7 @@ func TestRootCoord_ShowCollectionIDs(t *testing.T) { assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode()) // not specify db names - meta.EXPECT().ListDatabases(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock err")) + meta.EXPECT().ListDatabases(mock.Anything, mock.Anything).Return(nil, errors.New("mock err")) resp, err = c.ShowCollectionIDs(ctx, &rootcoordpb.ShowCollectionIDsRequest{}) assert.NoError(t, err) assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode()) @@ -760,7 +759,7 @@ func TestRootCoord_ShowCollectionIDs(t *testing.T) { meta.ExpectedCalls = nil meta.EXPECT().ListDatabases(mock.Anything, mock.Anything).Return( []*model.Database{model.NewDatabase(rand.Int63(), "db1", etcdpb.DatabaseState_DatabaseCreated, nil)}, nil) - meta.EXPECT().ListCollections(mock.Anything, mock.Anything, typeutil.MaxTimestamp, false).Return(nil, fmt.Errorf("mock err")) + meta.EXPECT().ListCollections(mock.Anything, mock.Anything, typeutil.MaxTimestamp, false).Return(nil, errors.New("mock err")) resp, err = c.ShowCollectionIDs(ctx, &rootcoordpb.ShowCollectionIDsRequest{ AllowUnavailable: true, }) diff --git a/internal/rootcoord/scheduler_test.go b/internal/rootcoord/scheduler_test.go index 7420e738e5..4c0c7cc8a1 100644 --- a/internal/rootcoord/scheduler_test.go +++ b/internal/rootcoord/scheduler_test.go @@ -18,7 +18,6 @@ package rootcoord import ( "context" - "fmt" "math/rand" "sync" "testing" @@ -258,7 +257,7 @@ func Test_scheduler_updateDdlMinTsLoop(t *testing.T) { return 100, nil } tsoAlloc.GenerateTSOF = func(count uint32) (uint64, error) { - return 0, fmt.Errorf("error mock GenerateTSO") + return 0, errors.New("error mock GenerateTSO") } ctx := context.Background() s := newScheduler(ctx, idAlloc, tsoAlloc) diff --git a/internal/rootcoord/timeticksync.go b/internal/rootcoord/timeticksync.go index f47fd7dd14..26075dd089 100644 --- a/internal/rootcoord/timeticksync.go +++ b/internal/rootcoord/timeticksync.go @@ -22,6 +22,7 @@ import ( "sync" "time" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -200,7 +201,7 @@ func (t *timetickSync) updateTimeTick(in *internalpb.ChannelTimeTickMsg, reason return nil } if len(in.Timestamps) != len(in.ChannelNames) { - return fmt.Errorf("invalid TimeTickMsg, timestamp and channelname size mismatch") + return errors.New("invalid TimeTickMsg, timestamp and channelname size mismatch") } prev, ok := t.sess2ChanTsMap[in.Base.SourceID] diff --git a/internal/rootcoord/undo.go b/internal/rootcoord/undo.go index 0928cbe140..55cd1ef2da 100644 --- a/internal/rootcoord/undo.go +++ b/internal/rootcoord/undo.go @@ -18,8 +18,8 @@ package rootcoord import ( "context" - "fmt" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus/pkg/v2/log" @@ -46,7 +46,7 @@ func (b *baseUndoTask) AddStep(todoStep, undoStep nestedStep) { func (b *baseUndoTask) Execute(ctx context.Context) error { if len(b.todoStep) != len(b.undoStep) { - return fmt.Errorf("todo step and undo step length not equal") + return errors.New("todo step and undo step length not equal") } for i := 0; i < len(b.todoStep); i++ { todoStep := b.todoStep[i] diff --git a/internal/storage/binlog_test.go b/internal/storage/binlog_test.go index 74c3a7eff3..8efe8a6daf 100644 --- a/internal/storage/binlog_test.go +++ b/internal/storage/binlog_test.go @@ -24,6 +24,7 @@ import ( "time" "unsafe" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -1477,7 +1478,7 @@ type testEvent struct { func (e *testEvent) Finish() error { if e.finishError { - return fmt.Errorf("finish error") + return errors.New("finish error") } return nil } @@ -1487,21 +1488,21 @@ func (e *testEvent) Close() { func (e *testEvent) Write(buffer *bytes.Buffer) error { if e.writeError { - return fmt.Errorf("write error") + return errors.New("write error") } return nil } func (e *testEvent) GetMemoryUsageInBytes() (int32, error) { if e.getMemoryError { - return -1, fmt.Errorf("getMemory error") + return -1, errors.New("getMemory error") } return 0, nil } func (e *testEvent) GetPayloadLengthFromWriter() (int, error) { if e.getPayloadLengthError { - return -1, fmt.Errorf("getPayloadLength error") + return -1, errors.New("getPayloadLength error") } return 0, nil } diff --git a/internal/storage/binlog_writer.go b/internal/storage/binlog_writer.go index 38e4934f42..47f30e242f 100644 --- a/internal/storage/binlog_writer.go +++ b/internal/storage/binlog_writer.go @@ -19,7 +19,8 @@ package storage import ( "bytes" "encoding/binary" - "fmt" + + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/common" @@ -91,7 +92,7 @@ func (writer *baseBinlogWriter) GetBinlogType() BinlogType { // GetBuffer gets binlog buffer. Return nil if binlog is not finished yet. func (writer *baseBinlogWriter) GetBuffer() ([]byte, error) { if writer.buffer == nil { - return nil, fmt.Errorf("please close binlog before get buffer") + return nil, errors.New("please close binlog before get buffer") } return writer.buffer.Bytes(), nil } @@ -102,7 +103,7 @@ func (writer *baseBinlogWriter) Finish() error { return nil } if writer.StartTimestamp == 0 || writer.EndTimestamp == 0 { - return fmt.Errorf("invalid start/end timestamp") + return errors.New("invalid start/end timestamp") } var offset int32 @@ -153,7 +154,7 @@ type InsertBinlogWriter struct { // NextInsertEventWriter returns an event writer to write insert data to an event. func (writer *InsertBinlogWriter) NextInsertEventWriter(opts ...PayloadWriterOptions) (*insertEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newInsertEventWriter(writer.PayloadDataType, opts...) @@ -173,7 +174,7 @@ type DeleteBinlogWriter struct { // NextDeleteEventWriter returns an event writer to write delete data to an event. func (writer *DeleteBinlogWriter) NextDeleteEventWriter(opts ...PayloadWriterOptions) (*deleteEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newDeleteEventWriter(writer.PayloadDataType, opts...) if err != nil { @@ -192,7 +193,7 @@ type DDLBinlogWriter struct { // information to an event. func (writer *DDLBinlogWriter) NextCreateCollectionEventWriter() (*createCollectionEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newCreateCollectionEventWriter(writer.PayloadDataType) if err != nil { @@ -206,7 +207,7 @@ func (writer *DDLBinlogWriter) NextCreateCollectionEventWriter() (*createCollect // information to an event. func (writer *DDLBinlogWriter) NextDropCollectionEventWriter() (*dropCollectionEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newDropCollectionEventWriter(writer.PayloadDataType) if err != nil { @@ -220,7 +221,7 @@ func (writer *DDLBinlogWriter) NextDropCollectionEventWriter() (*dropCollectionE // information to an event. func (writer *DDLBinlogWriter) NextCreatePartitionEventWriter() (*createPartitionEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newCreatePartitionEventWriter(writer.PayloadDataType) if err != nil { @@ -234,7 +235,7 @@ func (writer *DDLBinlogWriter) NextCreatePartitionEventWriter() (*createPartitio // information to an event. func (writer *DDLBinlogWriter) NextDropPartitionEventWriter() (*dropPartitionEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newDropPartitionEventWriter(writer.PayloadDataType) if err != nil { @@ -252,7 +253,7 @@ type IndexFileBinlogWriter struct { // NextIndexFileEventWriter return next available EventWriter func (writer *IndexFileBinlogWriter) NextIndexFileEventWriter() (*indexFileEventWriter, error) { if writer.isClosed() { - return nil, fmt.Errorf("binlog has closed") + return nil, errors.New("binlog has closed") } event, err := newIndexFileEventWriter(writer.PayloadDataType) if err != nil { diff --git a/internal/storage/data_codec.go b/internal/storage/data_codec.go index 099941e5b3..109ef161be 100644 --- a/internal/storage/data_codec.go +++ b/internal/storage/data_codec.go @@ -22,6 +22,7 @@ import ( "math" "sort" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -133,7 +134,7 @@ func NewInsertCodecWithSchema(schema *etcdpb.CollectionMeta) *InsertCodec { // Serialize Pk stats log func (insertCodec *InsertCodec) SerializePkStats(stats *PrimaryKeyStats, rowNum int64) (*Blob, error) { if stats == nil || stats.BF == nil { - return nil, fmt.Errorf("sericalize empty pk stats") + return nil, errors.New("sericalize empty pk stats") } // Serialize by pk stats @@ -178,10 +179,10 @@ func (insertCodec *InsertCodec) SerializePkStatsList(stats []*PrimaryKeyStats, r func (insertCodec *InsertCodec) SerializePkStatsByData(data *InsertData) (*Blob, error) { timeFieldData, ok := data.Data[common.TimeStampField] if !ok { - return nil, fmt.Errorf("data doesn't contains timestamp field") + return nil, errors.New("data doesn't contains timestamp field") } if timeFieldData.RowNum() <= 0 { - return nil, fmt.Errorf("there's no data in InsertData") + return nil, errors.New("there's no data in InsertData") } rowNum := int64(timeFieldData.RowNum()) @@ -204,7 +205,7 @@ func (insertCodec *InsertCodec) SerializePkStatsByData(data *InsertData) (*Blob, RowNum: rowNum, }, nil } - return nil, fmt.Errorf("there is no pk field") + return nil, errors.New("there is no pk field") } // Serialize transforms insert data to blob. It will sort insert data by timestamp. @@ -215,7 +216,7 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique blobs := make([]*Blob, 0) var writer *InsertBinlogWriter if insertCodec.Schema == nil { - return nil, fmt.Errorf("schema is not set") + return nil, errors.New("schema is not set") } var rowNum int64 @@ -225,7 +226,7 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique for _, block := range data { timeFieldData, ok := block.Data[common.TimeStampField] if !ok { - return nil, fmt.Errorf("data doesn't contains timestamp field") + return nil, errors.New("data doesn't contains timestamp field") } rowNum += int64(timeFieldData.RowNum()) @@ -406,7 +407,7 @@ func (insertCodec *InsertCodec) DeserializeAll(blobs []*Blob) ( err error, ) { if len(blobs) == 0 { - return InvalidUniqueID, InvalidUniqueID, InvalidUniqueID, nil, fmt.Errorf("blobs is empty") + return InvalidUniqueID, InvalidUniqueID, InvalidUniqueID, nil, errors.New("blobs is empty") } var blobList BlobList = blobs @@ -733,7 +734,7 @@ func (deleteCodec *DeleteCodec) Serialize(collectionID UniqueID, partitionID Uni defer eventWriter.Close() length := len(data.Pks) if length != len(data.Tss) { - return nil, fmt.Errorf("the length of pks, and TimeStamps is not equal") + return nil, errors.New("the length of pks, and TimeStamps is not equal") } sizeTotal := 0 @@ -786,7 +787,7 @@ func (deleteCodec *DeleteCodec) Serialize(collectionID UniqueID, partitionID Uni // Deserialize deserializes the deltalog blobs into DeleteData func (deleteCodec *DeleteCodec) Deserialize(blobs []*Blob) (partitionID UniqueID, segmentID UniqueID, data *DeltaData, err error) { if len(blobs) == 0 { - return InvalidUniqueID, InvalidUniqueID, nil, fmt.Errorf("blobs is empty") + return InvalidUniqueID, InvalidUniqueID, nil, errors.New("blobs is empty") } rowNum := lo.SumBy(blobs, func(blob *Blob) int64 { @@ -983,7 +984,7 @@ func (dataDefinitionCodec *DataDefinitionCodec) Serialize(ts []Timestamp, ddRequ // It returns origin @ts and @ddRequests in the end. func (dataDefinitionCodec *DataDefinitionCodec) Deserialize(blobs []*Blob) (ts []Timestamp, ddRequests []string, err error) { if len(blobs) == 0 { - return nil, nil, fmt.Errorf("blobs is empty") + return nil, nil, errors.New("blobs is empty") } var requestsStrings []string var resultTs []Timestamp diff --git a/internal/storage/event_reader.go b/internal/storage/event_reader.go index b7f073dc76..dab6ca7974 100644 --- a/internal/storage/event_reader.go +++ b/internal/storage/event_reader.go @@ -20,6 +20,8 @@ import ( "bytes" "fmt" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" ) @@ -34,7 +36,7 @@ type EventReader struct { func (reader *EventReader) readHeader() error { if reader.isClosed { - return fmt.Errorf("event reader is closed") + return errors.New("event reader is closed") } header, err := readEventHeader(reader.buffer) if err != nil { @@ -46,7 +48,7 @@ func (reader *EventReader) readHeader() error { func (reader *EventReader) readData() error { if reader.isClosed { - return fmt.Errorf("event reader is closed") + return errors.New("event reader is closed") } var data eventData var err error diff --git a/internal/storage/field_stats.go b/internal/storage/field_stats.go index b08769aca5..b1ba4360b6 100644 --- a/internal/storage/field_stats.go +++ b/internal/storage/field_stats.go @@ -17,8 +17,7 @@ package storage import ( - "fmt" - + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -68,7 +67,7 @@ func (stats *FieldStats) UnmarshalJSON(data []byte) error { return err } } else { - return fmt.Errorf("invalid fieldStats, no fieldID") + return errors.New("invalid fieldStats, no fieldID") } stats.Type = schemapb.DataType_Int64 diff --git a/internal/storage/field_value.go b/internal/storage/field_value.go index d95011f907..77186a04c6 100644 --- a/internal/storage/field_value.go +++ b/internal/storage/field_value.go @@ -21,6 +21,8 @@ import ( "math" "strings" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/json" "github.com/milvus-io/milvus/pkg/v2/log" @@ -157,7 +159,7 @@ func (ifv *Int8FieldValue) SetValue(data interface{}) error { value, ok := data.(int8) if !ok { log.Warn("wrong type value when setValue for Int64FieldValue") - return fmt.Errorf("wrong type value when setValue for Int64FieldValue") + return errors.New("wrong type value when setValue for Int64FieldValue") } ifv.Value = value @@ -277,7 +279,7 @@ func (ifv *Int16FieldValue) SetValue(data interface{}) error { value, ok := data.(int16) if !ok { log.Warn("wrong type value when setValue for Int64FieldValue") - return fmt.Errorf("wrong type value when setValue for Int64FieldValue") + return errors.New("wrong type value when setValue for Int64FieldValue") } ifv.Value = value @@ -397,7 +399,7 @@ func (ifv *Int32FieldValue) SetValue(data interface{}) error { value, ok := data.(int32) if !ok { log.Warn("wrong type value when setValue for Int64FieldValue") - return fmt.Errorf("wrong type value when setValue for Int64FieldValue") + return errors.New("wrong type value when setValue for Int64FieldValue") } ifv.Value = value @@ -517,7 +519,7 @@ func (ifv *Int64FieldValue) SetValue(data interface{}) error { value, ok := data.(int64) if !ok { log.Warn("wrong type value when setValue for Int64FieldValue") - return fmt.Errorf("wrong type value when setValue for Int64FieldValue") + return errors.New("wrong type value when setValue for Int64FieldValue") } ifv.Value = value @@ -638,7 +640,7 @@ func (ifv *FloatFieldValue) SetValue(data interface{}) error { value, ok := data.(float32) if !ok { log.Warn("wrong type value when setValue for FloatFieldValue") - return fmt.Errorf("wrong type value when setValue for FloatFieldValue") + return errors.New("wrong type value when setValue for FloatFieldValue") } ifv.Value = value @@ -758,7 +760,7 @@ func (ifv *DoubleFieldValue) SetValue(data interface{}) error { value, ok := data.(float64) if !ok { log.Warn("wrong type value when setValue for DoubleFieldValue") - return fmt.Errorf("wrong type value when setValue for DoubleFieldValue") + return errors.New("wrong type value when setValue for DoubleFieldValue") } ifv.Value = value @@ -854,7 +856,7 @@ func (sfv *StringFieldValue) UnmarshalJSON(data []byte) error { func (sfv *StringFieldValue) SetValue(data interface{}) error { value, ok := data.(string) if !ok { - return fmt.Errorf("wrong type value when setValue for StringFieldValue") + return errors.New("wrong type value when setValue for StringFieldValue") } sfv.Value = value @@ -932,7 +934,7 @@ func (vcfv *VarCharFieldValue) EQ(obj ScalarFieldValue) bool { func (vcfv *VarCharFieldValue) SetValue(data interface{}) error { value, ok := data.(string) if !ok { - return fmt.Errorf("wrong type value when setValue for StringFieldValue") + return errors.New("wrong type value when setValue for StringFieldValue") } vcfv.Value = value @@ -1012,7 +1014,7 @@ func (ifv *FloatVectorFieldValue) SetValue(data interface{}) error { value, ok := data.([]float32) if !ok { log.Warn("wrong type value when setValue for FloatVectorFieldValue") - return fmt.Errorf("wrong type value when setValue for FloatVectorFieldValue") + return errors.New("wrong type value when setValue for FloatVectorFieldValue") } ifv.Value = value diff --git a/internal/storage/index_data_codec.go b/internal/storage/index_data_codec.go index adfa5fbb28..9223e46028 100644 --- a/internal/storage/index_data_codec.go +++ b/internal/storage/index_data_codec.go @@ -321,7 +321,7 @@ func (indexCodec *IndexCodec) Deserialize(blobs []*Blob) ([]*Blob, map[string]st break } if file == nil { - return nil, nil, "", InvalidUniqueID, fmt.Errorf("can not find params blob") + return nil, nil, "", InvalidUniqueID, errors.New("can not find params blob") } info := struct { Params map[string]string diff --git a/internal/storage/payload_reader.go b/internal/storage/payload_reader.go index 34dc38980f..0f7903e1ed 100644 --- a/internal/storage/payload_reader.go +++ b/internal/storage/payload_reader.go @@ -621,7 +621,7 @@ func (r *PayloadReader) GetSparseFloatVectorFromPayload() (*SparseFloatVectorFie for _, value := range values { if len(value)%8 != 0 { - return nil, -1, fmt.Errorf("invalid bytesData length") + return nil, -1, errors.New("invalid bytesData length") } fieldData.Contents = append(fieldData.Contents, value) @@ -750,7 +750,7 @@ func (s *DataSet[T, E]) HasNext() bool { func (s *DataSet[T, E]) NextBatch(batch int64) ([]T, error) { if s.groupID > s.reader.NumRowGroups() || (s.groupID == s.reader.NumRowGroups() && s.cnt >= s.numRows) || s.numRows == 0 { - return nil, fmt.Errorf("has no more data") + return nil, errors.New("has no more data") } if s.groupID == 0 || s.cnt >= s.numRows { diff --git a/internal/storage/primary_key.go b/internal/storage/primary_key.go index 7aaa548ac6..b07316d02b 100644 --- a/internal/storage/primary_key.go +++ b/internal/storage/primary_key.go @@ -20,6 +20,8 @@ import ( "fmt" "strings" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/json" "github.com/milvus-io/milvus/pkg/v2/log" @@ -139,7 +141,7 @@ func (ip *Int64PrimaryKey) UnmarshalJSON(data []byte) error { func (ip *Int64PrimaryKey) SetValue(data interface{}) error { value, ok := data.(int64) if !ok { - return fmt.Errorf("wrong type value when setValue for Int64PrimaryKey") + return errors.New("wrong type value when setValue for Int64PrimaryKey") } ip.Value = value @@ -239,7 +241,7 @@ func (vcp *VarCharPrimaryKey) UnmarshalJSON(data []byte) error { func (vcp *VarCharPrimaryKey) SetValue(data interface{}) error { value, ok := data.(string) if !ok { - return fmt.Errorf("wrong type value when setValue for VarCharPrimaryKey") + return errors.New("wrong type value when setValue for VarCharPrimaryKey") } vcp.Value = value @@ -270,7 +272,7 @@ func GenPrimaryKeyByRawData(data interface{}, pkType schemapb.DataType) (Primary Value: data.(string), } default: - return nil, fmt.Errorf("not supported primary data type") + return nil, errors.New("not supported primary data type") } return result, nil @@ -303,11 +305,11 @@ func GenVarcharPrimaryKeys(data ...string) ([]PrimaryKey, error) { func ParseFieldData2PrimaryKeys(data *schemapb.FieldData) ([]PrimaryKey, error) { ret := make([]PrimaryKey, 0) if data == nil { - return ret, fmt.Errorf("failed to parse pks from nil field data") + return ret, errors.New("failed to parse pks from nil field data") } scalarData := data.GetScalars() if scalarData == nil { - return ret, fmt.Errorf("failed to parse pks from nil scalar data") + return ret, errors.New("failed to parse pks from nil scalar data") } switch data.Type { @@ -322,7 +324,7 @@ func ParseFieldData2PrimaryKeys(data *schemapb.FieldData) ([]PrimaryKey, error) ret = append(ret, pk) } default: - return ret, fmt.Errorf("not supported primary data type") + return ret, errors.New("not supported primary data type") } return ret, nil diff --git a/internal/storage/serde_events.go b/internal/storage/serde_events.go index 93a0db63a6..aea99065b6 100644 --- a/internal/storage/serde_events.go +++ b/internal/storage/serde_events.go @@ -28,6 +28,7 @@ import ( "github.com/apache/arrow/go/v17/arrow" "github.com/apache/arrow/go/v17/arrow/array" "github.com/apache/arrow/go/v17/arrow/memory" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -531,7 +532,7 @@ func (c *CompositeBinlogRecordWriter) Write(r Record) error { for fieldID, stats := range c.bm25Stats { field, ok := r.Column(fieldID).(*array.Binary) if !ok { - return fmt.Errorf("bm25 field value not found") + return errors.New("bm25 field value not found") } stats.AppendBytes(field.Value(i)) } @@ -1213,7 +1214,7 @@ func newDeltalogMultiFieldReader(blobs []*Blob) (*DeserializeReaderImpl[*DeleteL return NewDeserializeReader(reader, func(r Record, v []*DeleteLog) error { rec, ok := r.(*simpleArrowRecord) if !ok { - return fmt.Errorf("can not cast to simple arrow record") + return errors.New("can not cast to simple arrow record") } fields := rec.r.Schema().Fields() switch fields[0].Type.ID() { diff --git a/internal/storage/serde_events_v2.go b/internal/storage/serde_events_v2.go index 71343f853e..d5ea92f127 100644 --- a/internal/storage/serde_events_v2.go +++ b/internal/storage/serde_events_v2.go @@ -22,6 +22,7 @@ import ( "github.com/apache/arrow/go/v17/arrow" "github.com/apache/arrow/go/v17/arrow/array" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -297,7 +298,7 @@ func (pw *PackedBinlogRecordWriter) Write(r Record) error { for fieldID, stats := range pw.bm25Stats { field, ok := r.Column(fieldID).(*array.Binary) if !ok { - return fmt.Errorf("bm25 field value not found") + return errors.New("bm25 field value not found") } stats.AppendBytes(field.Value(i)) } diff --git a/internal/storage/stats.go b/internal/storage/stats.go index e24969168a..0a87c153b3 100644 --- a/internal/storage/stats.go +++ b/internal/storage/stats.go @@ -19,10 +19,10 @@ package storage import ( "bytes" "encoding/binary" - "fmt" "maps" "math" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -100,7 +100,7 @@ func (stats *PrimaryKeyStats) UnmarshalJSON(data []byte) error { stats.MaxPk = &VarCharPrimaryKey{} stats.MinPk = &VarCharPrimaryKey{} default: - return fmt.Errorf("Invalid PK Data Type") + return errors.New("Invalid PK Data Type") } if maxPkMessage, ok := messageMap["maxPk"]; ok && maxPkMessage != nil { diff --git a/internal/storage/utils.go b/internal/storage/utils.go index 6785e4b11d..0bc476eea4 100644 --- a/internal/storage/utils.go +++ b/internal/storage/utils.go @@ -441,7 +441,7 @@ func RowBasedInsertMsgToInsertData(msg *msgstream.InsertMsg, collSchema *schemap Dim: dim, } case schemapb.DataType_SparseFloatVector: - return nil, fmt.Errorf("Sparse Float Vector is not supported in row based data") + return nil, errors.New("Sparse Float Vector is not supported in row based data") case schemapb.DataType_Int8Vector: dim, err := GetDimFromParams(field.TypeParams) @@ -1326,7 +1326,7 @@ func TransferInsertDataToInsertRecord(insertData *InsertData) (*segcorepb.Insert }, } default: - return insertRecord, fmt.Errorf("unsupported data type when transter storage.InsertData to internalpb.InsertRecord") + return insertRecord, errors.New("unsupported data type when transter storage.InsertData to internalpb.InsertRecord") } insertRecord.FieldsData = append(insertRecord.FieldsData, fieldData) diff --git a/internal/storagev2/packed/packed_writer.go b/internal/storagev2/packed/packed_writer.go index 3f80212597..728e683a57 100644 --- a/internal/storagev2/packed/packed_writer.go +++ b/internal/storagev2/packed/packed_writer.go @@ -26,11 +26,11 @@ package packed import "C" import ( - "fmt" "unsafe" "github.com/apache/arrow/go/v17/arrow" "github.com/apache/arrow/go/v17/arrow/cdata" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus/internal/storagecommon" ) @@ -57,7 +57,7 @@ func NewPackedWriter(filePaths []string, schema *arrow.Schema, bufferSize int64, for _, group := range columnGroups { cGroup := C.malloc(C.size_t(len(group.Columns)) * C.size_t(unsafe.Sizeof(C.int(0)))) if cGroup == nil { - return nil, fmt.Errorf("failed to allocate memory for column groups") + return nil, errors.New("failed to allocate memory for column groups") } cGroupSlice := (*[1 << 30]C.int)(cGroup)[:len(group.Columns):len(group.Columns)] for i, val := range group.Columns { diff --git a/internal/util/function/alitext_embedding_provider_test.go b/internal/util/function/alitext_embedding_provider_test.go index fff23bccb0..5be55b2918 100644 --- a/internal/util/function/alitext_embedding_provider_test.go +++ b/internal/util/function/alitext_embedding_provider_test.go @@ -20,11 +20,11 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -78,7 +78,7 @@ func createAliProvider(url string, schema *schemapb.FieldSchema, providerName st case aliDashScopeProvider: return NewAliDashScopeEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/bedrock_embedding_provider.go b/internal/util/function/bedrock_embedding_provider.go index a21b0b6f4a..429256e2c7 100644 --- a/internal/util/function/bedrock_embedding_provider.go +++ b/internal/util/function/bedrock_embedding_provider.go @@ -29,6 +29,7 @@ import ( "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -59,7 +60,7 @@ func createBedRockEmbeddingClient(awsAccessKeyId string, awsSecretAccessKey stri return nil, fmt.Errorf("Missing credentials. Please pass `aws_secret_access_key`, or configure the %s environment variable in the Milvus service.", bedrockSAKEnvStr) } if region == "" { - return nil, fmt.Errorf("Missing AWS Service region. Please pass `region` param.") + return nil, errors.New("Missing AWS Service region. Please pass `region` param.") } cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region), diff --git a/internal/util/function/bedrock_text_embedding_provider_test.go b/internal/util/function/bedrock_text_embedding_provider_test.go index 6f381d554b..fd42a65c04 100644 --- a/internal/util/function/bedrock_text_embedding_provider_test.go +++ b/internal/util/function/bedrock_text_embedding_provider_test.go @@ -19,9 +19,9 @@ package function import ( - "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -73,7 +73,7 @@ func createBedrockProvider(schema *schemapb.FieldSchema, providerName string, di case bedrockProvider: return NewBedrockEmbeddingProvider(schema, functionSchema, &MockBedrockClient{dim: dim}, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/bm25_function.go b/internal/util/function/bm25_function.go index bafdb53b22..71907c06cc 100644 --- a/internal/util/function/bm25_function.go +++ b/internal/util/function/bm25_function.go @@ -22,6 +22,7 @@ import ( "fmt" "sync" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -72,7 +73,7 @@ func NewBM25FunctionRunner(coll *schemapb.CollectionSchema, schema *schemapb.Fun } if runner.outputField == nil { - return nil, fmt.Errorf("no output field") + return nil, errors.New("no output field") } tokenizer, err := ctokenizer.NewTokenizer(params) if err != nil { @@ -107,12 +108,12 @@ func (v *BM25FunctionRunner) run(data []string, dst []map[uint32]float32) error func (v *BM25FunctionRunner) BatchRun(inputs ...any) ([]any, error) { if len(inputs) > 1 { - return nil, fmt.Errorf("BM25 function received more than one input column") + return nil, errors.New("BM25 function received more than one input column") } text, ok := inputs[0].([]string) if !ok { - return nil, fmt.Errorf("BM25 function batch input not string list") + return nil, errors.New("BM25 function batch input not string list") } rowNum := len(text) diff --git a/internal/util/function/cohere_embedding_provider_test.go b/internal/util/function/cohere_embedding_provider_test.go index 50f2e9f64f..356c779c6a 100644 --- a/internal/util/function/cohere_embedding_provider_test.go +++ b/internal/util/function/cohere_embedding_provider_test.go @@ -20,11 +20,11 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -77,7 +77,7 @@ func createCohereProvider(url string, schema *schemapb.FieldSchema, providerName case cohereProvider: return NewCohereEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/function_executor.go b/internal/util/function/function_executor.go index 66913d1dd8..c7454959fa 100644 --- a/internal/util/function/function_executor.go +++ b/internal/util/function/function_executor.go @@ -24,6 +24,7 @@ import ( "strconv" "sync" + "github.com/cockroachdb/errors" "google.golang.org/protobuf/proto" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -116,7 +117,7 @@ func (executor *FunctionExecutor) processSingleFunction(ctx context.Context, run } } if len(inputs) != len(runner.GetSchema().InputFieldIds) { - return nil, fmt.Errorf("Input field not found") + return nil, errors.New("Input field not found") } tr := timerecord.NewTimeRecorder("function ProcessInsert") diff --git a/internal/util/function/models/ali/ali_dashscope_text_embedding.go b/internal/util/function/models/ali/ali_dashscope_text_embedding.go index 119983e8cc..c55e2eb8ec 100644 --- a/internal/util/function/models/ali/ali_dashscope_text_embedding.go +++ b/internal/util/function/models/ali/ali_dashscope_text_embedding.go @@ -24,6 +24,8 @@ import ( "sort" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/function/models/utils" ) @@ -107,11 +109,11 @@ func NewAliDashScopeEmbeddingClient(apiKey string, url string) *AliDashScopeEmbe func (c *AliDashScopeEmbedding) Check() error { if c.apiKey == "" { - return fmt.Errorf("api key is empty") + return errors.New("api key is empty") } if c.url == "" { - return fmt.Errorf("url is empty") + return errors.New("url is empty") } return nil } diff --git a/internal/util/function/models/cohere/cohere_text_embedding.go b/internal/util/function/models/cohere/cohere_text_embedding.go index cca6c08172..03d2c528c1 100644 --- a/internal/util/function/models/cohere/cohere_text_embedding.go +++ b/internal/util/function/models/cohere/cohere_text_embedding.go @@ -23,6 +23,8 @@ import ( "net/http" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/function/models/utils" ) @@ -69,11 +71,11 @@ func NewCohereEmbeddingClient(apiKey string, url string) *CohereEmbedding { func (c *CohereEmbedding) Check() error { if c.apiKey == "" { - return fmt.Errorf("api key is empty") + return errors.New("api key is empty") } if c.url == "" { - return fmt.Errorf("url is empty") + return errors.New("url is empty") } return nil } diff --git a/internal/util/function/models/openai/openai_embedding.go b/internal/util/function/models/openai/openai_embedding.go index 54bf01e9fb..8d65fef025 100644 --- a/internal/util/function/models/openai/openai_embedding.go +++ b/internal/util/function/models/openai/openai_embedding.go @@ -25,6 +25,8 @@ import ( "sort" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/function/models/utils" ) @@ -111,11 +113,11 @@ type openAIBase struct { func (c *openAIBase) Check() error { if c.apiKey == "" { - return fmt.Errorf("api key is empty") + return errors.New("api key is empty") } if c.url == "" { - return fmt.Errorf("url is empty") + return errors.New("url is empty") } return nil } diff --git a/internal/util/function/models/siliconflow/siliconflow_text_embedding.go b/internal/util/function/models/siliconflow/siliconflow_text_embedding.go index 515dd7d1e3..1cce1e4545 100644 --- a/internal/util/function/models/siliconflow/siliconflow_text_embedding.go +++ b/internal/util/function/models/siliconflow/siliconflow_text_embedding.go @@ -24,6 +24,8 @@ import ( "sort" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/function/models/utils" ) @@ -89,11 +91,11 @@ func NewSiliconflowEmbeddingClient(apiKey string, url string) *SiliconflowEmbedd func (c *SiliconflowEmbedding) Check() error { if c.apiKey == "" { - return fmt.Errorf("api key is empty") + return errors.New("api key is empty") } if c.url == "" { - return fmt.Errorf("url is empty") + return errors.New("url is empty") } return nil } diff --git a/internal/util/function/models/vertexai/vertexai_text_embedding.go b/internal/util/function/models/vertexai/vertexai_text_embedding.go index 6b1afd294a..e2f5823f8d 100644 --- a/internal/util/function/models/vertexai/vertexai_text_embedding.go +++ b/internal/util/function/models/vertexai/vertexai_text_embedding.go @@ -23,6 +23,7 @@ import ( "net/http" "time" + "github.com/cockroachdb/errors" "golang.org/x/oauth2/google" "github.com/milvus-io/milvus/internal/util/function/models/utils" @@ -89,13 +90,13 @@ func NewVertexAIEmbedding(url string, jsonKey []byte, scopes string, token strin func (c *VertexAIEmbedding) Check() error { if c.url == "" { - return fmt.Errorf("VertexAI embedding url is empty") + return errors.New("VertexAI embedding url is empty") } if len(c.jsonKey) == 0 { - return fmt.Errorf("jsonKey is empty") + return errors.New("jsonKey is empty") } if c.scopes == "" { - return fmt.Errorf("Scopes param is empty") + return errors.New("Scopes param is empty") } return nil } diff --git a/internal/util/function/models/voyageai/voyageai_text_embedding.go b/internal/util/function/models/voyageai/voyageai_text_embedding.go index 67a1400766..ca8ce74a6b 100644 --- a/internal/util/function/models/voyageai/voyageai_text_embedding.go +++ b/internal/util/function/models/voyageai/voyageai_text_embedding.go @@ -24,6 +24,8 @@ import ( "sort" "time" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/internal/util/function/models/utils" ) @@ -98,11 +100,11 @@ func NewVoyageAIEmbeddingClient(apiKey string, url string) *VoyageAIEmbedding { func (c *VoyageAIEmbedding) Check() error { if c.apiKey == "" { - return fmt.Errorf("api key is empty") + return errors.New("api key is empty") } if c.url == "" { - return fmt.Errorf("url is empty") + return errors.New("url is empty") } return nil } diff --git a/internal/util/function/openai_text_embedding_provider_test.go b/internal/util/function/openai_text_embedding_provider_test.go index 2432bee688..45eac88a1b 100644 --- a/internal/util/function/openai_text_embedding_provider_test.go +++ b/internal/util/function/openai_text_embedding_provider_test.go @@ -20,12 +20,12 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "os" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -81,7 +81,7 @@ func createOpenAIProvider(url string, schema *schemapb.FieldSchema, providerName case azureOpenAIProvider: return NewAzureOpenAIEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/siliconflow_embedding_provider_test.go b/internal/util/function/siliconflow_embedding_provider_test.go index 7ec4b204c7..ed72ccd16c 100644 --- a/internal/util/function/siliconflow_embedding_provider_test.go +++ b/internal/util/function/siliconflow_embedding_provider_test.go @@ -20,11 +20,11 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -77,7 +77,7 @@ func createSiliconflowProvider(url string, schema *schemapb.FieldSchema, provide case siliconflowProvider: return NewSiliconflowEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/tei_embedding_provider.go b/internal/util/function/tei_embedding_provider.go index 131e9c1839..bb87610308 100644 --- a/internal/util/function/tei_embedding_provider.go +++ b/internal/util/function/tei_embedding_provider.go @@ -24,6 +24,8 @@ import ( "strconv" "strings" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/util/function/models/tei" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -46,7 +48,7 @@ type TeiEmbeddingProvider struct { func createTEIEmbeddingClient(apiKey string, endpoint string) (*tei.TEIEmbedding, error) { enable := os.Getenv(enableTeiEnvStr) if strings.ToLower(enable) == "false" { - return nil, fmt.Errorf("TEI model serving is not enabled") + return nil, errors.New("TEI model serving is not enabled") } return tei.NewTEIEmbeddingClient(apiKey, endpoint) diff --git a/internal/util/function/tei_embedding_provider_test.go b/internal/util/function/tei_embedding_provider_test.go index 5e31174df7..7323cfa1db 100644 --- a/internal/util/function/tei_embedding_provider_test.go +++ b/internal/util/function/tei_embedding_provider_test.go @@ -20,12 +20,12 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "os" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -78,7 +78,7 @@ func createTEIProvider(url string, schema *schemapb.FieldSchema, providerName st case teiProvider: return NewTEIEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/function/text_embedding_function.go b/internal/util/function/text_embedding_function.go index 6359e228e9..a65e5ef796 100644 --- a/internal/util/function/text_embedding_function.go +++ b/internal/util/function/text_embedding_function.go @@ -23,6 +23,8 @@ import ( "fmt" "reflect" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/storage" @@ -57,7 +59,7 @@ func hasEmptyString(texts []string) bool { func TextEmbeddingOutputsCheck(fields []*schemapb.FieldSchema) error { if len(fields) != 1 || (fields[0].DataType != schemapb.DataType_FloatVector && fields[0].DataType != schemapb.DataType_Int8Vector) { - return fmt.Errorf("TextEmbedding function output field must be a FloatVector or Int8Vector field") + return errors.New("TextEmbedding function output field must be a FloatVector or Int8Vector field") } return nil } @@ -222,12 +224,12 @@ func (runner *TextEmbeddingFunction) ProcessInsert(ctx context.Context, inputs [ texts := inputs[0].GetScalars().GetStringData().GetData() if texts == nil { - return nil, fmt.Errorf("Input texts is empty") + return nil, errors.New("Input texts is empty") } // make sure all texts are not empty if hasEmptyString(texts) { - return nil, fmt.Errorf("There is an empty string in the input data, TextEmbedding function does not support empty text") + return nil, errors.New("There is an empty string in the input data, TextEmbedding function does not support empty text") } numRows := len(texts) if numRows > runner.MaxBatch() { @@ -250,7 +252,7 @@ func (runner *TextEmbeddingFunction) ProcessSearch(ctx context.Context, placehol } // make sure all texts are not empty if hasEmptyString(texts) { - return nil, fmt.Errorf("There is an empty string in the queries, TextEmbedding function does not support empty text") + return nil, errors.New("There is an empty string in the queries, TextEmbedding function does not support empty text") } embds, err := runner.embProvider.CallEmbedding(texts, SearchMode) if err != nil { @@ -275,13 +277,13 @@ func (runner *TextEmbeddingFunction) ProcessBulkInsert(inputs []storage.FieldDat texts, ok := inputs[0].GetDataRows().([]string) if !ok { - return nil, fmt.Errorf("Input texts is empty") + return nil, errors.New("Input texts is empty") } // make sure all texts are not empty // In storage.FieldData, null is also stored as an empty string if hasEmptyString(texts) { - return nil, fmt.Errorf("There is an empty string in the input data, TextEmbedding function does not support empty text") + return nil, errors.New("There is an empty string in the input data, TextEmbedding function does not support empty text") } embds, err := runner.embProvider.CallEmbedding(texts, InsertMode) if err != nil { @@ -316,5 +318,5 @@ func (runner *TextEmbeddingFunction) ProcessBulkInsert(inputs []storage.FieldDat runner.outputFields[0].FieldID: field, }, nil } - return nil, fmt.Errorf("Unknow embedding type") + return nil, errors.New("Unknow embedding type") } diff --git a/internal/util/function/vertexai_embedding_provider.go b/internal/util/function/vertexai_embedding_provider.go index 9b4abb2b9d..043c2392f7 100644 --- a/internal/util/function/vertexai_embedding_provider.go +++ b/internal/util/function/vertexai_embedding_provider.go @@ -24,6 +24,8 @@ import ( "strings" "sync" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/internal/util/function/models/vertexai" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -48,7 +50,7 @@ func getVertexAIJsonKey(credentialsFilePath string) ([]byte, error) { jsonKeyPath = credentialsFilePath } if jsonKeyPath == "" { - return nil, fmt.Errorf("VetexAI credentials file path is empty") + return nil, errors.New("VetexAI credentials file path is empty") } if vtxKey.filePath == jsonKeyPath { diff --git a/internal/util/function/voyageai_embedding_provider_test.go b/internal/util/function/voyageai_embedding_provider_test.go index 84c594bc70..610b7c4357 100644 --- a/internal/util/function/voyageai_embedding_provider_test.go +++ b/internal/util/function/voyageai_embedding_provider_test.go @@ -20,11 +20,11 @@ package function import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -78,7 +78,7 @@ func createVoyageAIProvider(url string, schema *schemapb.FieldSchema, providerNa case voyageAIProvider: return NewVoyageAIEmbeddingProvider(schema, functionSchema, map[string]string{}) default: - return nil, fmt.Errorf("Unknow provider") + return nil, errors.New("Unknow provider") } } diff --git a/internal/util/funcutil/count_util.go b/internal/util/funcutil/count_util.go index 170fc50b35..b498a6c228 100644 --- a/internal/util/funcutil/count_util.go +++ b/internal/util/funcutil/count_util.go @@ -1,7 +1,7 @@ package funcutil import ( - "fmt" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" @@ -12,7 +12,7 @@ import ( func CntOfInternalResult(res *internalpb.RetrieveResults) (int64, error) { if len(res.GetFieldsData()) != 1 { - return 0, fmt.Errorf("internal count result should only have one column") + return 0, errors.New("internal count result should only have one column") } f := res.GetFieldsData()[0] @@ -21,7 +21,7 @@ func CntOfInternalResult(res *internalpb.RetrieveResults) (int64, error) { func CntOfSegCoreResult(res *segcorepb.RetrieveResults) (int64, error) { if len(res.GetFieldsData()) != 1 { - return 0, fmt.Errorf("segcore count result should only have one column") + return 0, errors.New("segcore count result should only have one column") } f := res.GetFieldsData()[0] @@ -31,14 +31,14 @@ func CntOfSegCoreResult(res *segcorepb.RetrieveResults) (int64, error) { func CntOfFieldData(f *schemapb.FieldData) (int64, error) { scalars := f.GetScalars() if scalars == nil { - return 0, fmt.Errorf("count result should be scalar") + return 0, errors.New("count result should be scalar") } data := scalars.GetLongData() if data == nil { - return 0, fmt.Errorf("count result should be int64 data") + return 0, errors.New("count result should be int64 data") } if len(data.GetData()) != 1 { - return 0, fmt.Errorf("count result shoud only have one row") + return 0, errors.New("count result shoud only have one row") } return data.GetData()[0], nil } @@ -85,7 +85,7 @@ func WrapCntToQueryResults(cnt int64) *milvuspb.QueryResults { func CntOfQueryResults(res *milvuspb.QueryResults) (int64, error) { if len(res.GetFieldsData()) != 1 { - return 0, fmt.Errorf("milvus count result should only have one column") + return 0, errors.New("milvus count result should only have one column") } f := res.GetFieldsData()[0] diff --git a/internal/util/grpcclient/client_test.go b/internal/util/grpcclient/client_test.go index 168a25104c..1b51c09217 100644 --- a/internal/util/grpcclient/client_test.go +++ b/internal/util/grpcclient/client_test.go @@ -124,7 +124,7 @@ func TestClientBase_NodeSessionNotExist(t *testing.T) { base.grpcClient = &clientConnWrapper[*mockClient]{client: &mockClient{}} base.grpcClientMtx.Unlock() _, err = base.Call(ctx, func(client *mockClient) (any, error) { - return struct{}{}, status.Errorf(codes.Unknown, merr.ErrNodeNotMatch.Error()) + return struct{}{}, status.Error(codes.Unknown, merr.ErrNodeNotMatch.Error()) }) assert.True(t, IsServerIDMismatchErr(err)) @@ -133,7 +133,7 @@ func TestClientBase_NodeSessionNotExist(t *testing.T) { base.grpcClient = &clientConnWrapper[*mockClient]{client: &mockClient{}} base.grpcClientMtx.Unlock() _, err = base.Call(ctx, func(client *mockClient) (any, error) { - return struct{}{}, status.Errorf(codes.Unavailable, "fake error") + return struct{}{}, status.Error(codes.Unavailable, "fake error") }) assert.True(t, errors.Is(err, merr.ErrNodeNotFound)) } @@ -370,35 +370,35 @@ func TestClientBase_CheckGrpcError(t *testing.T) { base.MaxAttempts = 1 ctx := context.Background() - retry, reset, forceReset, _ := base.checkGrpcErr(ctx, status.Errorf(codes.Canceled, "fake context canceled")) + retry, reset, forceReset, _ := base.checkGrpcErr(ctx, status.Error(codes.Canceled, "fake context canceled")) assert.True(t, retry) assert.True(t, reset) assert.False(t, forceReset) - retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Errorf(codes.Unimplemented, "fake context canceled")) + retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Error(codes.Unimplemented, "fake context canceled")) assert.False(t, retry) assert.True(t, reset) assert.True(t, forceReset) - retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Errorf(codes.Unavailable, "fake context canceled")) + retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Error(codes.Unavailable, "fake context canceled")) assert.True(t, retry) assert.True(t, reset) assert.True(t, forceReset) // test serverId mismatch - retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Errorf(codes.Unknown, merr.ErrNodeNotMatch.Error())) + retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Error(codes.Unknown, merr.ErrNodeNotMatch.Error())) assert.True(t, retry) assert.True(t, reset) assert.True(t, forceReset) // test cross cluster - retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Errorf(codes.Unknown, merr.ErrServiceCrossClusterRouting.Error())) + retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Error(codes.Unknown, merr.ErrServiceCrossClusterRouting.Error())) assert.True(t, retry) assert.True(t, reset) assert.True(t, forceReset) // test default - retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Errorf(codes.Unknown, merr.ErrNodeNotFound.Error())) + retry, reset, forceReset, _ = base.checkGrpcErr(ctx, status.Error(codes.Unknown, merr.ErrNodeNotFound.Error())) assert.True(t, retry) assert.True(t, reset) assert.False(t, forceReset) @@ -417,7 +417,7 @@ func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*he log.Printf("success %d", s.reqCounter) return &helloworld.HelloReply{Message: strings.ToUpper(in.Name)}, nil } - return nil, status.Errorf(codes.Unavailable, "server: fail it") + return nil, status.Error(codes.Unavailable, "server: fail it") } func TestClientBase_RetryPolicy(t *testing.T) { diff --git a/internal/util/grpcclient/local_grpc_client.go b/internal/util/grpcclient/local_grpc_client.go index 21afecf061..879cc0f524 100644 --- a/internal/util/grpcclient/local_grpc_client.go +++ b/internal/util/grpcclient/local_grpc_client.go @@ -2,7 +2,6 @@ package grpcclient import ( "context" - "fmt" "reflect" "strings" @@ -33,7 +32,7 @@ type localConn struct { func (c *localConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { methodDesc := c.findMethod(method) if methodDesc == nil { - return status.Errorf(codes.Unimplemented, fmt.Sprintf("method %s not implemented", method)) + return status.Errorf(codes.Unimplemented, "method %s not implemented", method) } resp, err := methodDesc.Handler(c.server, ctx, func(in any) error { reflect.ValueOf(in).Elem().Set(reflect.ValueOf(args).Elem()) diff --git a/internal/util/hookutil/hook.go b/internal/util/hookutil/hook.go index 920cca04aa..d78dd67e78 100644 --- a/internal/util/hookutil/hook.go +++ b/internal/util/hookutil/hook.go @@ -24,6 +24,7 @@ import ( "sync" "sync/atomic" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/hook" @@ -87,7 +88,7 @@ func initHook() error { var ok bool hookVal, ok = h.(hook.Hook) if !ok { - return fmt.Errorf("fail to convert the `Hook` interface") + return errors.New("fail to convert the `Hook` interface") } if err = hookVal.Init(paramtable.GetHookParams().SoConfig.GetValue()); err != nil { return fmt.Errorf("fail to init configs for the hook, error: %s", err.Error()) @@ -113,7 +114,7 @@ func initHook() error { var extVal hook.Extension extVal, ok = e.(hook.Extension) if !ok { - return fmt.Errorf("fail to convert the `Extension` interface") + return errors.New("fail to convert the `Extension` interface") } storeExtension(extVal) diff --git a/internal/util/idalloc/basic_allocator.go b/internal/util/idalloc/basic_allocator.go index f96eb1bd43..4e2249ca6f 100644 --- a/internal/util/idalloc/basic_allocator.go +++ b/internal/util/idalloc/basic_allocator.go @@ -98,7 +98,7 @@ func (ta *tsoAllocator) batchAllocate(ctx context.Context, count uint32) (uint64 return 0, 0, fmt.Errorf("syncTimeStamp Failed:%s", resp.GetStatus().GetReason()) } if resp == nil { - return 0, 0, fmt.Errorf("empty AllocTimestampResponse") + return 0, 0, errors.New("empty AllocTimestampResponse") } return resp.GetTimestamp(), int(resp.GetCount()), nil } @@ -143,7 +143,7 @@ func (ta *idAllocator) batchAllocate(ctx context.Context, count uint32) (uint64, return 0, 0, fmt.Errorf("AllocID Failed:%s", resp.GetStatus().GetReason()) } if resp == nil { - return 0, 0, fmt.Errorf("empty AllocID") + return 0, 0, errors.New("empty AllocID") } if resp.GetID() < 0 { panic("get unexpected negative id") diff --git a/internal/util/importutilv2/csv/row_parser.go b/internal/util/importutilv2/csv/row_parser.go index 9cadaaf4ae..9007a2e148 100644 --- a/internal/util/importutilv2/csv/row_parser.go +++ b/internal/util/importutilv2/csv/row_parser.go @@ -21,6 +21,7 @@ import ( "strconv" "strings" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -99,7 +100,7 @@ func NewRowParser(schema *schemapb.CollectionSchema, header []string, nullkey st func (r *rowParser) Parse(strArr []string) (Row, error) { if len(strArr) != len(r.header) { - return nil, fmt.Errorf("the number of fields in the row is not equal to the header") + return nil, errors.New("the number of fields in the row is not equal to the header") } row := make(Row) @@ -143,7 +144,7 @@ func (r *rowParser) combineDynamicRow(dynamicValues map[string]string, row Row) var mp map[string]interface{} err := json.Unmarshal([]byte(str), &mp) if err != nil { - return fmt.Errorf("illegal value for dynamic field, not a JSON format string") + return errors.New("illegal value for dynamic field, not a JSON format string") } // put the all dynamic fields into newDynamicValues for k, v := range mp { @@ -164,7 +165,7 @@ func (r *rowParser) combineDynamicRow(dynamicValues map[string]string, row Row) // check if stasify the json format dynamicBytes, err := json.Marshal(newDynamicValues) if err != nil { - return fmt.Errorf("illegal value for dynamic field, not a JSON object") + return errors.New("illegal value for dynamic field, not a JSON object") } row[dynamicFieldID] = dynamicBytes diff --git a/internal/util/importutilv2/json/row_parser.go b/internal/util/importutilv2/json/row_parser.go index 89cc2d53a7..b60251b30c 100644 --- a/internal/util/importutilv2/json/row_parser.go +++ b/internal/util/importutilv2/json/row_parser.go @@ -20,6 +20,7 @@ import ( "fmt" "strconv" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" @@ -179,14 +180,14 @@ func (r *rowParser) combineDynamicRow(dynamicValues map[string]any, row Row) err // case 1, 3 err := json.Unmarshal([]byte(value), &mp) if err != nil { - return fmt.Errorf("illegal value for dynamic field, not a JSON format string") + return errors.New("illegal value for dynamic field, not a JSON format string") } case map[string]interface{}: // case 2, 4, 5 mp = value default: // invalid input - return fmt.Errorf("illegal value for dynamic field, not a JSON object") + return errors.New("illegal value for dynamic field, not a JSON object") } delete(dynamicValues, r.dynamicField.GetName()) for k, v := range mp { diff --git a/internal/util/importutilv2/json/row_parser_test.go b/internal/util/importutilv2/json/row_parser_test.go index a15d907080..e7b3e90d96 100644 --- a/internal/util/importutilv2/json/row_parser_test.go +++ b/internal/util/importutilv2/json/row_parser_test.go @@ -231,7 +231,7 @@ func TestRowParser_Parse_Invalid(t *testing.T) { desc.UseNumber() err = desc.Decode(&mp) assert.Error(t, err) - assert.True(t, strings.Contains(err.Error(), c.expectErr)) + assert.True(t, strings.Contains(err.Error(), c.expectErr), "error: %s, expectErr: %s", err.Error(), c.expectErr) }) } } diff --git a/internal/util/importutilv2/parquet/field_reader.go b/internal/util/importutilv2/parquet/field_reader.go index 13702c6f35..e1011b6b81 100644 --- a/internal/util/importutilv2/parquet/field_reader.go +++ b/internal/util/importutilv2/parquet/field_reader.go @@ -23,6 +23,7 @@ import ( "github.com/apache/arrow/go/v17/arrow" "github.com/apache/arrow/go/v17/arrow/array" "github.com/apache/arrow/go/v17/parquet/pqarrow" + "github.com/cockroachdb/errors" "github.com/samber/lo" "golang.org/x/exp/constraints" @@ -958,7 +959,7 @@ func checkVectorAlignWithDim(offsets []int32, dim int32) error { func checkVectorAligned(offsets []int32, dim int, dataType schemapb.DataType) error { if len(offsets) < 1 { - return fmt.Errorf("empty offsets") + return errors.New("empty offsets") } switch dataType { case schemapb.DataType_BinaryVector: diff --git a/internal/util/indexcgowrapper/helper.go b/internal/util/indexcgowrapper/helper.go index a599b35864..2833bef4be 100644 --- a/internal/util/indexcgowrapper/helper.go +++ b/internal/util/indexcgowrapper/helper.go @@ -13,6 +13,8 @@ import ( "fmt" "unsafe" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus/pkg/v2/log" "github.com/milvus-io/milvus/pkg/v2/util/merr" ) @@ -20,7 +22,7 @@ import ( func GetBinarySetKeys(cBinarySet C.CBinarySet) ([]string, error) { size := int(C.GetBinarySetSize(cBinarySet)) if size == 0 { - return nil, fmt.Errorf("BinarySet size is zero") + return nil, errors.New("BinarySet size is zero") } datas := make([]unsafe.Pointer, size) @@ -39,7 +41,7 @@ func GetBinarySetValue(cBinarySet C.CBinarySet, key string) ([]byte, error) { ret := C.GetBinarySetValueSize(cBinarySet, cIndexKey) size := int(ret) if size == 0 { - return nil, fmt.Errorf("GetBinarySetValueSize size is zero") + return nil, errors.New("GetBinarySetValueSize size is zero") } value := make([]byte, size) status := C.CopyBinarySetValue(unsafe.Pointer(&value[0]), cIndexKey, cBinarySet) diff --git a/internal/util/indexparamcheck/bitmap_index_checker.go b/internal/util/indexparamcheck/bitmap_index_checker.go index bbda35816f..6996b70052 100644 --- a/internal/util/indexparamcheck/bitmap_index_checker.go +++ b/internal/util/indexparamcheck/bitmap_index_checker.go @@ -1,7 +1,7 @@ package indexparamcheck import ( - "fmt" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -17,18 +17,18 @@ func (c *BITMAPChecker) CheckTrain(dataType schemapb.DataType, params map[string func (c *BITMAPChecker) CheckValidDataType(indexType IndexType, field *schemapb.FieldSchema) error { if field.IsPrimaryKey { - return fmt.Errorf("create bitmap index on primary key not supported") + return errors.New("create bitmap index on primary key not supported") } mainType := field.GetDataType() elemType := field.GetElementType() if !typeutil.IsBoolType(mainType) && !typeutil.IsIntegerType(mainType) && !typeutil.IsStringType(mainType) && !typeutil.IsArrayType(mainType) { - return fmt.Errorf("bitmap index are only supported on bool, int, string and array field") + return errors.New("bitmap index are only supported on bool, int, string and array field") } if typeutil.IsArrayType(mainType) { if !typeutil.IsBoolType(elemType) && !typeutil.IsIntegerType(elemType) && !typeutil.IsStringType(elemType) { - return fmt.Errorf("bitmap index are only supported on bool, int, string for array field") + return errors.New("bitmap index are only supported on bool, int, string for array field") } } return nil diff --git a/internal/util/indexparamcheck/hybrid_index_checker.go b/internal/util/indexparamcheck/hybrid_index_checker.go index 63c10d384e..7e7258ac72 100644 --- a/internal/util/indexparamcheck/hybrid_index_checker.go +++ b/internal/util/indexparamcheck/hybrid_index_checker.go @@ -3,6 +3,8 @@ package indexparamcheck import ( "fmt" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/common" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -25,12 +27,12 @@ func (c *HYBRIDChecker) CheckValidDataType(indexType IndexType, field *schemapb. elemType := field.GetElementType() if !typeutil.IsBoolType(mainType) && !typeutil.IsIntegerType(mainType) && !typeutil.IsStringType(mainType) && !typeutil.IsArrayType(mainType) { - return fmt.Errorf("hybrid index are only supported on bool, int, string and array field") + return errors.New("hybrid index are only supported on bool, int, string and array field") } if typeutil.IsArrayType(mainType) { if !typeutil.IsBoolType(elemType) && !typeutil.IsIntegerType(elemType) && !typeutil.IsStringType(elemType) { - return fmt.Errorf("hybrid index are only supported on bool, int, string for array field") + return errors.New("hybrid index are only supported on bool, int, string for array field") } } return nil diff --git a/internal/util/indexparamcheck/stl_sort_checker.go b/internal/util/indexparamcheck/stl_sort_checker.go index 35c0c0defe..58abf8f8ba 100644 --- a/internal/util/indexparamcheck/stl_sort_checker.go +++ b/internal/util/indexparamcheck/stl_sort_checker.go @@ -1,7 +1,7 @@ package indexparamcheck import ( - "fmt" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -18,7 +18,7 @@ func (c *STLSORTChecker) CheckTrain(dataType schemapb.DataType, params map[strin func (c *STLSORTChecker) CheckValidDataType(indexType IndexType, field *schemapb.FieldSchema) error { if !typeutil.IsArithmetic(field.GetDataType()) { - return fmt.Errorf("STL_SORT are only supported on numeric field") + return errors.New("STL_SORT are only supported on numeric field") } return nil } diff --git a/internal/util/indexparamcheck/trie_checker.go b/internal/util/indexparamcheck/trie_checker.go index 2f510dfb61..ad9745071d 100644 --- a/internal/util/indexparamcheck/trie_checker.go +++ b/internal/util/indexparamcheck/trie_checker.go @@ -1,7 +1,7 @@ package indexparamcheck import ( - "fmt" + "github.com/cockroachdb/errors" "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/util/typeutil" @@ -18,7 +18,7 @@ func (c *TRIEChecker) CheckTrain(dataType schemapb.DataType, params map[string]s func (c *TRIEChecker) CheckValidDataType(indexType IndexType, field *schemapb.FieldSchema) error { if !typeutil.IsStringType(field.GetDataType()) { - return fmt.Errorf("TRIE are only supported on varchar field") + return errors.New("TRIE are only supported on varchar field") } return nil } diff --git a/internal/util/indexparamcheck/vector_index_checker.go b/internal/util/indexparamcheck/vector_index_checker.go index dfb5902cc3..16dc33c9b0 100644 --- a/internal/util/indexparamcheck/vector_index_checker.go +++ b/internal/util/indexparamcheck/vector_index_checker.go @@ -13,6 +13,7 @@ import ( "math" "unsafe" + "github.com/cockroachdb/errors" "google.golang.org/protobuf/proto" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -61,7 +62,7 @@ func (c vecIndexChecker) StaticCheck(dataType schemapb.DataType, params map[stri indexType, exist := params[common.IndexTypeKey] if !exist { - return fmt.Errorf("no indexType is specified") + return errors.New("no indexType is specified") } if !vecindexmgr.GetVecIndexMgrInstance().IsVecIndex(indexType) { @@ -98,7 +99,7 @@ func (c vecIndexChecker) CheckTrain(dataType schemapb.DataType, params map[strin if typeutil.IsFixDimVectorType(dataType) { if !CheckIntByRange(params, DIM, 1, math.MaxInt) { - return fmt.Errorf("failed to check vector dimension, should be larger than 0 and smaller than math.MaxInt") + return errors.New("failed to check vector dimension, should be larger than 0 and smaller than math.MaxInt") } } diff --git a/internal/util/proxyutil/proxy_client_manager_test.go b/internal/util/proxyutil/proxy_client_manager_test.go index f0d2e03fc5..60033dfaf5 100644 --- a/internal/util/proxyutil/proxy_client_manager_test.go +++ b/internal/util/proxyutil/proxy_client_manager_test.go @@ -18,7 +18,6 @@ package proxyutil import ( "context" - "fmt" "sync" "testing" @@ -66,7 +65,7 @@ func (p *proxyMock) InvalidateCollectionMetaCache(ctx context.Context, request * }, nil } if p.returnGrpcError { - return nil, fmt.Errorf("grpc error") + return nil, errors.New("grpc error") } p.collArray = append(p.collArray, request.CollectionName) p.collIDs = append(p.collIDs, request.CollectionID) @@ -95,7 +94,7 @@ func (p *proxyMock) InvalidateCredentialCache(ctx context.Context, request *prox }, nil } if p.returnGrpcError { - return nil, fmt.Errorf("grpc error") + return nil, errors.New("grpc error") } return merr.Success(), nil } diff --git a/internal/util/segcore/reduce.go b/internal/util/segcore/reduce.go index e943206aac..ceeb0bcc29 100644 --- a/internal/util/segcore/reduce.go +++ b/internal/util/segcore/reduce.go @@ -72,10 +72,10 @@ func NewStreamReducer(ctx context.Context, sliceTopKs []int64, ) (StreamSearchReducer, error) { if plan.cSearchPlan == nil { - return nil, fmt.Errorf("nil search plan") + return nil, errors.New("nil search plan") } if len(sliceNQs) == 0 { - return nil, fmt.Errorf("empty slice nqs is not allowed") + return nil, errors.New("empty slice nqs is not allowed") } if len(sliceNQs) != len(sliceTopKs) { return nil, fmt.Errorf("unaligned sliceNQs(len=%d) and sliceTopKs(len=%d)", len(sliceNQs), len(sliceTopKs)) @@ -119,11 +119,11 @@ func ReduceSearchResultsAndFillData(ctx context.Context, plan *SearchPlan, searc numSegments int64, sliceNQs []int64, sliceTopKs []int64, ) (SearchResultDataBlobs, error) { if plan.cSearchPlan == nil { - return nil, fmt.Errorf("nil search plan") + return nil, errors.New("nil search plan") } if len(sliceNQs) == 0 { - return nil, fmt.Errorf("empty slice nqs is not allowed") + return nil, errors.New("empty slice nqs is not allowed") } if len(sliceNQs) != len(sliceTopKs) { @@ -133,7 +133,7 @@ func ReduceSearchResultsAndFillData(ctx context.Context, plan *SearchPlan, searc cSearchResults := make([]C.CSearchResult, 0) for _, res := range searchResults { if res == nil { - return nil, fmt.Errorf("nil searchResult detected when reduceSearchResultsAndFillData") + return nil, errors.New("nil searchResult detected when reduceSearchResultsAndFillData") } cSearchResults = append(cSearchResults, res.cSearchResult) } diff --git a/internal/util/sessionutil/session_util.go b/internal/util/sessionutil/session_util.go index ecb4e6ed3c..00e2f56e23 100644 --- a/internal/util/sessionutil/session_util.go +++ b/internal/util/sessionutil/session_util.go @@ -633,7 +633,7 @@ func fnWithTimeout(fn func() error, d time.Duration) error { case <-resultChan: log.Ctx(context.TODO()).Debug("retry func success") case <-time.After(d): - return fmt.Errorf("func timed out") + return errors.New("func timed out") } return err1 } diff --git a/pkg/common/common.go b/pkg/common/common.go index 6314b5d0f7..827bd17580 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -459,7 +459,7 @@ func ValidateAutoIndexMmapConfig(autoIndexConfigEnable, isVectorField bool, inde _, ok := indexParams[MmapEnabledKey] if ok && isVectorField { - return fmt.Errorf("mmap index is not supported to config for the collection in auto index mode") + return errors.New("mmap index is not supported to config for the collection in auto index mode") } return nil } diff --git a/pkg/go.mod b/pkg/go.mod index 7d96cd1813..7a5b204b7e 100644 --- a/pkg/go.mod +++ b/pkg/go.mod @@ -1,6 +1,6 @@ module github.com/milvus-io/milvus/pkg/v2 -go 1.22 +go 1.24.1 require ( cloud.google.com/go/storage v1.43.0 @@ -29,7 +29,6 @@ require ( github.com/quasilyte/go-ruleguard/dsl v0.3.22 github.com/remeh/sizedwaitgroup v1.0.0 github.com/samber/lo v1.27.0 - github.com/sasha-s/go-deadlock v0.3.1 github.com/shirou/gopsutil/v3 v3.23.7 github.com/sirupsen/logrus v1.9.3 github.com/spaolacci/murmur3 v1.1.0 @@ -57,12 +56,12 @@ require ( go.uber.org/atomic v1.11.0 go.uber.org/automaxprocs v1.5.3 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.31.0 + golang.org/x/crypto v0.35.0 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 - golang.org/x/net v0.33.0 - golang.org/x/oauth2 v0.21.0 - golang.org/x/sync v0.10.0 - golang.org/x/sys v0.28.0 + golang.org/x/net v0.36.0 + golang.org/x/oauth2 v0.27.0 + golang.org/x/sync v0.11.0 + golang.org/x/sys v0.30.0 google.golang.org/api v0.187.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -157,7 +156,6 @@ require ( github.com/nats-io/nuid v1.0.1 // indirect github.com/opencontainers/runtime-spec v1.0.2 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect - github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pierrec/lz4 v2.5.2+incompatible // indirect github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c // indirect github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 // indirect @@ -205,8 +203,8 @@ require ( go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/mod v0.17.0 // indirect - golang.org/x/term v0.27.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/term v0.29.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect @@ -220,7 +218,7 @@ require ( replace ( github.com/apache/pulsar-client-go => github.com/milvus-io/pulsar-client-go v0.12.1 github.com/bketelsen/crypt => github.com/bketelsen/crypt v0.0.4 // Fix security alert for core-os/etcd - github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8 + github.com/expr-lang/expr => github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9 github.com/go-kit/kit => github.com/go-kit/kit v0.1.0 github.com/ianlancetaylor/cgosymbolizer => github.com/milvus-io/cgosymbolizer v0.0.0-20250318084424-114f4050c3a6 github.com/streamnative/pulsarctl => github.com/xiaofan-luan/pulsarctl v0.5.1 diff --git a/pkg/go.sum b/pkg/go.sum index 04f1e10e95..0e81c39a64 100644 --- a/pkg/go.sum +++ b/pkg/go.sum @@ -81,8 +81,8 @@ github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwS github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= -github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8 h1:boN3QhAWQU9O8EYQWxN7AEYav39PuD29QzZwTiI8Ca0= -github.com/SimFG/expr v0.0.0-20241226082220-a9a764953bf8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= +github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9 h1:p/1Prokv2YkGbcyLV/gOD28Gr3VgMXIa0c9ulg5KjOY= +github.com/SimFG/expr v0.0.0-20250415035630-0728e795e4e9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= github.com/actgardner/gogen-avro/v10 v10.1.0/go.mod h1:o+ybmVjEa27AAr35FRqU98DJu1fXES56uXniYFv4yDA= github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ= github.com/actgardner/gogen-avro/v9 v9.1.0/go.mod h1:nyTj6wPqDJoxM3qdnjcLv+EnMDSDFqE0qDpva2QRmKc= @@ -624,8 +624,6 @@ github.com/panjf2000/ants/v2 v2.7.2 h1:2NUt9BaZFO5kQzrieOmK/wdb/tQ/K+QHaxN8sOgD6 github.com/panjf2000/ants/v2 v2.7.2/go.mod h1:KIBmYG9QQX5U2qzFP/yQJaq/nSb6rahS9iEHkrCMgM8= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI= github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= @@ -713,8 +711,6 @@ github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFo github.com/samber/lo v1.27.0 h1:GOyDWxsblvqYobqsmUuMddPa2/mMzkKyojlXol4+LaQ= github.com/samber/lo v1.27.0/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= -github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= -github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -937,8 +933,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= +golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1026,8 +1022,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= +golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1040,8 +1036,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= +golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1054,8 +1050,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1131,11 +1127,11 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= -golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= +golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1145,8 +1141,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/pkg/log/zap_log_test.go b/pkg/log/zap_log_test.go index 54edbe471f..c99c050b96 100644 --- a/pkg/log/zap_log_test.go +++ b/pkg/log/zap_log_test.go @@ -327,14 +327,14 @@ func (t *testLogSpy) assertMessagesNotContains(msg string) { func (t *testLogSpy) assertLastMessageContains(msg string) { if len(t.Messages) == 0 { - assert.Error(t.TB, fmt.Errorf("empty message")) + assert.Error(t.TB, errors.New("empty message")) } assert.Contains(t.TB, t.Messages[len(t.Messages)-1], msg) } func (t *testLogSpy) assertLastMessageNotContains(msg string) { if len(t.Messages) == 0 { - assert.Error(t.TB, fmt.Errorf("empty message")) + assert.Error(t.TB, errors.New("empty message")) } assert.NotContains(t.TB, t.Messages[len(t.Messages)-1], msg) } diff --git a/pkg/mq/common/message.go b/pkg/mq/common/message.go index 3625516d09..affac6ad0f 100644 --- a/pkg/mq/common/message.go +++ b/pkg/mq/common/message.go @@ -19,6 +19,7 @@ package common import ( "fmt" + "github.com/cockroachdb/errors" "google.golang.org/protobuf/proto" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -99,14 +100,14 @@ func GetMsgTypeFromRaw(payload []byte, properties map[string]string) (commonpb.M if msgType == commonpb.MsgType_Undefined { header := commonpb.MsgHeader{} if payload == nil { - return msgType, fmt.Errorf("failed to unmarshal message header, payload is empty") + return msgType, errors.New("failed to unmarshal message header, payload is empty") } err := proto.Unmarshal(payload, &header) if err != nil { return msgType, fmt.Errorf("failed to unmarshal message header, err %s", err.Error()) } if header.Base == nil { - return msgType, fmt.Errorf("failed to unmarshal message, header is uncomplete") + return msgType, errors.New("failed to unmarshal message, header is uncomplete") } msgType = header.Base.MsgType } diff --git a/pkg/mq/mqimpl/rocksmq/client/client_impl_test.go b/pkg/mq/mqimpl/rocksmq/client/client_impl_test.go index 246e9d28a5..5177d1eb29 100644 --- a/pkg/mq/mqimpl/rocksmq/client/client_impl_test.go +++ b/pkg/mq/mqimpl/rocksmq/client/client_impl_test.go @@ -12,11 +12,11 @@ package client import ( - "fmt" "os" "testing" "time" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "google.golang.org/protobuf/proto" @@ -156,7 +156,7 @@ func TestClient_SubscribeError(t *testing.T) { mockMQ.EXPECT().ExistConsumerGroup(testTopic, testGroupName).Return(false, nil, nil) mockMQ.EXPECT().CreateConsumerGroup(testTopic, testGroupName).Return(nil) mockMQ.EXPECT().RegisterConsumer(mock.Anything).Return(nil) - mockMQ.EXPECT().SeekToLatest(testTopic, testGroupName).Return(fmt.Errorf("test error")) + mockMQ.EXPECT().SeekToLatest(testTopic, testGroupName).Return(errors.New("test error")) consumer, err := client.Subscribe(ConsumerOptions{ Topic: testTopic, diff --git a/pkg/mq/mqimpl/rocksmq/client/util.go b/pkg/mq/mqimpl/rocksmq/client/util.go index 7aaa27f9e5..c48f1a0aed 100644 --- a/pkg/mq/mqimpl/rocksmq/client/util.go +++ b/pkg/mq/mqimpl/rocksmq/client/util.go @@ -12,8 +12,7 @@ package client import ( - "fmt" - + "github.com/cockroachdb/errors" "google.golang.org/protobuf/proto" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -30,14 +29,14 @@ func MarshalHeader(header *commonpb.MsgHeader) ([]byte, error) { func UnmarshalHeader(headerbyte []byte) (*commonpb.MsgHeader, error) { header := commonpb.MsgHeader{} if headerbyte == nil { - return &header, fmt.Errorf("failed to unmarshal message header, payload is empty") + return &header, errors.New("failed to unmarshal message header, payload is empty") } err := proto.Unmarshal(headerbyte, &header) if err != nil { return &header, err } if header.Base == nil { - return nil, fmt.Errorf("failed to unmarshal message, header is uncomplete") + return nil, errors.New("failed to unmarshal message, header is uncomplete") } return &header, nil } diff --git a/pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go b/pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go index 957f0b11e5..39cc03e383 100644 --- a/pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go +++ b/pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go @@ -709,7 +709,7 @@ func (rmq *rocksmq) destroyConsumerGroupInternal(topicName, groupName string) er // Produce produces messages for topic and updates page infos for retention func (rmq *rocksmq) Produce(topicName string, messages []ProducerMessage) ([]UniqueID, error) { if messages == nil { - return []UniqueID{}, fmt.Errorf("messages are empty") + return []UniqueID{}, errors.New("messages are empty") } if rmq.isClosed() { return nil, errors.New(RmqNotServingErrMsg) diff --git a/pkg/mq/msgstream/mq_msgstream.go b/pkg/mq/msgstream/mq_msgstream.go index 379e54692f..45c8ab4b11 100644 --- a/pkg/mq/msgstream/mq_msgstream.go +++ b/pkg/mq/msgstream/mq_msgstream.go @@ -919,7 +919,7 @@ func (ms *MqTtMsgStream) Seek(ctx context.Context, msgPositions []*MsgPosition, } if consumer == nil { - return false, fmt.Errorf("consumer is nil") + return false, errors.New("consumer is nil") } seekMsgID, err := ms.client.BytesToMsgID(mp.MsgID) @@ -960,7 +960,7 @@ func (ms *MqTtMsgStream) Seek(ctx context.Context, msgPositions []*MsgPosition, for idx := range msgPositions { mp = msgPositions[idx] if len(mp.MsgID) == 0 { - return fmt.Errorf("when msgID's length equal to 0, please use AsConsumer interface") + return errors.New("when msgID's length equal to 0, please use AsConsumer interface") } err = retry.Handle(ctx, fn, retry.Attempts(20), retry.Sleep(time.Millisecond*200), retry.MaxSleepTime(5*time.Second)) // err = retry.Do(ctx, fn, retry.Attempts(20), retry.Sleep(time.Millisecond*200), retry.MaxSleepTime(5*time.Second)) @@ -984,7 +984,7 @@ func (ms *MqTtMsgStream) Seek(ctx context.Context, msgPositions []*MsgPosition, log.Info("seek loop tick", zap.Int("loopMsgCnt", loopMsgCnt), zap.String("channel", mp.ChannelName)) case msg, ok := <-consumer.Chan(): if !ok { - return fmt.Errorf("consumer closed") + return errors.New("consumer closed") } loopMsgCnt++ consumer.Ack(msg) diff --git a/pkg/mq/msgstream/mqwrapper/kafka/kafka_producer.go b/pkg/mq/msgstream/mqwrapper/kafka/kafka_producer.go index 158f6ce5d0..22797e0855 100644 --- a/pkg/mq/msgstream/mqwrapper/kafka/kafka_producer.go +++ b/pkg/mq/msgstream/mqwrapper/kafka/kafka_producer.go @@ -2,10 +2,10 @@ package kafka import ( "context" - "fmt" "sync" "time" + "github.com/cockroachdb/errors" "github.com/confluentinc/confluent-kafka-go/kafka" "go.uber.org/zap" @@ -36,7 +36,7 @@ func (kp *kafkaProducer) Send(ctx context.Context, message *mqcommon.ProducerMes if kp.isClosed { metrics.MsgStreamOpCounter.WithLabelValues(metrics.SendMsgLabel, metrics.FailLabel).Inc() log.Error("kafka produce message fail because the producer has been closed", zap.String("topic", kp.topic)) - return nil, common.NewIgnorableError(fmt.Errorf("kafka producer is closed")) + return nil, common.NewIgnorableError(errors.New("kafka producer is closed")) } headers := make([]kafka.Header, 0, len(message.Properties)) @@ -61,7 +61,7 @@ func (kp *kafkaProducer) Send(ctx context.Context, message *mqcommon.ProducerMes case <-kp.stopCh: metrics.MsgStreamOpCounter.WithLabelValues(metrics.SendMsgLabel, metrics.FailLabel).Inc() log.Error("kafka produce message fail because of kafka producer is closed", zap.String("topic", kp.topic)) - return nil, common.NewIgnorableError(fmt.Errorf("kafka producer is closed")) + return nil, common.NewIgnorableError(errors.New("kafka producer is closed")) case e := <-resultCh: m = e.(*kafka.Message) } diff --git a/pkg/mq/msgstream/mqwrapper/nmq/nmq_client.go b/pkg/mq/msgstream/mqwrapper/nmq/nmq_client.go index 384be0ea92..4f81f3566a 100644 --- a/pkg/mq/msgstream/mqwrapper/nmq/nmq_client.go +++ b/pkg/mq/msgstream/mqwrapper/nmq/nmq_client.go @@ -118,12 +118,12 @@ func (nc *nmqClient) Subscribe(ctx context.Context, options mqwrapper.ConsumerOp if options.Topic == "" { metrics.MsgStreamOpCounter.WithLabelValues(metrics.CreateConsumerLabel, metrics.FailLabel).Inc() - return nil, fmt.Errorf("invalid consumer config: empty topic") + return nil, errors.New("invalid consumer config: empty topic") } if options.SubscriptionName == "" { metrics.MsgStreamOpCounter.WithLabelValues(metrics.CreateConsumerLabel, metrics.FailLabel).Inc() - return nil, fmt.Errorf("invalid consumer config: empty subscription name") + return nil, errors.New("invalid consumer config: empty subscription name") } // TODO: inject jetstream options. js, err := nc.conn.JetStream() diff --git a/pkg/mq/msgstream/msgstream.go b/pkg/mq/msgstream/msgstream.go index aaa2ee69de..127f4fe3c9 100644 --- a/pkg/mq/msgstream/msgstream.go +++ b/pkg/mq/msgstream/msgstream.go @@ -18,11 +18,11 @@ package msgstream import ( "context" - "fmt" "path/filepath" "strconv" "sync" + "github.com/cockroachdb/errors" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -225,39 +225,39 @@ func NewMarshaledMsg(msg common.Message, group string) (ConsumeMsg, error) { properties := msg.Properties() vchannel, ok := properties[common.ChannelTypeKey] if !ok { - return nil, fmt.Errorf("get channel name from msg properties failed") + return nil, errors.New("get channel name from msg properties failed") } collID, ok := properties[common.CollectionIDTypeKey] if !ok { - return nil, fmt.Errorf("get collection ID from msg properties failed") + return nil, errors.New("get collection ID from msg properties failed") } tsStr, ok := properties[common.TimestampTypeKey] if !ok { - return nil, fmt.Errorf("get minTs from msg properties failed") + return nil, errors.New("get minTs from msg properties failed") } timestamp, err := strconv.ParseUint(tsStr, 10, 64) if err != nil { log.Warn("parse message properties minTs failed, unknown message", zap.Error(err)) - return nil, fmt.Errorf("parse minTs from msg properties failed") + return nil, errors.New("parse minTs from msg properties failed") } idStr, ok := properties[common.MsgIdTypeKey] if !ok { - return nil, fmt.Errorf("get msgType from msg properties failed") + return nil, errors.New("get msgType from msg properties failed") } id, err := strconv.ParseInt(idStr, 10, 64) if err != nil { log.Warn("parse message properties minTs failed, unknown message", zap.Error(err)) - return nil, fmt.Errorf("parse minTs from msg properties failed") + return nil, errors.New("parse minTs from msg properties failed") } val, ok := properties[common.MsgTypeKey] if !ok { - return nil, fmt.Errorf("get msgType from msg properties failed") + return nil, errors.New("get msgType from msg properties failed") } msgType := commonpb.MsgType(commonpb.MsgType_value[val]) diff --git a/pkg/util/contextutil/context_util.go b/pkg/util/contextutil/context_util.go index 210ac87cec..3cebc6f8f5 100644 --- a/pkg/util/contextutil/context_util.go +++ b/pkg/util/contextutil/context_util.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/cockroachdb/errors" "google.golang.org/grpc/metadata" "github.com/milvus-io/milvus/pkg/v2/util" @@ -72,7 +73,7 @@ func GetCurUserFromContext(ctx context.Context) (string, error) { func GetAuthInfoFromContext(ctx context.Context) (string, string, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { - return "", "", fmt.Errorf("fail to get md from the context") + return "", "", errors.New("fail to get md from the context") } authorization, ok := md[strings.ToLower(util.HeaderAuthorize)] if !ok || len(authorization) < 1 { diff --git a/pkg/util/expr/expr.go b/pkg/util/expr/expr.go index ff7231427c..3cb9b50645 100644 --- a/pkg/util/expr/expr.go +++ b/pkg/util/expr/expr.go @@ -23,6 +23,7 @@ import ( "fmt" "unsafe" + "github.com/cockroachdb/errors" "github.com/expr-lang/expr" "github.com/expr-lang/expr/vm" "go.uber.org/zap" @@ -66,16 +67,16 @@ func Exec(code, auth string) (res string, err error) { } }() if v == nil { - return "", fmt.Errorf("the expr isn't inited") + return "", errors.New("the expr isn't inited") } if code == "" { - return "", fmt.Errorf("the expr code is empty") + return "", errors.New("the expr code is empty") } if auth == "" { - return "", fmt.Errorf("the expr auth is empty") + return "", errors.New("the expr auth is empty") } if authKey != auth { - return "", fmt.Errorf("the expr auth is invalid") + return "", errors.New("the expr auth is invalid") } program, err := expr.Compile(code, expr.Env(env), expr.WithContext("ctx")) if err != nil { diff --git a/pkg/util/funcutil/func.go b/pkg/util/funcutil/func.go index e524880345..0b46143e22 100644 --- a/pkg/util/funcutil/func.go +++ b/pkg/util/funcutil/func.go @@ -282,7 +282,7 @@ func GetVirtualChannel(pchannel string, collectionID int64, idx int) string { // ConvertChannelName assembles channel name according to parameters. func ConvertChannelName(chanName string, tokenFrom string, tokenTo string) (string, error) { if tokenFrom == "" { - return "", fmt.Errorf("the tokenFrom is empty") + return "", errors.New("the tokenFrom is empty") } if !strings.Contains(chanName, tokenFrom) { return "", fmt.Errorf("cannot find token '%s' in '%s'", tokenFrom, chanName) diff --git a/pkg/util/funcutil/policy.go b/pkg/util/funcutil/policy.go index 413c0a9247..6eaab94447 100644 --- a/pkg/util/funcutil/policy.go +++ b/pkg/util/funcutil/policy.go @@ -21,7 +21,7 @@ func GetVersion(m interface{}) (string, error) { log := log.Ctx(context.TODO()) pbMsg, ok := m.(proto.Message) if !ok { - err := fmt.Errorf("MessageDescriptorProto result is nil") + err := errors.New("MessageDescriptorProto result is nil") log.RatedInfo(60, "GetVersion failed", zap.Error(err)) return "", err } @@ -39,7 +39,7 @@ func GetVersion(m interface{}) (string, error) { func GetPrivilegeExtObj(m interface{}) (commonpb.PrivilegeExt, error) { pbMsg, ok := m.(proto.Message) if !ok { - err := fmt.Errorf("MessageDescriptorProto result is nil") + err := errors.New("MessageDescriptorProto result is nil") log.RatedInfo(60, "GetPrivilegeExtObj failed", zap.Error(err)) return commonpb.PrivilegeExt{}, err } @@ -69,7 +69,7 @@ func GetObjectName(m interface{}, index int32) string { pbMsg, ok := m.(proto.Message) if !ok { - err := fmt.Errorf("MessageDescriptorProto result is nil") + err := errors.New("MessageDescriptorProto result is nil") log.RatedInfo(60, "GetObjectName fail", zap.Error(err)) return util.AnyWord } @@ -95,7 +95,7 @@ func GetObjectNames(m interface{}, index int32) []string { pbMsg, ok := m.(proto.Message) if !ok { - err := fmt.Errorf("MessageDescriptorProto result is nil") + err := errors.New("MessageDescriptorProto result is nil") log.RatedInfo(60, "GetObjectNames fail", zap.Error(err)) return []string{} } diff --git a/pkg/util/indexparams/index_params.go b/pkg/util/indexparams/index_params.go index 42dba38137..d4fa596cdb 100644 --- a/pkg/util/indexparams/index_params.go +++ b/pkg/util/indexparams/index_params.go @@ -22,6 +22,8 @@ import ( "strconv" "unsafe" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/pkg/v2/common" "github.com/milvus-io/milvus/pkg/v2/util/funcutil" @@ -177,11 +179,11 @@ func FillDiskIndexParams(params *paramtable.ComponentParam, indexParams map[stri var ok bool maxDegree, ok = indexParams[MaxDegreeKey] if !ok { - return fmt.Errorf("index param max_degree not exist") + return errors.New("index param max_degree not exist") } searchListSize, ok = indexParams[SearchListSizeKey] if !ok { - return fmt.Errorf("index param search_list_size not exist") + return errors.New("index param search_list_size not exist") } extraParams, err := NewBigDataExtraParamsFromJSON(params.AutoIndexConfig.ExtraParams.GetValue()) if err != nil { @@ -224,13 +226,13 @@ func UpdateDiskIndexBuildParams(params *paramtable.ComponentParam, indexParams [ if params.AutoIndexConfig.Enable.GetAsBool() { extraParams, err := NewBigDataExtraParamsFromJSON(params.AutoIndexConfig.ExtraParams.GetValue()) if err != nil { - return indexParams, fmt.Errorf("index param search_cache_budget_gb_ratio not exist in AutoIndex Config") + return indexParams, errors.New("index param search_cache_budget_gb_ratio not exist in AutoIndex Config") } searchCacheBudgetGBRatio = fmt.Sprintf("%f", extraParams.SearchCacheBudgetGBRatio) } else { paramVal, err := strconv.ParseFloat(params.CommonCfg.SearchCacheBudgetGBRatio.GetValue(), 64) if err != nil { - return indexParams, fmt.Errorf("index param search_cache_budget_gb_ratio not exist in Config") + return indexParams, errors.New("index param search_cache_budget_gb_ratio not exist in Config") } searchCacheBudgetGBRatio = fmt.Sprintf("%f", paramVal) } @@ -269,7 +271,7 @@ func UpdateDiskIndexBuildParams(params *paramtable.ComponentParam, indexParams [ func SetDiskIndexBuildParams(indexParams map[string]string, fieldDataSize int64) error { pqCodeBudgetGBRatioStr, ok := indexParams[PQCodeBudgetRatioKey] if !ok { - return fmt.Errorf("index param pqCodeBudgetGBRatio not exist") + return errors.New("index param pqCodeBudgetGBRatio not exist") } pqCodeBudgetGBRatio, err := strconv.ParseFloat(pqCodeBudgetGBRatioStr, 64) if err != nil { @@ -277,7 +279,7 @@ func SetDiskIndexBuildParams(indexParams map[string]string, fieldDataSize int64) } buildNumThreadsRatioStr, ok := indexParams[NumBuildThreadRatioKey] if !ok { - return fmt.Errorf("index param buildNumThreadsRatio not exist") + return errors.New("index param buildNumThreadsRatio not exist") } buildNumThreadsRatio, err := strconv.ParseFloat(buildNumThreadsRatioStr, 64) if err != nil { @@ -313,7 +315,7 @@ func SetDiskIndexLoadParams(params *paramtable.ComponentParam, indexParams map[s dimStr, ok := indexParams[common.DimKey] if !ok { // type param dim has been put into index params before build index - return fmt.Errorf("type param dim not exist") + return errors.New("type param dim not exist") } dim, err := strconv.ParseInt(dimStr, 10, 64) if err != nil { diff --git a/pkg/util/retry/retry_test.go b/pkg/util/retry/retry_test.go index f703d70df8..67e0db8bec 100644 --- a/pkg/util/retry/retry_test.go +++ b/pkg/util/retry/retry_test.go @@ -67,7 +67,7 @@ func TestMaxSleepTime(t *testing.T) { ctx := context.Background() testFn := func() error { - return fmt.Errorf("some error") + return errors.New("some error") } err := Do(ctx, testFn, Attempts(3), MaxSleepTime(200*time.Millisecond)) @@ -85,7 +85,7 @@ func TestSleep(t *testing.T) { ctx := context.Background() testFn := func() error { - return fmt.Errorf("some error") + return errors.New("some error") } err := Do(ctx, testFn, Attempts(3), Sleep(500*time.Millisecond)) @@ -126,7 +126,7 @@ func TestContextDeadline(t *testing.T) { defer cancel() testFn := func() error { - return fmt.Errorf("some error") + return errors.New("some error") } err := Do(ctx, testFn) diff --git a/pkg/util/typeutil/field_schema.go b/pkg/util/typeutil/field_schema.go index b714b6dc40..a3a159edfc 100644 --- a/pkg/util/typeutil/field_schema.go +++ b/pkg/util/typeutil/field_schema.go @@ -4,6 +4,8 @@ import ( "fmt" "strconv" + "github.com/cockroachdb/errors" + "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" "github.com/milvus-io/milvus/pkg/v2/common" ) @@ -19,13 +21,13 @@ func (h *FieldSchemaHelper) GetDim() (int64, error) { return 0, fmt.Errorf("%s is not of vector type", h.schema.GetDataType()) } if IsSparseFloatVectorType(h.schema.GetDataType()) { - return 0, fmt.Errorf("typeutil.GetDim should not invoke on sparse vector type") + return 0, errors.New("typeutil.GetDim should not invoke on sparse vector type") } getDim := func(kvPairs *kvPairsHelper[string, string]) (int64, error) { dimStr, err := kvPairs.Get(common.DimKey) if err != nil { - return 0, fmt.Errorf("dim not found") + return 0, errors.New("dim not found") } dim, err := strconv.Atoi(dimStr) if err != nil { diff --git a/pkg/util/typeutil/float_util.go b/pkg/util/typeutil/float_util.go index 17e4658cf0..e00a8e13fc 100644 --- a/pkg/util/typeutil/float_util.go +++ b/pkg/util/typeutil/float_util.go @@ -20,6 +20,8 @@ import ( "encoding/binary" "fmt" "math" + + "github.com/cockroachdb/errors" ) func bfloat16IsNaN(f uint16) bool { @@ -79,13 +81,13 @@ func VerifyFloats64(values []float64) error { func VerifyFloats16(value []byte) error { if len(value)%2 != 0 { - return fmt.Errorf("The length of float16 is not aligned to 2.") + return errors.New("The length of float16 is not aligned to 2.") } dataSize := len(value) / 2 for i := 0; i < dataSize; i++ { v := binary.LittleEndian.Uint16(value[i*2:]) if float16IsNaN(v) || float16IsInf(v, -1) || float16IsInf(v, 1) { - return fmt.Errorf("float16 vector contain nan or infinity value.") + return errors.New("float16 vector contain nan or infinity value.") } } return nil @@ -93,13 +95,13 @@ func VerifyFloats16(value []byte) error { func VerifyBFloats16(value []byte) error { if len(value)%2 != 0 { - return fmt.Errorf("The length of bfloat16 in not aligned to 2") + return errors.New("The length of bfloat16 in not aligned to 2") } dataSize := len(value) / 2 for i := 0; i < dataSize; i++ { v := binary.LittleEndian.Uint16(value[i*2:]) if bfloat16IsNaN(v) || bfloat16IsInf(v, -1) || bfloat16IsInf(v, 1) { - return fmt.Errorf("bfloat16 vector contain nan or infinity value.") + return errors.New("bfloat16 vector contain nan or infinity value.") } } return nil diff --git a/pkg/util/typeutil/schema.go b/pkg/util/typeutil/schema.go index 53e5935976..3a6ecfaec3 100644 --- a/pkg/util/typeutil/schema.go +++ b/pkg/util/typeutil/schema.go @@ -227,12 +227,12 @@ func EstimateEntitySize(fieldsData []*schemapb.FieldData, rowOffset int) (int, e res += 8 case schemapb.DataType_VarChar, schemapb.DataType_Text: if rowOffset >= len(fs.GetScalars().GetStringData().GetData()) { - return 0, fmt.Errorf("offset out range of field datas") + return 0, errors.New("offset out range of field datas") } res += len(fs.GetScalars().GetStringData().Data[rowOffset]) case schemapb.DataType_Array: if rowOffset >= len(fs.GetScalars().GetArrayData().GetData()) { - return 0, fmt.Errorf("offset out range of field datas") + return 0, errors.New("offset out range of field datas") } array := fs.GetScalars().GetArrayData().GetData()[rowOffset] res += CalcColumnSize(&schemapb.FieldData{ @@ -241,7 +241,7 @@ func EstimateEntitySize(fieldsData []*schemapb.FieldData, rowOffset int) (int, e }) case schemapb.DataType_JSON: if rowOffset >= len(fs.GetScalars().GetJsonData().GetData()) { - return 0, fmt.Errorf("offset out range of field datas") + return 0, errors.New("offset out range of field datas") } res += len(fs.GetScalars().GetJsonData().GetData()[rowOffset]) case schemapb.DataType_BinaryVector: @@ -340,7 +340,7 @@ func CreateSchemaHelper(schema *schemapb.CollectionSchema) (*SchemaHelper, error // GetPrimaryKeyField returns the schema of the primary key func (helper *SchemaHelper) GetPrimaryKeyField() (*schemapb.FieldSchema, error) { if helper.primaryKeyOffset == -1 { - return nil, fmt.Errorf("failed to get primary key field: no primary in schema") + return nil, errors.New("failed to get primary key field: no primary in schema") } return helper.schema.Fields[helper.primaryKeyOffset], nil } @@ -348,7 +348,7 @@ func (helper *SchemaHelper) GetPrimaryKeyField() (*schemapb.FieldSchema, error) // GetPartitionKeyField returns the schema of the partition key func (helper *SchemaHelper) GetPartitionKeyField() (*schemapb.FieldSchema, error) { if helper.partitionKeyOffset == -1 { - return nil, fmt.Errorf("failed to get partition key field: no partition key in schema") + return nil, errors.New("failed to get partition key field: no partition key in schema") } return helper.schema.Fields[helper.partitionKeyOffset], nil } @@ -357,7 +357,7 @@ func (helper *SchemaHelper) GetPartitionKeyField() (*schemapb.FieldSchema, error // If not found, an error shall be returned. func (helper *SchemaHelper) GetClusteringKeyField() (*schemapb.FieldSchema, error) { if helper.clusteringKeyOffset == -1 { - return nil, fmt.Errorf("failed to get clustering key field: not clustering key in schema") + return nil, errors.New("failed to get clustering key field: not clustering key in schema") } return helper.schema.Fields[helper.clusteringKeyOffset], nil } @@ -366,7 +366,7 @@ func (helper *SchemaHelper) GetClusteringKeyField() (*schemapb.FieldSchema, erro // if there is no dynamic field defined in schema, error will be returned. func (helper *SchemaHelper) GetDynamicField() (*schemapb.FieldSchema, error) { if helper.dynamicFieldOffset == -1 { - return nil, fmt.Errorf("failed to get dynamic field: no dynamic field in schema") + return nil, errors.New("failed to get dynamic field: no dynamic field in schema") } return helper.schema.Fields[helper.dynamicFieldOffset], nil } @@ -421,7 +421,7 @@ func (helper *SchemaHelper) getDefaultJSONField(fieldName string) (*schemapb.Fie } errMsg := fmt.Sprintf("field %s not exist", fieldName) log.Warn(errMsg) - return nil, fmt.Errorf(errMsg) + return nil, fmt.Errorf("%s", errMsg) } // GetFieldFromID returns the schema of specified field @@ -462,7 +462,7 @@ func (helper *SchemaHelper) GetFunctionByOutputField(field *schemapb.FieldSchema } } } - return nil, fmt.Errorf("function not exist") + return nil, errors.New("function not exist") } // As of now, only BM25 function output field is not supported to retrieve raw field data @@ -1950,11 +1950,11 @@ func CreateSparseFloatRowFromMap(input map[string]interface{}) ([]byte, error) { values = append(values, val) } } else { - return nil, fmt.Errorf("invalid JSON input") + return nil, errors.New("invalid JSON input") } if len(indices) != len(values) { - return nil, fmt.Errorf("indices and values length mismatch") + return nil, errors.New("indices and values length mismatch") } sortedIndices, sortedValues := SortSparseFloatRow(indices, values) diff --git a/tests/go_client/Dockerfile b/tests/go_client/Dockerfile index 282a753cfb..3c3349e465 100644 --- a/tests/go_client/Dockerfile +++ b/tests/go_client/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 as builder +FROM golang:1.24.1 as builder # Define a build argument with an empty default value ARG CUSTOM_GOPROXY="" diff --git a/tests/go_client/go.mod b/tests/go_client/go.mod index 2c6959dd14..0cbb261726 100644 --- a/tests/go_client/go.mod +++ b/tests/go_client/go.mod @@ -1,8 +1,6 @@ module github.com/milvus-io/milvus/tests/go_client -go 1.21 - -toolchain go1.21.11 +go 1.24.1 require ( github.com/milvus-io/milvus/client/v2 v2.0.0-20241125024034-0b9edb62a92d @@ -100,12 +98,12 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/automaxprocs v1.5.3 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.31.0 // indirect + golang.org/x/crypto v0.35.0 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/net v0.36.0 // indirect + golang.org/x/sync v0.11.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect diff --git a/tests/go_client/go.sum b/tests/go_client/go.sum index f5805acbcf..73b3b34ad7 100644 --- a/tests/go_client/go.sum +++ b/tests/go_client/go.sum @@ -579,8 +579,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= +golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -634,8 +634,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= +golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -650,8 +650,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -698,8 +698,8 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -708,8 +708,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/tests/integration/import/util_test.go b/tests/integration/import/util_test.go index 8d743186a0..7d60a747d8 100644 --- a/tests/integration/import/util_test.go +++ b/tests/integration/import/util_test.go @@ -28,6 +28,7 @@ import ( "github.com/apache/arrow/go/v17/arrow/array" "github.com/apache/arrow/go/v17/parquet" "github.com/apache/arrow/go/v17/parquet/pqarrow" + "github.com/cockroachdb/errors" "github.com/samber/lo" "github.com/sbinet/npyio" "github.com/stretchr/testify/assert" @@ -50,7 +51,7 @@ func CheckLogID(fieldBinlogs []*datapb.FieldBinlog) error { for _, fieldBinlog := range fieldBinlogs { for _, l := range fieldBinlog.GetBinlogs() { if l.GetLogID() == 0 { - return fmt.Errorf("unexpected log id 0") + return errors.New("unexpected log id 0") } } } diff --git a/tests/integration/upsert/upsert_test.go b/tests/integration/upsert/upsert_test.go index ea3c01a133..ed4bca9d6c 100644 --- a/tests/integration/upsert/upsert_test.go +++ b/tests/integration/upsert/upsert_test.go @@ -21,6 +21,7 @@ import ( "fmt" "testing" + "github.com/cockroachdb/errors" "github.com/stretchr/testify/suite" "go.uber.org/zap" "google.golang.org/protobuf/proto" @@ -147,7 +148,7 @@ func (s *UpsertSuite) TestUpsertAutoIDFalse() { searchResult, _ := c.Proxy.Search(ctx, searchReq) checkFunc := func(data int) error { if data < start || data > start+rowNum { - return fmt.Errorf("upsert check pk fail") + return errors.New("upsert check pk fail") } return nil } @@ -279,7 +280,7 @@ func (s *UpsertSuite) TestUpsertAutoIDTrue() { searchResult, _ := c.Proxy.Search(ctx, searchReq) checkFunc := func(data int) error { if data >= start && data <= start+rowNum { - return fmt.Errorf("upsert check pk fail") + return errors.New("upsert check pk fail") } return nil }