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);
}
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]));
}
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());
}
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();
}
}
}
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;
}
Aggregations