Search in sources :

Example 1 with LogBuffer

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

the class SlaveTxIdGenerator method generate.

public long generate(final XaDataSource dataSource, final int identifier) {
    try {
        final int eventIdentifier = txManager.getEventIdentifier();
        Response<Long> response = broker.getMaster().first().commitSingleResourceTransaction(receiver.getSlaveContext(eventIdentifier), dataSource.getName(), new TxExtractor() {

            public void extract(LogBuffer buffer) {
                try {
                    dataSource.getPreparedTransaction(identifier, buffer);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            public ReadableByteChannel extract() {
                try {
                    return dataSource.getPreparedTransaction(identifier);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        return receiver.receive(response);
    } catch (ZooKeeperException e) {
        receiver.newMaster(null, e);
        throw e;
    } catch (ComException e) {
        receiver.newMaster(null, e);
        throw e;
    }
}
Also used : ZooKeeperException(org.neo4j.kernel.ha.zookeeper.ZooKeeperException) ComException(org.neo4j.com.ComException) LogBuffer(org.neo4j.kernel.impl.transaction.xaframework.LogBuffer) ReadableByteChannel(java.nio.channels.ReadableByteChannel) TxExtractor(org.neo4j.com.TxExtractor) IOException(java.io.IOException)

Example 2 with LogBuffer

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

the class MasterUtil method packResponse.

public static <T> Response<T> packResponse(GraphDatabaseService graphDb, SlaveContext context, T response, Predicate<Long> filter) {
    List<Triplet<String, Long, TxExtractor>> stream = new ArrayList<Triplet<String, Long, TxExtractor>>();
    Set<String> resourceNames = new HashSet<String>();
    XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
    for (Pair<String, Long> txEntry : context.lastAppliedTransactions()) {
        String resourceName = txEntry.first();
        final XaDataSource dataSource = dsManager.getXaDataSource(resourceName);
        if (dataSource == null) {
            throw new RuntimeException("No data source '" + resourceName + "' found");
        }
        resourceNames.add(resourceName);
        long masterLastTx = dataSource.getLastCommittedTxId();
        for (long txId = txEntry.other() + 1; txId <= masterLastTx; txId++) {
            if (filter.accept(txId)) {
                final long tx = txId;
                TxExtractor extractor = new TxExtractor() {

                    @Override
                    public ReadableByteChannel extract() {
                        try {
                            return dataSource.getCommittedTransaction(tx);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }

                    @Override
                    public void extract(LogBuffer buffer) {
                        try {
                            dataSource.getCommittedTransaction(tx, buffer);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                };
                stream.add(Triplet.of(resourceName, txId, extractor));
            }
        }
    }
    StoreId storeId = ((NeoStoreXaDataSource) dsManager.getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME)).getStoreId();
    return new Response<T>(response, storeId, TransactionStream.create(resourceNames, stream));
}
Also used : XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) Triplet(org.neo4j.helpers.Triplet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) LogBuffer(org.neo4j.kernel.impl.transaction.xaframework.LogBuffer) StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)2 LogBuffer (org.neo4j.kernel.impl.transaction.xaframework.LogBuffer)2 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ComException (org.neo4j.com.ComException)1 TxExtractor (org.neo4j.com.TxExtractor)1 Triplet (org.neo4j.helpers.Triplet)1 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)1 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)1 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)1 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)1 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)1 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)1