Merge pull request #1452 from ajnavarro/disco/coordinator-err-to-primary

Change coordinator error to primary
This commit is contained in:
Antonio Navarro Perez 2021-02-23 16:44:50 +01:00 committed by GitHub
commit 5794a4af69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 18 deletions

View file

@ -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,

View file

@ -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:

View file

@ -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")

View file

@ -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) {

View file

@ -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())

View file

@ -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