Skip to content

Commit

Permalink
feat: disabled rdb
Browse files Browse the repository at this point in the history
  • Loading branch information
xgzlucario committed Dec 1, 2024
1 parent 387ede1 commit 7c0660f
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 380 deletions.
2 changes: 1 addition & 1 deletion bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OUTPUT_FILE="output/$TEST_NAME"

COMMANDS="set,get,incr,lpush,rpush,hset,sadd,zadd"

PIPELINES=(1 10 100)
PIPELINES=(1 10 50)

mkdir -p output

Expand Down
36 changes: 18 additions & 18 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ var cmdTable = []*Command{
{"ping", pingCommand, 0, false},
{"hello", helloCommand, 0, false},
{"flushdb", flushdbCommand, 0, true},
{"load", loadCommand, 0, false},
{"save", saveCommand, 0, false},
//{"load", loadCommand, 0, false},
//{"save", saveCommand, 0, false},
}

func equalFold(a, b string) bool {
Expand Down Expand Up @@ -526,22 +526,22 @@ func helloCommand(writer *resp.Writer, _ []redcon.RESP) {
})
}

func loadCommand(writer *resp.Writer, _ []redcon.RESP) {
db.dict = New()
if err := db.rdb.LoadDB(); err != nil {
writer.WriteError(err.Error())
return
}
writer.WriteString("OK")
}

func saveCommand(writer *resp.Writer, _ []redcon.RESP) {
if err := db.rdb.SaveDB(); err != nil {
writer.WriteError(err.Error())
return
}
writer.WriteString("OK")
}
//func loadCommand(writer *resp.Writer, _ []redcon.RESP) {
// db.dict = New()
// if err := db.rdb.LoadDB(); err != nil {
// writer.WriteError(err.Error())
// return
// }
// writer.WriteString("OK")
//}
//
//func saveCommand(writer *resp.Writer, _ []redcon.RESP) {
// if err := db.rdb.SaveDB(); err != nil {
// writer.WriteError(err.Error())
// return
// }
// writer.WriteString("OK")
//}

func fetchMap(key []byte, setnx ...bool) (Map, error) {
return fetch(key, func() Map { return hash.New() }, setnx...)
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"port": 6379,
"appendonly": false,
"appendfilename": "appendonly.aof",
"save": true,
"save": false,
"savefilename": "dump.rdb"
}
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ require (
github.com/redis/go-redis/v9 v9.7.0
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
github.com/tidwall/mmap v0.3.0
github.com/tidwall/redcon v1.6.2
github.com/yuin/gopher-lua v1.1.1
github.com/zyedidia/generic v1.2.1
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/sys v0.27.0
)

require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/edsrzf/mmap-go v1.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -37,6 +34,7 @@ require (
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
golang.org/x/arch v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/aclements/go-perfevent v0.0.0-20240301234650-f7843625020f h1:JjxwchlOepwsUWcQwD2mLUAGE9aCp0/ehy6yCHFBOvo=
github.com/aclements/go-perfevent v0.0.0-20240301234650-f7843625020f/go.mod h1:tMDTce/yLLN/SK8gMOxQfnyeMeCg8KGzp0D1cbECEeo=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
Expand Down Expand Up @@ -32,9 +32,6 @@ github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80N
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
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/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/edsrzf/mmap-go v1.2.0 h1:hXLYlkbaPzt1SaQk+anYwKSRNhufIDCchSPkUD6dD84=
github.com/edsrzf/mmap-go v1.2.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
Expand Down Expand Up @@ -79,8 +76,6 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/mmap v0.3.0 h1:XXt1YsiXCF5/UAu3pLbu6g7iulJ9jsbs6vt7UpiV0sY=
github.com/tidwall/mmap v0.3.0/go.mod h1:2/dNzF5zA+te/JVHfrqNLcRkb8LjdH3c80vYHFQEZRk=
github.com/tidwall/redcon v1.6.2 h1:5qfvrrybgtO85jnhSravmkZyC0D+7WstbfCs3MmPhow=
github.com/tidwall/redcon v1.6.2/go.mod h1:p5Wbsgeyi2VSTBWOcA5vRXrOb9arFTcU2+ZzFjqV75Y=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand All @@ -91,9 +86,8 @@ github.com/zyedidia/generic v1.2.1 h1:Zv5KS/N2m0XZZiuLS82qheRG4X1o5gsWreGb0hR7XD
github.com/zyedidia/generic v1.2.1/go.mod h1:ly2RBz4mnz1yeuVbQA/VFwGjK3mnHGRj1JuoG336Bis=
golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg=
golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
23 changes: 0 additions & 23 deletions internal/hash/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hash
import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/xgzlucario/rotom/internal/resp"
"golang.org/x/exp/maps"
"testing"
)
Expand Down Expand Up @@ -51,14 +50,6 @@ func FuzzTestMap(f *testing.F) {
ast.ElementsMatch(kv1, kv2)

case 9: // Encode
if len(stdmap) == 0 {
break
}
w := resp.NewWriter()
ast.Nil(zipmap.Encode(w))
zipmap = New()
ast.Nil(zipmap.Decode(resp.NewReader(w.Buffer())))
ast.Equal(len(stdmap), zipmap.Len())
}
})
}
Expand Down Expand Up @@ -108,20 +99,6 @@ func FuzzTestSet(f *testing.F) {
ast.ElementsMatch(keys1, keys3)

case 9: // Encode
//w := resp.NewWriter(0)
//
//ast.Nil(hashset.Encode(w))
//hashset = NewSet()
//ast.Nil(hashset.Decode(resp.NewReader(w.Bytes())))
//
//w.Reset()
//ast.Nil(zipset.Encode(w))
//zipset = NewZipSet()
//ast.Nil(zipset.Decode(resp.NewReader(w.Bytes())))
//
//n := len(stdset)
//ast.Equal(n, hashset.Len())
//ast.Equal(n, zipset.Len())
}
})
}
20 changes: 0 additions & 20 deletions internal/hash/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hash
import (
mapset "github.com/deckarep/golang-set/v2"
"github.com/xgzlucario/rotom/internal/iface"
"github.com/xgzlucario/rotom/internal/resp"
)

const (
Expand Down Expand Up @@ -38,22 +37,3 @@ func (s Set) Scan(fn func(string)) {
func (s Set) Exist(key string) bool { return s.Set.ContainsOne(key) }

func (s Set) Len() int { return s.Cardinality() }

func (s Set) Encode(writer *resp.Writer) error {
writer.WriteArray(s.Len())
s.Scan(func(key string) {
writer.WriteBulkString(key)
})
return nil
}

func (s Set) Decode(reader *resp.Reader) error {
cmd, err := reader.ReadCommand()
if err != nil {
return err
}
for _, arg := range cmd.Args {
s.Add(string(arg))
}
return nil
}
4 changes: 0 additions & 4 deletions internal/hash/testdata/fuzz/FuzzTestMap/0263b28d8991ac47

This file was deleted.

4 changes: 0 additions & 4 deletions internal/hash/testdata/fuzz/FuzzTestMap/088ae9643e0ae77e

This file was deleted.

23 changes: 0 additions & 23 deletions internal/hash/zipmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/cockroachdb/swiss"
"github.com/xgzlucario/rotom/internal/iface"
"github.com/xgzlucario/rotom/internal/pool"
"github.com/xgzlucario/rotom/internal/resp"
)

const (
Expand Down Expand Up @@ -107,25 +106,3 @@ func (zm *ZipMap) Migrate() {
}

func (zm *ZipMap) Len() int { return zm.index.Len() }

func (zm *ZipMap) Encode(writer *resp.Writer) error {
writer.WriteArray(zm.Len() * 2)
zm.Scan(func(k string, v []byte) {
writer.WriteBulkString(k)
writer.WriteBulk(v)
})
return nil
}

func (zm *ZipMap) Decode(reader *resp.Reader) error {
cmd, err := reader.ReadCommand()
if err != nil {
return err
}
for i := 0; i < len(cmd.Args); i += 2 {
key := cmd.Args[i]
val := cmd.Args[i+1]
zm.Set(string(key), val)
}
return nil
}
9 changes: 0 additions & 9 deletions internal/hash/zipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hash
import (
"github.com/xgzlucario/rotom/internal/iface"
"github.com/xgzlucario/rotom/internal/list"
"github.com/xgzlucario/rotom/internal/resp"
"unsafe"
)

Expand Down Expand Up @@ -71,14 +70,6 @@ func (zs *ZipSet) ToSet() *Set {
return s
}

func (zs *ZipSet) Encode(writer *resp.Writer) error {
return zs.data.Encode(writer)
}

func (zs *ZipSet) Decode(reader *resp.Reader) error {
return zs.data.Decode(reader)
}

func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
7 changes: 0 additions & 7 deletions internal/iface/iface.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package iface

import (
"github.com/xgzlucario/rotom/internal/resp"
)

type Encoder interface {
Encode(writer *resp.Writer) error
Decode(reader *resp.Reader) error
Len() int
}

type MapI interface {
Expand Down
15 changes: 0 additions & 15 deletions internal/list/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ func FuzzTestList(f *testing.F) {
ast.ElementsMatch(keys1, keys3)

case 7: // Marshal
//if len(slice) == 0 {
// return
//}
//writer := resp.NewWriter(0)
//
//// listpack
//ast.Nil(lp.Encode(writer))
//lp = NewListPack()
//ast.Nil(lp.Decode(resp.NewReader(writer.Bytes())))
//writer.Reset()
//
//// list
//ast.Nil(ls.Encode(writer))
//ls = New()
//ast.Nil(ls.Decode(resp.NewReader(writer.Bytes())))
}
})
}
31 changes: 0 additions & 31 deletions internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package list

import (
"github.com/xgzlucario/rotom/internal/iface"
"github.com/xgzlucario/rotom/internal/resp"
"github.com/zyedidia/generic/list"
)

Expand Down Expand Up @@ -130,33 +129,3 @@ func (ls *QuickList) Range(start int, fn func(key []byte) (stop bool)) {
}
}
}

func (ls *QuickList) Encode(writer *resp.Writer) error {
num := 0
for n := ls.ls.Front; n != nil; n = n.Next {
num++
}
writer.WriteArray(num)
for n := ls.ls.Front; n != nil; n = n.Next {
if err := n.Value.Encode(writer); err != nil {
return err
}
}
return nil
}

func (ls *QuickList) Decode(reader *resp.Reader) error {
//n, err := reader.ReadCommand()
//if err != nil {
// return err
//}
//for range n {
// lp := NewListPack()
// if err = lp.Decode(reader); err != nil {
// return err
// }
// ls.ls.PushBack(lp)
// ls.size += lp.Len()
//}
return nil
}
17 changes: 0 additions & 17 deletions internal/list/listpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package list
import (
"encoding/binary"
"github.com/xgzlucario/rotom/internal/pool"
"github.com/xgzlucario/rotom/internal/resp"
"slices"
)

Expand Down Expand Up @@ -77,22 +76,6 @@ func (lp *ListPack) Iterator() *LpIterator {
return &LpIterator{ListPack: lp}
}

func (lp *ListPack) Encode(writer *resp.Writer) error {
writer.WriteInt(int(lp.size))
writer.WriteBulk(lp.data)
return nil
}

func (lp *ListPack) Decode(reader *resp.Reader) error {
//cmd, err := reader.ReadCommand()
//if err != nil {
// return err
//}
//lp.size = uint32(redcon.RESP{Data: cmd.Args[0]}.Int())
//lp.data = bytes.Clone(cmd.Args[1])
return nil
}

func (it *LpIterator) SeekLast() *LpIterator {
it.index = len(it.data)
return it
Expand Down
Loading

0 comments on commit 7c0660f

Please sign in to comment.