Search in sources :

Example 6 with StoreId

use of org.neo4j.kernel.impl.store.StoreId in project neo4j by neo4j.

the class BackupProtocolTest method shouldGatherForensicsInFullBackupRequest.

private void shouldGatherForensicsInFullBackupRequest(boolean forensics) throws Exception {
    // GIVEN
    Response<Void> response = Response.EMPTY;
    StoreId storeId = response.getStoreId();
    String host = "localhost";
    int port = BackupServer.DEFAULT_PORT;
    LifeSupport life = new LifeSupport();
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    BackupClient client = life.add(new BackupClient(host, port, null, NullLogProvider.getInstance(), storeId, 10_000, mock(ResponseUnpacker.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), reader));
    ControlledBackupInterface backup = new ControlledBackupInterface();
    life.add(new BackupServer(backup, new HostnamePort(host, port), NullLogProvider.getInstance(), mock(ByteCounterMonitor.class), mock(RequestMonitor.class)));
    life.start();
    try {
        // WHEN
        StoreWriter writer = mock(StoreWriter.class);
        client.fullBackup(writer, forensics);
        // THEN
        assertEquals(forensics, backup.receivedForensics);
    } finally {
        life.shutdown();
    }
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) StoreId(org.neo4j.kernel.impl.store.StoreId) StoreWriter(org.neo4j.com.storecopy.StoreWriter) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)

Example 7 with StoreId

use of org.neo4j.kernel.impl.store.StoreId in project neo4j by neo4j.

the class SwitchToSlave method checkMyStoreIdAndMastersStoreId.

void checkMyStoreIdAndMastersStoreId(StoreId myStoreId, URI masterUri, DependencyResolver resolver) {
    ClusterMembers clusterMembers = resolver.resolveDependency(ClusterMembers.class);
    InstanceId serverId = HighAvailabilityModeSwitcher.getServerId(masterUri);
    Iterable<ClusterMember> members = clusterMembers.getMembers();
    ClusterMember master = firstOrNull(filter(hasInstanceId(serverId), members));
    if (master == null) {
        throw new IllegalStateException("Cannot find the master among " + members + " with master serverId=" + serverId + " and uri=" + masterUri);
    }
    StoreId masterStoreId = master.getStoreId();
    if (!myStoreId.equals(masterStoreId)) {
        throw new MismatchingStoreIdException(myStoreId, master.getStoreId());
    } else if (!myStoreId.equalsByUpgradeId(master.getStoreId())) {
        throw new BranchedDataException("My store with " + myStoreId + " was updated independently from " + "master's store " + masterStoreId);
    }
}
Also used : ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) StoreId(org.neo4j.kernel.impl.store.StoreId) InstanceId(org.neo4j.cluster.InstanceId) ClusterMembers.hasInstanceId(org.neo4j.kernel.ha.cluster.member.ClusterMembers.hasInstanceId) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException)

Example 8 with StoreId

use of org.neo4j.kernel.impl.store.StoreId in project neo4j by neo4j.

the class MasterEpochTest method shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch.

@Test
public void shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch() throws Throwable {
    // GIVEN
    SPI spi = MasterImplTest.mockedSpi();
    IdAllocation servedIdAllocation = idAllocation(0, 999);
    when(spi.allocateIds(any(IdType.class))).thenReturn(servedIdAllocation);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(10L);
    StoreId storeId = newStoreIdForCurrentVersion();
    MasterImpl master = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1")));
    HandshakeResult handshake = master.handshake(1, storeId).response();
    master.start();
    // WHEN/THEN
    IdAllocation idAllocation = master.allocateIds(context(handshake.epoch()), IdType.NODE).response();
    assertEquals(servedIdAllocation.getHighestIdInUse(), idAllocation.getHighestIdInUse());
    try {
        master.allocateIds(context(handshake.epoch() + 1), IdType.NODE);
        fail("Should fail with invalid epoch");
    } catch (InvalidEpochException e) {
    // Good
    }
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) StoreId(org.neo4j.kernel.impl.store.StoreId) ConversationManager(org.neo4j.kernel.ha.com.master.ConversationManager) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) IdType(org.neo4j.kernel.impl.store.id.IdType) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 9 with StoreId

use of org.neo4j.kernel.impl.store.StoreId in project neo4j by neo4j.

the class SwitchToSlaveBranchThenCopyTest method shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId.

@Test
@SuppressWarnings("unchecked")
public void shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId() throws Throwable {
    // Given
    SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
    URI me = new URI("cluster://localhost?serverId=2");
    MasterClient masterClient = mock(MasterClient.class);
    Response<HandshakeResult> response = mock(Response.class);
    when(response.response()).thenReturn(new HandshakeResult(1, 2));
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
    StoreId storeId = newStoreIdForCurrentVersion(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
    // When
    try {
        switchToSlave.checkDataConsistency(masterClient, transactionIdStore, storeId, new URI("cluster://localhost?serverId=1"), me, CancellationRequest.NEVER_CANCELLED);
        fail("Should have thrown " + MismatchingStoreIdException.class.getSimpleName() + " exception");
    } catch (MismatchingStoreIdException e) {
    // good we got the expected exception
    }
    // Then
    verify(switchToSlave).stopServicesAndHandleBranchedStore(any(BranchedDataPolicy.class));
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.kernel.impl.store.StoreId) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) URI(java.net.URI) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Test(org.junit.Test)

Example 10 with StoreId

use of org.neo4j.kernel.impl.store.StoreId in project neo4j by neo4j.

the class SwitchToSlaveBranchThenCopyTest method newSwitchToSlaveSpy.

@SuppressWarnings("unchecked")
private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) throws IOException {
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    ClusterMember master = mock(ClusterMember.class);
    when(master.getStoreId()).thenReturn(storeId);
    when(master.getHARole()).thenReturn(HighAvailabilityModeSwitcher.MASTER);
    when(master.hasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
    when(master.getInstanceId()).thenReturn(new InstanceId(1));
    when(clusterMembers.getMembers()).thenReturn(singletonList(master));
    Dependencies resolver = new Dependencies();
    resolver.satisfyDependencies(requestContextFactory, clusterMembers, mock(TransactionObligationFulfiller.class), mock(OnlineBackupKernelExtension.class), mock(IndexConfigStore.class), mock(TransactionCommittingResponseUnpacker.class), mock(DataSourceManager.class), mock(StoreLockerLifecycleAdapter.class), mock(FileSystemWatcherService.class));
    NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
    when(dataSource.getStoreId()).thenReturn(storeId);
    TransactionStats transactionCounters = mock(TransactionStats.class);
    when(transactionCounters.getNumberOfActiveTransactions()).thenReturn(0L);
    Response<HandshakeResult> response = mock(Response.class);
    when(response.response()).thenReturn(new HandshakeResult(42, 2));
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
    when(masterClient.getProtocolVersion()).thenReturn(MasterClient320.PROTOCOL_VERSION);
    TransactionIdStore transactionIdStoreMock = mock(TransactionIdStore.class);
    // note that the checksum (the second member of the array) is the same as the one in the handshake mock above
    when(transactionIdStoreMock.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    MasterClientResolver masterClientResolver = mock(MasterClientResolver.class);
    when(masterClientResolver.instantiate(anyString(), anyInt(), anyString(), any(Monitors.class), any(StoreId.class), any(LifeSupport.class))).thenReturn(masterClient);
    return spy(new SwitchToSlaveBranchThenCopy(new File(""), NullLogService.getInstance(), configMock(), resolver, mock(HaIdGeneratorFactory.class), mock(DelegateInvocationHandler.class), mock(ClusterMemberAvailability.class), requestContextFactory, pullerFactory, masterClientResolver, mock(SwitchToSlave.Monitor.class), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave -> {
        SlaveServer server = mock(SlaveServer.class);
        InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);
        when(server.getSocketAddress()).thenReturn(inetSocketAddress);
        return server;
    }, updatePuller, pageCacheMock, mock(Monitors.class), transactionCounters));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) StoreId(org.neo4j.kernel.impl.store.StoreId) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) Suppliers(org.neo4j.function.Suppliers) URISyntaxException(java.net.URISyntaxException) OnlineBackupKernelExtension(org.neo4j.backup.OnlineBackupKernelExtension) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) NullLogProvider(org.neo4j.logging.NullLogProvider) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) Collections.singletonList(java.util.Collections.singletonList) StoreIdTestFactory.newStoreIdForCurrentVersion(org.neo4j.com.StoreIdTestFactory.newStoreIdForCurrentVersion) HighAvailabilityModeSwitcher(org.neo4j.kernel.ha.cluster.modeswitch.HighAvailabilityModeSwitcher) Mockito.doThrow(org.mockito.Mockito.doThrow) TransactionObligationFulfiller(org.neo4j.com.storecopy.TransactionObligationFulfiller) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Matchers.anyInt(org.mockito.Matchers.anyInt) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) Response(org.neo4j.com.Response) PageCache(org.neo4j.io.pagecache.PageCache) InetSocketAddress(java.net.InetSocketAddress) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) Matchers.any(org.mockito.Matchers.any) Stream(java.util.stream.Stream) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) Mockito.withSettings(org.mockito.Mockito.withSettings) RequestContextFactory(org.neo4j.kernel.ha.com.RequestContextFactory) SlaveUpdatePuller(org.neo4j.kernel.ha.SlaveUpdatePuller) Mockito.mock(org.mockito.Mockito.mock) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) PagedFile(org.neo4j.io.pagecache.PagedFile) Monitors(org.neo4j.kernel.monitoring.Monitors) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Mockito.spy(org.mockito.Mockito.spy) PullerFactory(org.neo4j.kernel.ha.PullerFactory) Matchers.anyString(org.mockito.Matchers.anyString) TransactionId(org.neo4j.kernel.impl.store.TransactionId) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) StoreLockerLifecycleAdapter(org.neo4j.kernel.internal.StoreLockerLifecycleAdapter) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) HaIdGeneratorFactory(org.neo4j.kernel.ha.id.HaIdGeneratorFactory) CancellationRequest(org.neo4j.helpers.CancellationRequest) Matchers.anyLong(org.mockito.Matchers.anyLong) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) Mockito.never(org.mockito.Mockito.never) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Assert.assertNull(org.junit.Assert.assertNull) ClusterSettings(org.neo4j.cluster.ClusterSettings) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) FileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService) MasterClient320(org.neo4j.kernel.ha.MasterClient320) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) TransactionObligationFulfiller(org.neo4j.com.storecopy.TransactionObligationFulfiller) InetSocketAddress(java.net.InetSocketAddress) OnlineBackupKernelExtension(org.neo4j.backup.OnlineBackupKernelExtension) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) StoreId(org.neo4j.kernel.impl.store.StoreId) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Dependencies(org.neo4j.kernel.impl.util.Dependencies) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) InstanceId(org.neo4j.cluster.InstanceId) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionId(org.neo4j.kernel.impl.store.TransactionId) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) FileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService) Monitors(org.neo4j.kernel.monitoring.Monitors) StoreLockerLifecycleAdapter(org.neo4j.kernel.internal.StoreLockerLifecycleAdapter) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

Aggregations

StoreId (org.neo4j.kernel.impl.store.StoreId)15 Test (org.junit.Test)10 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)10 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)8 URI (java.net.URI)7 TransactionId (org.neo4j.kernel.impl.store.TransactionId)7 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)7 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)6 IOException (java.io.IOException)5 InstanceId (org.neo4j.cluster.InstanceId)5 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)5 MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)5 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)4 File (java.io.File)3 InetSocketAddress (java.net.InetSocketAddress)3 Response (org.neo4j.com.Response)3 CancellationRequest (org.neo4j.helpers.CancellationRequest)3 ClusterMember (org.neo4j.kernel.ha.cluster.member.ClusterMember)3 ClusterMembers (org.neo4j.kernel.ha.cluster.member.ClusterMembers)3 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)3