Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean executeConsistencyChecks(org.neo4j.kernel.impl.transaction.log.TransactionIdStore txIdStore, java.net.URI masterUri, java.net.URI me, org.neo4j.storageengine.api.StoreId storeId, org.neo4j.helpers.CancellationRequest cancellationRequest) throws Throwable
        private bool ExecuteConsistencyChecks(TransactionIdStore txIdStore, URI masterUri, URI me, StoreId storeId, CancellationRequest cancellationRequest)
        {
            LifeSupport consistencyCheckLife = new LifeSupport();

            try
            {
                MasterClient masterClient = NewMasterClient(masterUri, me, storeId, consistencyCheckLife);
                consistencyCheckLife.Start();

                if (cancellationRequest.CancellationRequested())
                {
                    return(false);
                }

                CheckDataConsistency(masterClient, txIdStore, storeId, masterUri, me, cancellationRequest);
            }
            finally
            {
                consistencyCheckLife.Shutdown();
            }
            return(true);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.net.URI startHaCommunication(org.neo4j.kernel.lifecycle.LifeSupport haCommunicationLife, org.neo4j.kernel.NeoStoreDataSource neoDataSource, java.net.URI me, java.net.URI masterUri, org.neo4j.storageengine.api.StoreId storeId, org.neo4j.helpers.CancellationRequest cancellationRequest) throws IllegalArgumentException, InterruptedException
        private URI StartHaCommunication(LifeSupport haCommunicationLife, NeoStoreDataSource neoDataSource, URI me, URI masterUri, StoreId storeId, CancellationRequest cancellationRequest)
        {
            MasterClient master = NewMasterClient(masterUri, me, neoDataSource.StoreId, haCommunicationLife);

            TransactionObligationFulfiller obligationFulfiller   = ResolveDatabaseDependency(typeof(TransactionObligationFulfiller));
            UpdatePullerScheduler          updatePullerScheduler = _updatePullerFactory.createUpdatePullerScheduler(UpdatePuller);

            Slave slaveImpl = new SlaveImpl(obligationFulfiller);

            SlaveServer server = _slaveServerFactory.apply(slaveImpl);

            if (cancellationRequest.CancellationRequested())
            {
                MsgLog.info("Switch to slave cancelled, unable to start HA-communication");
                return(null);
            }

            _masterDelegateHandler.Delegate = master;

            haCommunicationLife.Add(updatePullerScheduler);
            haCommunicationLife.Add(server);
            haCommunicationLife.Start();

            /*
             * Take the opportunity to catch up with master, now that we're alone here, right before we
             * drop the availability guard, so that other transactions might start.
             */
            if (!CatchUpWithMaster(UpdatePuller))
            {
                return(null);
            }

            URI slaveHaURI = CreateHaURI(me, server);

            _clusterMemberAvailability.memberIsAvailable(HighAvailabilityModeSwitcher.SLAVE, slaveHaURI, storeId);

            return(slaveHaURI);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs a switch to the slave state. Starts the communication endpoints, switches components to the slave state
        /// and ensures that the current database is appropriate for this cluster. It also broadcasts the appropriate
        /// Slave Is Available event
        /// </summary>
        /// <param name="haCommunicationLife"> The LifeSupport instance to register the network facilities required for
        ///                            communication with the rest of the cluster </param>
        /// <param name="me"> The URI this instance must bind to </param>
        /// <param name="masterUri"> The URI of the master for which this instance must become slave to </param>
        /// <param name="cancellationRequest"> A handle for gracefully aborting the switch </param>
        /// <returns> The URI that was broadcasted as the slave endpoint or null if the task was cancelled </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.net.URI switchToSlave(org.neo4j.kernel.lifecycle.LifeSupport haCommunicationLife, java.net.URI me, java.net.URI masterUri, org.neo4j.helpers.CancellationRequest cancellationRequest) throws Throwable
//JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type:
        public virtual URI SwitchToSlaveConflict(LifeSupport haCommunicationLife, URI me, URI masterUri, CancellationRequest cancellationRequest)
        {
            URI  slaveUri;
            bool success = false;

            Monitor.switchToSlaveStarted();

            // Wait a short while for current transactions to stop first, just to be nice.
            // We can't wait forever since switching to our designated role is quite important.
            Clock clock    = Clocks.systemClock();
            long  deadline = clock.millis() + Config.get(HaSettings.internal_state_switch_timeout).toMillis();
            DatabaseTransactionStats transactionStats = _transactionStatsSupplier.get();

            while (transactionStats.NumberOfActiveTransactions > 0 && clock.millis() < deadline)
            {
                parkNanos(MILLISECONDS.toNanos(10));
            }

            try
            {
                InstanceId myId = Config.get(ClusterSettings.server_id);

                UserLog.info("ServerId %s, moving to slave for master %s", myId, masterUri);

                Debug.Assert(masterUri != null);                           // since we are here it must already have been set from outside

                _idGeneratorFactory.switchToSlave();

                CopyStoreFromMasterIfNeeded(masterUri, me, cancellationRequest);

                /*
                 * The following check is mandatory, since the store copy can be cancelled and if it was actually
                 * happening then we can't continue, as there is no store in place
                 */
                if (cancellationRequest.CancellationRequested())
                {
                    MsgLog.info("Switch to slave cancelled during store copy if no local store is present.");
                    return(null);
                }

                /*
                 * We get here either with a fresh store from the master copy above so we need to
                 * start the ds or we already had a store, so we have already started the ds. Either way,
                 * make sure it's there.
                 */
                NeoStoreDataSource neoDataSource = _neoDataSourceSupplier.get();
                neoDataSource.AfterModeSwitch();
                StoreId myStoreId = neoDataSource.StoreId;

                bool consistencyChecksExecutedSuccessfully = ExecuteConsistencyChecks(_transactionIdStoreSupplier.get(), masterUri, me, myStoreId, cancellationRequest);

                if (!consistencyChecksExecutedSuccessfully)
                {
                    MsgLog.info("Switch to slave cancelled due to consistency check failure.");
                    return(null);
                }

                if (cancellationRequest.CancellationRequested())
                {
                    MsgLog.info("Switch to slave cancelled after consistency checks.");
                    return(null);
                }

                // no exception were thrown and we can proceed
                slaveUri = StartHaCommunication(haCommunicationLife, neoDataSource, me, masterUri, myStoreId, cancellationRequest);
                if (slaveUri == null)
                {
                    MsgLog.info("Switch to slave unable to connect.");
                    return(null);
                }

                success = true;
                UserLog.info("ServerId %s, successfully moved to slave for master %s", myId, masterUri);
            }
            finally
            {
                Monitor.switchToSlaveCompleted(success);
            }

            return(slaveUri);
        }