forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Switch to use Bootloader. (airbytehq#8584)" (airbyteh…
…q#8778)" (airbytehq#8790) This reverts commit 216501b. Turn this back on since this was originally reverted for logging update changes.
- Loading branch information
Showing
33 changed files
with
530 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
airbyte-db/lib/src/main/java/io/airbyte/db/instance/MinimumFlywayMigrationVersionCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance; | ||
|
||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Contains reusable methods asserting if a database is ready. | ||
* <p> | ||
* This is intended to be used by applications in combination with the bootloader, and the minimum | ||
* migration env vars from {@link io.airbyte.config.Configs}, so application know it is safe to | ||
* start interacting with the database. | ||
* <p> | ||
* Both methods here poll every {@link #DEFAULT_POLL_PERIOD_MS} and have configurable timeouts. | ||
*/ | ||
public class MinimumFlywayMigrationVersionCheck { | ||
|
||
public static final long DEFAULT_ASSERT_DATABASE_TIMEOUT_MS = 2 * BaseDatabaseInstance.DEFAULT_CONNECTION_TIMEOUT_MS; | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MinimumFlywayMigrationVersionCheck.class); | ||
private static final long DEFAULT_POLL_PERIOD_MS = 2000; | ||
|
||
/** | ||
* Assert the given database can be connected to. | ||
* | ||
* @param db | ||
* @param timeoutMs | ||
*/ | ||
public static void assertDatabase(DatabaseInstance db, long timeoutMs) { | ||
var currWaitingTime = 0; | ||
var initialized = false; | ||
while (!initialized) { | ||
if (currWaitingTime >= timeoutMs) { | ||
throw new RuntimeException("Timeout while connecting to the database.."); | ||
} | ||
|
||
try { | ||
initialized = db.isInitialized(); | ||
} catch (IOException e) { | ||
currWaitingTime += BaseDatabaseInstance.DEFAULT_CONNECTION_TIMEOUT_MS; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Assert the given database contains the minimum flyway migrations needed to run the application. | ||
* | ||
* @param migrator | ||
* @param minimumFlywayVersion | ||
* @param timeoutMs | ||
* @throws InterruptedException | ||
*/ | ||
public static void assertMigrations(DatabaseMigrator migrator, String minimumFlywayVersion, long timeoutMs) throws InterruptedException { | ||
var currWaitingTime = 0; | ||
var currDatabaseMigrationVersion = migrator.getLatestMigration().getVersion().getVersion(); | ||
|
||
while (currDatabaseMigrationVersion.compareTo(minimumFlywayVersion) < 0) { | ||
if (currWaitingTime >= timeoutMs) { | ||
throw new RuntimeException("Timeout while waiting for database to fulfill minimum flyway migration version.."); | ||
} | ||
|
||
Thread.sleep(DEFAULT_POLL_PERIOD_MS); | ||
currWaitingTime += DEFAULT_POLL_PERIOD_MS; | ||
currDatabaseMigrationVersion = migrator.getLatestMigration().getVersion().getVersion(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.