void persistAccountMap(Collection<Account> accounts, int version, long modifiedTimeInSec) {
    if (backupDirPath == null) {
      return;
    }
    Objects.requireNonNull(accounts, "Invalid account collection");
    if (backupFileInfos.containsKey(version)) {
      logger.trace("Version {} already has a backup file {}, skip persisting the state", version,
          backupFileInfos.get(version).getFilename());
      return;
    }
    if (!backupFileInfos.isEmpty() && backupFileInfos.firstEntry().getKey() > version) {
      logger.error("Version {} is out of date, the smallest version is {}", version,
          backupFileInfos.firstEntry().getKey());
      return;
    }

    String fileName = getBackupFilename(version, modifiedTimeInSec);
    String tempFileName = fileName + SEP + TEMP_FILE_SUFFIX;
    Path filePath = backupDirPath.resolve(fileName);
    Path tempFilePath = backupDirPath.resolve(tempFileName);

    long startTimeInMs = System.currentTimeMillis();
    try {
      writeAccountsToFile(tempFilePath, accounts);
      Files.move(tempFilePath, filePath);
    } catch (IOException e) {
      logger.error("Failed to persist state to file: {}", fileName, e);
      accountServiceMetrics.backupErrorCount.inc();
      return;
    }
    accountServiceMetrics.backupWriteTimeInMs.update(System.currentTimeMillis() - startTimeInMs);

    while (backupFileInfos.size() >= maxBackupFileCount) {
      Map.Entry<Integer, BackupFileInfo> entry = backupFileInfos.firstEntry();
      tryDeleteBackupFile(entry.getValue());
      backupFileInfos.remove(entry.getKey());
    }
    backupFileInfos.put(version, new BackupFileInfo(version, fileName, modifiedTimeInSec));
  }
Persist account map to local storage, with associated version and modified time information.
@param accounts The account collection
@param version The version of the account
@param modifiedTimeInSec modified time in seconds
ambry-account/src/main/java/com/github/ambry/account/BackupFileManager.java