cassandra

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 9 Imported by: 10

README

Using the cassandra schema tool

This package contains the tooling for cadence cassandra operations.

For localhost development

make install-schema

NOTE: See CONTRIBUTING for prerequisite of make command.

For production

Get the Cassandra Schema tool

  • Use brew to install CLI: brew install cadence-workflow which includes cadence-cassandra-tool
    • The schema files are located at /usr/local/etc/cadence/schema/.
    • Follow the instructions if you need to install older versions of schema tools via homebrew. However, easier way is to use new versions of schema tools with old versions of schemas. All you need is to check out the older version of schemas from this repo. Run git checkout v0.21.3 to get the v0.21.3 schemas in the schema folder.
  • Or build yourself, with make cadence-cassandra-tool. See CONTRIBUTING for prerequisite of make command.

Note: The binaries can also be found in the ubercadence/server docker images

Do one time database creation and schema setup for a new cluster

This uses Cassandra's SimpleStratagey for replication. For production, we recommend using a replication factor of 3 with NetworkTopologyStrategy.

cadence-cassandra-tool --ep $CASSANDRA_SEEDS create -k $KEYSPACE --rf $RF

See https://www.ecyrd.com/cassandracalculator for an easy way to determine how many nodes and what replication factor you will want to use. Note that Cadence by default uses Quorum for read and write consistency.

./cadence-cassandra-tool -ep 127.0.0.1 -k cadence setup-schema -v 0.0 -- this sets up just the schema version tables with initial version of 0.0
./cadence-cassandra-tool -ep 127.0.0.1 -k cadence update-schema -d ./schema/cassandra/cadence/versioned -- upgrades your schema to the latest version

./cadence-cassandra-tool -ep 127.0.0.1 -k cadence_visibility setup-schema -v 0.0 -- this sets up just the schema version tables with initial version of 0.0 for visibility
./cadence-cassandra-tool -ep 127.0.0.1 -k cadence_visibility update-schema -d ./schema/cassandra/visibility/versioned -- upgrades your schema to the latest version for visibility

Update schema as part of a release

You can only upgrade to a new version after the initial setup done above.

./cadence-cassandra-tool -ep 127.0.0.1 -k cadence update-schema -d ./schema/cassandra/cadence/versioned -v x.x -y -- executes a dryrun of upgrade to version x.x
./cadence-cassandra-tool -ep 127.0.0.1 -k cadence update-schema -d ./schema/cassandra/cadence/versioned -v x.x    -- actually executes the upgrade to version x.x

./cadence-cassandra-tool -ep 127.0.0.1 -k cadence_visibility update-schema -d ./schema/cassandra/visibility/versioned -v x.x -y -- executes a dryrun of upgrade to version x.x
./cadence-cassandra-tool -ep 127.0.0.1 -k cadence_visibility update-schema -d ./schema/cassandra/visibility/versioned -v x.x    -- actually executes the upgrade to version x.x

Documentation

Index

Constants

View Source
const (
	DefaultTimeout        = 30 // Timeout in seconds
	DefaultConnectTimeout = 2  // Connect timeout in seconds
	DefaultCassandraPort  = 9042
	SystemKeyspace        = "system"
)

Variables

This section is empty.

Functions

func BuildCLIOptions added in v0.21.0

func BuildCLIOptions() *cli.App

func CheckCompatibleVersion added in v0.3.3

func CheckCompatibleVersion(
	cfg config.Cassandra,
	expectedVersion string,
	expectedConsistency gocql.Consistency,
) error

CheckCompatibleVersion check the version compatibility

func RunTool

func RunTool(args []string) error

RunTool runs the cadence-cassandra-tool command line tool

func SetupSchema

func SetupSchema(config *SetupSchemaConfig) error

SetupSchema setups the cassandra schema

func VerifyCompatibleVersion added in v0.3.6

func VerifyCompatibleVersion(
	cfg config.Persistence, expectedConsistency gocql.Consistency,
) error

VerifyCompatibleVersion ensures that the installed version of cadence and visibility keyspaces is greater than or equal to the expected version. In most cases, the versions should match. However if after a schema upgrade there is a code rollback, the code version (expected version) would fall lower than the actual version in cassandra.

Types

type CQLClientConfig added in v0.5.7

type CQLClientConfig struct {
	Hosts                 string
	Port                  int
	User                  string
	Password              string
	AllowedAuthenticators []string
	Keyspace              string
	Timeout               int
	ConnectTimeout        int
	NumReplicas           int
	ProtoVersion          int
	TLS                   *config.TLS
}

CQLClientConfig contains the configuration for cql client

type CqlClient added in v0.21.0

type CqlClient interface {
	CreateDatabase(name string) error
	DropDatabase(name string) error
	CreateKeyspace(name string) error
	CreateNTSKeyspace(name string, datacenter string) error
	DropKeyspace(name string) error
	DropAllTables() error
	CreateSchemaVersionTables() error
	ReadSchemaVersion() (string, error)
	UpdateSchemaVersion(newVersion string, minCompatibleVersion string) error
	WriteSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, desc string) error
	ExecDDLQuery(stmt string, args ...interface{}) error
	Close()
	ListTables() ([]string, error)
	ListTypes() ([]string, error)
	DropTable(name string) error
	DropType(name string) error
	DropAllTablesTypes() error
}

func NewCQLClient added in v0.21.0

func NewCQLClient(cfg *CQLClientConfig, expectedConsistency gocql.Consistency) (CqlClient, error)

NewCQLClient returns a new instance of CQLClient

type CqlClientImpl added in v1.0.0

type CqlClientImpl struct {
	// contains filtered or unexported fields
}

func (*CqlClientImpl) Close added in v1.0.0

func (client *CqlClientImpl) Close()

Close closes the cql client

func (*CqlClientImpl) CreateDatabase added in v1.0.0

func (client *CqlClientImpl) CreateDatabase(name string) error

func (*CqlClientImpl) CreateKeyspace added in v1.0.0

func (client *CqlClientImpl) CreateKeyspace(name string) error

CreateNTSKeyspace creates a cassandra Keyspace if it doesn't exist using network topology strategy

func (*CqlClientImpl) CreateNTSKeyspace added in v1.0.0

func (client *CqlClientImpl) CreateNTSKeyspace(name string, datacenter string) error

CreateNTSKeyspace creates a cassandra Keyspace if it doesn't exist using network topology strategy

func (*CqlClientImpl) CreateSchemaVersionTables added in v1.0.0

func (client *CqlClientImpl) CreateSchemaVersionTables() error

CreateSchemaVersionTables sets up the schema version tables

func (*CqlClientImpl) DropAllTables added in v1.0.0

func (client *CqlClientImpl) DropAllTables() error

func (*CqlClientImpl) DropAllTablesTypes added in v1.0.0

func (client *CqlClientImpl) DropAllTablesTypes() error

DropAllTablesTypes deletes all tables/types in the Keyspace without deleting the Keyspace

func (*CqlClientImpl) DropDatabase added in v1.0.0

func (client *CqlClientImpl) DropDatabase(name string) error

func (*CqlClientImpl) DropKeyspace added in v1.0.0

func (client *CqlClientImpl) DropKeyspace(name string) error

DropKeyspace drops a Keyspace

func (*CqlClientImpl) DropTable added in v1.0.0

func (client *CqlClientImpl) DropTable(name string) error

DropTable drops a given table from the Keyspace

func (*CqlClientImpl) DropType added in v1.0.0

func (client *CqlClientImpl) DropType(name string) error

DropType drops a given type from the Keyspace

func (*CqlClientImpl) ExecDDLQuery added in v1.0.0

func (client *CqlClientImpl) ExecDDLQuery(stmt string, args ...interface{}) error

ExecDDLQuery executes a cql statement

func (*CqlClientImpl) ListTables added in v1.0.0

func (client *CqlClientImpl) ListTables() ([]string, error)

ListTables lists the table names in a Keyspace

func (*CqlClientImpl) ListTypes added in v1.0.0

func (client *CqlClientImpl) ListTypes() ([]string, error)

ListTypes lists the User defined types in a Keyspace.

func (*CqlClientImpl) ReadSchemaVersion added in v1.0.0

func (client *CqlClientImpl) ReadSchemaVersion() (string, error)

ReadSchemaVersion returns the current schema version for the Keyspace

func (*CqlClientImpl) UpdateSchemaVersion added in v1.0.0

func (client *CqlClientImpl) UpdateSchemaVersion(newVersion string, minCompatibleVersion string) error

UpdateSchemaVersion updates the schema version for the Keyspace

func (*CqlClientImpl) WriteSchemaUpdateLog added in v1.0.0

func (client *CqlClientImpl) WriteSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, desc string) error

WriteSchemaUpdateLog adds an entry to the schema update history table

type SetupSchemaConfig

type SetupSchemaConfig struct {
	CQLClientConfig
	schema.SetupConfig
}

SetupSchemaConfig contains the configuration params needed to setup schema tables

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL