use of org.apache.hyracks.api.dataset.DatasetDirectoryRecord in project asterixdb by apache.
the class HyracksDatasetReader method nextPartition.
private boolean nextPartition() throws HyracksDataException {
++lastReadPartition;
try {
DatasetDirectoryRecord record = getRecord(lastReadPartition);
while (record.getEmpty() && (++lastReadPartition) < knownRecords.length) {
record = getRecord(lastReadPartition);
}
if (lastReadPartition == knownRecords.length) {
return false;
}
resultChannel = new DatasetNetworkInputChannel(netManager, getSocketAddress(record), jobId, resultSetId, lastReadPartition, NUM_READ_BUFFERS);
lastMonitor = getMonitor(lastReadPartition);
resultChannel.registerMonitor(lastMonitor);
resultChannel.open(datasetClientCtx);
return true;
} catch (Exception e) {
throw HyracksDataException.create(e);
}
}
use of org.apache.hyracks.api.dataset.DatasetDirectoryRecord in project asterixdb by apache.
the class Waiter method registerResultPartitionLocation.
@Override
public synchronized void registerResultPartitionLocation(JobId jobId, ResultSetId rsId, boolean orderedResult, boolean emptyResult, int partition, int nPartitions, NetworkAddress networkAddress) throws HyracksDataException {
DatasetJobRecord djr = getNonNullDatasetJobRecord(jobId);
djr.setResultSetMetaData(rsId, orderedResult, nPartitions);
DatasetDirectoryRecord record = djr.getOrCreateDirectoryRecord(rsId, partition);
record.setNetworkAddress(networkAddress);
record.setEmpty(emptyResult);
record.start();
final JobResultInfo jobResultInfo = jobResultLocations.get(jobId);
Waiter waiter = jobResultInfo.getWaiter(rsId);
if (waiter != null) {
try {
DatasetDirectoryRecord[] updatedRecords = updatedRecords(jobId, rsId, waiter.knownRecords);
if (updatedRecords != null) {
jobResultInfo.removeWaiter(rsId);
waiter.callback.setValue(updatedRecords);
}
} catch (Exception e) {
waiter.callback.setException(e);
}
}
notifyAll();
}
use of org.apache.hyracks.api.dataset.DatasetDirectoryRecord in project asterixdb by apache.
the class Waiter method updatedRecords.
/**
* Compares the records already known by the client for the given job's result set id with the records that the
* dataset directory service knows and if there are any newly discovered records returns a whole array with the
* new records filled in.
*
* @param jobId
* - Id of the job for which the directory records should be retrieved.
* @param rsId
* - Id of the result set for which the directory records should be retrieved.
* @param knownRecords
* - An array of directory records that the client is already aware of.
* @return
* Returns the updated records if new record were discovered, null otherwise
* @throws HyracksDataException
* TODO(madhusudancs): Think about caching (and still be stateless) instead of this ugly O(n) iterations for
* every check. This already looks very expensive.
*/
private DatasetDirectoryRecord[] updatedRecords(JobId jobId, ResultSetId rsId, DatasetDirectoryRecord[] knownRecords) throws HyracksDataException {
DatasetJobRecord djr = getNonNullDatasetJobRecord(jobId);
if (djr.getStatus().getState() == State.FAILED) {
List<Exception> caughtExceptions = djr.getStatus().getExceptions();
if (caughtExceptions != null && !caughtExceptions.isEmpty()) {
final Exception cause = caughtExceptions.get(caughtExceptions.size() - 1);
if (cause instanceof HyracksDataException) {
throw (HyracksDataException) cause;
}
throw HyracksDataException.create(ErrorCode.RESULT_FAILURE_EXCEPTION, cause, rsId, jobId);
} else {
throw HyracksDataException.create(ErrorCode.RESULT_FAILURE_NO_EXCEPTION, rsId, jobId);
}
}
final ResultSetMetaData resultSetMetaData = djr.getResultSetMetaData(rsId);
if (resultSetMetaData == null) {
return null;
}
DatasetDirectoryRecord[] records = resultSetMetaData.getRecords();
return Arrays.equals(records, knownRecords) ? null : records;
}
Aggregations