private void tryRemoveHostFromAccountStatsStore(DataNodeId removedDataNode) {
      String resource =
          "%s_%s_%d".format(LOCK_RESOURCE_PREFIX + removedDataNode.getHostname(), removedDataNode.getPort());
      try {
        DistributedLock lock = clusterParticipant.getDistributedLock(resource, "AccountStatsStoreRemoval");
        if (lock.tryLock()) {
          logger.info("Acquired distributed lock for host removal: {}_{}", removedDataNode.getHostname(),
              removedDataNode.getPort());
          try {
            accountStatsStore.deleteHostAccountStorageStatsForHost(removedDataNode.getHostname(),
                removedDataNode.getPort());
            logger.info("Successfully removed host {}_{} from account stats store", removedDataNode.getHostname(),
                removedDataNode.getPort());
          } catch (Exception e) {
            logger.error("Failed to remove host {}_{} from account stats store", removedDataNode.getHostname(),
                removedDataNode.getPort(), e);
          } finally {
            lock.unlock();
            lock.close();
          }
        } else {
          logger.info("Failed to acquire distributed lock for host removal: {}_{}", removedDataNode.getHostname(),
              removedDataNode.getPort());
        }
      } catch (Throwable t) {
        logger.error("Failed to execute the removal task", t);
      }
    }
An implementation of {@link ClusterMapChangeListener} to listen on the data node removal.
ambry-server/src/main/java/com/github/ambry/server/StatsManager.java