forked from dapr/components-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StateStore API implementation for CockroachDB (dapr#1559)
* statestore for CockroachDB Signed-off-by: Ricardo Corrêa <[email protected]> * Upgrade nacos sdk version to meet compliance (dapr#1547) * Upgrade nacos version Signed-off-by: Shubham Sharma <[email protected]> * Run go mod tidy all Signed-off-by: Shubham Sharma <[email protected]> * Add MaxSize to settings Signed-off-by: Shubham Sharma <[email protected]> Signed-off-by: Ricardo Corrêa <[email protected]> * conformance tests for CockroachDB Signed-off-by: Ricardo Corrêa <[email protected]> * fix comment for internalNew func (CockroachDB) Signed-off-by: Ricardo Corrêa <[email protected]> * remove metadata from log (CockroachDB) Signed-off-by: Ricardo Corrêa <[email protected]> * removed unnecessary nil fields from GetResponse Signed-off-by: Ricardo Corrêa <[email protected]> * Fix ordering in transaction API for CockroachDB Signed-off-by: Ricardo Corrêa <[email protected]> * fix non-deterministic etag error (CockroachDB) Signed-off-by: Ricardo Corrêa <[email protected]> * fix error message for delete operation without key (CockroachDB) Signed-off-by: Ricardo Corrêa <[email protected]> Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Yaron Schneider <[email protected]> Co-authored-by: Taction <[email protected]> Co-authored-by: Bernd Verst <[email protected]> Co-authored-by: Looong Dai <[email protected]> Signed-off-by: Surender Singh Malik <[email protected]>
- Loading branch information
1 parent
d6c3c3a
commit ced9170
Showing
13 changed files
with
2,260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: '2' | ||
services: | ||
cockroachdb: | ||
image: cockroachdb/cockroach:v21.2.3 | ||
hostname: cockroachdb | ||
command: start-single-node --cluster-name=single-node --logtostderr=WARNING --log-file-verbosity=WARNING --insecure | ||
restart: always | ||
ports: | ||
- "26257:26257" | ||
|
||
cockroachdb-init: | ||
hostname: cockroachdb-init | ||
image: timveil/cockroachdb-remote-client:latest | ||
environment: | ||
- COCKROACH_HOST=cockroachdb:26257 | ||
- COCKROACH_INSECURE=true | ||
- DATABASE_NAME=dapr_test | ||
depends_on: | ||
- cockroachdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
Copyright 2022 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cockroachdb | ||
|
||
import ( | ||
"github.com/dapr/components-contrib/state" | ||
"github.com/dapr/kit/logger" | ||
) | ||
|
||
// CockroachDB state store. | ||
type CockroachDB struct { | ||
features []state.Feature | ||
logger logger.Logger | ||
dbaccess dbAccess | ||
} | ||
|
||
// New creates a new instance of CockroachDB state store. | ||
func New(logger logger.Logger) *CockroachDB { | ||
dba := newCockroachDBAccess(logger) | ||
|
||
return internalNew(logger, dba) | ||
} | ||
|
||
// internalNew creates a new instance of a CockroachDB state store. | ||
// This unexported constructor allows injecting a dbAccess instance for unit testing. | ||
func internalNew(logger logger.Logger, dba dbAccess) *CockroachDB { | ||
return &CockroachDB{ | ||
features: []state.Feature{state.FeatureETag, state.FeatureTransactional}, | ||
logger: logger, | ||
dbaccess: dba, | ||
} | ||
} | ||
|
||
// Init initializes the CockroachDB state store. | ||
func (c *CockroachDB) Init(metadata state.Metadata) error { | ||
return c.dbaccess.Init(metadata) | ||
} | ||
|
||
// Features returns the features available in this state store. | ||
func (c *CockroachDB) Features() []state.Feature { | ||
return c.features | ||
} | ||
|
||
// Delete removes an entity from the store. | ||
func (c *CockroachDB) Delete(req *state.DeleteRequest) error { | ||
return c.dbaccess.Delete(req) | ||
} | ||
|
||
// Get returns an entity from store. | ||
func (c *CockroachDB) Get(req *state.GetRequest) (*state.GetResponse, error) { | ||
return c.dbaccess.Get(req) | ||
} | ||
|
||
// Set adds/updates an entity on store. | ||
func (c *CockroachDB) Set(req *state.SetRequest) error { | ||
return c.dbaccess.Set(req) | ||
} | ||
|
||
// Ping checks if database is available. | ||
func (c *CockroachDB) Ping() error { | ||
return c.dbaccess.Ping() | ||
} | ||
|
||
// BulkDelete removes multiple entries from the store. | ||
func (c *CockroachDB) BulkDelete(req []state.DeleteRequest) error { | ||
return c.dbaccess.BulkDelete(req) | ||
} | ||
|
||
// BulkGet performs a bulks get operations. | ||
func (c *CockroachDB) BulkGet(req []state.GetRequest) (bool, []state.BulkGetResponse, error) { | ||
// TODO: replace with ExecuteMulti for performance. | ||
return false, nil, nil | ||
} | ||
|
||
// BulkSet adds/updates multiple entities on store. | ||
func (c *CockroachDB) BulkSet(req []state.SetRequest) error { | ||
return c.dbaccess.BulkSet(req) | ||
} | ||
|
||
// Multi handles multiple transactions. Implements TransactionalStore. | ||
func (c *CockroachDB) Multi(request *state.TransactionalStateRequest) error { | ||
return c.dbaccess.ExecuteMulti(request) | ||
} | ||
|
||
// Query executes a query against store. | ||
func (c *CockroachDB) Query(req *state.QueryRequest) (*state.QueryResponse, error) { | ||
return c.dbaccess.Query(req) | ||
} | ||
|
||
// Close implements io.Closer. | ||
func (c *CockroachDB) Close() error { | ||
if c.dbaccess != nil { | ||
return c.dbaccess.Close() | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.