@Override
    public ZNRecord update(ZNRecord recordFromZk) {
      ZNRecord recordToUpdate;
      if (recordFromZk == null) {
        logger.info(
            "ZNRecord does not exist on path={} in HelixPropertyStore when updating accounts. Creating a new ZNRecord.",
            FULL_ACCOUNT_METADATA_PATH);
        recordToUpdate = new ZNRecord(ZN_RECORD_ID);
      } else {
        recordToUpdate = recordFromZk;
      }
      Map<String, String> accountMap = recordToUpdate.getMapField(ACCOUNT_METADATA_MAP_KEY);
      if (accountMap == null) {
        logger.info("AccountMap does not exist in ZNRecord when updating accounts. Creating a new accountMap");
        accountMap = new HashMap<>();
      }

      AccountInfoMap remoteAccountInfoMap;
      String errorMessage = null;
      try {
        remoteAccountInfoMap = new AccountInfoMap(accountServiceMetrics, accountMap);
      } catch (JSONException e) {
        // Do not depend on Helix to log, so log the error message here.
        accountServiceMetrics.remoteDataCorruptionErrorCount.inc();
        errorMessage = "Exception occurred when building AccountInfoMap from accountMap " + accountMap;
        logger.error(errorMessage, e);
        throw new IllegalStateException(errorMessage, e);
      }

      // if there is any conflict with the existing record, fail the update. Exception thrown in this updater will
      // be caught by Helix and helixStore#update will return false.
      if (remoteAccountInfoMap.hasConflictingAccount(accountsToUpdate, config.ignoreVersionMismatch)) {
        // Throw exception, so that helixStore can capture and terminate the update operation
        errorMessage = "Updating accounts failed because one account to update conflicts with existing accounts";
        logger.error(errorMessage);
        throw new IllegalArgumentException(errorMessage);
      } else {
        for (Account account : accountsToUpdate) {
          try {
            String accountJsonStr = objectMapper.writeValueAsString(
                new AccountBuilder(account).snapshotVersion(account.getSnapshotVersion() + 1).build());
            accountMap.put(String.valueOf(account.getId()), accountJsonStr);
          } catch (Exception e) {
            errorMessage = "Updating accounts failed because unexpected exception occurred when updating accountId="
                + account.getId() + " accountName=" + account.getName();
            logger.error(errorMessage, e);
            throw new IllegalStateException(errorMessage, e);
          }
        }
        recordToUpdate.setMapField(ACCOUNT_METADATA_MAP_KEY, accountMap);
        return recordToUpdate;
      }
    }
@param accountsToUpdate The {@link Account}s to update.
ambry-account/src/main/java/com/github/ambry/account/LegacyMetadataStore.java