@@ -33,38 +33,38 @@ import (
3333
3434const (
3535 createNamespaceQuery = `INSERT INTO
36- namespaces (id, name, is_global, data, data_encoding, notification_version)
37- VALUES($1, $2, $3, $4, $5, $6)`
36+ namespaces (partition_id, id, name, is_global, data, data_encoding, notification_version)
37+ VALUES($1, $2, $3, $4, $5, $6, $7 )`
3838
3939 updateNamespaceQuery = `UPDATE namespaces
4040 SET name = $1, data = $2, data_encoding = $3, notification_version = $4
41- WHERE shard_id =54321 AND id = $5`
41+ WHERE partition_id =54321 AND id = $5`
4242
4343 getNamespacePart = `SELECT id, name, is_global, data, data_encoding, notification_version FROM namespaces`
4444
45- getNamespaceByIDQuery = getNamespacePart + ` WHERE shard_id =$1 AND id = $2`
46- getNamespaceByNameQuery = getNamespacePart + ` WHERE shard_id =$1 AND name = $2`
45+ getNamespaceByIDQuery = getNamespacePart + ` WHERE partition_id =$1 AND id = $2`
46+ getNamespaceByNameQuery = getNamespacePart + ` WHERE partition_id =$1 AND name = $2`
4747
48- listNamespacesQuery = getNamespacePart + ` WHERE shard_id =$1 ORDER BY id LIMIT $2`
49- listNamespacesRangeQuery = getNamespacePart + ` WHERE shard_id =$1 AND id > $2 ORDER BY id LIMIT $3`
48+ listNamespacesQuery = getNamespacePart + ` WHERE partition_id =$1 ORDER BY id LIMIT $2`
49+ listNamespacesRangeQuery = getNamespacePart + ` WHERE partition_id =$1 AND id > $2 ORDER BY id LIMIT $3`
5050
51- deleteNamespaceByIDQuery = `DELETE FROM namespaces WHERE shard_id =$1 AND id = $2`
52- deleteNamespaceByNameQuery = `DELETE FROM namespaces WHERE shard_id =$1 AND name = $2`
51+ deleteNamespaceByIDQuery = `DELETE FROM namespaces WHERE partition_id =$1 AND id = $2`
52+ deleteNamespaceByNameQuery = `DELETE FROM namespaces WHERE partition_id =$1 AND name = $2`
5353
54- getNamespaceMetadataQuery = `SELECT notification_version FROM namespace_metadata`
55- lockNamespaceMetadataQuery = `SELECT notification_version FROM namespace_metadata FOR UPDATE`
56- updateNamespaceMetadataQuery = `UPDATE namespace_metadata SET notification_version = $1 WHERE notification_version = $2`
54+ getNamespaceMetadataQuery = `SELECT notification_version FROM namespace_metadata WHERE partition_id=$1 `
55+ lockNamespaceMetadataQuery = `SELECT notification_version FROM namespace_metadata WHERE partition_id=$1 FOR UPDATE`
56+ updateNamespaceMetadataQuery = `UPDATE namespace_metadata SET notification_version = $1 WHERE notification_version = $2 AND partition_id=$3 `
5757)
5858
5959const (
60- shardID = 54321
60+ partitionID = 54321
6161)
6262
6363var errMissingArgs = errors .New ("missing one or more args for API" )
6464
6565// InsertIntoNamespace inserts a single row into namespaces table
6666func (pdb * db ) InsertIntoNamespace (row * sqlplugin.NamespaceRow ) (sql.Result , error ) {
67- return pdb .conn .Exec (createNamespaceQuery , row .ID , row .Name , row .IsGlobal , row .Data , row .DataEncoding , row .NotificationVersion )
67+ return pdb .conn .Exec (createNamespaceQuery , partitionID , row .ID , row .Name , row .IsGlobal , row .Data , row .DataEncoding , row .NotificationVersion )
6868}
6969
7070// UpdateNamespace updates a single row in namespaces table
@@ -89,9 +89,9 @@ func (pdb *db) selectFromNamespace(filter *sqlplugin.NamespaceFilter) ([]sqlplug
8989 var row sqlplugin.NamespaceRow
9090 switch {
9191 case filter .ID != nil :
92- err = pdb .conn .Get (& row , getNamespaceByIDQuery , shardID , * filter .ID )
92+ err = pdb .conn .Get (& row , getNamespaceByIDQuery , partitionID , * filter .ID )
9393 case filter .Name != nil :
94- err = pdb .conn .Get (& row , getNamespaceByNameQuery , shardID , * filter .Name )
94+ err = pdb .conn .Get (& row , getNamespaceByNameQuery , partitionID , * filter .Name )
9595 }
9696 if err != nil {
9797 return nil , err
@@ -104,9 +104,9 @@ func (pdb *db) selectAllFromNamespace(filter *sqlplugin.NamespaceFilter) ([]sqlp
104104 var rows []sqlplugin.NamespaceRow
105105 switch {
106106 case filter .GreaterThanID != nil :
107- err = pdb .conn .Select (& rows , listNamespacesRangeQuery , shardID , * filter .GreaterThanID , * filter .PageSize )
107+ err = pdb .conn .Select (& rows , listNamespacesRangeQuery , partitionID , * filter .GreaterThanID , * filter .PageSize )
108108 default :
109- err = pdb .conn .Select (& rows , listNamespacesQuery , shardID , filter .PageSize )
109+ err = pdb .conn .Select (& rows , listNamespacesQuery , partitionID , filter .PageSize )
110110 }
111111 return rows , err
112112}
@@ -117,28 +117,28 @@ func (pdb *db) DeleteFromNamespace(filter *sqlplugin.NamespaceFilter) (sql.Resul
117117 var result sql.Result
118118 switch {
119119 case filter .ID != nil :
120- result , err = pdb .conn .Exec (deleteNamespaceByIDQuery , shardID , filter .ID )
120+ result , err = pdb .conn .Exec (deleteNamespaceByIDQuery , partitionID , filter .ID )
121121 default :
122- result , err = pdb .conn .Exec (deleteNamespaceByNameQuery , shardID , filter .Name )
122+ result , err = pdb .conn .Exec (deleteNamespaceByNameQuery , partitionID , filter .Name )
123123 }
124124 return result , err
125125}
126126
127127// LockNamespaceMetadata acquires a write lock on a single row in namespace_metadata table
128128func (pdb * db ) LockNamespaceMetadata () error {
129129 var row sqlplugin.NamespaceMetadataRow
130- err := pdb .conn .Get (& row .NotificationVersion , lockNamespaceMetadataQuery )
130+ err := pdb .conn .Get (& row .NotificationVersion , lockNamespaceMetadataQuery , partitionID )
131131 return err
132132}
133133
134134// SelectFromNamespaceMetadata reads a single row in namespace_metadata table
135135func (pdb * db ) SelectFromNamespaceMetadata () (* sqlplugin.NamespaceMetadataRow , error ) {
136136 var row sqlplugin.NamespaceMetadataRow
137- err := pdb .conn .Get (& row .NotificationVersion , getNamespaceMetadataQuery )
137+ err := pdb .conn .Get (& row .NotificationVersion , getNamespaceMetadataQuery , partitionID )
138138 return & row , err
139139}
140140
141141// UpdateNamespaceMetadata updates a single row in namespace_metadata table
142142func (pdb * db ) UpdateNamespaceMetadata (row * sqlplugin.NamespaceMetadataRow ) (sql.Result , error ) {
143- return pdb .conn .Exec (updateNamespaceMetadataQuery , row .NotificationVersion + 1 , row .NotificationVersion )
143+ return pdb .conn .Exec (updateNamespaceMetadataQuery , row .NotificationVersion + 1 , row .NotificationVersion , partitionID )
144144}
0 commit comments