Skip to content

Commit

Permalink
Merge pull request #462 from victorcoder/boltdb
Browse files Browse the repository at this point in the history
Use boltdb as default storage
  • Loading branch information
Victor Castell authored Nov 22, 2018
2 parents f11ed84 + c8320b5 commit c7da170
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ main
*.log
config/
dist
dkron.db
13 changes: 11 additions & 2 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/abronan/leadership"
"github.com/abronan/valkeyrie/store"
metrics "github.com/armon/go-metrics"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/serf/serf"
Expand Down Expand Up @@ -292,7 +293,11 @@ func (a *Agent) SetConfig(c *Config) {

func (a *Agent) StartServer() {
if a.Store == nil {
a.Store = NewStore(a.config.Backend, a.config.BackendMachines, a, a.config.Keyspace, nil)
var sConfig *store.Config
if a.config.Backend == "boltdb" {
sConfig = &store.Config{Bucket: a.config.Keyspace}
}
a.Store = NewStore(a.config.Backend, a.config.BackendMachines, a, a.config.Keyspace, sConfig)
if err := a.Store.Healthy(); err != nil {
log.WithError(err).Fatal("store: Store backend not reachable")
}
Expand All @@ -312,7 +317,11 @@ func (a *Agent) StartServer() {
log.WithError(err).Fatal("agent: RPC server failed to start")
}

a.participate()
if a.config.Backend != "boltdb" {
a.participate()
} else {
a.schedule()
}
}

func (a *Agent) participate() {
Expand Down
6 changes: 6 additions & 0 deletions dkron/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAgentCommand_runForElection(t *testing.T) {
c.NodeName = a1Name
c.Server = true
c.LogLevel = logLevel
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a1 := NewAgent(c, nil)
Expand All @@ -75,6 +76,7 @@ func TestAgentCommand_runForElection(t *testing.T) {
c.NodeName = a2Name
c.Server = true
c.LogLevel = logLevel
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a2 := NewAgent(c, nil)
Expand Down Expand Up @@ -132,6 +134,7 @@ func Test_processFilteredNodes(t *testing.T) {
c.Server = true
c.LogLevel = logLevel
c.Tags = map[string]string{"role": "test"}
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a1 := NewAgent(c, nil)
Expand All @@ -147,6 +150,7 @@ func Test_processFilteredNodes(t *testing.T) {
c.Server = true
c.LogLevel = logLevel
c.Tags = map[string]string{"role": "test"}
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a2 := NewAgent(c, nil)
Expand Down Expand Up @@ -182,6 +186,7 @@ func TestEncrypt(t *testing.T) {
c.Tags = map[string]string{"role": "test"}
c.EncryptKey = "kPpdjphiipNSsjd4QHWbkA=="
c.LogLevel = logLevel
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a := NewAgent(c, nil)
Expand All @@ -202,6 +207,7 @@ func Test_getRPCAddr(t *testing.T) {
c.Server = true
c.Tags = map[string]string{"role": "test"}
c.LogLevel = logLevel
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a := NewAgent(c, nil)
Expand Down
1 change: 1 addition & 0 deletions dkron/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func setupAPITest(t *testing.T) (a *Agent) {
c.Server = true
c.LogLevel = logLevel
c.Keyspace = "dkron-test"
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a = NewAgent(c, nil)
Expand Down
4 changes: 2 additions & 2 deletions dkron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func DefaultConfig() *Config {
NodeName: hostname,
BindAddr: fmt.Sprintf("0.0.0.0:%d", DefaultBindPort),
HTTPAddr: ":8080",
Backend: "etcdv3",
BackendMachines: []string{"127.0.0.1:2379"},
Backend: "boltdb",
BackendMachines: []string{"./dkron.db"},
Profile: "lan",
Keyspace: "dkron",
LogLevel: "info",
Expand Down
1 change: 1 addition & 0 deletions dkron/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestGRPCExecutionDone(t *testing.T) {
c.Server = true
c.LogLevel = logLevel
c.Keyspace = "dkron"
c.Backend = "etcdv3"
c.BackendMachines = []string{os.Getenv("DKRON_BACKEND_MACHINE")}

a := NewAgent(c, nil)
Expand Down
2 changes: 2 additions & 0 deletions dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/abronan/valkeyrie"
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/boltdb"
"github.com/abronan/valkeyrie/store/consul"
"github.com/abronan/valkeyrie/store/etcd/v2"
"github.com/abronan/valkeyrie/store/etcd/v3"
Expand Down Expand Up @@ -55,6 +56,7 @@ func init() {
consul.Register()
zookeeper.Register()
redis.Register()
boltdb.Register()
}

func NewStore(backend string, machines []string, a *Agent, keyspace string, config *store.Config) *Store {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/abronan/valkeyrie v0.0.0-20171113095143-063d875e3c5f
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6
github.com/coreos/bbolt v1.3.0 // indirect
github.com/coreos/etcd v3.2.9+incompatible // indirect
github.com/coreos/go-semver v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.2 // indirect
github.com/gin-contrib/multitemplate v0.0.0-20170922032617-bbc6daf6024b
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6 h1:rfTl4Lc+Gfud1YdmAFg99WN4rICM1S65KXBuADdLTms=
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.2.9+incompatible h1:rK6tzefpypqZLvs9aX7R5vcl4u1xucf2esUzFvJM6vw=
github.com/coreos/etcd v3.2.9+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY=
Expand Down

0 comments on commit c7da170

Please sign in to comment.