From bf35aefe0fa7628f813863d2e288310c899adab1 Mon Sep 17 00:00:00 2001 From: niteshsarda Date: Thu, 31 Aug 2017 13:10:41 +0530 Subject: [PATCH] CLOUDSTACK-10032 : Database entries for templates created from snapshots disappear after management-server service restart (#2224) This issue occurs only with KVM hypervisor. Database entries for templates created from snapshots disappear after management-server service restart # STEPS TO REPRODUCE Create a ACS setup and add KVM hypervisor as host. Create snapshot of any disk (root or data disk) of an instance. Create template using disk snapshot. Verify that template got downloaded completely and is in Ready state. Also, verify that entry for this template is present in template_store_ref table in database. Now restart management server. Once management server is restarted completely and web UI is available, check the template status. It will be in Active state instead of downloaded. Also, entry for this template vanishes from template_store_ref table in database. # Fix for the Issue In NfsSecondaryStorageResource.java class, inside method copySnapshotToTemplateFromNfsToNfs() bufferwriter which was created for writing data in template.properties file is not closed and hence few properties were not getting written in template.properties. As few properties were absent in template.properties file, so after management server restart, this template is not loaded and hence it goes into Active state. --- .../storage/resource/NfsSecondaryStorageResource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 4f3ad077452..4980d97f169 100644 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -528,6 +528,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S bufferWriter.write("\n"); long size = _storage.getSize(destFileFullPath); bufferWriter.write("size=" + size); + bufferWriter.close(); + writer.close(); /** * Snapshots might be in either QCOW2 or RAW image format