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();
}
}
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);
}
}
}
}
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);
}
}
}
}
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"));
}
}
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);
}
}
Aggregations