hashicorp / raft-boltdb

Raft backend implementation using BoltDB
Mozilla Public License 2.0
653 stars 112 forks source link

bolt options when opening #5

Closed superfell closed 7 years ago

superfell commented 7 years ago

Currently this opens the bolt db without specifying any options, which means if the db is already open by another process, this open attempt will block until that process closes it [potentially indefinitely]. I think it'd be better to specify a timeout, either a fixed one, or by adding an additional version of NewBoltStore that takes a bolt Options it can pass along. Happy to do the work either way.

FYI @slackpad @ongardie

slackpad commented 7 years ago

That seems reasonable. Making an additional version of NewBoltStore that takes options seems like a good way to go. Seems like it might be prudent to make a raft-boltdb struct that has bolt.Options as a member, so we have a future place to put other parameters for new. The Path can go in there, too, and we can make NewBoltStore() call the new version with just that option set.

superfell commented 7 years ago

Sounds good, I'll put together a PR for it.

oneEyedSunday commented 1 year ago

Hello @superfell i'm following Phillip O'Toole hashicorp raft golang guide, (unfortunately its rather dated)

https://github.com/otoolep/hraftd/blob/master/store/store.go#L90

When using the bolt db store, and i'm running into problems initializing the db best described by this issue. From what ive figured out, trying to create a new boltdb instance on the same file from multiple nodes fail (even with ReadOnly set to true for subsequent nodes)

I wonder how best to handle this, https://github.com/robustirc/robustirc/blob/master/robustirc.go#L439-L446 seems to be a recent implementation, but it makes different decisions as compared to the impl from Phillipe

Can you offer any advice here.

A repro of my impl can be found here

superfell commented 1 year ago

What exactly do you mean by "on the same file"? each node needs its own unique copy of the log. If you're running multiple nodes on the same host, each logical node will need a distinct log / file.

oneEyedSunday commented 1 year ago

What exactly do you mean by "on the same file"? each node needs its own unique copy of the log. If you're running multiple nodes on the same host, each logical node will need a distinct log / file.

Apologies as im not familiar with the WHY, from the code snippets I see even from Robustirc, RedisFailover the same raftlog file is being used

It does make sense to me that switching the file names will mean i dont run into this error

superfell commented 1 year ago

In production use, each raft node runs on a separate host, so yes, each node it trying to store its log at /something/log but its on different hosts, its not being shared across processes. If for testing / experimentation you want to run multiple raft nodes on a single host/pc, then you'll need to arrange for each logical raft node to use a different file for its log. You can see examples of this in the main raft libraries unit tests, and also in the fuzzing test repo. https://github.com/hashicorp/raft-fuzzy

superfell commented 1 year ago

e.g. see https://github.com/hashicorp/raft-fuzzy/blob/master/node.go#L23 where it uses the node name to put each file in a different directory

oneEyedSunday commented 1 year ago

Great, thanks, i'd check this setup out. I've been stuck on this for far longer than im willing to admit 😅

Thanks again