001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mapreduce; 019 020import static org.apache.hadoop.hbase.regionserver.HStoreFile.BULKLOAD_TASK_KEY; 021import static org.apache.hadoop.hbase.regionserver.HStoreFile.BULKLOAD_TIME_KEY; 022import static org.apache.hadoop.hbase.regionserver.HStoreFile.EXCLUDE_FROM_MINOR_COMPACTION_KEY; 023import static org.apache.hadoop.hbase.regionserver.HStoreFile.MAJOR_COMPACTION_KEY; 024 025import java.io.IOException; 026import java.io.UnsupportedEncodingException; 027import java.net.InetSocketAddress; 028import java.net.URLDecoder; 029import java.net.URLEncoder; 030import java.util.ArrayList; 031import java.util.Arrays; 032import java.util.Collections; 033import java.util.List; 034import java.util.Map; 035import java.util.Map.Entry; 036import java.util.Set; 037import java.util.TreeMap; 038import java.util.TreeSet; 039import java.util.UUID; 040import java.util.function.Function; 041import java.util.stream.Collectors; 042import org.apache.commons.lang3.StringUtils; 043import org.apache.hadoop.conf.Configuration; 044import org.apache.hadoop.fs.FileSystem; 045import org.apache.hadoop.fs.Path; 046import org.apache.hadoop.hbase.Cell; 047import org.apache.hadoop.hbase.CellUtil; 048import org.apache.hadoop.hbase.HConstants; 049import org.apache.hadoop.hbase.HRegionLocation; 050import org.apache.hadoop.hbase.HTableDescriptor; 051import org.apache.hadoop.hbase.KeyValue; 052import org.apache.hadoop.hbase.PrivateCellUtil; 053import org.apache.hadoop.hbase.TableName; 054import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 055import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 056import org.apache.hadoop.hbase.client.Connection; 057import org.apache.hadoop.hbase.client.ConnectionFactory; 058import org.apache.hadoop.hbase.client.Put; 059import org.apache.hadoop.hbase.client.RegionLocator; 060import org.apache.hadoop.hbase.client.Table; 061import org.apache.hadoop.hbase.client.TableDescriptor; 062import org.apache.hadoop.hbase.fs.HFileSystem; 063import org.apache.hadoop.hbase.io.ImmutableBytesWritable; 064import org.apache.hadoop.hbase.io.compress.Compression; 065import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; 066import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; 067import org.apache.hadoop.hbase.io.hfile.CacheConfig; 068import org.apache.hadoop.hbase.io.hfile.HFile; 069import org.apache.hadoop.hbase.io.hfile.HFileContext; 070import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder; 071import org.apache.hadoop.hbase.io.hfile.HFileWriterImpl; 072import org.apache.hadoop.hbase.regionserver.BloomType; 073import org.apache.hadoop.hbase.regionserver.HStore; 074import org.apache.hadoop.hbase.regionserver.StoreFileWriter; 075import org.apache.hadoop.hbase.regionserver.StoreUtils; 076import org.apache.hadoop.hbase.util.BloomFilterUtil; 077import org.apache.hadoop.hbase.util.Bytes; 078import org.apache.hadoop.hbase.util.CommonFSUtils; 079import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 080import org.apache.hadoop.hbase.util.MapReduceExtendedCell; 081import org.apache.hadoop.hbase.util.ReflectionUtils; 082import org.apache.hadoop.io.NullWritable; 083import org.apache.hadoop.io.SequenceFile; 084import org.apache.hadoop.io.Text; 085import org.apache.hadoop.mapreduce.Job; 086import org.apache.hadoop.mapreduce.OutputCommitter; 087import org.apache.hadoop.mapreduce.OutputFormat; 088import org.apache.hadoop.mapreduce.RecordWriter; 089import org.apache.hadoop.mapreduce.TaskAttemptContext; 090import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 091import org.apache.hadoop.mapreduce.lib.partition.TotalOrderPartitioner; 092import org.apache.yetus.audience.InterfaceAudience; 093import org.slf4j.Logger; 094import org.slf4j.LoggerFactory; 095 096/** 097 * Writes HFiles. Passed Cells must arrive in order. Writes current time as the sequence id for the 098 * file. Sets the major compacted attribute on created {@link HFile}s. Calling write(null,null) will 099 * forcibly roll all HFiles being written. 100 * <p> 101 * Using this class as part of a MapReduce job is best done using 102 * {@link #configureIncrementalLoad(Job, TableDescriptor, RegionLocator)}. 103 */ 104@InterfaceAudience.Public 105public class HFileOutputFormat2 extends FileOutputFormat<ImmutableBytesWritable, Cell> { 106 private static final Logger LOG = LoggerFactory.getLogger(HFileOutputFormat2.class); 107 108 static class TableInfo { 109 private TableDescriptor tableDesctiptor; 110 private RegionLocator regionLocator; 111 112 public TableInfo(TableDescriptor tableDesctiptor, RegionLocator regionLocator) { 113 this.tableDesctiptor = tableDesctiptor; 114 this.regionLocator = regionLocator; 115 } 116 117 /** 118 * The modification for the returned HTD doesn't affect the inner TD. 119 * @return A clone of inner table descriptor 120 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use {@link #getTableDescriptor()} 121 * instead. 122 * @see #getTableDescriptor() 123 * @see <a href="https://issues.apache.org/jira/browse/HBASE-18241">HBASE-18241</a> 124 */ 125 @Deprecated 126 public HTableDescriptor getHTableDescriptor() { 127 return new HTableDescriptor(tableDesctiptor); 128 } 129 130 public TableDescriptor getTableDescriptor() { 131 return tableDesctiptor; 132 } 133 134 public RegionLocator getRegionLocator() { 135 return regionLocator; 136 } 137 } 138 139 protected static final byte[] tableSeparator = Bytes.toBytes(";"); 140 141 protected static byte[] combineTableNameSuffix(byte[] tableName, byte[] suffix) { 142 return Bytes.add(tableName, tableSeparator, suffix); 143 } 144 145 // The following constants are private since these are used by 146 // HFileOutputFormat2 to internally transfer data between job setup and 147 // reducer run using conf. 148 // These should not be changed by the client. 149 static final String COMPRESSION_FAMILIES_CONF_KEY = 150 "hbase.hfileoutputformat.families.compression"; 151 static final String BLOOM_TYPE_FAMILIES_CONF_KEY = "hbase.hfileoutputformat.families.bloomtype"; 152 static final String BLOOM_PARAM_FAMILIES_CONF_KEY = "hbase.hfileoutputformat.families.bloomparam"; 153 static final String BLOCK_SIZE_FAMILIES_CONF_KEY = "hbase.mapreduce.hfileoutputformat.blocksize"; 154 static final String DATABLOCK_ENCODING_FAMILIES_CONF_KEY = 155 "hbase.mapreduce.hfileoutputformat.families.datablock.encoding"; 156 157 // This constant is public since the client can modify this when setting 158 // up their conf object and thus refer to this symbol. 159 // It is present for backwards compatibility reasons. Use it only to 160 // override the auto-detection of datablock encoding and compression. 161 public static final String DATABLOCK_ENCODING_OVERRIDE_CONF_KEY = 162 "hbase.mapreduce.hfileoutputformat.datablock.encoding"; 163 public static final String COMPRESSION_OVERRIDE_CONF_KEY = 164 "hbase.mapreduce.hfileoutputformat.compression"; 165 166 /** 167 * Keep locality while generating HFiles for bulkload. See HBASE-12596 168 */ 169 public static final String LOCALITY_SENSITIVE_CONF_KEY = 170 "hbase.bulkload.locality.sensitive.enabled"; 171 private static final boolean DEFAULT_LOCALITY_SENSITIVE = true; 172 static final String OUTPUT_TABLE_NAME_CONF_KEY = "hbase.mapreduce.hfileoutputformat.table.name"; 173 static final String MULTI_TABLE_HFILEOUTPUTFORMAT_CONF_KEY = 174 "hbase.mapreduce.use.multi.table.hfileoutputformat"; 175 176 /** 177 * ExtendedCell and ExtendedCellSerialization are InterfaceAudience.Private. We expose this config 178 * package-private for internal usage for jobs like WALPlayer which need to use features of 179 * ExtendedCell. 180 */ 181 static final String EXTENDED_CELL_SERIALIZATION_ENABLED_KEY = 182 "hbase.mapreduce.hfileoutputformat.extendedcell.enabled"; 183 static final boolean EXTENDED_CELL_SERIALIZATION_ENABLED_DEFULT = false; 184 185 public static final String REMOTE_CLUSTER_CONF_PREFIX = "hbase.hfileoutputformat.remote.cluster."; 186 public static final String REMOTE_CLUSTER_ZOOKEEPER_QUORUM_CONF_KEY = 187 REMOTE_CLUSTER_CONF_PREFIX + "zookeeper.quorum"; 188 public static final String REMOTE_CLUSTER_ZOOKEEPER_CLIENT_PORT_CONF_KEY = 189 REMOTE_CLUSTER_CONF_PREFIX + "zookeeper." + HConstants.CLIENT_PORT_STR; 190 public static final String REMOTE_CLUSTER_ZOOKEEPER_ZNODE_PARENT_CONF_KEY = 191 REMOTE_CLUSTER_CONF_PREFIX + HConstants.ZOOKEEPER_ZNODE_PARENT; 192 193 public static final String STORAGE_POLICY_PROPERTY = HStore.BLOCK_STORAGE_POLICY_KEY; 194 public static final String STORAGE_POLICY_PROPERTY_CF_PREFIX = STORAGE_POLICY_PROPERTY + "."; 195 196 @Override 197 public RecordWriter<ImmutableBytesWritable, Cell> 198 getRecordWriter(final TaskAttemptContext context) throws IOException, InterruptedException { 199 return createRecordWriter(context, this.getOutputCommitter(context)); 200 } 201 202 protected static byte[] getTableNameSuffixedWithFamily(byte[] tableName, byte[] family) { 203 return combineTableNameSuffix(tableName, family); 204 } 205 206 protected static Path getWorkPath(final OutputCommitter committer) { 207 return (Path) ReflectionUtils.invokeMethod(committer, "getWorkPath"); 208 } 209 210 static <V extends Cell> RecordWriter<ImmutableBytesWritable, V> createRecordWriter( 211 final TaskAttemptContext context, final OutputCommitter committer) throws IOException { 212 213 // Get the path of the temporary output file 214 final Path outputDir = getWorkPath(committer); 215 final Configuration conf = context.getConfiguration(); 216 final boolean writeMultipleTables = 217 conf.getBoolean(MULTI_TABLE_HFILEOUTPUTFORMAT_CONF_KEY, false); 218 final String writeTableNames = conf.get(OUTPUT_TABLE_NAME_CONF_KEY); 219 if (writeTableNames == null || writeTableNames.isEmpty()) { 220 throw new IllegalArgumentException("" + OUTPUT_TABLE_NAME_CONF_KEY + " cannot be empty"); 221 } 222 final FileSystem fs = outputDir.getFileSystem(conf); 223 // These configs. are from hbase-*.xml 224 final long maxsize = 225 conf.getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE); 226 // Invented config. Add to hbase-*.xml if other than default compression. 227 final String defaultCompressionStr = 228 conf.get("hfile.compression", Compression.Algorithm.NONE.getName()); 229 final Algorithm defaultCompression = HFileWriterImpl.compressionByName(defaultCompressionStr); 230 String compressionStr = conf.get(COMPRESSION_OVERRIDE_CONF_KEY); 231 final Algorithm overriddenCompression = 232 compressionStr != null ? Compression.getCompressionAlgorithmByName(compressionStr) : null; 233 final boolean compactionExclude = 234 conf.getBoolean("hbase.mapreduce.hfileoutputformat.compaction.exclude", false); 235 final Set<String> allTableNames = Arrays 236 .stream(writeTableNames.split(Bytes.toString(tableSeparator))).collect(Collectors.toSet()); 237 238 // create a map from column family to the compression algorithm 239 final Map<byte[], Algorithm> compressionMap = createFamilyCompressionMap(conf); 240 final Map<byte[], BloomType> bloomTypeMap = createFamilyBloomTypeMap(conf); 241 final Map<byte[], String> bloomParamMap = createFamilyBloomParamMap(conf); 242 final Map<byte[], Integer> blockSizeMap = createFamilyBlockSizeMap(conf); 243 244 String dataBlockEncodingStr = conf.get(DATABLOCK_ENCODING_OVERRIDE_CONF_KEY); 245 final Map<byte[], DataBlockEncoding> datablockEncodingMap = 246 createFamilyDataBlockEncodingMap(conf); 247 final DataBlockEncoding overriddenEncoding = 248 dataBlockEncodingStr != null ? DataBlockEncoding.valueOf(dataBlockEncodingStr) : null; 249 250 return new RecordWriter<ImmutableBytesWritable, V>() { 251 // Map of families to writers and how much has been output on the writer. 252 private final Map<byte[], WriterLength> writers = new TreeMap<>(Bytes.BYTES_COMPARATOR); 253 private final Map<byte[], byte[]> previousRows = new TreeMap<>(Bytes.BYTES_COMPARATOR); 254 private final long now = EnvironmentEdgeManager.currentTime(); 255 private byte[] tableNameBytes = writeMultipleTables ? null : Bytes.toBytes(writeTableNames); 256 257 @Override 258 public void write(ImmutableBytesWritable row, V cell) throws IOException { 259 Cell kv = cell; 260 // null input == user explicitly wants to flush 261 if (row == null && kv == null) { 262 rollWriters(null); 263 return; 264 } 265 266 byte[] rowKey = CellUtil.cloneRow(kv); 267 int length = (PrivateCellUtil.estimatedSerializedSizeOf(kv)) - Bytes.SIZEOF_INT; 268 byte[] family = CellUtil.cloneFamily(kv); 269 if (writeMultipleTables) { 270 tableNameBytes = MultiTableHFileOutputFormat.getTableName(row.get()); 271 tableNameBytes = TableName.valueOf(tableNameBytes).toBytes(); 272 if (!allTableNames.contains(Bytes.toString(tableNameBytes))) { 273 throw new IllegalArgumentException( 274 "TableName " + Bytes.toString(tableNameBytes) + " not expected"); 275 } 276 } 277 byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, family); 278 WriterLength wl = this.writers.get(tableAndFamily); 279 280 // If this is a new column family, verify that the directory exists 281 if (wl == null) { 282 Path writerPath = null; 283 if (writeMultipleTables) { 284 Path tableRelPath = getTableRelativePath(tableNameBytes); 285 writerPath = new Path(outputDir, new Path(tableRelPath, Bytes.toString(family))); 286 } else { 287 writerPath = new Path(outputDir, Bytes.toString(family)); 288 } 289 fs.mkdirs(writerPath); 290 configureStoragePolicy(conf, fs, tableAndFamily, writerPath); 291 } 292 293 // This can only happen once a row is finished though 294 if ( 295 wl != null && wl.written + length >= maxsize 296 && Bytes.compareTo(this.previousRows.get(family), rowKey) != 0 297 ) { 298 rollWriters(wl); 299 } 300 301 // create a new WAL writer, if necessary 302 if (wl == null || wl.writer == null) { 303 InetSocketAddress[] favoredNodes = null; 304 if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) { 305 HRegionLocation loc = null; 306 307 String tableName = Bytes.toString(tableNameBytes); 308 if (tableName != null) { 309 try ( 310 Connection connection = 311 ConnectionFactory.createConnection(createRemoteClusterConf(conf)); 312 RegionLocator locator = connection.getRegionLocator(TableName.valueOf(tableName))) { 313 loc = locator.getRegionLocation(rowKey); 314 } catch (Throwable e) { 315 LOG.warn("Something wrong locating rowkey {} in {}", Bytes.toString(rowKey), 316 tableName, e); 317 loc = null; 318 } 319 } 320 if (null == loc) { 321 LOG.trace("Failed get of location, use default writer {}", Bytes.toString(rowKey)); 322 } else { 323 LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey)); 324 InetSocketAddress initialIsa = 325 new InetSocketAddress(loc.getHostname(), loc.getPort()); 326 if (initialIsa.isUnresolved()) { 327 LOG.trace("Failed resolve address {}, use default writer", loc.getHostnamePort()); 328 } else { 329 LOG.debug("Use favored nodes writer: {}", initialIsa.getHostString()); 330 favoredNodes = new InetSocketAddress[] { initialIsa }; 331 } 332 } 333 } 334 wl = getNewWriter(tableNameBytes, family, conf, favoredNodes); 335 336 } 337 338 // we now have the proper WAL writer. full steam ahead 339 PrivateCellUtil.updateLatestStamp(cell, this.now); 340 wl.writer.append(kv); 341 wl.written += length; 342 343 // Copy the row so we know when a row transition. 344 this.previousRows.put(family, rowKey); 345 } 346 347 private Path getTableRelativePath(byte[] tableNameBytes) { 348 String tableName = Bytes.toString(tableNameBytes); 349 String[] tableNameParts = tableName.split(":"); 350 Path tableRelPath = new Path(tableNameParts[0]); 351 if (tableNameParts.length > 1) { 352 tableRelPath = new Path(tableRelPath, tableNameParts[1]); 353 } 354 return tableRelPath; 355 } 356 357 private void rollWriters(WriterLength writerLength) throws IOException { 358 if (writerLength != null) { 359 closeWriter(writerLength); 360 } else { 361 for (WriterLength wl : this.writers.values()) { 362 closeWriter(wl); 363 } 364 } 365 } 366 367 private void closeWriter(WriterLength wl) throws IOException { 368 if (wl.writer != null) { 369 LOG.info( 370 "Writer=" + wl.writer.getPath() + ((wl.written == 0) ? "" : ", wrote=" + wl.written)); 371 close(wl.writer); 372 wl.writer = null; 373 } 374 wl.written = 0; 375 } 376 377 private Configuration createRemoteClusterConf(Configuration conf) { 378 final Configuration newConf = new Configuration(conf); 379 380 final String quorum = conf.get(REMOTE_CLUSTER_ZOOKEEPER_QUORUM_CONF_KEY); 381 final String clientPort = conf.get(REMOTE_CLUSTER_ZOOKEEPER_CLIENT_PORT_CONF_KEY); 382 final String parent = conf.get(REMOTE_CLUSTER_ZOOKEEPER_ZNODE_PARENT_CONF_KEY); 383 384 if (quorum != null && clientPort != null && parent != null) { 385 newConf.set(HConstants.ZOOKEEPER_QUORUM, quorum); 386 newConf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.parseInt(clientPort)); 387 newConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, parent); 388 } 389 390 for (Entry<String, String> entry : conf) { 391 String key = entry.getKey(); 392 if ( 393 REMOTE_CLUSTER_ZOOKEEPER_QUORUM_CONF_KEY.equals(key) 394 || REMOTE_CLUSTER_ZOOKEEPER_CLIENT_PORT_CONF_KEY.equals(key) 395 || REMOTE_CLUSTER_ZOOKEEPER_ZNODE_PARENT_CONF_KEY.equals(key) 396 ) { 397 // Handled them above 398 continue; 399 } 400 401 if (entry.getKey().startsWith(REMOTE_CLUSTER_CONF_PREFIX)) { 402 String originalKey = entry.getKey().substring(REMOTE_CLUSTER_CONF_PREFIX.length()); 403 if (!originalKey.isEmpty()) { 404 newConf.set(originalKey, entry.getValue()); 405 } 406 } 407 } 408 409 return newConf; 410 } 411 412 /* 413 * Create a new StoreFile.Writer. 414 * @return A WriterLength, containing a new StoreFile.Writer. 415 */ 416 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "BX_UNBOXING_IMMEDIATELY_REBOXED", 417 justification = "Not important") 418 private WriterLength getNewWriter(byte[] tableName, byte[] family, Configuration conf, 419 InetSocketAddress[] favoredNodes) throws IOException { 420 byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableName, family); 421 Path familydir = new Path(outputDir, Bytes.toString(family)); 422 if (writeMultipleTables) { 423 familydir = 424 new Path(outputDir, new Path(getTableRelativePath(tableName), Bytes.toString(family))); 425 } 426 WriterLength wl = new WriterLength(); 427 Algorithm compression = overriddenCompression; 428 compression = compression == null ? compressionMap.get(tableAndFamily) : compression; 429 compression = compression == null ? defaultCompression : compression; 430 BloomType bloomType = bloomTypeMap.get(tableAndFamily); 431 bloomType = bloomType == null ? BloomType.NONE : bloomType; 432 String bloomParam = bloomParamMap.get(tableAndFamily); 433 if (bloomType == BloomType.ROWPREFIX_FIXED_LENGTH) { 434 conf.set(BloomFilterUtil.PREFIX_LENGTH_KEY, bloomParam); 435 } 436 Integer blockSize = blockSizeMap.get(tableAndFamily); 437 blockSize = blockSize == null ? HConstants.DEFAULT_BLOCKSIZE : blockSize; 438 DataBlockEncoding encoding = overriddenEncoding; 439 encoding = encoding == null ? datablockEncodingMap.get(tableAndFamily) : encoding; 440 encoding = encoding == null ? DataBlockEncoding.NONE : encoding; 441 HFileContextBuilder contextBuilder = new HFileContextBuilder().withCompression(compression) 442 .withDataBlockEncoding(encoding).withChecksumType(StoreUtils.getChecksumType(conf)) 443 .withBytesPerCheckSum(StoreUtils.getBytesPerChecksum(conf)).withBlockSize(blockSize) 444 .withColumnFamily(family).withTableName(tableName) 445 .withCreateTime(EnvironmentEdgeManager.currentTime()); 446 447 if (HFile.getFormatVersion(conf) >= HFile.MIN_FORMAT_VERSION_WITH_TAGS) { 448 contextBuilder.withIncludesTags(true); 449 } 450 451 HFileContext hFileContext = contextBuilder.build(); 452 if (null == favoredNodes) { 453 wl.writer = 454 new StoreFileWriter.Builder(conf, CacheConfig.DISABLED, fs).withOutputDir(familydir) 455 .withBloomType(bloomType).withFileContext(hFileContext).build(); 456 } else { 457 wl.writer = new StoreFileWriter.Builder(conf, CacheConfig.DISABLED, new HFileSystem(fs)) 458 .withOutputDir(familydir).withBloomType(bloomType).withFileContext(hFileContext) 459 .withFavoredNodes(favoredNodes).build(); 460 } 461 462 this.writers.put(tableAndFamily, wl); 463 return wl; 464 } 465 466 private void close(final StoreFileWriter w) throws IOException { 467 if (w != null) { 468 w.appendFileInfo(BULKLOAD_TIME_KEY, Bytes.toBytes(EnvironmentEdgeManager.currentTime())); 469 w.appendFileInfo(BULKLOAD_TASK_KEY, Bytes.toBytes(context.getTaskAttemptID().toString())); 470 w.appendFileInfo(MAJOR_COMPACTION_KEY, Bytes.toBytes(true)); 471 w.appendFileInfo(EXCLUDE_FROM_MINOR_COMPACTION_KEY, Bytes.toBytes(compactionExclude)); 472 w.appendTrackedTimestampsToMetadata(); 473 w.close(); 474 } 475 } 476 477 @Override 478 public void close(TaskAttemptContext c) throws IOException, InterruptedException { 479 for (WriterLength wl : this.writers.values()) { 480 close(wl.writer); 481 } 482 } 483 }; 484 } 485 486 /** 487 * Configure block storage policy for CF after the directory is created. 488 */ 489 static void configureStoragePolicy(final Configuration conf, final FileSystem fs, 490 byte[] tableAndFamily, Path cfPath) { 491 if (null == conf || null == fs || null == tableAndFamily || null == cfPath) { 492 return; 493 } 494 495 String policy = conf.get(STORAGE_POLICY_PROPERTY_CF_PREFIX + Bytes.toString(tableAndFamily), 496 conf.get(STORAGE_POLICY_PROPERTY)); 497 CommonFSUtils.setStoragePolicy(fs, cfPath, policy); 498 } 499 500 /* 501 * Data structure to hold a Writer and amount of data written on it. 502 */ 503 static class WriterLength { 504 long written = 0; 505 StoreFileWriter writer = null; 506 } 507 508 /** 509 * Return the start keys of all of the regions in this table, as a list of ImmutableBytesWritable. 510 */ 511 private static List<ImmutableBytesWritable> getRegionStartKeys(List<RegionLocator> regionLocators, 512 boolean writeMultipleTables) throws IOException { 513 514 ArrayList<ImmutableBytesWritable> ret = new ArrayList<>(); 515 for (RegionLocator regionLocator : regionLocators) { 516 TableName tableName = regionLocator.getName(); 517 LOG.info("Looking up current regions for table " + tableName); 518 byte[][] byteKeys = regionLocator.getStartKeys(); 519 for (byte[] byteKey : byteKeys) { 520 byte[] fullKey = byteKey; // HFileOutputFormat2 use case 521 if (writeMultipleTables) { 522 // MultiTableHFileOutputFormat use case 523 fullKey = combineTableNameSuffix(tableName.getName(), byteKey); 524 } 525 if (LOG.isDebugEnabled()) { 526 LOG.debug("SplitPoint startkey for " + tableName + ": " + Bytes.toStringBinary(fullKey)); 527 } 528 ret.add(new ImmutableBytesWritable(fullKey)); 529 } 530 } 531 return ret; 532 } 533 534 /** 535 * Write out a {@link SequenceFile} that can be read by {@link TotalOrderPartitioner} that 536 * contains the split points in startKeys. 537 */ 538 @SuppressWarnings("deprecation") 539 private static void writePartitions(Configuration conf, Path partitionsPath, 540 List<ImmutableBytesWritable> startKeys, boolean writeMultipleTables) throws IOException { 541 LOG.info("Writing partition information to " + partitionsPath); 542 if (startKeys.isEmpty()) { 543 throw new IllegalArgumentException("No regions passed"); 544 } 545 546 // We're generating a list of split points, and we don't ever 547 // have keys < the first region (which has an empty start key) 548 // so we need to remove it. Otherwise we would end up with an 549 // empty reducer with index 0 550 TreeSet<ImmutableBytesWritable> sorted = new TreeSet<>(startKeys); 551 ImmutableBytesWritable first = sorted.first(); 552 if (writeMultipleTables) { 553 first = 554 new ImmutableBytesWritable(MultiTableHFileOutputFormat.getSuffix(sorted.first().get())); 555 } 556 if (!first.equals(HConstants.EMPTY_BYTE_ARRAY)) { 557 throw new IllegalArgumentException( 558 "First region of table should have empty start key. Instead has: " 559 + Bytes.toStringBinary(first.get())); 560 } 561 sorted.remove(sorted.first()); 562 563 // Write the actual file 564 FileSystem fs = partitionsPath.getFileSystem(conf); 565 SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, partitionsPath, 566 ImmutableBytesWritable.class, NullWritable.class); 567 568 try { 569 for (ImmutableBytesWritable startKey : sorted) { 570 writer.append(startKey, NullWritable.get()); 571 } 572 } finally { 573 writer.close(); 574 } 575 } 576 577 /** 578 * Configure a MapReduce Job to perform an incremental load into the given table. This 579 * <ul> 580 * <li>Inspects the table to configure a total order partitioner</li> 581 * <li>Uploads the partitions file to the cluster and adds it to the DistributedCache</li> 582 * <li>Sets the number of reduce tasks to match the current number of regions</li> 583 * <li>Sets the output key/value class to match HFileOutputFormat2's requirements</li> 584 * <li>Sets the reducer up to perform the appropriate sorting (either KeyValueSortReducer or 585 * PutSortReducer)</li> 586 * <li>Sets the HBase cluster key to load region locations for locality-sensitive</li> 587 * </ul> 588 * The user should be sure to set the map output value class to either KeyValue or Put before 589 * running this function. 590 */ 591 public static void configureIncrementalLoad(Job job, Table table, RegionLocator regionLocator) 592 throws IOException { 593 configureIncrementalLoad(job, table.getDescriptor(), regionLocator); 594 configureRemoteCluster(job, table.getConfiguration()); 595 } 596 597 /** 598 * Configure a MapReduce Job to perform an incremental load into the given table. This 599 * <ul> 600 * <li>Inspects the table to configure a total order partitioner</li> 601 * <li>Uploads the partitions file to the cluster and adds it to the DistributedCache</li> 602 * <li>Sets the number of reduce tasks to match the current number of regions</li> 603 * <li>Sets the output key/value class to match HFileOutputFormat2's requirements</li> 604 * <li>Sets the reducer up to perform the appropriate sorting (either KeyValueSortReducer or 605 * PutSortReducer)</li> 606 * </ul> 607 * The user should be sure to set the map output value class to either KeyValue or Put before 608 * running this function. 609 */ 610 public static void configureIncrementalLoad(Job job, TableDescriptor tableDescriptor, 611 RegionLocator regionLocator) throws IOException { 612 ArrayList<TableInfo> singleTableInfo = new ArrayList<>(); 613 singleTableInfo.add(new TableInfo(tableDescriptor, regionLocator)); 614 configureIncrementalLoad(job, singleTableInfo, HFileOutputFormat2.class); 615 } 616 617 static void configureIncrementalLoad(Job job, List<TableInfo> multiTableInfo, 618 Class<? extends OutputFormat<?, ?>> cls) throws IOException { 619 Configuration conf = job.getConfiguration(); 620 job.setOutputKeyClass(ImmutableBytesWritable.class); 621 job.setOutputValueClass(MapReduceExtendedCell.class); 622 job.setOutputFormatClass(cls); 623 624 if (multiTableInfo.stream().distinct().count() != multiTableInfo.size()) { 625 throw new IllegalArgumentException("Duplicate entries found in TableInfo argument"); 626 } 627 boolean writeMultipleTables = false; 628 if (MultiTableHFileOutputFormat.class.equals(cls)) { 629 writeMultipleTables = true; 630 conf.setBoolean(MULTI_TABLE_HFILEOUTPUTFORMAT_CONF_KEY, true); 631 } 632 // Based on the configured map output class, set the correct reducer to properly 633 // sort the incoming values. 634 // TODO it would be nice to pick one or the other of these formats. 635 if ( 636 KeyValue.class.equals(job.getMapOutputValueClass()) 637 || MapReduceExtendedCell.class.equals(job.getMapOutputValueClass()) 638 ) { 639 job.setReducerClass(CellSortReducer.class); 640 } else if (Put.class.equals(job.getMapOutputValueClass())) { 641 job.setReducerClass(PutSortReducer.class); 642 } else if (Text.class.equals(job.getMapOutputValueClass())) { 643 job.setReducerClass(TextSortReducer.class); 644 } else { 645 LOG.warn("Unknown map output value type:" + job.getMapOutputValueClass()); 646 } 647 648 mergeSerializations(conf); 649 650 if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) { 651 LOG.info("bulkload locality sensitive enabled"); 652 } 653 654 /* Now get the region start keys for every table required */ 655 List<String> allTableNames = new ArrayList<>(multiTableInfo.size()); 656 List<RegionLocator> regionLocators = new ArrayList<>(multiTableInfo.size()); 657 List<TableDescriptor> tableDescriptors = new ArrayList<>(multiTableInfo.size()); 658 659 for (TableInfo tableInfo : multiTableInfo) { 660 regionLocators.add(tableInfo.getRegionLocator()); 661 allTableNames.add(tableInfo.getRegionLocator().getName().getNameAsString()); 662 tableDescriptors.add(tableInfo.getTableDescriptor()); 663 } 664 // Record tablenames for creating writer by favored nodes, and decoding compression, 665 // block size and other attributes of columnfamily per table 666 conf.set(OUTPUT_TABLE_NAME_CONF_KEY, 667 StringUtils.join(allTableNames, Bytes.toString(tableSeparator))); 668 List<ImmutableBytesWritable> startKeys = 669 getRegionStartKeys(regionLocators, writeMultipleTables); 670 // Use table's region boundaries for TOP split points. 671 LOG.info("Configuring " + startKeys.size() + " reduce partitions " 672 + "to match current region count for all tables"); 673 job.setNumReduceTasks(startKeys.size()); 674 675 configurePartitioner(job, startKeys, writeMultipleTables); 676 // Set compression algorithms based on column families 677 678 conf.set(COMPRESSION_FAMILIES_CONF_KEY, 679 serializeColumnFamilyAttribute(compressionDetails, tableDescriptors)); 680 conf.set(BLOCK_SIZE_FAMILIES_CONF_KEY, 681 serializeColumnFamilyAttribute(blockSizeDetails, tableDescriptors)); 682 conf.set(BLOOM_TYPE_FAMILIES_CONF_KEY, 683 serializeColumnFamilyAttribute(bloomTypeDetails, tableDescriptors)); 684 conf.set(BLOOM_PARAM_FAMILIES_CONF_KEY, 685 serializeColumnFamilyAttribute(bloomParamDetails, tableDescriptors)); 686 conf.set(DATABLOCK_ENCODING_FAMILIES_CONF_KEY, 687 serializeColumnFamilyAttribute(dataBlockEncodingDetails, tableDescriptors)); 688 689 TableMapReduceUtil.addDependencyJars(job); 690 TableMapReduceUtil.initCredentials(job); 691 LOG.info("Incremental output configured for tables: " + StringUtils.join(allTableNames, ",")); 692 } 693 694 private static void mergeSerializations(Configuration conf) { 695 List<String> serializations = new ArrayList<>(); 696 697 // add any existing values that have been set 698 String[] existing = conf.getStrings("io.serializations"); 699 if (existing != null) { 700 Collections.addAll(serializations, existing); 701 } 702 703 serializations.add(MutationSerialization.class.getName()); 704 serializations.add(ResultSerialization.class.getName()); 705 706 // Add ExtendedCellSerialization, if configured. Order matters here. Hadoop's 707 // SerializationFactory runs through serializations in the order they are registered. 708 // We want to register ExtendedCellSerialization before CellSerialization because both 709 // work for ExtendedCells but only ExtendedCellSerialization handles them properly. 710 if ( 711 conf.getBoolean(EXTENDED_CELL_SERIALIZATION_ENABLED_KEY, 712 EXTENDED_CELL_SERIALIZATION_ENABLED_DEFULT) 713 ) { 714 serializations.add(ExtendedCellSerialization.class.getName()); 715 } 716 serializations.add(CellSerialization.class.getName()); 717 718 conf.setStrings("io.serializations", serializations.toArray(new String[0])); 719 } 720 721 public static void configureIncrementalLoadMap(Job job, TableDescriptor tableDescriptor) 722 throws IOException { 723 Configuration conf = job.getConfiguration(); 724 725 job.setOutputKeyClass(ImmutableBytesWritable.class); 726 job.setOutputValueClass(MapReduceExtendedCell.class); 727 job.setOutputFormatClass(HFileOutputFormat2.class); 728 729 ArrayList<TableDescriptor> singleTableDescriptor = new ArrayList<>(1); 730 singleTableDescriptor.add(tableDescriptor); 731 732 conf.set(OUTPUT_TABLE_NAME_CONF_KEY, tableDescriptor.getTableName().getNameAsString()); 733 // Set compression algorithms based on column families 734 conf.set(COMPRESSION_FAMILIES_CONF_KEY, 735 serializeColumnFamilyAttribute(compressionDetails, singleTableDescriptor)); 736 conf.set(BLOCK_SIZE_FAMILIES_CONF_KEY, 737 serializeColumnFamilyAttribute(blockSizeDetails, singleTableDescriptor)); 738 conf.set(BLOOM_TYPE_FAMILIES_CONF_KEY, 739 serializeColumnFamilyAttribute(bloomTypeDetails, singleTableDescriptor)); 740 conf.set(BLOOM_PARAM_FAMILIES_CONF_KEY, 741 serializeColumnFamilyAttribute(bloomParamDetails, singleTableDescriptor)); 742 conf.set(DATABLOCK_ENCODING_FAMILIES_CONF_KEY, 743 serializeColumnFamilyAttribute(dataBlockEncodingDetails, singleTableDescriptor)); 744 745 TableMapReduceUtil.addDependencyJars(job); 746 TableMapReduceUtil.initCredentials(job); 747 LOG.info("Incremental table " + tableDescriptor.getTableName() + " output configured."); 748 } 749 750 /** 751 * Configure HBase cluster key for remote cluster to load region location for locality-sensitive 752 * if it's enabled. It's not necessary to call this method explicitly when the cluster key for 753 * HBase cluster to be used to load region location is configured in the job configuration. Call 754 * this method when another HBase cluster key is configured in the job configuration. For example, 755 * you should call when you load data from HBase cluster A using {@link TableInputFormat} and 756 * generate hfiles for HBase cluster B. Otherwise, HFileOutputFormat2 fetch location from cluster 757 * A and locality-sensitive won't working correctly. 758 * {@link #configureIncrementalLoad(Job, Table, RegionLocator)} calls this method using 759 * {@link Table#getConfiguration} as clusterConf. See HBASE-25608. 760 * @param job which has configuration to be updated 761 * @param clusterConf which contains cluster key of the HBase cluster to be locality-sensitive 762 * @see #configureIncrementalLoad(Job, Table, RegionLocator) 763 * @see #LOCALITY_SENSITIVE_CONF_KEY 764 * @see #REMOTE_CLUSTER_ZOOKEEPER_QUORUM_CONF_KEY 765 * @see #REMOTE_CLUSTER_ZOOKEEPER_CLIENT_PORT_CONF_KEY 766 * @see #REMOTE_CLUSTER_ZOOKEEPER_ZNODE_PARENT_CONF_KEY 767 */ 768 public static void configureRemoteCluster(Job job, Configuration clusterConf) { 769 Configuration conf = job.getConfiguration(); 770 771 if (!conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) { 772 return; 773 } 774 775 final String quorum = clusterConf.get(HConstants.ZOOKEEPER_QUORUM); 776 final int clientPort = clusterConf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 777 HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT); 778 final String parent = 779 clusterConf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); 780 781 conf.set(REMOTE_CLUSTER_ZOOKEEPER_QUORUM_CONF_KEY, quorum); 782 conf.setInt(REMOTE_CLUSTER_ZOOKEEPER_CLIENT_PORT_CONF_KEY, clientPort); 783 conf.set(REMOTE_CLUSTER_ZOOKEEPER_ZNODE_PARENT_CONF_KEY, parent); 784 785 LOG.info("ZK configs for remote cluster of bulkload is configured: " + quorum + ":" + clientPort 786 + "/" + parent); 787 } 788 789 /** 790 * Runs inside the task to deserialize column family to compression algorithm map from the 791 * configuration. 792 * @param conf to read the serialized values from 793 * @return a map from column family to the configured compression algorithm 794 */ 795 @InterfaceAudience.Private 796 static Map<byte[], Algorithm> createFamilyCompressionMap(Configuration conf) { 797 Map<byte[], String> stringMap = createFamilyConfValueMap(conf, COMPRESSION_FAMILIES_CONF_KEY); 798 Map<byte[], Algorithm> compressionMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); 799 for (Map.Entry<byte[], String> e : stringMap.entrySet()) { 800 Algorithm algorithm = HFileWriterImpl.compressionByName(e.getValue()); 801 compressionMap.put(e.getKey(), algorithm); 802 } 803 return compressionMap; 804 } 805 806 /** 807 * Runs inside the task to deserialize column family to bloom filter type map from the 808 * configuration. 809 * @param conf to read the serialized values from 810 * @return a map from column family to the the configured bloom filter type 811 */ 812 @InterfaceAudience.Private 813 static Map<byte[], BloomType> createFamilyBloomTypeMap(Configuration conf) { 814 Map<byte[], String> stringMap = createFamilyConfValueMap(conf, BLOOM_TYPE_FAMILIES_CONF_KEY); 815 Map<byte[], BloomType> bloomTypeMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); 816 for (Map.Entry<byte[], String> e : stringMap.entrySet()) { 817 BloomType bloomType = BloomType.valueOf(e.getValue()); 818 bloomTypeMap.put(e.getKey(), bloomType); 819 } 820 return bloomTypeMap; 821 } 822 823 /** 824 * Runs inside the task to deserialize column family to bloom filter param map from the 825 * configuration. 826 * @param conf to read the serialized values from 827 * @return a map from column family to the the configured bloom filter param 828 */ 829 @InterfaceAudience.Private 830 static Map<byte[], String> createFamilyBloomParamMap(Configuration conf) { 831 return createFamilyConfValueMap(conf, BLOOM_PARAM_FAMILIES_CONF_KEY); 832 } 833 834 /** 835 * Runs inside the task to deserialize column family to block size map from the configuration. 836 * @param conf to read the serialized values from 837 * @return a map from column family to the configured block size 838 */ 839 @InterfaceAudience.Private 840 static Map<byte[], Integer> createFamilyBlockSizeMap(Configuration conf) { 841 Map<byte[], String> stringMap = createFamilyConfValueMap(conf, BLOCK_SIZE_FAMILIES_CONF_KEY); 842 Map<byte[], Integer> blockSizeMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); 843 for (Map.Entry<byte[], String> e : stringMap.entrySet()) { 844 Integer blockSize = Integer.parseInt(e.getValue()); 845 blockSizeMap.put(e.getKey(), blockSize); 846 } 847 return blockSizeMap; 848 } 849 850 /** 851 * Runs inside the task to deserialize column family to data block encoding type map from the 852 * configuration. 853 * @param conf to read the serialized values from 854 * @return a map from column family to HFileDataBlockEncoder for the configured data block type 855 * for the family 856 */ 857 @InterfaceAudience.Private 858 static Map<byte[], DataBlockEncoding> createFamilyDataBlockEncodingMap(Configuration conf) { 859 Map<byte[], String> stringMap = 860 createFamilyConfValueMap(conf, DATABLOCK_ENCODING_FAMILIES_CONF_KEY); 861 Map<byte[], DataBlockEncoding> encoderMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); 862 for (Map.Entry<byte[], String> e : stringMap.entrySet()) { 863 encoderMap.put(e.getKey(), DataBlockEncoding.valueOf((e.getValue()))); 864 } 865 return encoderMap; 866 } 867 868 /** 869 * Run inside the task to deserialize column family to given conf value map. 870 * @param conf to read the serialized values from 871 * @param confName conf key to read from the configuration 872 * @return a map of column family to the given configuration value 873 */ 874 private static Map<byte[], String> createFamilyConfValueMap(Configuration conf, String confName) { 875 Map<byte[], String> confValMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); 876 String confVal = conf.get(confName, ""); 877 for (String familyConf : confVal.split("&")) { 878 String[] familySplit = familyConf.split("="); 879 if (familySplit.length != 2) { 880 continue; 881 } 882 try { 883 confValMap.put(Bytes.toBytes(URLDecoder.decode(familySplit[0], "UTF-8")), 884 URLDecoder.decode(familySplit[1], "UTF-8")); 885 } catch (UnsupportedEncodingException e) { 886 // will not happen with UTF-8 encoding 887 throw new AssertionError(e); 888 } 889 } 890 return confValMap; 891 } 892 893 /** 894 * Configure <code>job</code> with a TotalOrderPartitioner, partitioning against 895 * <code>splitPoints</code>. Cleans up the partitions file after job exists. 896 */ 897 static void configurePartitioner(Job job, List<ImmutableBytesWritable> splitPoints, 898 boolean writeMultipleTables) throws IOException { 899 Configuration conf = job.getConfiguration(); 900 // create the partitions file 901 FileSystem fs = FileSystem.get(conf); 902 String hbaseTmpFsDir = 903 conf.get(HConstants.TEMPORARY_FS_DIRECTORY_KEY, HConstants.DEFAULT_TEMPORARY_HDFS_DIRECTORY); 904 Path partitionsPath = new Path(hbaseTmpFsDir, "partitions_" + UUID.randomUUID()); 905 fs.makeQualified(partitionsPath); 906 writePartitions(conf, partitionsPath, splitPoints, writeMultipleTables); 907 fs.deleteOnExit(partitionsPath); 908 909 // configure job to use it 910 job.setPartitionerClass(TotalOrderPartitioner.class); 911 TotalOrderPartitioner.setPartitionFile(conf, partitionsPath); 912 } 913 914 @edu.umd.cs.findbugs.annotations.SuppressWarnings( 915 value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") 916 @InterfaceAudience.Private 917 static String serializeColumnFamilyAttribute(Function<ColumnFamilyDescriptor, String> fn, 918 List<TableDescriptor> allTables) throws UnsupportedEncodingException { 919 StringBuilder attributeValue = new StringBuilder(); 920 int i = 0; 921 for (TableDescriptor tableDescriptor : allTables) { 922 if (tableDescriptor == null) { 923 // could happen with mock table instance 924 // CODEREVIEW: Can I set an empty string in conf if mock table instance? 925 return ""; 926 } 927 for (ColumnFamilyDescriptor familyDescriptor : tableDescriptor.getColumnFamilies()) { 928 if (i++ > 0) { 929 attributeValue.append('&'); 930 } 931 attributeValue.append(URLEncoder 932 .encode(Bytes.toString(combineTableNameSuffix(tableDescriptor.getTableName().getName(), 933 familyDescriptor.getName())), "UTF-8")); 934 attributeValue.append('='); 935 attributeValue.append(URLEncoder.encode(fn.apply(familyDescriptor), "UTF-8")); 936 } 937 } 938 // Get rid of the last ampersand 939 return attributeValue.toString(); 940 } 941 942 /** 943 * Serialize column family to compression algorithm map to configuration. Invoked while 944 * configuring the MR job for incremental load. 945 */ 946 @InterfaceAudience.Private 947 static Function<ColumnFamilyDescriptor, String> compressionDetails = 948 familyDescriptor -> familyDescriptor.getCompressionType().getName(); 949 950 /** 951 * Serialize column family to block size map to configuration. Invoked while configuring the MR 952 * job for incremental load. 953 */ 954 @InterfaceAudience.Private 955 static Function<ColumnFamilyDescriptor, String> blockSizeDetails = 956 familyDescriptor -> String.valueOf(familyDescriptor.getBlocksize()); 957 958 /** 959 * Serialize column family to bloom type map to configuration. Invoked while configuring the MR 960 * job for incremental load. 961 */ 962 @InterfaceAudience.Private 963 static Function<ColumnFamilyDescriptor, String> bloomTypeDetails = familyDescriptor -> { 964 String bloomType = familyDescriptor.getBloomFilterType().toString(); 965 if (bloomType == null) { 966 bloomType = ColumnFamilyDescriptorBuilder.DEFAULT_BLOOMFILTER.name(); 967 } 968 return bloomType; 969 }; 970 971 /** 972 * Serialize column family to bloom param map to configuration. Invoked while configuring the MR 973 * job for incremental load. 974 */ 975 @InterfaceAudience.Private 976 static Function<ColumnFamilyDescriptor, String> bloomParamDetails = familyDescriptor -> { 977 BloomType bloomType = familyDescriptor.getBloomFilterType(); 978 String bloomParam = ""; 979 if (bloomType == BloomType.ROWPREFIX_FIXED_LENGTH) { 980 bloomParam = familyDescriptor.getConfigurationValue(BloomFilterUtil.PREFIX_LENGTH_KEY); 981 } 982 return bloomParam; 983 }; 984 985 /** 986 * Serialize column family to data block encoding map to configuration. Invoked while configuring 987 * the MR job for incremental load. 988 */ 989 @InterfaceAudience.Private 990 static Function<ColumnFamilyDescriptor, String> dataBlockEncodingDetails = familyDescriptor -> { 991 DataBlockEncoding encoding = familyDescriptor.getDataBlockEncoding(); 992 if (encoding == null) { 993 encoding = DataBlockEncoding.NONE; 994 } 995 return encoding.toString(); 996 }; 997 998}