Skip to content

[sql-41] firewalldb: add migration code for kvstores from kvdb to SQL #1079

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
36 changes: 36 additions & 0 deletions db/sqlc/kvstores.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions db/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions db/sqlc/queries/kvstores.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ VALUES ($1, $2, $3, $4, $5, $6);
DELETE FROM kvstores
WHERE perm = false;

-- name: ListAllKVStoresRecords :many
SELECT *
FROM kvstores;

-- name: GetGlobalKVStoreRecord :one
SELECT value
FROM kvstores
Expand Down
13 changes: 3 additions & 10 deletions firewalldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@ var (
ErrNoSuchKeyFound = fmt.Errorf("no such key found")
)

// firewallDBs is an interface that groups the RulesDB and PrivacyMapper
// interfaces.
type firewallDBs interface {
RulesDB
PrivacyMapper
}

// DB manages the firewall rules database.
type DB struct {
started sync.Once
stopped sync.Once

firewallDBs
FirewallDBs

cancel fn.Option[context.CancelFunc]
}

// NewDB creates a new firewall database. For now, it only contains the
// underlying rules' and privacy mapper databases.
func NewDB(dbs firewallDBs) *DB {
func NewDB(dbs FirewallDBs) *DB {
return &DB{
firewallDBs: dbs,
FirewallDBs: dbs,
}
}

Expand Down
7 changes: 7 additions & 0 deletions firewalldb/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,10 @@ type ActionDB interface {
// and feature name.
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
}

// FirewallDBs is an interface that groups the RulesDB and PrivacyMapper
// interfaces.
type FirewallDBs interface {
RulesDB
PrivacyMapper
}
12 changes: 6 additions & 6 deletions firewalldb/kvstores_kvdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ the temporary store changes instead of just keeping an in-memory store is that
we can then guarantee atomicity if changes are made to both the permanent and
temporary stores.

rules -> perm -> rule-name -> global -> {k:v}
-> sessions -> group ID -> session-kv-store -> {k:v}
-> feature-kv-stores -> feature-name -> {k:v}
"rules" -> "perm" -> rule-name -> "global" -> {k:v}
"session-kv-store" -> group ID -> {k:v}
-> "feature-kv-stores" -> feature-name -> {k:v}

-> temp -> rule-name -> global -> {k:v}
-> sessions -> group ID -> session-kv-store -> {k:v}
-> feature-kv-stores -> feature-name -> {k:v}
-> "temp" -> rule-name -> "global" -> {k:v}
"session-kv-store" -> group ID -> {k:v}
-> "feature-kv-stores" -> feature-name -> {k:v}
*/

var (
Expand Down
Loading
Loading