Search in sources :

Example 6 with DatabaseRuntimeException

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

the class AbstractRecordTable method updateOrAdd.

@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    List<Object[]> addingRecords = new ArrayList<>();
    updateOrAddingEventChunk.reset();
    long timestamp = 0L;
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent stateEvent = updateOrAddingEventChunk.next();
        Map<String, Object> variableMap = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
            variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateConditionParameterMaps.add(variableMap);
        Map<String, Object> variableMapForUpdateSet = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
            variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateSetParameterMaps.add(variableMapForUpdateSet);
        addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
        timestamp = stateEvent.getTimestamp();
    }
    try {
        if (recordTableHandler != null) {
            recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        } else {
            updateOrAdd(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        }
    } catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
        onUpdateOrAddError(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor, e);
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) HashMap(java.util.HashMap) DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) ArrayList(java.util.ArrayList) StateEvent(io.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 7 with DatabaseRuntimeException

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

the class Table method onDeleteError.

protected void onDeleteError(ComplexEventChunk<StateEvent> deletingEventChunk, CompiledCondition compiledCondition, Exception e) {
    OnErrorAction errorAction = onErrorAction;
    if (e instanceof ConnectionUnavailableException) {
        isConnected.set(false);
        if (errorAction == OnErrorAction.STORE) {
            deletingEventChunk.reset();
            ErroneousEvent erroneousEvent = new ErroneousEvent(new ReplayableTableRecord(deletingEventChunk, compiledCondition), e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events  at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.toString() + "'");
            if (LOG.isDebugEnabled()) {
                LOG.debug(e);
            }
            if (!isTryingToConnect.get()) {
                connectWithRetry();
            }
        } else {
            if (isTryingToConnect.get()) {
                LOG.warn("Error on '" + siddhiAppContext.getName() + "' while performing delete for events '" + deletingEventChunk + "', 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 delete operation for events '" + deletingEventChunk + "'");
                delete(deletingEventChunk, compiledCondition);
            } else {
                connectWithRetry();
                delete(deletingEventChunk, compiledCondition);
            }
        }
    } else if (e instanceof DatabaseRuntimeException) {
        if (errorAction == OnErrorAction.STORE) {
            deletingEventChunk.reset();
            ReplayableTableRecord record = new ReplayableTableRecord(deletingEventChunk, compiledCondition);
            record.setFromConnectionUnavailableException(false);
            ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
            erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
            ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
            LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events  at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.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)

Aggregations

ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)7 DatabaseRuntimeException (io.siddhi.core.exception.DatabaseRuntimeException)7 ArrayList (java.util.ArrayList)4 StateEvent (io.siddhi.core.event.state.StateEvent)3 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)3 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)3 ErroneousEvent (io.siddhi.core.util.error.handler.model.ErroneousEvent)3 ReplayableTableRecord (io.siddhi.core.util.error.handler.model.ReplayableTableRecord)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 StreamEvent (io.siddhi.core.event.stream.StreamEvent)1