zhijiangW commented on a change in pull request #11408: 
[FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error 
handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394111632
 
 

 ##########
 File path: 
flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment 
allocateUnpooledOffHeapMemory(int size) {
         * @return A new memory segment, backed by unpooled off-heap memory.
         */
        public static MemorySegment allocateUnpooledOffHeapMemory(int size, 
Object owner) {
-               ByteBuffer memory = ByteBuffer.allocateDirect(size);
+               ByteBuffer memory;
+               try {
+                       memory = ByteBuffer.allocateDirect(size);
+               } catch (OutOfMemoryError e) {
+                       if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+                               
LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+                       }
+                       throw e;
+               }
 
 Review comment:
   Some inputs from my side: there are two usages for 
`allocateUnpooledOffHeapMemory` ATM.
   
   - One is for initializing `NetworkBufferPool` in `TaskManagerServices`, and 
it also explicitly handles the `OutOfMemoryError` message inside. Maybe we also 
want to unify the message there.
   
   - Another is for reading blocking partitions for batch jobs on upstream 
side, which is triggered by netty stack. This error would not be thrown 
outsides to be visible in task stack, and be only transported to the downstream 
side via network to cause the respective task failure. It also makes sense to 
handle this special error on upstream side, to make processor exit if possible. 
Otherwise the same error might happen again after failover recovery.

----------------------------------------------------------------
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

Reply via email to