@@ -266,6 +266,7 @@ static <V extends Cell> RecordWriter<ImmutableBytesWritable, V> createRecordWrit
266266 private final Map <byte [], WriterLength > writers = new TreeMap <>(Bytes .BYTES_COMPARATOR );
267267 private final Map <byte [], byte []> previousRows = new TreeMap <>(Bytes .BYTES_COMPARATOR );
268268 private final long now = EnvironmentEdgeManager .currentTime ();
269+ private byte [] tableNameBytes = writeMultipleTables ? null : Bytes .toBytes (writeTableNames );
269270
270271 @ Override
271272 public void write (ImmutableBytesWritable row , V cell ) throws IOException {
@@ -279,7 +280,6 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
279280 byte [] rowKey = CellUtil .cloneRow (kv );
280281 int length = (PrivateCellUtil .estimatedSerializedSizeOf (kv )) - Bytes .SIZEOF_INT ;
281282 byte [] family = CellUtil .cloneFamily (kv );
282- byte [] tableNameBytes = null ;
283283 if (writeMultipleTables ) {
284284 tableNameBytes = MultiTableHFileOutputFormat .getTableName (row .get ());
285285 tableNameBytes = writeToTableWithNamespace
@@ -290,10 +290,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
290290 throw new IllegalArgumentException (
291291 "TableName " + Bytes .toString (tableNameBytes ) + " not expected" );
292292 }
293- } else {
294- tableNameBytes = Bytes .toBytes (writeTableNames );
295293 }
296- Path tableRelPath = getTableRelativePath (tableNameBytes );
297294 byte [] tableAndFamily = getTableNameSuffixedWithFamily (tableNameBytes , family );
298295
299296 WriterLength wl = this .writers .get (tableAndFamily );
@@ -302,6 +299,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
302299 if (wl == null ) {
303300 Path writerPath = null ;
304301 if (writeMultipleTables ) {
302+ Path tableRelPath = getTableRelativePath (tableNameBytes );
305303 writerPath = new Path (outputDir , new Path (tableRelPath , Bytes .toString (family )));
306304 } else {
307305 writerPath = new Path (outputDir , Bytes .toString (family ));
@@ -320,6 +318,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
320318
321319 // create a new WAL writer, if necessary
322320 if (wl == null || wl .writer == null ) {
321+ InetSocketAddress [] favoredNodes = null ;
323322 if (conf .getBoolean (LOCALITY_SENSITIVE_CONF_KEY , DEFAULT_LOCALITY_SENSITIVE )) {
324323 HRegionLocation loc = null ;
325324 String tableName = Bytes .toString (tableNameBytes );
@@ -335,26 +334,22 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
335334 loc = null ;
336335 }
337336 }
338-
339337 if (null == loc ) {
340338 LOG .trace ("Failed get of location, use default writer {}" , Bytes .toString (rowKey ));
341- wl = getNewWriter (tableNameBytes , family , conf , null );
342339 } else {
343340 LOG .debug ("First rowkey: [{}]" , Bytes .toString (rowKey ));
344341 InetSocketAddress initialIsa =
345342 new InetSocketAddress (loc .getHostname (), loc .getPort ());
346343 if (initialIsa .isUnresolved ()) {
347344 LOG .trace ("Failed resolve address {}, use default writer" , loc .getHostnamePort ());
348- wl = getNewWriter (tableNameBytes , family , conf , null );
349345 } else {
350346 LOG .debug ("Use favored nodes writer: {}" , initialIsa .getHostString ());
351- wl = getNewWriter (tableNameBytes , family , conf ,
352- new InetSocketAddress [] { initialIsa });
347+ favoredNodes = new InetSocketAddress [] { initialIsa };
353348 }
354349 }
355- } else {
356- wl = getNewWriter (tableNameBytes , family , conf , null );
357350 }
351+ wl = getNewWriter (tableNameBytes , family , conf , favoredNodes );
352+
358353 }
359354
360355 // we now have the proper WAL writer. full steam ahead
@@ -369,9 +364,9 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
369364 private Path getTableRelativePath (byte [] tableNameBytes ) {
370365 String tableName = Bytes .toString (tableNameBytes );
371366 String [] tableNameParts = tableName .split (":" );
372- Path tableRelPath = new Path (tableName . split ( ":" ) [0 ]);
367+ Path tableRelPath = new Path (tableNameParts [0 ]);
373368 if (tableNameParts .length > 1 ) {
374- tableRelPath = new Path (tableRelPath , tableName . split ( ":" ) [1 ]);
369+ tableRelPath = new Path (tableRelPath , tableNameParts [1 ]);
375370 }
376371 return tableRelPath ;
377372 }
0 commit comments