You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/02/05 09:08:36 UTC

[GitHub] [flink] StephanEwen commented on a change in pull request #11018: [FLINK-15905][runtime] Fix race condition between allocation and release of OpaqueMemoryResource

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_r375133066
 
 

 ##########
 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:
   I would like to keep the `finally` block, because of the following:
     - It would be possibly for the "release resource" call to fail
     - if we do not release the memory back, we must fail the process, because it leaved the TM in a "corrupt" state. It would not be possible to ever use that slot again.
   
   Double releasing should not be possible, guarded by the code of `SharedResources`.
   
   For clarity, I changed the `dispose()` method to not throw an exception on "double release".

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services