@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);
        }
    }
State holder for  partitioned use case
modules/siddhi-core/src/main/java/io/siddhi/core/util/snapshot/state/PartitionStateHolder.java