Skip to content

Commit e9a6702

Browse files
authored
Wait for config volume to be ready (#4835)
* Do not create config directory in fs persistence construction * Run kube acceptance test only for testing purpose * Wait for config volume to be ready * Move config volume wait for fs persistence construction * Restore ci workflow * Prune imports
1 parent 35806d9 commit e9a6702

File tree

4 files changed

+27
-37
lines changed

4 files changed

+27
-37
lines changed

airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/ConfigPersistenceBuilder.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.airbyte.db.Database;
3232
import io.airbyte.db.Databases;
3333
import java.io.IOException;
34-
import java.nio.file.Path;
3534
import org.slf4j.Logger;
3635
import org.slf4j.LoggerFactory;
3736

@@ -55,14 +54,14 @@ public class ConfigPersistenceBuilder {
5554
/**
5655
* Create a db config persistence and setup the database, including table creation and data loading.
5756
*/
58-
public static ConfigPersistence getAndInitializeDbPersistence(Configs configs) throws IOException {
57+
public static ConfigPersistence getAndInitializeDbPersistence(Configs configs) throws IOException, InterruptedException {
5958
return new ConfigPersistenceBuilder(configs, true).create();
6059
}
6160

6261
/**
6362
* Create a db config persistence without setting up the database.
6463
*/
65-
public static ConfigPersistence getDbPersistence(Configs configs) throws IOException {
64+
public static ConfigPersistence getDbPersistence(Configs configs) throws IOException, InterruptedException {
6665
return new ConfigPersistenceBuilder(configs, false).create();
6766
}
6867

@@ -71,20 +70,14 @@ public static ConfigPersistence getDbPersistence(Configs configs) throws IOExcep
7170
* database config persistence and copy the configs from the file-based config persistence.
7271
* Otherwise, seed the database from the yaml files.
7372
*/
74-
ConfigPersistence create() throws IOException {
73+
ConfigPersistence create() throws IOException, InterruptedException {
7574
// Uncomment this branch in a future version when config volume is removed.
7675
// if (configs.getConfigRoot() == null) {
7776
// return getDbPersistenceWithYamlSeed();
7877
// }
7978
return getDbPersistenceWithFileSeed();
8079
}
8180

82-
ConfigPersistence getFileSystemPersistence() throws IOException {
83-
Path configRoot = configs.getConfigRoot();
84-
LOGGER.info("Use file system config persistence (root: {})", configRoot);
85-
return FileSystemConfigPersistence.createWithValidation(configRoot);
86-
}
87-
8881
/**
8982
* Create the database config persistence and load it with the initial seed from the YAML seed files
9083
* if the database should be initialized.
@@ -99,10 +92,9 @@ ConfigPersistence getDbPersistenceWithYamlSeed() throws IOException {
9992
* Create the database config persistence and load it with the existing configs from the file system
10093
* config persistence if the database should be initialized.
10194
*/
102-
ConfigPersistence getDbPersistenceWithFileSeed() throws IOException {
95+
ConfigPersistence getDbPersistenceWithFileSeed() throws IOException, InterruptedException {
10396
LOGGER.info("Creating db-based config persistence, and loading seed and existing data from files");
104-
Path configRoot = configs.getConfigRoot();
105-
ConfigPersistence fsConfigPersistence = FileSystemConfigPersistence.createWithValidation(configRoot);
97+
ConfigPersistence fsConfigPersistence = FileSystemConfigPersistence.createWithValidation(configs.getConfigRoot());
10698
return getDbPersistence(fsConfigPersistence);
10799
}
108100

airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/FileSystemConfigPersistence.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
public class FileSystemConfigPersistence implements ConfigPersistence {
4848

4949
private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemConfigPersistence.class);
50-
private static final String CONFIG_DIR = "config";
50+
public static final String CONFIG_DIR = "config";
5151
private static final String TMP_DIR = "tmp_storage";
52+
private static final int INTERVAL_WAITING_SECONDS = 3;
5253

5354
private static final Object lock = new Object();
5455

@@ -57,14 +58,24 @@ public class FileSystemConfigPersistence implements ConfigPersistence {
5758
// root for where configs are stored
5859
private final Path configRoot;
5960

60-
public static ConfigPersistence createWithValidation(final Path storageRoot) throws IOException {
61+
public static ConfigPersistence createWithValidation(final Path storageRoot) throws InterruptedException {
62+
LOGGER.info("Constructing file system config persistence (root: {})", storageRoot);
63+
64+
Path configRoot = storageRoot.resolve(CONFIG_DIR);
65+
int totalWaitingSeconds = 0;
66+
while (!Files.exists(configRoot)) {
67+
LOGGER.warn("Config volume is not ready yet (waiting time: {} s)", totalWaitingSeconds);
68+
Thread.sleep(INTERVAL_WAITING_SECONDS * 1000);
69+
totalWaitingSeconds += INTERVAL_WAITING_SECONDS;
70+
}
71+
LOGGER.info("Config volume is ready (waiting time: {} s)", totalWaitingSeconds);
72+
6173
return new ValidatingConfigPersistence(new FileSystemConfigPersistence(storageRoot));
6274
}
6375

64-
public FileSystemConfigPersistence(final Path storageRoot) throws IOException {
76+
public FileSystemConfigPersistence(final Path storageRoot) {
6577
this.storageRoot = storageRoot;
6678
this.configRoot = storageRoot.resolve(CONFIG_DIR);
67-
Files.createDirectories(configRoot);
6879
}
6980

7081
@Override

airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/ConfigPersistenceBuilderTest.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,6 @@ public void testCreateDbPersistenceWithoutSetupDatabase() throws Exception {
155155
dbPersistence.dumpConfigs());
156156
}
157157

158-
@Test
159-
public void testCreateFileSystemConfigPersistence() throws Exception {
160-
Path testRoot = Path.of("/tmp/cpf_test_file_system");
161-
Path rootPath = Files.createTempDirectory(Files.createDirectories(testRoot), ConfigPersistenceBuilderTest.class.getName());
162-
ConfigPersistence seedPersistence = new FileSystemConfigPersistence(rootPath);
163-
writeSource(seedPersistence, SOURCE_GITHUB);
164-
writeDestination(seedPersistence, DESTINATION_S3);
165-
166-
when(configs.getConfigRoot()).thenReturn(rootPath);
167-
168-
ConfigPersistence filePersistence = new ConfigPersistenceBuilder(configs, false).getFileSystemPersistence();
169-
assertSameConfigDump(seedPersistence.dumpConfigs(), filePersistence.dumpConfigs());
170-
}
171-
172158
/**
173159
* This test mimics the file -> db config persistence migration process.
174160
*/
@@ -187,10 +173,11 @@ public void testMigrateFromFileToDbPersistence() throws Exception {
187173

188174
// first run uses file system config persistence, and adds an extra workspace
189175
Path testRoot = Path.of("/tmp/cpf_test_migration");
190-
Path rootPath = Files.createTempDirectory(Files.createDirectories(testRoot), ConfigPersistenceBuilderTest.class.getName());
191-
when(configs.getConfigRoot()).thenReturn(rootPath);
176+
Path storageRoot = Files.createTempDirectory(Files.createDirectories(testRoot), ConfigPersistenceBuilderTest.class.getName());
177+
Files.createDirectories(storageRoot.resolve(FileSystemConfigPersistence.CONFIG_DIR));
178+
when(configs.getConfigRoot()).thenReturn(storageRoot);
192179

193-
ConfigPersistence filePersistence = new ConfigPersistenceBuilder(configs, false).getFileSystemPersistence();
180+
ConfigPersistence filePersistence = FileSystemConfigPersistence.createWithValidation(storageRoot);
194181

195182
filePersistence.replaceAllConfigs(seedConfigs, false);
196183
filePersistence.writeConfig(ConfigSchema.STANDARD_WORKSPACE, extraWorkspace.getWorkspaceId().toString(), extraWorkspace);

airbyte-server/src/test/java/io/airbyte/server/migration/RunMigrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testRunMigration() {
117117
}
118118
}
119119

120-
private void assertPreMigrationConfigs(Path configRoot, JobPersistence jobPersistence) throws IOException, JsonValidationException {
120+
private void assertPreMigrationConfigs(Path configRoot, JobPersistence jobPersistence) throws Exception {
121121
assertDatabaseVersion(jobPersistence, INITIAL_VERSION);
122122
ConfigRepository configRepository = new ConfigRepository(FileSystemConfigPersistence.createWithValidation(configRoot));
123123
Map<String, StandardSourceDefinition> sourceDefinitionsBeforeMigration = configRepository.listStandardSources().stream()
@@ -132,7 +132,7 @@ private void assertDatabaseVersion(JobPersistence jobPersistence, String version
132132
assertEquals(versionFromDb.get(), version);
133133
}
134134

135-
private void assertPostMigrationConfigs(Path importRoot) throws IOException, JsonValidationException, ConfigNotFoundException {
135+
private void assertPostMigrationConfigs(Path importRoot) throws Exception {
136136
final ConfigRepository configRepository = new ConfigRepository(FileSystemConfigPersistence.createWithValidation(importRoot));
137137
final StandardSyncOperation standardSyncOperation = assertSyncOperations(configRepository);
138138
assertStandardSyncs(configRepository, standardSyncOperation);
@@ -293,7 +293,7 @@ private void assertDestinations(ConfigRepository configRepository) throws JsonVa
293293
}
294294
}
295295

296-
private void runMigration(JobPersistence jobPersistence, Path configRoot) throws IOException {
296+
private void runMigration(JobPersistence jobPersistence, Path configRoot) throws Exception {
297297
try (RunMigration runMigration = new RunMigration(
298298
INITIAL_VERSION,
299299
jobPersistence,

0 commit comments

Comments
 (0)