Search in sources :

Example 21 with XaDataSource

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

the class MasterImpl method commitSingleResourceTransaction.

public Response<Long> commitSingleResourceTransaction(SlaveContext context, String resource, TxExtractor txGetter) {
    Transaction otherTx = suspendOtherAndResumeThis(context);
    try {
        XaDataSource dataSource = graphDbConfig.getTxModule().getXaDataSourceManager().getXaDataSource(resource);
        final long txId = dataSource.applyPreparedTransaction(txGetter.extract());
        Predicate<Long> notThisTx = new Predicate<Long>() {

            public boolean accept(Long item) {
                return item != txId;
            }
        };
        return packResponse(context, txId, notThisTx);
    } catch (IOException e) {
        e.printStackTrace();
        return new FailedResponse<Long>();
    } finally {
        suspendThisAndResumeOther(otherTx, context);
    }
}
Also used : Transaction(javax.transaction.Transaction) IOException(java.io.IOException) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Predicate(org.neo4j.helpers.Predicate)

Example 22 with XaDataSource

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

the class MasterImpl method makeSureThereIsAtLeastOneKernelTx.

private SlaveContext makeSureThereIsAtLeastOneKernelTx(SlaveContext context) {
    Collection<Pair<String, Long>> txs = new ArrayList<Pair<String, Long>>();
    for (Pair<String, Long> txEntry : context.lastAppliedTransactions()) {
        String resourceName = txEntry.first();
        XaDataSource dataSource = graphDbConfig.getTxModule().getXaDataSourceManager().getXaDataSource(resourceName);
        if (dataSource instanceof NeoStoreXaDataSource) {
            if (txEntry.other() == 1 || txEntry.other() < dataSource.getLastCommittedTxId()) {
                // copying
                return context;
            }
            // Put back slave one tx so that it gets one transaction
            txs.add(Pair.of(resourceName, dataSource.getLastCommittedTxId() - 1));
        //                System.out.println( "Pushed in one extra tx " + dataSource.getLastCommittedTxId() );
        } else {
            txs.add(Pair.of(resourceName, dataSource.getLastCommittedTxId()));
        }
    }
    return new SlaveContext(context.machineId(), context.getEventIdentifier(), txs.toArray(new Pair[0]));
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) ArrayList(java.util.ArrayList) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Pair(org.neo4j.helpers.Pair)

Aggregations

XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)22 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)7 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Pair (org.neo4j.helpers.Pair)4 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)4 ArrayList (java.util.ArrayList)3 XAException (javax.transaction.xa.XAException)3 SlaveContext (org.neo4j.com.SlaveContext)3 File (java.io.File)2 Map (java.util.Map)2 XAResource (javax.transaction.xa.XAResource)2 Test (org.junit.Test)2 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)2 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)2 FileInputStream (java.io.FileInputStream)1 FilenameFilter (java.io.FilenameFilter)1 ByteBuffer (java.nio.ByteBuffer)1