use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class NeoStoresTest method shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent.
@Test
public void shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent() throws IOException {
FileSystemAbstraction fileSystem = fs.get();
File neoStoreDir = new File("/tmp/graph.db/neostore").getAbsoluteFile();
StoreFactory factory = newStoreFactory(neoStoreDir, pageCache, fileSystem);
long recordVersion = defaultStoreVersion();
try (NeoStores neoStores = factory.openAllNeoStores(true)) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
metaDataStore.setCreationTime(3);
metaDataStore.setRandomNumber(4);
metaDataStore.setCurrentLogVersion(5);
metaDataStore.setLastCommittedAndClosedTransactionId(6, 42, BASE_TX_COMMIT_TIMESTAMP, 43, 44);
metaDataStore.setStoreVersion(recordVersion);
metaDataStore.setGraphNextProp(8);
metaDataStore.setLatestConstraintIntroducingTx(9);
}
File file = new File(neoStoreDir, MetaDataStore.DEFAULT_NAME);
assertNotEquals(10, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID));
assertNotEquals(11, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM));
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID, 10);
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM, 11);
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TIME, 12);
try (NeoStores neoStores = factory.openAllNeoStores()) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
assertEquals(3, metaDataStore.getCreationTime());
assertEquals(4, metaDataStore.getRandomNumber());
assertEquals(5, metaDataStore.getCurrentLogVersion());
assertEquals(6, metaDataStore.getLastCommittedTransactionId());
assertEquals(recordVersion, metaDataStore.getStoreVersion());
assertEquals(8, metaDataStore.getGraphNextProp());
assertEquals(9, metaDataStore.getLatestConstraintIntroducingTx());
assertEquals(new TransactionId(10, 11, BASE_TX_COMMIT_TIMESTAMP), metaDataStore.getUpgradeTransaction());
assertEquals(12, metaDataStore.getUpgradeTime());
assertArrayEquals(metaDataStore.getLastClosedTransaction(), new long[] { 6, 44, 43 });
}
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, 13);
try (NeoStores neoStores = factory.openAllNeoStores()) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
assertEquals(new TransactionId(10, 11, 13), metaDataStore.getUpgradeTransaction());
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class NeoStoresTest method shouldCloseAllTheStoreEvenIfExceptionsAreThrown.
@Test
public void shouldCloseAllTheStoreEvenIfExceptionsAreThrown() throws Exception {
// given
FileSystemAbstraction fileSystem = fs.get();
Config defaults = Config.embeddedDefaults(singletonMap(counts_store_rotation_timeout.name(), "60m"));
StoreFactory factory = new StoreFactory(storeDir, defaults, new DefaultIdGeneratorFactory(fileSystem), pageCache, fileSystem, NullLogProvider.getInstance());
NeoStores neoStore = factory.openAllNeoStores(true);
// let's hack the counts store so it fails to rotate and hence it fails to close as well...
final CountsTracker counts = neoStore.getCounts();
counts.start();
long nextTxId = neoStore.getMetaDataStore().getLastCommittedTransactionId() + 1;
AtomicReference<Throwable> exRef = new AtomicReference<>();
Thread thread = new Thread(() -> {
try {
counts.rotate(nextTxId);
} catch (InterruptedIOException e) {
// expected due to the interrupted below
} catch (Throwable e) {
exRef.set(e);
throw new RuntimeException(e);
}
});
thread.start();
// let's wait for the thread to start waiting for the next transaction id
ThreadTestUtils.awaitThreadState(thread, 500, Thread.State.TIMED_WAITING, Thread.State.WAITING);
try {
// when we close the stores...
neoStore.close();
fail("should have thrown2");
} catch (IllegalStateException ex) {
// then
assertEquals("Cannot stop in state: rotating", ex.getMessage());
}
thread.interrupt();
thread.join();
// and the page cache closes with no errors
pageCache.close();
// and only InterruptedIOException is thrown in the other thread
assertNull(exRef.get());
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class NodeStoreTest method shouldCloseStoreFileOnFailureToOpen.
@Test
public void shouldCloseStoreFileOnFailureToOpen() throws Exception {
// GIVEN
final AtomicBoolean fired = new AtomicBoolean();
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(efs.get()) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public int read(ByteBuffer dst) throws IOException {
Exception stack = new Exception();
if (containsStackTraceElement(stack, item -> item.getMethodName().equals("initGenerator")) && !containsStackTraceElement(stack, item -> item.getMethodName().equals("createNodeStore"))) {
fired.set(true);
throw new IOException("Proving a point here");
}
return super.read(dst);
}
};
}
};
// WHEN
try (PageCache pageCache = pageCacheRule.getPageCache(fs)) {
newNodeStore(fs);
fail("Should fail");
}// Close the page cache here so that we can see failure to close (due to still mapped files)
catch (Exception e) {
// THEN
assertTrue(contains(e, IOException.class));
assertTrue(fired.get());
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class StoreFactoryTest method shouldHandleStoreConsistingOfOneEmptyFile.
@Test
public void shouldHandleStoreConsistingOfOneEmptyFile() throws Exception {
StoreFactory storeFactory = storeFactory(Config.empty());
FileSystemAbstraction fs = fsRule.get();
fs.create(new File(storeDir, "neostore.nodestore.db.labels"));
storeFactory.openAllNeoStores(true).close();
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class StoreFactoryTest method shouldCompleteInitializationOfStoresWithIncompleteHeaders.
@Test
public void shouldCompleteInitializationOfStoresWithIncompleteHeaders() throws Exception {
StoreFactory storeFactory = storeFactory(Config.empty());
storeFactory.openAllNeoStores(true).close();
FileSystemAbstraction fs = fsRule.get();
for (File f : fs.listFiles(storeDir)) {
fs.truncate(f, 0);
}
storeFactory.openAllNeoStores(true).close();
}
Aggregations