Search in sources :

Example 26 with DefaultIdGeneratorFactory

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;
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File)

Example 27 with DefaultIdGeneratorFactory

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();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 28 with DefaultIdGeneratorFactory

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();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 29 with DefaultIdGeneratorFactory

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();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 30 with DefaultIdGeneratorFactory

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();
}
Also used : DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File) Before(org.junit.Before)

Aggregations

DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)34 File (java.io.File)18 Config (org.neo4j.kernel.configuration.Config)17 Test (org.junit.Test)13 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)11 Before (org.junit.Before)10 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 PageCache (org.neo4j.io.pagecache.PageCache)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 ArrayList (java.util.ArrayList)3 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 PrintStream (java.io.PrintStream)1