@Override public StateSnapshotMetadata recover( long commitPosition, int term, Predicate<StateSnapshotMetadata> filter) throws Exception { final File runtimeDirectory = storage.getRuntimeDirectory(); final List<StateSnapshotMetadata> snapshots = storage.listRecoverable(commitPosition); StateSnapshotMetadata recoveredMetadata = null; if (!snapshots.isEmpty()) { recoveredMetadata = snapshots.stream() .sorted(Comparator.reverseOrder()) .filter(filter) .findFirst() .orElse(null); } if (runtimeDirectory.exists()) { FileUtil.deleteFolder(runtimeDirectory.getAbsolutePath()); } if (recoveredMetadata != null) { final File snapshotPath = storage.getSnapshotDirectoryFor(recoveredMetadata); copySnapshot(runtimeDirectory, snapshotPath); } else { recoveredMetadata = StateSnapshotMetadata.createInitial(term); } return recoveredMetadata; }
@Override public void takeSnapshot(final StateSnapshotMetadata metadata) { if (db == null) { throw new IllegalStateException("Cannot create snapshot of not open database."); } if (exists(metadata)) { return; } final File snapshotDir = storage.getSnapshotDirectoryFor(metadata); db.createSnapshot(snapshotDir); }
private void startExporter(ServiceName<Partition> partitionName, Partition partition) { final StateStorage stateStorage = partition.getStateStorageFactory().create(EXPORTER_PROCESSOR_ID, PROCESSOR_NAME); final SnapshotController snapshotController = new StateSnapshotController( DefaultZeebeDbFactory.defaultFactory(ExporterColumnFamilies.class), stateStorage); streamProcessorServiceFactory .createService(partition, partitionName) .processorId(EXPORTER_PROCESSOR_ID) .processorName(PROCESSOR_NAME) .snapshotController(snapshotController) .streamProcessorFactory( (zeebeDb) -> new ExporterStreamProcessor( zeebeDb, partition.getInfo().getPartitionId(), exporterRepository.getExporters().values())) .build(); }
private void startExporter(ServiceName<Partition> partitionName, Partition partition) { final StateStorage stateStorage = partition.getStateStorageFactory().create(EXPORTER_PROCESSOR_ID, PROCESSOR_NAME); final SnapshotController snapshotController = new StateSnapshotController( DefaultZeebeDbFactory.defaultFactory(ExporterColumnFamilies.class), stateStorage); streamProcessorServiceFactory .createService(partition, partitionName) .processorId(EXPORTER_PROCESSOR_ID) .processorName(PROCESSOR_NAME) .snapshotController(snapshotController) .streamProcessorFactory( (zeebeDb) -> new ExporterStreamProcessor( zeebeDb, partition.getInfo().getPartitionId(), exporterRepository.getExporters().values())) .build(); }
public void startStreamProcessors( final ServiceName<Partition> partitionServiceName, final Partition partition) { final int partitionId = partition.getInfo().getPartitionId(); final Builder streamProcessorServiceBuilder = streamProcessorServiceFactory .createService(partition, partitionServiceName) .processorId(partitionId) .processorName(PROCESSOR_NAME); final StateStorage stateStorage = partition.getStateStorageFactory().create(partitionId, PROCESSOR_NAME); final StateSnapshotController stateSnapshotController = new StateSnapshotController(DefaultZeebeDbFactory.DEFAULT_DB_FACTORY, stateStorage); streamProcessorServiceBuilder .snapshotController(stateSnapshotController) .streamProcessorFactory( (zeebeDb) -> { final ZeebeState zeebeState = new ZeebeState(partitionId, zeebeDb); final TypedStreamEnvironment streamEnvironment = new TypedStreamEnvironment( partition.getLogStream(), clientApiTransport.getOutput()); return createTypedStreamProcessor( partitionServiceName, partitionId, streamEnvironment, zeebeState); }) .build(); }
@Override public void takeSnapshot(final StateSnapshotMetadata metadata) { if (db == null) { throw new IllegalStateException("Cannot create snapshot of not open database."); } if (exists(metadata)) { return; } final File snapshotDir = storage.getSnapshotDirectoryFor(metadata); db.createSnapshot(snapshotDir); }
@Override public StateSnapshotMetadata recover( long commitPosition, int term, Predicate<StateSnapshotMetadata> filter) throws Exception { final File runtimeDirectory = storage.getRuntimeDirectory(); final List<StateSnapshotMetadata> snapshots = storage.listRecoverable(commitPosition); StateSnapshotMetadata recoveredMetadata = null; if (!snapshots.isEmpty()) { recoveredMetadata = snapshots.stream() .sorted(Comparator.reverseOrder()) .filter(filter) .findFirst() .orElse(null); } if (runtimeDirectory.exists()) { FileUtil.deleteFolder(runtimeDirectory.getAbsolutePath()); } if (recoveredMetadata != null) { final File snapshotPath = storage.getSnapshotDirectoryFor(recoveredMetadata); copySnapshot(runtimeDirectory, snapshotPath); } else { recoveredMetadata = StateSnapshotMetadata.createInitial(term); } return recoveredMetadata; }
public void startStreamProcessors( final ServiceName<Partition> partitionServiceName, final Partition partition) { final int partitionId = partition.getInfo().getPartitionId(); final Builder streamProcessorServiceBuilder = streamProcessorServiceFactory .createService(partition, partitionServiceName) .processorId(partitionId) .processorName(PROCESSOR_NAME); final StateStorage stateStorage = partition.getStateStorageFactory().create(partitionId, PROCESSOR_NAME); final StateSnapshotController stateSnapshotController = new StateSnapshotController(DefaultZeebeDbFactory.DEFAULT_DB_FACTORY, stateStorage); streamProcessorServiceBuilder .snapshotController(stateSnapshotController) .streamProcessorFactory( (zeebeDb) -> { final ZeebeState zeebeState = new ZeebeState(partitionId, zeebeDb); final TypedStreamEnvironment streamEnvironment = new TypedStreamEnvironment( partition.getLogStream(), clientApiTransport.getOutput()); return createTypedStreamProcessor( partitionServiceName, partitionId, streamEnvironment, zeebeState); }) .build(); }
private StreamProcessorService buildStreamProcessorController() { final String name = "processor"; final StateStorage stateStorage = getStateStorageFactory().create(streamProcessorId, name); currentSnapshotController = new StateSnapshotController(zeebeDbFactory, stateStorage); return LogStreams.createStreamProcessor(name, streamProcessorId) .logStream(stream) .snapshotController(currentSnapshotController) .actorScheduler(actorScheduler) .serviceContainer(serviceContainer) .streamProcessorFactory( zeebeDb -> { currentStreamProcessor.wrap(factory.createProcessor(zeebeDb)); return currentStreamProcessor; }) .build() .join(); } }
private StreamProcessorService buildStreamProcessorController() { final String name = "processor"; final StateStorage stateStorage = getStateStorageFactory().create(streamProcessorId, name); currentSnapshotController = new StateSnapshotController(zeebeDbFactory, stateStorage); return LogStreams.createStreamProcessor(name, streamProcessorId) .logStream(stream) .snapshotController(currentSnapshotController) .actorScheduler(actorScheduler) .serviceContainer(serviceContainer) .streamProcessorFactory( zeebeDb -> { currentStreamProcessor.wrap(factory.createProcessor(zeebeDb)); return currentStreamProcessor; }) .build() .join(); } }