Skip to content

Commit cbf71e6

Browse files
committed
Merge branch 'DBTOOLS-1940-bug-fixes' into 'master'
DBTOOLS-1940 bug fixes See merge request codekeeper/pgcodekeeper-core!243
2 parents c480367 + ec12dd8 commit cbf71e6

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Fixed
1515

16+
- Fixed incorrect error on parallel database load failure.
17+
1618
## [14.1.0] - 2026-03-18
1719

1820
### Added

CHANGELOG.ru.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
### Исправлено
1515

16+
- Исправлена некорректная ошибка при сбое параллельной загрузки БД.
17+
1618
## [14.1.0] - 2026-03-18
1719

1820
### Добавлено

src/main/java/org/pgcodekeeper/core/utils/Utils.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
import java.security.NoSuchAlgorithmException;
4848
import java.security.SecureRandom;
4949
import java.util.*;
50-
import java.util.concurrent.*;
50+
import java.util.concurrent.CompletableFuture;
51+
import java.util.concurrent.CompletionException;
5152
import java.util.function.Supplier;
5253
import java.util.stream.Stream;
5354

@@ -127,9 +128,9 @@ public static Document readXml(Reader reader) throws ParserConfigurationExceptio
127128
/**
128129
* Writes an XML document to the output stream
129130
*
130-
* @param xml - {@link Document} witch store xml document
131+
* @param xml - {@link Document} witch store xml document
131132
* @param encrypt - if true, enables secure XML processing
132-
* @param stream - The output stream to write the XML document to
133+
* @param stream - The output stream to write the XML document to
133134
* @throws TransformerException if an error occurred during the XML transformation
134135
*/
135136
public static void writeXml(Document xml, boolean encrypt, StreamResult stream) throws TransformerException {
@@ -355,16 +356,17 @@ public static boolean setLikeEquals(Collection<?> c1, Collection<?> c2) {
355356
/**
356357
* Loads databases from loaders
357358
*
358-
* @param oldDbLoader loader for the old database
359-
* @param newDbLoader loader for the new database
360-
* @param subMonitor the progress monitor for tracking operation progress
361-
* @param isParallelLoad flag indicating whether to load databases in parallel mode
359+
* @param oldDbLoader loader for the old database
360+
* @param newDbLoader loader for the new database
361+
* @param subMonitor the progress monitor for tracking operation progress
362+
* @param isParallelLoad flag indicating whether to load databases in parallel mode
362363
* @return pair of databases (old and new)
363364
* @throws IOException if I/O operations fail
364365
* @throws InterruptedException if the thread is interrupted during the operation
365366
*/
366367
public static Pair<IDatabase, IDatabase> loadDatabases(ILoader oldDbLoader, ILoader newDbLoader,
367-
IMonitor subMonitor, boolean isParallelLoad) throws IOException, InterruptedException {
368+
IMonitor subMonitor, boolean isParallelLoad)
369+
throws IOException, InterruptedException {
368370
if (isParallelLoad) {
369371
return loadDatabasesInParallelMode(oldDbLoader, newDbLoader, subMonitor);
370372
}
@@ -390,40 +392,41 @@ public static Pair<IDatabase, IDatabase> loadDatabases(ILoader oldDbLoader, ILoa
390392
* @throws IOException if an I/O error occurs during loading
391393
*/
392394
private static Pair<IDatabase, IDatabase> loadDatabasesInParallelMode(ILoader oldDbLoader, ILoader newDbLoader,
393-
IMonitor monitor) throws InterruptedException, IOException {
395+
IMonitor monitor)
396+
throws InterruptedException, IOException {
394397
// Parallel load
395398
monitor.setTaskName("Loading databases");
396399

397-
var oldDbFuture = CompletableFuture.supplyAsync(supplyLoader(oldDbLoader, monitor));
398-
var newDbFuture = CompletableFuture.supplyAsync(supplyLoader(newDbLoader, monitor));
400+
var oldDbFuture = CompletableFuture.supplyAsync(supplyLoader(oldDbLoader));
401+
var newDbFuture = CompletableFuture.supplyAsync(supplyLoader(newDbLoader));
399402

400403
try {
401404
CompletableFuture.allOf(oldDbFuture, newDbFuture).join();
402405
monitor.worked(60);
403406
return new Pair<>(oldDbFuture.join(), newDbFuture.join());
404407
} catch (CompletionException e) {
408+
monitor.setCancelled(true);
405409
Throwable cause = e.getCause();
406410
if (cause instanceof InterruptedException ie) {
407411
Thread.currentThread().interrupt();
408412
throw ie;
409413
}
414+
410415
if (cause instanceof IOException io) {
411416
throw io;
412417
}
413418
throw new IOException("Failed to load databases", cause);
414419
}
415420
}
416421

417-
private static Supplier<IDatabase> supplyLoader(ILoader oldDbLoader, IMonitor monitor) {
422+
private static Supplier<IDatabase> supplyLoader(ILoader oldDbLoader) {
418423
return () -> {
419424
try {
420425
return oldDbLoader.loadAndAnalyze();
421426
} catch (InterruptedException e) {
422427
Thread.currentThread().interrupt();
423-
monitor.setCancelled(true);
424428
throw new CompletionException(e);
425429
} catch (IOException e) {
426-
monitor.setCancelled(true);
427430
throw new CompletionException(e);
428431
}
429432
};

0 commit comments

Comments
 (0)