func openStore(cmd *cobra.Command, dir string, stopper *stop.Stopper) (*engine.RocksDB, error) { cache := engine.NewRocksDBCache(512 << 20) defer cache.Release() db := engine.NewRocksDB(roachpb.Attributes{}, dir, cache, 10<<20, 0, stopper) if err := db.Open(); err != nil { return nil, err } return db, nil }
// InitStores initializes ctx.Engines based on ctx.Stores. func (ctx *Context) InitStores(stopper *stop.Stopper) error { cache := engine.NewRocksDBCache(ctx.CacheSize) defer cache.Release() for _, spec := range ctx.Stores.Specs { var sizeInBytes = spec.SizeInBytes if spec.InMemory { if spec.SizePercent > 0 { sysMem, err := GetTotalMemory() if err != nil { return fmt.Errorf("could not retrieve system memory") } sizeInBytes = int64(float64(sysMem) * spec.SizePercent / 100) } if sizeInBytes != 0 && sizeInBytes < minimumStoreSize { return fmt.Errorf("%f%% of memory is only %s bytes, which is below the minimum requirement of %s", spec.SizePercent, humanizeutil.IBytes(sizeInBytes), humanizeutil.IBytes(minimumStoreSize)) } ctx.Engines = append(ctx.Engines, engine.NewInMem(spec.Attributes, sizeInBytes, stopper)) } else { if spec.SizePercent > 0 { fileSystemUsage := gosigar.FileSystemUsage{} if err := fileSystemUsage.Get(spec.Path); err != nil { return err } sizeInBytes = int64(float64(fileSystemUsage.Total) * spec.SizePercent / 100) } if sizeInBytes != 0 && sizeInBytes < minimumStoreSize { return fmt.Errorf("%f%% of %s's total free space is only %s bytes, which is below the minimum requirement of %s", spec.SizePercent, spec.Path, humanizeutil.IBytes(sizeInBytes), humanizeutil.IBytes(minimumStoreSize)) } ctx.Engines = append(ctx.Engines, engine.NewRocksDB(spec.Attributes, spec.Path, cache, ctx.MemtableBudget, sizeInBytes, stopper)) } } if len(ctx.Engines) == 1 { log.Infof("1 storage engine initialized") } else { log.Infof("%d storage engines initialized", len(ctx.Engines)) } return nil }
func openStore(cmd *cobra.Command, dir string, stopper *stop.Stopper) (*engine.RocksDB, error) { cache := engine.NewRocksDBCache(512 << 20) defer cache.Release() maxOpenFiles, err := server.SetOpenFileLimitForOneStore() if err != nil { return nil, err } db := engine.NewRocksDB( roachpb.Attributes{}, dir, cache, 10<<20, 0, maxOpenFiles, stopper, ) if err := db.Open(); err != nil { return nil, err } return db, nil }