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

feat: allow full control on rocksdb db opening #104

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing to enhance clarity and correct the spelling mistake.

- * Allow full control in rocksdb opening
+ * Allow full control over RocksDB opening

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* Allow full control in rocksdb opening
* Allow full control over RocksDB opening


## [v1.0.2] - 2024-02-26

* Downgrade Go version in go.mod to 1.19
yihuang marked this conversation as resolved.
Show resolved Hide resolved
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:staticcheck,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
Loading