Search in sources :

Example 6 with ConnectionUnavailableException

use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.

the class AbstractQueryableRecordTable method handleCacheExpiry.

public void handleCacheExpiry(CompiledCondition cacheExpiryCompiledCondition, ComplexEventChunk<StateEvent> deleteEventChunk) {
    if (log.isDebugEnabled()) {
        log.debug(siddhiAppContext.getName() + ": CacheExpirer started");
    }
    StateEvent stateEventForCaching = new StateEvent(1, 0);
    StreamEvent loadedDataFromStore;
    readWriteLock.writeLock().lock();
    try {
        if (storeTableSize != -1 && storeSizeLastCheckedTime > siddhiAppContext.getTimestampGenerator().currentTime() - retentionPeriod * 10) {
            if (log.isDebugEnabled()) {
                log.debug(siddhiAppContext.getName() + ": checking size of store table");
            }
            try {
                if (storeTableSize <= maxCacheSize) {
                    AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.TRUE);
                    try {
                        if (cacheLastReloadTime < siddhiAppContext.getTimestampGenerator().currentTime() + retentionPeriod) {
                            loadedDataFromStore = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
                            clearCacheAndReload(loadedDataFromStore);
                            cacheLastReloadTime = siddhiAppContext.getTimestampGenerator().currentTime();
                        }
                    } finally {
                        AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.FALSE);
                    }
                } else {
                    cacheTable.delete(deleteEventChunk, cacheExpiryCompiledCondition);
                }
            } catch (ConnectionUnavailableException e) {
                throw new SiddhiAppRuntimeException(siddhiAppContext.getName() + ": " + e.getMessage());
            }
        } else {
            try {
                AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.TRUE);
                try {
                    loadedDataFromStore = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
                    storeTableSize = findEventChunkSize(loadedDataFromStore);
                    storeSizeLastCheckedTime = siddhiAppContext.getTimestampGenerator().currentTime();
                } finally {
                    AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.FALSE);
                }
                if (storeTableSize <= maxCacheSize) {
                    if (cacheLastReloadTime < siddhiAppContext.getTimestampGenerator().currentTime() + retentionPeriod) {
                        clearCacheAndReload(loadedDataFromStore);
                        cacheLastReloadTime = siddhiAppContext.getTimestampGenerator().currentTime();
                    }
                } else {
                    cacheTable.delete(deleteEventChunk, cacheExpiryCompiledCondition);
                }
            } catch (Exception e) {
                throw new SiddhiAppRuntimeException(siddhiAppContext.getName() + ": " + e.getMessage());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(siddhiAppContext.getName() + ": CacheExpirer ended");
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
Also used : OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent(io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 7 with ConnectionUnavailableException

use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.

the class Table method onUpdateError.

protected void onUpdateError(ComplexEventChunk<StateEvent> updatingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, Exception e) {
    OnErrorAction errorAction = onErrorAction;
    if (e instanceof ConnectionUnavailableException) {
        isConnected.set(false);
        if (errorAction == OnErrorAction.STORE) {
            updatingEventChunk.reset();
            ErroneousEvent erroneousEvent = new ErroneousEvent(new ReplayableTableRecord(updatingEventChunk, compiledCondition, compiledUpdateSet), e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(updatingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_UPDATE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing update for events  " + "at '" + tableDefinition.getId() + "'. Events saved '" + updatingEventChunk.toString() + "'");
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
            if (!isTryingToConnect.get()) {
                connectWithRetry();
            }
        } else {
            if (isTryingToConnect.get()) {
                LOG.warn("Error on '" + siddhiAppContext.getName() + "' while performing update for " + "events '" + updatingEventChunk + "', operation busy waiting at Table '" + tableDefinition.getId() + "' as its trying to reconnect!");
                waitWhileConnect();
                LOG.info("SiddhiApp '" + siddhiAppContext.getName() + "' table '" + tableDefinition.getId() + "' has become available for update operation for events '" + updatingEventChunk + "'");
                update(updatingEventChunk, compiledCondition, compiledUpdateSet);
            } else {
                connectWithRetry();
                update(updatingEventChunk, compiledCondition, compiledUpdateSet);
            }
        }
    } else if (e instanceof DatabaseRuntimeException) {
        if (errorAction == OnErrorAction.STORE) {
            updatingEventChunk.reset();
            ReplayableTableRecord record = new ReplayableTableRecord(updatingEventChunk, compiledCondition, compiledUpdateSet);
            record.setFromConnectionUnavailableException(false);
            ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(updatingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_UPDATE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing update for events  " + "at '" + tableDefinition.getId() + "'. Events saved '" + updatingEventChunk.toString() + "'");
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
        }
    }
}
Also used : DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) ReplayableTableRecord(io.siddhi.core.util.error.handler.model.ReplayableTableRecord) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 8 with ConnectionUnavailableException

use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.

the class Table method onUpdateOrAddError.

protected void onUpdateOrAddError(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor, Exception e) {
    OnErrorAction errorAction = onErrorAction;
    if (e instanceof ConnectionUnavailableException) {
        isConnected.set(false);
        if (errorAction == OnErrorAction.STORE) {
            updateOrAddingEventChunk.reset();
            ErroneousEvent erroneousEvent = new ErroneousEvent(new ReplayableTableRecord(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor), e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(updateOrAddingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_UPDATE_OR_ADD, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing update or add for " + "events  at '" + tableDefinition.getId() + "'. Events saved '" + updateOrAddingEventChunk.toString() + "'");
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
            if (!isTryingToConnect.get()) {
                connectWithRetry();
            }
        } else {
            if (isTryingToConnect.get()) {
                LOG.warn("Error on '" + siddhiAppContext.getName() + "' while performing update or add for " + "events '" + updateOrAddingEventChunk + "', operation busy waiting at Table '" + tableDefinition.getId() + "' as its trying to reconnect!");
                waitWhileConnect();
                LOG.info("SiddhiApp '" + siddhiAppContext.getName() + "' table '" + tableDefinition.getId() + "' has become available for update or add operation for events '" + updateOrAddingEventChunk + "'");
                updateOrAdd(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor);
            } else {
                connectWithRetry();
                updateOrAdd(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor);
            }
        }
    } else if (e instanceof DatabaseRuntimeException) {
        if (errorAction == OnErrorAction.STORE) {
            updateOrAddingEventChunk.reset();
            ReplayableTableRecord record = new ReplayableTableRecord(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor);
            record.setFromConnectionUnavailableException(false);
            ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(updateOrAddingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_UPDATE_OR_ADD, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing update or add for " + "events  at '" + tableDefinition.getId() + "'. Events saved '" + updateOrAddingEventChunk.toString() + "'");
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
        }
    }
}
Also used : DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) ReplayableTableRecord(io.siddhi.core.util.error.handler.model.ReplayableTableRecord) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) ErroneousEvent(io.siddhi.core.util.error.handler.model.ErroneousEvent)

Example 9 with ConnectionUnavailableException

use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.

the class Sink method publish.

@Override
public final void publish(Object payload) {
    if (mapperLatencyTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
        mapperLatencyTracker.markOut();
    }
    DynamicOptions dynamicOptions = trpDynamicOptions.get();
    if (isConnected()) {
        S state = stateHolder.getState();
        try {
            publish(payload, dynamicOptions, state);
            if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                throughputTracker.eventIn();
            }
        } catch (ConnectionUnavailableException e) {
            setConnected(false);
            if (connectionCallback != null) {
                connectionCallback.connectionFailed();
            }
            if (!isTryingToConnect.getAndSet(true)) {
                try {
                    connectAndPublish(payload, dynamicOptions, state);
                    isTryingToConnect.set(false);
                } catch (ConnectionUnavailableException e1) {
                    isTryingToConnect.set(false);
                    onError(payload, dynamicOptions, e);
                }
            } else {
                onError(payload, dynamicOptions, e);
            }
        } finally {
            stateHolder.returnState(state);
        }
    } else if (!isShutdown.get()) {
        onError(payload, dynamicOptions, new ConnectionUnavailableException("Connection unavailable at Sink '" + type + "' at '" + streamDefinition.getId() + "'. Connection retrying is in progress from a different thread"));
    }
}
Also used : DynamicOptions(io.siddhi.core.util.transport.DynamicOptions) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 10 with ConnectionUnavailableException

use of io.siddhi.core.exception.ConnectionUnavailableException in project siddhi by wso2.

the class AbstractRecordTable method add.

@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
    List<Object[]> records = new ArrayList<>();
    addingEventChunk.reset();
    long timestamp = 0L;
    while (addingEventChunk.hasNext()) {
        StreamEvent event = addingEventChunk.next();
        records.add(event.getOutputData());
        timestamp = event.getTimestamp();
    }
    try {
        if (recordTableHandler != null) {
            recordTableHandler.add(timestamp, records);
        } else {
            add(records);
        }
    } catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
        onAddError(addingEventChunk, e);
    }
}
Also used : DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Aggregations

ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)14 DatabaseRuntimeException (io.siddhi.core.exception.DatabaseRuntimeException)7 StateEvent (io.siddhi.core.event.state.StateEvent)5 StreamEvent (io.siddhi.core.event.stream.StreamEvent)5 ErroneousEvent (io.siddhi.core.util.error.handler.model.ErroneousEvent)4 ArrayList (java.util.ArrayList)4 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)3 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)3 ReplayableTableRecord (io.siddhi.core.util.error.handler.model.ReplayableTableRecord)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)2 OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent (io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent)2 Attribute (io.siddhi.query.api.definition.Attribute)2 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)1 SiddhiManager (io.siddhi.core.SiddhiManager)1 Event (io.siddhi.core.event.Event)1