Skip to content

Commit 66a0375

Browse files
committed
Some small refactoring
1 parent 12cfee3 commit 66a0375

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

cmd/kvgod/grpc_server/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import (
88
)
99

1010
const (
11-
port = ":50051"
11+
port = ":50051"
12+
raftAddr = ":12000"
1213
)
1314

1415
func main() {
1516
log.Info("Creating storage...")
1617
dbPath := filepath.Join(".", "data.db")
1718
indexPath := filepath.Join(".", "indexes.idx")
19+
raftDir := filepath.Join(".", "raft")
1820

19-
store := server.NewStore(dbPath, indexPath, 4, 100)
21+
store := server.NewStore(dbPath, indexPath, 4, 100, raftDir, raftAddr)
2022
log.Info("Storage was succesfully created")
2123

2224
server.ListenAndServGrpc(":50051", store)

cmd/kvgod/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ func main() {
4343

4444
log.Info("Creating storage...")
4545
store := server.NewStore(
46-
filepath.Join(*raftDir, dbPath), filepath.Join(*raftDir, indexPath), 1000, 10000,
46+
filepath.Join(*raftDir, dbPath), filepath.Join(*raftDir, indexPath), 1000, 10000, *raftDir, *raftAddr,
4747
)
48-
store.RaftDir = *raftDir
49-
store.RaftBind = *raftAddr
5048

5149
if err := store.Open(*joinAddr == "", *nodeID); err != nil {
5250
log.Fatalf("failed to open store: %s", err.Error())

pkg/server/grpc_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
func TestGRPCServerBasic(t *testing.T) {
1717
port := ":50051"
18+
raftAddr := ":12000"
1819
address := "localhost" + port
1920

2021
tmpDir, _ := ioutil.TempDir("", "kvgo_grpc_tests")
@@ -25,9 +26,7 @@ func TestGRPCServerBasic(t *testing.T) {
2526
raftDir := filepath.Join(".", "raft")
2627

2728
log.Info("Creating storage...")
28-
store := NewStore(dbPath, indexPath, 1000, 10000)
29-
store.RaftDir = raftDir
30-
store.RaftBind = ":12000"
29+
store := NewStore(dbPath, indexPath, 1000, 10000, raftDir, raftAddr)
3130

3231
if err := store.Open(true, "node1"); err != nil {
3332
log.Fatalf("failed to open store: %s", err.Error())

pkg/server/server_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
func TestServerBasic(t *testing.T) {
1515
port := ":56379"
16+
raftAddr := ":12001"
1617
tmpDir, _ := ioutil.TempDir("", "kvgo_tests")
1718
defer os.RemoveAll(tmpDir)
1819

@@ -21,9 +22,7 @@ func TestServerBasic(t *testing.T) {
2122
raftDir := filepath.Join(tmpDir, "raft")
2223

2324
log.Info("Creating storage...")
24-
store := NewStore(dbPath, indexPath, 1000, 10000)
25-
store.RaftDir = raftDir
26-
store.RaftBind = ":12001"
25+
store := NewStore(dbPath, indexPath, 1000, 10000, raftDir, raftAddr)
2726

2827
if err := store.Open(true, "node1"); err != nil {
2928
log.Fatalf("failed to open store: %s", err.Error())

pkg/server/store.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ type command struct {
3535
Value string `json:"value,omitempty"`
3636
}
3737

38-
func NewStore(dbPath, indexPath string, blockSize uint32, maxBlockNumber int16) *Store {
38+
func NewStore(dbPath, indexPath string, blockSize uint32, maxBlockNumber int16, RaftDir, RaftBind string) *Store {
3939
store := new(Store)
4040
store.KV = kv.NewKV(dbPath, indexPath, blockSize, maxBlockNumber)
4141

42+
store.RaftDir = RaftDir
43+
store.RaftBind = RaftBind
44+
4245
return store
4346
}
4447

0 commit comments

Comments
 (0)