Disable writes to disc

How can you disable writes to disc when loading in your OSM file so it only loads to memory? I have tried to set setStoreOnFlush to false but this does not help and setting isAllowWrites to false only gives a “Writes are not allowed!” error.

Which version are you using?

Using version 5.3 upgraded from 0.6.0 in which we didn’t had to specify something to disable writing besides setting it to RAM

What happens when you use setStoreOnFlush(false). I think this should do exactly what you want (or it is broken).

Nothing happens I think since graph car|RAM_STORE|2D|no_turn_cost|nodes:9,edges:21,geometry:6,location_index:5,string_index:6,nodesCH:0,shortcuts:8 still shows RAM_STORE and not RAM

Do you call the init() method as well? After you called setStoreOnFlush()? Maybe there are different settings overwriting each other.

Have this as code:

fun setupGraphhopper(graph: String): GraphHopper? {
        val graphHopperConfig = createDefaultConfig()
        val graphHopper = GraphHopper().apply {
            isAllowWrites = false
            osmFile = graph
            setStoreOnFlush(false)
            setElevation(false)
            setPreciseIndexResolution(1000)
        }

        try {
            graphHopper.init(graphHopperConfig)
        } catch (throwable: Throwable) {
            logger.error(t = throwable) { "Error while creating graphhopper" }
            return null
        }

        graphHopper.importOrLoad()
        return graphHopper
    }

So it is set before the init method

Can you show what createDefaultConfig does?

Nothing special but here is the code:

private fun createDefaultConfig(): GraphHopperConfig {
        val graphHopperConfig = GraphHopperConfig()
        graphHopperConfig.profiles = listOf(Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(false))
        graphHopperConfig.chProfiles = listOf(CHProfile("car"))
        return graphHopperConfig
    }

Generally it is often not a good idea to use the different setters in the GraphHopper class and the init method at the same time. Better use either or. And maybe better just use init… This is one thing I’d like to improve since a long time, but it is not so easy to do unfortunately.

Do you maybe have the docs for me for the different configs I can set with putObject?

I just checked and indeed the init method overwrites the data access type that you chose using setStoreOnFlush before with the default (RAM_STORE), because there is no such setting. So either you need to skip the init call and set the profiles directly on the GraphHopper object (using hopper.setProfiles() and hopper.getCHPreparationHandler().setCHProfiles()). Or you keep calling the init method and instead of setStoreOnFlush you put graphHopperConfig.putObject("graph.dataaccess", "RAM") in your config. You probably still need to call isAllowWrites(false), otherwise you might get an error because the lock file cannot be created. The others you can probably replace with the corresponding config options as well.

I think you should take a look at either config-example.yml in the root folder or directly take a look at the init method.

Should I make a ticket on github for it or is it already a known issue?

I think it is a known issue that the GraphHopper class is a huge mess :slight_smile: For example we have this: rather broad issue: Refactor GraphHopper class · Issue #1895 · graphhopper/graphhopper · GitHub
But I will add a comment to the init method that care needs to be taken when it is combined with the different setters. Would this have helped you?

If you would do so I would appreciate it, have just done it with putObject and it works fine now thanks

I added a comment here: Add comment about GraphHopper#init · graphhopper/graphhopper@c79bb96 · GitHub

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.