diff --git a/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java b/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java index 6fa212b3e5..c2f5d076e9 100644 --- a/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java +++ b/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java @@ -38,7 +38,7 @@ public interface StoreManager { * Build state after filecopy is completed * @param partitionName the partition id for which state is to be built.. */ - void buildStateForFileCopy(String partitionName); + void buildStateForFileCopy(ReplicaId replica); /** * Remove store from storage manager. diff --git a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java index bcc9fa87af..73da9fe19a 100644 --- a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java +++ b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java @@ -57,7 +57,7 @@ public boolean addBlobStore(ReplicaId replica) { return createAndStartBlobStoreIfAbsent(replica.getPartitionId()) != null; } @Override - public void buildStateForFileCopy(String partitionName){ + public void buildStateForFileCopy(ReplicaId replica){ // no-op } diff --git a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java index fc20ead896..4eba480c84 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java +++ b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java @@ -531,26 +531,25 @@ public boolean addBlobStore(ReplicaId replica) { return true; } @Override - public void buildStateForFileCopy(String partitionName){ - // The partition map should have the replica for the current partition since it was called in pre-file-copy step. - ReplicaId replica = partitionNameToReplicaId.get(partitionName); + public void buildStateForFileCopy(ReplicaId replica){ + PartitionId partitionId = replica.getPartitionId(); if (replica == null) { - logger.error("No existing replica found for partition {} in partitionNameToReplicaId", partitionName); + logger.error("No existing replica found for partition {} in partitionNameToReplicaId", partitionId.getId()); throw new StateTransitionException( - "Existing replica " + partitionName + " is not found in clustermap for " + currentNode, ReplicaNotFound); + "Existing replica " + partitionId.getId() + " is not found in clustermap for " + currentNode, ReplicaNotFound); } if (!addBlobStore(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 {} into storage manager", partitionName); - throw new StateTransitionException("Failed to add store " + partitionName + " into storage manager", + 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 {} at location {}. Retrying bootstrapping replica at different location", - partitionName, replica.getReplicaPath()); + logger.info("Failed to add store for replica {} at location {}. Retrying bootstrapping replica at different location", + partitionId.getId(), replica.getReplicaPath()); tryRemoveFailedBootstrapBlobStore(replica); } } diff --git a/ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java b/ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java index b2e86d054a..626033c217 100644 --- a/ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java +++ b/ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java @@ -269,6 +269,26 @@ public void scheduleAndControlCompactionTest() throws Exception { shutdownAndAssertStoresInaccessible(storageManager, replicas); } + @Test + public void buildStateForFileCopyTest() throws Exception { + generateConfigs(true, false); + MockDataNodeId localNode = clusterMap.getDataNodes().get(0); + List localReplicas = clusterMap.getReplicaIds(localNode); + int newMountPathIndex = 3; + // add new MountPath to local node + File f = File.createTempFile("ambry", ".tmp"); + File mountFile = + new File(f.getParent(), "mountpathfile" + MockClusterMap.PLAIN_TEXT_PORT_START_NUMBER + newMountPathIndex); + MockClusterMap.deleteFileOrDirectory(mountFile); + assertTrue("Couldn't create mount path directory", mountFile.mkdir()); + localNode.addMountPaths(Collections.singletonList(mountFile.getAbsolutePath())); + PartitionId newPartition1 = + new MockPartitionId(803, MockClusterMap.DEFAULT_PARTITION_CLASS, clusterMap.getDataNodes(), newMountPathIndex); + StorageManager storageManager = createStorageManager(localNode, metricRegistry, null); + storageManager.start(); + storageManager.buildStateForFileCopy(newPartition1.getReplicaIds().get(0)); + } + /** * Test add new BlobStore with given {@link ReplicaId}. */