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

widen 'isMigrationError' to catch constraint errors #1261

Merged
merged 3 commits into from
Jan 14, 2020

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Jan 13, 2020

Issue Number

#1251

Overview

  • c68cc47
    widen 'isMigrationError' to catch constraint errors
    On start-up, we run persistent migrations and in case of migration issues, we
    execute some particular handling (e.g. the pool db resets itself). Yet, we
    failed at catching migration issues coming from constraints introduced later
    and that can't be satisfied on already existing data. This commit fixes it.

Before

[cardano-wallet.network:Info:22] Jörmungandr is ready.
cardano-wallet-jormungandr: SQLite3 returned ErrorConstraint while attempting to perform step: NOT NULL constraint failed: pool_owner_backup.pool_owner_index
(exiting with an error code)

After

[cardano-wallet.network:Info:22] Jörmungandr is ready.
[cardano-wallet.stake-pool-db:Error:22]  Failed to migrate the database: : NOT NULL constraint failed: pool_owner_backup.pool_owner_index
[cardano-wallet.stake-pool-db:Notice:22] Non backward compatible database found. Removing old database and re-creating it from scratch. Ignore the previous error.
[cardano-wallet.stake-pool-db:Notice:22] 1 migrations were applied to the database.
(... and continuing as normal)
  • 25fa318
    rename 'IsMigration...' to 'MatchMigration...'

  • 9d61437
    flatten result after tryJust to a single 'Either'

Comments

On start-up, we run persistent migrations and in case of migration issues, we
execute some particular handling (e.g. the pool db resets itself). Yet, we
failed at catching migration issues coming from constraints introduced later
and that can't be satisfied on already existing data. This commit fixes it.

Before
======

[cardano-wallet.network:Info:22] Jörmungandr is ready.
cardano-wallet-jormungandr: SQLite3 returned ErrorConstraint while attempting to perform step: NOT NULL constraint failed: pool_owner_backup.pool_owner_index
(exiting with an error code)

After
=====

[cardano-wallet.network:Info:22] Jörmungandr is ready.
[cardano-wallet.stake-pool-db:Error:22]  Failed to migrate the database: : NOT NULL constraint failed: pool_owner_backup.pool_owner_index
[cardano-wallet.stake-pool-db:Notice:22] Non backward compatible database found. Removing old database and re-creating it from scratch. Ignore the previous error.
[cardano-wallet.stake-pool-db:Notice:22] 1 migrations were applied to the database.
(... and continuing as normal)
Copy link
Member

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

I've tested this going from v2019-12-13 (f3576be) to the current master (10b5512), and it does appear to solve the problem of recreating the stake pool DB:

[cardano-wallet.stake-pool-db:Error:22] [2020-01-14 02:52:08.72 UTC] Failed to migrate the database: : NOT NULL constraint failed: pool_owner_backup.pool_owner_index
[cardano-wallet.stake-pool-db:Notice:22] [2020-01-14 02:52:08.72 UTC] Non backward compatible database found. Removing old database and re-creating it from scratch. Ignore the previous error.

I only have a small suggestion regarding naming of the function isMigrationError. (See comments.)

mark = "Database migration: manual intervention required."
class Exception e => IsMigrationError e where
-- | Exception predicate for migration errors.
isMigrationError :: e -> Maybe MigrationError
Copy link
Member

Choose a reason for hiding this comment

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

I think the function name isMigrationError is a bit misleading, as the prefix is strongly implies a Boolean result, when what we actually want is to match and extract an error of a particular type (if it exists).

Suggestion: rename this to something like catchMigrationError or matchMigrationError.

@KtorZ
Copy link
Member Author

KtorZ commented Jan 14, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 14, 2020
1261: widen 'isMigrationError' to catch constraint errors r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1251 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

On start-up, we run persistent migrations and in case of migration issues, we
execute some particular handling (e.g. the pool db resets itself). Yet, we
failed at catching migration issues coming from constraints introduced later
and that can't be satisfied on already existing data. This commit fixes it.

Before
======

```
[cardano-wallet.network:Info:22] Jörmungandr is ready.
cardano-wallet-jormungandr: SQLite3 returned ErrorConstraint while attempting to perform step: NOT NULL constraint failed: pool_owner_backup.pool_owner_index
(exiting with an error code)
```
After
=====
```
[cardano-wallet.network:Info:22] Jörmungandr is ready.
[cardano-wallet.stake-pool-db:Error:22]  Failed to migrate the database: : NOT NULL constraint failed: pool_owner_backup.pool_owner_index
[cardano-wallet.stake-pool-db:Notice:22] Non backward compatible database found. Removing old database and re-creating it from scratch. Ignore the previous error.
[cardano-wallet.stake-pool-db:Notice:22] 1 migrations were applied to the database.
(... and continuing as normal)
```
# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <matthias.benkort@gmail.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 14, 2020

Build succeeded

@iohk-bors iohk-bors bot merged commit 9d61437 into master Jan 14, 2020
@KtorZ KtorZ deleted the KtorZ/1251/widen-migration-error-handling branch January 20, 2020 10:41
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.

2 participants