Package com.linkedin.venice.helix
Class ResourceAssignment
java.lang.Object
com.linkedin.venice.helix.ResourceAssignment
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. The
updateResourceAssignment(ResourceAssignment)
function swaps the resourceToAssignmentsMap
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)
and getPartitionAssignment(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, since updateResourceAssignment(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 with updateResourceAssignment(ResourceAssignment)
. TODO: refactor this.-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsResource
(String resource) Deprecated.getPartition
(String resource, int partitionId) getPartitionAssignment
(String resource) TODO: Rename this "getPartitionAssignmentOrThrow", and create an equivalent which returns null when absent.void
setPartitionAssignment
(String resource, PartitionAssignment partitionAssignment) 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
-
Constructor Details
-
ResourceAssignment
public ResourceAssignment()
-
-
Method Details
-
getPartitionAssignment
TODO: Rename this "getPartitionAssignmentOrThrow", and create an equivalent which returns null when absent. -
setPartitionAssignment
-
getPartition
-
containsResource
Deprecated.TODO: Delete this function entirely, to avoid the "contains, then get" anti-pattern. -
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
-