Пример #1
0
        private static ChildInitializer ChildInitializer(FileSystemAbstraction fileSystem, GraphDatabaseAPI graphDb)
        {
            ApplicationSupportedProtocols catchupProtocols  = new ApplicationSupportedProtocols(CATCHUP, emptyList());
            ModifierSupportedProtocols    modifierProtocols = new ModifierSupportedProtocols(COMPRESSION, emptyList());

            ApplicationProtocolRepository catchupRepository  = new ApplicationProtocolRepository(Protocol_ApplicationProtocols.values(), catchupProtocols);
            ModifierProtocolRepository    modifierRepository = new ModifierProtocolRepository(Protocol_ModifierProtocols.values(), singletonList(modifierProtocols));

            System.Func <CheckPointer>       checkPointer = () => graphDb.DependencyResolver.resolveDependency(typeof(CheckPointer));
            System.Func <bool>               availability = () => graphDb.DependencyResolver.resolveDependency(typeof(DatabaseAvailabilityGuard)).Available;
            System.Func <NeoStoreDataSource> dataSource   = () => graphDb.DependencyResolver.resolveDependency(typeof(NeoStoreDataSource));
            LogProvider logProvider = NullLogProvider.Instance;

            Org.Neo4j.Storageengine.Api.StoreId kernelStoreId = dataSource().StoreId;
            StoreId storeId = new StoreId(kernelStoreId.CreationTime, kernelStoreId.RandomId, kernelStoreId.UpgradeTime, kernelStoreId.UpgradeId);

            CheckPointerService         checkPointerService  = new CheckPointerService(checkPointer, createInitialisedScheduler(), Group.CHECKPOINT);
            RegularCatchupServerHandler catchupServerHandler = new RegularCatchupServerHandler(new Monitors(), logProvider, () => storeId, dataSource, availability, fileSystem, null, checkPointerService);

            NettyPipelineBuilderFactory pipelineBuilder = new NettyPipelineBuilderFactory(VoidPipelineWrapperFactory.VOID_WRAPPER);

            CatchupProtocolServerInstaller.Factory catchupProtocolServerInstaller = new CatchupProtocolServerInstaller.Factory(pipelineBuilder, logProvider, catchupServerHandler);

            ProtocolInstallerRepository <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Server> protocolInstallerRepository = new ProtocolInstallerRepository <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Server>(singletonList(catchupProtocolServerInstaller), Org.Neo4j.causalclustering.protocol.ModifierProtocolInstaller_Fields.AllServerInstallers);

            return(new HandshakeServerInitializer(catchupRepository, modifierRepository, protocolInstallerRepository, pipelineBuilder, logProvider));
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetLastPulledTransactionId() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSetLastPulledTransactionId()
        {
            // given
            long    lastFlushedTxId           = 12;
            StoreId wantedStoreId             = new StoreId(1, 2, 3, 4);
            AdvertisedSocketAddress localhost = new AdvertisedSocketAddress("127.0.0.1", 1234);
            CatchupAddressProvider  catchupAddressProvider = CatchupAddressProvider.fromSingleAddress(localhost);

            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));

            when(storeCopyClient.CopyStoreFiles(eq(catchupAddressProvider), eq(wantedStoreId), any(typeof(StoreFileStreamProvider)), any(), any())).thenReturn(lastFlushedTxId);

            TxPullClient txPullClient = mock(typeof(TxPullClient));

            when(txPullClient.PullTransactions(eq(localhost), eq(wantedStoreId), anyLong(), any())).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));

            TransactionLogCatchUpWriter writer = mock(typeof(TransactionLogCatchUpWriter));

            RemoteStore remoteStore = new RemoteStore(NullLogProvider.Instance, mock(typeof(FileSystemAbstraction)), null, storeCopyClient, txPullClient, Factory(writer), Config.defaults(), new Monitors());

            // when
            remoteStore.Copy(catchupAddressProvider, wantedStoreId, DatabaseLayout.of(new File("destination")), true);

            // then
            long previousTxId = lastFlushedTxId - 1;               // the interface is defined as asking for the one preceding

            verify(txPullClient).pullTransactions(eq(localhost), eq(wantedStoreId), eq(previousTxId), any());
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseDownTxLogWriterIfTxStreamingFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseDownTxLogWriterIfTxStreamingFails()
        {
            // given
            StoreId                     storeId                = new StoreId(1, 2, 3, 4);
            StoreCopyClient             storeCopyClient        = mock(typeof(StoreCopyClient));
            TxPullClient                txPullClient           = mock(typeof(TxPullClient));
            TransactionLogCatchUpWriter writer                 = mock(typeof(TransactionLogCatchUpWriter));
            CatchupAddressProvider      catchupAddressProvider = CatchupAddressProvider.fromSingleAddress(null);

            RemoteStore remoteStore = new RemoteStore(NullLogProvider.Instance, mock(typeof(FileSystemAbstraction)), null, storeCopyClient, txPullClient, Factory(writer), Config.defaults(), new Monitors());

            doThrow(typeof(CatchUpClientException)).when(txPullClient).pullTransactions(Null, eq(storeId), anyLong(), any());

            // when
            try
            {
                remoteStore.Copy(catchupAddressProvider, storeId, DatabaseLayout.of(new File(".")), true);
            }
            catch (StoreCopyFailedException)
            {
                // expected
            }

            // then
            verify(writer).close();
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tryCatchingUpDelegatesToRemoteStore() throws org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException, java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TryCatchingUpDelegatesToRemoteStore()
        {
            // given
            AdvertisedSocketAddress fromAddress = new AdvertisedSocketAddress("neo4j.com", 5432);
            StoreId        expectedStoreId      = new StoreId(7, 2, 5, 98);
            DatabaseLayout databaseLayout       = DatabaseLayout.of(new File("."));

            // when
            Subject.tryCatchingUp(fromAddress, expectedStoreId, databaseLayout);

            // then
            verify(_remoteStore).tryCatchingUp(fromAddress, expectedStoreId, databaseLayout, true, true);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void storeIdIsTransmitted()
        public virtual void StoreIdIsTransmitted()
        {
            // given store id requests transmit store id
            StoreId storeId = new StoreId(1, 2, 3, 4);
            PrepareStoreCopyRequest prepareStoreCopyRequest = new PrepareStoreCopyRequest(storeId);

            // when transmitted
            SendToChannel(prepareStoreCopyRequest, EmbeddedChannel);

            // then it can be received/deserialised
            PrepareStoreCopyRequest prepareStoreCopyRequestRead = EmbeddedChannel.readInbound();

            assertEquals(prepareStoreCopyRequest.StoreId, prepareStoreCopyRequestRead.StoreId);
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotOverwriteNonEmptyMismatchingStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotOverwriteNonEmptyMismatchingStore()
        {
            // given
            when(_localDatabase.Empty).thenReturn(false);
            StoreId remoteStoreId = new StoreId(5, 6, 7, 8);

            when(_remoteStore.getStoreId(_remoteAddress)).thenReturn(remoteStoreId);

            // when
            assertFalse(_downloader.downloadSnapshot(_catchupAddressProvider));

            // then
            verify(_remoteStore, never()).copy(any(), any(), any(), anyBoolean());
            verify(_remoteStore, never()).tryCatchingUp(any(), any(), any(), anyBoolean(), anyBoolean());
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDownloadCompleteStoreWhenEmpty() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDownloadCompleteStoreWhenEmpty()
        {
            // given
            StoreId remoteStoreId = new StoreId(5, 6, 7, 8);

            when(_remoteStore.getStoreId(_remoteAddress)).thenReturn(remoteStoreId);
            when(_localDatabase.Empty).thenReturn(true);

            // when
            _downloader.downloadSnapshot(_catchupAddressProvider);

            // then
            verify(_remoteStore, never()).tryCatchingUp(any(), any(), any(), anyBoolean(), anyBoolean());
            verify(_storeCopyProcess).replaceWithStoreFrom(_catchupAddressProvider, remoteStoreId);
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStreamTxEntriesIfStoreIdMismatches() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotStreamTxEntriesIfStoreIdMismatches()
        {
            // given
            StoreId serverStoreId = new StoreId(1, 2, 3, 4);
            StoreId clientStoreId = new StoreId(5, 6, 7, 8);

            TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () => serverStoreId, () => true, () => _datasource, new Monitors(), _logProvider);

            // when
            txPullRequestHandler.ChannelRead0(_context, new TxPullRequest(1, clientStoreId));

            // then
            verify(_context).write(ResponseMessageType.TX_STREAM_FINISHED);
            verify(_context).writeAndFlush(new TxStreamFinishedResponse(E_STORE_ID_MISMATCH, 15L));
            _logProvider.assertAtLeastOnce(inLog(typeof(TxPullRequestHandler)).info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", 2L, clientStoreId, serverStoreId));
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void fetchStoreIdDelegatesToStoreCopyClient() throws org.neo4j.causalclustering.catchup.storecopy.StoreIdDownloadFailedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FetchStoreIdDelegatesToStoreCopyClient()
        {
            // given
            AdvertisedSocketAddress fromAddress = new AdvertisedSocketAddress("neo4.com", 935);

            // and
            StoreId expectedStoreId = new StoreId(6, 2, 9, 3);

            when(_storeCopyClient.fetchStoreId(fromAddress)).thenReturn(expectedStoreId);

            // when
            StoreId storeId = Subject.fetchStoreId(fromAddress);

            // then
            assertEquals(expectedStoreId, storeId);
        }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, final TxPullRequest msg) throws Exception
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        protected internal override void ChannelRead0(ChannelHandlerContext ctx, TxPullRequest msg)
        {
            _monitor.increment();

            if (msg.PreviousTxId() <= 0)
            {
                _log.error("Illegal tx pull request");
                EndInteraction(ctx, E_INVALID_REQUEST, -1);
                return;
            }

            StoreId localStoreId    = _storeIdSupplier.get();
            StoreId expectedStoreId = msg.ExpectedStoreId();

            long firstTxId = msg.PreviousTxId() + 1;

            /*
             * This is the minimum transaction id we must send to consider our streaming operation successful. The kernel can
             * concurrently prune even future transactions while iterating and the cursor will silently fail on iteration, so
             * we need to add our own protection for this reason and also as a generally important sanity check for the fulfillment
             * of the consistent recovery contract which requires us to stream transactions at least as far as the time when the
             * file copy operation completed.
             */
            long txIdPromise = _transactionIdStore.LastCommittedTransactionId;
            IOCursor <CommittedTransactionRepresentation> txCursor = GetCursor(txIdPromise, ctx, firstTxId, localStoreId, expectedStoreId);

            if (txCursor != null)
            {
                ChunkedTransactionStream txStream = new ChunkedTransactionStream(_log, localStoreId, firstTxId, txIdPromise, txCursor, _protocol);
                // chunked transaction stream ends the interaction internally and closes the cursor
                ctx.writeAndFlush(txStream).addListener(f =>
                {
                    if (_log.DebugEnabled || !f.Success)
                    {
                        string message = format("Streamed transactions [%d--%d] to %s", firstTxId, txStream.LastTxId(), ctx.channel().remoteAddress());
                        if (f.Success)
                        {
                            _log.debug(message);
                        }
                        else
                        {
                            _log.warn(message, f.cause());
                        }
                    }
                });
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void retrieveStoreDelegatesToStoreCopyService() throws org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException, org.neo4j.causalclustering.catchup.CatchupAddressResolutionException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RetrieveStoreDelegatesToStoreCopyService()
        {
            // given
            StoreId        storeId        = new StoreId(92, 5, 7, 32);
            DatabaseLayout databaseLayout = DatabaseLayout.of(new File("."));

            // when
            Subject.copy(_anyAddress, storeId, databaseLayout);

            // then
            ArgumentCaptor <CatchupAddressProvider> argumentCaptor = ArgumentCaptor.forClass(typeof(CatchupAddressProvider));

            verify(_remoteStore).copy(argumentCaptor.capture(), eq(storeId), eq(databaseLayout), eq(true));

            //and
            assertEquals(_anyAddress, argumentCaptor.Value.primary());
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCopyStoreFilesAndPullTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCopyStoreFilesAndPullTransactions()
        {
            // given
            StoreId         storeId         = new StoreId(1, 2, 3, 4);
            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));
            TxPullClient    txPullClient    = mock(typeof(TxPullClient));

            when(txPullClient.PullTransactions(any(), any(), anyLong(), any())).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
            TransactionLogCatchUpWriter writer = mock(typeof(TransactionLogCatchUpWriter));

            RemoteStore remoteStore = new RemoteStore(NullLogProvider.Instance, mock(typeof(FileSystemAbstraction)), null, storeCopyClient, txPullClient, Factory(writer), Config.defaults(), new Monitors());

            // when
            AdvertisedSocketAddress localhost = new AdvertisedSocketAddress("127.0.0.1", 1234);
            CatchupAddressProvider  catchupAddressProvider = CatchupAddressProvider.fromSingleAddress(localhost);

            remoteStore.Copy(catchupAddressProvider, storeId, DatabaseLayout.of(new File("destination")), true);

            // then
            verify(storeCopyClient).copyStoreFiles(eq(catchupAddressProvider), eq(storeId), any(typeof(StoreFileStreamProvider)), any(), any());
            verify(txPullClient).pullTransactions(eq(localhost), eq(storeId), anyLong(), any());
        }
Пример #13
0
 internal static bool HasSameStoreId(StoreId storeId, NeoStoreDataSource dataSource)
 {
     return(storeId.EqualToKernelStoreId(dataSource.StoreId));
 }
Пример #14
0
 internal GetStoreIdResponse(StoreId storeId)
 {
     this._storeId = storeId;
 }
Пример #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void copy(org.neo4j.helpers.AdvertisedSocketAddress fromAddress, org.neo4j.causalclustering.identity.StoreId expectedStoreId, org.neo4j.io.layout.DatabaseLayout databaseLayout) throws org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException
        internal virtual void Copy(AdvertisedSocketAddress fromAddress, StoreId expectedStoreId, DatabaseLayout databaseLayout)
        {
            _remoteStore.copy(new Org.Neo4j.causalclustering.catchup.CatchupAddressProvider_SingleAddressProvider(fromAddress), expectedStoreId, databaseLayout, true);
        }
Пример #16
0
        private Fallible <BackupStageOutcome> Catchup(AdvertisedSocketAddress fromAddress, StoreId storeId, DatabaseLayout databaseLayout)
        {
            CatchupResult catchupResult;

            try
            {
                catchupResult = _backupDelegator.tryCatchingUp(fromAddress, storeId, databaseLayout);
            }
            catch (StoreCopyFailedException e)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, e));
            }
            if (catchupResult == CatchupResult.SUCCESS_END_OF_STREAM)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Success, null));
            }
            return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, new StoreCopyFailedException("End state of catchup was not a successful end of stream")));
        }
Пример #17
0
 public TxPullRequest(long previousTxId, StoreId expectedStoreId)
 {
     this._previousTxId    = previousTxId;
     this._expectedStoreId = expectedStoreId;
 }
Пример #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.cursor.IOCursor<org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation> getCursor(long txIdPromise, io.netty.channel.ChannelHandlerContext ctx, long firstTxId, org.neo4j.causalclustering.identity.StoreId localStoreId, org.neo4j.causalclustering.identity.StoreId expectedStoreId) throws java.io.IOException
        private IOCursor <CommittedTransactionRepresentation> GetCursor(long txIdPromise, ChannelHandlerContext ctx, long firstTxId, StoreId localStoreId, StoreId expectedStoreId)
        {
            if (localStoreId == null || !localStoreId.Equals(expectedStoreId))
            {
                _log.info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", firstTxId, expectedStoreId, localStoreId);
                EndInteraction(ctx, E_STORE_ID_MISMATCH, txIdPromise);
                return(null);
            }
            else if (!_databaseAvailable.AsBoolean)
            {
                _log.info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", firstTxId);
                EndInteraction(ctx, E_STORE_UNAVAILABLE, txIdPromise);
                return(null);
            }
            else if (txIdPromise < firstTxId)
            {
                EndInteraction(ctx, SUCCESS_END_OF_STREAM, txIdPromise);
                return(null);
            }

            try
            {
                return(_logicalTransactionStore.getTransactions(firstTxId));
            }
            catch (NoSuchTransactionException)
            {
                _log.info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", firstTxId);
                EndInteraction(ctx, E_TRANSACTION_PRUNED, txIdPromise);
                return(null);
            }
        }
Пример #19
0
 public PrepareStoreCopyRequest(StoreId expectedStoreId)
 {
     this._storeId = expectedStoreId;
 }
Пример #20
0
 public TxPullResponse(StoreId storeId, CommittedTransactionRepresentation tx)
 {
     this._storeId = storeId;
     this._tx      = tx;
 }
Пример #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.neo4j.causalclustering.catchup.CatchupResult tryCatchingUp(org.neo4j.helpers.AdvertisedSocketAddress fromAddress, org.neo4j.causalclustering.identity.StoreId expectedStoreId, org.neo4j.io.layout.DatabaseLayout databaseLayout) throws org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException
        internal virtual CatchupResult TryCatchingUp(AdvertisedSocketAddress fromAddress, StoreId expectedStoreId, DatabaseLayout databaseLayout)
        {
            try
            {
                return(_remoteStore.tryCatchingUp(fromAddress, expectedStoreId, databaseLayout, true, true));
            }
            catch (IOException e)
            {
                throw new StoreCopyFailedException(e);
            }
        }
Пример #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.catchup.TxPullRequestResult pullTransactions(org.neo4j.helpers.AdvertisedSocketAddress fromAddress, org.neo4j.causalclustering.identity.StoreId storeId, long previousTxId, TxPullResponseListener txPullResponseListener) throws org.neo4j.causalclustering.catchup.CatchUpClientException
        public virtual TxPullRequestResult PullTransactions(AdvertisedSocketAddress fromAddress, StoreId storeId, long previousTxId, TxPullResponseListener txPullResponseListener)
        {
            _pullRequestMonitor.txPullRequest(previousTxId);
            return(_catchUpClient.makeBlockingRequest(fromAddress, new TxPullRequest(previousTxId, storeId), new CatchUpResponseAdaptorAnonymousInnerClass(this, previousTxId, txPullResponseListener)));
        }