Skip to content
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

[core] Add limitation to the buffer spill disk usage #3108

Merged
merged 6 commits into from
Apr 1, 2024

Conversation

Aitozi
Copy link
Contributor

@Aitozi Aitozi commented Mar 28, 2024

Purpose

Linked issue: close #3104

Tests

API and Format

Documentation

@@ -154,7 +161,16 @@ public long getOccupancy() {
@Override
public boolean flushMemory() throws IOException {
spill();
return true;
return getDiskUsage() < maxDiskSize.getBytes();
Copy link
Contributor

Choose a reason for hiding this comment

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

also modify ExternalBuffer for append table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


public ChannelWithMeta(FileIOChannel.ID channel, int blockCount, int numBytesInLastBlock) {
this.channel = channel;
this.blockCount = blockCount;
this.numBytesInLastBlock = numBytesInLastBlock;
this.size = channel.getPathFile().length();
Copy link
Contributor

Choose a reason for hiding this comment

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

pass size from outside instead of access file again.

@@ -90,7 +96,16 @@ public void reset() {
@Override
public boolean flushMemory() throws IOException {
spill();
return true;
return getDiskUsage() < maxDiskSize.getBytes();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check first before spill?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated

@@ -147,6 +163,7 @@ private void spill() throws IOException {
? inMemoryBuffer.getNumBytesInLastBuffer()
: segment.size();
writer.writeBlock(Buffer.create(segment, bufferSize));
numEstimatedBytes += bufferSize;
}
LOG.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just cache writer.getSize().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get it, directly use FileChannel.getSize() can avoid an extra system call to get the file length, Right ?

@@ -24,11 +24,17 @@ public class ChannelWithMeta {
private final FileIOChannel.ID channel;
private final int blockCount;
private final int numBytesInLastBlock;
private final long numEstimatedBytes;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get real size, see comments.

@@ -309,6 +309,13 @@ public class CoreOptions implements Serializable {
.withDescription(
"Amount of data to build up in memory before converting to a sorted on-disk file.");

public static final ConfigOption<MemorySize> WRITE_BUFFER_MAX_DISK_SIZE =
Copy link
Contributor

Choose a reason for hiding this comment

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

@Documentation.OverrideDefault("infinite")?

@JingsongLi
Copy link
Contributor

Looks good to me!

@JingsongLi JingsongLi merged commit 85f1cfd into apache:master Apr 1, 2024
10 checks passed
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.

[Feature] Add limitation to disk usage of buffer spill
2 participants