|
@@ -794,41 +794,48 @@ public class DFSTestUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Wait for the given file to reach the given replication factor.
|
|
* Wait for the given file to reach the given replication factor.
|
|
- * @throws TimeoutException if we fail to sufficiently replicate the file
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param fs the defined filesystem.
|
|
|
|
+ * @param fileName being written.
|
|
|
|
+ * @param replFactor desired replication
|
|
|
|
+ * @throws IOException getting block locations
|
|
|
|
+ * @throws InterruptedException during sleep
|
|
|
|
+ * @throws TimeoutException if 40 seconds passed before reaching the desired
|
|
|
|
+ * replication.
|
|
*/
|
|
*/
|
|
- public static void waitReplication(FileSystem fs, Path fileName, short replFactor)
|
|
|
|
|
|
+ public static void waitReplication(FileSystem fs, Path fileName,
|
|
|
|
+ short replFactor)
|
|
throws IOException, InterruptedException, TimeoutException {
|
|
throws IOException, InterruptedException, TimeoutException {
|
|
boolean correctReplFactor;
|
|
boolean correctReplFactor;
|
|
- final int ATTEMPTS = 40;
|
|
|
|
- int count = 0;
|
|
|
|
-
|
|
|
|
|
|
+ int attempt = 0;
|
|
do {
|
|
do {
|
|
correctReplFactor = true;
|
|
correctReplFactor = true;
|
|
|
|
+ if (attempt++ > 0) {
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ }
|
|
BlockLocation locs[] = fs.getFileBlockLocations(
|
|
BlockLocation locs[] = fs.getFileBlockLocations(
|
|
- fs.getFileStatus(fileName), 0, Long.MAX_VALUE);
|
|
|
|
- count++;
|
|
|
|
- for (int j = 0; j < locs.length; j++) {
|
|
|
|
- String[] hostnames = locs[j].getNames();
|
|
|
|
|
|
+ fs.getFileStatus(fileName), 0, Long.MAX_VALUE);
|
|
|
|
+ for (int currLoc = 0; currLoc < locs.length; currLoc++) {
|
|
|
|
+ String[] hostnames = locs[currLoc].getNames();
|
|
if (hostnames.length != replFactor) {
|
|
if (hostnames.length != replFactor) {
|
|
|
|
+ LOG.info(
|
|
|
|
+ "Block {} of file {} has replication factor {} "
|
|
|
|
+ + "(desired {}); locations: {}",
|
|
|
|
+ currLoc, fileName, hostnames.length, replFactor,
|
|
|
|
+ Joiner.on(' ').join(hostnames));
|
|
correctReplFactor = false;
|
|
correctReplFactor = false;
|
|
- System.out.println("Block " + j + " of file " + fileName
|
|
|
|
- + " has replication factor " + hostnames.length
|
|
|
|
- + " (desired " + replFactor + "); locations "
|
|
|
|
- + Joiner.on(' ').join(hostnames));
|
|
|
|
- Thread.sleep(1000);
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (correctReplFactor) {
|
|
|
|
- System.out.println("All blocks of file " + fileName
|
|
|
|
- + " verified to have replication factor " + replFactor);
|
|
|
|
- }
|
|
|
|
- } while (!correctReplFactor && count < ATTEMPTS);
|
|
|
|
|
|
+ } while (!correctReplFactor && attempt < 40);
|
|
|
|
|
|
- if (count == ATTEMPTS) {
|
|
|
|
- throw new TimeoutException("Timed out waiting for " + fileName +
|
|
|
|
- " to reach " + replFactor + " replicas");
|
|
|
|
|
|
+ if (!correctReplFactor) {
|
|
|
|
+ throw new TimeoutException("Timed out waiting for file ["
|
|
|
|
+ + fileName + "] to reach [" + replFactor + "] replicas");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ LOG.info("All blocks of file {} verified to have replication factor {}",
|
|
|
|
+ fileName, replFactor);
|
|
}
|
|
}
|
|
|
|
|
|
/** delete directory and everything underneath it.*/
|
|
/** delete directory and everything underneath it.*/
|