use of io.siddhi.core.util.snapshot.state.State 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);
}
}
Aggregations