Skip to content

Commit

Permalink
Merge pull request #198 from ByteStorage/temp
Browse files Browse the repository at this point in the history
feat: cli add clean/stop method
  • Loading branch information
sjcsjc123 authored Jul 11, 2023
2 parents e1d4f43 + 2439f0c commit d97e642
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
6 changes: 2 additions & 4 deletions cmd/server/cli/flydb-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

func main() {
args := os.Args
if len(args) >= 2 {
fmt.Println("Usage: flydb-server [start|clean|stop]")
if len(args) > 2 {
fmt.Println("Usage: flydb-server [start|clean]")
return
}
if len(args) == 1 {
Expand All @@ -20,8 +20,6 @@ func main() {
switch args[1] {
case "start":
server.StartServer()
case "stop":
server.StopServer()
case "clean":
server.CleanServer()
}
Expand Down
17 changes: 10 additions & 7 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ import (
"github.com/ByteStorage/FlyDB/config"
"github.com/ByteStorage/FlyDB/engine/grpc/service"
"github.com/ByteStorage/FlyDB/structure"
"os"
)

var s *service.Service

func StartServer() {
options := config.DefaultOptions
db, err := structure.NewStringStructure(options)
str, err := structure.NewStringStructure(options)
if err != nil {
fmt.Println("flydb start error: ", err)
return
}
s := service.NewService(config.DefaultAddr, db)
s = service.NewService(config.DefaultAddr, str)
s.StartServer()
}

func StopServer() {
panic("implement me")
}

func CleanServer() {
panic("implement me")
err := os.Remove(config.DefaultOptions.DirPath)
if err != nil {
fmt.Println("flydb clean error: ", err)
return
}
}
7 changes: 7 additions & 0 deletions engine/grpc/service/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func (s *Service) StartServer() {
signal.Notify(s.sig, syscall.SIGINT, syscall.SIGKILL)

<-s.sig
err = s.db.Stop()
if err != nil {
fmt.Println("flydb stop error: ", err)
return
}
fmt.Println("flydb stop success on ", s.Addr)

}

// StopServer stops a grpc server
Expand Down
9 changes: 9 additions & 0 deletions structure/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,12 @@ func decodeStringValue(value []byte) ([]byte, error) {
// Return the original value value
return value[bufIndex:], nil
}

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

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

0 comments on commit d97e642

Please sign in to comment.