/** * @param accountsToUpdate The {@link Account}s to update. */ ZkUpdater(Collection<Account> accountsToUpdate) { this.accountsToUpdate = accountsToUpdate; Pair<String, Path> backupPrefixAndPath = null; if (backupDirPath != null) { try { backupPrefixAndPath = reserveBackupFile(); } catch (IOException e) { logger.error("Error reserving backup file", e); } } this.backupPrefixAndPath = backupPrefixAndPath; }
/** * Save the zookeeper state from after the update to disk. This will only save the file if the update succeeded * and the old state backup file was successfully reserved. * The following file name format will be used: {@code {yyyyMMdd}T{HHmmss}.{unique long}.new}. * @param succeeded {@code true} iff the update succeeded. */ void maybePersistNewState(boolean succeeded) { if (backupPrefixAndPath != null && succeeded) { try { Path filepath = backupDirPath.resolve(backupPrefixAndPath.getFirst() + NEW_STATE_SUFFIX); writeBackup(filepath, potentialNewState); } catch (Exception e) { logger.error("Could not write new state backup file", e); accountServiceMetrics.backupErrorCount.inc(); } } }
accountServiceMetrics.updateAccountErrorCount.inc(); } else { ZkUpdater zkUpdater = new ZkUpdater(accounts); hasSucceeded = helixStore.update(FULL_ACCOUNT_METADATA_PATH, zkUpdater, AccessOption.PERSISTENT); zkUpdater.maybePersistNewState(hasSucceeded);
throw new IllegalStateException("Exception occurred when building AccountInfoMap from accountMap", e); maybePersistOldState(accountMap);
/** * Save the zookeeper state from before the update to disk. * The following file name format will be used: {@code {yyyyMMdd}T{HHmmss}.{unique long}.old}. * If there are multiple files with the same timestamp, the unique long will prevent the file names from clashing. */ private void maybePersistOldState(Map<String, String> oldState) { if (backupPrefixAndPath != null) { try { writeBackup(backupPrefixAndPath.getSecond(), oldState); } catch (Exception e) { logger.error("Could not write previous state backup file", e); accountServiceMetrics.backupErrorCount.inc(); } } }