Package com.linkedin.venice.helix
Class ResourceAssignment
- java.lang.Object
-
- com.linkedin.venice.helix.ResourceAssignment
-
public class ResourceAssignment extends java.lang.Object
Assignments for all of resources. This is NOT a thread-safe class. But in our use case, there is no any concurrent operations to assignments. So here we only use volatile resourceToAssignmentsMap to ensure the reference is up to date. N.B.: This class seems to have thread safety issues. TheupdateResourceAssignment(ResourceAssignment)
function swaps theresourceToAssignmentsMap
to another reference, and the two callers of that function wrap its invocation within locks. However, there are many other code paths which perform lock-free accesses to the same map across two functions:containsResource(String)
andgetPartitionAssignment(String)
. These other code paths first check if the resource is contained, then if it is, they get it. But there is no guarantee that the reference to the map is the same, sinceupdateResourceAssignment(ResourceAssignment)
could have been called in between. Ideally, we would eliminate this "contains, then get" pattern entirely, and instead rely on a single invocation to get the resource (which should be allowed to return null, rather than throw when absent); then the caller can use a null check as the equivalent of today's contains check, which would make the operation atomic and thus impossible to interleave withupdateResourceAssignment(ResourceAssignment)
. TODO: refactor this.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceAssignment.ResourceAssignmentChanges
-
Constructor Summary
Constructors Constructor Description ResourceAssignment()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
containsResource(java.lang.String resource)
Deprecated.java.util.Set<java.lang.String>
getAssignedResources()
Partition
getPartition(java.lang.String resource, int partitionId)
PartitionAssignment
getPartitionAssignment(java.lang.String resource)
TODO: Rename this "getPartitionAssignmentOrThrow", and create an equivalent which returns null when absent.void
setPartitionAssignment(java.lang.String resource, PartitionAssignment partitionAssignment)
ResourceAssignment.ResourceAssignmentChanges
updateResourceAssignment(ResourceAssignment newAssignment)
Calculate resource assignment changes between the current one and the given one and also swap the current assignment to the given one in the end
-
-
-
Method Detail
-
getPartitionAssignment
public PartitionAssignment getPartitionAssignment(java.lang.String resource)
TODO: Rename this "getPartitionAssignmentOrThrow", and create an equivalent which returns null when absent.
-
setPartitionAssignment
public void setPartitionAssignment(java.lang.String resource, PartitionAssignment partitionAssignment)
-
getPartition
public Partition getPartition(java.lang.String resource, int partitionId)
-
containsResource
@Deprecated public boolean containsResource(java.lang.String resource)
Deprecated.TODO: Delete this function entirely, to avoid the "contains, then get" anti-pattern.
-
getAssignedResources
public java.util.Set<java.lang.String> getAssignedResources()
-
updateResourceAssignment
public ResourceAssignment.ResourceAssignmentChanges updateResourceAssignment(ResourceAssignment newAssignment)
Calculate resource assignment changes between the current one and the given one and also swap the current assignment to the given one in the end- Parameters:
newAssignment
- the given resource assignment- Returns:
- the changes between 2 assignments
-
-