Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this SDK to read the rocksdb sst files and import them to redis? #168

Open
GpsLypy opened this issue Nov 20, 2024 · 1 comment

Comments

@GpsLypy
Copy link

GpsLypy commented Nov 20, 2024

`
const (
cFNameDefault = "default"
//cFNameTest = "test"
DB_PATH = "./backup"
timestampSize = 8
)

func OpenDB() (*grocksdb.DB, error) {
opts := grocksdb.NewDefaultOptions()
opts.SetCreateIfMissing(true)
db, err := grocksdb.OpenDbForReadOnly(opts, DB_PATH, true)
if err != nil {
log.Fatalln("OPEN DB error", db, err)
db.Close()
return nil, errors.New("fail to open db")
} else {
log.Println("OPEN DB success", db)
}
return db, nil
}

func main() {
logrus.Info("rocksdb test begin")
db, err := OpenDB()
if err != nil {
log.Println("fail to open db,", nil, db)
}

ro := grocksdb.NewDefaultReadOptions()
ro.SetFillCache(false)

it := db.NewIterator(ro)
defer it.Close()
for it.SeekToFirst(); it.Valid(); it.Next() {
	logrus.Info("table_db item name:", string((it.Key().Data())))
	key := it.Key()
	value := it.Value()
	fmt.Printf("Key: %v Value: %v\n", key.Data(), value.Data())
	key.Free()
	value.Free()
}
if err := it.Err(); err != nil {
	log.Fatalln("Seek DB error", db, err)
	db.Close()
}

}
`

@linxGnu
Copy link
Owner

linxGnu commented Nov 28, 2024

Hi @GpsLypy

Regarding https://github.com/linxGnu/grocksdb/blob/master/c.h (exposed by RocksDB):

  • No API to Read SST Files directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants