-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What changes are proposed in this pull request? ![image](https://github.com/user-attachments/assets/9230d1fb-c522-4d21-b382-9e06dc9d83ee) ### Why are the changes needed? To check the file integrity ### Does this PR introduce any user facing changes? Add a crc64 check cli pr-link: #18682 change-id: cid-4eb62e603591f3235b92e4191c5b511b534f6fc3
- Loading branch information
Showing
21 changed files
with
1,133 additions
and
11 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
74 changes: 74 additions & 0 deletions
74
core/common/src/main/java/alluxio/network/protocol/databuffer/NioHeapBufferPool.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,74 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.network.protocol.databuffer; | ||
|
||
import alluxio.exception.runtime.ResourceExhaustedRuntimeException; | ||
import alluxio.retry.RetryPolicy; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.LinkedList; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Heap buffer pool. | ||
*/ | ||
public class NioHeapBufferPool { | ||
private static final TreeMap<Integer, LinkedList<ByteBuffer>> BUF_POOL = new TreeMap<>(); | ||
|
||
/** | ||
* @param length | ||
* @return buffer | ||
*/ | ||
public static synchronized ByteBuffer acquire(int length) { | ||
Map.Entry<Integer, LinkedList<ByteBuffer>> entry = BUF_POOL.ceilingEntry(length); | ||
if (entry == null || entry.getValue().size() == 0) { | ||
return ByteBuffer.allocate(length); | ||
} | ||
ByteBuffer buffer = entry.getValue().pop(); | ||
buffer.clear(); | ||
// the buffer probably is larger than the amount of capacity being requested | ||
// need to set the limit explicitly | ||
buffer.limit(length); | ||
return buffer; | ||
} | ||
|
||
/** | ||
* @param length | ||
* @param policy the retry policy to use | ||
* @return buffer | ||
*/ | ||
public static synchronized ByteBuffer acquire(int length, RetryPolicy policy) { | ||
Error cause = null; | ||
while (policy.attempt()) { | ||
try { | ||
return acquire(length); | ||
} catch (OutOfMemoryError error) { | ||
cause = error; | ||
} | ||
} | ||
throw new ResourceExhaustedRuntimeException("Not enough heap memory allocated to buffer", | ||
cause, false); | ||
} | ||
|
||
/** | ||
* @param buffer | ||
*/ | ||
public static synchronized void release(ByteBuffer buffer) { | ||
LinkedList<ByteBuffer> bufList = BUF_POOL.get(buffer.capacity()); | ||
if (bufList == null) { | ||
bufList = new LinkedList<>(); | ||
BUF_POOL.put(buffer.capacity(), bufList); | ||
} | ||
bufList.push(buffer); | ||
} | ||
} |
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
Oops, something went wrong.