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

HDFS-17391. Adjust the checkpoint io buffer size to the chunk size. #6594

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private static void uploadImage(URL url, Configuration conf,
ImageServlet.setVerificationHeadersForPut(connection, imageFile);

// Write the file to output stream.
writeFileToPutRequest(conf, connection, imageFile, canceler);
writeFileToPutRequest(conf, connection, imageFile, canceler, chunkSize);

int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
Expand All @@ -330,15 +330,16 @@ private static void uploadImage(URL url, Configuration conf,
}

private static void writeFileToPutRequest(Configuration conf,
HttpURLConnection connection, File imageFile, Canceler canceler)
HttpURLConnection connection, File imageFile, Canceler canceler,
int bufferSize)
throws IOException {
connection.setRequestProperty(Util.CONTENT_TYPE, "application/octet-stream");
connection.setRequestProperty(Util.CONTENT_TRANSFER_ENCODING, "binary");
OutputStream output = connection.getOutputStream();
FileInputStream input = new FileInputStream(imageFile);
try {
copyFileToStream(output, imageFile, input,
ImageServlet.getThrottler(conf), canceler);
ImageServlet.getThrottler(conf), canceler, bufferSize);
} finally {
IOUtils.closeStream(input);
IOUtils.closeStream(output);
Expand All @@ -352,13 +353,14 @@ private static void writeFileToPutRequest(Configuration conf,
public static void copyFileToStream(OutputStream out, File localfile,
FileInputStream infile, DataTransferThrottler throttler)
throws IOException {
copyFileToStream(out, localfile, infile, throttler, null);
copyFileToStream(out, localfile, infile, throttler, null, -1);
}

private static void copyFileToStream(OutputStream out, File localfile,
FileInputStream infile, DataTransferThrottler throttler,
Canceler canceler) throws IOException {
byte buf[] = new byte[IO_FILE_BUFFER_SIZE];
Canceler canceler, int bufferSize) throws IOException {
int bufSize = bufferSize > 0 ? bufferSize : IO_FILE_BUFFER_SIZE;
byte[] buf = new byte[bufSize];
long total = 0;
int num = 1;
IOException ioe = null;
Expand All @@ -369,13 +371,13 @@ private static void copyFileToStream(OutputStream out, File localfile,
.aboutToSendFile(localfile);

if (CheckpointFaultInjector.getInstance().
shouldSendShortFile(localfile)) {
// Test sending image shorter than localfile
long len = localfile.length();
buf = new byte[(int)Math.min(len/2, IO_FILE_BUFFER_SIZE)];
// This will read at most half of the image
// and the rest of the image will be sent over the wire
infile.read(buf);
shouldSendShortFile(localfile)) {
// Test sending image shorter than localfile
long len = localfile.length();
buf = new byte[(int) Math.min(len / 2, bufSize)];
// This will read at most half of the image
// and the rest of the image will be sent over the wire
infile.read(buf);
}
while (num > 0) {
if (canceler != null && canceler.isCancelled()) {
Expand Down