use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project graphdb by neo4j-attic.
the class TestXaFramework method testCreateXaResource.
@Test
public void testCreateXaResource() throws Exception {
Map<Object, Object> config = new HashMap<Object, Object>();
config.put("store_dir", "target/var");
config.put(LogBufferFactory.class, CommonFactories.defaultLogBufferFactory(config));
xaDsMgr.registerDataSource("dummy_datasource", new DummyXaDataSource(config), UTF8.encode("DDDDDD"));
XaDataSource xaDs = xaDsMgr.getXaDataSource("dummy_datasource");
DummyXaConnection xaC = null;
try {
xaC = (DummyXaConnection) xaDs.getXaConnection();
try {
xaC.doStuff1();
fail("Non enlisted resource should throw exception");
} catch (XAException e) {
// good
}
Xid xid = new XidImpl(new byte[0], new byte[0]);
xaC.getXaResource().start(xid, XAResource.TMNOFLAGS);
try {
xaC.doStuff1();
xaC.doStuff2();
} catch (XAException e) {
fail("Enlisted resource should not throw exception");
}
xaC.getXaResource().end(xid, XAResource.TMSUCCESS);
xaC.getXaResource().prepare(xid);
xaC.getXaResource().commit(xid, false);
} finally {
xaDsMgr.unregisterDataSource("dummy_datasource");
if (xaC != null) {
xaC.destroy();
}
}
// cleanup dummy resource log
File dir = new File(".");
File[] files = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String fileName) {
return fileName.startsWith(resourceFile());
}
});
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project graphdb by neo4j-attic.
the class HighlyAvailableGraphDatabase method tryToEnsureIAmNotABrokenMachine.
private void tryToEnsureIAmNotABrokenMachine(Pair<Master, Machine> master) {
if (master.other().getMachineId() == machineId) {
return;
} else if (master.first() == null) {
// Temporarily disconnected from ZK
RuntimeException cause = new RuntimeException("Unable to get master from ZK");
shutdown(cause, false);
throw cause;
}
XaDataSource nioneoDataSource = getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
long myLastCommittedTx = nioneoDataSource.getLastCommittedTxId();
long highestCommonTxId = Math.min(myLastCommittedTx, master.other().getLastCommittedTxId());
int masterForMyHighestCommonTxId = -1;
try {
masterForMyHighestCommonTxId = nioneoDataSource.getMasterForCommittedTx(highestCommonTxId);
;
} catch (IOException e) {
// This is quite dangerous to just catch here... but the special case is
// where this db was just now copied from the master where there's data,
// but no logical logs were transfered and hence no masterId info is here
msgLog.logMessage("Couldn't get master ID for txId " + highestCommonTxId + ". It may be that a log file is missing due to the db being copied from master?", e);
return;
}
int masterForMastersHighestCommonTxId = master.first().getMasterIdForCommittedTx(highestCommonTxId).response();
// Compare those two, if equal -> good
if (masterForMyHighestCommonTxId == masterForMastersHighestCommonTxId) {
msgLog.logMessage("Master id for last committed tx ok with highestCommonTxId=" + highestCommonTxId + " with masterId=" + masterForMyHighestCommonTxId, true);
return;
} else {
String msg = "Broken store, I (machineId:" + machineId + ") think machineId for txId (" + highestCommonTxId + ") is " + masterForMyHighestCommonTxId + ", but master (machineId:" + master.other().getMachineId() + ") says that it's " + masterForMastersHighestCommonTxId;
msgLog.logMessage(msg, true);
RuntimeException exception = new BranchedDataException(msg);
shutdown(exception, false);
throw exception;
}
}
use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource 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.xaframework.XaDataSource in project graphdb by neo4j-attic.
the class Client method getMyStoreId.
protected StoreId getMyStoreId() {
if (myStoreId == null) {
XaDataSource ds = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
myStoreId = ((NeoStoreXaDataSource) ds).getStoreId();
}
return myStoreId;
}
use of org.neo4j.kernel.impl.transaction.xaframework.XaDataSource in project graphdb by neo4j-attic.
the class MasterUtil method packResponseWithoutTransactionStream.
public static <T> Response<T> packResponseWithoutTransactionStream(GraphDatabaseService graphDb, SlaveContext context, T response) {
XaDataSource ds = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
StoreId storeId = ((NeoStoreXaDataSource) ds).getStoreId();
return new Response<T>(response, storeId, TransactionStream.EMPTY);
}
Aggregations