public void buildStateForFileCopy(ReplicaId replica) {
    if (replica == null) {
      logger.error("ReplicaId is null");
      throw new StateTransitionException("ReplicaId null is not found in clustermap for " + currentNode,
          ReplicaNotFound);
    }
    PartitionId partitionId = replica.getPartitionId();

    if (!addBlobStoreForFileCopy(replica)) {
      // We have decreased the available disk space in HelixClusterManager#getDiskForBootstrapReplica. Increase it
      // back since addition of store failed.
      replica.getDiskId().increaseAvailableSpaceInBytes(replica.getCapacityInBytes());
      if (!clusterMap.isDataNodeInFullAutoMode(currentNode)) {
        logger.error("Failed to add store for replica {} into storage manager", partitionId.getId());
        throw new StateTransitionException(
            "Failed to add store for replica " + partitionId.getId() + " into storage manager",
            ReplicaOperationFailure);
      } else {
        logger.info("Failed to add store for replica {} at location {}. Cleanup and raise StateTransitionException",
            partitionId.getId(), replica.getReplicaPath());
        // This will remove the reserved space from diskSpaceAllocator
        tryRemoveFailedBootstrapBlobStore(replica);
        // Throwing StateTransitionException here since we cannot retry adding BlobStore since Filecopy has copied data
        // into the selected disk itself. Hence, putting the replica into ERROR state via StateTransitionException
        throw new StateTransitionException(
            "Failed to add store for replica " + partitionId.getId() + " into storage manager",
            ReplicaOperationFailure);
      }
    }
    Store store = getStore(replica.getPartitionId(), false);
    // Only update store state if this is a state transition for primary participant. Since replication Manager
    // which eventually moves this state to STANDBY/LEADER only listens to primary participant, store state gets
    // stuck in BOOTSTRAP if this is updated by second participant listener too
    ReplicaState currentState = store.getCurrentState();
    if (currentState != ReplicaState.LEADER && currentState != ReplicaState.STANDBY) {
      // Only set the current state to BOOTSTRAP when it's not LEADER or STANDBY
      store.setCurrentState(ReplicaState.BOOTSTRAP);
    }
  }
Build in-memory state for file copy based replication post filecopy is completed.
@param replicaId the {@link ReplicaId} of the {@link Store} for which store needs to be built
ambry-store/src/main/java/com/github/ambry/store/StorageManager.java