Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Storage Factory #1558

Merged
merged 8 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/keytransparency-sequencer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ var (
lockDir = flag.String("lock_file_path", "/keytransparency/master", "etcd lock file directory path")

dbPath = flag.String("db", "", "Database connection string")
dbEngine = flag.String("db_engine", "mysql", "Storage implementation. One of ['mysql', 'spanner']")

dbEngine = flag.String("db_engine", "mysql", fmt.Sprintf("Storage engines: %v", impl.StorageEngines()))
// Info to connect to the trillian map and log.
mapURL = flag.String("map-url", "", "URL of Trillian Map Server")
logURL = flag.String("log-url", "", "URL of Trillian Log Server for Signed Map Heads")
Expand Down Expand Up @@ -141,7 +140,8 @@ func main() {
trillian.NewTrillianLogClient(lconn),
trillian.NewTrillianMapClient(mconn),
trillian.NewTrillianMapWriteClient(mconn),
db.Batches, db.Logs,
db.Batches,
db.Logs,
spb.NewKeyTransparencySequencerClient(conn),
prometheus.MetricFactory{}))

Expand Down
3 changes: 2 additions & 1 deletion cmd/keytransparency-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"context"
"flag"
"fmt"

"github.com/golang/glog"
"github.com/google/trillian"
Expand Down Expand Up @@ -44,7 +45,7 @@ var (
addr = flag.String("addr", ":8080", "The ip:port combination to listen on")
metricsAddr = flag.String("metrics-addr", ":8081", "The ip:port to publish metrics on")
dbPath = flag.String("db", "test:zaphod@tcp(localhost:3306)/test", "Database connection string")
dbEngine = flag.String("db_engine", "mysql", "Storage implementation. One of ['mysql', 'spanner']")
dbEngine = flag.String("db_engine", "mysql", fmt.Sprintf("Storage engines: %v", impl.StorageEngines()))
keyFile = flag.String("tls-key", "genfiles/server.key", "TLS private key file")
certFile = flag.String("tls-cert", "genfiles/server.crt", "TLS cert file")
authType = flag.String("auth-type", "google", "Sets the type of authentication required from clients to update their entries. Accepted values are google (oauth tokens) and insecure-fake (for testing only).")
Expand Down
2 changes: 1 addition & 1 deletion impl/mysql/dberrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package sql
package mysql

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion impl/mysql/dberrors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package sql
package mysql

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion impl/mysql/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// Package sql provides functions for interacting with MySQL.
gdbelvin marked this conversation as resolved.
Show resolved Hide resolved
package sql
package mysql

import (
"database/sql"
Expand Down
31 changes: 17 additions & 14 deletions impl/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ import (
"fmt"

"cloud.google.com/go/spanner"
"github.com/google/keytransparency/core/directory"
"github.com/google/keytransparency/core/sequencer"
"github.com/google/keytransparency/core/water"
"github.com/google/keytransparency/impl/mysql/mutationstorage"
"github.com/google/keytransparency/impl/spanner/batch"
"github.com/google/keytransparency/impl/spanner/directory"
"github.com/google/keytransparency/impl/spanner/mutations"
"github.com/google/keytransparency/impl/mysql"

pb "github.com/google/keytransparency/core/api/v1/keytransparency_go_proto"
dinterface "github.com/google/keytransparency/core/directory"
ktsql "github.com/google/keytransparency/impl/mysql"
sqld "github.com/google/keytransparency/impl/mysql/directory"
mysqldir "github.com/google/keytransparency/impl/mysql/directory"
mysqlmutations "github.com/google/keytransparency/impl/mysql/mutationstorage"
spanbatch "github.com/google/keytransparency/impl/spanner/batch"
spandir "github.com/google/keytransparency/impl/spanner/directory"
spanmutations "github.com/google/keytransparency/impl/spanner/mutations"
)

// Storage holds an abstract storage implementation
type Storage struct {
Directories dinterface.Storage
Directories directory.Storage
Logs interface {
sequencer.LogsReader

Expand All @@ -56,6 +56,9 @@ type Storage struct {
// HealthCheck reports on the health of the underlying database connection.
func (s *Storage) HealthCheck() error { return s.healthCheck() }

// StorageEngines returns a list of supported storage engines.
func StorageEngines() []string { return []string{"mysql", "spanner"} }

// NewStorage returns a Storage with the requested engine.
func NewStorage(ctx context.Context, engine, db string) (*Storage, error) {
switch engine {
Expand All @@ -74,25 +77,25 @@ func spannerStorage(ctx context.Context, db string) (*Storage, error) {
return nil, err
}
return &Storage{
Directories: directory.New(spanClient),
Batches: batch.New(spanClient),
Logs: mutations.New(spanClient),
Directories: spandir.New(spanClient),
Batches: spanbatch.New(spanClient),
Logs: spanmutations.New(spanClient),
healthCheck: func() error { return nil },
Close: spanClient.Close,
}, nil
}

func mysqlStorage(db string) (*Storage, error) {
sqldb, err := ktsql.Open(db)
sqldb, err := mysql.Open(db)
if err != nil {
return nil, err
}
directories, err := sqld.NewStorage(sqldb)
directories, err := mysqldir.NewStorage(sqldb)
if err != nil {
sqldb.Close()
return nil, fmt.Errorf("failed to create directory storage: %w", err)
}
logs, err := mutationstorage.New(sqldb)
logs, err := mysqlmutations.New(sqldb)
if err != nil {
sqldb.Close()
return nil, fmt.Errorf("failed to create mutations storage: %w", err)
Expand Down