Skip to content

Commit

Permalink
Merge pull request #241 from tigrisdata/main
Browse files Browse the repository at this point in the history
Release Alpha
  • Loading branch information
efirs authored May 4, 2022
2 parents f81bfe8 + c52549b commit 589748a
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all: server

.PRECIOUS: ${PROTO_DIR}/%_openapi.yaml ${PROTO_DIR}/%.proto

BUILD_PARAM=-tags=release -ldflags "-X 'main.Version=$(VERSION)' -X 'main.BuildHash=$(GIT_HASH)'" $(shell printenv BUILD_PARAM)
BUILD_PARAM=-tags=release -ldflags "-X 'github.com/tigrisdata/tigris/util.Version=$(VERSION)' -X 'github.com/tigrisdata/tigris/util.BuildHash=$(GIT_HASH)'" $(shell printenv BUILD_PARAM)
TEST_PARAM=-cover -race -tags=test,integration $(shell printenv TEST_PARAM)

${PROTO_DIR}/%.proto:
Expand Down
2 changes: 1 addition & 1 deletion api/proto
Submodule proto updated from 25333a to 830440
3 changes: 2 additions & 1 deletion api/server/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func GetTransaction(req Request) *TransactionCtx {
return r.GetOptions().GetWriteOptions().GetTxCtx()
case *ReadRequest:
if r.GetOptions() == nil {
return r.GetOptions().GetTxCtx()
return nil
}
return r.GetOptions().GetTxCtx()
case *CreateOrUpdateCollectionRequest:
if r.GetOptions() == nil || r.GetOptions().GetTxCtx() == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/getkin/kin-openapi v0.94.0
github.com/go-chi/chi/v5 v5.0.7
github.com/golang/protobuf v1.5.2
github.com/google/gnostic v0.6.9
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware/providers/zerolog/v2 v2.0.0-rc.2.0.20211207221722-a5b9e0b0458c
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d/go.
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/deepmap/oapi-codegen v1.10.1 h1:xybuJUR6D8l7P+LAuxOm5SD7nTlFKHWvOPl31q+DDVs=
github.com/deepmap/oapi-codegen v1.10.1/go.mod h1:TvVmDQlUkFli9gFij/gtW1o+tFBr4qCHyv2zG+R0YZY=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -97,6 +98,7 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
Expand Down Expand Up @@ -175,6 +177,8 @@ github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=
github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -268,6 +272,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
Expand Down Expand Up @@ -368,6 +373,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down Expand Up @@ -793,6 +799,7 @@ google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEc
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc h1:fb/ViRpv3ln/LvbqZtTpoOd1YQDNH12gaGZreoSFovE=
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
9 changes: 2 additions & 7 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ import (
"github.com/tigrisdata/tigris/server/config"
"github.com/tigrisdata/tigris/server/muxer"
"github.com/tigrisdata/tigris/store/kv"
"github.com/tigrisdata/tigris/util"
ulog "github.com/tigrisdata/tigris/util/log"
)

//Version of this build
var Version string

//BuildHash keeps Git hash of the commit of this build
var BuildHash string

func main() {
pflag.String("api.port", "", "set port server listens on")

config.LoadConfig("server", &config.DefaultConfig)

ulog.Configure(config.DefaultConfig.Log)

log.Info().Str("version", Version).Str("BuildHash", BuildHash).Msgf("Starting server")
log.Info().Str("version", util.Version).Msgf("Starting server")

kvStore, err := kv.NewKeyValueStore(&config.DefaultConfig.FoundationDB)
if err != nil {
Expand Down
17 changes: 11 additions & 6 deletions server/metadata/key_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ type Encoder interface {
// information i.e. whether the index is pkey, etc. The remaining elements are values for this index.
EncodeKey(ns Namespace, db *Database, coll *schema.DefaultCollection, idx *schema.Index, idxParts []interface{}) (keys.Key, error)

DecodeTableName(tableName []byte) (uint32, uint32, uint32)
// DecodeTableName is used to decode the key stored in FDB and extract namespace name, database name and collection name.
DecodeTableName(tableName []byte) (string, string, string, bool)
DecodeIndexName(indexName []byte) uint32
}

// NewEncoder creates Dictionary encoder to encode keys.
func NewEncoder() Encoder {
return &DictKeyEncoder{}
func NewEncoder(mgr *TenantManager) Encoder {
return &DictKeyEncoder{
mgr: mgr,
}
}

type DictKeyEncoder struct{}
type DictKeyEncoder struct {
mgr *TenantManager
}

func (d *DictKeyEncoder) EncodeTableName(ns Namespace, db *Database, coll *schema.DefaultCollection) []byte {
return d.encodedTableName(ns, db, coll)
Expand Down Expand Up @@ -88,12 +93,12 @@ func (d *DictKeyEncoder) encodedIdxName(idx *schema.Index) []byte {
return encoding.UInt32ToByte(idx.Id)
}

func (d *DictKeyEncoder) DecodeTableName(tableName []byte) (uint32, uint32, uint32) {
func (d *DictKeyEncoder) DecodeTableName(tableName []byte) (string, string, string, bool) {
nsId := encoding.ByteToUInt32(tableName[0:4])
dbId := encoding.ByteToUInt32(tableName[4:8])
collId := encoding.ByteToUInt32(tableName[8:12])

return nsId, dbId, collId
return d.mgr.GetTableNameFromId(nsId, dbId, collId)
}

func (d *DictKeyEncoder) DecodeIndexName(indexName []byte) uint32 {
Expand Down
42 changes: 37 additions & 5 deletions server/metadata/key_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,50 @@ import (
"github.com/tigrisdata/tigris/server/metadata/encoding"
)

func TestEncodeKey(t *testing.T) {
ns := NewTenantNamespace("hello", 1)
db := &Database{id: 3}
coll := &schema.DefaultCollection{Id: 5}
func TestEncodeDecodeKey(t *testing.T) {
coll := &schema.DefaultCollection{
Id: 5,
Name: "test_coll",
}
idx := &schema.Index{Id: 10}
ns := NewTenantNamespace("test_ns", 1)
db := &Database{
id: 3,
name: "test_db",
idToCollectionMap: map[uint32]string{
coll.Id: coll.Name,
},
}

k := NewEncoder()
mgr := &TenantManager{
idToTenantMap: map[uint32]string{
ns.Id(): ns.Name(),
},
tenants: map[string]*Tenant{
ns.Name(): {
namespace: ns,
databases: map[string]*Database{
db.name: db,
},
idToDatabaseMap: map[uint32]string{
db.id: db.Name(),
},
},
},
}

k := NewEncoder(mgr)
encodedTable := k.EncodeTableName(ns, db, coll)
require.Equal(t, uint32(1), encoding.ByteToUInt32(encodedTable[0:4]))
require.Equal(t, uint32(3), encoding.ByteToUInt32(encodedTable[4:8]))
require.Equal(t, uint32(5), encoding.ByteToUInt32(encodedTable[8:12]))

encodedIdx := k.EncodeIndexName(idx)
require.Equal(t, uint32(10), encoding.ByteToUInt32(encodedIdx))

tenantName, dbName, collName, ok := k.DecodeTableName(encodedTable)
require.Equal(t, ns.Name(), tenantName)
require.Equal(t, db.name, dbName)
require.Equal(t, coll.Name, collName)
require.True(t, ok)
}
8 changes: 4 additions & 4 deletions server/metadata/meta_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ var (

type Version []byte

// MetaVersion is used to maintain a version for each schema change. Using this we can implement transactional DDL APIs.
// MetaVersionMgr is used to maintain a version for each schema change. Using this we can implement transactional DDL APIs.
// This will also be used to provide a strongly consistent Cache lookup on the schemas i.e. anytime version changes we
// know that a DDL operation is performed which means we can invalidate the cache and reload from the disk.
type MetaVersion struct{}
type MetaVersionMgr struct{}

// Increment is used to increment the metadata version
func (m *MetaVersion) Increment(ctx context.Context, tx transaction.Tx) error {
func (m *MetaVersionMgr) Increment(ctx context.Context, tx transaction.Tx) error {
return tx.SetVersionstampedValue(ctx, VersionKey, VersionValue)
}

// Read reads the latest metadata version
func (m *MetaVersion) Read(ctx context.Context, tx transaction.Tx) (Version, error) {
func (m *MetaVersionMgr) Read(ctx context.Context, tx transaction.Tx) (Version, error) {
return tx.Get(ctx, VersionKey)
}
4 changes: 2 additions & 2 deletions server/metadata/meta_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestMetaVersion(t *testing.T) {
require.NoError(t, err)

t.Run("read versions", func(t *testing.T) {
m := &MetaVersion{}
m := &MetaVersionMgr{}
ctx := context.TODO()
tm := transaction.NewManager(kv)
tx, err := tm.StartTxWithoutTracking(ctx)
Expand All @@ -51,7 +51,7 @@ func TestMetaVersion(t *testing.T) {
require.Equal(t, first, second)
})
t.Run("bump and read", func(t *testing.T) {
m := &MetaVersion{}
m := &MetaVersionMgr{}
ctx := context.TODO()
tm := transaction.NewManager(kv)
tx, err := tm.StartTxWithoutTracking(ctx)
Expand Down
Loading

0 comments on commit 589748a

Please sign in to comment.