Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maurodelazeri committed Jan 6, 2023
1 parent b428bbd commit 50ceb50
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/golang/snappy v0.0.4
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.19.0
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
Expand Down Expand Up @@ -37,11 +43,13 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
10 changes: 10 additions & 0 deletions leveldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sync/atomic"
"time"

"github.com/go-redis/redis/v8"
"github.com/maurodelazeri/goleveldb/leveldb/cache"
"github.com/maurodelazeri/goleveldb/leveldb/errors"
"github.com/maurodelazeri/goleveldb/leveldb/iterator"
Expand Down Expand Up @@ -89,6 +90,8 @@ type DB struct {
closeC chan struct{}
closed uint32
closer io.Closer

rdb *redis.Client
}

func openDB(s *session) (*DB, error) {
Expand Down Expand Up @@ -159,6 +162,13 @@ func openDB(s *session) (*DB, error) {
// go db.jWriter()
}

rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
db.rdb = rdb

s.logf("db@open done T·%v", time.Since(start))

runtime.SetFinalizer(db, (*DB).Close)
Expand Down
17 changes: 10 additions & 7 deletions leveldb/db_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func (db *DB) unlockWrite(overflow bool, merged int, err error) {

// ourBatch is batch that we can modify.
func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
s := fmt.Sprintf("leveldb writeLocked batch len %v merge %v sync %v.\n", batch.Len(), merge, sync)
fmt.Println(s)
//s := fmt.Sprintf("leveldb writeLocked batch len %v merge %v sync %v.\n", batch.Len(), merge, sync)
//fmt.Println(s)

// Try to flush memdb. This method would also trying to throttle writes
// if it is too fast and compaction cannot catch-up.
Expand Down Expand Up @@ -238,10 +238,10 @@ func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
}

// Put batches.
for _, batch := range batches {
s := fmt.Sprintf("leveldb memory batch %v %v", seq, string(batch.data))
fmt.Println(s)
}
// for index, batch := range batches {
// s := fmt.Sprintf("leveldb memory batch keyType %v keyPos %v keyLen %v valueLen %v valuePos %v", batch.index[index].keyType.String(), batch.index[index].keyPos, batch.index[index].keyLen, batch.index[index].valueLen, batch.index[index].valuePos, batch.index[index].v())
// fmt.Println(s)
// }

// Put batches.
for _, batch := range batches {
Expand Down Expand Up @@ -274,7 +274,7 @@ func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
// It is safe to modify the contents of the arguments after Write returns but
// not before. Write will not modify content of the batch.
func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
s := fmt.Sprintf("leveldb WriteEEEEEEEEEEEEEEEE len %v %v", batch.Len(), string(batch.data))
s := fmt.Sprintf("leveldb WriteEEEEEEEEEEEEEEEE len %v dump %v data %v", batch.Dump(), batch.Len(), string(batch.data))
fmt.Println(s)

if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
Expand Down Expand Up @@ -336,6 +336,9 @@ func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
func (db *DB) putRec(kt keyType, key, value []byte, wo *opt.WriteOptions) error {
//fmt.Println("leveldb putRec", kt.String(), string(key), string(value))

s := fmt.Sprintf("leveldb putRec keyType %v key %v value %v.\n", kt.String(), string(key), string(value))
fmt.Println(s)

if err := db.ok(); err != nil {
return err
}
Expand Down

0 comments on commit 50ceb50

Please sign in to comment.