Hard-fail on persistence errors, otherwise the network can get confused on a restart.
Create `Allocator.fatalf()`, for consistency
This commit is contained in:
1 parent
06f3793f05
commit
546f9592f9
1 file changed
+7
-4
+7
-4
@@ -774,18 +774,18 @@ const (
|
|||||||
func (alloc *Allocator) persistRing() {
|
func (alloc *Allocator) persistRing() {
|
||||||
// It would be better if these two Save operations happened in the same transaction
|
// It would be better if these two Save operations happened in the same transaction
|
||||||
if err := alloc.db.Save(nameIdent, alloc.ourName); err != nil {
|
if err := alloc.db.Save(nameIdent, alloc.ourName); err != nil {
|
||||||
common.Log.Errorf("Error persisting ring data: %s", err)
|
alloc.fatalf("Error persisting ring data: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := alloc.db.Save(ringIdent, alloc.ring); err != nil {
|
if err := alloc.db.Save(ringIdent, alloc.ring); err != nil {
|
||||||
common.Log.Errorf("Error persisting ring data: %s", err)
|
alloc.fatalf("Error persisting ring data: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (alloc *Allocator) loadPersistedRing() {
|
func (alloc *Allocator) loadPersistedRing() {
|
||||||
var checkPeerName mesh.PeerName
|
var checkPeerName mesh.PeerName
|
||||||
if err := alloc.db.Load(nameIdent, &checkPeerName); err != nil {
|
if err := alloc.db.Load(nameIdent, &checkPeerName); err != nil {
|
||||||
common.Log.Errorf("Error loading persisted peer name: %s", err)
|
alloc.fatalf("Error loading persisted peer name: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if checkPeerName != alloc.ourName {
|
if checkPeerName != alloc.ourName {
|
||||||
@@ -794,7 +794,7 @@ func (alloc *Allocator) loadPersistedRing() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := alloc.db.Load(ringIdent, &alloc.ring); err != nil {
|
if err := alloc.db.Load(ringIdent, &alloc.ring); err != nil {
|
||||||
common.Log.Errorf("Error loading persisted ring data: %s", err)
|
alloc.fatalf("Error loading persisted ring data: %s", err)
|
||||||
}
|
}
|
||||||
if alloc.ring != nil {
|
if alloc.ring != nil {
|
||||||
alloc.space.UpdateRanges(alloc.ring.OwnedRanges())
|
alloc.space.UpdateRanges(alloc.ring.OwnedRanges())
|
||||||
@@ -860,6 +860,9 @@ func (alloc *Allocator) findOwner(addr address.Address) string {
|
|||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
|
||||||
|
func (alloc *Allocator) fatalf(fmt string, args ...interface{}) {
|
||||||
|
common.Log.Fatalf("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...)
|
||||||
|
}
|
||||||
func (alloc *Allocator) infof(fmt string, args ...interface{}) {
|
func (alloc *Allocator) infof(fmt string, args ...interface{}) {
|
||||||
common.Log.Infof("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...)
|
common.Log.Infof("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user