Skip to content

Commit

Permalink
Merge pull request #2905 from benbjohnson/limit-cluster-size
Browse files Browse the repository at this point in the history
Limit cluster to 3 nodes
  • Loading branch information
benbjohnson committed Jun 11, 2015
2 parents 6a579c8 + 405ec78 commit ed4d009
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [#2886](https://github.com/influxdb/influxdb/issues/2886): Refactor backup & restore
- [#2804](https://github.com/influxdb/influxdb/pull/2804): BREAKING: change time literals to be single quoted in InfluxQL. Thanks @nvcook42!
- [#2906](https://github.com/influxdb/influxdb/pull/2906): Restrict replication factor to the cluster size
- [#2905](https://github.com/influxdb/influxdb/pull/2905): Restrict clusters to 3 peers

## v0.9.0-rc33 [2015-06-09]

Expand Down
3 changes: 3 additions & 0 deletions meta/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var (

// ErrStoreClosed is returned when closing an already closed store.
ErrStoreClosed = errors.New("raft store already closed")

// ErrTooManyPeers is returned when more than 3 peers are used.
ErrTooManyPeers = errors.New("too many peers; influxdb v0.9.0 is limited to 3 nodes in a cluster")
)

var (
Expand Down
6 changes: 6 additions & 0 deletions meta/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ func (s *Store) IDPath() string { return filepath.Join(s.path, "id") }

// Open opens and initializes the raft store.
func (s *Store) Open() error {
// Verify that no more than 3 peers.
// https://github.com/influxdb/influxdb/issues/2750
if len(s.peers) > 3 {
return ErrTooManyPeers
}

// Verify listeners are set.
if s.RaftListener == nil {
panic("Store.RaftListener not set")
Expand Down
11 changes: 11 additions & 0 deletions meta/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func TestStore_Open_ErrStoreOpen(t *testing.T) {
}
}

// Ensure that opening a store with more than 3 peers returns an error.
func TestStore_Open_ErrTooManyPeers(t *testing.T) {
t.Parallel()
config := NewConfig(MustTempFile())
config.Peers = []string{"localhost:9000", "localhost:9001", "localhost:9002", "localhost:9003"}
s := NewStore(config)
if err := s.Open(); err != meta.ErrTooManyPeers {
t.Fatalf("unexpected error: %s", err)
}
}

// Ensure the store can create a new node.
func TestStore_CreateNode(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit ed4d009

Please sign in to comment.