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