Intermediate File Read - hydrays/osrm-backend GitHub Wiki

The intermediate file-write process is mainly in Extractor module and Contractor module. The file-read process is in Route module which could receive HTTP request and do routing process.

中间文件的写入过程主要在Extractor模块Contractor模块中,文件读取过程在Route模块中,该模块可以接收网络请求,并作出导航处理。

The core file of route module is src/tools/routed.cpp. In this file, it record the osrm base file path convenient for file-reading process. Then in the main function of routed.cpp, it initializes ServerHandler type variable service_handler. The initialization statement is as follows.

route模块的核心文件是src/tools/routed.cpp。在这个文件中,它记录了osrm文件的基础路径,便于后续的文件读取过程。然后在route.cpp的main函数中它初始化了ServerHandler类型变量service_handler。初始化语句如下所示。

auto service_handler = std::make_unique<server::ServiceHandler>(config);

This variable is a C++ smart point to ServiceHandler variable. When the program initializes ServiceHandler variable, it initializes OSRM type variable routing_machine. It has a EngineInterface type member variable called engine_.

这个变量是一个C++智能指针,它指向ServiceHandler类型的变量。当程序初始化ServiceHandler类型变量时,它会初始化该变量的成员变量OSRM类型routing_machine。它有一个EngineInterface类型的成员变量叫做engine_

When initializing this member variable, the smart pointer points to a subclass of EngineInterface called Engine. The Engine type variable has a member variable called facade_provider which is DatafacadeProvider type. In OSRM project, datafacade is an important data structure which encapsulate data related to project. This structure is complex, so the interpretation will be show in detail in other page.

当初始化这个成员变量时(engine_),智能指针指向EngineInterface的子类叫做EngineEngine类型的变量有一个DatafacadeProvider类型的成员变量叫做facade_provider。在OSRM项目中,datafacade是一个重要的数据结构,它封装了项目相关的数据。datafacade这个结构很复杂,在其他页中会有该结构的详细解释。

In the initialization of variable engine_, it calls the constructor of Engine class. Here is a code fragment of constructor.

在*engine_*变量的初始化过程中,它调用了Engine类型的构造函数。下面是构造函数的代码片段。

if (config.use_shared_memory)
{
    util::Log(logDEBUG) << "Using shared memory with algorithm " 
                        << algorithm::name<AlgorithmT>();
    facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>();
}
else
{
    util::Log(logDEBUG) << "Using internal memory with algorithm " 
                        << algorithm::name<AlgorithmT>();
    facade_provider = std::make_unique
                         <ImmutableProvider<AlgorithmT>>(config.storage_config);
}

When facade_provider points to WatchingProvider variable, it will initialize a DataWatchDog type member variable. DataWatchDog type variable has a member called facade which points to a SharedMemoryAllocator variable.

facade_provider指向WatchingProvider类型变量时,它将会初始化一个DataWatchDog类型的成员变量。DataWatchDog类型变量的一个成员叫做facade,它指向SharedMemoryAllocator类型变量。

In another case, facade_provider points to ImmutableProvider varible. ImutableProvider class has a member immutable_data_facade which points to a ProcessMemoryAllocator variable.

另一方面,facade_provider指向ImmutableProvider类型变量。ImmutableProvider类有一个成员immutable_data_facade,它指向ProcessMemoryAllocator变量。

SharedMemoryAllocator class and ProcessMemoryAllocator class both are used to load data from intermediate file into memory. The difference between two class is that SharedMemoryAllocator class uses an IPC shared memory block as data location,while ProcessMemoryAllocator class uses a process-local memory block to load data into.

SharedMemoryAllocator类和ProcessMemoryAllocator类都用来从中间文件中把数据加载到内存中。这两个类的不同点在于SharedMemoryAllocator类使用一个IPC(进程间通讯)共享内存块作为数据位置,而ProcessMemoryAllocator类使用一个进程局部内存块在加载数据。

Both class will read the data in intermediate file, and load it into memory. Then other route service like match,route could do data processing and path routing.

这两个类都会从中间文件读取数据加载至内存。其他导航服务像match,route就可以对数据进行处理并且进行路径导航。

⚠️ **GitHub.com Fallback** ⚠️