Skip to content

Wrap cleanupStagedMetadataAttribute in a transaction#151

Merged
dinhys merged 2 commits intofeatures/HPCDATAMGM-2165from
copilot/sub-pr-150
Mar 3, 2026
Merged

Wrap cleanupStagedMetadataAttribute in a transaction#151
dinhys merged 2 commits intofeatures/HPCDATAMGM-2165from
copilot/sub-pr-150

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Without a transaction, a failure in the DELETE after a successful INSERT into HPC_MIGRATED_METADATA_ATTRIBUTES leaves the staged row eligible for retry, causing duplicate entries in the migrated table.

Changes

  • HpcDataMigrationDAOImpl: Added @Transactional to cleanupStagedMetadataAttribute() so the INSERT into HPC_MIGRATED_METADATA_ATTRIBUTES and DELETE from HPC_STAGED_METADATA_ATTRIBUTES are atomic.
@Override
@Transactional
public int cleanupStagedMetadataAttribute(HpcStagedMetadataAttribute stagedMetadataAttribute) throws HpcException {
    jdbcTemplate.update(INSERT_MIGRATED_METADATA_ATTRIBUTE_SQL, ...);
    return jdbcTemplate.update(CLEANUP_STAGED_METADATA_ATTRIBUTE_SQL, ...);
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dinhys <31490208+dinhys@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • raw.github.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/HPC_DME_APIs/HPC_DME_APIs/src/hpc-server/hpc-dao-impl org.codehaus.plexus.classworlds.launcher.Launcher compile -q (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/HPC_DME_APIs/HPC_DME_APIs/src org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Update task for system/user metadata based on feedback Wrap cleanupStagedMetadataAttribute in a transaction Mar 3, 2026
@dinhys dinhys marked this pull request as ready for review March 3, 2026 16:31
Copilot AI review requested due to automatic review settings March 3, 2026 16:31
@dinhys dinhys merged commit 8bf0b09 into features/HPCDATAMGM-2165 Mar 3, 2026
2 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make cleanup of staged metadata attributes atomic so that a successful INSERT into HPC_MIGRATED_METADATA_ATTRIBUTES cannot be left behind if the subsequent DELETE from HPC_STAGED_METADATA_ATTRIBUTES fails.

Changes:

  • Added @Transactional to cleanupStagedMetadataAttribute() in HpcDataMigrationDAOImpl.
  • Added the Transactional import needed for the new annotation.
Comments suppressed due to low confidence (1)

src/hpc-server/hpc-dao-impl/src/main/java/gov/nih/nci/hpc/dao/oracle/impl/HpcDataMigrationDAOImpl.java:588

  • @Transactional will not roll back by default when this method throws HpcException (it’s a checked exception). Since you catch DataAccessException and rethrow HpcException, the transaction interceptor will likely commit, meaning the INSERT can still persist even if the DELETE fails—so the duplicate-entry scenario may remain. Consider updating the annotation to roll back for HpcException (or Exception) or otherwise marking the transaction rollback-only before throwing.
	@Override
	@Transactional
	public int cleanupStagedMetadataAttribute(HpcStagedMetadataAttribute stagedMetadataAttribute) throws HpcException {
		try {
			jdbcTemplate.update(INSERT_MIGRATED_METADATA_ATTRIBUTE_SQL, stagedMetadataAttribute.getPath(), stagedMetadataAttribute.getAttribute(),
					stagedMetadataAttribute.getValue(), Calendar.getInstance());

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants