Search in sources :

Example 6 with AbstractGraphDatabase

use of org.neo4j.kernel.AbstractGraphDatabase 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)

Example 7 with AbstractGraphDatabase

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

the class TestIndexDeletion method indexDeleteShouldDeleteDirectory.

@Test
public void indexDeleteShouldDeleteDirectory() {
    String otherIndexName = "other-index";
    StringBuffer tempPath = new StringBuffer(((AbstractGraphDatabase) graphDb).getStoreDir()).append(File.separator).append("index").append(File.separator).append("lucene").append(File.separator).append("node").append(File.separator);
    File pathToLuceneIndex = new File(tempPath.toString() + INDEX_NAME);
    File pathToOtherLuceneIndex = new File(tempPath.toString() + otherIndexName);
    Index<Node> otherIndex = graphDb.index().forNodes(otherIndexName);
    Node node = graphDb.createNode();
    otherIndex.add(node, "someKey", "someValue");
    assertFalse(pathToLuceneIndex.exists());
    assertFalse(pathToOtherLuceneIndex.exists());
    restartTx();
    // Here "index" and "other-index" indexes should exist
    assertTrue(pathToLuceneIndex.exists());
    assertTrue(pathToOtherLuceneIndex.exists());
    index.delete();
    assertTrue(pathToLuceneIndex.exists());
    assertTrue(pathToOtherLuceneIndex.exists());
    restartTx();
    // Here only "other-index" should exist
    assertFalse(pathToLuceneIndex.exists());
    assertTrue(pathToOtherLuceneIndex.exists());
}
Also used : Node(org.neo4j.graphdb.Node) AbstractGraphDatabase(org.neo4j.kernel.AbstractGraphDatabase) File(java.io.File) Test(org.junit.Test)

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