Search in sources :

Example 1 with NeoStoreXaDataSource

use of org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource 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);
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 2 with NeoStoreXaDataSource

use of org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource 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;
}
Also used : NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 3 with NeoStoreXaDataSource

use of org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource in project graphdb by neo4j-attic.

the class UdcExtensionImpl method load.

@Override
protected UdcTimerTask load(KernelData kernel) {
    MyConfig configuration = new MyConfig(kernel.getConfig(), loadSystemProperties());
    try {
        // break if disabled
        if (configuration.getBool(UDC_DISABLE_KEY, "false"))
            return null;
    } catch (Exception e) {
    // default: not disabled
    }
    int firstDelay = DEFAULT_DELAY;
    int interval = DEFAULT_INTERVAL;
    String hostAddress = DEFAULT_HOST;
    String source = null;
    try {
        firstDelay = configuration.getInt(FIRST_DELAY_CONFIG_KEY, Integer.toString(firstDelay));
    } catch (Exception e) {
    // fall back to default
    }
    try {
        interval = configuration.getInt(INTERVAL_CONFIG_KEY, Integer.toString(interval));
    } catch (Exception e) {
    // fall back to default
    }
    try {
        hostAddress = configuration.getString(UDC_HOST_ADDRESS_KEY, hostAddress);
    } catch (Exception e) {
    // fall back to default
    }
    try {
        source = configuration.getString(UDC_SOURCE_KEY, source);
    } catch (Exception e) {
    // fall back to default
    }
    NeoStoreXaDataSource ds = (NeoStoreXaDataSource) kernel.getConfig().getTxModule().getXaDataSourceManager().getXaDataSource("nioneodb");
    boolean crashPing = ds.getXaContainer().getLogicalLog().wasNonClean();
    String storeId = Long.toHexString(ds.getRandomIdentifier());
    String version = kernel.version().getRevision();
    if (version.equals(""))
        version = kernel.version().getVersion();
    UdcTimerTask task = new UdcTimerTask(hostAddress, version, storeId, source, crashPing);
    timer.scheduleAtFixedRate(task, firstDelay, interval);
    return task;
}
Also used : NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)

Example 4 with NeoStoreXaDataSource

use of org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource 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)

Example 5 with NeoStoreXaDataSource

use of org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource 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

NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)6 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)2 HashSet (java.util.HashSet)1 SlaveContext (org.neo4j.com.SlaveContext)1 Pair (org.neo4j.helpers.Pair)1 Triplet (org.neo4j.helpers.Triplet)1 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)1 LockReleaser (org.neo4j.kernel.impl.core.LockReleaser)1 LockManager (org.neo4j.kernel.impl.transaction.LockManager)1 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)1 LogBuffer (org.neo4j.kernel.impl.transaction.xaframework.LogBuffer)1