sodonnel commented on code in PR #4955:
URL: https://github.com/apache/ozone/pull/4955#discussion_r1238690687
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableECContainerProvider.java:
##########
@@ -150,21 +153,70 @@ public ContainerInfo getContainer(final long size,
}
}
}
+
// If we get here, all the pipelines we tried were no good. So try to
// allocate a new one.
+ container = allocateContainerIfWithinLimit(
+ maximumPipelines, openPipelineCount, true,
+ repConfig, size, owner, excludeList);
+
+ if (container != null) {
+ return container;
+ }
+
+ String msg = "Unable to allocate a pipeline for " + repConfig + ":"
+ + " the maximum of " + maximumPipelines + " has been reached";
+ if (openPipelineCount > 0) {
+ msg += ", and none of the " + openPipelineCount
+ + " existing ones are suitable";
+ }
+
+ throw new IOException(msg);
+ }
+
+ @Nullable
+ private ContainerInfo allocateContainerIfWithinLimit(
+ int max, int current, boolean finalAttempt,
+ ECReplicationConfig repConfig, long size, String owner,
+ ExcludeList excludeList) throws IOException, TimeoutException {
+
+ final String msg = "Unable to allocate a container for {} as {} existing "
+ + "containers and {} pending allocations have reached the limit of {}";
+
+ final int pending = pendingAllocations.getAndIncrement();
try {
- synchronized (this) {
- if (openPipelineCount < maximumPipelines) {
- return allocateContainer(repConfig, size, owner, excludeList);
+ if (current + pending < max) {
+ ContainerInfo containerInfo =
+ allocateContainer(repConfig, size, owner, excludeList);
+ allocation.signal();
Review Comment:
Is there a potential race condition here?
Say we are 1 off the max, and 1 pipline is pending create.
Another thread falls into the "else if". Just before it calls
`allocation.await()` the previous allocation completes and calls
allocation.signal().
Then the "other thread" will get blocked on allocation.await() with nothing
to wake it up?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]