コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotifyCancelListeners()
        public virtual void ShouldNotifyCancelListeners()
        {
            // GIVEN
            CentralJobScheduler centralJobScheduler = new CentralJobScheduler();

            centralJobScheduler.Init();

            // WHEN
            AtomicBoolean halted = new AtomicBoolean();
            ThreadStart   job    = () =>
            {
                while (!halted.get())
                {
                    LockSupport.parkNanos(MILLISECONDS.toNanos(10));
                }
            };
            JobHandle handle = centralJobScheduler.Schedule(Group.INDEX_POPULATION, job);

            handle.RegisterCancelListener(mayBeInterrupted => halted.set(true));
            handle.Cancel(false);

            // THEN
            assertTrue(halted.get());
            centralJobScheduler.Shutdown();
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeOneIteration(TestCoordinator testCoordinator, java.util.concurrent.atomic.AtomicBoolean failHalt) throws java.io.IOException, InterruptedException
        private void WriteOneIteration(TestCoordinator testCoordinator, AtomicBoolean failHalt)
        {
            int batchSize = testCoordinator.WriteBatchSize();
            IEnumerable <UpdateOperation> toWrite         = testCoordinator.NextToWrite();
            IEnumerator <UpdateOperation> toWriteIterator = toWrite.GetEnumerator();

            while (toWriteIterator.MoveNext())
            {
                using (Writer <KEY, VALUE> writer = _index.writer())
                {
                    int inBatch = 0;
                    while (toWriteIterator.MoveNext() && inBatch < batchSize)
                    {
                        UpdateOperation operation = toWriteIterator.Current;
                        operation.Apply(writer);
                        if (failHalt.get())
                        {
                            break;
                        }
                        inBatch++;
                    }
                }
                // Sleep to allow checkpointer to step in
                MILLISECONDS.sleep(1);
            }
        }
コード例 #3
0
ファイル: StopCompatibility.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertThreadIsWaitingForLock(LockAcquisition lockAcquisition) throws Exception
        private void AssertThreadIsWaitingForLock(LockAcquisition lockAcquisition)
        {
            for (int i = 0; i < 30 && !Suite.isAwaitingLockAcquisition(lockAcquisition.Executor.waitUntilWaiting()); i++)
            {
                LockSupport.parkNanos(MILLISECONDS.toNanos(100));
            }
            assertFalse("locking thread completed", lockAcquisition.Completed());
        }
コード例 #4
0
        private void AwaitTransactionsClosedWithinTimeout()
        {
            long deadline = _clock.millis() + _awaitActiveTransactionDeadlineMillis;

            while (_transactionCounters.NumberOfActiveTransactions > 0 && _clock.millis() < deadline)
            {
                parkNanos(MILLISECONDS.toNanos(10));
            }
        }
コード例 #5
0
 public OtherThreadExecutor(string name, long timeout, TimeUnit unit, T initialState)
 {
     if (!InstanceFieldsInitialized)
     {
         InitializeInstanceFields();
         InstanceFieldsInitialized = true;
     }
     this._name         = name;
     this.StateConflict = initialState;
     this._timeout      = MILLISECONDS.convert(timeout, unit);
 }
コード例 #6
0
ファイル: TimeUtil.cs プロジェクト: Neo4Net/Neo4Net
        public static string NanosToString(long nanos)
        {
            Debug.Assert(nanos >= 0);
            long          nanoSeconds = nanos;
            StringBuilder timeString  = new StringBuilder();

            long days = DAYS.convert(nanoSeconds, NANOSECONDS);

            if (days > 0)
            {
                nanoSeconds -= DAYS.toNanos(days);
                timeString.Append(days).Append('d');
            }
            long hours = HOURS.convert(nanoSeconds, NANOSECONDS);

            if (hours > 0)
            {
                nanoSeconds -= HOURS.toNanos(hours);
                timeString.Append(hours).Append('h');
            }
            long minutes = MINUTES.convert(nanoSeconds, NANOSECONDS);

            if (minutes > 0)
            {
                nanoSeconds -= MINUTES.toNanos(minutes);
                timeString.Append(minutes).Append('m');
            }
            long seconds = SECONDS.convert(nanoSeconds, NANOSECONDS);

            if (seconds > 0)
            {
                nanoSeconds -= SECONDS.toNanos(seconds);
                timeString.Append(seconds).Append('s');
            }
            long milliseconds = MILLISECONDS.convert(nanoSeconds, NANOSECONDS);

            if (milliseconds > 0)
            {
                nanoSeconds -= MILLISECONDS.toNanos(milliseconds);
                timeString.Append(milliseconds).Append("ms");
            }
            long microseconds = MICROSECONDS.convert(nanoSeconds, NANOSECONDS);

            if (microseconds > 0)
            {
                nanoSeconds -= MICROSECONDS.toNanos(microseconds);
                timeString.Append(microseconds).Append("μs");
            }
            if (nanoSeconds > 0 || timeString.Length == 0)
            {
                timeString.Append(nanoSeconds).Append("ns");
            }
            return(timeString.ToString());
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleTheWholeWorkloadShebang() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleTheWholeWorkloadShebang()
        {
            // GIVEN
            const int         size       = 1_000;
            const long        bufferTime = 3;
            VerifyingConsumer consumer   = new VerifyingConsumer(size);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.Clock clock = org.neo4j.time.Clocks.systemClock();
            Clock clock = Clocks.systemClock();

            System.Func <long>      chunkThreshold = clock.millis;
            System.Predicate <long> safeThreshold  = time => clock.millis() - bufferTime >= time;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final DelayedBuffer<long> buffer = new DelayedBuffer<>(chunkThreshold, safeThreshold, 10, consumer);
            DelayedBuffer <long> buffer      = new DelayedBuffer <long>(chunkThreshold, safeThreshold, 10, consumer);
            MaintenanceThread    maintenance = new MaintenanceThread(buffer, 5);
            Race      adders         = new Race();
            const int numberOfAdders = 20;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] offeredIds = new byte[size];
            sbyte[] offeredIds = new sbyte[size];
            for (int i = 0; i < numberOfAdders; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int finalI = i;
                int finalI = i;
                adders.AddContestant(() =>
                {
                    for (int j = 0; j < size; j++)
                    {
                        if (j % numberOfAdders == finalI)
                        {
                            buffer.Offer(j);
                            offeredIds[j] = 1;
                            parkNanos(MILLISECONDS.toNanos(current().Next(2)));
                        }
                    }
                });
            }

            // WHEN (multi-threaded) offering of ids
            adders.Go();
            // ... ensuring the test is sane itself (did we really offer all these IDs?)
            for (int i = 0; i < size; i++)
            {
                assertEquals("ID " + i, ( sbyte )1, offeredIds[i]);
            }
            maintenance.Halt();
            buffer.Close();

            // THEN
            consumer.AssertHaveOnlySeenRange(0, size - 1);
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitSchemaStateCleared(String keyForProbing) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private void AwaitSchemaStateCleared(string keyForProbing)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                while (transaction.SchemaRead().schemaStateGetOrCreate(keyForProbing, ignored => null) != null)
                {
                    LockSupport.parkNanos(MILLISECONDS.toNanos(10));
                }
                transaction.Success();
            }
        }
コード例 #9
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 Runnable endAfterMax(final int time, final java.util.concurrent.TimeUnit unit, final java.util.concurrent.atomic.AtomicBoolean end)
        private ThreadStart EndAfterMax(int time, TimeUnit unit, AtomicBoolean end)
        {
            return(() =>
            {
                long endTime = currentTimeMillis() + unit.toMillis(time);
                while (currentTimeMillis() < endTime && !end.get())
                {
                    parkNanos(MILLISECONDS.toNanos(50));
                }
                end.set(true);
            });
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDoProcessingInitializationInOrder() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldDoProcessingInitializationInOrder()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Race race = new org.neo4j.test.Race();
            Race race = new Race();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger coordination = new java.util.concurrent.atomic.AtomicInteger(-1);
            AtomicInteger coordination = new AtomicInteger(-1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger expected = new java.util.concurrent.atomic.AtomicInteger();
            AtomicInteger expected = new AtomicInteger();
            const int     threads  = 30;

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") final RecordCheckWorker<int>[] workers = new RecordCheckWorker[threads];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            RecordCheckWorker <int>[] workers = new RecordCheckWorker[threads];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RecordProcessor<int> processor = new RecordProcessor_Adapter<int>()
            RecordProcessor <int> processor = new RecordProcessor_AdapterAnonymousInnerClass(this, expected);

            for (int id = 0; id < threads; id++)
            {
                ArrayBlockingQueue <int> queue = new ArrayBlockingQueue <int>(10);
                race.AddContestant(workers[id] = new RecordCheckWorker <int>(id, coordination, queue, processor));
            }
            race.AddContestant(() =>
            {
                try
                {
                    long end = currentTimeMillis() + SECONDS.toMillis(100);
                    while (currentTimeMillis() < end && expected.get() < threads)
                    {
                        parkNanos(MILLISECONDS.toNanos(10));
                    }
                    assertEquals(threads, expected.get());
                }
                finally
                {
                    foreach (RecordCheckWorker <int> worker in workers)
                    {
                        worker.Done();
                    }
                }
            });

            // WHEN
            race.Go();
        }
コード例 #11
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: static String formatInterval(final long l)
        internal static string FormatInterval(long l)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long hr = MILLISECONDS.toHours(l);
            long hr = MILLISECONDS.toHours(l);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long min = MILLISECONDS.toMinutes(l - HOURS.toMillis(hr));
            long min = MILLISECONDS.toMinutes(l - HOURS.toMillis(hr));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long sec = MILLISECONDS.toSeconds(l - HOURS.toMillis(hr) - MINUTES.toMillis(min));
            long sec = MILLISECONDS.toSeconds(l - HOURS.toMillis(hr) - MINUTES.toMillis(min));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long ms = l - HOURS.toMillis(hr) - MINUTES.toMillis(min) - SECONDS.toMillis(sec);
            long ms = l - HOURS.toMillis(hr) - MINUTES.toMillis(min) - SECONDS.toMillis(sec);

            return(string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hr, min, sec, ms));
        }
コード例 #12
0
        internal static object[] Build(Org.Neo4j.causalclustering.routing.load_balancing.LoadBalancingProcessor_Result result)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            object[] routers = result.RouteEndpoints().Select(Endpoint::address).Select(SocketAddress::toString).ToArray();
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            object[] readers = result.ReadEndpoints().Select(Endpoint::address).Select(SocketAddress::toString).ToArray();
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            object[] writers = result.WriteEndpoints().Select(Endpoint::address).Select(SocketAddress::toString).ToArray();

            IList <IDictionary <string, object> > servers = new List <IDictionary <string, object> >();

            if (writers.Length > 0)
            {
                IDictionary <string, object> map = new SortedDictionary <string, object>();

                map[ROLE_KEY]      = WRITE.name();
                map[ADDRESSES_KEY] = writers;

                servers.Add(map);
            }

            if (readers.Length > 0)
            {
                IDictionary <string, object> map = new SortedDictionary <string, object>();

                map[ROLE_KEY]      = READ.name();
                map[ADDRESSES_KEY] = readers;

                servers.Add(map);
            }

            if (routers.Length > 0)
            {
                IDictionary <string, object> map = new SortedDictionary <string, object>();

                map[ROLE_KEY]      = ROUTE.name();
                map[ADDRESSES_KEY] = routers;

                servers.Add(map);
            }

            long timeToLiveSeconds = MILLISECONDS.toSeconds(result.TtlMillis());

            return(new object[] { timeToLiveSeconds, servers });
        }
コード例 #13
0
 private ThreadStart CheckpointThread(AtomicBoolean endSignal, AtomicReference <Exception> readerError, AtomicBoolean failHalt)
 {
     return(() =>
     {
         while (!endSignal.get())
         {
             try
             {
                 _index.checkpoint(IOLimiter.UNLIMITED);
                 // Sleep a little in between checkpoints
                 MILLISECONDS.sleep(20L);
             }
             catch (Exception e)
             {
                 readerError.set(e);
                 failHalt.set(true);
             }
         }
     });
 }
コード例 #14
0
        internal static object[] Build(MultiClusterRoutingResult result)
        {
            System.Func <IList <Endpoint>, object[]> stringifyAddresses = es => es.Select(e => e.address().ToString()).ToArray();

            IList <IDictionary <string, object> > response = result.Routers().SetOfKeyValuePairs().Select(entry =>
            {
                string dbName      = entry.Key;
                object[] addresses = stringifyAddresses(entry.Value);

                IDictionary <string, object> responseRow = new SortedDictionary <string, object>();

                responseRow.put(DB_NAME_KEY, dbName);
                responseRow.put(ADDRESSES_KEY, addresses);

                return(responseRow);
            }).ToList();

            long ttlSeconds = MILLISECONDS.toSeconds(result.TtlMillis());

            return(new object[] { ttlSeconds, response });
        }
コード例 #15
0
        /// <summary>
        /// Starts the race and waits {@code maxWaitTime} for all contestants to either fail or succeed.
        /// </summary>
        /// <param name="maxWaitTime"> max time to wait for all contestants, 0 means indefinite wait. </param>
        /// <param name="unit"> <seealso cref="TimeUnit"/> that {£{@code maxWaitTime} is given in. </param>
        /// <exception cref="TimeoutException"> if all contestants haven't either succeeded or failed within the given time. </exception>
        /// <exception cref="Throwable"> on any exception thrown from any contestant. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void go(long maxWaitTime, java.util.concurrent.TimeUnit unit) throws Throwable
        public virtual void Go(long maxWaitTime, TimeUnit unit)
        {
            if (_endCondition == null)
            {
                _endCondition = () => true;
            }

            _readySet = new System.Threading.CountdownEvent(_contestants.Count);
            foreach (Contestant contestant in _contestants)
            {
                contestant.Start();
            }
            _readySet.await();
            _go.Signal();

            if (_asyncExecution)
            {
                return;
            }

            int  errorCount        = 0;
            long maxWaitTimeMillis = MILLISECONDS.convert(maxWaitTime, unit);
            long waitedSoFar       = 0;

            foreach (Contestant contestant in _contestants)
            {
                if (maxWaitTime == 0)
                {
                    contestant.Join();
                }
                else
                {
                    long time = currentTimeMillis();
                    contestant.Join(maxWaitTimeMillis - waitedSoFar);
                    waitedSoFar += currentTimeMillis() - time;
                    if (waitedSoFar >= maxWaitTimeMillis)
                    {
                        throw new TimeoutException("Didn't complete after " + maxWaitTime + " " + unit);
                    }
                }
                if (contestant.Error != null)
                {
                    errorCount++;
                }
            }

            if (errorCount > 1)
            {
                Exception errors = new Exception("Multiple errors found");
                foreach (Contestant contestant in _contestants)
                {
                    if (contestant.Error != null)
                    {
                        errors.addSuppressed(contestant.Error);
                    }
                }
                throw errors;
            }
            if (errorCount == 1)
            {
                foreach (Contestant contestant in _contestants)
                {
                    if (contestant.Error != null)
                    {
                        throw contestant.Error;
                    }
                }
            }
        }
コード例 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToSnapshotDuringHeavyLoad() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToSnapshotDuringHeavyLoad()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final KernelTransactions transactions = newKernelTransactions();
            KernelTransactions transactions = NewKernelTransactions();
            Race      race    = new Race();
            const int threads = 50;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReferenceArray<KernelTransactionsSnapshot> snapshots = new java.util.concurrent.atomic.AtomicReferenceArray<>(threads);
            AtomicReferenceArray <KernelTransactionsSnapshot> snapshots = new AtomicReferenceArray <KernelTransactionsSnapshot>(threads);

            // Representing "transaction" threads
            for (int i = 0; i < threads; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int threadIndex = i;
                int threadIndex = i;
                race.AddContestant(() =>
                {
                    ThreadLocalRandom random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        try
                        {
                            using (KernelTransaction transaction = GetKernelTransaction(transactions))
                            {
                                KernelTransactionsSnapshot snapshot = null;
                                try
                                {
                                    parkNanos(MILLISECONDS.toNanos(random.Next(3)));
                                    if (snapshots.get(threadIndex) == null)
                                    {
                                        requireNonNull(transactions, "transactions is null");
                                        snapshot = requireNonNull(transactions.Get(), "transactions.get() returned null");
                                        snapshots.set(threadIndex, snapshot);
                                        parkNanos(MILLISECONDS.toNanos(random.Next(3)));
                                    }
                                }
                                catch (Exception e)
                                {
                                    StringBuilder sb = (new StringBuilder("Gotcha!\n")).Append("threadIndex=").Append(threadIndex).Append('\n').Append("transaction=").Append(transaction).Append('\n').Append("snapshots=").Append(snapshots).Append('\n').Append("snapshot=").Append(snapshot).Append('\n').Append("end=").Append(end);
                                    throw new Exception(sb.ToString(), e);
                                }
                            }
                        }
                        catch (TransactionFailureException e)
                        {
                            throw new Exception(e);
                        }
                    }
                });
            }

            // Just checks snapshots
            race.AddContestant(() =>
            {
                ThreadLocalRandom random = ThreadLocalRandom.current();
                int snapshotsLeft        = 1_000;
                while (snapshotsLeft > 0)
                {
                    int threadIndex = random.Next(threads);
                    KernelTransactionsSnapshot snapshot = snapshots.get(threadIndex);
                    if (snapshot != null && snapshot.AllClosed())
                    {
                        snapshotsLeft--;
                        snapshots.set(threadIndex, null);
                    }
                }

                // End condition of this test can be described as:
                //   when 1000 snapshots have been seen as closed.
                // setting this boolean to true will have all other threads end as well so that race.go() will end
                end.set(true);
            });

            // WHEN
            race.Go();
        }
コード例 #17
0
 private static void ParkARandomWhile()
 {
     LockSupport.parkNanos(MILLISECONDS.toNanos(ThreadLocalRandom.current().Next(10)));
 }
コード例 #18
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);
        }
コード例 #19
0
 public override long CpuTimeNanos(long threadId)
 {
     Iteration++;
     return(MILLISECONDS.toNanos(Iteration * threadId));
 }
コード例 #20
0
 private static void ParkAWhile()
 {
     LockSupport.parkNanos(MILLISECONDS.toNanos(100));
 }