From f0a5ca5d3afad84fc5a3cedaeffee9b1c60d895f Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Tue, 23 Feb 2021 09:58:22 +0100 Subject: [PATCH] Change coordinator error to primary Signed-off-by: Antonio Navarro Perez --- http/client_test.go | 2 +- http/handler.go | 8 ++++---- pilosa.go | 8 ++++---- server.go | 8 ++++---- server/grpc.go | 2 +- server/server_test.go | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/http/client_test.go b/http/client_test.go index 0077ae555..55fb5d607 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -1359,7 +1359,7 @@ func TestClientTransactions(t *testing.T) { // non-coordinator if trns, err := client1.StartTransaction(context.Background(), "blah", time.Minute, false); err == nil || - !strings.Contains(err.Error(), pilosa.ErrNodeNotCoordinator.Error()) { + !strings.Contains(err.Error(), pilosa.ErrNodeNotPrimary.Error()) { t.Fatalf("unexpected error starting on non-coordinator: %v", err) } else { test.CompareTransactions(t, diff --git a/http/handler.go b/http/handler.go index 8083e1e12..2619315e5 100644 --- a/http/handler.go +++ b/http/handler.go @@ -1510,7 +1510,7 @@ func (h *Handler) handleGetTransactionList(w http.ResponseWriter, r *http.Reques trnsMap, err := h.api.Transactions(r.Context()) if err != nil { switch errors.Cause(err) { - case pilosa.ErrNodeNotCoordinator: + case pilosa.ErrNodeNotPrimary: http.Error(w, err.Error(), http.StatusBadRequest) default: http.Error(w, "problem getting transactions: "+err.Error(), http.StatusInternalServerError) @@ -1545,7 +1545,7 @@ func (h *Handler) handleGetTransactions(w http.ResponseWriter, r *http.Request) trnsMap, err := h.api.Transactions(r.Context()) if err != nil { switch errors.Cause(err) { - case pilosa.ErrNodeNotCoordinator: + case pilosa.ErrNodeNotPrimary: http.Error(w, err.Error(), http.StatusBadRequest) default: http.Error(w, "problem getting transactions: "+err.Error(), http.StatusInternalServerError) @@ -1567,7 +1567,7 @@ type TransactionResponse struct { func (h *Handler) doTransactionResponse(w http.ResponseWriter, err error, trns *pilosa.Transaction) { if err != nil { switch errors.Cause(err) { - case pilosa.ErrNodeNotCoordinator, pilosa.ErrTransactionExists: + case pilosa.ErrNodeNotPrimary, pilosa.ErrTransactionExists: w.WriteHeader(http.StatusBadRequest) case pilosa.ErrTransactionExclusive: w.WriteHeader(http.StatusConflict) @@ -2117,7 +2117,7 @@ func (h *Handler) handlePostClusterResizeAbort(w http.ResponseWriter, r *http.Re var msg string if err != nil { switch errors.Cause(err) { - case pilosa.ErrNodeNotCoordinator: + case pilosa.ErrNodeNotPrimary: http.Error(w, err.Error(), http.StatusBadRequest) return case pilosa.ErrResizeNotRunning: diff --git a/pilosa.go b/pilosa.go index 8538a25bb..f318a6eb4 100644 --- a/pilosa.go +++ b/pilosa.go @@ -75,10 +75,10 @@ var ( // ErrPreconditionFailed is returned when specified index/field createdAt timestamps don't match ErrPreconditionFailed = errors.New("precondition failed") - ErrNodeIDNotExists = errors.New("node with provided ID does not exist") - ErrNodeNotCoordinator = errors.New("node is not the coordinator") - ErrResizeNotRunning = errors.New("no resize job currently running") - ErrResizeNoReplicas = errors.New("not enough data to perform resize (replica factor may need to be increased)") + ErrNodeIDNotExists = errors.New("node with provided ID does not exist") + ErrNodeNotPrimary = errors.New("node is not the primary") + ErrResizeNotRunning = errors.New("no resize job currently running") + ErrResizeNoReplicas = errors.New("not enough data to perform resize (replica factor may need to be increased)") ErrNotImplemented = errors.New("not implemented") ErrFieldsArgumentRequired = errors.New("fields argument required") diff --git a/server.go b/server.go index ee783d2ec..2c95f31b3 100644 --- a/server.go +++ b/server.go @@ -1110,7 +1110,7 @@ func (srv *Server) StartTransaction(ctx context.Context, id string, timeout time snap := topology.NewClusterSnapshot(srv.cluster.noder, srv.cluster.Hasher, srv.cluster.partitionN) node := srv.node() if !remote && !snap.IsPrimaryFieldTranslationNode(node.ID) && len(srv.cluster.Nodes()) > 1 { - return nil, ErrNodeNotCoordinator + return nil, ErrNodeNotPrimary } if remote && (snap.IsPrimaryFieldTranslationNode(node.ID) || len(srv.cluster.Nodes()) == 1) { return nil, errors.New("unexpected remote start call to coordinator or single node cluster") @@ -1157,7 +1157,7 @@ func (srv *Server) FinishTransaction(ctx context.Context, id string, remote bool snap := topology.NewClusterSnapshot(srv.cluster.noder, srv.cluster.Hasher, srv.cluster.partitionN) node := srv.node() if !remote && !snap.IsPrimaryFieldTranslationNode(node.ID) && len(srv.cluster.Nodes()) > 1 { - return nil, ErrNodeNotCoordinator + return nil, ErrNodeNotPrimary } if remote && (snap.IsPrimaryFieldTranslationNode(node.ID) || len(srv.cluster.Nodes()) == 1) { return nil, errors.New("unexpected remote finish call to coordinator or single node cluster") @@ -1187,7 +1187,7 @@ func (srv *Server) Transactions(ctx context.Context) (map[string]*Transaction, e snap := topology.NewClusterSnapshot(srv.cluster.noder, srv.cluster.Hasher, srv.cluster.partitionN) node := srv.node() if !snap.IsPrimaryFieldTranslationNode(node.ID) && len(srv.cluster.Nodes()) > 1 { - return nil, ErrNodeNotCoordinator + return nil, ErrNodeNotPrimary } return srv.holder.Transactions(ctx) @@ -1198,7 +1198,7 @@ func (srv *Server) GetTransaction(ctx context.Context, id string, remote bool) ( node := srv.node() if !remote && !snap.IsPrimaryFieldTranslationNode(node.ID) && len(srv.cluster.Nodes()) > 1 { - return nil, ErrNodeNotCoordinator + return nil, ErrNodeNotPrimary } if remote && (snap.IsPrimaryFieldTranslationNode(node.ID) || len(srv.cluster.Nodes()) == 1) { diff --git a/server/grpc.go b/server/grpc.go index cdfe8108d..e95952688 100644 --- a/server/grpc.go +++ b/server/grpc.go @@ -121,7 +121,7 @@ func errToStatusError(err error) error { case pilosa.ErrClusterDoesNotOwnShard, pilosa.ErrResizeNoReplicas, pilosa.ErrResizeNotRunning, - pilosa.ErrNodeNotCoordinator, + pilosa.ErrNodeNotPrimary, pilosa.ErrTooManyWrites, pilosa.ErrNodeIDNotExists: return status.Error(codes.Internal, err.Error()) diff --git a/server/server_test.go b/server/server_test.go index 126e08ba4..c370d28a0 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -412,8 +412,8 @@ func TestTransactionsAPI(t *testing.T) { } // can't fetch transactions from non-coordinator - if _, err := other.Transactions(ctx); err != pilosa.ErrNodeNotCoordinator { - t.Errorf("api1 should return ErrNodeNotCoordinator when asked for transactions but got: %v", err) + if _, err := other.Transactions(ctx); err != pilosa.ErrNodeNotPrimary { + t.Errorf("api1 should return ErrNodeNotPrimary when asked for transactions but got: %v", err) } // can start transaction @@ -443,8 +443,8 @@ func TestTransactionsAPI(t *testing.T) { } // can't finish transaction on non-coordinator - if _, err := other.FinishTransaction(ctx, id, false); err != pilosa.ErrNodeNotCoordinator { - t.Errorf("unexpected error is not ErrNodeNotCoordinator: %v", err) + if _, err := other.FinishTransaction(ctx, id, false); err != pilosa.ErrNodeNotPrimary { + t.Errorf("unexpected error is not ErrNodeNotPrimary: %v", err) } // can finish transaction