use of org.apache.hadoop.hive.llap.registry.LlapServiceInstance in project hive by apache.
the class LlapBaseInputFormat method getServiceInstanceRandom.
private LlapServiceInstance getServiceInstanceRandom(LlapRegistryService registryService) throws IOException {
ServiceInstanceSet<LlapServiceInstance> instanceSet = registryService.getInstances();
LlapServiceInstance serviceInstance = null;
LOG.info("Finding random live service instance");
Collection<LlapServiceInstance> allInstances = instanceSet.getAll();
if (allInstances.size() > 0) {
int randIdx = rand.nextInt(allInstances.size());
;
serviceInstance = allInstances.toArray(serviceInstanceArray)[randIdx];
}
return serviceInstance;
}
use of org.apache.hadoop.hive.llap.registry.LlapServiceInstance in project hive by apache.
the class LlapBaseInputFormat method getServiceInstance.
private LlapServiceInstance getServiceInstance(JobConf job, LlapInputSplit llapSplit) throws IOException {
LlapRegistryService registryService = LlapRegistryService.getClient(job);
String host = llapSplit.getLocations()[0];
LlapServiceInstance serviceInstance = getServiceInstanceForHost(registryService, host);
if (serviceInstance == null) {
LOG.info("No service instances found for " + host + " in registry.");
serviceInstance = getServiceInstanceRandom(registryService);
if (serviceInstance == null) {
throw new IOException("No service instances found in registry");
}
}
return serviceInstance;
}
use of org.apache.hadoop.hive.llap.registry.LlapServiceInstance in project hive by apache.
the class LlapBaseInputFormat method getServiceInstanceForHost.
private LlapServiceInstance getServiceInstanceForHost(LlapRegistryService registryService, String host) throws IOException {
InetAddress address = InetAddress.getByName(host);
ServiceInstanceSet<LlapServiceInstance> instanceSet = registryService.getInstances();
LlapServiceInstance serviceInstance = null;
// The name used in the service registry may not match the host name we're using.
// Try hostname/canonical hostname/host address
String name = address.getHostName();
LOG.info("Searching service instance by hostname " + name);
serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
if (serviceInstance != null) {
return serviceInstance;
}
name = address.getCanonicalHostName();
LOG.info("Searching service instance by canonical hostname " + name);
serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
if (serviceInstance != null) {
return serviceInstance;
}
name = address.getHostAddress();
LOG.info("Searching service instance by address " + name);
serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
if (serviceInstance != null) {
return serviceInstance;
}
return serviceInstance;
}
use of org.apache.hadoop.hive.llap.registry.LlapServiceInstance in project hive by apache.
the class LlapTaskSchedulerService method selectHost.
/**
* @param request the list of preferred hosts. null implies any host
* @return
*/
private SelectHostResult selectHost(TaskInfo request) {
String[] requestedHosts = request.requestedHosts;
String requestedHostsDebugStr = Arrays.toString(requestedHosts);
if (LOG.isDebugEnabled()) {
LOG.debug("selectingHost for task={} on hosts={}", request.task, requestedHostsDebugStr);
}
long schedulerAttemptTime = clock.getTime();
// Read-lock. Not updating any stats at the moment.
readLock.lock();
try {
boolean shouldDelayForLocality = request.shouldDelayForLocality(schedulerAttemptTime);
LOG.debug("ShouldDelayForLocality={} for task={} on hosts={}", shouldDelayForLocality, request.task, requestedHostsDebugStr);
if (requestedHosts != null && requestedHosts.length > 0) {
int prefHostCount = -1;
boolean requestedHostsWillBecomeAvailable = false;
for (String host : requestedHosts) {
prefHostCount++;
// Pick the first host always. Weak attempt at cache affinity.
Set<LlapServiceInstance> instances = activeInstances.getByHost(host);
if (!instances.isEmpty()) {
for (LlapServiceInstance inst : instances) {
NodeInfo nodeInfo = instanceToNodeMap.get(inst.getWorkerIdentity());
if (nodeInfo != null) {
if (nodeInfo.canAcceptTask()) {
// Successfully scheduled.
LOG.info("Assigning {} when looking for {}." + " local=true FirstRequestedHost={}, #prefLocations={}", nodeInfo.toShortString(), host, (prefHostCount == 0), requestedHosts.length);
return new SelectHostResult(nodeInfo);
} else {
// The node cannot accept a task at the moment.
if (shouldDelayForLocality) {
// Perform some checks on whether the node will become available or not.
if (request.shouldForceLocality()) {
requestedHostsWillBecomeAvailable = true;
} else {
if (nodeInfo.getEnableTime() > request.getLocalityDelayTimeout() && nodeInfo.isDisabled() && nodeInfo.hadCommFailure()) {
LOG.debug("Host={} will not become available within requested timeout", nodeInfo);
// This node will likely be activated after the task timeout expires.
} else {
// Worth waiting for the timeout.
requestedHostsWillBecomeAvailable = true;
}
}
}
}
} else {
LOG.warn("Null NodeInfo when attempting to get host with worker {}, and host {}", inst, host);
// Leave requestedHostWillBecomeAvailable as is. If some other host is found - delay,
// else ends up allocating to a random host immediately.
}
}
}
}
// Check if forcing the location is required.
if (shouldDelayForLocality) {
if (requestedHostsWillBecomeAvailable) {
if (LOG.isDebugEnabled()) {
LOG.debug("Delaying local allocation for [" + request.task + "] when trying to allocate on [" + requestedHostsDebugStr + "]" + ". ScheduleAttemptTime=" + schedulerAttemptTime + ", taskDelayTimeout=" + request.getLocalityDelayTimeout());
}
return SELECT_HOST_RESULT_DELAYED_LOCALITY;
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping local allocation for [" + request.task + "] when trying to allocate on [" + requestedHostsDebugStr + "] since none of these hosts are part of the known list");
}
}
}
}
/* fall through - miss in locality or no locality-requested */
Collection<LlapServiceInstance> instances = activeInstances.getAllInstancesOrdered(true);
List<NodeInfo> allNodes = new ArrayList<>(instances.size());
List<NodeInfo> activeNodesWithFreeSlots = new ArrayList<>();
for (LlapServiceInstance inst : instances) {
if (inst instanceof InactiveServiceInstance) {
allNodes.add(null);
} else {
NodeInfo nodeInfo = instanceToNodeMap.get(inst.getWorkerIdentity());
if (nodeInfo == null) {
allNodes.add(null);
} else {
allNodes.add(nodeInfo);
if (nodeInfo.canAcceptTask()) {
activeNodesWithFreeSlots.add(nodeInfo);
}
}
}
}
if (allNodes.isEmpty()) {
return SELECT_HOST_RESULT_DELAYED_RESOURCES;
}
// no locality-requested, randomly pick a node containing free slots
if (requestedHosts == null || requestedHosts.length == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("No-locality requested. Selecting a random host for task={}", request.task);
}
return randomSelection(activeNodesWithFreeSlots);
}
// miss in locality request, try picking consistent location with fallback to random selection
final String firstRequestedHost = requestedHosts[0];
int requestedHostIdx = -1;
for (int i = 0; i < allNodes.size(); i++) {
NodeInfo nodeInfo = allNodes.get(i);
if (nodeInfo != null) {
if (nodeInfo.getHost().equals(firstRequestedHost)) {
requestedHostIdx = i;
break;
}
}
}
// TODO: At this point we don't know the slot number of the requested host, so can't rollover to next available
if (requestedHostIdx == -1) {
if (LOG.isDebugEnabled()) {
LOG.debug("Requested node [{}] in consistent order does not exist. Falling back to random selection for " + "request {}", firstRequestedHost, request);
}
return randomSelection(activeNodesWithFreeSlots);
}
// requested host is still alive but cannot accept task, pick the next available host in consistent order
for (int i = 0; i < allNodes.size(); i++) {
NodeInfo nodeInfo = allNodes.get((i + requestedHostIdx + 1) % allNodes.size());
// next node in consistent order died or does not have free slots, rollover to next
if (nodeInfo == null || !nodeInfo.canAcceptTask()) {
continue;
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Assigning {} in consistent order when looking for first requested host, from #hosts={}," + " requestedHosts={}", nodeInfo.toShortString(), allNodes.size(), ((requestedHosts == null || requestedHosts.length == 0) ? "null" : requestedHostsDebugStr));
}
return new SelectHostResult(nodeInfo);
}
}
return SELECT_HOST_RESULT_DELAYED_RESOURCES;
} finally {
readLock.unlock();
}
}
use of org.apache.hadoop.hive.llap.registry.LlapServiceInstance in project hive by apache.
the class ProactiveEviction method evict.
/**
* Trigger LLAP cache eviction of buffers related to entities residing in request parameter.
* @param conf
* @param request
*/
public static void evict(Configuration conf, Request request) {
if (!HiveConf.getBoolVar(conf, HiveConf.ConfVars.LLAP_IO_PROACTIVE_EVICTION_ENABLED)) {
return;
}
try {
LlapRegistryService llapRegistryService = LlapRegistryService.getClient(conf);
Collection<LlapServiceInstance> instances = llapRegistryService.getInstances().getAll();
if (instances.size() == 0) {
// Not in LLAP mode.
return;
}
LOG.info("Requesting proactive LLAP cache eviction.");
LOG.debug("Request: {}", request);
// Fire and forget - requests are enqueued on the single threaded executor and this (caller) thread won't wait.
for (LlapServiceInstance instance : instances) {
EvictionRequestTask task = new EvictionRequestTask(conf, instance, request);
EXECUTOR.execute(task);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations