Search in sources :

Example 1 with XaDataSourceManager

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

the class HighlyAvailableGraphDatabase method getSlaveContext.

@Override
public SlaveContext getSlaveContext(int eventIdentifier) {
    XaDataSourceManager localDataSourceManager = getConfig().getTxModule().getXaDataSourceManager();
    Collection<XaDataSource> dataSources = localDataSourceManager.getAllRegisteredDataSources();
    @SuppressWarnings("unchecked") Pair<String, Long>[] txs = new Pair[dataSources.size()];
    int i = 0;
    for (XaDataSource dataSource : dataSources) {
        txs[i++] = Pair.of(dataSource.getName(), dataSource.getLastCommittedTxId());
    }
    return new SlaveContext(machineId, eventIdentifier, txs);
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Pair(org.neo4j.helpers.Pair)

Example 2 with XaDataSourceManager

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

the class OnlineBackup method slaveContextOf.

@SuppressWarnings("unchecked")
private SlaveContext slaveContextOf(GraphDatabaseService graphDb) {
    XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
    List<Pair<String, Long>> txs = new ArrayList<Pair<String, Long>>();
    for (XaDataSource ds : dsManager.getAllRegisteredDataSources()) {
        txs.add(Pair.of(ds.getName(), ds.getLastCommittedTxId()));
    }
    return new SlaveContext(0, 0, txs.toArray(new Pair[0]));
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) ArrayList(java.util.ArrayList) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Pair(org.neo4j.helpers.Pair)

Example 3 with XaDataSourceManager

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

the class TestNeo4j method testKeepLogsConfig.

@Test
public void testKeepLogsConfig() {
    Map<String, String> config = new HashMap<String, String>();
    config.put(Config.KEEP_LOGICAL_LOGS, "nioneodb");
    String storeDir = "target/configdb";
    deleteFileOrDirectory(storeDir);
    EmbeddedGraphDatabase db = new EmbeddedGraphDatabase(storeDir, config);
    XaDataSourceManager xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    XaDataSource xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
    db.shutdown();
    config.remove(Config.KEEP_LOGICAL_LOGS);
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(!xaDs.isLogicalLogKept());
    db.shutdown();
    config.put(Config.KEEP_LOGICAL_LOGS, "true");
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) HashMap(java.util.HashMap) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Test(org.junit.Test)

Example 4 with XaDataSourceManager

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

the class MasterUtil method applyReceivedTransactions.

public static <T> void applyReceivedTransactions(Response<T> response, GraphDatabaseService graphDb, TxHandler txHandler) throws IOException {
    XaDataSourceManager dataSourceManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
    for (Triplet<String, Long, TxExtractor> tx : IteratorUtil.asIterable(response.transactions())) {
        String resourceName = tx.first();
        XaDataSource dataSource = dataSourceManager.getXaDataSource(resourceName);
        txHandler.accept(tx, dataSource);
        ReadableByteChannel txStream = tx.third().extract();
        try {
            dataSource.applyCommittedTransaction(tx.second(), txStream);
        } finally {
            txStream.close();
        }
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 5 with XaDataSourceManager

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

the class MasterUtil method rotateLogsAndStreamStoreFiles.

public static SlaveContext rotateLogsAndStreamStoreFiles(GraphDatabaseService graphDb, StoreWriter writer) {
    File baseDir = getBaseDir(graphDb);
    XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
    Collection<XaDataSource> sources = dsManager.getAllRegisteredDataSources();
    @SuppressWarnings("unchecked") Pair<String, Long>[] appliedTransactions = new Pair[sources.size()];
    int i = 0;
    for (XaDataSource ds : sources) {
        appliedTransactions[i++] = Pair.of(ds.getName(), ds.getLastCommittedTxId());
        try {
            ds.getXaContainer().getResourceManager().rotateLogicalLog();
        } catch (IOException e) {
            // TODO: what about error message?
            throw new MasterFailureException(e);
        }
    }
    SlaveContext context = new SlaveContext(-1, -1, appliedTransactions);
    ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(1024 * 1024);
    for (XaDataSource ds : sources) {
        try {
            ClosableIterable<File> files = ds.listStoreFiles();
            try {
                for (File storefile : files) {
                    FileInputStream stream = new FileInputStream(storefile);
                    try {
                        writer.write(relativePath(baseDir, storefile), stream.getChannel(), temporaryBuffer, storefile.length() > 0);
                    } finally {
                        stream.close();
                    }
                }
            } finally {
                files.close();
            }
        } catch (IOException e) {
            // TODO: what about error message?
            throw new MasterFailureException(e);
        }
    }
    return context;
}
Also used : XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) IOException(java.io.IOException) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) File(java.io.File) Pair(org.neo4j.helpers.Pair)

Aggregations

XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)7 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)6 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)4 Pair (org.neo4j.helpers.Pair)3 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SlaveContext (org.neo4j.com.SlaveContext)2 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)2 FileInputStream (java.io.FileInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Transaction (javax.transaction.Transaction)1 TransactionManager (javax.transaction.TransactionManager)1 Triplet (org.neo4j.helpers.Triplet)1 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)1