Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private void switchToPending(final org.neo4j.kernel.ha.cluster.HighAvailabilityMemberState oldState)
        private void SwitchToPending(HighAvailabilityMemberState oldState)
        {
            _msgLog.info("I am %s, moving to pending", _instanceId);

            StartModeSwitching(() =>
            {
                if (_cancellationHandle.cancellationRequested())
                {
                    _msgLog.info("Switch to pending cancelled on start.");
                    return;
                }

                _componentSwitcher.switchToPending();
                _neoStoreDataSourceSupplier.DataSource.beforeModeSwitch();

                if (_cancellationHandle.cancellationRequested())
                {
                    _msgLog.info("Switch to pending cancelled before ha communication shutdown.");
                    return;
                }

                _haCommunicationLife.shutdown();
                _haCommunicationLife = new LifeSupport();
            }, new CancellationHandle());

            try
            {
                _modeSwitcherFuture.get(10, TimeUnit.SECONDS);
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        private void SwitchToMaster()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CancellationHandle cancellationHandle = new CancellationHandle();
            CancellationHandle cancellationHandle = new CancellationHandle();

            StartModeSwitching(() =>
            {
                if (_currentTargetState != HighAvailabilityMemberState.ToMaster)
                {
                    return;
                }

                // We just got scheduled. Maybe we are already obsolete - test
                if (cancellationHandle.CancellationRequested())
                {
                    _msgLog.info("Switch to master cancelled on start.");
                    return;
                }

                _componentSwitcher.switchToMaster();

                if (cancellationHandle.CancellationRequested())
                {
                    _msgLog.info("Switch to master cancelled before ha communication started.");
                    return;
                }

                _haCommunicationLife.shutdown();
                _haCommunicationLife = new LifeSupport();

                try
                {
                    _masterHaURI = _switchToMaster.switchToMaster(_haCommunicationLife, _me);
                    _canAskForElections.set(true);
                }
                catch (Exception e)
                {
                    _msgLog.error("Failed to switch to master", e);

                    /*
                     * If the attempt to switch to master fails, then we must not try again. We'll trigger an election
                     * and if we are elected again, we'll try again. We differentiate between this case and the case where
                     * we simply receive another election result while switching hasn't completed yet by setting the
                     * currentTargetState as follows:
                     */
                    _currentTargetState = HighAvailabilityMemberState.Pending;
                    // Since this master switch failed, elect someone else
                    _election.demote(_instanceId);
                }
            }, cancellationHandle);
        }
Ejemplo n.º 3
0
        private static ClusterMember UpdateRole(ClusterMember member, HighAvailabilityMemberState state)
        {
            switch (state.innerEnumValue)
            {
            case HighAvailabilityMemberState.InnerEnum.MASTER:
                return(member.AvailableAs(HighAvailabilityModeSwitcher.MASTER, member.HAUri, member.StoreId));

            case HighAvailabilityMemberState.InnerEnum.SLAVE:
                return(member.AvailableAs(HighAvailabilityModeSwitcher.SLAVE, member.HAUri, member.StoreId));

            default:
                return(member.Unavailable());
            }
        }
Ejemplo n.º 4
0
        private static System.Func <ClusterMembers> GetClusterMembers(string memberRole, HighAvailabilityMemberState memberState)
        {
            HighAvailabilityMemberStateMachine stateMachine = mock(typeof(HighAvailabilityMemberStateMachine));

            when(stateMachine.CurrentState).thenReturn(memberState);
            ClusterMember clusterMember = spy(new ClusterMember(new InstanceId(1)));

            when(clusterMember.HARole).thenReturn(memberRole);
            ObservedClusterMembers observedClusterMembers = mock(typeof(ObservedClusterMembers));

            when(observedClusterMembers.CurrentMember).thenReturn(clusterMember);
            return(() => new ClusterMembers(observedClusterMembers, stateMachine));
        }
Ejemplo n.º 5
0
        private void StateChanged(HighAvailabilityMemberChangeEvent @event)
        {
            /*
             * First of all, check if the state change is internal or external. In this context, internal means
             * that the old and new state are different, so we definitely need to do something.
             * Both cases may require a switcher to be activated, but external needs to check if the same as previously
             * should be the one used (because the last attempt failed, for example) or maybe we simply need to update
             * a field. Internal will probably require a new switcher to be used.
             */
            if (@event.NewState == @event.OldState)
            {
                /*
                 * This is the external change case. We need to check our internals and perhaps retry a transition
                 */
                if (@event.NewState != HighAvailabilityMemberState.TO_MASTER)
                {
                    /*
                     * We get here if for example a new master becomes available while we are already switching. In that
                     * case we don't change state but we must update with the new availableMasterId,
                     * but only if it is not null.
                     */
                    if (@event.ServerHaUri != null)
                    {
                        _availableMasterId = @event.ServerHaUri;
                    }
                    return;
                }

                /*
                 * The other case is that the new state is TO_MASTER
                 */
                else if (_currentTargetState == HighAvailabilityMemberState.TO_MASTER)
                {
                    /*
                     * We are still switching from before. If a failure had happened, then currentTargetState would
                     * be PENDING.
                     */
                    return;
                }
            }

            _availableMasterId = @event.ServerHaUri;

            _currentTargetState = @event.NewState;
            switch (@event.NewState)
            {
            case TO_MASTER:

                if (@event.OldState.Equals(HighAvailabilityMemberState.SLAVE))
                {
                    _clusterMemberAvailability.memberIsUnavailable(SLAVE);
                }

                SwitchToMaster();
                break;

            case TO_SLAVE:
                SwitchToSlave();
                break;

            case PENDING:

                SwitchToPending(@event.OldState);
                break;

            default:
                // do nothing
                break;
            }
        }