Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ test-go-units-crdb: cleanup-test-go-units-crdb
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/rid --db_version latest --datastore_host localhost
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/scd --db_version latest --datastore_host localhost
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/aux_ --db_version latest --datastore_host localhost
go test -cover -count=1 -v ./pkg/rid/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/rid/store/sqlstore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/rid/application --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/scd/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/aux_/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/scd/store/sqlstore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/aux_/store/sqlstore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
@docker stop dss-crdb-for-testing > /dev/null
@docker rm dss-crdb-for-testing > /dev/null

Expand Down
2 changes: 1 addition & 1 deletion build/db_schemas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ places:
* [DSS main.jsonnet](../../deploy/services/tanka/examples/minimum/main.jsonnet)
* [Schema manager main.jsonnet](../../deploy/services/tanka/examples/schema_manager/main.jsonnet)
* [Minikube main.jsonnet](../../deploy/services/tanka/examples/minikube/main.jsonnet)
* /pkg/{rid|scd|aux_}/store/datastore/store.go
* /pkg/{rid|scd|aux_}/store/sqlstore/store.go
* /deploy/infrastructure/dependencies/terraform-commons-dss/default_latest.tf
* /deploy/services/helm-charts/dss/templates/schema-manager.yaml

Expand Down
14 changes: 7 additions & 7 deletions build/db_schemas/update_latest_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ YBDB_RID_MAJOR=$(echo "$YBDB_RID" | cut -d. -f1)
YBDB_SCD_MAJOR=$(echo "$YBDB_SCD" | cut -d. -f1)
AUX_MAJOR=$(echo "$AUX" | cut -d. -f1)

# Replace major versions in datastore files
sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$CRDB_SCD_MAJOR/" "${BASEDIR}/pkg/scd/store/datastore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$YBDB_SCD_MAJOR/" "${BASEDIR}/pkg/scd/store/datastore/store.go"
# Replace major versions in sqlstore files
sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$CRDB_SCD_MAJOR/" "${BASEDIR}/pkg/scd/store/sqlstore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$YBDB_SCD_MAJOR/" "${BASEDIR}/pkg/scd/store/sqlstore/store.go"

sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$CRDB_RID_MAJOR/" "${BASEDIR}/pkg/rid/store/datastore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$YBDB_RID_MAJOR/" "${BASEDIR}/pkg/rid/store/datastore/store.go"
sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$CRDB_RID_MAJOR/" "${BASEDIR}/pkg/rid/store/sqlstore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$YBDB_RID_MAJOR/" "${BASEDIR}/pkg/rid/store/sqlstore/store.go"

sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$AUX_MAJOR/" "${BASEDIR}/pkg/aux_/store/datastore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$AUX_MAJOR/" "${BASEDIR}/pkg/aux_/store/datastore/store.go"
sed -i -E "s/(currentCrdbMajorSchemaVersion.*= )[0-9]/\1$AUX_MAJOR/" "${BASEDIR}/pkg/aux_/store/sqlstore/store.go"
sed -i -E "s/(currentYugabyteMajorSchemaVersion.*= )[0-9]/\1$AUX_MAJOR/" "${BASEDIR}/pkg/aux_/store/sqlstore/store.go"
2 changes: 1 addition & 1 deletion cmds/core-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ go run ./cmds/core-service \

#### CockroachDB cluster

To run correctly, core-service must be able to [access](../../pkg/datastore/params/params.go) a CockroachDB or a Yugabyte cluster. Provision of this cluster is handled automatically for a local development environment if following [the instructions for a standalone instance](../../build/dev/standalone_instance.md).
To run correctly, core-service must be able to [access](../../pkg/sqlstore/params/params.go) a CockroachDB or a Yugabyte cluster. Provision of this cluster is handled automatically for a local development environment if following [the instructions for a standalone instance](../../build/dev/standalone_instance.md).

Alternatively, a CockroachDB instance can be created manually with:

Expand Down
16 changes: 8 additions & 8 deletions cmds/core-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
apiversioningv1 "github.com/interuss/dss/pkg/api/versioningv1"
"github.com/interuss/dss/pkg/auth"
aux "github.com/interuss/dss/pkg/aux_"
auxc "github.com/interuss/dss/pkg/aux_/store/datastore"
auxs "github.com/interuss/dss/pkg/aux_/store"
"github.com/interuss/dss/pkg/build"
"github.com/interuss/dss/pkg/datastore"
"github.com/interuss/dss/pkg/logging"
"github.com/interuss/dss/pkg/rid/application"
rid_v1 "github.com/interuss/dss/pkg/rid/server/v1"
rid_v2 "github.com/interuss/dss/pkg/rid/server/v2"
ridc "github.com/interuss/dss/pkg/rid/store/datastore"
rids "github.com/interuss/dss/pkg/rid/store"
"github.com/interuss/dss/pkg/scd"
scdc "github.com/interuss/dss/pkg/scd/store/datastore"
scds "github.com/interuss/dss/pkg/scd/store"
"github.com/interuss/dss/pkg/store"
"github.com/interuss/dss/pkg/version"
"github.com/interuss/dss/pkg/versioning"
"github.com/interuss/stacktrace"
Expand Down Expand Up @@ -84,7 +84,7 @@ func createKeyResolver() (auth.KeyResolver, error) {
}

func createAuxServer(ctx context.Context, locality string, publicEndpoint string, scdGlobalLock bool, logger *zap.Logger) (*aux.Server, error) {
auxStore, err := auxc.Dial(ctx, logger, true)
auxStore, err := auxs.Init(ctx, logger, true)
if err != nil {
return nil, err
}
Expand All @@ -105,7 +105,7 @@ func createAuxServer(ctx context.Context, locality string, publicEndpoint string

func createRIDServers(ctx context.Context, locality string, logger *zap.Logger) (*rid_v1.Server, *rid_v2.Server, error) {

ridStore, err := ridc.Dial(ctx, logger, true)
ridStore, err := rids.Init(ctx, logger, true)
if err != nil {
return nil, nil, err
}
Expand All @@ -129,7 +129,7 @@ func createRIDServers(ctx context.Context, locality string, logger *zap.Logger)

func createSCDServer(ctx context.Context, logger *zap.Logger) (*scd.Server, error) {

scdStore, err := scdc.Dial(ctx, logger, true, *scdGlobalLock)
scdStore, err := scds.Init(ctx, logger, true, *scdGlobalLock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func main() {
backoff := 0
for {
if err := RunHTTPServer(ctx, cancel, *address, *locality); err != nil {
if stacktrace.GetCode(err) == datastore.CodeRetryable {
if stacktrace.GetCode(err) == store.CodeRetryable {
logger.Info(fmt.Sprintf("Prerequisites not yet satisfied; waiting %.fs to retry...", backoffs[backoff].Seconds()), zap.Error(err))
time.Sleep(backoffs[backoff])
if backoff < len(backoffs)-1 {
Expand Down
8 changes: 4 additions & 4 deletions cmds/db-manager/cleanup/evict.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
dssmodels "github.com/interuss/dss/pkg/models"
ridmodels "github.com/interuss/dss/pkg/rid/models"
ridrepos "github.com/interuss/dss/pkg/rid/repos"
ridc "github.com/interuss/dss/pkg/rid/store/datastore"
rids "github.com/interuss/dss/pkg/rid/store"
scdmodels "github.com/interuss/dss/pkg/scd/models"
scdrepos "github.com/interuss/dss/pkg/scd/repos"
scdc "github.com/interuss/dss/pkg/scd/store/datastore"
scds "github.com/interuss/dss/pkg/scd/store"
"github.com/interuss/stacktrace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -54,12 +54,12 @@ func evict(cmd *cobra.Command, _ []string) error {

logger := logging.WithValuesFromContext(ctx, logging.Logger)

scdStore, err := scdc.Dial(ctx, logger, false, false)
scdStore, err := scds.Init(ctx, logger, false, false)
if err != nil {
return err
}

ridStore, err := ridc.Dial(ctx, logger, false)
ridStore, err := rids.Init(ctx, logger, false)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions cmds/db-manager/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"time"

"github.com/coreos/go-semver/semver"
"github.com/interuss/dss/pkg/datastore"
"github.com/interuss/dss/pkg/datastore/params"
"github.com/interuss/dss/pkg/sqlstore"
"github.com/interuss/dss/pkg/sqlstore/params"

"github.com/interuss/stacktrace"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -97,8 +97,8 @@ func migrate(cmd *cobra.Command, _ []string) error {
log.Printf("Datastore server type and version: %s@%s", ds.Version.Type, ds.Version.SemVer.String())

var (
isCockroach = ds.Version.Type == datastore.CockroachDB
isYugabyte = ds.Version.Type == datastore.Yugabyte
isCockroach = ds.Version.Type == sqlstore.CockroachDB
isYugabyte = ds.Version.Type == sqlstore.Yugabyte
)

// Make sure specified database exists
Expand Down Expand Up @@ -225,11 +225,11 @@ func migrate(cmd *cobra.Command, _ []string) error {
return nil
}

func connectTo(ctx context.Context, dbName string) (*datastore.Datastore, error) {
func connectTo(ctx context.Context, dbName string) (*sqlstore.Store[any], error) {
// Connect to database server
connectParameters := params.GetConnectParameters()
connectParameters.DBName = dbName
return datastore.Dial(ctx, connectParameters)
return sqlstore.Dial[any](ctx, connectParameters)
}

func enumerateMigrationSteps(path *string) ([]MigrationStep, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/aux_/accepted_ca_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

restapi "github.com/interuss/dss/pkg/api/auxv1"
"github.com/interuss/dss/pkg/datastore/params"
"github.com/interuss/dss/pkg/sqlstore/params"
)

func (a *Server) GetAcceptedCAs(ctx context.Context, req *restapi.GetAcceptedCAsRequest) restapi.GetAcceptedCAsResponseSet {
Expand Down
2 changes: 1 addition & 1 deletion pkg/aux_/instance_ca_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

restapi "github.com/interuss/dss/pkg/api/auxv1"
"github.com/interuss/dss/pkg/datastore/params"
"github.com/interuss/dss/pkg/sqlstore/params"
)

func (a *Server) GetInstanceCAs(ctx context.Context, req *restapi.GetInstanceCAsRequest) restapi.GetInstanceCAsResponseSet {
Expand Down
60 changes: 0 additions & 60 deletions pkg/aux_/store/datastore/store.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package aux_.store.datastore provides a concrete implementation of a
// Package aux_.store.sqlstore provides a concrete implementation of a
// store.Store[aux_.repos.Repository] using a database as a data backing (such as CockroachDB or
// YugabyteDB).
package datastore
package sqlstore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package datastore
package sqlstore

import (
"context"
"time"

auxmodels "github.com/interuss/dss/pkg/aux_/models"
"github.com/interuss/dss/pkg/datastore"
dsserr "github.com/interuss/dss/pkg/errors"
"github.com/interuss/dss/pkg/sqlstore"
"github.com/interuss/stacktrace"
)

Expand Down Expand Up @@ -145,16 +145,16 @@ func (r *repo) RecordHeartbeat(ctx context.Context, heartbeat auxmodels.Heartbea

}

// GetDSSAirspaceRepresentationID gets the ID of the common DSS Airspace Representation the Datastore represents.
// GetDSSAirspaceRepresentationID gets the ID of the common DSS Airspace Representation the sqlstore represents.
func (r *repo) GetDSSAirspaceRepresentationID(ctx context.Context) (string, error) {
switch r.version.Type {
case datastore.CockroachDB:
case sqlstore.CockroachDB:
var darID string
if err := r.QueryRow(ctx, "SELECT crdb_internal.cluster_id()").Scan(&darID); err != nil {
return darID, stacktrace.Propagate(err, "Error getting CockroachDB cluster ID")
}
return darID, nil
case datastore.Yugabyte:
case sqlstore.Yugabyte:

var darID string

Expand All @@ -173,6 +173,6 @@ func (r *repo) GetDSSAirspaceRepresentationID(ctx context.Context) (string, erro
return darID, nil

default:
return "", stacktrace.NewErrorWithCode(dsserr.NotImplemented, "GetDSSAirspaceRepresentationID is not yet supported in current Datastore type '%s'", r.version.Type)
return "", stacktrace.NewErrorWithCode(dsserr.NotImplemented, "GetDSSAirspaceRepresentationID is not yet supported in current sqlstore type '%s'", r.version.Type)
}
}
43 changes: 43 additions & 0 deletions pkg/aux_/store/sqlstore/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package sqlstore

import (
"context"

"github.com/interuss/dss/pkg/aux_/repos"
"github.com/interuss/dss/pkg/logging"
dssql "github.com/interuss/dss/pkg/sql"
"github.com/interuss/dss/pkg/sqlstore"
"github.com/jonboulle/clockwork"
"go.uber.org/zap"
)

const (
// The current major schema version per sqlstore type.
currentCrdbMajorSchemaVersion = 1
currentYugabyteMajorSchemaVersion = 1
)

type repo struct {
dssql.Queryable
clock clockwork.Clock
logger *zap.Logger
version *sqlstore.Version
}

// Init initializes the SQL-backed rid store. It return a concrete sqlstore.Store[aux_.repos.Repository] providing the
// ability to interact with a database-backed store of aux information.
func Init(ctx context.Context, logger *zap.Logger, withCheckCron bool) (*sqlstore.Store[repos.Repository], error) {
return sqlstore.Init(ctx, sqlstore.Config[repos.Repository]{
DBName: "aux",
CrdbMajorSchemaVersion: currentCrdbMajorSchemaVersion,
YbMajorSchemaVersion: currentYugabyteMajorSchemaVersion,
NewRepo: func(q dssql.Queryable, clock clockwork.Clock, version *sqlstore.Version) repos.Repository {
return &repo{
Queryable: q,
clock: clock,
logger: logging.WithValuesFromContext(ctx, logger),
version: version,
}
},
}, withCheckCron)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package datastore
package sqlstore

import (
"context"
"testing"

"github.com/interuss/dss/pkg/datastore"
"github.com/interuss/dss/pkg/datastore/params"
"github.com/interuss/dss/pkg/aux_/repos"
"github.com/interuss/dss/pkg/logging"
"github.com/interuss/dss/pkg/sqlstore"
"github.com/interuss/dss/pkg/sqlstore/params"
"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,7 +16,7 @@ var (
fakeClock = clockwork.NewFakeClock()
)

func setUpStore(ctx context.Context, t *testing.T) (*Store, func()) {
func setUpStore(ctx context.Context, t *testing.T) (*sqlstore.Store[repos.Repository], func()) {
connectParameters := params.GetConnectParameters()
if connectParameters.Host == "" || connectParameters.Port == 0 {
t.Skip()
Expand All @@ -32,11 +33,9 @@ func setUpStore(ctx context.Context, t *testing.T) (*Store, func()) {
}
}

func newTestStore(ctx context.Context, t *testing.T, connectParameters params.ConnectParameters) (*Store, error) {
db, err := datastore.Dial(ctx, connectParameters)
require.NoError(t, err)
func newTestStore(ctx context.Context, t *testing.T, connectParameters params.ConnectParameters) (*sqlstore.Store[repos.Repository], error) {
s, err := Init(ctx, logging.Logger, false)

s, err := newStore(ctx, db, logging.Logger)
if err != nil {
return nil, err
}
Expand All @@ -46,11 +45,11 @@ func newTestStore(ctx context.Context, t *testing.T, connectParameters params.Co
}

// cleanUp drops all required tables from the store, useful for testing.
func cleanUp(ctx context.Context, s *Store) error {
func cleanUp(ctx context.Context, s *sqlstore.Store[repos.Repository]) error {
const query = `
DELETE FROM dss_metadata WHERE locality IS NOT NULL;
`

_, err := s.DB.Pool.Exec(ctx, query)
_, err := s.Pool.Exec(ctx, query)
return err
}
Loading