forked from apache/ozone
-
Notifications
You must be signed in to change notification settings - Fork 0
Hdds 13184 persist block size #7
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
Closed
Closed
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
c33f8e0
HDDS-13460. [Docs] S3 secret storage. (#8824)
jojochuang cc73087
HDDS-13801. [Docs] ozone s3 getsecret command and REST API supports u…
jojochuang 1b595f3
HDDS-13770. SstBackup Directory can have orphan files after bootstrap…
jojochuang 65fb295
HDDS-13639. Optimize container iterator for frequent operation (#9147)
sarvekshayr b067b70
HDDS-13834. [Ozone 2.1] Update master branch version number (#9196)
chungen0126 ddef96e
HDDS-13837. Bump jnr-posix to 3.1.21 (#9200)
dependabot[bot] 87dbdcc
HDDS-13838. Bump zstd-jni to 1.5.7-6 (#9197)
dependabot[bot] 7e8e0ad
HDDS-13836. Bump exec-maven-plugin to 3.6.2 (#9199)
dependabot[bot] 1390527
HDDS-13717. Bump Bouncy Castle to 1.82 (#9054)
dependabot[bot] 94ea432
HDDS-13839. Bump awssdk to 2.36.2 (#9198)
dependabot[bot] 798c4aa
HDDS-13843. Add Open Containers card in new UI (#9204).
spacemonkd d5be986
HDDS-13840. Reset Namespace metadata pagination when path changes (#9…
spacemonkd b39bac0
HDDS-13783. Implement locks for OmSnapshotLocalDataManager (#9140)
swamirishi 388f3d2
HDDS-13400. S3g has accumulated memory pressure due to unlimited Elas…
Gargi-jais11 2806bae
HDDS-13004. Snapshot Cache lock on a specific snapshotId (#9210)
swamirishi d4e7d94
HDDS-13167. Add example for uploading file via HttpFS (#9175)
unknowntpo 8a5c4e8
HDDS-12749. Use EnumCounters instead Map<Type, Integer> for command c…
sarvekshayr f30870f
HDDS-13841. Namespace summary API gives wrong count of directories an…
ArafatKhan2198 fb706e7
HDDS-13831. Refine set role logic in getServicelist (#9191)
symious 8bd70b7
HDDS-13833. Add transactionInfo field in SnapshotLocalData and update…
swamirishi a8b8607
HDDS-13856. Change SstFileInfo to track fileName as the name of the f…
swamirishi e2e862e
HDDS-13859. OmSnapshotLocalDataManager should handle needsDefrag flag…
swamirishi 72167cf
HDDS-13860. RocksDatabase#open leaks column family handles when faili…
smengcl c21ec5d
HDDS-13847. Introduce Snapshot Content Lock to lock table contents (#…
swamirishi 833e955
HDDS-13822. Add regression testing for OM epoch and txId calculation …
rich7420 4d6f3a5
HDDS-13772. Snapshot Paths to be re read from om checkpoint db inside…
sadanand48 1de5c2f
HDDS-13755. Add doc for ozone sh snapshot listDiff command (#9238)
rich7420 29a9d0f
HDDS-13871. Bump awssdk to 2.37.3 (#9233)
dependabot[bot] 55bd1f1
HDDS-13851. Remove extra OzoneConfiguration#of from OzoneFileSystem#i…
ivandika3 25cceef
HDDS-13872. Bump junit to 5.14.1 (#9232)
dependabot[bot] 991a291
HDDS-13485. Reduce duplication between ContainerSafeModeRule tests (#…
kousei47747 5c35ebb
HDDS-13830. Snapshot Rocks DB directory path computation based on loc…
swamirishi be8567e
HDDS-13858. Add permission check and test in getFileStatus (#9237)
rich7420 af123a5
HDDS-13640. Add CLI that allows manually triggering snapshot defrag (…
smengcl be3b828
HDDS-13823. Initial s3v volume cache entry will not be evicted until …
0lai0 bc577ae
HDDS-13868. Add unit test coverage for OMNodeDetails (#9245)
0lai0 51deb3c
HDDS-13826. Move ACL check in OMKeySetTimesRequest (#9192)
ss77892 5ab59c9
HDDS-13737. S3 ETag JSON should be quoted (#9248)
echonesis 61cf1f7
HDDS-13178. Include block size in delete request and pass it to SCM. …
priyeshkaratha 63cd56c
HDDS-13184. Persist Block Size in Delete Transaction for SCM (#8845)
ChenSammi 5cbed04
fixing errors and conflicts
priyeshkaratha 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
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
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
148 changes: 148 additions & 0 deletions
148
.../client/src/main/java/org/apache/hadoop/ozone/client/io/BoundedElasticByteBufferPool.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,148 @@ | ||
| /* | ||
| * 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.hadoop.ozone.client.io; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.ComparisonChain; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Map; | ||
| import java.util.TreeMap; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
| import org.apache.hadoop.io.ByteBufferPool; | ||
|
|
||
| /** | ||
| * A bounded version of ElasticByteBufferPool that limits the total size | ||
| * of buffers that can be cached in the pool. This prevents unbounded memory | ||
| * growth in long-lived rpc clients like S3 Gateway. | ||
| * | ||
| * When the pool reaches its maximum size, newly returned buffers are not | ||
| * added back to the pool and will be garbage collected instead. | ||
| */ | ||
| public class BoundedElasticByteBufferPool implements ByteBufferPool { | ||
| private final TreeMap<Key, ByteBuffer> buffers = new TreeMap<>(); | ||
| private final TreeMap<Key, ByteBuffer> directBuffers = new TreeMap<>(); | ||
| private final long maxPoolSize; | ||
| private final AtomicLong currentPoolSize = new AtomicLong(0); | ||
|
|
||
| /** | ||
| * A logical timestamp counter used for creating unique Keys in the TreeMap. | ||
| * This is used as the insertionTime for the Key instead of System.nanoTime() | ||
| * to guarantee uniqueness and avoid a potential spin-wait in putBuffer | ||
| * if two buffers of the same capacity are added at the same nanosecond. | ||
| */ | ||
| private long logicalTimestamp = 0; | ||
|
|
||
| public BoundedElasticByteBufferPool(long maxPoolSize) { | ||
| super(); | ||
| this.maxPoolSize = maxPoolSize; | ||
| } | ||
|
|
||
| private TreeMap<Key, ByteBuffer> getBufferTree(boolean direct) { | ||
| return direct ? this.directBuffers : this.buffers; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized ByteBuffer getBuffer(boolean direct, int length) { | ||
| TreeMap<Key, ByteBuffer> tree = this.getBufferTree(direct); | ||
| Map.Entry<Key, ByteBuffer> entry = tree.ceilingEntry(new Key(length, 0L)); | ||
| if (entry == null) { | ||
| // Pool is empty or has no suitable buffer. Allocate a new one. | ||
| return direct ? ByteBuffer.allocateDirect(length) : ByteBuffer.allocate(length); | ||
| } | ||
| tree.remove(entry.getKey()); | ||
| ByteBuffer buffer = entry.getValue(); | ||
|
|
||
| // Decrement the size because we are taking a buffer OUT of the pool. | ||
| currentPoolSize.addAndGet(-buffer.capacity()); | ||
| buffer.clear(); | ||
| return buffer; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void putBuffer(ByteBuffer buffer) { | ||
| if (buffer == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (currentPoolSize.get() + buffer.capacity() > maxPoolSize) { | ||
| // Pool is full, do not add the buffer back. | ||
| // It will be garbage collected by JVM. | ||
| return; | ||
| } | ||
|
|
||
| buffer.clear(); | ||
| TreeMap<Key, ByteBuffer> tree = getBufferTree(buffer.isDirect()); | ||
| Key key = new Key(buffer.capacity(), logicalTimestamp++); | ||
|
|
||
| tree.put(key, buffer); | ||
| // Increment the size because we have successfully added buffer back to the pool. | ||
| currentPoolSize.addAndGet(buffer.capacity()); | ||
| } | ||
|
|
||
| /** | ||
| * Get the current size of buffers in the pool. | ||
| * | ||
| * @return Current pool size in bytes | ||
| */ | ||
| @VisibleForTesting | ||
| public synchronized long getCurrentPoolSize() { | ||
| return currentPoolSize.get(); | ||
| } | ||
|
|
||
| /** | ||
| * The Key for the buffer TreeMaps. | ||
| * This is copied directly from the original ElasticByteBufferPool. | ||
| */ | ||
| protected static final class Key implements Comparable<Key> { | ||
| private final int capacity; | ||
| private final long insertionTime; | ||
|
|
||
| Key(int capacity, long insertionTime) { | ||
| this.capacity = capacity; | ||
| this.insertionTime = insertionTime; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(Key other) { | ||
| return ComparisonChain.start() | ||
| .compare(this.capacity, other.capacity) | ||
| .compare(this.insertionTime, other.insertionTime) | ||
| .result(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object rhs) { | ||
| if (rhs == null) { | ||
| return false; | ||
| } | ||
| try { | ||
| Key o = (Key) rhs; | ||
| return compareTo(o) == 0; | ||
| } catch (ClassCastException e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return new HashCodeBuilder().append(capacity).append(insertionTime) | ||
| .toHashCode(); | ||
| } | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
...ent/src/test/java/org/apache/hadoop/ozone/client/io/TestBoundedElasticByteBufferPool.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,121 @@ | ||
| /* | ||
| * 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.hadoop.ozone.client.io; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Unit tests for BoundedElasticByteBufferPool. | ||
| */ | ||
| public class TestBoundedElasticByteBufferPool { | ||
|
|
||
| private static final int MB = 1024 * 1024; | ||
| private static final long MAX_POOL_SIZE = 3L * MB; // 3MB | ||
|
|
||
| @Test | ||
| public void testLogicalTimestampOrdering() { | ||
| // Pool with plenty of capacity | ||
| BoundedElasticByteBufferPool pool = new BoundedElasticByteBufferPool(MAX_POOL_SIZE); | ||
| int bufferSize = 5 * 1024; // 5KB | ||
|
|
||
| // Create and add three distinct buffers of the same size | ||
| ByteBuffer buffer1 = ByteBuffer.allocate(bufferSize); | ||
| ByteBuffer buffer2 = ByteBuffer.allocate(bufferSize); | ||
| ByteBuffer buffer3 = ByteBuffer.allocate(bufferSize); | ||
|
|
||
| // Store their unique identity hash codes | ||
| int hash1 = System.identityHashCode(buffer1); | ||
| int hash2 = System.identityHashCode(buffer2); | ||
| int hash3 = System.identityHashCode(buffer3); | ||
|
|
||
| pool.putBuffer(buffer1); | ||
| pool.putBuffer(buffer2); | ||
| pool.putBuffer(buffer3); | ||
|
|
||
| // The pool should now contain 15KB data | ||
| Assertions.assertEquals(bufferSize * 3L, pool.getCurrentPoolSize()); | ||
|
|
||
| // Get the buffers back. They should come back in the same | ||
| // order they were put in (FIFO). | ||
| ByteBuffer retrieved1 = pool.getBuffer(false, bufferSize); | ||
| ByteBuffer retrieved2 = pool.getBuffer(false, bufferSize); | ||
| ByteBuffer retrieved3 = pool.getBuffer(false, bufferSize); | ||
|
|
||
| // Verify we got the exact same buffer instances back in FIFO order | ||
| Assertions.assertEquals(hash1, System.identityHashCode(retrieved1)); | ||
| Assertions.assertEquals(hash2, System.identityHashCode(retrieved2)); | ||
| Assertions.assertEquals(hash3, System.identityHashCode(retrieved3)); | ||
|
|
||
| // The pool should now be empty | ||
| Assertions.assertEquals(0, pool.getCurrentPoolSize()); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies the core feature: the pool stops caching buffers | ||
| * once its maximum size is reached. | ||
| */ | ||
| @Test | ||
| public void testPoolBoundingLogic() { | ||
| BoundedElasticByteBufferPool pool = new BoundedElasticByteBufferPool(MAX_POOL_SIZE); | ||
|
|
||
| ByteBuffer buffer1 = ByteBuffer.allocate(2 * MB); | ||
| ByteBuffer buffer2 = ByteBuffer.allocate(1 * MB); | ||
| ByteBuffer buffer3 = ByteBuffer.allocate(3 * MB); | ||
|
|
||
| int hash1 = System.identityHashCode(buffer1); | ||
| int hash2 = System.identityHashCode(buffer2); | ||
| int hash3 = System.identityHashCode(buffer3); | ||
|
|
||
| // 1. Put buffer 1 (Pool size: 2MB, remaining: 1MB) | ||
| pool.putBuffer(buffer1); | ||
| Assertions.assertEquals(2 * MB, pool.getCurrentPoolSize()); | ||
|
|
||
| // 2. Put buffer 2 (Pool size: 2MB + 1MB = 3MB, remaining: 0) | ||
| // The check is (current(2MB) + new(1MB)) > max(3MB), which is false. | ||
| // So, the buffer IS added. | ||
| pool.putBuffer(buffer2); | ||
| Assertions.assertEquals(3 * MB, pool.getCurrentPoolSize()); | ||
|
|
||
| // 3. Put buffer 3 (Capacity 3MB) | ||
| // The check is (current(3MB) + new(3MB)) > max(3MB), which is true. | ||
| // This buffer should be REJECTED. | ||
| pool.putBuffer(buffer3); | ||
| // The pool size should NOT change. | ||
| Assertions.assertEquals(3 * MB, pool.getCurrentPoolSize()); | ||
|
|
||
| // 4. Get buffers back | ||
| ByteBuffer retrieved1 = pool.getBuffer(false, 2 * MB); | ||
| ByteBuffer retrieved2 = pool.getBuffer(false, 1 * MB); | ||
|
|
||
| // The pool should now be empty | ||
| Assertions.assertEquals(0, pool.getCurrentPoolSize()); | ||
|
|
||
| // 5. Ask for a third buffer. | ||
| // Since buffer3 was rejected, this should be a NEWLY allocated buffer. | ||
| ByteBuffer retrieved3 = pool.getBuffer(false, 3 * MB); | ||
|
|
||
| // Verify that we got the first two buffers from the pool | ||
| Assertions.assertEquals(hash1, System.identityHashCode(retrieved1)); | ||
| Assertions.assertEquals(hash2, System.identityHashCode(retrieved2)); | ||
|
|
||
| // Verify that the third buffer is a NEW instance, not buffer3 | ||
| Assertions.assertNotEquals(hash3, System.identityHashCode(retrieved3)); | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description for
STORAGE_DATA_DISTRIBUTIONappears to be a copy-paste from theWITNESSED_CONTAINER_DB_PROTO_VALUEenum constant. Please update it to accurately describe the new layout feature, which seems to be related to persisting block sizes in deleted block transactions.