Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void channelRead0(io.netty.channel.ChannelHandlerContext channelHandlerContext, PrepareStoreCopyRequest prepareStoreCopyRequest) throws java.io.IOException
        protected internal override void ChannelRead0(ChannelHandlerContext channelHandlerContext, PrepareStoreCopyRequest prepareStoreCopyRequest)
        {
            CloseablesListener       closeablesListener = new CloseablesListener();
            PrepareStoreCopyResponse response           = PrepareStoreCopyResponse.Error(PrepareStoreCopyResponse.Status.EListingStore);

            try
            {
                NeoStoreDataSource neoStoreDataSource = _dataSourceSupplier.get();
                if (!hasSameStoreId(prepareStoreCopyRequest.StoreId, neoStoreDataSource))
                {
                    channelHandlerContext.write(ResponseMessageType.PREPARE_STORE_COPY_RESPONSE);
                    response = PrepareStoreCopyResponse.Error(PrepareStoreCopyResponse.Status.EStoreIdMismatch);
                }
                else
                {
                    CheckPointer checkPointer = neoStoreDataSource.DependencyResolver.resolveDependency(typeof(CheckPointer));
                    closeablesListener.Add(TryCheckpointAndAcquireMutex(checkPointer));
                    PrepareStoreCopyFiles prepareStoreCopyFiles = closeablesListener.Add(_prepareStoreCopyFilesProvider.prepareStoreCopyFiles(neoStoreDataSource));

                    StoreResource[] nonReplayable = prepareStoreCopyFiles.AtomicFilesSnapshot;
                    foreach (StoreResource storeResource in nonReplayable)
                    {
                        _streamingProtocol.stream(channelHandlerContext, storeResource);
                    }
                    channelHandlerContext.write(ResponseMessageType.PREPARE_STORE_COPY_RESPONSE);
                    response = CreateSuccessfulResponse(checkPointer, prepareStoreCopyFiles);
                }
            }
            finally
            {
                channelHandlerContext.writeAndFlush(response).addListener(closeablesListener);
                _protocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
            }
        }
Beispiel #2
0
 protected internal override void channelRead0(ChannelHandlerContext channelHandlerContext, GetStoreFileRequest getStoreFileRequest)
 {
     _outerInstance.log.info("Received request for file %s", getStoreFileRequest.File().Name);
     outerInstance.incrementRequestCount(getStoreFileRequest.File());
     try
     {
         if (outerInstance.handleFileDoesNotExist(channelHandlerContext, getStoreFileRequest))
         {
             _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
             return;
         }
         outerInstance.handleFileExists(channelHandlerContext, getStoreFileRequest.File());
     }
     finally
     {
         _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
     }
 }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Object readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override object ReadChunk(ByteBufAllocator allocator)
        {
            Debug.Assert(!_endOfInput);

            if (_pending != null)
            {
                if (_noMoreTransactions)
                {
                    _endOfInput = true;
                }

                return(ConsumePending());
            }
            else if (_noMoreTransactions)
            {
                /* finalization should always have a last ending message */
                throw new System.InvalidOperationException();
            }
            else if (_txCursor.next())
            {
                Debug.Assert(_pending == null);

                CommittedTransactionRepresentation tx = _txCursor.get();
                _lastTxId = tx.CommitEntry.TxId;
                if (_lastTxId != _expectedTxId)
                {
                    string msg = format("Transaction cursor out of order. Expected %d but was %d", _expectedTxId, _lastTxId);
                    throw new System.InvalidOperationException(msg);
                }
                _expectedTxId++;
                _pending = new TxPullResponse(_storeId, tx);
                return(ResponseMessageType.TX);
            }
            else
            {
                Debug.Assert(_pending == null);

                _noMoreTransactions = true;
                _protocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
                CatchupResult result;
                if (_lastTxId >= _txIdPromise)
                {
                    result = SUCCESS_END_OF_STREAM;
                }
                else
                {
                    result = E_TRANSACTION_PRUNED;
                    _log.warn("Transaction cursor fell short. Expected at least %d but only got to %d.", _txIdPromise, _lastTxId);
                }
                _pending = new TxStreamFinishedResponse(result, _lastTxId);
                return(ResponseMessageType.TX_STREAM_FINISHED);
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _catchupServerProtocol = new CatchupServerProtocol();
            _catchupServerProtocol.expect(CatchupServerProtocol.State.GET_STORE_FILE);
            StoreCopyRequestHandler storeCopyRequestHandler = new NiceStoreCopyRequestHandler(this, _catchupServerProtocol, () => _neoStoreDataSource, new StoreFileStreamingProtocol(), _fileSystemAbstraction, NullLogProvider.Instance);
            Dependencies            dependencies            = new Dependencies();

            when(_neoStoreDataSource.StoreId).thenReturn(new Org.Neo4j.Storageengine.Api.StoreId(1, 2, 5, 3, 4));
            when(_neoStoreDataSource.DependencyResolver).thenReturn(dependencies);
            when(_neoStoreDataSource.DatabaseLayout).thenReturn(DatabaseLayout.of(new File(".")));
            _embeddedChannel = new EmbeddedChannel(storeCopyRequestHandler);
        }
Beispiel #5
0
        private PrepareStoreCopyRequestHandler CreateHandler()
        {
            _catchupServerProtocol = new CatchupServerProtocol();
            _catchupServerProtocol.expect(CatchupServerProtocol.State.PREPARE_STORE_COPY);
            System.Func <NeoStoreDataSource> dataSourceSupplier = () => _neoStoreDataSource;
            when(_neoStoreDataSource.StoreId).thenReturn(new Org.Neo4j.Storageengine.Api.StoreId(1, 2, 5, 3, 4));

            PrepareStoreCopyFilesProvider prepareStoreCopyFilesProvider = mock(typeof(PrepareStoreCopyFilesProvider));

            when(prepareStoreCopyFilesProvider.PrepareStoreCopyFiles(any())).thenReturn(_prepareStoreCopyFiles);

            return(new PrepareStoreCopyRequestHandler(_catchupServerProtocol, dataSourceSupplier, prepareStoreCopyFilesProvider));
        }
Beispiel #6
0
            protected internal override void channelRead0(ChannelHandlerContext channelHandlerContext, PrepareStoreCopyRequest prepareStoreCopyRequest)
            {
                channelHandlerContext.writeAndFlush(ResponseMessageType.PREPARE_STORE_COPY_RESPONSE);
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
                IList <File> list = _outerInstance.filesystem.Select(FakeFile::getFile).ToList();

                File[] files = new File[list.Count];
                files = list.toArray(files);
                long    transactionId = 123L;
                LongSet indexIds      = LongSets.immutable.of(13);

                channelHandlerContext.writeAndFlush(PrepareStoreCopyResponse.Success(files, indexIds, transactionId));
                _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
            }
Beispiel #7
0
                protected internal override void channelRead0(ChannelHandlerContext ctx, GetStoreFileRequest msg)
                {
                    // create the files and write the given content
                    File file     = new File(_outerInstance.fileName);
                    File fileCopy = new File(_outerInstance.copyFileName);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    string thisConent = _outerInstance.contents.next();

                    WriteContents(_outerInstance.outerInstance.fsa, file, thisConent);
                    WriteContents(_outerInstance.outerInstance.fsa, fileCopy, thisConent);

                    sendFile(ctx, file);
                    sendFile(ctx, fileCopy);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    StoreCopyFinishedResponse.Status status = _outerInstance.contents.hasNext() ? StoreCopyFinishedResponse.Status.EUnknown : StoreCopyFinishedResponse.Status.Success;
                    (new StoreFileStreamingProtocol()).End(ctx, status);
                    _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
                }
Beispiel #8
0
 protected internal override void channelRead0(ChannelHandlerContext channelHandlerContext, GetIndexFilesRequest snapshotRequest)
 {
     _outerInstance.log.info("Received request for index %s", snapshotRequest.IndexId());
     try
     {
         foreach (FakeFile indexFile in _outerInstance.indexFiles)
         {
             _outerInstance.log.info("FakeServer File %s does exist", indexFile.File);
             channelHandlerContext.writeAndFlush(ResponseMessageType.FILE);
             channelHandlerContext.writeAndFlush(new FileHeader(indexFile.File.Name));
             StoreResource storeResource = outerInstance.storeResourceFromEntry(indexFile.File);
             channelHandlerContext.writeAndFlush(new FileSender(storeResource));
         }
         (new StoreFileStreamingProtocol()).End(channelHandlerContext, StoreCopyFinishedResponse.Status.Success);
     }
     finally
     {
         _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
     }
 }
Beispiel #9
0
 protected internal override void channelRead0(ChannelHandlerContext ctx, PrepareStoreCopyRequest msg)
 {
     ctx.write(ResponseMessageType.PREPARE_STORE_COPY_RESPONSE);
     ctx.writeAndFlush(PrepareStoreCopyResponse.Success(new File[] { new File(_outerInstance.fileName) }, LongSets.immutable.empty(), 1));
     _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
 }
Beispiel #10
0
 protected internal override void ChannelRead0(ChannelHandlerContext ctx, GetStoreIdRequest msg)
 {
     ctx.writeAndFlush(ResponseMessageType.STORE_ID);
     ctx.writeAndFlush(_storeIdSupplier.get());
     _protocol.expect(State.MESSAGE_TYPE);
 }
Beispiel #11
0
 private void EndInteraction(ChannelHandlerContext ctx, CatchupResult status, long lastCommittedTransactionId)
 {
     ctx.write(ResponseMessageType.TX_STREAM_FINISHED);
     ctx.writeAndFlush(new TxStreamFinishedResponse(status, lastCommittedTransactionId));
     _protocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE);
 }