use of org.apache.samza.config.BlobStoreConfig in project samza by apache.
the class TestBlobStoreRestoreManager method testDeleteUnusedStoresRemovesStoresDeletedFromConfig.
@Test
public void testDeleteUnusedStoresRemovesStoresDeletedFromConfig() {
String jobName = "testJobName";
String jobId = "testJobId";
String taskName = "taskName";
StorageConfig storageConfig = mock(StorageConfig.class);
BlobStoreConfig blobStoreConfig = mock(BlobStoreConfig.class);
SnapshotIndex mockSnapshotIndex = mock(SnapshotIndex.class);
String blobId = "blobId";
Map<String, Pair<String, SnapshotIndex>> initialStoreSnapshotIndexes = ImmutableMap.of("oldStoreName", Pair.of(blobId, mockSnapshotIndex));
when(storageConfig.getStoresWithBackupFactory(eq(BlobStoreStateBackendFactory.class.getName()))).thenReturn(ImmutableList.of("newStoreName"));
when(storageConfig.getStoresWithRestoreFactory(eq(BlobStoreStateBackendFactory.class.getName()))).thenReturn(ImmutableList.of("newStoreName"));
DirIndex dirIndex = mock(DirIndex.class);
when(mockSnapshotIndex.getDirIndex()).thenReturn(dirIndex);
BlobStoreUtil blobStoreUtil = mock(BlobStoreUtil.class);
when(blobStoreUtil.cleanUpDir(any(DirIndex.class), any(Metadata.class))).thenReturn(CompletableFuture.completedFuture(null));
when(blobStoreUtil.deleteDir(any(DirIndex.class), any(Metadata.class))).thenReturn(CompletableFuture.completedFuture(null));
when(blobStoreUtil.deleteSnapshotIndexBlob(anyString(), any(Metadata.class))).thenReturn(CompletableFuture.completedFuture(null));
BlobStoreRestoreManager.deleteUnusedStoresFromBlobStore(jobName, jobId, taskName, storageConfig, blobStoreConfig, initialStoreSnapshotIndexes, blobStoreUtil, EXECUTOR);
verify(blobStoreUtil, times(1)).cleanUpDir(eq(dirIndex), any(Metadata.class));
verify(blobStoreUtil, times(1)).deleteDir(eq(dirIndex), any(Metadata.class));
verify(blobStoreUtil, times(1)).deleteSnapshotIndexBlob(eq(blobId), any(Metadata.class));
}
use of org.apache.samza.config.BlobStoreConfig in project samza by apache.
the class BlobStoreRestoreManager method deleteUnusedStoresFromBlobStore.
/**
* Deletes blob store contents for stores that were present in the last checkpoint but are either no longer
* present in job configs (removed by user since last deployment) or are no longer configured to be backed
* up using blob stores.
*
* This method blocks until all the necessary store contents and snapshot index blobs have been marked for deletion.
*/
@VisibleForTesting
static void deleteUnusedStoresFromBlobStore(String jobName, String jobId, String taskName, StorageConfig storageConfig, BlobStoreConfig blobStoreConfig, Map<String, Pair<String, SnapshotIndex>> initialStoreSnapshotIndexes, BlobStoreUtil blobStoreUtil, ExecutorService executor) {
List<String> storesToBackup = storageConfig.getStoresWithBackupFactory(BlobStoreStateBackendFactory.class.getName());
List<String> storesToRestore = storageConfig.getStoresWithRestoreFactory(BlobStoreStateBackendFactory.class.getName());
List<CompletionStage<Void>> storeDeletionFutures = new ArrayList<>();
initialStoreSnapshotIndexes.forEach((storeName, scmAndSnapshotIndex) -> {
if (!storesToBackup.contains(storeName) && !storesToRestore.contains(storeName)) {
LOG.debug("Removing task: {} store: {} from blob store. It is either no longer used, " + "or is no longer configured to be backed up or restored with blob store.", taskName, storeName);
DirIndex dirIndex = scmAndSnapshotIndex.getRight().getDirIndex();
Metadata requestMetadata = new Metadata(Metadata.SNAPSHOT_INDEX_PAYLOAD_PATH, Optional.empty(), jobName, jobId, taskName, storeName);
CompletionStage<Void> storeDeletionFuture = // delete files and sub-dirs previously marked for removal
blobStoreUtil.cleanUpDir(dirIndex, requestMetadata).thenComposeAsync(v -> blobStoreUtil.deleteDir(dirIndex, requestMetadata), // deleted files and dirs still present
executor).thenComposeAsync(v -> blobStoreUtil.deleteSnapshotIndexBlob(scmAndSnapshotIndex.getLeft(), requestMetadata), // delete the snapshot index blob
executor);
storeDeletionFutures.add(storeDeletionFuture);
}
});
FutureUtil.allOf(storeDeletionFutures).join();
}
use of org.apache.samza.config.BlobStoreConfig in project samza by apache.
the class BlobStoreStateBackendFactory method getRestoreManager.
@Override
public TaskRestoreManager getRestoreManager(JobContext jobContext, ContainerContext containerContext, TaskModel taskModel, ExecutorService restoreExecutor, MetricsRegistry metricsRegistry, Set<String> storesToRestore, Config config, Clock clock, File loggedStoreBaseDir, File nonLoggedStoreBaseDir, KafkaChangelogRestoreParams kafkaChangelogRestoreParams) {
BlobStoreConfig blobStoreConfig = new BlobStoreConfig(config);
String blobStoreManagerFactory = blobStoreConfig.getBlobStoreManagerFactory();
Preconditions.checkState(StringUtils.isNotBlank(blobStoreManagerFactory));
BlobStoreManagerFactory factory = ReflectionUtil.getObj(blobStoreManagerFactory, BlobStoreManagerFactory.class);
BlobStoreManager blobStoreManager = factory.getRestoreBlobStoreManager(config, restoreExecutor);
BlobStoreRestoreManagerMetrics metrics = new BlobStoreRestoreManagerMetrics(metricsRegistry);
return new BlobStoreRestoreManager(taskModel, restoreExecutor, storesToRestore, metrics, config, loggedStoreBaseDir, nonLoggedStoreBaseDir, new StorageManagerUtil(), blobStoreManager);
}
use of org.apache.samza.config.BlobStoreConfig in project samza by apache.
the class BlobStoreStateBackendFactory method getBackupManager.
@Override
public TaskBackupManager getBackupManager(JobContext jobContext, ContainerModel containerModel, TaskModel taskModel, ExecutorService backupExecutor, MetricsRegistry metricsRegistry, Config config, Clock clock, File loggedStoreBaseDir, File nonLoggedStoreBaseDir) {
BlobStoreConfig blobStoreConfig = new BlobStoreConfig(config);
String blobStoreManagerFactory = blobStoreConfig.getBlobStoreManagerFactory();
Preconditions.checkState(StringUtils.isNotBlank(blobStoreManagerFactory));
BlobStoreManagerFactory factory = ReflectionUtil.getObj(blobStoreManagerFactory, BlobStoreManagerFactory.class);
BlobStoreManager blobStoreManager = factory.getBackupBlobStoreManager(config, backupExecutor);
BlobStoreBackupManagerMetrics metrics = new BlobStoreBackupManagerMetrics(metricsRegistry);
return new BlobStoreBackupManager(jobContext.getJobModel(), containerModel, taskModel, backupExecutor, metrics, config, clock, loggedStoreBaseDir, new StorageManagerUtil(), blobStoreManager);
}
use of org.apache.samza.config.BlobStoreConfig in project samza by apache.
the class BlobStoreStateBackendFactory method getAdmin.
@Override
public StateBackendAdmin getAdmin(JobModel jobModel, Config config) {
BlobStoreConfig blobStoreConfig = new BlobStoreConfig(config);
String stateBackendAdminFactory = blobStoreConfig.getBlobStoreAdminFactory();
BlobStoreAdminFactory factory = ReflectionUtil.getObj(stateBackendAdminFactory, BlobStoreAdminFactory.class);
return factory.getStateBackendAdmin(config, jobModel);
}
Aggregations