From d34ad9f8359d5eea2c46dde0be3c0cafd5263529 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 12 Nov 2024 07:17:38 -0800 Subject: [PATCH] Cannot rebuild a replicated database. This feature must be integrated into the restore phase. --- src/main/java/org/cojen/tupl/Database.java | 2 +- src/main/java/org/cojen/tupl/core/Launcher.java | 4 ++++ src/main/java/org/cojen/tupl/core/Rebuilder.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cojen/tupl/Database.java b/src/main/java/org/cojen/tupl/Database.java index acbaf840a..4d5fe7beb 100644 --- a/src/main/java/org/cojen/tupl/Database.java +++ b/src/main/java/org/cojen/tupl/Database.java @@ -126,7 +126,7 @@ public static Database connect(SocketAddress addr, SSLContext context, long... t * @param numThreads pass 0 for default, or if negative, the actual number will be {@code * (-numThreads * availableProcessors)}. * @return the newly built database - * @throws IllegalStateException if the new database already exists + * @throws IllegalStateException if the new database already exists or if either is replicated */ public static Database rebuild(DatabaseConfig oldConfig, DatabaseConfig newConfig, int numThreads) diff --git a/src/main/java/org/cojen/tupl/core/Launcher.java b/src/main/java/org/cojen/tupl/core/Launcher.java index 63f2a0a21..0b20ce04b 100644 --- a/src/main/java/org/cojen/tupl/core/Launcher.java +++ b/src/main/java/org/cojen/tupl/core/Launcher.java @@ -400,6 +400,10 @@ EnumSet createOpenOptions() { return options; } + boolean isReplicated() { + return mRepl != null || mReplConfig != null; + } + /** * @return true if mRepl was assigned a new replicator */ diff --git a/src/main/java/org/cojen/tupl/core/Rebuilder.java b/src/main/java/org/cojen/tupl/core/Rebuilder.java index 827ad972a..b547144ba 100644 --- a/src/main/java/org/cojen/tupl/core/Rebuilder.java +++ b/src/main/java/org/cojen/tupl/core/Rebuilder.java @@ -60,6 +60,12 @@ public CoreDatabase run() throws IOException { private void doRun() throws IOException { // Prepare configuration and perform basic configuration checks. + if (mOldLauncher.isReplicated() || mNewLauncher.isReplicated()) { + // Both databases must not be concurrently modified by any other threads. This is + // always possible with a replicated database. + throw new IllegalStateException("Cannot rebuild a replicated database"); + } + // Page access mode must be consistent in order for the parallelCopy method to work. if (mNewLauncher.mDirectPageAccess == null) { mNewLauncher.mDirectPageAccess = mOldLauncher.mDirectPageAccess;