Skip to content

Commit

Permalink
Scaffold config store for sql plugins (uber#5396)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored Sep 8, 2023
1 parent 98771a8 commit d97ee5d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
19 changes: 17 additions & 2 deletions common/persistence/sql/sqlConfigStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
"github.com/uber/cadence/common/persistence/serialization"
"github.com/uber/cadence/common/persistence/sql/sqlplugin"
)
Expand All @@ -54,9 +55,23 @@ func NewSQLConfigStore(
}

func (m *sqlConfigStore) FetchConfig(ctx context.Context, configType persistence.ConfigType) (*persistence.InternalConfigStoreEntry, error) {
return nil, fmt.Errorf("not implemented")
entry, err := m.db.SelectLatestConfig(ctx, int(configType))
if m.db.IsNotFoundError(err) {
return nil, nil
}
if err != nil {
return nil, convertCommonErrors(m.db, "FetchConfig", "", err)
}
return entry, nil
}

func (m *sqlConfigStore) UpdateConfig(ctx context.Context, value *persistence.InternalConfigStoreEntry) error {
return fmt.Errorf("not implemented")
err := m.db.InsertConfig(ctx, value)
if err != nil {
if _, ok := err.(*nosqlplugin.ConditionFailure); ok {
return &persistence.ConditionFailedError{Msg: fmt.Sprintf("Version %v already exists. Condition Failed", value.Version)}
}
return convertCommonErrors(m.db, "UpdateConfig", "", err)
}
return nil
}
5 changes: 5 additions & 0 deletions common/persistence/sql/sqlplugin/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@ type (
GetAckLevels(ctx context.Context, queueType persistence.QueueType, forUpdate bool) (map[string]int64, error)
GetQueueSize(ctx context.Context, queueType persistence.QueueType) (int64, error)

// InsertConfig insert a config entry with version. Return nosqlplugin.NewConditionFailure if the same version of the row_type is existing
InsertConfig(ctx context.Context, row *persistence.InternalConfigStoreEntry) error
// SelectLatestConfig returns the config entry of the row_type with the largest(latest) version value
SelectLatestConfig(ctx context.Context, rowType int) (*persistence.InternalConfigStoreEntry, error)

// The follow provide information about the underlying sql crud implementation
SupportsTTL() bool
MaxAllowedTTL() (*time.Duration, error)
Expand Down
38 changes: 38 additions & 0 deletions common/persistence/sql/sqlplugin/mysql/configstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 Uber Technologies Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package mysql

import (
"context"
"fmt"

"github.com/uber/cadence/common/persistence"
)

func (mdb *db) InsertConfig(ctx context.Context, row *persistence.InternalConfigStoreEntry) error {
return fmt.Errorf("not implemented")
}

func (mdb *db) SelectLatestConfig(ctx context.Context, rowType int) (*persistence.InternalConfigStoreEntry, error) {
return nil, fmt.Errorf("not implemented")
}
38 changes: 38 additions & 0 deletions common/persistence/sql/sqlplugin/postgres/configstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 Uber Technologies Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package postgres

import (
"context"
"fmt"

"github.com/uber/cadence/common/persistence"
)

func (pdb *db) InsertConfig(ctx context.Context, row *persistence.InternalConfigStoreEntry) error {
return fmt.Errorf("not implemented")
}

func (pdb *db) SelectLatestConfig(ctx context.Context, rowType int) (*persistence.InternalConfigStoreEntry, error) {
return nil, fmt.Errorf("not implemented")
}

0 comments on commit d97ee5d

Please sign in to comment.