示例#1
0
 public override void AllocationSuccessful(long memory, NumberArrayFactory successfulFactory, IEnumerable <NumberArrayFactory_AllocationFailure> attemptedAllocationFailures)
 {
     if (successfulFactory is PageCachedNumberArrayFactory)
     {
         StringBuilder builder = new StringBuilder(format("Memory allocation of %s ended up in page cache, which may impact performance negatively", bytes(memory)));
         attemptedAllocationFailures.forEach(failure => builder.Append(format("%n%s: %s", failure.Factory, failure.Failure)));
         _failedFactoriesDescription.compareAndSet(null, builder.ToString());
     }
 }
示例#2
0
        private void InsertPack(PackFile pf)
        {
            PackList o, n;

            do
            {
                o = _packList.get();
                PackFile[] oldList = o.packs;
                var        newList = new PackFile[1 + oldList.Length];
                newList[0] = pf;
                Array.Copy(oldList, 0, newList, 1, oldList.Length);
                n = new PackList(o.lastRead, o.lastModified, newList);
            } while (!_packList.compareAndSet(o, n));
        }
示例#3
0
            protected override void writeFile(string name, byte[] content)
            {
                _lck.setNeedStatInformation(true);
                try
                {
                    _lck.Write(content);
                }
                catch (IOException ioe)
                {
                    throw new ObjectWritingException("Unable to write " + name,
                                                     ioe);
                }
                try
                {
                    _lck.waitForStatChange();
                }
                catch (ThreadAbortException)
                {
                    _lck.Unlock();
                    throw new ObjectWritingException("Interrupted writing "
                                                     + name);
                }
                if (!_lck.Commit())
                {
                    throw new ObjectWritingException("Unable to write " + name);
                }

                _packedRefs.compareAndSet(_oldPackedList, new PackedRefList(_refs,
                                                                            content.Length, _lck.CommitLastModified));
            }
 private void trigger(TrackMarker marker, TrackMarkerHandler_MarkerState state)
 {
     if (current.compareAndSet(marker, null))
     {
         marker.handler.handle(state);
     }
 }
示例#5
0
        protected internal override void DoWork()
        {
            GraphDatabaseService db = _dbRef.get();

            Db.shutdown();
            LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(5));
            bool replaced = _dbRef.compareAndSet(db, _factory.newInstance());

            assertTrue(replaced);
        }
示例#6
0
 private void ReportError(Race.ThrowingRunnable checkpoint, AtomicReference <Exception> error)
 {
     try
     {
         checkpoint.Run();
     }
     catch (Exception t)
     {
         error.compareAndSet(null, t);
     }
 }
示例#7
0
            public override void accept(ThreadStart operation)
            {
                Instant now     = _clock.instant();
                Instant lastRun = lastRunRef.get();

                if (lastRun == null)
                {
                    if (lastRunRef.compareAndSet(null, now))
                    {
                        operation.run();
                    }
                    return;
                }

                if (lastRun.plus(_minInterval).isAfter(now))
                {
                    return;
                }

                if (lastRunRef.compareAndSet(lastRun, now))
                {
                    operation.run();
                }
            }
示例#8
0
            public override void Run()
            {
                AwaitStartSignal();
                while (Failure.get() == null && !StopSignal.get())
                {
                    try
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            // ArrayIndexOutOfBoundsException happens here
                            Iterables.count(ParentNode.getRelationships(RELTYPE, OUTGOING));

                            ParentNode.createRelationshipTo(Db.createNode(), RELTYPE);
                            tx.Success();
                        }
                    }
                    catch (Exception e)
                    {
                        Failure.compareAndSet(null, e);
                    }
                }
            }
示例#9
0
        /// <summary>
        /// Offers a transaction id. Will be accepted if this is higher than the current highest.
        /// This method is thread-safe.
        /// </summary>
        /// <param name="transactionId"> transaction id to compare for highest. </param>
        /// <param name="checksum"> checksum of the transaction. </param>
        /// <param name="commitTimestamp"> commit time for transaction with {@code transactionId}. </param>
        /// <returns> {@code true} if the given transaction id was higher than the current highest,
        /// {@code false}. </returns>
        public virtual bool Offer(long transactionId, long checksum, long commitTimestamp)
        {
            TransactionId high = _highest.get();

            if (transactionId < high.TransactionIdConflict())
            {               // a higher id has already been offered
                return(false);
            }

            TransactionId update = new TransactionId(transactionId, checksum, commitTimestamp);

            while (!_highest.compareAndSet(high, update))
            {
                high = _highest.get();
                if (high.TransactionIdConflict() >= transactionId)
                {                         // apparently someone else set a higher id while we were trying to set this id
                    return(false);
                }
            }
            // we set our id as the highest
            return(true);
        }
 public override void Start()
 {
     if (_state.compareAndSet(State.Init, State.Starting))
     {
         try
         {
             base.Start();
         }
         finally
         {
             this._state.set(State.Started);
         }
     }
     else
     {
         throw new System.InvalidOperationException("An IndexProxy can only be started once");
     }
 }
示例#11
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()
        {
            AtomicReference <IndexEntryConflictException> chainedExceptions = new AtomicReference <IndexEntryConflictException>();

            InstanceSelector.close(indexUpdater =>
            {
                try
                {
                    indexUpdater.close();
                }
                catch (IndexEntryConflictException e)
                {
                    if (!chainedExceptions.compareAndSet(null, e))
                    {
                        chainedExceptions.get().addSuppressed(e);
                    }
                }
            });

            if (chainedExceptions.get() != null)
            {
                throw chainedExceptions.get();
            }
        }
示例#12
0
 public void error(RecordType recordType, AbstractBaseRecord record, string message, object[] args)
 {
     assertTrue(_loggedError.compareAndSet(null, message));
 }
示例#13
0
        /*
         * Tests that changes performed in a transaction before commit are not apparent in another.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSimpleTransactionIsolation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestSimpleTransactionIsolation()
        {
            // Start setup - create base data
            Commit();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch1 = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent latch1 = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch2 = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent latch2 = new System.Threading.CountdownEvent(1);
            Node         n1;
            Node         n2;
            Relationship r1;

            using (Transaction tx = GraphDb.beginTx())
            {
                n1 = GraphDb.createNode();
                n2 = GraphDb.createNode();
                r1 = n1.CreateRelationshipTo(n2, RelationshipType.withName("TEST"));
                tx.Success();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node1 = n1;
            Node node1 = n1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node2 = n2;
            Node node2 = n2;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Relationship rel1 = r1;
            Relationship rel1 = r1;

            using (Transaction tx = GraphDb.beginTx())
            {
                node1.SetProperty("key", "old");
                rel1.SetProperty("key", "old");
                tx.Success();
            }
            AssertPropertyEqual(node1, "key", "old");
            AssertPropertyEqual(rel1, "key", "old");
            AssertRelationshipCount(node1, 1);
            AssertRelationshipCount(node2, 1);

            // This is the mutating transaction - it will change stuff which will be read in between
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<Exception> t1Exception = new java.util.concurrent.atomic.AtomicReference<>();
            AtomicReference <Exception> t1Exception = new AtomicReference <Exception>();
            Thread t1 = new Thread(() =>
            {
                try
                {
                    using (Transaction tx = GraphDb.beginTx())
                    {
                        node1.SetProperty("key", "new");
                        rel1.SetProperty("key", "new");
                        node1.CreateRelationshipTo(node2, RelationshipType.withName("TEST"));
                        AssertPropertyEqual(node1, "key", "new");
                        AssertPropertyEqual(rel1, "key", "new");
                        AssertRelationshipCount(node1, 2);
                        AssertRelationshipCount(node2, 2);
                        latch1.Signal();
                        latch2.await();
                        AssertPropertyEqual(node1, "key", "new");
                        AssertPropertyEqual(rel1, "key", "new");
                        AssertRelationshipCount(node1, 2);
                        AssertRelationshipCount(node2, 2);
                        // no tx.success();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    Thread.interrupted();
                    t1Exception.set(e);
                }
                finally
                {
                    try
                    {
                        AssertPropertyEqual(node1, "key", "old");
                        AssertPropertyEqual(rel1, "key", "old");
                        AssertRelationshipCount(node1, 1);
                        AssertRelationshipCount(node2, 1);
                    }
                    catch (Exception e)
                    {
                        t1Exception.compareAndSet(null, e);
                    }
                }
            });

            t1.Start();

            latch1.await();

            // The transaction started above that runs in t1 has not finished. The old values should still be visible.
            AssertPropertyEqual(node1, "key", "old");
            AssertPropertyEqual(rel1, "key", "old");
            AssertRelationshipCount(node1, 1);
            AssertRelationshipCount(node2, 1);

            latch2.Signal();
            t1.Join();

            // The transaction in t1 has finished but not committed. Its changes should still not be visible.
            AssertPropertyEqual(node1, "key", "old");
            AssertPropertyEqual(rel1, "key", "old");
            AssertRelationshipCount(node1, 1);
            AssertRelationshipCount(node2, 1);

            if (t1Exception.get() != null)
            {
                throw t1Exception.get();
            }

            using (Transaction tx = GraphDb.beginTx())
            {
                foreach (Relationship rel in node1.Relationships)
                {
                    rel.Delete();
                }
                node1.Delete();
                node2.Delete();
                tx.Success();
            }
        }
示例#14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long[] repeatCreateNamedPeopleFor(int totalNumberOfPeople) throws Exception
        private long[] RepeatCreateNamedPeopleFor(int totalNumberOfPeople)
        {
            // Parallelize the creation of persons
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long[] nodes = new long[totalNumberOfPeople];
            long[]    nodes   = new long[totalNumberOfPeople];
            const int threads = 100;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int peoplePerThread = totalNumberOfPeople / threads;
            int peoplePerThread = totalNumberOfPeople / threads;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.ExecutorService service = java.util.concurrent.Executors.newFixedThreadPool(threads);
            ExecutorService service = Executors.newFixedThreadPool(threads);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<org.neo4j.internal.kernel.api.exceptions.KernelException> exception = new java.util.concurrent.atomic.AtomicReference<>();
            AtomicReference <KernelException> exception = new AtomicReference <KernelException>();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<java.util.concurrent.Callable<Void>> jobs = new java.util.ArrayList<>(threads);
            IList <Callable <Void> > jobs = new List <Callable <Void> >(threads);

            // Start threads that creates these people, relying on batched writes to speed things up
            for (int i = 0; i < threads; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int finalI = i;
                int finalI = i;

                jobs.Add(() =>
                {
                    int offset = finalI * peoplePerThread;
                    while (offset < (finalI + 1) * peoplePerThread)
                    {
                        try
                        {
                            offset += CreateNamedPeople(nodes, offset);
                        }
                        catch (KernelException e)
                        {
                            exception.compareAndSet(null, e);
                            throw new Exception(e);
                        }
                    }
                    return(null);
                });
            }

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> job : service.invokeAll(jobs))
            foreach (Future <object> job in service.invokeAll(jobs))
            {
                job.get();
            }

            service.awaitTermination(1, TimeUnit.SECONDS);
            service.shutdown();

            // Make any KernelException thrown from a creation thread visible in the main thread
            Exception ex = exception.get();

            if (ex != null)
            {
                throw ex;
            }

            return(nodes);
        }