Skip to content

Commit

Permalink
Only attempt monitor storage creation on leader
Browse files Browse the repository at this point in the history
Since only the leader can create it, the system might as well only
attempt creation on the leader.
  • Loading branch information
otoolep committed Oct 5, 2015
1 parent 62fab49 commit 899e1cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion monitor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Monitor struct {
ClusterID() (uint64, error)
NodeID() uint64
WaitForLeader(d time.Duration) error
IsLeader() bool
CreateDatabaseIfNotExists(name string) (*meta.DatabaseInfo, error)
CreateRetentionPolicyIfNotExists(database string, rpi *meta.RetentionPolicyInfo) (*meta.RetentionPolicyInfo, error)
SetDefaultRetentionPolicy(database, name string) error
Expand Down Expand Up @@ -297,7 +298,7 @@ func (m *Monitor) Diagnostics() (map[string]*Diagnostic, error) {

// createInternalStorage ensures the internal storage has been created.
func (m *Monitor) createInternalStorage() {
if m.storeCreated {
if !m.MetaStore.IsLeader() || m.storeCreated {
return
}

Expand Down
1 change: 1 addition & 0 deletions monitor/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type mockMetastore struct{}
func (m *mockMetastore) ClusterID() (uint64, error) { return 1, nil }
func (m *mockMetastore) NodeID() uint64 { return 2 }
func (m *mockMetastore) WaitForLeader(d time.Duration) error { return nil }
func (m *mockMetastore) IsLeader() bool { return true }
func (m *mockMetastore) SetDefaultRetentionPolicy(database, name string) error { return nil }
func (m *mockMetastore) DropRetentionPolicy(database, name string) error { return nil }
func (m *mockMetastore) CreateDatabaseIfNotExists(name string) (*meta.DatabaseInfo, error) {
Expand Down

0 comments on commit 899e1cc

Please sign in to comment.