Skip to content

Commit

Permalink
HDFS-17216. Distcp: When handle the small files, the bandwidth parame…
Browse files Browse the repository at this point in the history
…ter will be invalid, fix this bug.
  • Loading branch information
xiaojunxiang2023 committed Oct 2, 2023
1 parent b8815fe commit 0d0f772
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions hadoop-tools/hadoop-distcp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ public long getTotalBytesRead() {
* @return Read rate, in bytes/sec.
*/
public long getBytesPerSec() {
long elapsed = (System.currentTimeMillis() - startTime) / 1000;
if (elapsed == 0) {
return bytesRead;
} else {
return bytesRead / elapsed;
if (bytesRead == 0){
return 0;
}
float elapsed = (System.currentTimeMillis() - startTime) / 1000.0f;
return (long) (bytesRead / elapsed);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.slf4j.LoggerFactory;
import org.apache.hadoop.io.IOUtils;
import org.junit.Assert;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertThat;
import org.junit.Test;

import java.io.*;
Expand Down Expand Up @@ -67,6 +69,34 @@ public void testRead() {
}
}

@Test
public void testThrottleRead() {
File[] srcFiles = new File[100];
File destFile;
try {
destFile = createFile(100 * 50 * 1024);
destFile.deleteOnExit();
// create file
for (int i = 0; i < srcFiles.length; i++) {
srcFiles[i] = createFile(48 * 1024);
srcFiles[i].deleteOnExit();
}

Check failure on line 84 in hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestThrottledInputStream.java

View check run for this annotation

ASF Cloudbees Jenkins ci-hadoop / Apache Yetus

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestThrottledInputStream.java#L84

blanks: end of line
// copy srcFiles
long begin = System.currentTimeMillis();
LOG.info("begin: " + begin);
for (File srcFile : srcFiles) {
LOG.info("fileLength: " + srcFiles.length);
copyAndAssert(srcFile, destFile, 50, 1, 0, CB.BUFFER);
}
long end = System.currentTimeMillis();
LOG.info("end: " + end);
assertThat((int) (end - begin) / 1000, greaterThanOrEqualTo(100));
} catch (IOException e) {
LOG.error("Exception encountered ", e);
}
}

private long copyAndAssert(File tmpFile, File outFile,
long maxBandwidth, float factor,
int sleepTime, CB flag) throws IOException {
Expand Down

0 comments on commit 0d0f772

Please sign in to comment.