Merge pull request #1888 from molecula/fb1146

fb1146 - fixes panic on POST /transaction on non-primary node
This commit is contained in:
reese 2022-01-24 17:11:49 -06:00 committed by GitHub
commit de11a1d903
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 31 deletions

26
api.go
View file

@ -2514,24 +2514,24 @@ func (api *API) StartTransaction(ctx context.Context, id string, timeout time.Du
return nil, errors.Wrap(err, "validating api method")
}
t, err := api.server.StartTransaction(ctx, id, timeout, exclusive, remote)
if exclusive {
switch err {
case nil:
switch err {
case nil:
if exclusive {
api.holder.Stats.Count(MetricExclusiveTransactionRequest, 1, 1.0)
case ErrTransactionExclusive:
api.holder.Stats.Count(MetricExclusiveTransactionBlocked, 1, 1.0)
}
if t.Active {
api.holder.Stats.Count(MetricExclusiveTransactionActive, 1, 1.0)
}
} else {
switch err {
case nil:
} else {
api.holder.Stats.Count(MetricTransactionStart, 1, 1.0)
case ErrTransactionExclusive:
}
case ErrTransactionExclusive:
if exclusive {
api.holder.Stats.Count(MetricExclusiveTransactionBlocked, 1, 1.0)
} else {
api.holder.Stats.Count(MetricTransactionBlocked, 1, 1.0)
}
}
if exclusive && t != nil && t.Active {
api.holder.Stats.Count(MetricExclusiveTransactionActive, 1, 1.0)
}
return t, err
}

View file

@ -14,7 +14,7 @@ import (
"time"
"github.com/davecgh/go-spew/spew"
"github.com/molecula/featurebase/v3"
pilosa "github.com/molecula/featurebase/v3"
"github.com/molecula/featurebase/v3/http"
"github.com/molecula/featurebase/v3/pql"
"github.com/molecula/featurebase/v3/server"
@ -1419,12 +1419,11 @@ func TestClientTransactions(t *testing.T) {
}
// non-primary
if trns, err := client1.StartTransaction(context.Background(), "blah", time.Minute, false); err == nil ||
!strings.Contains(err.Error(), pilosa.ErrNodeNotPrimary.Error()) {
if trns, err := client1.StartTransaction(context.Background(), "blah", time.Minute, false); err != nil {
t.Fatalf("unexpected error starting on non-primary: %v", err)
} else {
test.CompareTransactions(t,
nil,
&pilosa.Transaction{ID: "blah", Timeout: time.Minute, Active: true, Exclusive: false, Deadline: expDeadline},
trns)
}

View file

@ -2158,9 +2158,15 @@ func (h *Handler) handlePostTransaction(w http.ResponseWriter, r *http.Request)
if !ok {
id = reqTrns.ID
}
trns, err := h.api.StartTransaction(r.Context(), id, reqTrns.Timeout, reqTrns.Exclusive, false)
h.doTransactionResponse(w, err, trns)
if primary := h.api.PrimaryNode(); h.api.NodeID() == primary.ID {
trns, err := h.api.StartTransaction(r.Context(), id, reqTrns.Timeout, reqTrns.Exclusive, false)
h.doTransactionResponse(w, err, trns)
return
} else {
http.Redirect(w, r, primary.URI.Normalize()+"/transaction/"+id, http.StatusSeeOther)
return
}
}
func (h *Handler) handlePostFinishTransaction(w http.ResponseWriter, r *http.Request) {

View file

@ -5,8 +5,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33455:10101"
environment:
- PILOSA_CLUSTER_COORDINATOR=true
- PILOSA_GOSSIP_SEEDS=pilosa1:14000
@ -20,8 +18,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33456:10101"
environment:
- PILOSA_GOSSIP_SEEDS=pilosa1:14000
- PILOSA_CLUSTER_REPLICAS=2
@ -34,8 +30,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33457:10101"
environment:
- PILOSA_GOSSIP_SEEDS=pilosa1:14000,pilosa2:14000
- PILOSA_CLUSTER_REPLICAS=2

View file

@ -5,8 +5,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33455:10101"
environment:
- PILOSA_NAME=pilosa1
- PILOSA_ETCD_DIR=/root/.etcd
@ -25,8 +23,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33456:10101"
environment:
- PILOSA_NAME=pilosa2
- PILOSA_ETCD_DIR=/root/.etcd
@ -45,8 +41,6 @@ services:
context: ../..
dockerfile: Dockerfile-clustertests
image: ptest
ports:
- "33457:10101"
environment:
- PILOSA_NAME=pilosa3
- PILOSA_ETCD_DIR=/root/.etcd
@ -76,5 +70,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
command:
- "cd /go/src/github.com/molecula/featurebase/ && go test -mod=vendor -v -count=1 github.com/molecula/featurebase/v3/internal/clustertests"
networks:
pilosanet: