Renamed memebrlist_layer directory to memberlist.

Renamed raft_layer directory to raft.
Created snapshot and aof packages to handle snapshots in standalone mode and aof package to handle append-only function.
Created server package that will contain the server logic.
This commit is contained in:
Kelvin Clement Mwinuka
2024-01-21 15:03:36 +08:00
parent 12c78a4a5a
commit 78aa9a82c6
28 changed files with 28 additions and 21 deletions

1
src/aof/aof.go Normal file
View File

@@ -0,0 +1 @@
package aof

View File

@@ -7,18 +7,18 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/kelvinmwinuka/memstore/src/command_modules/acl" ml "github.com/kelvinmwinuka/memstore/src/memberlist"
"github.com/kelvinmwinuka/memstore/src/command_modules/etc" "github.com/kelvinmwinuka/memstore/src/modules/acl"
"github.com/kelvinmwinuka/memstore/src/command_modules/get" "github.com/kelvinmwinuka/memstore/src/modules/etc"
"github.com/kelvinmwinuka/memstore/src/command_modules/hash" "github.com/kelvinmwinuka/memstore/src/modules/get"
"github.com/kelvinmwinuka/memstore/src/command_modules/list" "github.com/kelvinmwinuka/memstore/src/modules/hash"
"github.com/kelvinmwinuka/memstore/src/command_modules/ping" "github.com/kelvinmwinuka/memstore/src/modules/list"
"github.com/kelvinmwinuka/memstore/src/command_modules/pubsub" "github.com/kelvinmwinuka/memstore/src/modules/ping"
"github.com/kelvinmwinuka/memstore/src/command_modules/set" "github.com/kelvinmwinuka/memstore/src/modules/pubsub"
"github.com/kelvinmwinuka/memstore/src/command_modules/sorted_set" "github.com/kelvinmwinuka/memstore/src/modules/set"
str "github.com/kelvinmwinuka/memstore/src/command_modules/string" "github.com/kelvinmwinuka/memstore/src/modules/sorted_set"
ml "github.com/kelvinmwinuka/memstore/src/memberlist_layer" str "github.com/kelvinmwinuka/memstore/src/modules/string"
rl "github.com/kelvinmwinuka/memstore/src/raft_layer" rl "github.com/kelvinmwinuka/memstore/src/raft"
"io" "io"
"log" "log"
"net" "net"
@@ -242,6 +242,7 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
connRW.Write([]byte(fmt.Sprintf("-%s\r\n\n", err.Error()))) connRW.Write([]byte(fmt.Sprintf("-%s\r\n\n", err.Error())))
} else { } else {
connRW.Write(res) connRW.Write(res)
// TODO: Write successful, add entry to AOF
} }
connRW.Flush() connRW.Flush()
continue continue

View File

@@ -1,4 +1,4 @@
package memberlist_layer package memberlist
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,4 +1,4 @@
package memberlist_layer package memberlist
import ( import (
"context" "context"

View File

@@ -1,4 +1,4 @@
package memberlist_layer package memberlist
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,4 +1,4 @@
package memberlist_layer package memberlist
import ( import (
"context" "context"

View File

@@ -1,4 +1,4 @@
package raft_layer package raft
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,4 +1,4 @@
package raft_layer package raft
import ( import (
"context" "context"

View File

@@ -1,10 +1,10 @@
package raft_layer package raft
import ( import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/kelvinmwinuka/memstore/src/memberlist_layer" "github.com/kelvinmwinuka/memstore/src/memberlist"
"log" "log"
"net" "net"
"os" "os"
@@ -175,7 +175,7 @@ func (r *Raft) AddVoter(
return nil return nil
} }
func (r *Raft) RemoveServer(meta memberlist_layer.NodeMeta) error { func (r *Raft) RemoveServer(meta memberlist.NodeMeta) error {
if !r.IsRaftLeader() { if !r.IsRaftLeader() {
return errors.New("not leader, could not remove server") return errors.New("not leader, could not remove server")
} }

1
src/server/server.go Normal file
View File

@@ -0,0 +1 @@
package server

4
src/snapshot/snapshot.go Normal file
View File

@@ -0,0 +1,4 @@
package snapshot
// This package contains the snapshot engine for standalone mode.
// Snapshots in cluster mode will be handled using the raft package in the raft layer.