Skip to content

Commit

Permalink
set db version after full import is complete (#4626)
Browse files Browse the repository at this point in the history
* set db version after full import is complete

* check db version in the last step

* add comment
  • Loading branch information
subodh1810 authored and gl-pix committed Jul 22, 2021
1 parent 83e26b0 commit f63066a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import java.util.UUID;
import java.util.stream.Stream;

/**
* TODO Introduce a locking mechanism so that no DB operation is allowed when automatic migration is
* running
*/
public interface JobPersistence {

Job getJob(long jobId) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ public ImportRead importData(File archive) {
// 1. Unzip source
Archives.extractArchive(archive.toPath(), sourceRoot);

// 2. Set DB version
LOGGER.info("Setting the DB Airbyte version to : " + targetVersion);
postgresPersistence.setVersion(targetVersion);

// 3. dry run
// 2. dry run
try {
checkImport(sourceRoot);
} catch (Exception e) {
Expand All @@ -130,11 +126,18 @@ public ImportRead importData(File archive) {
throw e;
}

// 4. Import Postgres content
// 3. Import Postgres content
importDatabaseFromArchive(sourceRoot, targetVersion);

// 5. Import Configs
// 4. Import Configs
importConfigsFromArchive(sourceRoot, false);

// 5. Set DB version
LOGGER.info("Setting the DB Airbyte version to : " + targetVersion);
postgresPersistence.setVersion(targetVersion);

// 6. check db version
checkDBVersion(targetVersion);
result = new ImportRead().status(StatusEnum.SUCCEEDED);
} finally {
FileUtils.deleteDirectory(sourceRoot.toFile());
Expand Down Expand Up @@ -164,7 +167,6 @@ private void checkImport(Path tempFolder) throws IOException, JsonValidationExce
"Please upgrade your Airbyte Archive, see more at https://docs.airbyte.io/tutorials/upgrading-airbyte\n",
importVersion, targetVersion));
}
checkDBVersion(targetVersion);
importConfigsFromArchive(tempFolder, true);
}

Expand Down
4 changes: 4 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ public static void main(String[] args) throws Exception {
}
}

/**
* Ideally when automatic migration runs, we should make sure that we acquire a lock on database and
* no other operation is allowed
*/
private static void runAutomaticMigration(ConfigRepository configRepository,
JobPersistence jobPersistence,
String airbyteVersion,
Expand Down

0 comments on commit f63066a

Please sign in to comment.