use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class SiddhiAppRuntimeImpl method startSources.
public void startSources() {
if (running) {
log.warn("Error calling startSources() for Siddhi App '" + siddhiAppContext.getName() + "', " + "SiddhiApp already started with the sources.");
return;
}
if (!runningWithoutSources) {
throw new SiddhiAppRuntimeException("Cannot call startSources() without calling startWithoutSources() " + "for Siddhi App '" + siddhiAppContext.getName() + "'");
} else {
try {
for (List<Source> sources : sourceMap.values()) {
for (Source source : sources) {
source.connectWithRetry();
}
}
running = true;
runningWithoutSources = false;
} catch (Throwable t) {
log.error("Error starting Siddhi App '" + siddhiAppContext.getName() + "', " + "triggering shutdown process. " + t.getMessage());
try {
shutdown();
} catch (Throwable t1) {
log.error("Error shutting down partially started Siddhi App '" + siddhiAppContext.getName() + "', " + t1.getMessage());
}
}
}
}
use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class SiddhiAppRuntimeImpl method removeCallback.
public void removeCallback(QueryCallback callback) {
if (callback.getQueryName() == null) {
throw new SiddhiAppRuntimeException("Cannot find QueryName in the queryCallback");
}
String queryName = callback.getQueryName();
QueryRuntime queryRuntime = queryProcessorMap.get(queryName);
if (queryRuntime != null) {
((QueryRuntimeImpl) queryRuntime).removeCallback(callback);
}
}
use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class SnapshotService method waitForSystemStabilization.
private void waitForSystemStabilization() {
int retryCount = 100;
int activeThreads = siddhiAppContext.getThreadBarrier().getActiveThreads();
while (activeThreads != 0 && retryCount > 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new SiddhiAppRuntimeException("Stabilization of Siddhi App " + siddhiAppContext.getName() + " for snapshot/restore interrupted. " + e.getMessage(), e);
}
activeThreads = siddhiAppContext.getThreadBarrier().getActiveThreads();
retryCount--;
}
if (retryCount == 0) {
throw new SiddhiAppRuntimeException("Siddhi App " + siddhiAppContext.getName() + " not stabilized for snapshot/restore, Active thread count is " + activeThreads);
}
}
use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class SnapshotService method fullSnapshot.
public byte[] fullSnapshot() {
try {
SnapshotRequest.requestForFullSnapshot(true);
Map<String, Map<String, Map<String, Map<String, Map<String, Object>>>>> fullSnapshot = new HashMap<>();
byte[] serializedFullState = null;
if (log.isDebugEnabled()) {
log.debug("Taking snapshot ...");
}
try {
threadBarrier.lock();
waitForSystemStabilization();
for (Map.Entry<String, PartitionIdStateHolder> partitionIdState : partitionIdStates.entrySet()) {
for (Map.Entry<String, ElementStateHolder> queryState : partitionIdState.getValue().queryStateHolderMap.entrySet()) {
for (Map.Entry<String, StateHolder> elementState : queryState.getValue().elementHolderMap.entrySet()) {
Map<String, Map<String, State>> partitionKeyStates = elementState.getValue().getAllStates();
try {
for (Map.Entry<String, Map<String, State>> partitionKeyState : partitionKeyStates.entrySet()) {
for (Map.Entry<String, State> groupByKeyState : partitionKeyState.getValue().entrySet()) {
String partitionAndGroupByKey = partitionKeyState.getKey() + "--" + groupByKeyState.getKey();
State state = groupByKeyState.getValue();
Map<String, Object> itemStates = state.snapshot();
if (itemStates != null) {
Map<String, Object> itemSnapshots = new HashMap<>();
for (Map.Entry<String, Object> itemState : itemStates.entrySet()) {
if (itemState.getValue() instanceof Snapshot) {
if (((Snapshot) itemState.getValue()).isIncrementalSnapshot()) {
throw new NoPersistenceStoreException("No incremental " + "persistence store exist to store incremental " + "snapshot of siddhiApp:'" + siddhiAppContext.getName() + "' subElement:'" + queryState.getKey() + "' elementId:'" + elementState.getKey() + "' partitionKey:'" + partitionKeyState.getKey() + "' groupByKey:'" + groupByKeyState.getKey() + "' and itemKey:'" + itemState.getKey() + "'");
} else {
itemSnapshots.put(itemState.getKey(), itemState.getValue());
}
} else {
itemSnapshots.put(itemState.getKey(), itemState.getValue());
}
}
Map<String, Map<String, Map<String, Map<String, Object>>>> partitionIdSnapshot = fullSnapshot.computeIfAbsent(partitionIdState.getKey(), k -> new HashMap<>());
Map<String, Map<String, Map<String, Object>>> partitionGroupByKeySnapshot = partitionIdSnapshot.computeIfAbsent(partitionAndGroupByKey, k -> new HashMap<>());
Map<String, Map<String, Object>> querySnapshot = partitionGroupByKeySnapshot.computeIfAbsent(queryState.getKey(), k -> new HashMap<>());
Map<String, Object> elementSnapshot = querySnapshot.get(elementState.getKey());
if (elementSnapshot == null) {
querySnapshot.put(elementState.getKey(), itemSnapshots);
} else {
throw new SiddhiAppRuntimeException("Duplicate state exist for " + "siddhiApp:'" + siddhiAppContext.getName() + "' partitionKey:'" + partitionKeyState.getKey() + "' groupByKey:'" + groupByKeyState.getKey() + "' subElement:'" + queryState.getKey() + "' elementId:'" + elementState.getKey() + "'");
}
}
}
}
} finally {
elementState.getValue().returnAllStates(partitionKeyStates);
}
}
}
}
if (log.isDebugEnabled()) {
log.debug("Snapshot serialization started ...");
}
serializedFullState = ByteSerializer.objectToByte(fullSnapshot, siddhiAppContext);
if (log.isDebugEnabled()) {
log.debug("Snapshot serialization finished.");
}
} finally {
threadBarrier.unlock();
}
if (log.isDebugEnabled()) {
log.debug("Snapshot taken for Siddhi app '" + siddhiAppContext.getName() + "'");
}
return serializedFullState;
} finally {
SnapshotRequest.requestForFullSnapshot(false);
}
}
use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class PartitionStateHolder method returnState.
@Override
public void returnState(State state) {
String partitionFlowId = SiddhiAppContext.getPartitionFlowId();
String groupByFlowId = SiddhiAppContext.getGroupByFlowId();
if (state.activeUseCount == 0) {
try {
if (state.canDestroy()) {
removeState(partitionFlowId, groupByFlowId);
}
} catch (Throwable t) {
log.error("Dropping partition state for partition key '" + partitionFlowId + "' and the group by key '" + groupByFlowId + "', due to error! " + t.getMessage(), t);
removeState(partitionFlowId, groupByFlowId);
}
} else if (state.activeUseCount < 0) {
throw new SiddhiAppRuntimeException("State active count has reached less then zero for partition key '" + partitionFlowId + "' and the group by key '" + groupByFlowId + "', current value is " + state.activeUseCount);
}
}
Aggregations