use of org.apache.samza.checkpoint.Checkpoint in project samza by apache.
the class TestBlobStoreUtil method testGetSSIThrowsExceptionOnSyncBlobStoreErrors.
@Test(expected = SamzaException.class)
public void testGetSSIThrowsExceptionOnSyncBlobStoreErrors() {
Checkpoint checkpoint = createCheckpointV2(BlobStoreStateBackendFactory.class.getName(), ImmutableMap.of("storeName", "snapshotIndexBlobId"));
Set<String> storesToBackupOrRestore = new HashSet<>();
storesToBackupOrRestore.add("storeName");
BlobStoreUtil mockBlobStoreUtil = mock(BlobStoreUtil.class);
when(mockBlobStoreUtil.getSnapshotIndex(anyString(), any(Metadata.class))).thenThrow(new RuntimeException());
when(mockBlobStoreUtil.getStoreSnapshotIndexes(anyString(), anyString(), anyString(), any(Checkpoint.class), anySetOf(String.class))).thenCallRealMethod();
mockBlobStoreUtil.getStoreSnapshotIndexes("testJobName", "testJobId", "taskName", checkpoint, storesToBackupOrRestore);
}
use of org.apache.samza.checkpoint.Checkpoint in project samza by apache.
the class TestBlobStoreUtil method testGetSSIThrowsExceptionForCheckpointV1.
public void testGetSSIThrowsExceptionForCheckpointV1() {
Checkpoint mockCheckpoint = mock(Checkpoint.class);
when(mockCheckpoint.getVersion()).thenReturn((short) 1);
BlobStoreUtil blobStoreUtil = new BlobStoreUtil(mock(BlobStoreManager.class), MoreExecutors.newDirectExecutorService(), null, null);
Map<String, Pair<String, SnapshotIndex>> prevSnapshotIndexes = blobStoreUtil.getStoreSnapshotIndexes("testJobName", "testJobId", "taskName", mockCheckpoint, new HashSet<>());
assertEquals(prevSnapshotIndexes.size(), 0);
}
use of org.apache.samza.checkpoint.Checkpoint in project samza by apache.
the class TestBlobStoreUtil method testGetCheckpointIndexIgnoresStoresNotInStoresToBackupRestoreSet.
@Test
public void testGetCheckpointIndexIgnoresStoresNotInStoresToBackupRestoreSet() {
String store = "storeName1";
String anotherStore = "storeName2";
String oneMoreStore = "storeName3";
SnapshotIndex mockStoreSnapshotIndex = mock(SnapshotIndex.class);
Set<String> storesToBackupOrRestore = ImmutableSet.of(store, anotherStore);
CheckpointV2 checkpoint = createCheckpointV2(BlobStoreStateBackendFactory.class.getName(), ImmutableMap.of(store, "1", anotherStore, "2", oneMoreStore, "3"));
BlobStoreUtil mockBlobStoreUtil = mock(BlobStoreUtil.class);
when(mockBlobStoreUtil.getSnapshotIndex(any(String.class), any(Metadata.class))).thenReturn(CompletableFuture.completedFuture(mockStoreSnapshotIndex));
when(mockBlobStoreUtil.getStoreSnapshotIndexes(anyString(), anyString(), anyString(), any(Checkpoint.class), anySetOf(String.class))).thenCallRealMethod();
Map<String, Pair<String, SnapshotIndex>> snapshotIndexes = mockBlobStoreUtil.getStoreSnapshotIndexes("testJobName", "testJobId", "taskName", checkpoint, storesToBackupOrRestore);
verify(mockBlobStoreUtil, times(storesToBackupOrRestore.size())).getSnapshotIndex(anyString(), any(Metadata.class));
}
use of org.apache.samza.checkpoint.Checkpoint in project samza by apache.
the class TransactionalStateTaskRestoreManager method getCheckpointedChangelogOffsets.
private Map<String, KafkaStateCheckpointMarker> getCheckpointedChangelogOffsets(Checkpoint checkpoint) {
Map<String, KafkaStateCheckpointMarker> checkpointedChangelogOffsets = new HashMap<>();
if (checkpoint == null)
return checkpointedChangelogOffsets;
if (checkpoint instanceof CheckpointV2) {
Map<String, Map<String, String>> factoryStoreSCMs = ((CheckpointV2) checkpoint).getStateCheckpointMarkers();
if (factoryStoreSCMs.containsKey(KafkaStateCheckpointMarker.KAFKA_STATE_BACKEND_FACTORY_NAME)) {
factoryStoreSCMs.get(KafkaStateCheckpointMarker.KAFKA_STATE_BACKEND_FACTORY_NAME).forEach((storeName, scmString) -> {
KafkaStateCheckpointMarker kafkaSCM = KafkaStateCheckpointMarker.deserialize(scmString);
checkpointedChangelogOffsets.put(storeName, kafkaSCM);
});
}
// skip the non-KafkaStateCheckpointMarkers
} else if (checkpoint instanceof CheckpointV1) {
// If the checkpoint v1 is used, we need to fetch the changelog SSPs in the inputOffsets in order to get the
// store offset.
Map<SystemStreamPartition, String> checkpointedOffsets = checkpoint.getOffsets();
storeChangelogs.forEach((storeName, systemStream) -> {
Partition changelogPartition = taskModel.getChangelogPartition();
SystemStreamPartition storeChangelogSSP = new SystemStreamPartition(systemStream, changelogPartition);
String checkpointedOffset = checkpointedOffsets.get(storeChangelogSSP);
if (StringUtils.isNotBlank(checkpointedOffset)) {
KafkaChangelogSSPOffset kafkaChangelogSSPOffset = KafkaChangelogSSPOffset.fromString(checkpointedOffset);
KafkaStateCheckpointMarker marker = new KafkaStateCheckpointMarker(storeChangelogSSP, kafkaChangelogSSPOffset.getChangelogOffset());
checkpointedChangelogOffsets.put(storeName, marker);
}
});
} else {
throw new SamzaException("Unsupported checkpoint version: " + checkpoint.getVersion());
}
return checkpointedChangelogOffsets;
}
use of org.apache.samza.checkpoint.Checkpoint in project samza by apache.
the class TaskStorageCommitManager method writeCheckpointToStoreDirectories.
/**
* Writes the {@link Checkpoint} information returned by {@link #upload(CheckpointId, Map)}
* in each store directory and store checkpoint directory. Written content depends on the type of {@code checkpoint}.
* For {@link CheckpointV2}, writes the entire task {@link CheckpointV2}.
* For {@link CheckpointV1}, only writes the changelog ssp offsets in the OFFSET* files.
*
* Note: The assumption is that this method will be invoked once for each {@link Checkpoint} version that the
* task needs to write as determined by {@link org.apache.samza.config.TaskConfig#getCheckpointWriteVersions()}.
* This is required for upgrade and rollback compatibility.
*
* @param checkpoint the latest checkpoint to be persisted to local file system
*/
public void writeCheckpointToStoreDirectories(Checkpoint checkpoint) {
if (checkpoint instanceof CheckpointV1) {
LOG.debug("Writing CheckpointV1 to store and checkpoint directories for taskName: {} with checkpoint: {}", taskName, checkpoint);
// Write CheckpointV1 changelog offsets to store and checkpoint directories
writeChangelogOffsetFiles(checkpoint.getOffsets());
} else if (checkpoint instanceof CheckpointV2) {
LOG.debug("Writing CheckpointV2 to store and checkpoint directories for taskName: {} with checkpoint: {}", taskName, checkpoint);
storageEngines.forEach((storeName, storageEngine) -> {
// Only write the checkpoint file if the store is durable and persisted to disk
if (storageEngine.getStoreProperties().isDurableStore() && storageEngine.getStoreProperties().isPersistedToDisk()) {
CheckpointV2 checkpointV2 = (CheckpointV2) checkpoint;
try {
File storeDir = storageManagerUtil.getTaskStoreDir(durableStoreBaseDir, storeName, taskName, TaskMode.Active);
storageManagerUtil.writeCheckpointV2File(storeDir, checkpointV2);
CheckpointId checkpointId = checkpointV2.getCheckpointId();
File checkpointDir = Paths.get(storageManagerUtil.getStoreCheckpointDir(storeDir, checkpointId)).toFile();
storageManagerUtil.writeCheckpointV2File(checkpointDir, checkpointV2);
} catch (Exception e) {
throw new SamzaException(String.format("Write checkpoint file failed for task: %s, storeName: %s, checkpointId: %s", taskName, storeName, ((CheckpointV2) checkpoint).getCheckpointId()), e);
}
}
});
} else {
throw new SamzaException("Unsupported checkpoint version: " + checkpoint.getVersion());
}
}
Aggregations