/// <summary>
        /// Set a new track position marker. </summary>
        /// <param name="marker"> Marker </param>
        /// <param name="currentTimecode"> Current timecode of the track when this marker is set </param>
        public virtual void set(TrackMarker marker, long currentTimecode)
        {
            TrackMarker previous = current.getAndSet(marker);

            if (previous != null)
            {
                previous.handler.handle(marker != null ? OVERWRITTEN : REMOVED);
            }

            if (marker != null && currentTimecode >= marker.timecode)
            {
                trigger(marker, LATE);
            }
        }
        /// <summary>
        /// Called by the appender that just appended a transaction to the log.
        /// </summary>
        /// <param name="logForceEvents"> A trace event for the given log append operation. </param>
        /// <returns> {@code true} if we got lucky and were the ones forcing the log. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected boolean forceAfterAppend(org.neo4j.kernel.impl.transaction.tracing.LogForceEvents logForceEvents) throws java.io.IOException
        protected internal virtual bool ForceAfterAppend(LogForceEvents logForceEvents)
        {
            // There's a benign race here, where we add our link before we update our next pointer.
            // This is okay, however, because unparkAll() spins when it sees a null next pointer.
            ThreadLink threadLink = new ThreadLink(Thread.CurrentThread);

            threadLink.Next = _threadLinkHead.getAndSet(threadLink);
            bool attemptedForce = false;

            using (LogForceWaitEvent logForceWaitEvent = logForceEvents.BeginLogForceWait())
            {
                do
                {
                    if (_forceLock.tryLock())
                    {
                        attemptedForce = true;
                        try
                        {
                            ForceLog(logForceEvents);
                            // In the event of any failure a database panic will be raised and thrown here
                        }
                        finally
                        {
                            _forceLock.unlock();

                            // We've released the lock, so unpark anyone who might have decided park while we were working.
                            // The most recently parked thread is the one most likely to still have warm caches, so that's
                            // the one we would prefer to unpark. Luckily, the stack nature of the ThreadLinks makes it easy
                            // to get to.
                            ThreadLink nextWaiter = _threadLinkHead.get();
                            nextWaiter.Unpark();
                        }
                    }
                    else
                    {
                        WaitForLogForce();
                    }
                } while (!threadLink.Done);

                // If there were many threads committing simultaneously and I wasn't the lucky one
                // actually doing the forcing (where failure would throw panic exception) I need to
                // explicitly check if everything is OK before considering this transaction committed.
                if (!attemptedForce)
                {
                    _databaseHealth.assertHealthy(typeof(IOException));
                }
            }
            return(attemptedForce);
        }
示例#3
0
        public override long Receive(long ticket, T batch)
        {
            long time = nanoTime();

            while (QueuedBatches.get() >= _maxQueueLength)
            {
                Park.park(_receiverThread = Thread.CurrentThread);
            }
            // It is of importance that all items in the queue at the same time agree on the number of processors. We take this lock in order to make sure that we
            // do not interfere with another thread trying to drain the queue in order to change the processor count.
            long @lock = ApplyProcessorCount(_stripingLock.readLock());

            QueuedBatches.incrementAndGet();
            Unit unit = new Unit(this, ticket, batch, _numberOfForkedProcessors);

            // [old head] [unit]
            //               ^
            //              head
            Unit myHead = _head.getAndSet(unit);

            // [old head] -next-> [unit]
            myHead.Next = unit;
            _stripingLock.unlock(@lock);

            return(nanoTime() - time);
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void stressLatch()
        internal virtual void StressLatch()
        {
            assertTimeout(ofSeconds(60), () =>
            {
                AtomicReference <BinaryLatch> latchRef = new AtomicReference <BinaryLatch>(new BinaryLatch());
                ThreadStart awaiter = () =>
                {
                    BinaryLatch latch;
                    while ((latch = latchRef.get()) != null)
                    {
                        latch.Await();
                    }
                };

                int awaiters = 6;
                Future <object>[] futures = new Future <object> [awaiters];
                for (int i = 0; i < awaiters; i++)
                {
                    futures[i] = _executor.submit(awaiter);
                }

                ThreadLocalRandom rng = ThreadLocalRandom.current();
                for (int i = 0; i < 500000; i++)
                {
                    latchRef.getAndSet(new BinaryLatch()).release();
                    Spin(rng.nextLong(0, 10));
                }

                latchRef.getAndSet(null).release();

                // None of the tasks we started should get stuck, e.g. miss a release signal:
                foreach (Future <object> future in futures)
                {
                    future.get();
                }
            });
        }
示例#5
0
 public static LogProvider setLogProvider(LogProvider newLogProvider)
 {
     return(_logProvider.getAndSet(newLogProvider));
 }
示例#6
0
 /// <summary>
 /// Set the <seealso cref="Level"/> that logging should be enabled at
 /// </summary>
 /// <param name="level"> the new logging level </param>
 /// <returns> the previous logging level </returns>
 public virtual Level setLevel(Level level)
 {
     return(_levelRef.getAndSet(level));
 }