@@ -53,17 +53,21 @@ public Connection migrate(Path dbPath, String databaseName, Connection connectio
5353 NotificationUtil .inGameNotification ("Database: " + databaseName + " recovered successfully! Retrying migration..." );
5454 continue ;
5555 }
56- XaeroPlus .LOGGER .error ("Failed migrating database: {}" , databaseName , e );
57- NotificationUtil .inGameNotification ("Database: " + databaseName + " failed to migrate!" );
58- NotificationUtil .inGameNotification ("More info will be in your log" );
56+ if (e instanceof InterruptedException ) {
57+ XaeroPlus .LOGGER .warn ("Migration interrupted: {}" , databaseName );
58+ } else {
59+ XaeroPlus .LOGGER .error ("Failed migrating database: {}" , databaseName , e );
60+ NotificationUtil .inGameNotification ("Database: " + databaseName + " failed to migrate!" );
61+ NotificationUtil .inGameNotification ("More info will be in your log" );
62+ }
5963 throw e ;
6064 }
6165 }
6266 }
6367
6468 private Connection migrateExisting (final Path dbPath , String databaseName , Connection connection ) throws SQLException , InterruptedException {
6569 for (var migration : migrations ) {
66- if (migration .shouldMigrate (databaseName , connection )) {
70+ if (migration .shouldMigrate (databaseName , connection , false )) {
6771 long beforeMigration = System .nanoTime ();
6872 XaeroPlus .LOGGER .info ("Found database: {} that needs migration" , databaseName );
6973 MIGRATION_MONITOR .onMigrationStart (databaseName );
@@ -72,18 +76,18 @@ private Connection migrateExisting(final Path dbPath, String databaseName, Conne
7276 long beforeBackup = System .nanoTime ();
7377 var backupPath = backupDatabase (dbPath , databaseName , connection );
7478 long afterBackup = System .nanoTime ();
75- XaeroPlus .LOGGER .info ("Backed up database: {} to {} in {} ms" , databaseName , backupPath , (afterBackup - beforeBackup ) / 1000000 );
79+ XaeroPlus .LOGGER .info ("Backed up database: {} to {} in {} ms" , databaseName , backupPath , TimeUnit . NANOSECONDS . toMillis (afterBackup - beforeBackup ));
7680 long beforeRunMigration = System .nanoTime ();
77- runMigration (databaseName , connection , migration );
81+ runMigration (databaseName , connection , migration , false );
7882 long afterRunMigration = System .nanoTime ();
79- XaeroPlus .LOGGER .info ("Ran migration: {} in {} ms" , migration .getClass ().getSimpleName (), (afterRunMigration - beforeRunMigration ) / 1000000 );
83+ XaeroPlus .LOGGER .info ("Ran migration: {} in {} ms" , migration .getClass ().getSimpleName (), TimeUnit . NANOSECONDS . toMillis (afterRunMigration - beforeRunMigration ));
8084 long beforeVacuum = System .nanoTime ();
8185 vacuum (connection );
8286 long afterVacuum = System .nanoTime ();
83- XaeroPlus .LOGGER .info ("Vacuumed database: {} in {} ms" , databaseName , (afterVacuum - beforeVacuum ) / 1000000 );
87+ XaeroPlus .LOGGER .info ("Vacuumed database: {} in {} ms" , databaseName , TimeUnit . NANOSECONDS . toMillis (afterVacuum - beforeVacuum ));
8488 });
8589 long afterMigration = System .nanoTime ();
86- XaeroPlus .LOGGER .info ("completed {} migration duration in {} ms" , databaseName , (afterMigration - beforeMigration ) / 1000000 );
90+ XaeroPlus .LOGGER .info ("completed {} migration duration in {} ms" , databaseName , TimeUnit . NANOSECONDS . toMillis (afterMigration - beforeMigration ));
8791 MIGRATION_MONITOR .onMigrationEnd (databaseName , true );
8892 }
8993 }
@@ -92,8 +96,8 @@ private Connection migrateExisting(final Path dbPath, String databaseName, Conne
9296
9397 private Connection migrateInit (final Path dbPath , String databaseName , Connection connection ) throws SQLException , InterruptedException {
9498 for (var migration : migrations ) {
95- if (migration .shouldMigrate (databaseName , connection )) {
96- runMigration (databaseName , connection , migration );
99+ if (migration .shouldMigrate (databaseName , connection , true )) {
100+ runMigration (databaseName , connection , migration , true );
97101 }
98102 }
99103 return connection ;
@@ -102,16 +106,20 @@ private Connection migrateInit(final Path dbPath, String databaseName, Connectio
102106 private void runMigration (
103107 final String databaseName ,
104108 final Connection connection ,
105- final DatabaseMigration migration
109+ final DatabaseMigration migration ,
110+ final boolean init
106111 ) throws SQLException , InterruptedException {
107112 var committed = false ;
108113 try {
109114 connection .setAutoCommit (false );
110- migration .doMigration (databaseName , connection );
115+ migration .doMigration (databaseName , connection , init );
111116 if (Thread .currentThread ().isInterrupted ()) {
112117 throw new InterruptedException ("Migration interrupted" );
113118 }
119+ long beforeCommit = System .nanoTime ();
114120 connection .commit ();
121+ long afterCommit = System .nanoTime ();
122+ if (!init ) XaeroPlus .LOGGER .info ("Committed migration: {} in {} ms" , migration .getClass ().getSimpleName (), TimeUnit .NANOSECONDS .toMillis (afterCommit - beforeCommit ));
115123 committed = true ;
116124 } finally {
117125 try {
@@ -132,7 +140,7 @@ private void executeConcurrencyLimited(
132140 final String operation ,
133141 final SqlOperation sqlOperation
134142 ) throws SQLException , InterruptedException {
135- var permitAcquired = HEAVY_OPERATION_PERMITS .tryAcquire (48 , TimeUnit .HOURS );
143+ var permitAcquired = HEAVY_OPERATION_PERMITS .tryAcquire (100 , TimeUnit .HOURS );
136144 if (!permitAcquired ) {
137145 throw new RuntimeException ("Failed to acquire permit for database " + operation + ": " + databaseName );
138146 }
@@ -231,9 +239,10 @@ private void validateAvailableDiskSpace(Path dbPath) {
231239 if (!dbPath .toFile ().exists ()) return ;
232240 try {
233241 var dbSize = Files .size (dbPath );
242+ XaeroPlus .LOGGER .info ("Database size: {} mb" , dbSize / (1024 * 1024 ));
234243 long freeSpace = dbPath .getParent ().toFile ().getUsableSpace ();
235244 if (freeSpace < dbSize * 3 ) {
236- throw new RuntimeException ("Not enough available disk space to migrate database: " + dbPath .toFile ().getName ());
245+ throw new RuntimeException ("Not enough available disk space to migrate database: " + dbPath .toFile ().getName () + " - " + freeSpace / ( 1024 * 1024 ) + "mb available" );
237246 }
238247 } catch (IOException e ) {
239248 throw new RuntimeException ("Failed to check available disk space for database: " + dbPath .toFile ().getName (), e );
0 commit comments