From c8e19a90d0e1c399f6d8a8bb05399a6f0050b6f1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 24 Mar 2012 23:53:35 -0700 Subject: [PATCH] mysqlindexer: connect; ping Change-Id: Ic9a8422dc10c8514a4f10a14a878c5729068d56f --- pkg/mysqlindexer/mysqlindexer.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/mysqlindexer/mysqlindexer.go b/pkg/mysqlindexer/mysqlindexer.go index c0bdeb6e6..88d2ad4ac 100644 --- a/pkg/mysqlindexer/mysqlindexer.go +++ b/pkg/mysqlindexer/mysqlindexer.go @@ -72,12 +72,16 @@ func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Stor if err := config.Validate(); err != nil { return nil, err } - - // TODO: connect; set is.db - // TODO: ping it; see if it's alive; else return err + db, err := sql.Open("mymysql", is.database + "/" + is.user + "/" + is.password) + if err != nil { + return nil, err + } + is.db = db + if err := is.ping(); err != nil { + return nil, err + } indexer := index.New(is) - version, err := is.SchemaVersion() if err != nil { return nil, fmt.Errorf("error getting schema version (need to init database?): %v", err) @@ -99,10 +103,10 @@ func init() { blobserver.RegisterStorageConstructor("mysqlindexer", blobserver.StorageConstructor(newFromConfig)) } -func (mi *myIndexStorage) IsAlive() (ok bool, err error) { +func (mi *myIndexStorage) ping() error { // TODO(bradfitz): something more efficient here? - _, err = mi.SchemaVersion() - return err == nil, err + _, err := mi.SchemaVersion() + return err } func (mi *myIndexStorage) SchemaVersion() (version int, err error) {