more work done

This commit is contained in:
ston1th 2021-03-06 16:51:36 +01:00
commit 6fda229a8e
23 changed files with 384 additions and 177 deletions

View file

@ -3,7 +3,7 @@ package raft
import (
"errors"
"git.giftfish.de/ston1th/vipman/pkg/cluster"
"git.giftfish.de/ston1th/haproxy-lb/pkg/cluster"
"github.com/go-logr/logr"
"github.com/hashicorp/raft"
)

View file

@ -2,13 +2,18 @@ package raft
import (
"errors"
"strings"
"sync"
"git.giftfish.de/ston1th/raftbbolt/msgpack"
"github.com/hashicorp/raft"
)
var ErrNotLeader = errors.New("not leader")
var (
ErrNotLeader = errors.New("raft: not leader")
ErrKeyNotFound = errors.New("raft: key not found")
ErrPrefixNotFound = errors.New("raft: prefix not found")
)
type kvm map[string][]byte
@ -21,7 +26,11 @@ type kv struct {
func (kv *kv) Get(k string) ([]byte, error) {
kv.mu.Lock()
defer kv.mu.Unlock()
return kv.m[k], nil
v, ok := kv.m[k]
if !ok {
return nil, ErrKeyNotFound
}
return v, nil
}
func (kv *kv) GetPrefix(pk string) (m map[string][]byte, err error) {
@ -33,6 +42,9 @@ func (kv *kv) GetPrefix(pk string) (m map[string][]byte, err error) {
m[k] = v
}
}
if len(m) == 0 {
err = ErrPrefixNotFound
}
return
}

View file

@ -8,10 +8,10 @@ import (
"path/filepath"
"time"
"git.giftfish.de/ston1th/haproxy-lb/pkg/config"
"git.giftfish.de/ston1th/haproxy-lb/pkg/raft/tls"
"git.giftfish.de/ston1th/haproxy-lb/pkg/util"
"git.giftfish.de/ston1th/raftbbolt"
"git.giftfish.de/ston1th/vipman/pkg/config"
"git.giftfish.de/ston1th/vipman/pkg/raft/tls"
"git.giftfish.de/ston1th/vipman/pkg/util"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/raft"
)
@ -187,6 +187,11 @@ func (c *Cluster) Stepdown() {
}
}
func (c *Cluster) Fatal(err error, msg string) {
c.Error(err, "a fatal error occurred", "message", msg)
c.Stop()
}
func (c *Cluster) Stop() {
close(c.stop)
<-c.done

View file

@ -6,7 +6,7 @@ import (
"net"
"time"
"git.giftfish.de/ston1th/vipman/pkg/config"
"git.giftfish.de/ston1th/haproxy-lb/pkg/config"
"github.com/hashicorp/raft"
)