Skip to content

Commit

Permalink
Merge pull request #246 from tigrisdata/main
Browse files Browse the repository at this point in the history
Alpha release
  • Loading branch information
efirs authored May 5, 2022
2 parents 589748a + 105827c commit ebf8207
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/push-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Fetch tags
run: |
git fetch --prune --unshallow --tags
- name: Login to Docker Hub
id: login-docker-hub
uses: docker/login-action@v1
Expand Down
6 changes: 5 additions & 1 deletion server/services/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,11 @@ func (s *apiService) GetInfo(_ context.Context, _ *api.GetInfoRequest) (*api.Get

func (s *apiService) Run(ctx context.Context, req *ReqOptions) (*Response, error) {
queryLifecycle := s.queryLifecycleFactory.Get()
return queryLifecycle.run(ctx, req)
resp, err := queryLifecycle.run(ctx, req)
if err == kv.ErrConflictingTransaction {
return nil, api.Errorf(codes.Aborted, err.Error())
}
return resp, err
}

func (s *apiService) Stream(r *api.StreamRequest, stream api.Tigris_StreamServer) error {
Expand Down
4 changes: 1 addition & 3 deletions server/services/v1/query_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (q *queryLifecycle) createOrGetTenant() (*metadata.Tenant, error) {
return tenant, nil
}

func (q *queryLifecycle) run(ctx context.Context, options *ReqOptions) (*Response, error) {
func (q *queryLifecycle) run(ctx context.Context, options *ReqOptions) (resp *Response, txErr error) {
if options == nil {
return nil, api.Errorf(codes.Internal, "empty options")
}
Expand All @@ -111,8 +111,6 @@ func (q *queryLifecycle) run(ctx context.Context, options *ReqOptions) (*Respons
return nil, err
}

var resp *Response
var txErr error
defer func() {
var err error
if txErr == nil {
Expand Down
7 changes: 5 additions & 2 deletions store/kv/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import "fmt"
type StoreErrCode byte

const (
ErrCodeInvalid StoreErrCode = 0x00
ErrCodeDuplicateKey StoreErrCode = 0x01
ErrCodeInvalid StoreErrCode = 0x00
ErrCodeDuplicateKey StoreErrCode = 0x01
ErrCodeConflictingTransaction StoreErrCode = 0x02
)

var (
// ErrDuplicateKey is returned when an insert call is made for a key that already exist.
ErrDuplicateKey = NewStoreError(ErrCodeDuplicateKey, "duplicate key value, violates key constraint")
// ErrConflictingTransaction is returned when there are conflicting transactions.
ErrConflictingTransaction = NewStoreError(ErrCodeConflictingTransaction, "transaction not committed due to conflict with another transaction")
)

type StoreError struct {
Expand Down
7 changes: 5 additions & 2 deletions store/kv/fdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ func (t *ftx) Commit(ctx context.Context) error {
}

err = t.tx.Commit().Get()

if err == nil {
break
}
Expand All @@ -483,7 +482,11 @@ func (t *ftx) Commit(ctx context.Context) error {

var ep fdb.Error
if xerrors.As(err, &ep) {
err = t.tx.OnError(ep).Get()
if ep.Code == 1020 {
err = ErrConflictingTransaction
} else if err1 := t.tx.OnError(ep).Get(); err1 != nil {
err = err1
}
}

if err != nil {
Expand Down

0 comments on commit ebf8207

Please sign in to comment.