use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.
the class StringRepeatDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
// Argument evaluators.
private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
// Argument pointers.
private IPointable argString = new VoidPointable();
private IPointable argNumber = new VoidPointable();
// For outputting the result.
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private byte[] tempLengthArray = new byte[5];
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
// Calls argument evaluators.
evalString.evaluate(tuple, argString);
evalStart.evaluate(tuple, argNumber);
// Gets the repeating times.
byte[] bytes = argNumber.getByteArray();
int offset = argNumber.getStartOffset();
int repeatingTimes = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset);
// Checks repeatingTimes. It should be a non-negative value.
if (repeatingTimes < 0) {
throw new RuntimeDataException(ErrorCode.NEGATIVE_VALUE, getIdentifier(), 1, repeatingTimes);
}
// Gets the input string.
bytes = argString.getByteArray();
offset = argString.getStartOffset();
// Checks the type of the string argument.
if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Calculates the result string length.
int inputLen = UTF8StringUtil.getUTFLength(bytes, offset + 1);
// Can throw overflow exception.
int resultLen = Math.multiplyExact(inputLen, repeatingTimes);
int cbytes = UTF8StringUtil.encodeUTF8Length(resultLen, tempLengthArray, 0);
// Writes the output string.
int inputStringStart = offset + 1 + UTF8StringUtil.getNumBytesToStoreLength(inputLen);
try {
out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
out.write(tempLengthArray, 0, cbytes);
for (int numRepeats = 0; numRepeats < repeatingTimes; ++numRepeats) {
out.write(bytes, inputStringStart, inputLen);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.
the class ReplicationStrategyFactory method create.
public static IReplicationStrategy create(Cluster cluster) throws HyracksDataException {
boolean highAvailabilityEnabled = cluster.getHighAvailability() != null && cluster.getHighAvailability().getEnabled() != null && Boolean.valueOf(cluster.getHighAvailability().getEnabled());
if (!highAvailabilityEnabled || cluster.getHighAvailability().getDataReplication() == null || cluster.getHighAvailability().getDataReplication().getStrategy() == null) {
return new NoReplicationStrategy();
}
String strategyName = cluster.getHighAvailability().getDataReplication().getStrategy().toLowerCase();
if (!BUILT_IN_REPLICATION_STRATEGY.containsKey(strategyName)) {
throw new RuntimeDataException(ErrorCode.UNSUPPORTED_REPLICATION_STRATEGY, String.format("%s. Available strategies: %s", strategyName, BUILT_IN_REPLICATION_STRATEGY.keySet().toString()));
}
Class<? extends IReplicationStrategy> clazz = BUILT_IN_REPLICATION_STRATEGY.get(strategyName);
try {
return clazz.newInstance().from(cluster);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeDataException(ErrorCode.INSTANTIATION_ERROR, e, clazz.getName());
}
}
use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.
the class MetadataOnlyReplicationStrategy method from.
@Override
public MetadataOnlyReplicationStrategy from(Cluster cluster) throws HyracksDataException {
if (cluster.getMetadataNode() == null) {
throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "Metadata node must be specified.");
}
Node metadataNode = ClusterProperties.INSTANCE.getNodeById(cluster.getMetadataNode());
if (metadataNode == null) {
throw new IllegalStateException("Invalid metadata node specified");
}
if (cluster.getHighAvailability().getFaultTolerance().getReplica() == null || cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId() == null || cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId().isEmpty()) {
throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "One or more replicas must be specified for metadata node.");
}
final Set<Replica> replicas = new HashSet<>();
for (String nodeId : cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId()) {
Node node = ClusterProperties.INSTANCE.getNodeById(nodeId);
if (node == null) {
throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "Invalid replica specified: " + nodeId);
}
replicas.add(new Replica(node));
}
MetadataOnlyReplicationStrategy st = new MetadataOnlyReplicationStrategy();
st.metadataNodeId = cluster.getMetadataNode();
st.metadataPrimaryReplica = new Replica(metadataNode);
st.metadataNodeReplicas = replicas;
return st;
}
use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.
the class DCPMessageToRecordConverter method convert.
@Override
public RecordWithMetadataAndPK<char[]> convert(final IRawRecord<? extends DCPRequest> input) throws IOException {
final DCPRequest dcpRequest = input.get();
if (dcpRequest instanceof MutationMessage) {
final MutationMessage message = (MutationMessage) dcpRequest;
try {
final String key = message.key();
final int vbucket = message.partition();
final long seq = message.bySequenceNumber();
final long cas = message.cas();
final int expiration = message.expiration();
final int flags = message.flags();
final long revSeqNumber = message.revisionSequenceNumber();
final int lockTime = message.lockTime();
int i = 0;
recordWithMetadata.reset();
recordWithMetadata.setMetadata(i++, key);
recordWithMetadata.setMetadata(i++, vbucket);
recordWithMetadata.setMetadata(i++, seq);
recordWithMetadata.setMetadata(i++, cas);
recordWithMetadata.setMetadata(i++, expiration);
recordWithMetadata.setMetadata(i++, flags);
recordWithMetadata.setMetadata(i++, revSeqNumber);
recordWithMetadata.setMetadata(i, lockTime);
DCPMessageToRecordConverter.set(message.content(), decoder, bytes, chars, value);
} finally {
ReferenceCountUtil.release(message.content());
}
} else if (dcpRequest instanceof RemoveMessage) {
final RemoveMessage message = (RemoveMessage) dcpRequest;
final String key = message.key();
recordWithMetadata.reset();
recordWithMetadata.setMetadata(0, key);
} else {
throw new RuntimeDataException(ErrorCode.INPUT_RECORD_CONVERTER_DCP_MSG_TO_RECORD_CONVERTER_UNKNOWN_DCP_REQUEST, dcpRequest.toString());
}
return recordWithMetadata;
}
use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.
the class ExternalFileIndexAccessor method lookup.
public void lookup(int fileId, ExternalFile file) throws HyracksDataException {
// Set search parameters
currentFileNumber.setValue(fileId);
searchKeyTupleBuilder.reset();
searchKeyTupleBuilder.addField(intSerde, currentFileNumber);
searchKey.reset(searchKeyTupleBuilder.getFieldEndOffsets(), searchKeyTupleBuilder.getByteArray());
fileIndexSearchCursor.reset();
// Perform search
fileIndexAccessor.search(fileIndexSearchCursor, searchPredicate);
if (fileIndexSearchCursor.hasNext()) {
fileIndexSearchCursor.next();
ITupleReference tuple = fileIndexSearchCursor.getTuple();
// Deserialize
byte[] serRecord = tuple.getFieldData(FilesIndexDescription.FILE_PAYLOAD_INDEX);
int recordStartOffset = tuple.getFieldStart(FilesIndexDescription.FILE_PAYLOAD_INDEX);
int recordLength = tuple.getFieldLength(FilesIndexDescription.FILE_PAYLOAD_INDEX);
ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
DataInput in = new DataInputStream(stream);
ARecord externalFileRecord = (ARecord) externalFileRecordSerde.deserialize(in);
setFile(externalFileRecord, file);
} else {
// This should never happen
throw new RuntimeDataException(ErrorCode.INDEXING_EXTERNAL_FILE_INDEX_ACCESSOR_UNABLE_TO_FIND_FILE_INDEX);
}
}
Aggregations