Search in sources :

Example 56 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class ProcedureExecutionParentImpl method execute.

@Override
public void execute() throws TranslatorException {
    String name = getCommand().getMetadataObject().getSourceName();
    if (name == null) {
        name = getCommand().getProcedureName();
    }
    if (GET_UPDATED.equalsIgnoreCase(name)) {
        execution = new GetUpdatedExecutionImpl(this);
    } else if (GET_DELETED.equalsIgnoreCase(name)) {
        execution = new GetDeletedExecutionImpl(this);
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TeiidRuntimeException("Unknown procedure " + getCommand().getProcedureName() + " with name in source " + name);
    }
    execution.execute(this);
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 57 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class SolrExecutionFactory method convertFromSolrType.

public Object convertFromSolrType(final Object value, final Class<?> expectedType) {
    if (value == null) {
        return null;
    }
    if (expectedType.isInstance(value)) {
        return value;
    }
    try {
        if (expectedType.isArray()) {
            ArrayList multiValues = (ArrayList) value;
            Object transformed = Array.newInstance(expectedType.getComponentType(), multiValues.size());
            for (int i = 0; i < multiValues.size(); i++) {
                Object obj = multiValues.get(i);
                if (obj == null) {
                    Array.set(transformed, i, obj);
                    continue;
                }
                if (expectedType.getComponentType().isInstance(obj)) {
                    Array.set(transformed, i, obj);
                    continue;
                }
                if (DataTypeManager.isTransformable(obj.getClass(), expectedType.getComponentType())) {
                    Array.set(transformed, i, DataTypeManager.transformValue(obj, expectedType.getComponentType()));
                } else {
                    throw new TeiidRuntimeException(SolrPlugin.Event.TEIID20001, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20001, value, expectedType.getName()));
                }
            }
            return transformed;
        }
        if (DataTypeManager.isTransformable(value.getClass(), expectedType)) {
            return DataTypeManager.transformValue(value, expectedType);
        }
        throw new TeiidRuntimeException(SolrPlugin.Event.TEIID20001, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20001, value, expectedType.getName()));
    } catch (TransformationException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : TransformationException(org.teiid.core.types.TransformationException) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 58 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class DataTierTupleSource method asynchGet.

private AtomicResultsMessage asynchGet() throws BlockedException, TeiidProcessingException, TeiidComponentException, TranslatorException {
    if (futureResult == null) {
        addWork();
    }
    if (!futureResult.isDone()) {
        // $NON-NLS-1$
        throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking on source query", aqr.getAtomicRequestID());
    }
    FutureWork<AtomicResultsMessage> currentResults = futureResult;
    futureResult = null;
    AtomicResultsMessage results = null;
    try {
        results = currentResults.get();
        if (results.getFinalRow() < 0) {
            addWork();
        }
    } catch (CancellationException e) {
        throw new TeiidProcessingException(e);
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30503, e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof TeiidProcessingException) {
            throw (TeiidProcessingException) e.getCause();
        }
        if (e.getCause() instanceof TeiidComponentException) {
            throw (TeiidComponentException) e.getCause();
        }
        if (e.getCause() instanceof TranslatorException) {
            throw (TranslatorException) e.getCause();
        }
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        // shouldn't happen
        throw new RuntimeException(e);
    }
    return results;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CancellationException(java.util.concurrent.CancellationException) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 59 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class BufferFrontedFileStoreCache method evictFromMemoryBuffer.

/**
 * Eviction routine.  When space is exhausted data blocks are acquired from
 * memory entries.
 * @param acquire
 * @return
 */
int evictFromMemoryBuffer(boolean acquire) {
    boolean writeLocked = false;
    int next = EMPTY_ADDRESS;
    try {
        for (int i = 0; i < EVICTION_SCANS && next == EMPTY_ADDRESS; i++) {
            // doing a cleanup may trigger the purging of resources
            AutoCleanupUtil.doCleanup(true);
            // scan the eviction queue looking for a victim
            Iterator<PhysicalInfo> iter = memoryBufferEntries.getEvictionQueue().iterator();
            while (((!acquire && lowBlocks(false)) || (acquire && (next = blocksInuse.getAndSetNextClearBit()) == EMPTY_ADDRESS)) && iter.hasNext()) {
                PhysicalInfo info = iter.next();
                synchronized (info) {
                    if (info.inode == EMPTY_ADDRESS) {
                        continue;
                    }
                    if (info.pinned || info.evicting) {
                        if (!acquire || i != EVICTION_SCANS - 1) {
                            continue;
                        }
                        if (acquire && !writeLocked) {
                            // stop the world - prevent any other thread from taking a free block
                            // until this one is satisfied
                            memoryEvictionLock.writeLock().lock();
                            writeLocked = true;
                        }
                        // wait for the read/eviction to be over
                        info.await(true, true);
                        if (info.inode == EMPTY_ADDRESS) {
                            continue;
                        }
                    }
                    // mark as evicting early so that other evictFromMemoryCalls don't select this same entry
                    info.evicting = true;
                }
                next = free(info, true, acquire);
                break;
            }
        }
        if (acquire && next == EMPTY_ADDRESS) {
            if (!writeLocked) {
                memoryEvictionLock.writeLock().lock();
                writeLocked = true;
            }
            freedLock.lock();
            try {
                long waitTime = TIMEOUT_NANOS;
                while (true) {
                    next = blocksInuse.getAndSetNextClearBit();
                    if (next != EMPTY_ADDRESS) {
                        return next;
                    }
                    waitTime = blocksFreed.awaitNanos(waitTime);
                    if (waitTime <= 0) {
                        break;
                    }
                }
            } finally {
                freedLock.unlock();
            }
            next = blocksInuse.getAndSetNextClearBit();
            if (next == EMPTY_ADDRESS) {
                // $NON-NLS-1$
                throw new AssertionError("Could not free space for pending write");
            }
        }
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30050, e);
    } finally {
        if (writeLocked) {
            memoryEvictionLock.writeLock().unlock();
        }
    }
    return next;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 60 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class BufferFrontedFileStoreCache method get.

@Override
public CacheEntry get(PhysicalInfo info, Long oid, WeakReference<? extends Serializer<?>> ref) throws TeiidComponentException {
    if (info == null) {
        return null;
    }
    Serializer<?> serializer = ref.get();
    if (serializer == null) {
        return null;
    }
    readAttempts.incrementAndGet();
    InputStream is = null;
    Lock lock = null;
    ExtensibleBufferedInputStream eis = null;
    int memoryBlocks = 0;
    try {
        synchronized (info) {
            // load should be locked
            assert !info.pinned && info.loading;
            // not necessary, but should make things safer
            info.await(true, false);
            if (info.inode != EMPTY_ADDRESS) {
                info.pinned = true;
                memoryBufferEntries.touch(info);
                if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
                    // $NON-NLS-1$
                    LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at inode", info.inode, serializer.getId(), oid);
                }
                BlockManager manager = getBlockManager(serializer.getId(), oid, info.inode);
                is = new BlockInputStream(manager, info.memoryBlockCount);
            } else if (info.block != EMPTY_ADDRESS) {
                info.pinned = true;
                memoryBufferEntries.recordAccess(info);
                storageReads.incrementAndGet();
                if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
                    // $NON-NLS-1$
                    LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at block", info.block, info.sizeIndex, serializer.getId(), oid);
                }
                BlockStore blockStore = sizeBasedStores[info.sizeIndex];
                int segment = info.block / blockStore.blocksInUse.getBitsPerSegment();
                FileStore fs = blockStore.stores[segment];
                long blockOffset = (info.block % blockStore.blocksInUse.getBitsPerSegment()) * blockStore.blockSize;
                eis = fs.createInputStream(blockOffset, info.memoryBlockCount << LOG_BLOCK_SIZE);
                lock = blockStore.locks[segment].writeLock();
                memoryBlocks = info.memoryBlockCount;
            } else {
                return null;
            }
        }
        if (lock != null) {
            is = readIntoMemory(info, eis, lock, memoryBlocks);
        }
        for (int i = 0; i < HEADER_BYTES; i++) {
            is.read();
        }
        ObjectInput dis = new ObjectInputStream(is);
        CacheEntry ce = new CacheEntry(new CacheKey(oid, 1, 1), info.sizeEstimate, serializer.deserialize(dis), ref, true);
        return ce;
    } catch (IOException e) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
    } catch (ClassNotFoundException e) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30049, e);
    } finally {
        synchronized (info) {
            info.pinned = false;
            info.notifyAll();
        }
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) ExtensibleBufferedInputStream(org.teiid.common.buffer.ExtensibleBufferedInputStream) InputStream(java.io.InputStream) ExtensibleBufferedInputStream(org.teiid.common.buffer.ExtensibleBufferedInputStream) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CacheEntry(org.teiid.common.buffer.CacheEntry) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) FileStore(org.teiid.common.buffer.FileStore) TeiidComponentException(org.teiid.core.TeiidComponentException) ObjectInput(java.io.ObjectInput) CacheKey(org.teiid.common.buffer.CacheKey) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4