Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11716. Address Incomplete Upgrade Scenario in Recon Upgrade Framework #7452

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ArafatKhan2198
Copy link
Contributor

What changes were proposed in this pull request?

This PR enhances the ReconLayoutVersionManager to ensure upgrade actions and schema version updates occur together in a single transaction, preventing inconsistent states.

Key Changes:

  1. Transactional Handling: Upgrade actions and schema updates are wrapped in a single transaction.
    Schema updates only commit if the action succeeds; otherwise, changes are rolled back.

  2. Enhanced updateSchemaVersion: Modified to accept a Connection for transaction consistency, aligning with the transactional scope of finalizeLayoutFeatures.

System Behavior with Latest Changes:

  • When Upgrade Action Fails: The upgrade action is attempted within a transaction. If it fails, the transaction is rolled back, no changes are made, and the system logs the error. This prevents partial upgrades and preserves the existing schema state.
  • When Schema Update Fails: If updating the schema version fails The transaction (including any preceding upgrade changes) is rolled back. This ensures no changes are committed, maintaining consistency and preventing partial updates.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-11716

How was this patch tested?

@ArafatKhan2198 ArafatKhan2198 marked this pull request as draft November 18, 2024 08:33
@devmadhuu devmadhuu self-requested a review November 22, 2024 04:15
Copy link
Contributor

@devmadhuu devmadhuu left a comment

Choose a reason for hiding this comment

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

Thanks @ArafatKhan2198 for the patch. Overall changes LGTM, Few comments to take care. Pls check.

try {
boolean recordExists = dslContext.fetchExists(dslContext.selectOne()
.from(DSL.table(RECON_SCHEMA_VERSION_TABLE_NAME)));
public void updateSchemaVersion(int newVersion, Connection conn)
Copy link
Contributor

Choose a reason for hiding this comment

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

this method doesn't throw SQLException

*/
private void updateSchemaVersion(int newVersion) throws SQLException {
schemaVersionTableManager.updateSchemaVersion(newVersion);
private void updateSchemaVersion(int newVersion, Connection connection) throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

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

this method doesn't throw SQLException.

action.get().execute(scmFacade);
updateSchemaVersion(feature.getVersion());
LOG.info("Feature versioned {} finalized successfully.", feature.getVersion());
try (Connection connection = scmFacade.getDataSource()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to open connection everytime for every feature ? Can we use same connection for every feature ?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, every feature as once a feature is upgraded, it should not be rollbacked due to crash in next feature.

LOG.info("Feature versioned {} finalized successfully.",
feature.getVersion());
} catch (Exception e) {
// Rollback any pending change`s due to failure
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment as well as log message doesn't fit well as we are not rolling back anything. It is just that it will not be committed.

@@ -112,8 +112,8 @@ public void testFinalizeLayoutFeaturesWithMockedValues() throws SQLException {
ReconStorageContainerManagerFacade.class));

// Verify that schema versions are updated for our custom features
verify(schemaVersionTableManager, times(1)).updateSchemaVersion(1);
verify(schemaVersionTableManager, times(1)).updateSchemaVersion(2);
verify(schemaVersionTableManager, times(1)).updateSchemaVersion(1, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you write a test case to verify in case of edge case when exception being thrown.

Copy link
Contributor

@sumitagrawl sumitagrawl left a comment

Choose a reason for hiding this comment

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

LGTM , handle other comments,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants