Skip to content

Commit a747ee5

Browse files
committed
CLOUDSTACK-3976: if the snapshot is empty and it's the last one in the chain, we need to take full snapshot for the snapshots in sequence
1 parent da124c2 commit a747ee5

1 file changed

Lines changed: 35 additions & 22 deletions

File tree

‎engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,44 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
130130
protected boolean deleteSnapshotChain(SnapshotInfo snapshot) {
131131
s_logger.debug("delete snapshot chain for snapshot: " + snapshot.getId());
132132
boolean result = false;
133-
while (snapshot != null && (snapshot.getState() == Snapshot.State.Destroying || snapshot.getState()
134-
== Snapshot.State.Destroyed || snapshot.getState() == Snapshot.State.Error)) {
135-
SnapshotInfo child = snapshot.getChild();
133+
boolean resultIsSet = false; //need to track, the snapshot itself is deleted or not.
134+
try {
135+
while (snapshot != null && (snapshot.getState() == Snapshot.State.Destroying || snapshot.getState()
136+
== Snapshot.State.Destroyed || snapshot.getState() == Snapshot.State.Error)) {
137+
SnapshotInfo child = snapshot.getChild();
136138

137-
if (child != null) {
138-
s_logger.debug("the snapshot has child, can't delete it on the storage");
139-
break;
140-
}
141-
s_logger.debug("Snapshot: " + snapshot.getId() + " doesn't have children, so it's ok to delete it and its parents");
142-
SnapshotInfo parent = snapshot.getParent();
143-
boolean deleted = false;
144-
if (parent != null) {
145-
if (parent.getPath() != null && parent.getPath().equalsIgnoreCase(snapshot.getPath())) {
146-
//NOTE: if both snapshots share the same path, it's for xenserver's empty delta snapshot. We can't delete the snapshot on the backend, as parent snapshot still reference to it
147-
//Instead, mark it as destroyed in the db.
148-
s_logger.debug("for empty delta snapshot, only mark it as destroyed in db");
149-
snapshot.processEvent(Event.DestroyRequested);
150-
snapshot.processEvent(Event.OperationSuccessed);
151-
deleted = true;
139+
if (child != null) {
140+
s_logger.debug("the snapshot has child, can't delete it on the storage");
141+
break;
152142
}
143+
s_logger.debug("Snapshot: " + snapshot.getId() + " doesn't have children, so it's ok to delete it and its parents");
144+
SnapshotInfo parent = snapshot.getParent();
145+
boolean deleted = false;
146+
if (parent != null) {
147+
if (parent.getPath() != null && parent.getPath().equalsIgnoreCase(snapshot.getPath())) {
148+
//NOTE: if both snapshots share the same path, it's for xenserver's empty delta snapshot. We can't delete the snapshot on the backend, as parent snapshot still reference to it
149+
//Instead, mark it as destroyed in the db.
150+
s_logger.debug("for empty delta snapshot, only mark it as destroyed in db");
151+
snapshot.processEvent(Event.DestroyRequested);
152+
snapshot.processEvent(Event.OperationSuccessed);
153+
deleted = true;
154+
if (!resultIsSet) {
155+
result = true;
156+
resultIsSet = true;
157+
}
158+
}
159+
}
160+
if (!deleted) {
161+
boolean r = this.snapshotSvr.deleteSnapshot(snapshot);
162+
if (!resultIsSet) {
163+
result = r;
164+
resultIsSet = true;
165+
}
166+
}
167+
snapshot = parent;
153168
}
154-
if (!deleted) {
155-
result = this.snapshotSvr.deleteSnapshot(snapshot);
156-
}
157-
snapshot = parent;
169+
} catch (Exception e) {
170+
s_logger.debug("delete snapshot failed: ", e);
158171
}
159172
return result;
160173
}

0 commit comments

Comments
 (0)