Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priortisation Manager Interface and FCFS Implementation #3042

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

aga9900
Copy link
Contributor

@aga9900 aga9900 commented Mar 18, 2025

Summary

Interface for Prioritisation Manager.
Implementation of FCFS Priotisation Manager

Testing Done

Test Cases

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the file FileCopyBasedReplicationManager*

@@ -0,0 +1,75 @@
package com.github.ambry.replica.prioritization;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add copyright stub

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applicable to all new files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import java.util.concurrent.ConcurrentHashMap;


public class FCFSPrioritizationManager implements PrioritizationManager{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments on methods and ensure checkstyle (an extra line at L17, a space between PrioritizationManager{) etc


private final ConcurrentHashMap<DiskId, List<ReplicaId>> diskToReplicaMap;
public FCFSPrioritizationManager() {
isRunning = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be set in the init step for this prop as well.
private boolean isRunning = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed altogether. Removing it.

private final ConcurrentHashMap<DiskId, List<ReplicaId>> diskToReplicaMap;
public FCFSPrioritizationManager() {
isRunning = false;
diskToReplicaMap = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, as above. Can be done within the init step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is happening inside the Constructor. So, happening as part of init only.

ExecutorService executor = Executors.newFixedThreadPool(10);
for(int diskIndex=1; diskIndex <= 10;diskIndex++){
int finalDiskIndex = diskIndex;
int finalDiskIndex1 = diskIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet is not clear on what is it trying to do.
Why do we have finalDiskIndex and finalDiskIndex1 ?

Add comments to explain the test logic, expectation etc.

}

@Override
public List<ReplicaId> getPartitionListForDisk(DiskId diskId, int numberOfReplicasPerDisk) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add null check for diskId, checks for numberOfReplicasPerDisk (Cant be <=0 etc)

return null;
LinkedList<ReplicaId> listsToReturn = new LinkedList<>();

for( int index = 0; index < Math.min(numberOfReplicasPerDisk, replicaListForDisk.size());index++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precompute Math.min(numberOfReplicasPerDisk, replicaListForDisk.size())
Doing this in the for loop is wasteful as it'll be evaluated in every iteration of the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


for( int index = 0; index < Math.min(numberOfReplicasPerDisk, replicaListForDisk.size());index++){
listsToReturn.add(replicaListForDisk.get(index));
replicaListForDisk.remove(index);
Copy link
Contributor

@DevenAhluwalia DevenAhluwalia Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler impl:

int limit = Math.min(numberOfReplicasPerDisk, replicaListForDisk.size());
List<ReplicaId> subList = diskToReplicaMap.get(diskId).subList(0, limit);
return subList

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this will remove the element from original list. list.subList() will only create a shallow copy.


for( int index = 0; index < Math.min(numberOfReplicasPerDisk, replicaListForDisk.size());index++){
listsToReturn.add(replicaListForDisk.get(index));
replicaListForDisk.remove(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step also removes the entry from diskToReplicaMap because of this statement-
List<ReplicaId> replicaListForDisk = diskToReplicaMap.get(diskId);

Because replicaListForDisk now holds a reference to that same list, not a copy.

@aga9900 aga9900 closed this Mar 18, 2025
@aga9900 aga9900 reopened this Mar 20, 2025
@aga9900 aga9900 marked this pull request as draft March 20, 2025 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants