Search in sources :

Example 11 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method rollsBackDisabledNamespacesAfterPartialFailure.

// Case A: start with no disabled namespaces; disable fails on some node; we should re-enable all
@Test
public void rollsBackDisabledNamespacesAfterPartialFailure() {
    Set<Namespace> failedNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    ReenableNamespacesRequest rollbackRequest = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
    verify(remote1).reenable(AUTH_HEADER, rollbackRequest);
    verify(remote2, never()).reenable(AUTH_HEADER, rollbackRequest);
    verify(localUpdater, never()).disable(any());
    assertThat(response).isEqualTo(partiallyDisabled(BOTH_NAMESPACES));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 12 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method reportsRollbackFailures.

@Test
public void reportsRollbackFailures() {
    Set<Namespace> failedNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    when(remote1.reenable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    verify(remote1).reenable(any(), any());
    verify(remote2, never()).reenable(any(), any());
    verify(localUpdater).getNamespacesLockedWithDifferentLockId(any(), any());
    verifyNoMoreInteractions(localUpdater);
    assertThat(response).isEqualTo(partiallyDisabled(failedNamespaces));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 13 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method handlesNodesBecomingUnreachableDuringDisable.

@Test
public void handlesNodesBecomingUnreachableDuringDisable() {
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenThrow(new SafeRuntimeException("unreachable"));
    when(remote2.reenable(any(), any())).thenThrow(new SafeRuntimeException("unreachable"));
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    // We don't know if the request succeeded or failed on remote2, so we should try our best to roll back
    verify(remote2).reenable(any(), any());
    verify(remote1).reenable(any(), any());
    // No known bad namespaces
    assertThat(response).isEqualTo(DISABLE_FAILED_SUCCESSFULLY);
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Test(org.junit.Test)

Example 14 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse 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);
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RunWith(org.junit.runner.RunWith) AuthHeader(com.palantir.tokens.auth.AuthHeader) ServiceId(com.palantir.atlasdb.backup.api.ServiceId) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) InOrder(org.mockito.InOrder) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Assertions.assertThatLoggableExceptionThrownBy(com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Example 15 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse in project atlasdb by palantir.

the class AtlasRestoreServiceTest method prepareRestoreFailsIfDisableFails.

@Test
public void prepareRestoreFailsIfDisableFails() {
    DisableNamespacesResponse failedDisable = DisableNamespacesResponse.unsuccessful(UnsuccessfulDisableNamespacesResponse.of(ImmutableSet.of(WITH_BACKUP_NS), ImmutableSet.of()));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(failedDisable);
    Set<AtlasService> disabledAtlasServices = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP), restoreRequest(NO_BACKUP)), BACKUP_ID);
    assertThat(disabledAtlasServices).isEmpty();
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Aggregations

DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)15 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)15 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)15 Test (org.junit.Test)14 Namespace (com.palantir.atlasdb.timelock.api.Namespace)10 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)7 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)5 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)3 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)3 ImmutableSingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse)3 SingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)3 Set (java.util.Set)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AtlasRestoreClient (com.palantir.atlasdb.backup.api.AtlasRestoreClient)2 CompleteRestoreResponse (com.palantir.atlasdb.backup.api.CompleteRestoreResponse)2 CassandraRepairHelper (com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper)2 RangesForRepair (com.palantir.atlasdb.cassandra.backup.RangesForRepair)2 TimeLockManagementService (com.palantir.atlasdb.timelock.api.management.TimeLockManagementService)2