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

[feature] 1: custom fs, 2: custom lock. 3: use DB interface #310

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 5 additions & 4 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package rosedb
import (
"bytes"
"fmt"
"github.com/rosedblabs/rosedb/v2/utils"
"sync"
"time"

"github.com/rosedblabs/rosedb/v2/utils"

"github.com/bwmarrin/snowflake"
"github.com/valyala/bytebufferpool"
)
Expand All @@ -23,7 +24,7 @@ import (
//
// You must call Commit method to commit the batch, otherwise the DB will be locked.
type Batch struct {
db *DB
db *rose
pendingWrites []*LogRecord // save the data to be written
pendingWritesMap map[uint64][]int // map record hash key to index, fast lookup to pendingWrites
options BatchOptions
Expand All @@ -35,7 +36,7 @@ type Batch struct {
}

// NewBatch creates a new Batch instance.
func (db *DB) NewBatch(options BatchOptions) *Batch {
func (db *rose) NewBatch(options BatchOptions) *Batch {
batch := &Batch{
db: db,
options: options,
Expand Down Expand Up @@ -68,7 +69,7 @@ func newRecord() interface{} {
return &LogRecord{}
}

func (b *Batch) init(rdonly, sync bool, db *DB) *Batch {
func (b *Batch) init(rdonly, sync bool, db *rose) *Batch {
b.options.ReadOnly = rdonly
b.options.Sync = sync
b.db = db
Expand Down
11 changes: 5 additions & 6 deletions batch_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package rosedb

import (
"os"
"testing"

"github.com/rosedblabs/rosedb/v2/utils"
"github.com/stretchr/testify/assert"
)

func destroyDB(db *DB) {
func destroyDB(db DB) {
_ = db.Close()
_ = os.RemoveAll(db.options.DirPath)
_ = os.RemoveAll(mergeDirPath(db.options.DirPath))
_ = db.Fs().RemoveAll(db.(*rose).options.DirPath)
_ = db.Fs().RemoveAll(mergeDirPath(db.(*rose).options.DirPath))
}

func TestBatch_Put_Normal(t *testing.T) {
Expand Down Expand Up @@ -140,7 +139,7 @@ func TestBatch_Exist_Normal(t *testing.T) {
assertKeyExistOrNot(t, db2, utils.GetTestKey(99), true)
}

func generateData(t *testing.T, db *DB, start, end int, valueLen int) {
func generateData(t *testing.T, db DB, start, end int, valueLen int) {
for ; start < end; start++ {
err := db.Put(utils.GetTestKey(start), utils.RandomValue(valueLen))
assert.Nil(t, err)
Expand Down Expand Up @@ -183,7 +182,7 @@ func batchPutAndIterate(t *testing.T, segmentSize int64, size int, valueLen int)
}
}

func assertKeyExistOrNot(t *testing.T, db *DB, key []byte, exist bool) {
func assertKeyExistOrNot(t *testing.T, db DB, key []byte, exist bool) {
val, err := db.Get(key)
if exist {
assert.Nil(t, err)
Expand Down
5 changes: 2 additions & 3 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package benchmark
import (
"errors"
"math/rand"
"os"
"testing"

"github.com/rosedblabs/rosedb/v2"
"github.com/rosedblabs/rosedb/v2/utils"
"github.com/stretchr/testify/assert"
)

var db *rosedb.DB
var db rosedb.DB

func openDB() func() {
options := rosedb.DefaultOptions
Expand All @@ -25,7 +24,7 @@ func openDB() func() {

return func() {
_ = db.Close()
_ = os.RemoveAll(options.DirPath)
_ = options.Fs.RemoveAll(options.DirPath)
}
}

Expand Down
Loading