Search in sources :

Example 91 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.

@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
    // GIVEN
    LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
    FileSystemAbstraction fs = fsRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
        // skip 7 to emulate the fact we have an hole in the committed tx ids list
        final long expectedTxId = 8L;
        store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
        ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
        // WHEN
        Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
        // THEN
        assertTrue(response instanceof TransactionObligationResponse);
        ((TransactionObligationResponse) response).accept(new Response.Handler() {

            @Override
            public void obligation(long txId) throws IOException {
                assertEquals(expectedTxId, txId);
            }

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
                throw new UnsupportedOperationException("not expected");
            }
        });
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Visitor(org.neo4j.helpers.collection.Visitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) IOException(java.io.IOException) Response(org.neo4j.com.Response) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) RequestContext(org.neo4j.com.RequestContext) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 92 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StoreCopyClientTest method checkStoreCopyClientWithRecordFormats.

private void checkStoreCopyClientWithRecordFormats(String recordFormatsName) throws Exception {
    final File copyDir = new File(testDir.directory(), "copy");
    final File originalDir = new File(testDir.directory(), "original");
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    Config config = Config.empty().augment(stringMap(record_format.name(), recordFormatsName));
    StoreCopyClient copier = new StoreCopyClient(copyDir, config, loadKernelExtensions(), NullLogProvider.getInstance(), fileSystem, pageCache, new StoreCopyClient.Monitor.Adapter(), false);
    final GraphDatabaseAPI original = (GraphDatabaseAPI) startDatabase(originalDir, recordFormatsName);
    StoreCopyClient.StoreCopyRequester storeCopyRequest = new LocalStoreCopyRequester(original, originalDir, fileSystem);
    copier.copyStore(storeCopyRequest, CancellationRequest.NEVER_CANCELLED, MoveAfterCopy.moveReplaceExisting());
    assertFalse(new File(copyDir, TEMP_COPY_DIRECTORY_NAME).exists());
    // Must not throw
    startDatabase(copyDir, recordFormatsName).shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.kernel.configuration.Config) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache)

Example 93 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StoreCopyClientTest method shouldCopyStoreFilesAcrossIfACancellationRequestHappensAfterTheTempStoreHasBeenRecovered.

@Test
public void shouldCopyStoreFilesAcrossIfACancellationRequestHappensAfterTheTempStoreHasBeenRecovered() throws Exception {
    // given
    final File copyDir = new File(testDir.directory(), "copy");
    final File originalDir = new File(testDir.directory(), "original");
    final AtomicBoolean cancelStoreCopy = new AtomicBoolean(false);
    StoreCopyClient.Monitor storeCopyMonitor = new StoreCopyClient.Monitor.Adapter() {

        @Override
        public void finishRecoveringStore() {
            // simulate a cancellation request
            cancelStoreCopy.set(true);
        }
    };
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    StoreCopyClient copier = new StoreCopyClient(copyDir, Config.empty(), loadKernelExtensions(), NullLogProvider.getInstance(), fileSystem, pageCache, storeCopyMonitor, false);
    final GraphDatabaseAPI original = (GraphDatabaseAPI) startDatabase(originalDir);
    try (Transaction tx = original.beginTx()) {
        original.createNode(label("BeforeCopyBegins"));
        tx.success();
    }
    StoreCopyClient.StoreCopyRequester storeCopyRequest = spy(new LocalStoreCopyRequester(original, originalDir, fileSystem));
    // when
    copier.copyStore(storeCopyRequest, cancelStoreCopy::get, MoveAfterCopy.moveReplaceExisting());
    // Then
    GraphDatabaseService copy = startDatabase(copyDir);
    try (Transaction tx = copy.beginTx()) {
        long nodesCount = Iterators.count(copy.findNodes(label("BeforeCopyBegins")));
        assertThat(nodesCount, equalTo(1L));
        assertThat(Iterators.single(copy.findNodes(label("BeforeCopyBegins"))).getId(), equalTo(0L));
        tx.success();
    }
    verify(storeCopyRequest, times(1)).done();
    assertFalse(new File(copyDir, TEMP_COPY_DIRECTORY_NAME).exists());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 94 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StoreCopyClientTest method shouldEndUpWithAnEmptyStoreIfCancellationRequestIssuedJustBeforeRecoveryTakesPlace.

@Test
public void shouldEndUpWithAnEmptyStoreIfCancellationRequestIssuedJustBeforeRecoveryTakesPlace() throws Exception {
    // given
    final File copyDir = new File(testDir.directory(), "copy");
    final File originalDir = new File(testDir.directory(), "original");
    final AtomicBoolean cancelStoreCopy = new AtomicBoolean(false);
    StoreCopyClient.Monitor storeCopyMonitor = new StoreCopyClient.Monitor.Adapter() {

        @Override
        public void finishReceivingStoreFiles() {
            // simulate a cancellation request
            cancelStoreCopy.set(true);
        }
    };
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    StoreCopyClient copier = new StoreCopyClient(copyDir, Config.empty(), loadKernelExtensions(), NullLogProvider.getInstance(), fileSystem, pageCache, storeCopyMonitor, false);
    final GraphDatabaseAPI original = (GraphDatabaseAPI) startDatabase(originalDir);
    try (Transaction tx = original.beginTx()) {
        original.createNode(label("BeforeCopyBegins"));
        tx.success();
    }
    StoreCopyClient.StoreCopyRequester storeCopyRequest = spy(new LocalStoreCopyRequester(original, originalDir, fileSystem));
    // when
    copier.copyStore(storeCopyRequest, cancelStoreCopy::get, MoveAfterCopy.moveReplaceExisting());
    // Then
    GraphDatabaseService copy = startDatabase(copyDir);
    try (Transaction tx = copy.beginTx()) {
        long nodesCount = Iterators.count(copy.findNodes(label("BeforeCopyBegins")));
        assertThat(nodesCount, equalTo(0L));
        tx.success();
    }
    verify(storeCopyRequest, times(1)).done();
    assertFalse(new File(copyDir, TEMP_COPY_DIRECTORY_NAME).exists());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 95 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class RecordFormatSelectorTest method selectForStoreWithInvalidStoreVersion.

@Test
public void selectForStoreWithInvalidStoreVersion() throws IOException {
    PageCache pageCache = getPageCache();
    prepareNeoStoreFile("v9.Z.9", pageCache);
    assertNull(selectForStore(storeDir, fs, getPageCache(), LOG));
}
Also used : PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

PageCache (org.neo4j.io.pagecache.PageCache)134 Test (org.junit.Test)90 File (java.io.File)74 Config (org.neo4j.kernel.configuration.Config)39 IOException (java.io.IOException)32 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)31 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)19 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)16 PagedFile (org.neo4j.io.pagecache.PagedFile)15 LogService (org.neo4j.kernel.impl.logging.LogService)13 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)12 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)12 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)12 NeoStores (org.neo4j.kernel.impl.store.NeoStores)11 RecordFormatSelector.selectForConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig)11 RecordFormatSelector.selectForStoreOrConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig)11 Before (org.junit.Before)10 TransactionId (org.neo4j.kernel.impl.store.TransactionId)10 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)9