func NewTempDirRocksDB() (*RocksDB, func(), error) {
	dir, err := ioutil.TempDir("", "kvdb-test-rocksdb")
	cleanup := func() {
		rmErr := os.RemoveAll(dir)
		if rmErr != nil {
			panic(rmErr)
		}
	}
	if err != nil {
		return nil, cleanup, err
	}
	rdb, err := NewRocksDB(dir)
	return rdb, cleanup, err
}
NewTempDirRocksDB creates a new RocksDB instance (used mostly for local testing) in a local
temporary directory.
package db
import (
	"encoding/hex"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"sync"
	errors2 "github.com/drausin/libri/libri/common/errors"
	"github.com/tecbot/gorocksdb"
)
type KVDB interface {
	Get(key []byte) ([]byte, error)
	Put(key []byte, value []byte) error
	Delete(key []byte) error
	Iterate(keyLB, keyUB []byte, done chan struct{}, callback func(key, value []byte)) error
	Close()
}
type RocksDB struct {
	rdb *gorocksdb.DB
	ro *gorocksdb.ReadOptions
	wo *gorocksdb.WriteOptions
}
func NewRocksDB(dbDir string) (*RocksDB, error) {
	err := os.MkdirAll(dbDir, os.ModePerm)
	if err != nil {
		return nil, err
	}
	options := newRocksDBOptimizedOptions()
	db, err := gorocksdb.OpenDb(options, dbDir)
	if err != nil {
		return nil, err
	}
	return &RocksDB{
		rdb: db,
		ro:  gorocksdb.NewDefaultReadOptions(),
		wo:  gorocksdb.NewDefaultWriteOptions(),
	}, nil
}
func newRocksDBDefaultOptions() *gorocksdb.Options {
	opts := gorocksdb.NewDefaultOptions()
	opts.SetCreateIfMissing(true)
	return opts
}
func newRocksDBOptimizedOptions() *gorocksdb.Options {
	opts := newRocksDBDefaultOptions()
	opts.IncreaseParallelism(4)
	bbtOpts := gorocksdb.NewDefaultBlockBasedTableOptions()
	bbtOpts.SetBlockCache(gorocksdb.NewLRUCache(1024 * 1024 * 1024))  
	bbtOpts.SetBlockSize(32 * 1024)                                   
	bbtOpts.SetFilterPolicy(gorocksdb.NewBloomFilter(10))
	opts.SetBlockBasedTableFactory(bbtOpts)
	opts.SetAllowConcurrentMemtableWrites(true)
	opts.OptimizeLevelStyleCompaction(500 * 1024 * 1024)  
	opts.SetStatsDumpPeriodSec(10 * 60)
	return opts
}