Java Code Examples for org.apache.flink.util.ResourceGuard#Lease

The following examples show how to use org.apache.flink.util.ResourceGuard#Lease . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyOnWriteSkipListStateMap.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public CopyOnWriteSkipListStateMapSnapshot<K, N, S> stateSnapshot() {
	tryToDeleteNodesPhysically();

	ResourceGuard.Lease lease;
	try {
		lease = resourceGuard.acquireResource();
	} catch (Exception e) {
		throw new RuntimeException("Acquire resource failed, and can't make snapshot of state map", e);
	}

	synchronized (snapshotVersions) {
		// increase the map version for copy-on-write and register the snapshot
		if (++stateMapVersion < 0) {
			// this is just a safety net against overflows, but should never happen in practice (i.e., only after 2^31 snapshots)
			throw new IllegalStateException("Version count overflow. Enforcing restart.");
		}

		highestRequiredSnapshotVersionPlusOne = stateMapVersion;
		snapshotVersions.add(highestRequiredSnapshotVersionPlusOne);
	}

	return new CopyOnWriteSkipListStateMapSnapshot<>(this, lease);
}
 
Example 2
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().getPath());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example 3
Source File: RocksFullSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
SnapshotAsynchronousPartCallable(
	@Nonnull SupplierWithException<CheckpointStreamWithResultProvider, Exception> checkpointStreamSupplier,
	@Nonnull ResourceGuard.Lease dbLease,
	@Nonnull Snapshot snapshot,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots,
	@Nonnull List<RocksDbKvStateInfo> metaDataCopy,
	@Nonnull String logPathString) {

	this.checkpointStreamSupplier = checkpointStreamSupplier;
	this.dbLease = dbLease;
	this.snapshot = snapshot;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
	this.metaData = fillMetaData(metaDataCopy);
	this.logPathString = logPathString;
}
 
Example 4
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().getPath());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example 5
Source File: RocksFullSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
SnapshotAsynchronousPartCallable(
	@Nonnull SupplierWithException<CheckpointStreamWithResultProvider, Exception> checkpointStreamSupplier,
	@Nonnull ResourceGuard.Lease dbLease,
	@Nonnull Snapshot snapshot,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots,
	@Nonnull List<RocksDbKvStateInfo> metaDataCopy,
	@Nonnull String logPathString) {

	this.checkpointStreamSupplier = checkpointStreamSupplier;
	this.dbLease = dbLease;
	this.snapshot = snapshot;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
	this.metaData = fillMetaData(metaDataCopy);
	this.logPathString = logPathString;
}
 
Example 6
Source File: CopyOnWriteSkipListStateMapSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CopyOnWriteSkipListStateMap}.
 *
 * @param owningStateMap the {@link CopyOnWriteSkipListStateMap} for which this object represents a snapshot.
 * @param lease the lease protects the state map resources.
 */
CopyOnWriteSkipListStateMapSnapshot(
	CopyOnWriteSkipListStateMap<K, N, S> owningStateMap,
	ResourceGuard.Lease lease) {
	super(owningStateMap);

	this.snapshotVersion = owningStateMap.getStateMapVersion();
	this.numberOfEntriesInSnapshotData = owningStateMap.size();
	this.lease = lease;
}
 
Example 7
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().toString());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example 8
Source File: RocksFullSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
SnapshotAsynchronousPartCallable(
	@Nonnull SupplierWithException<CheckpointStreamWithResultProvider, Exception> checkpointStreamSupplier,
	@Nonnull ResourceGuard.Lease dbLease,
	@Nonnull Snapshot snapshot,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots,
	@Nonnull List<RocksDbKvStateInfo> metaDataCopy,
	@Nonnull String logPathString) {

	this.checkpointStreamSupplier = checkpointStreamSupplier;
	this.dbLease = dbLease;
	this.snapshot = snapshot;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
	this.metaData = fillMetaData(metaDataCopy);
	this.logPathString = logPathString;
}
 
Example 9
Source File: NonClosingCheckpointOutputStream.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link org.apache.flink.util.ResourceGuard.Lease} that prevents closing this stream. To allow the system
 * to close this stream, each of the acquired leases need to call {@link Lease#close()}, on their acquired leases.
 */
public final ResourceGuard.Lease acquireLease() throws IOException {
	return resourceGuard.acquireResource();
}
 
Example 10
Source File: NonClosingCheckpointOutputStream.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link org.apache.flink.util.ResourceGuard.Lease} that prevents closing this stream. To allow the system
 * to close this stream, each of the acquired leases need to call {@link Lease#close()}, on their acquired leases.
 */
public final ResourceGuard.Lease acquireLease() throws IOException {
	return resourceGuard.acquireResource();
}