Skip to content

HDDS-9549. defaultReadBufferCapacity should be int instead of long#5522

Merged
sumitagrawl merged 2 commits intoapache:masterfrom
Tejaskriya:HDDS-9549
Nov 3, 2023
Merged

HDDS-9549. defaultReadBufferCapacity should be int instead of long#5522
sumitagrawl merged 2 commits intoapache:masterfrom
Tejaskriya:HDDS-9549

Conversation

@Tejaskriya
Copy link
Contributor

What changes were proposed in this pull request?

defaultReadBufferCapacity was changed from long to int in this PR.
This change was made because although defaultReadBufferCapacity was long in BlockManagerImpl/FilePerBlockStrategy/FilePerChunkStrategy, it was casted to int when it is used as shown below.

//BufferUtils.assignByteBuffers
    for (int i = 0; i < numBuffers - 1; i++) {
      dataBuffers[i] = ByteBuffer.allocate((int) bufferCapacity);
      buffersAllocated += bufferCapacity;
    }

Using long as buffer capacity does NOT work for Java array, Java ByteBuffer, Protobuf ByteString and Netty ByteBuf. Moreover, if we set ozone.chunk.read.buffer.default.size to "2GB", ((int) bufferCapacity) == -2147483648 would throw an IllegalArgumentException from ByteBuffer.allocate(..).

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-9549

How was this patch tested?

Existing tests in TestChunkUtils, TestFilePerBlockStrategy, TestFilePerChunkStrategy cover this change

Copy link
Contributor

@sadanand48 sadanand48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Tejaskriya for the patch, LGTM

Copy link
Contributor

@sumitagrawl sumitagrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tejaskriya Thanks for working over this, LGTM

@sumitagrawl sumitagrawl merged commit e4ff5fa into apache:master Nov 3, 2023
Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tejaskriya , thanks for working on this! Individual buffer size is int but len (e.g. file length/chunk length) should be long. Also, we should check range before casting.

Since this is already merge, will fix them in HDDS-9611.

*/
public static ByteBuffer[] assignByteBuffers(long totalLen,
long bufferCapacity) {
public static ByteBuffer[] assignByteBuffers(int totalLen,
Copy link
Contributor

@szetszwo szetszwo Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The totalLen and buffersAllocated should be long. We should allow >= 2GB chunks/files.

Preconditions.checkNotNull(conf, "Config cannot be null");
this.config = conf;
this.defaultReadBufferCapacity = (long) config.getStorageSize(
this.defaultReadBufferCapacity = (int) config.getStorageSize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check range before casting to (int).


long len = info.getLen();
long bufferCapacity = ChunkManager.getBufferCapacityForChunkRead(info,
int len = (int) info.getLen();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len should be long.

long bufferCapacity = 0;
static int getBufferCapacityForChunkRead(ChunkInfo chunkInfo,
int defaultReadBufferCapacity) {
int bufferCapacity = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use long and check range.

@szetszwo
Copy link
Contributor

szetszwo commented Nov 4, 2023

@sumitagrawl , please resolve the JIRA after merge. Thanks.

ibrusentsev pushed a commit to ibrusentsev/ozone that referenced this pull request Nov 14, 2023
@Tejaskriya Tejaskriya deleted the HDDS-9549 branch December 18, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants