-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARQUET-2432: Use ByteBufferAllocator over hardcoded heap allocation (#…
…1278) * PARQUET-2432: Use ByteBufferAllocator over hardcoded heap allocation * Updated BytesInput implementations to rely on a ByteBufferAllocator instance for allocating/releasing ByteBuffer objects. * Extend the usage of a ByteBufferAllocator instead of the hardcoded usage of heap (e.g. byte[], ByteBuffer.allocate etc.) * parquet-cli related code parts including ParquetRewriter and tests are not changed in this effort * Reuse temporary ByteBuffer instead of keep allocating/releasing
- Loading branch information
1 parent
d839608
commit 274dc51
Showing
34 changed files
with
1,549 additions
and
159 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
62 changes: 62 additions & 0 deletions
62
parquet-common/src/main/java/org/apache/parquet/bytes/ByteBufferReleaser.java
This file contains 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,62 @@ | ||
/* | ||
* 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.bytes; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Convenient class for releasing {@link java.nio.ByteBuffer} objects with the corresponding allocator; | ||
*/ | ||
public class ByteBufferReleaser implements AutoCloseable { | ||
|
||
final ByteBufferAllocator allocator; | ||
private final List<ByteBuffer> toRelease = new ArrayList<>(); | ||
|
||
/** | ||
* Constructs a new {@link ByteBufferReleaser} instance with the specified {@link ByteBufferAllocator} to be used for | ||
* releasing the buffers in {@link #close()}. | ||
* | ||
* @param allocator the allocator to be used for releasing the buffers | ||
* @see #releaseLater(ByteBuffer) | ||
* @see #close() | ||
*/ | ||
public ByteBufferReleaser(ByteBufferAllocator allocator) { | ||
this.allocator = allocator; | ||
} | ||
|
||
/** | ||
* Adds a {@link ByteBuffer} object to the list of buffers to be released at {@link #close()}. The specified buffer | ||
* shall be one that was allocated by the {@link ByteBufferAllocator} of this object. | ||
* | ||
* @param buffer the buffer to be released | ||
*/ | ||
public void releaseLater(ByteBuffer buffer) { | ||
toRelease.add(buffer); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
for (ByteBuffer buf : toRelease) { | ||
allocator.release(buf); | ||
} | ||
toRelease.clear(); | ||
} | ||
} |
Oops, something went wrong.