Search in sources :

Example 6 with IncrementalSnapshotInfo

use of io.siddhi.core.util.persistence.util.IncrementalSnapshotInfo in project siddhi by wso2.

the class IncrementalFileSystemPersistenceStore method cleanOldRevisions.

private void cleanOldRevisions(IncrementalSnapshotInfo incrementalSnapshotInfo) {
    if (incrementalSnapshotInfo.getType() != IncrementalSnapshotInfo.SnapshotType.INCREMENT) {
        File dir = new File(folder + File.separator + incrementalSnapshotInfo.getSiddhiAppId());
        File[] files = dir.listFiles();
        if (files != null) {
            long baseTimeStamp = (incrementalSnapshotInfo.getTime());
            for (File file : files) {
                String fileName = file.getName();
                IncrementalSnapshotInfo snapshotInfo = PersistenceHelper.convertRevision(fileName);
                if (snapshotInfo.getTime() < baseTimeStamp && incrementalSnapshotInfo.getId().equals(snapshotInfo.getId())) {
                    if (incrementalSnapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.BASE && snapshotInfo.getType() != IncrementalSnapshotInfo.SnapshotType.PERIODIC) {
                        if (file.exists()) {
                            Boolean isDeleted = file.delete();
                            if (!isDeleted) {
                                log.error("Error deleting old revision " + fileName);
                            }
                        }
                    } else if (incrementalSnapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.PERIODIC && snapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.PERIODIC) {
                        if (file.exists()) {
                            Boolean isDeleted = file.delete();
                            if (!isDeleted) {
                                log.error("Error deleting old revision " + fileName);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IncrementalSnapshotInfo(io.siddhi.core.util.persistence.util.IncrementalSnapshotInfo) File(java.io.File)

Aggregations

IncrementalSnapshotInfo (io.siddhi.core.util.persistence.util.IncrementalSnapshotInfo)6 CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)3 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)2 CannotClearSiddhiAppStateException (io.siddhi.core.exception.CannotClearSiddhiAppStateException)2 NoPersistenceStoreException (io.siddhi.core.exception.NoPersistenceStoreException)2 PersistenceStoreException (io.siddhi.core.exception.PersistenceStoreException)2 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 ThreadBarrier (io.siddhi.core.util.ThreadBarrier)2 IncrementalPersistenceStore (io.siddhi.core.util.persistence.IncrementalPersistenceStore)2 PersistenceStore (io.siddhi.core.util.persistence.PersistenceStore)2 PersistenceConstants (io.siddhi.core.util.persistence.util.PersistenceConstants)2 PersistenceHelper (io.siddhi.core.util.persistence.util.PersistenceHelper)2 Snapshot (io.siddhi.core.util.snapshot.state.Snapshot)2 SnapshotStateList (io.siddhi.core.util.snapshot.state.SnapshotStateList)2 State (io.siddhi.core.util.snapshot.state.State)2