Search in sources :

Example 1 with XidImpl

use of org.neo4j.kernel.impl.transaction.XidImpl in project graphdb by neo4j-attic.

the class LogIoUtils method readTxStartEntry.

private static LogEntry.Start readTxStartEntry(ByteBuffer buf, ReadableByteChannel channel) throws IOException, ReadPastEndException {
    byte globalIdLength = readNextByte(buf, channel);
    byte branchIdLength = readNextByte(buf, channel);
    byte[] globalId = new byte[globalIdLength];
    readIntoBufferAndFlip(ByteBuffer.wrap(globalId), channel, globalIdLength);
    byte[] branchId = new byte[branchIdLength];
    readIntoBufferAndFlip(ByteBuffer.wrap(branchId), channel, branchIdLength);
    int identifier = readNextInt(buf, channel);
    int formatId = readNextInt(buf, channel);
    // re-create the transaction
    Xid xid = new XidImpl(globalId, branchId, formatId);
    return new LogEntry.Start(xid, identifier, -1);
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl)

Example 2 with XidImpl

use of org.neo4j.kernel.impl.transaction.XidImpl in project graphdb by neo4j-attic.

the class TestNeoStore method startTx.

private void startTx() throws XAException {
    dummyXid = new XidImpl(new byte[txCount], new byte[txCount]);
    txCount++;
    xaResource = xaCon.getXaResource();
    xaResource.start(dummyXid, XAResource.TMNOFLAGS);
}
Also used : XidImpl(org.neo4j.kernel.impl.transaction.XidImpl)

Example 3 with XidImpl

use of org.neo4j.kernel.impl.transaction.XidImpl in project graphdb by neo4j-attic.

the class TestXa method testLogicalLogPrePrepared.

@Test
public void testLogicalLogPrePrepared() throws Exception {
    Xid xid = new XidImpl(new byte[3], new byte[3]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaCon.clearAllTransactions();
    copyLogicalLog(path());
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 4 with XidImpl

use of org.neo4j.kernel.impl.transaction.XidImpl in project graphdb by neo4j-attic.

the class TestXa method testLogicalLogPrepared.

@Test
public void testLogicalLogPrepared() throws Exception {
    Xid xid = new XidImpl(new byte[2], new byte[2]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    ds.rotateLogicalLog();
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(1, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaRes.commit(xid, true);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 5 with XidImpl

use of org.neo4j.kernel.impl.transaction.XidImpl in project graphdb by neo4j-attic.

the class TestXa method testLogicalLog.

@Test
public void testLogicalLog() throws Exception {
    Xid xid = new XidImpl(new byte[1], new byte[1]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().getProperties(node1, false);
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaCon.getNodeConsumer().removeProperty(node1, n1prop1);
    xaCon.getRelationshipConsumer().removeProperty(rel1, r1prop1);
    xaCon.getRelationshipConsumer().deleteRelationship(rel1);
    xaCon.getNodeConsumer().deleteNode(node1);
    xaCon.getNodeConsumer().deleteNode(node2);
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.commit(xid, true);
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)12 Xid (javax.transaction.xa.Xid)11 XAResource (javax.transaction.xa.XAResource)9 Test (org.junit.Test)9 RelationshipType (org.neo4j.graphdb.RelationshipType)5