use of com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper in project atlasdb by palantir.
the class AtlasRestoreServiceTest method restoresToNewNamespaceCorrectly.
@Test
public void restoresToNewNamespaceCorrectly() {
RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(WITH_BACKUP).newNamespace(NO_BACKUP).build();
// prepare
DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(disabledNamespaces).containsExactly(NO_BACKUP);
// repair
BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
};
Set<Namespace> repairedNamespaces = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
assertThat(repairedNamespaces).containsExactly(NO_BACKUP);
verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
verifyNoMoreInteractions(cassandraRepairHelper);
// complete
CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP, completedBackup));
when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
Set<Namespace> completedNamespaces = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(completedNamespaces).containsExactly(NO_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper in project atlasdb by palantir.
the class AtlasRestoreService method create.
public static AtlasRestoreService create(AuthHeader authHeader, Refreshable<ServicesConfigBlock> servicesConfigBlock, String serviceName, BackupPersister backupPersister, Function<Namespace, CassandraKeyValueServiceConfig> keyValueServiceConfigFactory, Function<Namespace, KeyValueService> keyValueServiceFactory) {
DialogueClients.ReloadingFactory reloadingFactory = DialogueClients.create(servicesConfigBlock).withUserAgent(UserAgent.of(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT_AGENT));
AtlasRestoreClient atlasRestoreClient = new DialogueAdaptingAtlasRestoreClient(reloadingFactory.get(AtlasRestoreClientBlocking.class, serviceName));
TimeLockManagementService timeLockManagementService = new DialogueAdaptingTimeLockManagementService(reloadingFactory.get(TimeLockManagementServiceBlocking.class, serviceName));
CassandraRepairHelper cassandraRepairHelper = new CassandraRepairHelper(KvsRunner.create(keyValueServiceFactory), keyValueServiceConfigFactory);
return new AtlasRestoreService(authHeader, atlasRestoreClient, timeLockManagementService, backupPersister, cassandraRepairHelper);
}
use of com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper in project atlasdb by palantir.
the class AtlasRestoreService method create.
public static AtlasRestoreService create(AuthHeader authHeader, Refreshable<ServicesConfigBlock> servicesConfigBlock, String serviceName, BackupPersister backupPersister, Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFactory, Function<AtlasService, Refreshable<CassandraServersConfig>> refreshableCassandraServersConfigFactory, Function<AtlasService, KeyValueService> keyValueServiceFactory) {
DialogueClients.ReloadingFactory reloadingFactory = DialogueClients.create(servicesConfigBlock).withUserAgent(UserAgent.of(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT_AGENT));
AtlasRestoreClient atlasRestoreClient = new DialogueAdaptingAtlasRestoreClient(reloadingFactory.get(AtlasRestoreClientBlocking.class, serviceName));
TimeLockManagementService timeLockManagementService = new DialogueAdaptingTimeLockManagementService(reloadingFactory.get(TimeLockManagementServiceBlocking.class, serviceName));
CassandraRepairHelper cassandraRepairHelper = new CassandraRepairHelper(KvsRunner.create(keyValueServiceFactory), cassandraClusterConfigFactory, refreshableCassandraServersConfigFactory);
return new AtlasRestoreService(authHeader, atlasRestoreClient, timeLockManagementService, backupPersister, cassandraRepairHelper);
}
use of com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper in project atlasdb by palantir.
the class CassandraRepairEteTest method setUp.
@Before
public void setUp() {
int replicationFactor = 2;
config = ThreeNodeCassandraCluster.getKvsConfig();
runtimeConfig = ThreeNodeCassandraCluster.getRuntimeConfig(replicationFactor);
kvs = CassandraKeyValueServiceImpl.createForTesting(config, runtimeConfig);
TransactionTables.createTables(kvs);
kvs.createTable(TABLE_REF, AtlasDbConstants.GENERIC_TABLE_METADATA);
kvs.putUnlessExists(TABLE_REF, ImmutableMap.of(NONEMPTY_CELL, CONTENTS));
KvsRunner kvsRunner = KvsRunner.create(_unused -> kvs);
Function<AtlasService, CassandraKeyValueServiceConfig> configFactory = _unused -> config;
Function<AtlasService, Refreshable<CassandraKeyValueServiceRuntimeConfig>> runtimeConfigFactory = _unused -> runtimeConfig;
Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFunction = atlasService -> CassandraClusterConfig.of(configFactory.apply(atlasService), runtimeConfigFactory.apply(atlasService).get());
Function<AtlasService, Refreshable<CassandraServersConfig>> cassandraServersConfigFactory = runtimeConfigFactory.andThen(runtimeConfig -> runtimeConfig.map(CassandraKeyValueServiceRuntimeConfig::servers));
cassandraRepairHelper = new CassandraRepairHelper(kvsRunner, cassandraClusterConfigFunction, cassandraServersConfigFactory);
cluster = new ClusterFactory(Cluster::builder).constructCluster(cassandraClusterConfigFunction.apply(ATLAS_SERVICE), cassandraServersConfigFactory.apply(ATLAS_SERVICE).get());
cqlCluster = new CqlCluster(cluster, cassandraServersConfigFactory.apply(ATLAS_SERVICE).get(), NAMESPACE);
}
use of com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper in project atlasdb by palantir.
the class AtlasRestoreServiceTest method restoresToNewAtlasServiceCorrectly.
@Test
public void restoresToNewAtlasServiceCorrectly() {
RestoreRequest restoreRequest = RestoreRequest.builder().oldAtlasService(WITH_BACKUP).newAtlasService(NO_BACKUP).build();
// prepare
DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP_NS), BACKUP_ID);
when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
Set<AtlasService> disabledAtlasServices = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(disabledAtlasServices).containsExactly(NO_BACKUP);
// repair
BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
};
Set<AtlasService> repairedAtlasServices = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
assertThat(repairedAtlasServices).containsExactly(NO_BACKUP);
verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
verifyNoMoreInteractions(cassandraRepairHelper);
// complete
CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP_NS, completedBackup));
when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP_NS)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP_NS), BACKUP_ID);
Set<AtlasService> completedAtlasServices = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(completedAtlasServices).containsExactly(NO_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
Aggregations