Bug 1497518

Summary: An exception is thrown when importing a VM with memory snapshots for the second time ('duplicate key value violates unique constraint "pk_images"')
Product: [oVirt] ovirt-engine Reporter: Eyal Shenitzky <eshenitz>
Component: BLL.StorageAssignee: Eyal Shenitzky <eshenitz>
Status: CLOSED CURRENTRELEASE QA Contact: Raz Tamir <ratamir>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.2.0CC: amureini, bugs, tnisan
Target Milestone: ovirt-4.1.7Flags: rule-engine: ovirt-4.1+
Target Release: 4.1.7.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-11-13 12:25:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Storage RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
engine log
none
vdsm log none

Description Eyal Shenitzky 2017-10-01 10:42:13 UTC
Created attachment 1332884 [details]
engine log

Description of problem:
When having a VM with memory snapshots that exported to an export domain without collapsing them.
After importing the VM back to the environment for the second time an exception is thrown and the operation failed:

2017-10-01 13:28:53,598+03 ERROR [org.ovirt.engine.core.bll.exportimport.ImportVmCommand] (org.ovirt.thread.EE-ManagedThreadFactory-engine-Thread-119) [4647aada-b091-4501-8b32-775055560630] Command 'org.ovirt.engine.core.bll.exportimport.ImportVmCommand' failed: CallableStatementCallback; SQL [{call insertimage(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; ERROR: duplicate key value violates unique constraint "pk_images"
  Detail: Key (image_guid)=(5ac402c2-3c47-4af0-81f9-55f53dc51802) already exists.
  Where: SQL statement "INSERT INTO images (
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active,
        volume_classification
        )
    VALUES (
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active,
        v_volume_classification
        )"
PL/pgSQL function insertimage(timestamp with time zone,uuid,uuid,bigint,uuid,integer,timestamp with time zone,uuid,integer,integer,uuid,boolean,smallint) line 3 at SQL statement; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_images"
  Detail: Key (image_guid)=(5ac402c2-3c47-4af0-81f9-55f53dc51802) already exists.
  Where: SQL statement "INSERT INTO images (
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active,
        volume_classification
        )
    VALUES (
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active,
        v_volume_classification
        )"
PL/pgSQL function insertimage(timestamp with time zone,uuid,uuid,bigint,uuid,integer,timestamp with time zone,uuid,integer,integer,uuid,boolean,smallint) line 3 at SQL statement
2017-10-01 13:28:53,603+03 ERROR [org.ovirt.engine.core.bll.exportimport.ImportVmCommand] (org.ovirt.thread.EE-ManagedThreadFactory-engine-Thread-119) [4647aada-b091-4501-8b32-775055560630] Exception: org.springframework.dao.DuplicateKeyException: CallableStatementCallback; SQL [{call insertimage(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; ERROR: duplicate key value violates unique constraint "pk_images"
  Detail: Key (image_guid)=(5ac402c2-3c47-4af0-81f9-55f53dc51802) already exists.
  Where: SQL statement "INSERT INTO images (
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active,
        volume_classification
        )
    VALUES (
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active,
        v_volume_classification
        )"
PL/pgSQL function insertimage(timestamp with time zone,uuid,uuid,bigint,uuid,integer,timestamp with time zone,uuid,integer,integer,uuid,boolean,smallint) line 3 at SQL statement; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_images"
  Detail: Key (image_guid)=(5ac402c2-3c47-4af0-81f9-55f53dc51802) already exists.
  Where: SQL statement "INSERT INTO images (
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active,
        volume_classification
        )
    VALUES (
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active,
        v_volume_classification
        )"
PL/pgSQL function insertimage(timestamp with time zone,uuid,uuid,bigint,uuid,integer,timestamp with time zone,uuid,integer,integer,uuid,boolean,smallint) line 3 at SQL statement
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1099) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1135) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:405) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:365) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:198) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeImpl(SimpleJdbcCallsHandler.java:135) [dal.jar:]
	at org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeImpl(SimpleJdbcCallsHandler.java:130) [dal.jar:]
	at org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeModification(SimpleJdbcCallsHandler.java:76) [dal.jar:]
	at org.ovirt.engine.core.dao.DefaultGenericDao.save(DefaultGenericDao.java:93) [dal.jar:]
	at org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler.saveImage(ImagesHandler.java:458) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.saveImage(ImportVmCommand.java:961) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.addDisk(ImportVmCommand.java:1102) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.lambda$addMemoryImages$4(ImportVmCommand.java:1045) [bll.jar:]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) [rt.jar:1.8.0_144]
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) [rt.jar:1.8.0_144]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) [rt.jar:1.8.0_144]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) [rt.jar:1.8.0_144]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) [rt.jar:1.8.0_144]
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) [rt.jar:1.8.0_144]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) [rt.jar:1.8.0_144]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [rt.jar:1.8.0_144]
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) [rt.jar:1.8.0_144]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.addMemoryImages(ImportVmCommand.java:1044) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.lambda$processImages$1(ImportVmCommand.java:724) [bll.jar:]
	at org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInNewTransaction(TransactionSupport.java:202) [utils.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.processImages(ImportVmCommand.java:722) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.processImages(ImportVmCommand.java:714) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommandBase.executeVmCommand(ImportVmCommandBase.java:458) [bll.jar:]
	at org.ovirt.engine.core.bll.exportimport.ImportVmCommand.executeVmCommand(ImportVmCommand.java:321) [bll.jar:]
	at org.ovirt.engine.core.bll.VmCommand.executeCommand(VmCommand.java:148) [bll.jar:]
	at org.ovirt.engine.core.bll.CommandBase.executeWithoutTransaction(CommandBase.java:1205) [bll.jar:]
	at org.ovirt.engine.core.bll.CommandBase.executeActionInTransactionScope(CommandBase.java:1345) [bll.jar:]
	at org.ovirt.engine.core.bll.CommandBase.runInTransaction(CommandBase.java:1987) [bll.jar:]
	at org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInSuppressed(TransactionSupport.java:164) [utils.jar:]
	at org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInScope(TransactionSupport.java:103) [utils.jar:]
	at org.ovirt.engine.core.bll.CommandBase.execute(CommandBase.java:1405) [bll.jar:]
	at org.ovirt.engine.core.bll.CommandBase.executeAction(CommandBase.java:412) [bll.jar:]
	at org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.executeValidatedCommand(PrevalidatingMultipleActionsRunner.java:204) [bll.jar:]
	at org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.runCommands(PrevalidatingMultipleActionsRunner.java:176) [bll.jar:]
	at org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.lambda$invokeCommands$3(PrevalidatingMultipleActionsRunner.java:182) [bll.jar:]
	at org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil$InternalWrapperRunnable.run(ThreadPoolUtil.java:96) [utils.jar:]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_144]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_144]
	at org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:141) [javax.enterprise.concurrent-1.0.jar:]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_144]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_144]
	at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_144]
	at org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:250) [javax.enterprise.concurrent-1.0.jar:]
	at org.jboss.as.ee.concurrent.service.ElytronManagedThreadFactory$ElytronManagedThread.run(ElytronManagedThreadFactory.java:78)
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_images"
  Detail: Key (image_guid)=(5ac402c2-3c47-4af0-81f9-55f53dc51802) already exists.
  Where: SQL statement "INSERT INTO images (
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active,
        volume_classification
        )
    VALUES (
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active,
        v_volume_classification
        )"
PL/pgSQL function insertimage(timestamp with time zone,uuid,uuid,bigint,uuid,integer,timestamp with time zone,uuid,integer,integer,uuid,boolean,smallint) line 3 at SQL statement
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:410)
	at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.execute(CachedPreparedStatement.java:303)
	at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:442)
	at org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1138) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1135) [spring-jdbc.jar:4.3.9.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1083) [spring-jdbc.jar:4.3.9.RELEASE]
	... 48 more


Version-Release number of selected component (if applicable):
4.2.0_master - from commit 6426ca5cf3a0eebf5c74111edf6795fcfc131478
Checked on that version, It is not clear sinse when the problem was created.

How reproducible:
100%

Steps to Reproduce:
1. Create a VM with 1 disk + OS
2. Run it and create snapshot with memory
3. Export it to an export domain (no collapse, no override)
4. Remove the origin VM
5. Import the VM (no collapse, no clone)
6. Remove the imported VM
7. Import the VM (no collapse, no clone) again

Actual results:
Failed to import the VM, an exception is thrown

Expected results:
Import the VM should end successfully

Additional info:
Engine and VDSM log attached

Comment 1 Eyal Shenitzky 2017-10-01 10:44:01 UTC
Created attachment 1332885 [details]
vdsm log

Comment 2 Sandro Bonazzola 2017-10-11 11:12:23 UTC
Should be in oVirt 4.1.7 RC3

Comment 3 Raz Tamir 2017-10-15 08:18:49 UTC
Verified on rhevm-4.1.7.3-0.1.el7.noarch