Skip to content

Commit

Permalink
Merge pull request #8078 from hashicorp/b-empty-cluster-metadata
Browse files Browse the repository at this point in the history
Handle nil/empty cluster metadata
  • Loading branch information
Mahmood Ali committed Jun 1, 2020
1 parent bf18e7e commit 246e8ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,9 @@ func (s *nomadSnapshot) persistSchedulerConfig(sink raft.SnapshotSink,
if err != nil {
return err
}
if schedConfig == nil {
return nil
}
// Write out scheduler config
sink.Write([]byte{byte(SchedulerConfigSnapshot)})
if err := encoder.Encode(schedConfig); err != nil {
Expand All @@ -2156,6 +2159,9 @@ func (s *nomadSnapshot) persistClusterMetadata(sink raft.SnapshotSink,
if err != nil {
return err
}
if clusterMetadata == nil {
return nil
}

// Write out the cluster metadata
sink.Write([]byte{byte(ClusterMetadataSnapshot)})
Expand Down
2 changes: 1 addition & 1 deletion nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5114,7 +5114,7 @@ func (s *StateStore) setClusterMetadata(txn *memdb.Txn, meta *structs.ClusterMet

if existing != nil {
existingClusterID := existing.(*structs.ClusterMetadata).ClusterID
if meta.ClusterID != existingClusterID {
if meta.ClusterID != existingClusterID && existingClusterID != "" {
// there is a bug in cluster ID detection
return fmt.Errorf("refusing to set new cluster id, previous: %s, new: %s", existingClusterID, meta.ClusterID)
}
Expand Down

0 comments on commit 246e8ec

Please sign in to comment.