@@ -266,6 +266,7 @@ static <V extends Cell> RecordWriter<ImmutableBytesWritable, V> createRecordWrit
266
266
private final Map <byte [], WriterLength > writers = new TreeMap <>(Bytes .BYTES_COMPARATOR );
267
267
private final Map <byte [], byte []> previousRows = new TreeMap <>(Bytes .BYTES_COMPARATOR );
268
268
private final long now = EnvironmentEdgeManager .currentTime ();
269
+ private byte [] tableNameBytes = writeMultipleTables ? null : Bytes .toBytes (writeTableNames );
269
270
270
271
@ Override
271
272
public void write (ImmutableBytesWritable row , V cell ) throws IOException {
@@ -279,7 +280,6 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
279
280
byte [] rowKey = CellUtil .cloneRow (kv );
280
281
int length = (PrivateCellUtil .estimatedSerializedSizeOf (kv )) - Bytes .SIZEOF_INT ;
281
282
byte [] family = CellUtil .cloneFamily (kv );
282
- byte [] tableNameBytes = null ;
283
283
if (writeMultipleTables ) {
284
284
tableNameBytes = MultiTableHFileOutputFormat .getTableName (row .get ());
285
285
tableNameBytes = writeToTableWithNamespace
@@ -290,10 +290,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
290
290
throw new IllegalArgumentException (
291
291
"TableName " + Bytes .toString (tableNameBytes ) + " not expected" );
292
292
}
293
- } else {
294
- tableNameBytes = Bytes .toBytes (writeTableNames );
295
293
}
296
- Path tableRelPath = getTableRelativePath (tableNameBytes );
297
294
byte [] tableAndFamily = getTableNameSuffixedWithFamily (tableNameBytes , family );
298
295
299
296
WriterLength wl = this .writers .get (tableAndFamily );
@@ -302,6 +299,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
302
299
if (wl == null ) {
303
300
Path writerPath = null ;
304
301
if (writeMultipleTables ) {
302
+ Path tableRelPath = getTableRelativePath (tableNameBytes );
305
303
writerPath = new Path (outputDir , new Path (tableRelPath , Bytes .toString (family )));
306
304
} else {
307
305
writerPath = new Path (outputDir , Bytes .toString (family ));
@@ -320,6 +318,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
320
318
321
319
// create a new WAL writer, if necessary
322
320
if (wl == null || wl .writer == null ) {
321
+ InetSocketAddress [] favoredNodes = null ;
323
322
if (conf .getBoolean (LOCALITY_SENSITIVE_CONF_KEY , DEFAULT_LOCALITY_SENSITIVE )) {
324
323
HRegionLocation loc = null ;
325
324
String tableName = Bytes .toString (tableNameBytes );
@@ -335,26 +334,22 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
335
334
loc = null ;
336
335
}
337
336
}
338
-
339
337
if (null == loc ) {
340
338
LOG .trace ("Failed get of location, use default writer {}" , Bytes .toString (rowKey ));
341
- wl = getNewWriter (tableNameBytes , family , conf , null );
342
339
} else {
343
340
LOG .debug ("First rowkey: [{}]" , Bytes .toString (rowKey ));
344
341
InetSocketAddress initialIsa =
345
342
new InetSocketAddress (loc .getHostname (), loc .getPort ());
346
343
if (initialIsa .isUnresolved ()) {
347
344
LOG .trace ("Failed resolve address {}, use default writer" , loc .getHostnamePort ());
348
- wl = getNewWriter (tableNameBytes , family , conf , null );
349
345
} else {
350
346
LOG .debug ("Use favored nodes writer: {}" , initialIsa .getHostString ());
351
- wl = getNewWriter (tableNameBytes , family , conf ,
352
- new InetSocketAddress [] { initialIsa });
347
+ favoredNodes = new InetSocketAddress [] { initialIsa };
353
348
}
354
349
}
355
- } else {
356
- wl = getNewWriter (tableNameBytes , family , conf , null );
357
350
}
351
+ wl = getNewWriter (tableNameBytes , family , conf , favoredNodes );
352
+
358
353
}
359
354
360
355
// we now have the proper WAL writer. full steam ahead
@@ -369,9 +364,9 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
369
364
private Path getTableRelativePath (byte [] tableNameBytes ) {
370
365
String tableName = Bytes .toString (tableNameBytes );
371
366
String [] tableNameParts = tableName .split (":" );
372
- Path tableRelPath = new Path (tableName . split ( ":" ) [0 ]);
367
+ Path tableRelPath = new Path (tableNameParts [0 ]);
373
368
if (tableNameParts .length > 1 ) {
374
- tableRelPath = new Path (tableRelPath , tableName . split ( ":" ) [1 ]);
369
+ tableRelPath = new Path (tableRelPath , tableNameParts [1 ]);
375
370
}
376
371
return tableRelPath ;
377
372
}
0 commit comments