@@ -147,12 +147,13 @@ public static void checkOtherInstanceRunning(boolean toCheck) {
147
147
148
148
private final BalancerProtocols namenode ;
149
149
/**
150
- * If set balancerShouldRequestStandby true, Balancer will getBlocks from
150
+ * If set requestToStandby true, Balancer will getBlocks from
151
151
* Standby NameNode only and it can reduce the performance impact of Active
152
152
* NameNode, especially in a busy HA mode cluster.
153
153
*/
154
- private boolean balancerShouldRequestStandby ;
155
- private NamenodeProtocol standbyNameNode ;
154
+ private boolean requestToStandby ;
155
+ private String nsId ;
156
+ private Configuration config ;
156
157
private final KeyManager keyManager ;
157
158
final AtomicBoolean fallbackToSimpleAuth = new AtomicBoolean (false );
158
159
@@ -188,10 +189,10 @@ public NameNodeConnector(String name, URI nameNodeUri, Path idPath,
188
189
189
190
this .namenode = NameNodeProxies .createProxy (conf , nameNodeUri ,
190
191
BalancerProtocols .class , fallbackToSimpleAuth ).getProxy ();
191
- this .balancerShouldRequestStandby = conf .getBoolean (
192
+ this .requestToStandby = conf .getBoolean (
192
193
DFSConfigKeys .DFS_HA_ALLOW_STALE_READ_KEY ,
193
194
DFSConfigKeys .DFS_HA_ALLOW_STALE_READ_DEFAULT );
194
- this .standbyNameNode = null ;
195
+ this .config = conf ;
195
196
196
197
this .fs = (DistributedFileSystem )FileSystem .get (nameNodeUri , conf );
197
198
@@ -216,24 +217,7 @@ public NameNodeConnector(String name, URI nameNodeUri, String nsId,
216
217
Configuration conf , int maxNotChangedIterations )
217
218
throws IOException {
218
219
this (name , nameNodeUri , idPath , targetPaths , conf , maxNotChangedIterations );
219
- if (nsId != null && HAUtil .isHAEnabled (conf , nsId )) {
220
- List <ClientProtocol > namenodes =
221
- HAUtil .getProxiesForAllNameNodesInNameservice (conf , nsId );
222
- for (ClientProtocol proxy : namenodes ) {
223
- try {
224
- if (proxy .getHAServiceState ().equals (
225
- HAServiceProtocol .HAServiceState .STANDBY )) {
226
- this .standbyNameNode = NameNodeProxies .createNonHAProxy (
227
- conf , RPC .getServerAddress (proxy ), NamenodeProtocol .class ,
228
- UserGroupInformation .getCurrentUser (), false ).getProxy ();
229
- break ;
230
- }
231
- } catch (Exception e ) {
232
- //Ignore the exception while connecting to a namenode.
233
- LOG .debug ("Error while connecting to namenode" , e );
234
- }
235
- }
236
- }
220
+ this .nsId = nsId ;
237
221
}
238
222
239
223
public DistributedFileSystem getDistributedFileSystem () {
@@ -255,23 +239,43 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
255
239
if (getBlocksRateLimiter != null ) {
256
240
getBlocksRateLimiter .acquire ();
257
241
}
258
- boolean isRequestStandby = true ;
242
+ boolean isRequestStandby = false ;
243
+ NamenodeProtocol nnproxy = null ;
259
244
try {
260
- if (balancerShouldRequestStandby && standbyNameNode != null ) {
261
- return standbyNameNode .getBlocks (datanode , size , minBlockSize );
245
+ if (requestToStandby && nsId != null
246
+ && HAUtil .isHAEnabled (config , nsId )) {
247
+ List <ClientProtocol > namenodes =
248
+ HAUtil .getProxiesForAllNameNodesInNameservice (config , nsId );
249
+ for (ClientProtocol proxy : namenodes ) {
250
+ try {
251
+ if (proxy .getHAServiceState ().equals (
252
+ HAServiceProtocol .HAServiceState .STANDBY )) {
253
+ NamenodeProtocol sbn = NameNodeProxies .createNonHAProxy (
254
+ config , RPC .getServerAddress (proxy ), NamenodeProtocol .class ,
255
+ UserGroupInformation .getCurrentUser (), false ).getProxy ();
256
+ nnproxy = sbn ;
257
+ isRequestStandby = true ;
258
+ break ;
259
+ }
260
+ } catch (Exception e ) {
261
+ // Ignore the exception while connecting to a namenode.
262
+ LOG .debug ("Error while connecting to namenode" , e );
263
+ }
264
+ }
265
+ if (nnproxy == null ) {
266
+ LOG .warn ("Request #getBlocks to Standby NameNode but meet exception,"
267
+ + " will fallback to normal way." );
268
+ nnproxy = namenode ;
269
+ }
262
270
} else {
263
- isRequestStandby = false ;
271
+ nnproxy = namenode ;
264
272
}
265
- } catch (Exception e ) {
266
- LOG .warn ("Request #getBlocks to Standby NameNode but meet exception, " +
267
- "will fallback to normal way" , e );
268
- isRequestStandby = false ;
273
+ return nnproxy .getBlocks (datanode , size , minBlockSize );
269
274
} finally {
270
275
if (isRequestStandby ) {
271
276
LOG .info ("Request #getBlocks to Standby NameNode success." );
272
277
}
273
278
}
274
- return namenode .getBlocks (datanode , size , minBlockSize );
275
279
}
276
280
277
281
/**
0 commit comments