Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix config init race condition #4679

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,29 @@ public void configure() {
server.join();
}

private static void setCustomerIdIfNotSet(final ConfigRepository configRepository) {
final StandardWorkspace workspace;
try {
workspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, true);

if (workspace.getCustomerId() == null) {
final UUID customerId = UUID.randomUUID();
LOGGER.info("customerId not set for workspace. Setting it to " + customerId);
workspace.setCustomerId(customerId);

configRepository.writeStandardWorkspace(workspace);
private static void setCustomerIdIfNotSet(final ConfigRepository configRepository) throws InterruptedException {
StandardWorkspace workspace = null;

// retry until the workspace is available / waits for file config initialization
while (workspace == null) {
try {
workspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, true);

if (workspace.getCustomerId() == null) {
final UUID customerId = UUID.randomUUID();
LOGGER.info("customerId not set for workspace. Setting it to " + customerId);
workspace.setCustomerId(customerId);

configRepository.writeStandardWorkspace(workspace);
} else {
LOGGER.info("customerId already set for workspace: " + workspace.getCustomerId());
}
} catch (ConfigNotFoundException e) {
LOGGER.error("Could not find workspace with id: " + PersistenceConstants.DEFAULT_WORKSPACE_ID, e);
Thread.sleep(1000);
} catch (JsonValidationException | IOException e) {
throw new RuntimeException(e);
}
} catch (ConfigNotFoundException e) {
throw new RuntimeException("could not find workspace with id: " + PersistenceConstants.DEFAULT_WORKSPACE_ID, e);
} catch (JsonValidationException | IOException e) {
throw new RuntimeException(e);
}
}

Expand Down