Ejemplo n.º 1
0
func newSorted(t *testing.T) (kv sorted.KeyValue, clean func()) {
	skipOrFailIfNoMySQL(t)
	dbname := "camlitest_" + osutil.Username()
	do(rootdb, "DROP DATABASE IF EXISTS "+dbname)
	do(rootdb, "CREATE DATABASE "+dbname)

	db, err := sql.Open("mymysql", dbname+"/root/root")
	if err != nil {
		t.Fatalf("opening test database: " + err.Error())
	}
	for _, tableSql := range mysql.SQLCreateTables() {
		do(db, tableSql)
	}
	do(db, fmt.Sprintf(`REPLACE INTO meta VALUES ('version', '%d')`, mysql.SchemaVersion()))

	kv, err = mysql.NewKeyValue(mysql.Config{
		Database: dbname,
		User:     "******",
		Password: "******",
	})
	if err != nil {
		t.Fatal(err)
	}
	return kv, func() {
		kv.Close()
	}
}
Ejemplo n.º 2
0
func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
	blobPrefix := config.RequiredString("blobSource")
	mysqlConf, err := mysql.ConfigFromJSON(config)
	if err != nil {
		return nil, err
	}
	kv, err := mysql.NewKeyValue(mysqlConf)
	if err != nil {
		return nil, err
	}

	ix, err := index.New(kv)
	if err != nil {
		return nil, err
	}

	sto, err := ld.GetStorage(blobPrefix)
	if err != nil {
		ix.Close()
		return nil, err
	}
	ix.BlobSource = sto
	// Good enough, for now:
	ix.KeyFetcher = ix.BlobSource

	return ix, nil
}