Exemple #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);
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized int createToken(String name) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        public override int CreateToken(string name)
        {
            lock (this)
            {
                Kernel kernel = _kernelSupplier.get();
                using (Transaction tx = kernel.BeginTransaction(Transaction_Type.@implicit, LoginContext.AUTH_DISABLED))
                {
                    int id = CreateKey(tx, name);
                    tx.Success();
                    return(id);
                }
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void perform(io.netty.channel.ChannelHandlerContext ctx) throws java.io.IOException
        internal virtual void Perform(ChannelHandlerContext ctx)
        {
            CheckPointer checkPointer   = _checkPointerSupplier.get();
            Resource     checkPointLock = _mutex.storeCopy(() => checkPointer.TryCheckPoint(new SimpleTriggerInfo("Store copy")));

            Future <Void> completion = null;

            try
            {
                using (RawCursor <StoreResource, IOException> resources = _resourceStreamFactory.create())
                {
                    while (resources.Next())
                    {
                        StoreResource resource = resources.get();
                        _protocol.stream(ctx, resource);
                    }
                    completion = _protocol.end(ctx, SUCCESS);
                }
            }
            finally
            {
                if (completion != null)
                {
                    completion.addListener(f => checkPointLock.close());
                }
                else
                {
                    checkPointLock.Close();
                }
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void close() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        public override void Close()
        {
            _actual.close();
            try
            {
                using (IndexReader reader = _readerSupplier.get())
                {
                    foreach (ValueTuple tuple in _touchedTuples)
                    {
                        using (PrimitiveLongResourceIterator results = reader.Query(QueryOf(tuple)))
                        {
                            if (results.hasNext())
                            {
                                long firstEntityId = results.next();
                                if (results.hasNext())
                                {
                                    long secondEntityId = results.next();
                                    throw new IndexEntryConflictException(firstEntityId, secondEntityId, tuple);
                                }
                            }
                        }
                    }
                }
            }
            catch (IndexNotApplicableKernelException e)
            {
                throw new System.ArgumentException("Unexpectedly the index reader couldn't handle this query", e);
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.security.LoginContext authenticate(String username, String password) throws org.neo4j.kernel.api.security.exception.InvalidAuthTokenException
        private LoginContext Authenticate(string username, string password)
        {
            AuthManager authManager = _authManagerSupplier.get();
            IDictionary <string, object> authToken = newBasicAuthToken(username, !string.ReferenceEquals(password, null) ? UTF8.encode(password) : null);

            return(authManager.Login(authToken));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateLabelStoreScanOnNodeCommands() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateLabelStoreScanOnNodeCommands()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
            IndexBatchTransactionApplier applier = NewIndexTransactionApplier();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.record.NodeRecord before = new org.neo4j.kernel.impl.store.record.NodeRecord(11);
            NodeRecord before = new NodeRecord(11);

            before.SetLabelField(17, _emptyDynamicRecords);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.record.NodeRecord after = new org.neo4j.kernel.impl.store.record.NodeRecord(12);
            NodeRecord after = new NodeRecord(12);

            after.SetLabelField(18, _emptyDynamicRecords);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Command.NodeCommand command = new Command.NodeCommand(before, after);
            Command.NodeCommand command = new Command.NodeCommand(before, after);

            LabelScanWriter labelScanWriter = mock(typeof(LabelScanWriter));

            when(_labelScanStore.get()).thenReturn(labelScanWriter);

            // when
            bool result;

            using (TransactionApplier txApplier = applier.StartTx(_transactionToApply))
            {
                result = txApplier.VisitNodeCommand(command);
            }
            // then
            assertFalse(result);
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            _fs         = FileSystemRule.get();
            _pageCache  = PageCacheRule.getPageCache(_fs);
            _storeFiles = new StoreFiles(_fs, _pageCache);
            _logFiles   = LogFilesBuilder.logFilesBasedOnlyBuilder(TestDirectory.directory(), _fs).build();
        }
Exemple #8
0
        public override void Start()
        {
            _monitors.addMonitorListener(_listener);

            CheckPointerMonitor checkPointerMonitor = _checkPointerMonitorSupplier.get();

            _registry.register(CheckPointEvents, (Gauge <long>)checkPointerMonitor.numberOfCheckPointEvents);
            _registry.register(CheckPointTotalTime, (Gauge <long>)checkPointerMonitor.checkPointAccumulatedTotalTimeMillis);
        }
Exemple #9
0
        public override void Start()
        {
            StoreEntityCounters counters = _storeEntityCountersSupplier.get();

            _registry.register(CountsNode, (Gauge <long>)counters.nodes);
            _registry.register(CountsRelationship, (Gauge <long>)counters.relationships);
            _registry.register(CountsProperty, (Gauge <long>)counters.properties);
            _registry.register(CountsRelationshipType, (Gauge <long>)counters.relationshipTypes);
        }
Exemple #10
0
 public override void Run()
 {
     if (!DbHealthSupplier.get().Healthy)
     {
         CatchUpFuture.completeExceptionally(DbHealthSupplier.get().cause());
     }
     else if (IAmAVotingMember() && CaughtUpWithLeader())
     {
         CatchUpFuture.complete(true);
         outerInstance.monitor.JoinedRaftGroup();
     }
     else
     {
         outerInstance.currentCatchupDelayInMs += SECONDS.toMillis(1);
         long longerDelay = outerInstance.currentCatchupDelayInMs < outerInstance.maxCatchupLag ? outerInstance.currentCatchupDelayInMs : outerInstance.maxCatchupLag;
         outerInstance.jobScheduler.Schedule(Group.MEMBERSHIP_WAITER, this, longerDelay, MILLISECONDS);
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override public void bulk(@Nonnull Consumer<org.neo4j.logging.Log> consumer)
        public override void Bulk(Consumer <Log> consumer)
        {
            PrintWriter writer;

            lock (this)
            {
                writer = _writerSupplier.get();
                consumer.accept(new ConsistencyReportLog(Suppliers.singleton(writer), @lock, false));
            }
        }
Exemple #12
0
 // Must be called under synchronized on this
 private void Flush()
 {
     if (_chunkCursor > 0)
     {
         lock ( _chunks )
         {
             Chunk <T> chunkToAdd = new Chunk <T>(_thresholdSupplier.get(), copyOf(_chunk, _chunkCursor));
             _chunks.offer(chunkToAdd);
         }
         _chunkCursor = 0;
     }
 }
Exemple #13
0
 public override bool ExistsForNodes(string indexName)
 {
     try
     {
         _transactionBridge.get().indexRead().nodeExplicitIndexGetConfiguration(indexName);
         return(true);
     }
     catch (ExplicitIndexNotFoundKernelException)
     {
         return(false);
     }
 }
Exemple #14
0
        public override Index <Node> GetOrCreateNodeIndex(string indexName, IDictionary <string, string> customConfiguration)
        {
            KernelTransaction ktx = _transactionBridge.get();

            try
            {
                using (Statement ignore = ktx.AcquireStatement())
                {
                    if (!ktx.IndexRead().nodeExplicitIndexExists(indexName, customConfiguration))
                    {
                        // There's a sub-o-meta thing here where we create index config,
                        // and the index will itself share the same IndexConfigStore as us and pick up and use
                        // that. We should pass along config somehow with calls.
                        ktx.IndexWrite().nodeExplicitIndexCreateLazily(indexName, customConfiguration);
                    }
                    return(new ExplicitIndexProxy <Node>(indexName, ExplicitIndexProxy.NODE, _gds, _transactionBridge));
                }
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
        /// <param name="start"> the label of the start node of relationships to get the number of, or {@code null} for "any". </param>
        /// <param name="type">  the type of the relationships to get the number of, or {@code null} for "any". </param>
        /// <param name="end">   the label of the end node of relationships to get the number of, or {@code null} for "any". </param>
        private long CountsForRelationship(Label start, RelationshipType type, Label end)
        {
            KernelTransaction ktx = _ktxSupplier.get();

            using (Statement ignore = ktx.AcquireStatement())
            {
                TokenRead tokenRead = ktx.TokenRead();
                int       startId;
                int       typeId;
                int       endId;
                // start
                if (start == null)
                {
                    startId = [email protected]_Fields.ANY_LABEL;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (startId = tokenRead.NodeLabel(start.Name())))
                    {
                        return(0);
                    }
                }
                // type
                if (type == null)
                {
                    typeId = [email protected]_Fields.ANY_RELATIONSHIP_TYPE;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (typeId = tokenRead.RelationshipType(type.Name())))
                    {
                        return(0);
                    }
                }
                // end
                if (end == null)
                {
                    endId = [email protected]_Fields.ANY_LABEL;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (endId = tokenRead.NodeLabel(end.Name())))
                    {
                        return(0);
                    }
                }
                return(ktx.DataRead().countsForRelationship(startId, typeId, endId));
            }
        }
Exemple #16
0
        public override void Start()
        {
            _registry.register(TxStarted, (Gauge <long>)_transactionCounters.getNumberOfStartedTransactions);
            _registry.register(TxPeakConcurrent, (Gauge <long>)_transactionCounters.getPeakConcurrentNumberOfTransactions);

            _registry.register(TxActive, (Gauge <long>)_transactionCounters.getNumberOfActiveTransactions);
            _registry.register(ReadTxActive, (Gauge <long>)_transactionCounters.getNumberOfActiveReadTransactions);
            _registry.register(WriteTxActive, (Gauge <long>)_transactionCounters.getNumberOfActiveWriteTransactions);

            _registry.register(TxCommitted, (Gauge <long>)_transactionCounters.getNumberOfCommittedTransactions);
            _registry.register(ReadTxCommitted, (Gauge <long>)_transactionCounters.getNumberOfCommittedReadTransactions);
            _registry.register(WriteTxCommitted, (Gauge <long>)_transactionCounters.getNumberOfCommittedWriteTransactions);

            _registry.register(TxRollbacks, (Gauge <long>)_transactionCounters.getNumberOfRolledBackTransactions);
            _registry.register(ReadTxRollbacks, (Gauge <long>)_transactionCounters.getNumberOfRolledBackReadTransactions);
            _registry.register(WriteTxRollbacks, (Gauge <long>)_transactionCounters.getNumberOfRolledBackWriteTransactions);

            _registry.register(TxTerminated, (Gauge <long>)_transactionCounters.getNumberOfTerminatedTransactions);
            _registry.register(ReadTxTerminated, (Gauge <long>)_transactionCounters.getNumberOfTerminatedReadTransactions);
            _registry.register(WriteTxTerminated, (Gauge <long>)_transactionCounters.getNumberOfTerminatedWriteTransactions);

            _registry.register(LastCommittedTxId, (Gauge <long>)() => _transactionIdStore.get().LastCommittedTransactionId);
            _registry.register(LastClosedTxId, (Gauge <long>)() => _transactionIdStore.get().LastClosedTransactionId);
        }
        public override bool Next()
        {
            while (_current == null || _cursor >= _current.Length)
            {
                _current = _supplier.get();
                if (_current == null)
                {                         // End reached
                    return(false);
                }

                _cursor = 0;
            }
            _cursor++;
            return(true);
        }
Exemple #18
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());
                        }
                    }
                });
            }
        }
Exemple #19
0
        /// <param name="label"> the label to get the number of nodes of, or {@code null} to get the total number of nodes. </param>
        private long CountsForNode(Label label)
        {
            KernelTransaction transaction = _transactionSupplier.get();
            Read read = transaction.DataRead();
            int  labelId;

            if (label == null)
            {
                labelId = StatementConstants.ANY_LABEL;
            }
            else
            {
                if ([email protected]_Fields.NO_TOKEN == (labelId = transaction.TokenRead().nodeLabel(label.Name())))
                {
                    return(0);
                }
            }
            return(read.CountsForNode(labelId));
        }
Exemple #20
0
        public override void Send(MemberId to, RaftMessages_RaftMessage message, bool block)
        {
            Optional <ClusterId> clusterId = _clusterIdentity.get();

            if (!clusterId.Present)
            {
                _log.warn("Attempting to send a message before bound to a cluster");
                return;
            }

            Optional <CoreServerInfo> coreServerInfo = _coreTopologyService.localCoreServers().find(to);

            if (coreServerInfo.Present)
            {
                _outbound.send(coreServerInfo.get().RaftServer, Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage.of(clusterId.get(), message), block);
            }
            else
            {
                _unknownAddressMonitor.logAttemptToSendToMemberWithNoKnownAddress(to);
            }
        }
Exemple #21
0
        /// <summary>
        /// Performs a switch to the master state. Starts communication endpoints, switches components to the master state
        /// and broadcasts the appropriate Master Is Available event. </summary>
        /// <param name="haCommunicationLife"> The LifeSupport instance to register communication endpoints. </param>
        /// <param name="me"> The URI that the communication endpoints should bind to </param>
        /// <returns> The URI at which the master communication was bound. </returns>
//JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type:
        public virtual URI SwitchToMasterConflict(LifeSupport haCommunicationLife, URI me)
        {
            _userLog.info("I am %s, moving to master", MyId(_config));

            // Do not wait for currently active transactions to complete before continuing switching.
            // - A master in a cluster is very important, without it the cluster cannot process any write requests
            // - Awaiting open transactions to complete assumes that this instance just now was a slave that is
            //   switching to master, which means the previous master where these active transactions were hosted
            //   is no longer available so these open transactions cannot continue and complete anyway,
            //   so what's the point waiting for them?
            // - Read transactions may still be able to complete, but the correct response to failures in those
            //   is to have them throw transient error exceptions hinting that they should be retried,
            //   at which point they may get redirected to another instance, or to this instance if it has completed
            //   the switch until then.

            _idGeneratorFactory.switchToMaster();
            NeoStoreDataSource dataSource = _dataSourceSupplier.get();

            dataSource.AfterModeSwitch();

            Locks locks = dataSource.DependencyResolver.resolveDependency(typeof(Locks));
            ConversationManager conversationManager = ConversationManagerFactory.apply(locks);
            Master master = MasterFactory.apply(conversationManager, haCommunicationLife);

            MasterServer masterServer = MasterServerFactory.apply(master, conversationManager);

            haCommunicationLife.Add(masterServer);
            _masterDelegateHandler.Delegate = master;

            haCommunicationLife.Start();

            URI masterHaURI = GetMasterUri(me, masterServer, _config);

            _clusterMemberAvailability.memberIsAvailable(MASTER, masterHaURI, dataSource.StoreId);
            _userLog.info("I am %s, successfully moved to master", MyId(_config));

            _slaveFactorySupplier.get().StoreId = dataSource.StoreId;

            return(masterHaURI);
        }
Exemple #22
0
 public override void Apply <BUILDER>(NettyPipelineBuilder <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Server, BUILDER> nettyPipelineBuilder) where BUILDER : NettyPipelineBuilder <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Server, BUILDER>
 {
     nettyPipelineBuilder.Add(PipelineDecoderName, Decoder.get());
 }
 public override Root CatchupFrom(long fromId)
 {
     UpdateTripCount(fromId);
     AssertTripCount();
     return(_rootSupplier.get());
 }
Exemple #24
0
 private RecentK <string> ClientNames()
 {
     return(_userDataSupplier.get().get(UsageDataKeys.clientNames));
 }
Exemple #25
0
 private long CountsForNode()
 {
     return(_kernelTransactionSupplier.get().dataRead().countsForNode(StatementConstants.ANY_LABEL));
 }
Exemple #26
0
 internal virtual Type GenerateDefaultValue()
 {
     return(_defaultVal == null ? default(Type) : _defaultVal.get());
 }
Exemple #27
0
 public override void Start()
 {
     this._txIdStore = _txIdStoreSupplier.get();
 }
Exemple #28
0
        public override Slave NewSlave(LifeSupport life, ClusterMember clusterMember, string originHostNameOrIp, int originPort)
        {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            return(life.Add(new SlaveClient(clusterMember.InstanceId, clusterMember.HAUri.Host, clusterMember.HAUri.Port, originHostNameOrIp, _logProvider, _storeId, 2, _chunkSize, _monitors.newMonitor(typeof(ByteCounterMonitor), typeof(SlaveClient).FullName), _monitors.newMonitor(typeof(RequestMonitor), typeof(SlaveClient).FullName), _entryReader.get())));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToArchive(java.nio.file.Path archiveDestination, DiagnosticsReporterProgress progress) throws java.io.IOException
            public override void AddToArchive(Path archiveDestination, DiagnosticsReporterProgress progress)
            {
                string message = MessageSupplier.get();

                Files.write(archiveDestination, message.GetBytes(Encoding.UTF8), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
            }
Exemple #30
0
 public override void Init()
 {
     this._dataSource = new LuceneDataSource(_databaseLayout, _config, _indexStore.get(), _fileSystemAbstraction, _operationalMode);
     this._dataSource.init();
 }