Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions christmasdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package christmasdb

import "github.com/DevourTech/christmasdb/raft"

func Launch() {
raft.StartServer()
}
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import christmasdb "github.com/DevourTech/christmasdb"

func main() {
christmasdb.Launch()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/DevourTech/devourKV
module github.com/DevourTech/christmasdb

go 1.15

Expand Down
14 changes: 7 additions & 7 deletions internal/bplustree/bplustree.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package bplustree

import (
"github.com/DevourTech/devourKV/internal/apis"
"github.com/DevourTech/devourKV/internal/errors"
"github.com/DevourTech/christmasdb/internal/apis"
"github.com/DevourTech/christmasdb/internal/errors"
)

const (
//indexFilePath = "./db/index.db"
//recordFilePath = "./db/records.db"
//indexFilePath = "./db/index.db"
//recordFilePath = "./db/records.db"
)

// Node is the structure used to represent a BPlusTree node
Expand Down Expand Up @@ -40,8 +40,8 @@ type BPlusTree struct {
t int
}

// Construct creates a tree either from the file or an entirely new tree
func Construct(degree int) apis.Tree {
// New creates a tree either from the file or an entirely new tree
func New(degree int) apis.Tree {
// TODO: Check if an entry exists in the file for the root.
r := &Node{
keys: nil,
Expand All @@ -59,7 +59,7 @@ func (tree *BPlusTree) Search(key uint64) (interface{}, error) {
return tree.search(tree.root, key)
}

// search searches for key in node x
// search looks for key in node x
func (tree *BPlusTree) search(x *Node, key uint64) (interface{}, error) {
if !x.leaf {
i := 0
Expand Down
12 changes: 12 additions & 0 deletions internal/bplustree/bplustree_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
package bplustree

import (
"fmt"
"reflect"
"testing"
)

func TestNew(t *testing.T) {
n := Node{}
typ := reflect.TypeOf(n)
fmt.Println(typ.Size())
}
1 change: 0 additions & 1 deletion internal/btree/btree.go

This file was deleted.

1 change: 1 addition & 0 deletions internal/skiplist/skiplist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package skiplist
16 changes: 16 additions & 0 deletions raft/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package raft

import (
"fmt"
"time"
)

func StartServer() {
et := NewTimer()
go et.WaitTillElection()

// TODO: Use wait group maybe
time.Sleep(10 * time.Second)
et.Stop()
fmt.Println("some timer impl")
}
44 changes: 44 additions & 0 deletions raft/timer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package raft

import (
"fmt"
"time"
)

type Timer interface {
WaitTillElection()
Stop()
}

func NewTimer() Timer {
return &electionTimer{
ticker: time.NewTicker(getRandomTimeout()),
done: make(chan bool),
}
}

type electionTimer struct {
ticker *time.Ticker
done chan bool
}

func (et *electionTimer) WaitTillElection() {
for {
select {
case <-et.done:
return
case t := <-et.ticker.C:
fmt.Println("Ticked at ", t)
// TODO: Invoke the TCP Client to send heartbeat to all other servers
}
}
}

func (et *electionTimer) Stop() {
et.done <- true
}

// TODO: Make this randomized
func getRandomTimeout() time.Duration {
return time.Second * 3
}