Skip to content
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

Remove storage cache layer (#324) #326

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 additions & 4 deletions extension/builtin/default_registry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builtin

import (
"database/sql"
"flag"

_ "github.com/go-sql-driver/mysql" // Load MySQL driver
Expand All @@ -15,19 +16,29 @@ var MySQLURIFlag = flag.String("mysql_uri", "test:zaphod@tcp(127.0.0.1:3306)/tes
"uri to use with mysql storage")

// Default implementation of extension.Registry.
type defaultRegistry struct{}
type defaultRegistry struct {
db *sql.DB
}

// TODO(codingllama): Get rid of the error return
func (r defaultRegistry) GetLogStorage(treeID int64) (storage.LogStorage, error) {
return mysql.NewLogStorage(treeID, *MySQLURIFlag)
return mysql.NewLogStorage(treeID, r.db)
}

// TODO(codingllama): Get rid of the error return
func (r defaultRegistry) GetMapStorage(treeID int64) (storage.MapStorage, error) {
return mysql.NewMapStorage(treeID, *MySQLURIFlag)
return mysql.NewMapStorage(treeID, r.db)
}

// NewDefaultExtensionRegistry returns the default extension.Registry implementation, which is
// backed by a MySQL database and configured via flags.
// The returned registry is wraped in a cached registry.
func NewDefaultExtensionRegistry() (extension.Registry, error) {
return extension.NewCachedRegistry(defaultRegistry{}), nil
db, err := mysql.OpenDB(*MySQLURIFlag)
if err != nil {
return nil, err
}
return &defaultRegistry{
db: db,
}, nil
}
72 changes: 0 additions & 72 deletions extension/cached_registry.go

This file was deleted.

129 changes: 0 additions & 129 deletions extension/cached_registry_test.go

This file was deleted.

9 changes: 5 additions & 4 deletions storage/mysql/log_admin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mysql

import (
"database/sql"
"fmt"

"github.com/google/trillian/crypto"
Expand Down Expand Up @@ -29,10 +30,10 @@ const (

// CreateTree instantiates a new log with default parameters.
// TODO(codinglama): Move to admin API when the admin API is created.
func CreateTree(treeID int64, dbURL string) error {
func CreateTree(treeID int64, db *sql.DB) error {
// TODO(codinglama) replace with a GetDatabase from the new extension API when LogID is removed.
th := merkle.NewRFC6962TreeHasher(crypto.NewSHA256())
m, err := newTreeStorage(treeID, dbURL, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
m, err := newTreeStorage(treeID, db, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
if err != nil {
return fmt.Errorf("couldn't create a new treeStorage: %s", err)
}
Expand Down Expand Up @@ -60,10 +61,10 @@ func CreateTree(treeID int64, dbURL string) error {
}

// DeleteTree deletes a tree by the treeID.
func DeleteTree(treeID int64, dbURL string) error {
func DeleteTree(treeID int64, db *sql.DB) error {
// TODO(codinglama) replace with a GetDatabase from the new extension API when LogID is removed.
th := merkle.NewRFC6962TreeHasher(crypto.NewSHA256())
m, err := newTreeStorage(treeID, dbURL, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
m, err := newTreeStorage(treeID, db, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
if err != nil {
return fmt.Errorf("couldn't create a new treeStorage: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions storage/mysql/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ type mySQLLogStorage struct {
}

// NewLogStorage creates a mySQLLogStorage instance for the specified MySQL URL.
func NewLogStorage(id int64, dbURL string) (storage.LogStorage, error) {
func NewLogStorage(id int64, db *sql.DB) (storage.LogStorage, error) {
// TODO(al): pass this through/configure from DB
th := merkle.NewRFC6962TreeHasher(crypto.NewSHA256())
ts, err := newTreeStorage(id, dbURL, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
ts, err := newTreeStorage(id, db, th.Size(), defaultLogStrata, cache.PopulateLogSubtreeNodes(th))
if err != nil {
return nil, fmt.Errorf("couldn't create a new treeStorage: %s", err)
}
Expand Down
Loading