use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.
/**
* Reading a node command might leave a node record which referred to
* labels in one or more dynamic records as marked as heavy even if that
* node already had references to dynamic records, changed in a transaction,
* but had no labels on that node changed within that same transaction.
* Now defensively only marks as heavy if there were one or more dynamic
* records provided when providing the record object with the label field
* value. This would give the opportunity to load the dynamic records the
* next time that record would be ensured heavy.
*/
@Test
public void shouldRecoverNodeWithDynamicLabelRecords() throws Exception {
// GIVEN
database = new TestGraphDatabaseFactory().setFileSystem(fs).newImpermanentDatabase();
Node node;
Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
try (Transaction tx = database.beginTx()) {
node = database.createNode(labels);
tx.success();
}
// WHEN
try (Transaction tx = database.beginTx()) {
node.setProperty("prop", "value");
tx.success();
}
EphemeralFileSystemAbstraction snapshot = fs.snapshot();
database.shutdown();
database = new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase();
// THEN
try (Transaction ignored = database.beginTx()) {
node = database.getNodeById(node.getId());
for (Label label : labels) {
assertTrue(node.hasLabel(label));
}
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class KernelIntegrationTest method setup.
@Before
public void setup() {
fs = new EphemeralFileSystemAbstraction();
startDb();
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestCrashWithRebuildSlow method crashAndRebuildSlowWithDynamicStringDeletions.
@Test
public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception {
File storeDir = new File("dir").getAbsoluteFile();
final GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase(storeDir);
List<Long> deletedNodeIds = produceNonCleanDefraggedStringStore(db);
Map<IdType, Long> highIdsBeforeCrash = getHighIds(db);
long checksumBefore = fs.get().checksum();
long checksumBefore2 = fs.get().checksum();
assertThat(checksumBefore, Matchers.equalTo(checksumBefore2));
EphemeralFileSystemAbstraction snapshot = fs.snapshot(() -> db.shutdown());
long snapshotChecksum = snapshot.checksum();
if (snapshotChecksum != checksumBefore) {
try (OutputStream out = new FileOutputStream(testDir.file("snapshot.zip"))) {
snapshot.dumpZip(out);
}
try (OutputStream out = new FileOutputStream(testDir.file("fs.zip"))) {
fs.get().dumpZip(out);
}
}
assertThat(snapshotChecksum, equalTo(checksumBefore));
// Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false
assertNumberOfFreeIdsEquals(storeDir, snapshot, 0);
GraphDatabaseAPI newDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase();
Map<IdType, Long> highIdsAfterCrash = getHighIds(newDb);
assertEquals(highIdsBeforeCrash, highIdsAfterCrash);
try (Transaction tx = newDb.beginTx()) {
// Verify that the data we didn't delete is still around
int nameCount = 0;
int relCount = 0;
for (Node node : newDb.getAllNodes()) {
nameCount++;
assertThat(node, inTx(newDb, hasProperty("name"), true));
relCount += Iterables.count(node.getRelationships(Direction.OUTGOING));
}
assertEquals(16, nameCount);
assertEquals(12, relCount);
// Verify that the ids of the nodes we deleted are reused
List<Long> newIds = new ArrayList<>();
newIds.add(newDb.createNode().getId());
newIds.add(newDb.createNode().getId());
newIds.add(newDb.createNode().getId());
newIds.add(newDb.createNode().getId());
assertThat(newIds, is(deletedNodeIds));
tx.success();
} finally {
newDb.shutdown();
snapshot.close();
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class NodeStoreTest method shouldCombineProperFiveByteLabelField.
@Test
public void shouldCombineProperFiveByteLabelField() throws Exception {
// GIVEN
// -- a store
EphemeralFileSystemAbstraction fs = efs.get();
nodeStore = newNodeStore(fs);
// -- a record with the msb carrying a negative value
long nodeId = 0, labels = 0x8000000001L;
NodeRecord record = new NodeRecord(nodeId, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue());
record.setInUse(true);
record.setLabelField(labels, Collections.<DynamicRecord>emptyList());
nodeStore.updateRecord(record);
// WHEN
// -- reading that record back
NodeRecord readRecord = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
// THEN
// -- the label field must be the same
assertEquals(labels, readRecord.getLabelField());
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class NodeStoreTest method shouldFreeSecondaryUnitIdOfShrunkRecord.
@Test
public void shouldFreeSecondaryUnitIdOfShrunkRecord() throws Exception {
// GIVEN
EphemeralFileSystemAbstraction fs = efs.get();
nodeStore = newNodeStore(fs);
NodeRecord record = new NodeRecord(5L);
record.setRequiresSecondaryUnit(true);
record.setSecondaryUnitId(10L);
record.setInUse(true);
nodeStore.updateRecord(record);
nodeStore.setHighestPossibleIdInUse(10L);
// WHEN
record.setRequiresSecondaryUnit(false);
nodeStore.updateRecord(record);
// THEN
IdGenerator idGenerator = idGeneratorFactory.get(IdType.NODE);
verify(idGenerator, times(0)).freeId(5L);
verify(idGenerator).freeId(10L);
}
Aggregations