Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HubSpot Backport: HBASE-28586 Backport HBASE-24791 Improve HFileOutputFormat2 to avoid always call getTableRelativePath method #98

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static <V extends Cell> RecordWriter<ImmutableBytesWritable, V> createRecordWrit
private final Map<byte[], WriterLength> writers = new TreeMap<>(Bytes.BYTES_COMPARATOR);
private final Map<byte[], byte[]> previousRows = new TreeMap<>(Bytes.BYTES_COMPARATOR);
private final long now = EnvironmentEdgeManager.currentTime();
private byte[] tableNameBytes = writeMultipleTables ? null : Bytes.toBytes(writeTableNames);

@Override
public void write(ImmutableBytesWritable row, V cell) throws IOException {
Expand All @@ -275,7 +276,6 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
byte[] rowKey = CellUtil.cloneRow(kv);
int length = (PrivateCellUtil.estimatedSerializedSizeOf(kv)) - Bytes.SIZEOF_INT;
byte[] family = CellUtil.cloneFamily(kv);
byte[] tableNameBytes = null;
if (writeMultipleTables) {
tableNameBytes = MultiTableHFileOutputFormat.getTableName(row.get());
tableNameBytes = writeToTableWithNamespace
Expand All @@ -286,10 +286,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
throw new IllegalArgumentException(
"TableName " + Bytes.toString(tableNameBytes) + " not expected");
}
} else {
tableNameBytes = Bytes.toBytes(writeTableNames);
}
Path tableRelPath = getTableRelativePath(tableNameBytes);
byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, family);

WriterLength wl = this.writers.get(tableAndFamily);
Expand All @@ -298,6 +295,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
if (wl == null) {
Path writerPath = null;
if (writeMultipleTables) {
Path tableRelPath = getTableRelativePath(tableNameBytes);
writerPath = new Path(outputDir, new Path(tableRelPath, Bytes.toString(family)));
} else {
writerPath = new Path(outputDir, Bytes.toString(family));
Expand All @@ -316,6 +314,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {

// create a new WAL writer, if necessary
if (wl == null || wl.writer == null) {
InetSocketAddress[] favoredNodes = null;
if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) {
HRegionLocation loc = null;
String tableName = Bytes.toString(tableNameBytes);
Expand All @@ -331,26 +330,22 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
loc = null;
}
}

if (null == loc) {
LOG.trace("Failed get of location, use default writer {}", Bytes.toString(rowKey));
wl = getNewWriter(tableNameBytes, family, conf, null);
} else {
LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey));
InetSocketAddress initialIsa =
new InetSocketAddress(loc.getHostname(), loc.getPort());
if (initialIsa.isUnresolved()) {
LOG.trace("Failed resolve address {}, use default writer", loc.getHostnamePort());
wl = getNewWriter(tableNameBytes, family, conf, null);
} else {
LOG.debug("Use favored nodes writer: {}", initialIsa.getHostString());
wl = getNewWriter(tableNameBytes, family, conf,
new InetSocketAddress[] { initialIsa });
favoredNodes = new InetSocketAddress[] { initialIsa };
}
}
} else {
wl = getNewWriter(tableNameBytes, family, conf, null);
}
wl = getNewWriter(tableNameBytes, family, conf, favoredNodes);

}

// we now have the proper WAL writer. full steam ahead
Expand All @@ -365,9 +360,9 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
private Path getTableRelativePath(byte[] tableNameBytes) {
String tableName = Bytes.toString(tableNameBytes);
String[] tableNameParts = tableName.split(":");
Path tableRelPath = new Path(tableName.split(":")[0]);
Path tableRelPath = new Path(tableNameParts[0]);
if (tableNameParts.length > 1) {
tableRelPath = new Path(tableRelPath, tableName.split(":")[1]);
tableRelPath = new Path(tableRelPath, tableNameParts[1]);
}
return tableRelPath;
}
Expand Down