func (self *ShardDatastore) GetOrCreateShard(id uint32) (cluster.LocalShardDb, error) { now := time.Now() self.shardsLock.Lock() defer self.shardsLock.Unlock() db := self.shards[id] self.lastAccess[id] = now if db != nil { self.incrementShardRefCountAndCloseOldestIfNeeded(id) return db, nil } dbDir := self.shardDir(id) log.Info("DATASTORE: opening or creating shard %s", dbDir) engine, err := self.getEngine(dbDir) if err != nil { return nil, err } init, err := storage.GetInitializer(engine) if err != nil { log.Error("Error opening shard: ", err) return nil, err } c := init.NewConfig() conf, ok := self.config.StorageEngineConfigs[engine] if err := toml.PrimitiveDecode(conf, c); ok && err != nil { return nil, err } // TODO: this is for backward compatability with the old // configuration if leveldbConfig, ok := c.(*storage.LevelDbConfiguration); ok { if leveldbConfig.LruCacheSize == 0 { leveldbConfig.LruCacheSize = configuration.Size(self.config.LevelDbLruCacheSize) } if leveldbConfig.MaxOpenFiles == 0 { leveldbConfig.MaxOpenFiles = self.config.LevelDbMaxOpenFiles } } se, err := init.Initialize(dbDir, c) if err != nil { os.RemoveAll(dbDir) return nil, err } db, err = NewShard(se, self.pointBatchSize, self.writeBatchSize, self.metaStore) if err != nil { log.Error("Error creating shard: ", err) se.Close() return nil, err } self.shards[id] = db self.incrementShardRefCountAndCloseOldestIfNeeded(id) return db, nil }
func benchmark(name string, c Config) { init, err := storage.GetInitializer(name) if err != nil { panic(err) } conf := init.NewConfig() db, err := init.Initialize(fmt.Sprintf("%s/test-%s", c.path, name), conf) defer db.Close() benchmarkDbCommon(db, c) }