StephanEwen commented on a change in pull request #11018:
[FLINK-15905][runtime] Fix race condition between allocation and release of
OpaqueMemoryResource
URL: https://github.com/apache/flink/pull/11018#discussion_r375185846
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/memory/SharedResources.java
##########
@@ -80,27 +81,37 @@
}
}
+ /**
+ * Releases a lease (identified by the lease holder object) for the
given type.
+ * If no further leases exist, the resource is disposed.
+ */
+ void release(String type, Object leaseHolder) throws Exception {
+ release(type, leaseHolder, (value) -> {});
+ }
+
/**
* Releases a lease (identified by the lease holder object) for the
given type.
* If no further leases exist, the resource is disposed.
*
- * @return True, if this was the last lease holder and the resource was
disposed.
+ * <p>This method takes an additional hook that is called when the
resource is disposed.
*/
- boolean release(String type, Object leaseHolder) throws Exception {
+ void release(String type, Object leaseHolder, Consumer<Long> releaser)
throws Exception {
lock.lock();
try {
- final LeasedResource resource =
reservedResources.get(type);
+ final LeasedResource<?> resource =
reservedResources.get(type);
if (resource == null) {
- return false;
+ return;
}
if (resource.removeLeaseHolder(leaseHolder)) {
- reservedResources.remove(type);
- resource.dispose();
- return true;
+ try {
+ reservedResources.remove(type);
+ resource.dispose();
+ }
+ finally {
+ releaser.accept(resource.size());
+ }
Review comment:
The double release of the "reservation" is actually guarded twice:
- `if (resource.removeLeaseHolder(leaseHolder))`: Only the last release of
a lease can trigger that.
- The memory manager itself has this under an "owner", so if no memory is
reserved under that owner, none can be released.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services