Search in sources :

Example 11 with RuntimeDataException

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);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 12 with RuntimeDataException

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());
    }
}
Also used : RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 13 with RuntimeDataException

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;
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HashSet(java.util.HashSet)

Example 14 with RuntimeDataException

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;
}
Also used : MutationMessage(com.couchbase.client.core.message.dcp.MutationMessage) RemoveMessage(com.couchbase.client.core.message.dcp.RemoveMessage) DCPRequest(com.couchbase.client.core.message.dcp.DCPRequest) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 15 with RuntimeDataException

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);
    }
}
Also used : DataInput(java.io.DataInput) ARecord(org.apache.asterix.om.base.ARecord) ByteArrayInputStream(java.io.ByteArrayInputStream) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) DataInputStream(java.io.DataInputStream) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)33 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 IOException (java.io.IOException)12 DataOutput (java.io.DataOutput)7 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)7 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)7 IPointable (org.apache.hyracks.data.std.api.IPointable)7 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)7 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)7 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)7 ATypeTag (org.apache.asterix.om.types.ATypeTag)6 IAType (org.apache.asterix.om.types.IAType)6 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)6 AsterixException (org.apache.asterix.common.exceptions.AsterixException)5 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)4 AUnionType (org.apache.asterix.om.types.AUnionType)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 RecordBuilder (org.apache.asterix.builders.RecordBuilder)2 IInputStreamFactory (org.apache.asterix.external.api.IInputStreamFactory)2