From af1b9d5239a9399ae4c30572e2b5a9cead58ddb8 Mon Sep 17 00:00:00 2001 From: Jared Rhizor Date: Mon, 12 Jul 2021 16:10:08 -0700 Subject: [PATCH] fix config init race condition (#4679) --- .../java/io/airbyte/server/ServerApp.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java index ffea3cbd392b..87f7755d8472 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java @@ -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); } }