Skip to content

Commit

Permalink
Fixed a bug where switching data structures made it impossible to rea…
Browse files Browse the repository at this point in the history
…d data
  • Loading branch information
qishenonly committed Jan 25, 2024
1 parent e2250d7 commit ea5ad96
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 18 deletions.
9 changes: 9 additions & 0 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"github.com/ByteStorage/FlyDB/lib/wal"
"os"
"path/filepath"
)

// Options is a comprehensive configuration struct that
Expand Down Expand Up @@ -140,3 +141,11 @@ var DefaultDbMemoryOptions = DbMemoryOptions{
ColumnName: "default",
Wal: nil,
}

var (
RedisStringDirPath = filepath.Join(os.TempDir(), "flydb/redis/string")
RedisHashDirPath = filepath.Join(os.TempDir(), "flydb/redis/hash")
RedisListDirPath = filepath.Join(os.TempDir(), "flydb/redis/list")
RedisSetDirPath = filepath.Join(os.TempDir(), "flydb/redis/set")
RedisZSetDirPath = filepath.Join(os.TempDir(), "flydb/redis/zset")
)
6 changes: 3 additions & 3 deletions lib/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type CmdHandler func(cli *FlyDBClient, args [][]byte) (interface{}, error)

var FlyDBSupportCommands = map[string]CmdHandler{
// string
"use-string": UseString,
"set": Set,
"get": Get,
"use-str": UseString,
"set": Set,
"get": Get,

// hash
"use-hash": UseHash,
Expand Down
8 changes: 6 additions & 2 deletions lib/redis/cmd/flydb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (

func main() {
// 打开 Redis 数据结构服务
stringStructure, err := flydb_stru.NewStringStructure(config.DefaultOptions)
options := config.DefaultOptions
options.DirPath = config.RedisStringDirPath
stringStructure, err := flydb_stru.NewStringStructure(options)
if err != nil {
panic(err)
}
hashStructure, err := flydb_stru.NewHashStructure(config.DefaultOptions)

options.DirPath = config.RedisHashDirPath
hashStructure, err := flydb_stru.NewHashStructure(options)
if err != nil {
panic(err)
}
Expand Down
2 changes: 0 additions & 2 deletions lib/redis/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ func UseHash(cli *FlyDBClient, args [][]byte) (interface{}, error) {
if len(args) != 0 {
return nil, NewWrongNumberOfArgsError("use-hash")
}

cli.DB[0].(*structure.StringStructure).Close()
return redcon.SimpleString("OK"), nil
}
5 changes: 1 addition & 4 deletions lib/redis/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ func Get(cli *FlyDBClient, args [][]byte) (interface{}, error) {

func UseString(cli *FlyDBClient, args [][]byte) (interface{}, error) {
if len(args) != 0 {
return nil, NewWrongNumberOfArgsError("use-string")
return nil, NewWrongNumberOfArgsError("use-str")
}

cli.DB[1].(*structure.HashStructure).Stop()

return redcon.SimpleString("OK"), nil
}
3 changes: 1 addition & 2 deletions structure/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,7 @@ func (hs *HashStructure) findHashMeta(key string, dataType DataStructure) (*Hash
}

func (hs *HashStructure) Stop() error {
err := hs.db.Close()
return err
return hs.db.Close()
}

func (hs *HashStructure) Clean() {
Expand Down
3 changes: 1 addition & 2 deletions structure/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,7 @@ func (l *ListStructure) decodeList(value []byte) (*DecodedList, error) {
}

func (s *ListStructure) Stop() error {
err := s.db.Close()
return err
return s.db.Close()
}

func (l *ListStructure) Size(key string) (string, error) {
Expand Down
8 changes: 5 additions & 3 deletions structure/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,16 @@ func decodeStringValue(value []byte) ([]byte, int64, error) {
}

func (s *StringStructure) Stop() error {
err := s.db.Close()
return err
return s.db.Close()
}

func (s *StringStructure) Clean() {
s.db.Clean()
}

func (s *StringStructure) Close() {
s.db.Close()
err := s.db.Close()
if err != nil {
return
}
}

0 comments on commit ea5ad96

Please sign in to comment.