forked from kalutes/CS193_Fall18_Lab1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhadoop.patch
99 lines (90 loc) · 4.59 KB
/
hadoop.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
diff --git hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java
index 0feb3b78aca..16330c17bfd 100644
--- hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java
+++ hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java
@@ -3363,6 +3363,11 @@ boolean reserveLockedMemory(long bytesNeeded) {
return cacheManager.reserve(bytesNeeded) > 0;
}
+ @VisibleForTesting
+ public int getNonPersistentReplicas() {
+ return ramDiskReplicaTracker.numReplicasNotPersisted();
+ }
+
@VisibleForTesting
public void setTimer(Timer newTimer) {
this.timer = newTimer;
diff --git hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistReplicaRecovery.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistReplicaRecovery.java
index 537f9e8d621..a62dc389b24 100644
--- hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistReplicaRecovery.java
+++ hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistReplicaRecovery.java
@@ -17,8 +17,14 @@
*/
package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl;
-
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.client.BlockReportOptions;
+import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
+import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
+import org.apache.hadoop.hdfs.server.datanode.DataNode;
+import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test;
@@ -27,6 +33,7 @@
import static org.apache.hadoop.fs.StorageType.DEFAULT;
import static org.apache.hadoop.fs.StorageType.RAM_DISK;
+import static org.junit.Assert.assertTrue;
public class TestLazyPersistReplicaRecovery extends LazyPersistTestCase {
@Test
@@ -34,6 +41,10 @@ public void testDnRestartWithSavedReplicas()
throws IOException, InterruptedException, TimeoutException {
getClusterBuilder().build();
+ FSNamesystem fsn = cluster.getNamesystem();
+ final DataNode dn = cluster.getDataNodes().get(0);
+ DatanodeDescriptor dnd =
+ NameNodeAdapter.getDatanode(fsn, dn.getDatanodeId());
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path path1 = new Path("/" + METHOD_NAME + ".01.dat");
@@ -42,14 +53,17 @@ public void testDnRestartWithSavedReplicas()
// Sleep for a short time to allow the lazy writer thread to do its job.
// However the block replica should not be evicted from RAM_DISK yet.
- Thread.sleep(3 * LAZY_WRITER_INTERVAL_SEC * 1000);
+ FsDatasetImpl fsDImpl = (FsDatasetImpl) DataNodeTestUtils.getFSDataset(dn);
+ GenericTestUtils
+ .waitFor(() -> fsDImpl.getNonPersistentReplicas() == 0, 10,
+ 3 * LAZY_WRITER_INTERVAL_SEC * 1000);
ensureFileReplicasOnStorageType(path1, RAM_DISK);
LOG.info("Restarting the DataNode");
- cluster.restartDataNode(0, true);
- cluster.waitActive();
- triggerBlockReport();
-
+ assertTrue("DN did not restart properly",
+ cluster.restartDataNode(0, true));
+ // wait for blockreport
+ waitForBlockReport(dn, dnd);
// Ensure that the replica is now on persistent storage.
ensureFileReplicasOnStorageType(path1, DEFAULT);
}
@@ -73,4 +87,20 @@ public void testDnRestartWithUnsavedReplicas()
// Ensure that the replica is still on transient storage.
ensureFileReplicasOnStorageType(path1, RAM_DISK);
}
+
+ private boolean waitForBlockReport(final DataNode dn,
+ final DatanodeDescriptor dnd) throws IOException, InterruptedException {
+ final DatanodeStorageInfo storage = dnd.getStorageInfos()[0];
+ final long lastCount = storage.getBlockReportCount();
+ dn.triggerBlockReport(
+ new BlockReportOptions.Factory().setIncremental(false).build());
+ try {
+ GenericTestUtils
+ .waitFor(() -> lastCount != storage.getBlockReportCount(), 10, 10000);
+ } catch (TimeoutException te) {
+ LOG.error("Timeout waiting for block report for {}", dnd);
+ return false;
+ }
+ return true;
+ }
}