Skip to content

Commit

Permalink
fix config init race condition (#4679)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhizor authored and gl-pix committed Jul 22, 2021
1 parent 0150c03 commit af1b9d5
Showing 1 changed file with 22 additions and 15 deletions.
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 @@ -174,22 +174,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

0 comments on commit af1b9d5

Please sign in to comment.