use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class NodeStoreTest method newNodeStore.
private NodeStore newNodeStore(FileSystemAbstraction fs, PageCache pageCache) throws IOException {
File storeDir = new File("dir");
fs.mkdirs(storeDir);
idGeneratorFactory = spy(new DefaultIdGeneratorFactory(fs) {
@Override
protected IdGenerator instantiate(FileSystemAbstraction fs, File fileName, int grabSize, long maxValue, boolean aggressiveReuse, long highId) {
return spy(super.instantiate(fs, fileName, grabSize, maxValue, aggressiveReuse, highId));
}
});
StoreFactory factory = new StoreFactory(storeDir, Config.empty(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance());
neoStores = factory.openAllNeoStores(true);
nodeStore = neoStores.getNodeStore();
return nodeStore;
}
use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class TestIdGeneratorRebuilding method verifyDynamicSizedStoresCanRebuildIdGeneratorSlowly.
@Test
public void verifyDynamicSizedStoresCanRebuildIdGeneratorSlowly() throws Exception {
// Given we have a store ...
Config config = Config.embeddedDefaults(MapUtil.stringMap(GraphDatabaseSettings.rebuild_idgenerators_fast.name(), "false"));
StoreFactory storeFactory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), fs, NullLogProvider.getInstance());
NeoStores neoStores = storeFactory.openAllNeoStores(true);
DynamicStringStore store = neoStores.getPropertyStore().getStringStore();
// ... that contain a number of records ...
DynamicRecord record = new DynamicRecord(1);
record.setInUse(true, PropertyType.STRING.intValue());
int highestId = 50;
for (// id '0' is the dynamic store header
int i = 1; // id '0' is the dynamic store header
i <= highestId; // id '0' is the dynamic store header
i++) {
assertThat(store.nextId(), is((long) i));
record.setId(i);
StringBuilder sb = new StringBuilder(i);
for (int j = 0; j < i; j++) {
sb.append('a');
}
record.setData(sb.toString().getBytes("UTF-16"));
store.updateRecord(record);
}
store.setHighestPossibleIdInUse(highestId);
// ... and some have been deleted
Long[] idsToFree = { 2L, 3L, 5L, 7L };
record.setInUse(false);
for (long toDelete : idsToFree) {
record.setId(toDelete);
store.updateRecord(record);
}
// Then when we rebuild the id generator
store.rebuildIdGenerator();
// We should observe that the ids above got freed
List<Long> nextIds = new ArrayList<>();
// 2
nextIds.add(store.nextId());
// 3
nextIds.add(store.nextId());
// 5
nextIds.add(store.nextId());
// 7
nextIds.add(store.nextId());
// 51
nextIds.add(store.nextId());
assertThat(nextIds, contains(2L, 3L, 5L, 7L, 51L));
neoStores.close();
}
use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class TestIdGeneratorRebuilding method rebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage.
@Test
public void rebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage() throws IOException {
// Given we have a store ...
Config config = Config.embeddedDefaults(MapUtil.stringMap(GraphDatabaseSettings.rebuild_idgenerators_fast.name(), "false"));
File storeFile = file("nodes");
DynamicArrayStore labelStore = mock(DynamicArrayStore.class);
NodeStore store = new NodeStore(storeFile, config, new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), NullLogProvider.getInstance(), labelStore, RecordFormatSelector.defaultFormat());
store.initialise(true);
store.makeStoreOk();
// ... that contain enough records to fill several file pages ...
int recordsPerPage = store.getRecordsPerPage();
NodeRecord record = new NodeRecord(0);
record.setInUse(true);
// 3 pages worth of records
int highestId = recordsPerPage * 3;
for (int i = 0; i < highestId; i++) {
assertThat(store.nextId(), is((long) i));
record.setId(i);
store.updateRecord(record);
}
store.setHighestPossibleIdInUse(highestId);
// ... and some records at the end of a page have been deleted
// id's are zero based, hence -2 and -1
Long[] idsToFree = { recordsPerPage - 2L, recordsPerPage - 1L };
record.setInUse(false);
for (long toDelete : idsToFree) {
record.setId(toDelete);
store.updateRecord(record);
}
// Then when we rebuild the id generator
store.rebuildIdGenerator();
store.closeIdGenerator();
// simulate a restart to allow id reuse
store.openIdGenerator();
// We should observe that the ids above got freed
List<Long> nextIds = new ArrayList<>();
// recordsPerPage - 2
nextIds.add(store.nextId());
// recordsPerPage - 1
nextIds.add(store.nextId());
// recordsPerPage * 3 (we didn't use this id in the create-look above)
nextIds.add(store.nextId());
assertThat(nextIds, contains(recordsPerPage - 2L, recordsPerPage - 1L, recordsPerPage * 3L));
store.close();
}
use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class TestIdGeneratorRebuilding method verifyFixedSizeStoresCanRebuildIdGeneratorSlowly.
@Test
public void verifyFixedSizeStoresCanRebuildIdGeneratorSlowly() throws IOException {
// Given we have a store ...
Config config = Config.embeddedDefaults(MapUtil.stringMap(GraphDatabaseSettings.rebuild_idgenerators_fast.name(), "false"));
File storeFile = file("nodes");
DynamicArrayStore labelStore = mock(DynamicArrayStore.class);
NodeStore store = new NodeStore(storeFile, config, new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), NullLogProvider.getInstance(), labelStore, RecordFormatSelector.defaultFormat());
store.initialise(true);
store.makeStoreOk();
// ... that contain a number of records ...
NodeRecord record = new NodeRecord(0);
record.setInUse(true);
int highestId = 50;
for (int i = 0; i < highestId; i++) {
assertThat(store.nextId(), is((long) i));
record.setId(i);
store.updateRecord(record);
}
store.setHighestPossibleIdInUse(highestId);
// ... and some have been deleted
Long[] idsToFree = { 2L, 3L, 5L, 7L };
record.setInUse(false);
for (long toDelete : idsToFree) {
record.setId(toDelete);
store.updateRecord(record);
}
// Then when we rebuild the id generator
store.rebuildIdGenerator();
store.closeIdGenerator();
// simulate a restart to allow id reuse
store.openIdGenerator();
// We should observe that the ids above got freed
List<Long> nextIds = new ArrayList<>();
// 2
nextIds.add(store.nextId());
// 3
nextIds.add(store.nextId());
// 5
nextIds.add(store.nextId());
// 7
nextIds.add(store.nextId());
// 51
nextIds.add(store.nextId());
assertThat(nextIds, contains(2L, 3L, 5L, 7L, 50L));
store.close();
}
use of org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class SchemaStoreTest method before.
@Before
public void before() throws Exception {
File storeDir = new File("dir");
fs.get().mkdirs(storeDir);
config = Config.empty();
DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs.get());
storeFactory = new StoreFactory(storeDir, config, idGeneratorFactory, pageCacheRule.getPageCache(fs.get()), fs.get(), NullLogProvider.getInstance());
neoStores = storeFactory.openAllNeoStores(true);
store = neoStores.getSchemaStore();
}
Aggregations