Skip to content

Commit

Permalink
Added test for state build and changed method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jai Balani committed Dec 11, 2024
1 parent 613a104 commit b608e52
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplicaId> 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}.
*/
Expand Down

0 comments on commit b608e52

Please sign in to comment.