Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Cassandra Namespace Tables #608

Merged
merged 2 commits into from
Jul 27, 2020
Merged
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
22 changes: 11 additions & 11 deletions common/persistence/cassandra/cassandraMetadataPersistenceV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,50 +45,50 @@ const (
)

const (
templateCreateNamespaceQuery = `INSERT INTO namespaces (` +
templateCreateNamespaceQuery = `INSERT INTO namespaces_by_id (` +
`id, name) ` +
`VALUES(?, ?) IF NOT EXISTS`

templateGetNamespaceQuery = `SELECT name ` +
`FROM namespaces ` +
`FROM namespaces_by_id ` +
`WHERE id = ?`

templateDeleteNamespaceQuery = `DELETE FROM namespaces ` +
templateDeleteNamespaceQuery = `DELETE FROM namespaces_by_id ` +
`WHERE id = ?`

templateNamespaceColumns = `id, name, detail, detail_encoding, notification_version, is_global_namespace`

templateCreateNamespaceByNameQueryWithinBatchV2 = `INSERT INTO namespaces_by_name_v2 ` +
templateCreateNamespaceByNameQueryWithinBatchV2 = `INSERT INTO namespaces ` +
`( namespaces_partition, ` + templateNamespaceColumns + `) ` +
`VALUES(?, ?, ?, ?, ?, ?, ?) IF NOT EXISTS`

templateGetNamespaceByNameQueryV2 = templateListNamespaceQueryV2 + `and name = ?`

templateUpdateNamespaceByNameQueryWithinBatchV2 = `UPDATE namespaces_by_name_v2 ` +
templateUpdateNamespaceByNameQueryWithinBatchV2 = `UPDATE namespaces ` +
`SET detail = ? ,` +
`detail_encoding = ? ,` +
`notification_version = ? ` +
`WHERE namespaces_partition = ? ` +
`and name = ?`

templateGetMetadataQueryV2 = `SELECT notification_version ` +
`FROM namespaces_by_name_v2 ` +
`FROM namespaces ` +
`WHERE namespaces_partition = ? ` +
`and name = ? `

templateUpdateMetadataQueryWithinBatchV2 = `UPDATE namespaces_by_name_v2 ` +
templateUpdateMetadataQueryWithinBatchV2 = `UPDATE namespaces ` +
`SET notification_version = ? ` +
`WHERE namespaces_partition = ? ` +
`and name = ? ` +
`IF notification_version = ? `

templateDeleteNamespaceByNameQueryV2 = `DELETE FROM namespaces_by_name_v2 ` +
templateDeleteNamespaceByNameQueryV2 = `DELETE FROM namespaces ` +
`WHERE namespaces_partition = ? ` +
`and name = ?`

templateListNamespaceQueryV2 = `SELECT ` +
templateNamespaceColumns +
` FROM namespaces_by_name_v2 ` +
` FROM namespaces ` +
`WHERE namespaces_partition = ? `
)

Expand Down Expand Up @@ -171,7 +171,7 @@ func (m *cassandraMetadataPersistenceV2) CreateNamespaceInV2Table(request *p.Int
}()

if err != nil {
return nil, serviceerror.NewInternal(fmt.Sprintf("CreateNamespace operation failed. Inserting into namespaces_by_name_v2 table. Error: %v", err))
return nil, serviceerror.NewInternal(fmt.Sprintf("CreateNamespace operation failed. Inserting into namespaces table. Error: %v", err))
}

if !applied {
Expand Down Expand Up @@ -362,7 +362,7 @@ func (m *cassandraMetadataPersistenceV2) GetMetadata() (*p.GetMetadataResponse,
if err != nil {
if err == gocql.ErrNotFound {
// this error can be thrown in the very beginning,
// i.e. when namespaces_by_name_v2 is initialized
// i.e. when namespaces is initialized
return &p.GetMetadataResponse{NotificationVersion: 0}, nil
}
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions schema/cassandra/temporal/schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ CREATE TABLE tasks (
};

-- this table is only used for storage of mapping of namespace uuid to namespace name
CREATE TABLE namespaces (
CREATE TABLE namespaces_by_id (
id uuid,
name text,
PRIMARY KEY (id)
) WITH COMPACTION = {
'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'
};

CREATE TABLE namespaces_by_name_v2 (
CREATE TABLE namespaces (
namespaces_partition int,
name text,
id uuid,
Expand Down
8 changes: 4 additions & 4 deletions schema/cassandra/temporal/versioned/v1.0/schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ CREATE TABLE tasks (
};

-- this table is only used for storage of mapping of namespace uuid to namespace name
CREATE TABLE namespaces (
CREATE TABLE namespaces_by_id (
id uuid,
name text,
PRIMARY KEY (id)
) WITH COMPACTION = {
'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'
};
'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy' };

CREATE TABLE namespaces_by_name_v2 (

CREATE TABLE namespaces (
namespaces_partition int,
name text,
id uuid,
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/adminCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func AdminGetNamespaceIDOrName(c *cli.Context) {
fmt.Printf("namespace for namespaceId %v is %v \n", namespaceID, namespaceName)
} else {
tmpl := "select namespace from namespaces_by_name where name = ?"
tmplV2 := "select namespace from namespaces_by_name_v2 where namespaces_partition=0 and name = ?"
tmplV2 := "select namespace from namespaces where namespaces_partition=0 and name = ?"

query := session.Query(tmpl, namespace)
res, err := readOneRow(query)
Expand Down