Skip to content

Commit

Permalink
feat: allow full control on rocksdb db opening (cosmos#104)
Browse files Browse the repository at this point in the history
* feat: allow full control on rocksdb db opening

* Update prefixdb_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and mmsqe committed Sep 25, 2024
1 parent 8a5e4f5 commit daf0472
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## UNRELEASED

* Allow full control in rocksdb opening

## [v1.0.0] - 2023-05-25

> Note this repository was forked from [github.com/tendermint/tm-db](https://github.com/tendermint/tm-db). Minor modifications were made after the fork to better support the Cosmos SDK. Notably, this repo removes badger, boltdb and cleveldb.
Expand Down
7 changes: 5 additions & 2 deletions prefixdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package db

import (
"bytes"
"crypto/rand"
"encoding/binary"
"fmt"
"math/rand"
"path/filepath"
"sync"
"testing"
Expand Down Expand Up @@ -32,7 +32,10 @@ func taskKey(i, k int) []byte {

func randomValue() []byte {
b := make([]byte, 16)
rand.Read(b) //nolint:gosec
_, err := rand.Read(b)
if err != nil {
panic(fmt.Sprintf("random value generation failed: %v", err))
}
return b
}

Expand Down
12 changes: 11 additions & 1 deletion rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ func NewRocksDBWithOptions(name string, dir string, opts *grocksdb.Options) (*Ro
wo := grocksdb.NewDefaultWriteOptions()
woSync := grocksdb.NewDefaultWriteOptions()
woSync.SetSync(true)
return NewRocksDBWithRaw(db, ro, wo, woSync), nil
return NewRocksDBWithRawDB(db, ro, wo, woSync), nil
}

// NewRocksDBWithRawDB lets caller has full control on how the db instance is constructed
func NewRocksDBWithRawDB(
db *grocksdb.DB,
ro *grocksdb.ReadOptions,
wo *grocksdb.WriteOptions,
woSync *grocksdb.WriteOptions,
) *RocksDB {
return NewRocksDBWithRaw(db, ro, wo, woSync)
}

// NewRocksDBWithRaw is useful if user want to create the db in read-only or seconday-standby mode,
Expand Down

0 comments on commit daf0472

Please sign in to comment.