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

[Enhance](fe) select BE local broker to scan Hive table when 'broker.name' in hms catalog is specified #27122

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
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 @@ -99,6 +99,8 @@ public abstract class FileQueryScanNode extends FileScanNode {
@Getter
protected TableSample tableSample;

protected String brokerName;

/**
* External file scan node for Query hms table
* needCheckColumnPriv: Some of ExternalFileScanNode do not need to check column priv
Expand Down Expand Up @@ -318,7 +320,6 @@ public void createScanRangeLocations() throws UserException {
for (Split split : inputSplits) {
FileSplit fileSplit = (FileSplit) split;
TFileType locationType = getLocationType(fileSplit.getPath().toString());
setLocationPropertiesIfNecessary(locationType, locationProperties);

TScanRangeLocations curLocations = newLocations();
// If fileSplit has partition values, use the values collected from hive partitions.
Expand Down Expand Up @@ -378,6 +379,7 @@ public void createScanRangeLocations() throws UserException {
} else {
selectedBackend = backendPolicy.getNextBe();
}
setLocationPropertiesIfNecessary(selectedBackend, locationType, locationProperties);
location.setBackendId(selectedBackend.getId());
location.setServer(new TNetworkAddress(selectedBackend.getHost(), selectedBackend.getBePort()));
curLocations.addToLocations(location);
Expand All @@ -394,7 +396,7 @@ public void createScanRangeLocations() throws UserException {
scanRangeLocations.size(), (System.currentTimeMillis() - start));
}

private void setLocationPropertiesIfNecessary(TFileType locationType,
private void setLocationPropertiesIfNecessary(Backend selectedBackend, TFileType locationType,
Map<String, String> locationProperties) throws UserException {
if (locationType == TFileType.FILE_HDFS || locationType == TFileType.FILE_BROKER) {
if (!params.isSetHdfsParams()) {
Expand All @@ -407,7 +409,15 @@ private void setLocationPropertiesIfNecessary(TFileType locationType,
params.setProperties(locationProperties);

if (!params.isSetBrokerAddresses()) {
FsBroker broker = Env.getCurrentEnv().getBrokerMgr().getAnyAliveBroker();
FsBroker broker;
if (brokerName != null) {
broker = Env.getCurrentEnv().getBrokerMgr().getBroker(brokerName, selectedBackend.getHost());
LOG.debug(String.format(
"Set location for broker [%s], selected BE host: [%s] selected broker host: [%s]",
brokerName, selectedBackend.getHost(), broker.host));
} else {
broker = Env.getCurrentEnv().getBrokerMgr().getAnyAliveBroker();
}
if (broker == null) {
throw new UserException("No alive broker.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ public class HiveScanNode extends FileQueryScanNode {
public HiveScanNode(PlanNodeId id, TupleDescriptor desc, boolean needCheckColumnPriv) {
super(id, desc, "HIVE_SCAN_NODE", StatisticalType.HIVE_SCAN_NODE, needCheckColumnPriv);
hmsTable = (HMSExternalTable) desc.getTable();
brokerName = hmsTable.getCatalog().bindBrokerName();
}

public HiveScanNode(PlanNodeId id, TupleDescriptor desc, String planNodeName,
StatisticalType statisticalType, boolean needCheckColumnPriv) {
super(id, desc, planNodeName, statisticalType, needCheckColumnPriv);
hmsTable = (HMSExternalTable) desc.getTable();
brokerName = hmsTable.getCatalog().bindBrokerName();
}

@Override
Expand Down