Skip to content

Commit 4551048

Browse files
committed
Remove automatic migration upon server start
1 parent 278cb7d commit 4551048

File tree

2 files changed

+33
-79
lines changed

2 files changed

+33
-79
lines changed

airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteVersion.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
*/
3232
public class AirbyteVersion {
3333

34+
/**
35+
* We moved the configs from the data volume to the configs database, and introduced Flyway
36+
* migration in v0.29. The data volume and the file-based migration are deprecated in v0.30. Users
37+
* must first upgrade to the last version before v0.30 to migrate their configs from the data
38+
* volume, and integrate with the new Flyway system.
39+
*/
40+
public static final AirbyteVersion MINIMUM_REQUIRED_VERSION = new AirbyteVersion("0.29.17-alpha");
41+
3442
private static final String DEV_VERSION = "dev";
3543
public static final String AIRBYTE_VERSION_KEY_NAME = "airbyte_version";
3644

@@ -39,6 +47,9 @@ public class AirbyteVersion {
3947
private final String minor;
4048
private final String patch;
4149

50+
/**
51+
* Expected input format: x.y.z-w
52+
*/
4253
public AirbyteVersion(final String version) {
4354
Preconditions.checkNotNull(version);
4455
this.version = version;
@@ -112,6 +123,10 @@ public int patchVersionCompareTo(final AirbyteVersion another) {
112123
return compareVersion(patch, another.patch);
113124
}
114125

126+
public boolean compatibleWithMinRequiredVersion() {
127+
return this.patchVersionCompareTo(MINIMUM_REQUIRED_VERSION) >= 0;
128+
}
129+
115130
/**
116131
* Version string needs to be converted to integer for comparison, because string comparison does
117132
* not handle version string with different digits correctly. For example:
@@ -132,8 +147,9 @@ public static String getErrorMessage(final String version1, final String version
132147
final String cleanVersion2 = version2.replace("\n", "").strip();
133148
return String.format(
134149
"Version mismatch between %s and %s.\n" +
135-
"Please upgrade or reset your Airbyte Database, see more at https://docs.airbyte.io/operator-guides/upgrading-airbyte",
136-
cleanVersion1, cleanVersion2);
150+
"Please upgrade to at least %s, or reset your Airbyte Database.\n" +
151+
"See more at https://docs.airbyte.io/operator-guides/upgrading-airbyte",
152+
cleanVersion1, cleanVersion2, MINIMUM_REQUIRED_VERSION.getVersion());
137153
}
138154

139155
public static boolean isCompatible(final String v1, final String v2) {

airbyte-server/src/main/java/io/airbyte/server/ServerApp.java

+15-77
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
import io.airbyte.commons.resources.MoreResources;
3030
import io.airbyte.commons.version.AirbyteVersion;
3131
import io.airbyte.config.Configs;
32-
import io.airbyte.config.Configs.WorkerEnvironment;
3332
import io.airbyte.config.EnvConfigs;
3433
import io.airbyte.config.StandardWorkspace;
3534
import io.airbyte.config.helpers.LogClientSingleton;
3635
import io.airbyte.config.persistence.ConfigRepository;
3736
import io.airbyte.config.persistence.ConfigSeedProvider;
3837
import io.airbyte.config.persistence.DatabaseConfigPersistence;
39-
import io.airbyte.config.persistence.YamlSeedConfigPersistence;
4038
import io.airbyte.db.Database;
4139
import io.airbyte.db.instance.DatabaseMigrator;
4240
import io.airbyte.db.instance.configs.ConfigsDatabaseInstance;
@@ -54,7 +52,6 @@
5452
import io.airbyte.scheduler.persistence.JobPersistence;
5553
import io.airbyte.scheduler.persistence.job_factory.OAuthConfigSupplier;
5654
import io.airbyte.scheduler.persistence.job_tracker.JobTracker;
57-
import io.airbyte.server.converters.SpecFetcher;
5855
import io.airbyte.server.errors.InvalidInputExceptionMapper;
5956
import io.airbyte.server.errors.InvalidJsonExceptionMapper;
6057
import io.airbyte.server.errors.InvalidJsonInputExceptionMapper;
@@ -85,12 +82,7 @@ public class ServerApp implements ServerRunnable {
8582

8683
private static final Logger LOGGER = LoggerFactory.getLogger(ServerApp.class);
8784
private static final int PORT = 8001;
88-
/**
89-
* We can't support automatic migration for kube before this version because we had a bug in kube
90-
* which would cause airbyte db to erase state upon termination, as a result the automatic migration
91-
* wouldn't run
92-
*/
93-
private static final AirbyteVersion KUBE_SUPPORT_FOR_AUTOMATIC_MIGRATION = new AirbyteVersion("0.26.5-alpha");
85+
9486
private final String airbyteVersion;
9587
private final Set<Class<?>> customComponentClasses;
9688
private final Set<Object> customComponents;
@@ -223,84 +215,30 @@ public static ServerRunnable getServer(final ServerFactory apiFactory) throws Ex
223215
final SynchronousSchedulerClient bucketSpecCacheSchedulerClient =
224216
new BucketSpecCacheSchedulerClient(syncSchedulerClient, configs.getSpecCacheBucket());
225217
final SpecCachingSynchronousSchedulerClient cachingSchedulerClient = new SpecCachingSynchronousSchedulerClient(bucketSpecCacheSchedulerClient);
226-
final SpecFetcher specFetcher = new SpecFetcher(cachingSchedulerClient);
227-
228-
Optional<String> airbyteDatabaseVersion = jobPersistence.getVersion();
229-
if (airbyteDatabaseVersion.isPresent() && isDatabaseVersionBehindAppVersion(airbyteVersion, airbyteDatabaseVersion.get())) {
230-
final boolean isKubernetes = configs.getWorkerEnvironment() == WorkerEnvironment.KUBERNETES;
231-
final boolean versionSupportsAutoMigrate =
232-
new AirbyteVersion(airbyteDatabaseVersion.get()).patchVersionCompareTo(KUBE_SUPPORT_FOR_AUTOMATIC_MIGRATION) >= 0;
233-
if (!isKubernetes || versionSupportsAutoMigrate) {
234-
runAutomaticMigration(configRepository, jobPersistence, specFetcher, airbyteVersion, airbyteDatabaseVersion.get());
235-
// After migration, upgrade the DB version
236-
airbyteDatabaseVersion = jobPersistence.getVersion();
237-
} else {
238-
LOGGER.info("Can not run automatic migration for Airbyte on KUBERNETES before version " + KUBE_SUPPORT_FOR_AUTOMATIC_MIGRATION.getVersion());
239-
}
218+
219+
Optional<String> dbVersion = jobPersistence.getVersion();
220+
if (dbVersion.isPresent() && !new AirbyteVersion(dbVersion.get()).compatibleWithMinRequiredVersion()) {
221+
return new VersionMismatchServer(airbyteVersion, dbVersion.get(), PORT);
240222
}
241223

242224
runFlywayMigration(configs, configDatabase, jobDatabase);
243225

244-
if (airbyteDatabaseVersion.isPresent() && AirbyteVersion.isCompatible(airbyteVersion, airbyteDatabaseVersion.get())) {
245-
LOGGER.info("Starting server...");
246-
247-
return apiFactory.create(
248-
schedulerJobClient,
249-
cachingSchedulerClient,
250-
temporalService,
251-
configRepository,
252-
jobPersistence,
253-
configDatabase,
254-
jobDatabase,
255-
configs);
256-
} else {
257-
LOGGER.info("Start serving version mismatch errors. Automatic migration either failed or didn't run");
258-
return new VersionMismatchServer(airbyteVersion, airbyteDatabaseVersion.orElseThrow(), PORT);
259-
}
226+
LOGGER.info("Starting server...");
227+
return apiFactory.create(
228+
schedulerJobClient,
229+
cachingSchedulerClient,
230+
temporalService,
231+
configRepository,
232+
jobPersistence,
233+
configDatabase,
234+
jobDatabase,
235+
configs);
260236
}
261237

262238
public static void main(final String[] args) throws Exception {
263239
getServer(new ServerFactory.Api()).start();
264240
}
265241

266-
/**
267-
* Ideally when automatic migration runs, we should make sure that we acquire a lock on database and
268-
* no other operation is allowed
269-
*/
270-
private static void runAutomaticMigration(final ConfigRepository configRepository,
271-
final JobPersistence jobPersistence,
272-
final SpecFetcher specFetcher,
273-
final String airbyteVersion,
274-
final String airbyteDatabaseVersion) {
275-
LOGGER.info("Running Automatic Migration from version : " + airbyteDatabaseVersion + " to version : " + airbyteVersion);
276-
try (final RunMigration runMigration = new RunMigration(
277-
jobPersistence,
278-
configRepository,
279-
airbyteVersion,
280-
YamlSeedConfigPersistence.get(),
281-
specFetcher)) {
282-
runMigration.run();
283-
} catch (final Exception e) {
284-
LOGGER.error("Automatic Migration failed ", e);
285-
}
286-
}
287-
288-
public static boolean isDatabaseVersionBehindAppVersion(final String airbyteVersion, final String airbyteDatabaseVersion) {
289-
final boolean bothVersionsCompatible = AirbyteVersion.isCompatible(airbyteVersion, airbyteDatabaseVersion);
290-
if (bothVersionsCompatible) {
291-
return false;
292-
}
293-
294-
final AirbyteVersion serverVersion = new AirbyteVersion(airbyteVersion);
295-
final AirbyteVersion databaseVersion = new AirbyteVersion(airbyteDatabaseVersion);
296-
297-
if (databaseVersion.getMajorVersion().compareTo(serverVersion.getMajorVersion()) < 0) {
298-
return true;
299-
}
300-
301-
return databaseVersion.getMinorVersion().compareTo(serverVersion.getMinorVersion()) < 0;
302-
}
303-
304242
private static void runFlywayMigration(final Configs configs, final Database configDatabase, final Database jobDatabase) {
305243
final DatabaseMigrator configDbMigrator = new ConfigsDatabaseMigrator(configDatabase, ServerApp.class.getSimpleName());
306244
final DatabaseMigrator jobDbMigrator = new JobsDatabaseMigrator(jobDatabase, ServerApp.class.getSimpleName());

0 commit comments

Comments
 (0)