/** * Executes the task asynchronously, returning a Rows object that can be * used to fetch results. */ public Records execAndFetch(Task task) throws RecordServiceException, IOException { validateIsConnected(); TaskState result = execTaskInternal(task, 0); Records records = null; try { records = new Records(this, result); return records; } finally { if (records == null) closeTask(result); } }
private void nextBatch() throws IOException, RecordServiceException { if (handle_ == null) { throw new RuntimeException("Task has been closed already."); } fetchResult_ = worker_.fetch(handle_); if (fetchResult_.recordFormat != FetchResult.RecordFormat.Columnar) { throw new RuntimeException("Unsupported record format"); } record_.reset(fetchResult_); progress_ = (float)fetchResult_.taskProgress; }
/** * Executes the task asynchronously, returning the handle to the client. */ public TaskState execTask(Task task) throws RecordServiceException, IOException { validateIsConnected(); return execTaskInternal(task, 0); }
/** * Gets status on the current task executing. */ public TaskStatus getTaskStatus(TaskState handle) throws RecordServiceException, IOException { validateIsConnected(); validateHandleIsActive(handle); LOG.debug("Calling getTaskStatus(): " + handle.handle_); TException firstException = null; boolean connected = true; for (int i = 0; i < maxAttempts_; ++i) { try { if (!connected) { connected = waitAndReconnect(); if (!connected) continue; } return new TaskStatus(workerClient_.GetTaskStatus(handle.handle_)); } catch (TException e) { if (firstException == null) firstException = e; connected = false; } } handleThriftException(firstException, "Could not call getTaskStatus."); throw new RuntimeException("Could not get task status."); }
close(); if (i + 1 < maxAttempts_ && e.getCode() == TErrorCode.SERVICE_BUSY) { sleepForRetry(); continue; hostname + ":" + port + " is rejected. ", e); } catch (TTransportException e) { close(); if (e.getType() == TTransportException.END_OF_FILE) { TRecordServiceException ex = new TRecordServiceException(); throw new IOException(errorMsg, e); } catch (TException e) { close(); String errorMsg = "Could not get service protocol version. It's likely " + "the service at " + hostname + ":" + port + " is not running the " +
try { if (!connected) { connected = waitAndReconnect(); if (!connected) continue; switch (e.code) { case SERVICE_BUSY: sleepForRetry(); continue; default: handleThriftException(firstException, "Could not exec task."); throw new RuntimeException("Could not exec task.");
/** * Utility function to launch task 'taskId' in plan at the first host. * Local hosts are preferred over remote hosts. * * TODO: move this into a test/sample directory? Real frameworks have * to deal with much more stuff. */ public static Records execTask(PlanRequestResult plan, int taskId) throws RecordServiceException, IOException { if (taskId >= plan.tasks.size() || taskId < 0) { throw new RuntimeException("Invalid task id."); } Task task = plan.tasks.get(taskId); NetworkAddress host; if (task.localHosts.isEmpty()) { if (plan.hosts.isEmpty()) { throw new RuntimeException("No hosts are provided to run this task."); } host = plan.hosts.get(0); } else { host = task.localHosts.get(0); } Records records = new RecordServiceWorkerClient.Builder() .connect(host.hostname, host.port).execAndFetch(task); records.setCloseWorker(true); return records; } }
/** * Closes the task and worker connection. */ @Override public void close() { if (records_ != null) records_.close(); if (worker_ != null) worker_.close(); }
/** * Returns the protocol version of the connected service. */ public ProtocolVersion getProtocolVersion() throws RuntimeException { validateIsConnected(); return protocolVersion_; }
/** * Returns the status of the underlying task. This issues an RPC to the server * and cannot be used in the hot path. */ public TaskStatus getStatus() throws IOException, RecordServiceException { if (handle_ == null) throw new RuntimeException("Task already closed."); return worker_.getTaskStatus(handle_); }
/** * Sleeps for retrySleepMs_ and reconnects to the worker. Returns * true if the connection was established. * TODO: why does this behave so differently than the Planner implementation. */ private boolean waitAndReconnect() { sleepForRetry(); try { protocol_.getTransport().open(); TSocket socket = ThriftUtils.getSocketTransport(protocol_.getTransport()); socket.setTimeout(connectionTimeoutMs_); workerClient_ = new RecordServiceWorker.Client(protocol_); socket.setTimeout(rpcTimeoutMs_); return true; } catch (TTransportException e) { return false; } }
validateIsConnected(); validateHandleIsActive(state); TException firstException = null; try { if (!connected) { connected = waitAndReconnect(); if (!connected) continue; TaskState newState = execTaskInternal(state.task_, state.recordsFetched_); state.handle_ = newState.handle_; continue; handleThriftException(firstException, "Retry attempts exhausted. Could not call fetch."); throw new RuntimeException(firstException);
/** * Creates a RecordReaderCore to read the records for taskInfo. */ @SuppressWarnings("unchecked") public RecordReaderCore(Configuration config, Credentials credentials, TaskInfo taskInfo) throws RecordServiceException, IOException { Token<DelegationTokenIdentifier> token = (Token<DelegationTokenIdentifier>) credentials.getToken(DelegationTokenIdentifier.DELEGATION_KIND); RecordServiceWorkerClient.Builder builder = WorkerUtil.getBuilder(config, TokenUtils.toDelegationToken(token)); NetworkAddress address = WorkerUtil.getWorkerToConnectTo( taskInfo.getTask().taskId, taskInfo.getLocations(), taskInfo.getAllWorkerAddresses()); setTag(taskInfo.getTask(), config); try { worker_ = builder.connect(address.hostname, address.port); records_ = worker_.execAndFetch(taskInfo.getTask()); } finally { if (records_ == null) close(); } schema_ = new Schema(records_.getSchema()); }
/** * Closes the underlying transport, used to simulate an error with the service * connection. */ public void closeTask(TaskState handle) { validateIsConnected(); if (activeTasks_.containsKey(handle.handle_)) { LOG.info("Closing RecordServiceWorker task: " + handle.handle_); try { workerClient_.CloseTask(handle.handle_); } catch (TException e) { LOG.warn( "Failed to close task handle=" + handle.handle_ + " reason=" + e.getMessage()); } activeTasks_.remove(handle.handle_); } }