-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PARQUET-1485: Fix Snappy direct memory leak #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gszadovszky
merged 8 commits into
apache:master
from
liupc:Fix-Snappy-direct-memory-leak
Feb 12, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8dcd0ea
Fix direct memory leak
d75c8e4
Use reflection for cleaning DirectBuffer to fix java9+ incompatibility
238b149
Add CleanUtil
b4a249f
Update log and Refine initial buffer size
b26a9f4
Fix OutputBuffer should be empty check
03467dd
Updated as comment
14e301c
Minor fix
b553464
Return immediately when cleanerField or cleanMethod is null
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/codec/CleanUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.parquet.hadoop.codec; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * A Helper class which use reflections to clean up DirectBuffer. It's implemented for | ||
| * better compatibility with both java8 and java9+, because the Cleaner class is moved to | ||
| * another place since java9+. | ||
| */ | ||
| public class CleanUtil { | ||
| private static final Logger logger = LoggerFactory.getLogger(CleanUtil.class); | ||
| private static final Field CLEANER_FIELD; | ||
| private static final Method CLEAN_METHOD; | ||
|
|
||
| static { | ||
| ByteBuffer buf = null; | ||
| Field cleanerField = null; | ||
| Method cleanMethod = null; | ||
| try { | ||
| buf = ByteBuffer.allocateDirect(1); | ||
| cleanerField = buf.getClass().getDeclaredField("cleaner"); | ||
| cleanerField.setAccessible(true); | ||
| Object cleaner = cleanerField.get(buf); | ||
| cleanMethod = cleaner.getClass().getDeclaredMethod("clean"); | ||
| } catch (NoSuchFieldException | NoSuchMethodException | IllegalAccessException e) { | ||
| logger.warn("Initialization failed for cleanerField or cleanMethod", e); | ||
| } finally { | ||
| clean(buf); | ||
gszadovszky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| CLEANER_FIELD = cleanerField; | ||
| CLEAN_METHOD = cleanMethod; | ||
| } | ||
|
|
||
| public static void clean(ByteBuffer buffer) { | ||
| if (CLEANER_FIELD == null || CLEAN_METHOD == null) { | ||
| return; | ||
| } | ||
| try { | ||
| Object cleaner = CLEANER_FIELD.get(buffer); | ||
| CLEAN_METHOD.invoke(cleaner); | ||
| } catch (IllegalAccessException | InvocationTargetException | NullPointerException e) { | ||
| // Ignore clean failure | ||
| logger.warn("Clean failed for buffer " + buffer.getClass().getSimpleName(), e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.