Skip to content

Commit 640d378

Browse files
authoredMay 27, 2021
Add skeleton of other nosql plugin and add dynamodb package
1 parent 3866711 commit 640d378

21 files changed

+548
-37
lines changed
 

‎common/config/config.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ type (
151151
// DataStore is the configuration for a single datastore
152152
DataStore struct {
153153
// Cassandra contains the config for a cassandra datastore
154+
// Deprecated: please use NoSQL instead, the structure is backward-compatible
154155
Cassandra *Cassandra `yaml:"cassandra"`
155156
// SQL contains the config for a SQL based datastore
156157
SQL *SQL `yaml:"sql"`
158+
// NoSQL contains the config for a NoSQL based datastore
159+
NoSQL *NoSQL `yaml:"nosql"`
157160
// ElasticSearch contains the config for a ElasticSearch datastore
158161
ElasticSearch *ElasticSearchConfig `yaml:"elasticsearch"`
159162
}
@@ -179,7 +182,13 @@ type (
179182
}
180183

181184
// Cassandra contains configuration to connect to Cassandra cluster
182-
Cassandra struct {
185+
// Deprecated: please use NoSQL instead, the structure is backward-compatible
186+
Cassandra = NoSQL
187+
188+
// NoSQL contains configuration to connect to NoSQL Database cluster
189+
NoSQL struct {
190+
// PluginName is the name of NoSQL plugin, default is "cassandra". Supported values: cassandra
191+
PluginName string `yaml:"pluginName" validate:"nonzero"`
183192
// Hosts is a csv of cassandra endpoints
184193
Hosts string `yaml:"hosts" validate:"nonzero"`
185194
// Port is the cassandra port used for connection by gocql client
@@ -198,6 +207,11 @@ type (
198207
MaxConns int `yaml:"maxConns"`
199208
// TLS configuration
200209
TLS *TLS `yaml:"tls"`
210+
// ConnectAttributes is a set of key-value attributes as a supplement/extension to the above common fields
211+
// Use it ONLY when a configure is too specific to a particular NoSQL database that should not be in the common struct
212+
// Otherwise please add new fields to the struct for better documentation
213+
// If being used in any database, update this comment here to make it clear
214+
ConnectAttributes map[string]string `yaml:"connectAttributes"`
201215
}
202216

203217
// SQL is the configuration for connecting to a SQL backed datastore

‎common/config/persistence.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ func (c *Persistence) Validate() error {
4545
if !ok {
4646
return fmt.Errorf("persistence config: missing config for datastore %v", st)
4747
}
48-
if ds.SQL == nil && ds.Cassandra == nil {
49-
return fmt.Errorf("persistence config: datastore %v: must provide config for one of cassandra or sql stores", st)
48+
if ds.Cassandra != nil {
49+
if ds.NoSQL != nil {
50+
return fmt.Errorf("persistence config: datastore %v: only one of Cassandra or NoSQL can be specified", st)
51+
}
52+
// for backward-compatibility
53+
ds.NoSQL = ds.Cassandra
54+
ds.NoSQL.PluginName = "cassandra"
5055
}
51-
if ds.SQL != nil && ds.Cassandra != nil {
52-
return fmt.Errorf("persistence config: datastore %v: only one of SQL or cassandra can be specified", st)
56+
if ds.SQL == nil && ds.NoSQL == nil {
57+
return fmt.Errorf("persistence config: datastore %v: must provide config for one of SQL or NoSQL stores", st)
58+
}
59+
if ds.SQL != nil && ds.NoSQL != nil {
60+
return fmt.Errorf("persistence config: datastore %v: only one of SQL or NoSQL can be specified", st)
5361
}
5462
if ds.SQL != nil && ds.SQL.NumShards == 0 {
5563
ds.SQL.NumShards = 1

‎common/persistence/cassandra/cassandraPersistenceTest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *TestCluster) Config() config.Persistence {
7979
DefaultStore: "test",
8080
VisibilityStore: "test",
8181
DataStores: map[string]config.DataStore{
82-
"test": {Cassandra: &cfg},
82+
"test": {NoSQL: &cfg},
8383
},
8484
TransactionSizeLimit: dynamicconfig.GetIntPropertyFn(common.DefaultTransactionSizeLimit),
8585
ErrorInjectionRate: dynamicconfig.GetFloatPropertyFn(0),

‎common/persistence/client/factory.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,13 @@ func (f *factoryImpl) Close() {
306306
func (f *factoryImpl) init(clusterName string, limiters map[string]quotas.Limiter) {
307307
f.datastores = make(map[storeType]Datastore, len(storeTypes))
308308
defaultCfg := f.config.DataStores[f.config.DefaultStore]
309+
if defaultCfg.Cassandra != nil {
310+
f.logger.Warn("Cassandra config is deprecated, please use NoSQL with pluginName of cassandra.")
311+
}
309312
defaultDataStore := Datastore{ratelimit: limiters[f.config.DefaultStore]}
310313
switch {
311-
case defaultCfg.Cassandra != nil:
312-
defaultDataStore.factory = cassandra.NewFactory(*defaultCfg.Cassandra, clusterName, f.logger)
314+
case defaultCfg.NoSQL != nil:
315+
defaultDataStore.factory = cassandra.NewFactory(*defaultCfg.NoSQL, clusterName, f.logger)
313316
case defaultCfg.SQL != nil:
314317
if defaultCfg.SQL.EncodingType == "" {
315318
defaultCfg.SQL.EncodingType = string(common.EncodingTypeThriftRW)
@@ -339,10 +342,13 @@ func (f *factoryImpl) init(clusterName string, limiters map[string]quotas.Limite
339342
}
340343

341344
visibilityCfg := f.config.DataStores[f.config.VisibilityStore]
345+
if visibilityCfg.Cassandra != nil {
346+
f.logger.Warn("Cassandra config is deprecated, please use NoSQL with pluginName of cassandra.")
347+
}
342348
visibilityDataStore := Datastore{ratelimit: limiters[f.config.VisibilityStore]}
343349
switch {
344-
case visibilityCfg.Cassandra != nil:
345-
visibilityDataStore.factory = cassandra.NewFactory(*visibilityCfg.Cassandra, clusterName, f.logger)
350+
case visibilityCfg.NoSQL != nil:
351+
visibilityDataStore.factory = cassandra.NewFactory(*visibilityCfg.NoSQL, clusterName, f.logger)
346352
case visibilityCfg.SQL != nil:
347353
var decodingTypes []common.EncodingType
348354
for _, dt := range visibilityCfg.SQL.DecodingTypes {

‎common/persistence/nosql/nosqlplugin/cassandra/tests/cassandra_tool_version_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func (s *VersionTestSuite) TestVerifyCompatibleVersion() {
8282
DefaultStore: "default",
8383
VisibilityStore: "visibility",
8484
DataStores: map[string]config.DataStore{
85-
"default": {Cassandra: &defaultCfg},
86-
"visibility": {Cassandra: &visibilityCfg},
85+
"default": {NoSQL: &defaultCfg},
86+
"visibility": {NoSQL: &visibilityCfg},
8787
},
8888
TransactionSizeLimit: dynamicconfig.GetIntPropertyFn(common.DefaultTransactionSizeLimit),
8989
ErrorInjectionRate: dynamicconfig.GetFloatPropertyFn(0),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2020 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package dynamodb
22+
23+
import (
24+
"errors"
25+
26+
"github.com/uber/cadence/common/config"
27+
"github.com/uber/cadence/common/log"
28+
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
29+
)
30+
31+
const (
32+
// PluginName is the name of the plugin
33+
PluginName = "dynamodb"
34+
)
35+
36+
var (
37+
errConditionFailed = errors.New("internal condition fail error")
38+
)
39+
40+
// ddb represents a logical connection to DynamoDB database
41+
type ddb struct {
42+
logger log.Logger
43+
}
44+
45+
var _ nosqlplugin.DB = (*ddb)(nil)
46+
47+
// NewDynamoDB return a new DB
48+
func NewDynamoDB(cfg config.NoSQL, logger log.Logger) (nosqlplugin.DB, error) {
49+
panic("TODO")
50+
}
51+
52+
func (db *ddb) Close() {
53+
panic("TODO")
54+
}
55+
56+
func (db *ddb) PluginName() string {
57+
return PluginName
58+
}
59+
60+
func (db *ddb) IsNotFoundError(err error) bool {
61+
panic("TODO")
62+
}
63+
64+
func (db *ddb) IsTimeoutError(err error) bool {
65+
panic("TODO")
66+
}
67+
68+
func (db *ddb) IsThrottlingError(err error) bool {
69+
panic("TODO")
70+
}
71+
72+
func (db *ddb) IsConditionFailedError(err error) bool {
73+
if err == errConditionFailed {
74+
return true
75+
}
76+
return false
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) 2020 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package dynamodb
22+
23+
import (
24+
"context"
25+
26+
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
27+
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"
28+
)
29+
30+
// Insert a new record to domain, return error if failed or already exists
31+
// Must return conditionFailed error if domainName already exists
32+
func (db *ddb) InsertDomain(
33+
ctx context.Context,
34+
row *nosqlplugin.DomainRow,
35+
) error {
36+
panic("TODO")
37+
}
38+
39+
func (db *ddb) updateMetadataBatch(
40+
ctx context.Context,
41+
batch gocql.Batch,
42+
notificationVersion int64,
43+
) {
44+
panic("TODO")
45+
}
46+
47+
// Update domain
48+
func (db *ddb) UpdateDomain(
49+
ctx context.Context,
50+
row *nosqlplugin.DomainRow,
51+
) error {
52+
panic("TODO")
53+
}
54+
55+
// Get one domain data, either by domainID or domainName
56+
func (db *ddb) SelectDomain(
57+
ctx context.Context,
58+
domainID *string,
59+
domainName *string,
60+
) (*nosqlplugin.DomainRow, error) {
61+
panic("TODO")
62+
}
63+
64+
// Get all domain data
65+
func (db *ddb) SelectAllDomains(
66+
ctx context.Context,
67+
pageSize int,
68+
pageToken []byte,
69+
) ([]*nosqlplugin.DomainRow, []byte, error) {
70+
panic("TODO")
71+
}
72+
73+
// Delete a domain, either by domainID or domainName
74+
func (db *ddb) DeleteDomain(
75+
ctx context.Context,
76+
domainID *string,
77+
domainName *string,
78+
) error {
79+
panic("TODO")
80+
}
81+
82+
func (db *ddb) SelectDomainMetadata(
83+
ctx context.Context,
84+
) (int64, error) {
85+
panic("TODO")
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2020 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package dynamodb
22+
23+
import (
24+
"context"
25+
26+
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
27+
)
28+
29+
// InsertIntoHistoryTreeAndNode inserts one or two rows: tree row and node row(at least one of them)
30+
func (db *ddb) InsertIntoHistoryTreeAndNode(ctx context.Context, treeRow *nosqlplugin.HistoryTreeRow, nodeRow *nosqlplugin.HistoryNodeRow) error {
31+
panic("TODO")
32+
}
33+
34+
// SelectFromHistoryNode read nodes based on a filter
35+
func (db *ddb) SelectFromHistoryNode(ctx context.Context, filter *nosqlplugin.HistoryNodeFilter) ([]*nosqlplugin.HistoryNodeRow, []byte, error) {
36+
panic("TODO")
37+
}
38+
39+
// DeleteFromHistoryTreeAndNode delete a branch record, and a list of ranges of nodes.
40+
func (db *ddb) DeleteFromHistoryTreeAndNode(ctx context.Context, treeFilter *nosqlplugin.HistoryTreeFilter, nodeFilters []*nosqlplugin.HistoryNodeFilter) error {
41+
panic("TODO")
42+
}
43+
44+
// SelectAllHistoryTrees will return all tree branches with pagination
45+
func (db *ddb) SelectAllHistoryTrees(ctx context.Context, nextPageToken []byte, pageSize int) ([]*nosqlplugin.HistoryTreeRow, []byte, error) {
46+
panic("TODO")
47+
}
48+
49+
// SelectFromHistoryTree read branch records for a tree
50+
func (db *ddb) SelectFromHistoryTree(ctx context.Context, filter *nosqlplugin.HistoryTreeFilter) ([]*nosqlplugin.HistoryTreeRow, error) {
51+
panic("TODO")
52+
}
53+

0 commit comments

Comments
 (0)
Please sign in to comment.