[Neo] Fwd: Neo4J and Concurrency

Johan Svensson johan at neotechnology.com
Mon Apr 26 14:33:04 CEST 2010


Hi,

This code will shutdown the kernel right away. Depending on timing you
may shutdown the kernel while the thread pool is still executing and
that could be the cause of your error.

If you remove the @After / kernel shutdown code or add code in the
@Test method to wait for the thread pool to execute all tasks will it
work then?

Regards,
Johan

On Mon, Apr 26, 2010 at 2:05 PM, Stefan Berndt <kontakt at stberndt.de> wrote:
> Off course i can. This is my testcase-classfile:
>
> import org.junit.After;
> import org.junit.Before;
> import org.junit.Test;
> import org.neo4j.graphdb.Transaction;
> import org.neo4j.kernel.impl.transaction.DeadlockDetectedException;
>
> import java.io.IOException;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
>
>
> public class WriteOneNode {
>    private DatabaseAccessor db;
>    private static long NodeId;
>
>    @Before
>    public void setUp() throws IOException {
>        db = SingletonFactory.getInstance();
>        createNodes();
>    }
>
>    @After
>
>    public void tearDown() {
>        db.shutdown();
>    }
>
>    private void createNodes() {
>        Transaction tx = db.beginTx();
>
>        try {
>            Kunde k = new KundeImpl(db.createNode());
>            k.setName("ol");
>            NodeId = k.getunderlyingNode().getId();
>            tx.success();
>        }
>        finally {
>            tx.finish();
>        }
>    }
>
>    @Test
>    public void writeOneNodeConcurrent() {
>        ExecutorService pool = Executors.newFixedThreadPool(1);
>        for (int i = 0; i < 10; i++) {
>            final int j = i;
>
>
>            pool.execute(new Runnable() {
>
>
>                public void run() {
>                    Transaction tx = db.beginTx();
>                    try {
>
>                        writeNode(j);
>                    }
>                    catch (DeadlockDetectedException e) {
>                        System.err.println(e.getMessage());
>                    }
>                    finally {
>                        tx.finish();
>                    }
>
>
>                }
>
>
>            });
>
>
>        }
>    }
>
>    private void writeNode(int j) {
>        if (j % 2 == 1) {
>            db.getNodeById(NodeId).setProperty(KundeImpl.KEY_NAME, "n1");
>
>        } else db.getNodeById(NodeId).setProperty(KundeImpl.KEY_NAME,
> "n2");
>    }
>
>
> }
>
> Thx for your help
> --
> Stefan
>
> ----
> We should fix this as soon as we can, could you provide a (small) test case
> that can reproduce this with some reliability?
>
> /Tobias
>
>
> -------- Original Message --------
> Subject: Neo4J and Concurrency
> Date: Mon, 26 Apr 2010 09:10:18 +0000
> From: Stefan Berndt <kontakt at stberndt.de>
> To: user at lists.neo4j.org
>
> Hello,
>
> I am testing Neo4j for a week now and i'm trying to make some operations on
> the Graph concurrent.
> For this I use the PoolExecutor and do some Write-Operations. but the
> TransactionManager just throws Exceptions i don't understand.
> F.ex.:
>
> javax.transaction.xa.XAException: Unknown
> xid[GlobalId[NEOKERNL|1272272945279|2], BranchId[ 52 49 52 49 52 49 ]]
>        at
> org.neo4j.kernel.impl.transaction.xaframework.XaResourceManager.rollback(XaResourceManager.java:416)
>        at
> org.neo4j.kernel.impl.transaction.xaframework.XaResourceHelpImpl.rollback(XaResourceHelpImpl.java:111)
>        at
> org.neo4j.kernel.impl.transaction.TransactionImpl.doRollback(TransactionImpl.java:531)
>        at
> org.neo4j.kernel.impl.transaction.TxManager.rollback(TxManager.java:728)
>        at
> org.neo4j.kernel.impl.transaction.TransactionImpl.rollback(TransactionImpl.java:114)
>        at
> org.neo4j.kernel.EmbeddedGraphDbImpl$TransactionImpl.finish(EmbeddedGraphDbImpl.java:336)
>        at ConcurrentTest$1.run(ConcurrentTest.java:62)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:619)
> 26.04.2010 11:09:05 org.neo4j.kernel.impl.transaction.TxManager rollback
> SCHWERWIEGEND: Unable to rollback marked or active transaction. Some
> resources may be commited others not. Neo4j kernel should be SHUTDOWN for
> resource maintance and transaction recovery ---->
> Exception in thread "pool-1-thread-1"
> org.neo4j.kernel.impl.transaction.TransactionFailureException: Unable to
> rollback transaction
>        at
> org.neo4j.kernel.EmbeddedGraphDbImpl$TransactionImpl.finish(EmbeddedGraphDbImpl.java:349)
>        at ConcurrentTest$1.run(ConcurrentTest.java:62)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:619)
> Caused by: javax.transaction.SystemException: Unable to rollback  --->
> error code for rollback: 0
>        at
> org.neo4j.kernel.impl.transaction.TxManager.rollback(TxManager.java:738)
>        at
> org.neo4j.kernel.impl.transaction.TransactionImpl.rollback(TransactionImpl.java:114)
>        at
> org.neo4j.kernel.EmbeddedGraphDbImpl$TransactionImpl.finish(EmbeddedGraphDbImpl.java:336)
>        ... 4 more
>
> This Exceptions are coming up already just with one Thread in the
> ExcecutorPool. Thx for your help.


More information about the User mailing list