Search in sources :

Example 1 with SlaveContext

use of org.neo4j.com.SlaveContext 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 SlaveContext

use of org.neo4j.com.SlaveContext in project graphdb by neo4j-attic.

the class HighlyAvailableGraphDatabase method copyStoreFromMaster.

private void copyStoreFromMaster(Pair<Master, Machine> master) throws Exception {
    msgLog.logMessage("Copying store from master");
    Response<Void> response = master.first().copyStore(new SlaveContext(machineId, 0, new Pair[0]), new ToFileStoreWriter(storeDir));
    EmbeddedGraphDatabase tempDb = new EmbeddedGraphDatabase(storeDir);
    try {
        MasterUtil.applyReceivedTransactions(response, tempDb, MasterUtil.txHandlerForFullCopy());
    } finally {
        tempDb.shutdown();
    }
    msgLog.logMessage("Done copying store from master");
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) Pair(org.neo4j.helpers.Pair) ToFileStoreWriter(org.neo4j.com.ToFileStoreWriter)

Example 3 with SlaveContext

use of org.neo4j.com.SlaveContext in project graphdb by neo4j-attic.

the class BackupImpl method fullBackup.

public Response<Void> fullBackup(StoreWriter writer) {
    SlaveContext context = MasterUtil.rotateLogsAndStreamStoreFiles(graphDb, writer);
    writer.done();
    return MasterUtil.packResponse(graphDb, context, null, MasterUtil.ALL);
}
Also used : SlaveContext(org.neo4j.com.SlaveContext)

Example 4 with SlaveContext

use of org.neo4j.com.SlaveContext 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 5 with SlaveContext

use of org.neo4j.com.SlaveContext 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

SlaveContext (org.neo4j.com.SlaveContext)7 Pair (org.neo4j.helpers.Pair)4 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Channel (org.jboss.netty.channel.Channel)1 ToFileStoreWriter (org.neo4j.com.ToFileStoreWriter)1 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)1 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)1