Skip to content

Commit

Permalink
Merge pull request #282 from tigrisdata/main
Browse files Browse the repository at this point in the history
Alpha release
  • Loading branch information
efirs authored Jun 8, 2022
2 parents 1496a4b + 4b7d1bb commit 0cafb54
Show file tree
Hide file tree
Showing 38 changed files with 1,021 additions and 526 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
api/client/*

.idea
.vscode
server/service
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ DATA_PROTO_DIR=internal

# Needed to be able to build amd64 binaries on MacOS M1
DOCKER_PLATFORM="linux/amd64"
DOCKER_COMPOSE=COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 DOCKER_DEFAULT_PLATFORM=$(DOCKER_PLATFORM) docker-compose -f test/docker/docker-compose.yml
DOCKER_DIR=test/docker
DOCKER_COMPOSE=COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 DOCKER_DEFAULT_PLATFORM=$(DOCKER_PLATFORM) docker-compose -f ${DOCKER_DIR}/docker-compose.yml
GOARCH="amd64"
CGO_ENABLED=1

Expand Down Expand Up @@ -42,6 +43,7 @@ server/service: $(GO_SRC) generate
lint: generate
yq --exit-status 'tag == "!!map" or tag== "!!seq"' .github/workflows/*.yaml config/*.yaml
shellcheck scripts/*
shellcheck test/docker/grafana/*
golangci-lint run

docker_compose_build:
Expand All @@ -64,6 +66,13 @@ local_test: generate
run: clean generate
$(DOCKER_COMPOSE) up --build --detach tigris_server

# Runs tigris server and foundationdb, plus additional tools for it like:
# - prometheus and grafana for monitoring
run_full: clean generate
${DOCKER_COMPOSE} up --build --detach tigris_grafana
./${DOCKER_DIR}/grafana/set_admin_password.sh
./${DOCKER_DIR}/grafana/add_prometheus_datasource.sh

bins: $(BINS)

clean:
Expand Down
43 changes: 43 additions & 0 deletions api/server/v1/header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package api

import (
"context"
"strings"

"github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)

const (
// HeaderRequestTimeout is an end-to-end request header that indicates the maximum time that a client is
// prepared to await a response. The value of the header is in seconds. A client is allowed to send fractional
// values. For ex, 0.1 means 100milliseconds.
HeaderRequestTimeout = "Request-Timeout"

HeaderPrefix = "Tigris-"

HeaderTxID = "Tigris-Tx-Id"
HeaderTxOrigin = "Tigris-Tx-Origin"

grpcGatewayPrefix = "grpc-gateway-"
)

func CustomMatcher(key string) (string, bool) {
switch key {
case HeaderRequestTimeout:
return key, true
default:
if strings.HasPrefix(key, HeaderPrefix) {
return key, true
}
return runtime.DefaultHeaderMatcher(key)
}
}

func GetHeader(ctx context.Context, header string) string {
if val := metautils.ExtractIncoming(ctx).Get(header); val != "" {
return val
}

return metautils.ExtractIncoming(ctx).Get(grpcGatewayPrefix + header)
}
36 changes: 31 additions & 5 deletions api/server/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,39 @@

package api

func IsTxSupported(req Request) bool {
switch req.(type) {
case *InsertRequest, *ReplaceRequest, *UpdateRequest, *DeleteRequest, *ReadRequest,
*CreateOrUpdateCollectionRequest, *DropCollectionRequest, *ListCollectionsRequest:
import (
"context"

"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)

func IsTxSupported(ctx context.Context) bool {
m, _ := grpc.Method(ctx)
switch m {
case "Insert", "Replace", "Update", "Delete", "Read",
"CreateOrUpdateCollection", "DropCollection", "ListCollections",
"CommitTransaction", "RollbackTransaction":
return true
default:
return false
}
}

func GetTransaction(req Request) *TransactionCtx {
func GetTransaction(ctx context.Context, req proto.Message) *TransactionCtx {
tx := &TransactionCtx{
Id: GetHeader(ctx, HeaderTxID),
Origin: GetHeader(ctx, HeaderTxOrigin),
}

if tx.Id != "" {
return tx
}

return GetTransactionLegacy(req)
}

func GetTransactionLegacy(req proto.Message) *TransactionCtx {
switch r := req.(type) {
case *InsertRequest:
r.GetOptions().ProtoReflect()
Expand Down Expand Up @@ -67,6 +89,10 @@ func GetTransaction(req Request) *TransactionCtx {
return nil
}
return r.GetOptions().GetTxCtx()
case *CommitTransactionRequest:
return r.GetTxCtx()
case *RollbackTransactionRequest:
return r.GetTxCtx()
}
return nil
}
47 changes: 0 additions & 47 deletions api/server/v1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ func (x *CreateOrUpdateCollectionRequest) Validate() error {
return Errorf(Code_INVALID_ARGUMENT, "schema is a required during collection creation")
}

if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

Expand All @@ -121,42 +115,18 @@ func (x *DropCollectionRequest) Validate() error {
return err
}

if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

func (x *ListCollectionsRequest) Validate() error {
if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

func (x *DescribeCollectionRequest) Validate() error {
if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

func (x *DescribeDatabaseRequest) Validate() error {
if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

Expand All @@ -165,12 +135,6 @@ func (x *CreateDatabaseRequest) Validate() error {
return err
}

if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

Expand All @@ -179,21 +143,10 @@ func (x *DropDatabaseRequest) Validate() error {
return err
}

if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}

return nil
}

func (x *ListDatabasesRequest) Validate() error {
if !IsTxSupported(x) {
if transaction := GetTransaction(x); transaction != nil {
return Errorf(Code_INVALID_ARGUMENT, "interactive tx not supported but transaction token found")
}
}
return nil
}

Expand Down
99 changes: 0 additions & 99 deletions cdc/listener.go

This file was deleted.

Loading

0 comments on commit 0cafb54

Please sign in to comment.