From fcbb9700d2ba6fb97ae9e8b30a621c3fe3d049ef Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox@redhat.com>
Date: Tue, 5 Jun 2018 13:11:05 +0200
Subject: [PATCH] db-upgrade: prevent upgrade from failing with orphaned
 brickid in volume

If a volume links back to a brick-id that does not
exist any more in the db, this does not harm otherwise,
so let's not have heketi refuse to start up in this
situation.

Signed-off-by: Michael Adam <obnox@redhat.com>
---
 apps/glusterfs/brick_entry.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/apps/glusterfs/brick_entry.go b/apps/glusterfs/brick_entry.go
index 261fc60a..ccea748a 100644
--- a/apps/glusterfs/brick_entry.go
+++ b/apps/glusterfs/brick_entry.go
@@ -274,6 +274,12 @@ func addVolumeIdInBrickEntry(tx *bolt.Tx) error {
 		}
 		for _, brick := range volumeEntry.Bricks {
 			brickEntry, err := NewBrickEntryFromId(tx, brick)
+			if err == ErrNotFound {
+				logger.Warning("Volume [%v] links to "+
+					"nonexistent brick [%v]. Ignoring.",
+					volume, brick)
+				continue
+			}
 			if err != nil {
 				return err
 			}
-- 
GitLab