Search in sources :

Example 1 with AbstractGraphDatabase

use of org.neo4j.kernel.AbstractGraphDatabase in project neo4j-clean-remote-db-addon by jexp.

the class DeleteDatabaseResource method cleanDbDirectory.

private Map<String, Object> cleanDbDirectory(Database database) throws Throwable {
    AbstractGraphDatabase graph = database.graph;
    String storeDir = graph.getStoreDir();
    if (storeDir == null) {
        storeDir = config.getString(DATABASE_LOCATION_PROPERTY_KEY);
    }
    graph.shutdown();
    Map<String, Object> result = removeDirectory(storeDir);
    // TODO wtf?
    // database.graph = new EmbeddedGraphDatabase(storeDir, graph.getKernelData().getConfigParams());
    database.start();
    return result;
}
Also used : AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase)

Example 2 with AbstractGraphDatabase

use of org.neo4j.kernel.AbstractGraphDatabase 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]));
}
Also used : SlaveContext(org.neo4j.com.SlaveContext) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) ArrayList(java.util.ArrayList) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Pair(org.neo4j.helpers.Pair)

Example 3 with AbstractGraphDatabase

use of org.neo4j.kernel.AbstractGraphDatabase in project graphdb by neo4j-attic.

the class TestNode method testLockProblem.

private void testLockProblem(final PropertyContainer entity) throws InterruptedException {
    entity.setProperty("key", "value");
    final AtomicBoolean gotTheLock = new AtomicBoolean();
    Thread thread = new Thread() {

        @Override
        public void run() {
            Transaction tx = getGraphDb().beginTx();
            try {
                ((AbstractGraphDatabase) getGraphDb()).getConfig().getLockManager().getWriteLock(entity);
                gotTheLock.set(true);
                tx.success();
            } catch (RuntimeException e) {
                e.printStackTrace();
                throw e;
            } finally {
                tx.failure();
            }
        }
    };
    thread.start();
    long endTime = System.currentTimeMillis() + 5000;
    while (thread.getState() != State.TERMINATED) {
        Thread.sleep(100);
        if (System.currentTimeMillis() > endTime) {
            break;
        }
    }
    assertFalse(gotTheLock.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase)

Example 4 with AbstractGraphDatabase

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

Example 5 with AbstractGraphDatabase

use of org.neo4j.kernel.AbstractGraphDatabase 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;
}
Also used : XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) IOException(java.io.IOException) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) File(java.io.File) Pair(org.neo4j.helpers.Pair)

Aggregations

AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)7 XaDataSourceManager (org.neo4j.kernel.impl.transaction.XaDataSourceManager)4 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)4 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Pair (org.neo4j.helpers.Pair)2 FileInputStream (java.io.FileInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 SlaveContext (org.neo4j.com.SlaveContext)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 Triplet (org.neo4j.helpers.Triplet)1 StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)1 LogBuffer (org.neo4j.kernel.impl.transaction.xaframework.LogBuffer)1