@@ -2201,4 +2201,76 @@ public void testBlockReportSetNoAckBlockToInvalidate() throws Exception {
2201
2201
assertEquals (1 , getLongCounter ("IncrementalBlockReportsNumOps" , rb ));
2202
2202
}
2203
2203
}
2204
+
2205
+ @ Test
2206
+ public void testTwoFBRSInARow () throws Exception {
2207
+ DatanodeDescriptor node = spy (nodes .get (0 ));
2208
+ node .setAlive (true );
2209
+
2210
+ DatanodeRegistration nodeReg =
2211
+ new DatanodeRegistration (node , null , null , "" );
2212
+
2213
+ // pretend to be in safemode
2214
+ doReturn (true ).when (fsn ).isInStartupSafeMode ();
2215
+
2216
+ // register new node
2217
+ bm .getDatanodeManager ().registerDatanode (nodeReg );
2218
+ bm .getDatanodeManager ().addDatanode (node );
2219
+ assertEquals (node , bm .getDatanodeManager ().getDatanode (node ));
2220
+
2221
+ DatanodeStorageInfo [] storageInfos = node .getStorageInfos ();
2222
+ for (int r = 0 ; r < storageInfos .length ; r ++) {
2223
+ DatanodeStorageInfo storageInfo = storageInfos [r ];
2224
+ assertEquals (0 , storageInfo .getBlockReportCount ());
2225
+ }
2226
+
2227
+ reset (node );
2228
+ // 1.Here's the original logic
2229
+ BlockReportLeaseManager brlm = new BlockReportLeaseManager (new Configuration ());
2230
+ // This is the first FBR
2231
+ for (int r = 0 ; r < storageInfos .length ; r ++) {
2232
+ bm .processReport (node , new DatanodeStorage (storageInfos [r ].getStorageID ()),
2233
+ BlockListAsLongs .EMPTY , null , storageInfos .length , r + 1 );
2234
+ //The first FBR times out because the namenode is busy,
2235
+ break ;
2236
+ }
2237
+ //and then the second FBR is the same
2238
+ for (int r = 0 ; r < storageInfos .length ; r ++) {
2239
+ bm .processReport (node , new DatanodeStorage (storageInfos [r ].getStorageID ()),
2240
+ BlockListAsLongs .EMPTY , null , storageInfos .length , r + 1 );
2241
+ //In the original method, sending FBR twice from one disk will call removeLease
2242
+ brlm .removeLease (node );
2243
+ //Starting from the second disk, FBR will fail because the lease is removed
2244
+ break ;
2245
+ }
2246
+
2247
+ assertEquals (2 , storageInfos [0 ].getBlockReportCount ());
2248
+ assertEquals (0 , storageInfos [1 ].getBlockReportCount ());
2249
+ assertEquals (0 , storageInfos [2 ].getBlockReportCount ());
2250
+ assertEquals (0 , storageInfos [3 ].getBlockReportCount ());
2251
+ assertEquals (0 , storageInfos [4 ].getBlockReportCount ());
2252
+ assertEquals (0 , storageInfos [5 ].getBlockReportCount ());
2253
+
2254
+
2255
+ reset (node );
2256
+ //2. Now the processReport method calls removeLease only when it determines that it is the last disk
2257
+ // This is the first FBR
2258
+ for (int r = 0 ; r < storageInfos .length ; r ++) {
2259
+ bm .processReport (node , new DatanodeStorage (storageInfos [r ].getStorageID ()),
2260
+ BlockListAsLongs .EMPTY , null , storageInfos .length , r + 1 );
2261
+ //The first FBR times out because the namenode is busy, and then the second FBR is the same
2262
+ break ;
2263
+ }
2264
+ for (int r = 0 ; r < storageInfos .length ; r ++) {
2265
+ bm .processReport (node , new DatanodeStorage (storageInfos [r ].getStorageID ()),
2266
+ BlockListAsLongs .EMPTY , null , storageInfos .length , r + 1 );
2267
+ }
2268
+
2269
+ assertEquals (2 , storageInfos [0 ].getBlockReportCount ());
2270
+ assertEquals (1 , storageInfos [1 ].getBlockReportCount ());
2271
+ assertEquals (1 , storageInfos [2 ].getBlockReportCount ());
2272
+ assertEquals (1 , storageInfos [3 ].getBlockReportCount ());
2273
+ assertEquals (1 , storageInfos [4 ].getBlockReportCount ());
2274
+ assertEquals (1 , storageInfos [5 ].getBlockReportCount ());
2275
+ }
2204
2276
}
0 commit comments