CN103530420B - The dynamic updating method and device of data file - Google Patents
The dynamic updating method and device of data file Download PDFInfo
- Publication number
- CN103530420B CN103530420B CN201310526090.3A CN201310526090A CN103530420B CN 103530420 B CN103530420 B CN 103530420B CN 201310526090 A CN201310526090 A CN 201310526090A CN 103530420 B CN103530420 B CN 103530420B
- Authority
- CN
- China
- Prior art keywords
- data file
- variable
- shared memory
- address
- stored
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 94
- 230000008569 process Effects 0.000 claims abstract description 54
- 230000015654 memory Effects 0.000 claims description 80
- 230000008859 change Effects 0.000 claims description 6
- 230000000694 effects Effects 0.000 abstract description 4
- 238000012423 maintenance Methods 0.000 description 8
- 230000008901 benefit Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 230000007547 defect Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 238000000429 assembly Methods 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及一种数据文件的动态更新方法及装置。该方法包括:当数据文件需要更新时,将更新后的数据文件存储到第二存储空间,其中,更新前的数据文件存储在第一存储空间中;将预设的最新数据文件的存储地址从第一存储空间的地址变更为第二存储空间的地址;当有进程访问数据文件时,根据预设的最新数据文件的存储地址,查找并访问第二存储空间中存储的更新后的数据文件。通过本发明提供的数据文件的动态更新方法及装置,实现了在数据库正常运行的过程中动态加载数据文件的技术效果。
The invention relates to a method and device for dynamically updating data files. The method includes: when the data file needs to be updated, storing the updated data file in the second storage space, wherein the data file before updating is stored in the first storage space; The address of the first storage space is changed to the address of the second storage space; when a process accesses the data file, the updated data file stored in the second storage space is searched and accessed according to the preset storage address of the latest data file. Through the dynamic update method and device of the data file provided by the invention, the technical effect of dynamically loading the data file during the normal operation of the database is realized.
Description
技术领域technical field
本发明涉及网络通信技术领域,具体涉及一种数据文件的动态更新方法及装置。The invention relates to the technical field of network communication, in particular to a method and device for dynamically updating data files.
背景技术Background technique
目前,数据库的应用范围越来越广泛,通过数据库能够对现实生活中的数据信息进行有效的管理。随着实际情况的变化,在数据库中用于存储数据信息的数据文件也要时常进行更新,以满足实际需求。At present, the application scope of the database is more and more extensive, and the data information in real life can be effectively managed through the database. As the actual situation changes, the data files used to store data information in the database should also be updated frequently to meet actual needs.
例如,IPQuery库是一种常用的PHP扩展数据库,其中的数据文件内存储了有关地址、天气等方面的信息,从而能够为用户提供相关信息的查询。为了确保查询信息的正确性和及时性,需要有专门的运维人员对IPQuery库中的数据文件进行维护和更新。For example, the IPQuery library is a commonly used PHP extension database, in which data files store information about addresses, weather, etc., so as to provide users with relevant information queries. In order to ensure the correctness and timeliness of query information, special operation and maintenance personnel are required to maintain and update the data files in the IPQuery library.
目前,IPQuery库在初次启动时把数据文件内的数据按一定的格式加载到内存中,并对外提供用于查询的IPQuery接口,以供其他进程(例如PHP进程)调用。当数据文件需要更新时,只能先关闭IPQuery库,并用更新后的数据文件覆盖原来的数据文件,之后重新启动IPQuery库,在重启的过程中,先要删除内存中原有的数据文件,再将更新后的数据文件加载到内存中,从而实现IPQuery库中的数据文件的更新。然而,从IPQuery库关闭的时间点至更新后的数据文件加载完成的时间点之间的这段时间内,将导致IPQuery库无法正常处理用户的访问请求,从而给用户带来不便。At present, the IPQuery library loads the data in the data file into the memory in a certain format when it is first started, and provides an IPQuery interface for querying for other processes (such as PHP processes) to call. When the data file needs to be updated, you can only close the IPQuery library first, and overwrite the original data file with the updated data file, and then restart the IPQuery library. During the restart process, first delete the original data file in the memory, and then replace the The updated data file is loaded into the memory, thereby realizing the update of the data file in the IPQuery library. However, during the period from the time point when the IPQuery library is closed to the time point when the updated data file is loaded, the IPQuery library will not be able to process the user's access request normally, thereby causing inconvenience to the user.
另外,在上述过程中,也可能由于意外原因导致IPQuery库未能成功重启,从而使该库无法正常使用。为此,还需要由运维人员实时跟踪数据文件的加载结果,一旦出现失败的情况还要单独进行处理,从而增加了大量的运维成本。In addition, in the above process, the IPQuery library may fail to restart due to unexpected reasons, so that the library cannot be used normally. For this reason, it is also necessary for the operation and maintenance personnel to track the loading results of the data files in real time. Once a failure occurs, it must be processed separately, which increases a lot of operation and maintenance costs.
发明内容Contents of the invention
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决上述问题的数据文件的动态更新方法及装置。In view of the above problems, the present invention is proposed to provide a method and device for dynamically updating data files that overcome the above problems or at least partially solve the above problems.
依据本发明的一个方面,提供了一种数据文件的动态更新方法,包括:当数据文件需要更新时,将更新后的数据文件存储到第二存储空间,其中,更新前的数据文件存储在第一存储空间中;将预设的最新数据文件的存储地址从第一存储空间的地址变更为第二存储空间的地址;当有进程访问数据文件时,根据预设的最新数据文件的存储地址,查找并访问第二存储空间中存储的更新后的数据文件。According to one aspect of the present invention, a method for dynamically updating data files is provided, including: when the data files need to be updated, storing the updated data files in the second storage space, wherein the data files before updating are stored in the second storage space. In a storage space; the storage address of the preset latest data file is changed from the address of the first storage space to the address of the second storage space; when a process accesses the data file, according to the storage address of the preset latest data file, Find and access the updated data files stored in the second storage space.
可选地,预设的最新数据文件的存储地址通过第一变量表示,则将预设的最新数据文件的存储地址从第一存储空间的地址变更为第二存储空间的地址的步骤包括:将第一变量的值从第一存储空间的地址变更为第二存储空间的地址。Optionally, the storage address of the preset latest data file is represented by the first variable, then the step of changing the storage address of the preset latest data file from the address of the first storage space to the address of the second storage space includes: The value of the first variable is changed from the address of the first storage space to the address of the second storage space.
可选地,根据最新数据文件的存储地址,查找并访问第二存储空间中存储的更新后的数据文件的步骤包括:获取第一变量的值,将第一变量的值与本地存储的第二变量的值进行比较,其中,第二变量用于表示当前使用的数据文件的存储地址;若比较结果不同,则先将第一变量的值赋给第二变量,再查找并访问第二变量对应的存储地址中的数据文件。Optionally, according to the storage address of the latest data file, the step of finding and accessing the updated data file stored in the second storage space includes: obtaining the value of the first variable, and combining the value of the first variable with the second Variable values are compared, wherein the second variable is used to indicate the storage address of the currently used data file; if the comparison results are different, first assign the value of the first variable to the second variable, and then search and access the corresponding The data file in the storage address of .
可选地,第二变量为全局变量。Optionally, the second variable is a global variable.
可选地,数据文件为IPQuery数据文件,进程为PHP进程。Optionally, the data file is an IPQuery data file, and the process is a PHP process.
依据本发明的另一方面,提供了一种数据文件的动态更新装置,包括:存储单元,适于当数据文件需要更新时,将更新后的数据文件存储到第二存储空间,其中,更新前的数据文件存储在第一存储空间中;变更单元,适于将预设的最新数据文件的存储地址从第一存储空间的地址变更为第二存储空间的地址;查找单元,适于当有进程访问数据文件时,根据预设的最新数据文件的存储地址,查找并访问第二存储空间中存储的更新后的数据文件。According to another aspect of the present invention, a device for dynamically updating data files is provided, including: a storage unit adapted to store the updated data files in the second storage space when the data files need to be updated, wherein, before the update The data file is stored in the first storage space; the change unit is adapted to change the storage address of the preset latest data file from the address of the first storage space to the address of the second storage space; the search unit is suitable for when there is a process When accessing the data file, the updated data file stored in the second storage space is searched for and accessed according to the preset storage address of the latest data file.
可选地,预设的最新数据文件的存储地址通过第一变量表示,则变更单元用于将第一变量的值从第一存储空间的地址变更为第二存储空间的地址。Optionally, the preset storage address of the latest data file is represented by the first variable, and the changing unit is configured to change the value of the first variable from the address of the first storage space to the address of the second storage space.
可选地,查找单元用于:获取第一变量的值,将第一变量的值与本地存储的第二变量的值进行比较,其中,第二变量用于表示当前使用的数据文件的存储地址;若比较结果不同,则先将第一变量的值赋给第二变量,再查找并访问第二变量对应的存储地址中的数据文件。Optionally, the search unit is configured to: acquire the value of the first variable, and compare the value of the first variable with the value of the second variable stored locally, wherein the second variable is used to represent the storage address of the currently used data file ; If the comparison results are different, first assign the value of the first variable to the second variable, and then search and access the data file in the storage address corresponding to the second variable.
可选地,第二变量为全局变量。Optionally, the second variable is a global variable.
可选地,数据文件为IPQuery数据文件,进程为PHP进程。Optionally, the data file is an IPQuery data file, and the process is a PHP process.
在本发明提供的数据文件的动态更新方法及装置中,将更新前后的数据文件分别存储到不同的存储空间内,并通过预设的最新数据文件的存储地址来标识更新后的数据文件的位置,因而,进程能够在该位置访问到更新后的数据文件。由于更新前后的数据文件的存储空间不同,因而避免了现有技术中必须先删除内存中存储的更新前的数据文件,之后才能在同一内存中加载更新后的数据文件的缺陷,以及由此导致的重启数据库及相关的运维问题。通过本发明提供的数据文件的动态更新方法及装置,实现了在数据库正常运行的过程中动态加载数据文件的技术效果。In the method and device for dynamically updating data files provided by the present invention, the data files before and after the update are respectively stored in different storage spaces, and the location of the updated data file is identified by the preset storage address of the latest data file , so the process can access the updated data file at this location. Because the storage space of the data files before and after the update is different, thus avoiding the defects in the prior art that the data files before the update stored in the internal memory must be deleted first, and then the updated data files can be loaded in the same internal memory, and the resulting Restart the database and related operation and maintenance issues. Through the dynamic update method and device of the data file provided by the invention, the technical effect of dynamically loading the data file during the normal operation of the database is realized.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the description, and in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable , the specific embodiments of the present invention are enumerated below.
附图说明Description of drawings
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention. Also throughout the drawings, the same reference numerals are used to designate the same components. In the attached picture:
图1示出了根据本发明实施例提供的数据文件的动态更新方法的方法流程图;Fig. 1 shows the method flowchart of the method for dynamically updating data files provided according to an embodiment of the present invention;
图2示出了本发明优选实施例提供的IPQuery数据文件的动态更新方法的流程图;Fig. 2 shows the flowchart of the dynamic updating method of the IPQuery data file that the preferred embodiment of the present invention provides;
图3示出了本发明优选实施例中访问更新后的IPQuery数据文件的方法流程图;以及Fig. 3 shows the flow chart of the method for visiting the IPQuery data file after updating in the preferred embodiment of the present invention; And
图4示出了根据本发明实施例提供的数据文件的动态更新装置的结构示意图。Fig. 4 shows a schematic structural diagram of an apparatus for dynamically updating data files according to an embodiment of the present invention.
具体实施方式detailed description
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided for more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
本发明实施例提供了一种数据文件的动态更新方法及装置,用以解决现有技术中更新数据文件时必须重启数据库,且在重启过程中无法处理用户的访问请求的问题。Embodiments of the present invention provide a method and device for dynamically updating data files, which are used to solve the problem in the prior art that the database must be restarted when updating data files, and the user's access request cannot be processed during the restart process.
图1示出了本发明实施例提供的数据文件的动态更新方法的流程图。如图1所示,该方法起始于步骤S110,在步骤S110中,当数据文件需要更新时,将更新后的数据文件存储到第二存储空间,其中,更新前的数据文件存储在第一存储空间中。FIG. 1 shows a flowchart of a method for dynamically updating data files provided by an embodiment of the present invention. As shown in Figure 1, the method starts at step S110. In step S110, when the data file needs to be updated, the updated data file is stored in the second storage space, wherein the data file before the update is stored in the first storage space. in storage space.
接下来,在步骤S120中,将预设的最新数据文件的存储地址从上述第一存储空间的地址变更为上述第二存储空间的地址。Next, in step S120, the storage address of the preset latest data file is changed from the address of the first storage space to the address of the second storage space.
其中,预设的最新数据文件的存储地址可以通过第一变量来表示,此时,步骤S120中将预设的最新数据文件的存储地址从上述第一存储空间的地址变更为上述第二存储空间的地址的操作是通过将上述第一变量的值从上述第一存储空间的地址变更为上述第二存储空间的地址来实现的。Wherein, the storage address of the preset latest data file can be represented by the first variable, at this time, in step S120, the storage address of the preset latest data file is changed from the address of the above-mentioned first storage space to the above-mentioned second storage space The operation of the address of is realized by changing the value of the above-mentioned first variable from the address of the above-mentioned first storage space to the address of the above-mentioned second storage space.
最后,在步骤S130中,当有进程访问该数据文件时,根据步骤S120中预设的最新数据文件的存储地址,查找并访问上述第二存储空间中存储的更新后的数据文件。Finally, in step S130, when a process accesses the data file, the updated data file stored in the above-mentioned second storage space is searched and accessed according to the storage address of the latest data file preset in step S120.
具体地,步骤S130的实现方式包括:获取上述第一变量的值,将上述第一变量的值与本地存储的第二变量的值进行比较,其中,第二变量用于表示当前使用的数据文件的存储地址;若比较结果不同,则先将上述第一变量的值赋给上述第二变量,使第二变量的值与第一变量的值相同,然后再查找并访问第二变量对应的存储地址中的数据文件,从而确保当前使用的数据文件为最新的数据文件。Specifically, the implementation of step S130 includes: acquiring the value of the above-mentioned first variable, and comparing the value of the above-mentioned first variable with the value of the locally stored second variable, wherein the second variable is used to represent the currently used data file storage address; if the comparison results are different, first assign the value of the first variable to the second variable so that the value of the second variable is the same as the value of the first variable, and then search and access the storage corresponding to the second variable The data file in the address, so as to ensure that the data file currently in use is the latest data file.
可选地,上述的第二变量是一个全局变量,以便确保在进程的整个运行周期内都能使用。Optionally, the above-mentioned second variable is a global variable, so as to ensure that it can be used throughout the running period of the process.
由此可见,在本发明实施例提供的数据文件的动态更新方法中,将更新前后的数据文件分别存储到不同的存储空间内,并通过预设的最新数据文件的存储地址来标识更新后的数据文件的位置,因而,进程能够在该位置访问到更新后的数据文件。由此避免了现有技术中必须先删除内存中存储的更新前的数据文件,之后才能在同一内存中加载更新后的数据文件的缺陷,以及由此导致的重启数据库及相关的运维问题。It can be seen that, in the method for dynamically updating data files provided by the embodiment of the present invention, the data files before and after the update are respectively stored in different storage spaces, and the updated data files are identified by the preset storage address of the latest data file. The location of the data file where the process can access the updated data file. This avoids the defects in the prior art that the data files before the update stored in the memory must be deleted first, and then the updated data files can be loaded in the same memory, as well as restarting the database and related operation and maintenance problems caused thereby.
本发明实施例提供的数据文件的动态更新方法能够广泛应用于各类数据库中的数据文件。在下文描述的本发明的优选实施例中,将以IPQuery数据文件的动态更新过程为例进行介绍。但本领域技术人员能够理解的是,本发明提供的数据文件的动态更新方法还可以应用于其他各类数据文件。The method for dynamically updating data files provided by the embodiments of the present invention can be widely applied to data files in various databases. In the preferred embodiment of the present invention described below, the dynamic update process of the IPQuery data file will be taken as an example for introduction. However, those skilled in the art can understand that the method for dynamically updating data files provided by the present invention can also be applied to other types of data files.
图2示出了本发明优选实施例提供的IPQuery数据文件的动态更新方法的流程图。如图2所示,该方法起始于步骤S210,在步骤S210中,预先创建变量F_KEY。Fig. 2 shows a flowchart of a method for dynamically updating IPQuery data files provided by a preferred embodiment of the present invention. As shown in FIG. 2, the method starts at step S210, and in step S210, a variable F_KEY is created in advance.
其中,变量F_KEY的作用在于:指示最新数据文件的存储地址。具体实现时,可以直接将变量F_KEY的值取值为最新数据文件的存储地址。或者,也可以将变量F_KEY的值取值为一块预设的代理共享内存的存储地址,然后,在该代理共享内存中存储最新数据文件的存储地址。在本实施例中采用后一种方式实现。Among them, the function of the variable F_KEY is to indicate the storage address of the latest data file. During specific implementation, the value of the variable F_KEY can be directly set as the storage address of the latest data file. Alternatively, the value of the variable F_KEY can also be set as a storage address of a preset proxy shared memory, and then the storage address of the latest data file is stored in the proxy shared memory. In this embodiment, the latter method is adopted.
其中,代理共享内存是指:为共享内存提供代理服务的内存空间。具体地,在本发明实施例中,将更新前后的数据文件分别存储在不同的共享内存中,通过共享内存的使用能够使多个PHP进程同时访问同一块内存空间,以实现同时为多个PHP进程服务的目的。但是,由于更新前后的数据文件分别存储在不同的共享内存中,因此,在本发明中,为了使访问数据文件的PHP进程能够明确知道哪一个共享内存中存储的是最新的数据文件而引入了代理共享内存的概念。也就是说,代理共享内存对本发明中的各个共享内存进行管理,访问数据文件的PHP进程需要先通过代理共享内存获取到当前存储最新数据文件的共享内存的地址。而且,采用代理共享内存的优势还在于:能够在代理共享内存中存储最新数据文件的其他相关信息(例如长度信息),从而能够为用户的访问带来更多的便利。Wherein, the proxy shared memory refers to a memory space that provides proxy services for the shared memory. Specifically, in the embodiment of the present invention, the data files before and after the update are respectively stored in different shared memories, and through the use of shared memories, multiple PHP processes can access the same memory space at the same time, so as to realize simultaneous processing for multiple PHP processes. The purpose of the process service. However, since the data files before and after the update are stored in different shared memories respectively, in the present invention, in order to make the PHP process accessing the data files know clearly which shared memory stores the latest data files, the The concept of agent shared memory. That is to say, the proxy shared memory manages each shared memory in the present invention, and the PHP process accessing the data file needs to obtain the address of the shared memory currently storing the latest data file through the proxy shared memory. Moreover, the advantage of using the proxy shared memory is that other relevant information (such as length information) of the latest data file can be stored in the proxy shared memory, thereby bringing more convenience to the user's access.
接下来,当需要更新数据文件时执行步骤S220,在步骤S220中,查找变量F_KEY所指示的代理共享内存是否存在,若存在,则说明IPQuery数据库已经启动,继续执行步骤S230;若不存在,则说明IPQuery数据库没有启动,因而不需要采用本发明中的方法来动态更新数据文件,直接退出程序。Next, when the data file needs to be updated, step S220 is executed. In step S220, whether the agent shared memory indicated by the variable F_KEY is searched exists. If it exists, it means that the IPQuery database has been started, and step S230 is continued; if it does not exist, then It shows that the IPQuery database is not started, so it is not necessary to use the method of the present invention to dynamically update the data file, and directly exit the program.
在步骤S230中,将代理共享内存加载到当前进程(即执行动态更新数据文件这一操作的进程)的进程空间中,使当前进程有权限对代理共享内存中的存储内容进行修改。In step S230, the proxy shared memory is loaded into the process space of the current process (that is, the process performing the operation of dynamically updating data files), so that the current process has the right to modify the stored content in the proxy shared memory.
然后,在步骤S240中,申请第二共享内存,并将更新后的数据文件加载到第二共享内存中。由此可见,第二共享内存用来存储更新后的数据文件,其地址不同于更新前的数据文件所对应的第一共享内存的地址。具体实现时,可以先通过函数ftok随机创建变量B_KEY(即B_KEY=ftok()),然后由变量B_KEY来指示第二共享内存的地址。Then, in step S240, apply for a second shared memory, and load the updated data file into the second shared memory. It can be seen that the second shared memory is used to store the updated data file, and its address is different from the address of the first shared memory corresponding to the data file before the update. In specific implementation, the variable B_KEY can be randomly created through the function ftok (that is, B_KEY=ftok()), and then the variable B_KEY can indicate the address of the second shared memory.
最后,在步骤S250中,把第二共享内存的地址(即变量B_KEY的值)和第二共享内存的大小写入代理共享内存中,并在当前进程中卸载代理共享内存,以退出当前进程对代理共享内存的修改操作。Finally, in step S250, the address of the second shared memory (i.e. the value of the variable B_KEY) and the size of the second shared memory are written in the proxy shared memory, and the proxy shared memory is unloaded in the current process to exit the current process. Proxy modification operations for shared memory.
通过上面的步骤就完成了IPQuery数据文件的动态更新过程。另外,当下次再需要对第二共享内存中的数据文件进行更新时,可以再申请第三共享内存……或者,也可以先删除第一共享内存中的数据文件,然后将再次更新后的数据文件存储到第一共享内存中,并将代理共享内存中存储的地址修改为第一共享内存的地址,这样,通过第一共享内存和第二共享内存的交替使用,只需两块共享内存即可实现多次动态更新的目的,从而实现节约存储空间的效果。Through the above steps, the dynamic update process of the IPQuery data file is completed. In addition, when the data files in the second shared memory need to be updated next time, you can apply for the third shared memory...or, you can also delete the data files in the first shared memory first, and then update the updated data The file is stored in the first shared memory, and the address stored in the agent shared memory is changed to the address of the first shared memory. In this way, only two pieces of shared memory are required to use the first shared memory and the second shared memory alternately. The purpose of multiple dynamic updates can be realized, thereby achieving the effect of saving storage space.
图3示出了本发明优选实施例中访问更新后的IPQuery数据文件的方法流程图。如图3所示,当PHP进程要访问IPQuery数据文件时,首先,执行步骤S310,在步骤S310中,对SDK参数的有效性进行检查,以便过滤掉其中的无效参数,提高程序运行的效率。其中,执行步骤S310的主要作用在于对程序的运行效率进行优化,因此,步骤S310并不是一个必需的步骤,只是一个优选的步骤。Fig. 3 shows a flowchart of a method for accessing an updated IPQuery data file in a preferred embodiment of the present invention. As shown in Figure 3, when the PHP process wants to access the IPQuery data file, first, step S310 is executed, and in step S310, the validity of SDK parameters is checked, so as to filter out invalid parameters therein and improve the efficiency of program operation. Wherein, the main function of performing step S310 is to optimize the operating efficiency of the program, therefore, step S310 is not a necessary step, but an optimal step.
在步骤S320中,当PHP进程调用IPQuery接口时,会通过上述的F_KEY变量获取到代理共享内存的地址,并对代理共享内存中存储的内容进行访问。在本步骤中,PHP进程将代理共享内存中存储的内容(即更新后的数据文件的存储地址)赋值给预设的T_KEY变量。In step S320, when the PHP process calls the IPQuery interface, the address of the proxy shared memory will be obtained through the above-mentioned F_KEY variable, and the content stored in the proxy shared memory will be accessed. In this step, the PHP process assigns the content stored in the proxy shared memory (that is, the storage address of the updated data file) to the preset T_KEY variable.
另外,在每个PHP进程中,还预先存储有一个全局变量G_KEY,用来表示PHP进程当前使用的数据文件的存储地址。因此,在步骤S320中,PHP进程比较T_KEY变量与G_KEY变量的值是否相等。如果相等,则说明G_KEY变量所对应的共享内存中的数据文件已经是最新的数据文件,因而执行步骤S340,直接访问G_KEY变量所对应的共享内存中的数据文件。如果不相等,则说明G_KEY变量所对应的共享内存中的数据文件不是最新的数据文件,因而执行步骤S330,在步骤S330中,先卸载G_KEY变量所对应的共享内存,然后将T_KEY变量的值赋给G_KEY变量,再加载G_KEY变量所对应的共享内存,以便访问到最新的数据文件。In addition, in each PHP process, a global variable G_KEY is also stored in advance, which is used to indicate the storage address of the data file currently used by the PHP process. Therefore, in step S320, the PHP process compares whether the values of the T_KEY variable and the G_KEY variable are equal. If they are equal, it means that the data file in the shared memory corresponding to the G_KEY variable is already the latest data file, so step S340 is executed to directly access the data file in the shared memory corresponding to the G_KEY variable. If they are not equal, it means that the data file in the shared memory corresponding to the G_KEY variable is not the latest data file, so step S330 is executed. In step S330, the shared memory corresponding to the G_KEY variable is first unloaded, and then the value of the T_KEY variable is assigned to Give the G_KEY variable, and then load the shared memory corresponding to the G_KEY variable, so as to access the latest data file.
在本优选实施例中,以PHP进程访问IPQuery数据文件的实现方式为例进行了介绍,本领域技术人员能够理解的是,当其他的非PHP进程访问IPQuery数据文件时,也可以采用本发明提供的方法。In this preferred embodiment, the implementation of the PHP process accessing the IPQuery data file is taken as an example. Those skilled in the art can understand that when other non-PHP processes access the IPQuery data file, the present invention can also be used to provide Methods.
通过本优选实施例提供的IPQuery数据文件动态更新方法,能够实现IPQuery数据文件的热加载,由于热加载不必重启IPQuery数据库,所以成功避免了用户在重启的时间段内无法访问的问题,从而提高了用户的体验满意度。另外,从运维的角度讲,由于避免了重启的操作,因而也杜绝了由重启失败所导致的运维问题。The IPQuery data file dynamic update method provided by this preferred embodiment can realize the hot loading of the IPQuery data file, because the hot loading does not need to restart the IPQuery database, so the problem that the user cannot access in the restarted time period is successfully avoided, thereby improving User experience satisfaction. In addition, from the perspective of operation and maintenance, since the restart operation is avoided, the operation and maintenance problems caused by restart failures are also eliminated.
图4示出了本发明实施例提供的数据文件的动态更新装置的结构图。如图4所示,该装置包括:存储单元41、变更单元42以及查找单元43。Fig. 4 shows a structural diagram of an apparatus for dynamically updating data files provided by an embodiment of the present invention. As shown in FIG. 4 , the device includes: a storage unit 41 , a modification unit 42 and a search unit 43 .
其中,存储单元41当数据文件需要更新时,将更新后的数据文件存储到第二存储空间,其中,更新前的数据文件存储在第一存储空间中。Wherein, when the data file needs to be updated, the storage unit 41 stores the updated data file in the second storage space, wherein the data file before the update is stored in the first storage space.
变更单元42将预设的最新数据文件的存储地址从第一存储空间的地址变更为第二存储空间的地址。The changing unit 42 changes the preset storage address of the latest data file from the address of the first storage space to the address of the second storage space.
其中,预设的最新数据文件的存储地址通过第一变量表示,则变更单元42用于将第一变量的值从第一存储空间的地址变更为第二存储空间的地址。Wherein, the preset storage address of the latest data file is represented by the first variable, and the changing unit 42 is used to change the value of the first variable from the address of the first storage space to the address of the second storage space.
查找单元43当有进程访问数据文件时,根据预设的最新数据文件的存储地址,查找并访问第二存储空间中存储的更新后的数据文件。When a process accesses the data file, the search unit 43 searches and accesses the updated data file stored in the second storage space according to the preset storage address of the latest data file.
所述查找单元43获取第一变量的值,将第一变量的值与本地存储的第二变量的值进行比较,其中,第二变量用于表示当前使用的数据文件的存储地址;若比较结果不同,则先将第一变量的值赋给第二变量,再查找并访问第二变量对应的存储地址中的数据文件。可选地,其中的第二变量为全局变量。The search unit 43 obtains the value of the first variable, and compares the value of the first variable with the value of the second variable stored locally, wherein the second variable is used to represent the storage address of the currently used data file; if the comparison result If different, assign the value of the first variable to the second variable first, and then search and access the data file in the storage address corresponding to the second variable. Optionally, the second variable is a global variable.
可选地,上述数据文件为IPQuery数据文件,上述进程为PHP进程。Optionally, the above data file is an IPQuery data file, and the above process is a PHP process.
关于上述的存储单元41、变更单元42以及查找单元43的具体工作过程可分别参照方法实施例中步骤S110、步骤S120以及步骤S130中相应部分的描述,此处不再赘述。For the specific working process of the storage unit 41 , the modification unit 42 and the search unit 43 , please refer to the descriptions of the corresponding parts in step S110 , step S120 and step S130 in the method embodiment, and details will not be repeated here.
在本发明提供的数据文件的动态更新方法及装置中,将更新前后的数据文件分别存储到不同的存储空间内,并通过预设的最新数据文件的存储地址来标识更新后的数据文件的位置,因而,进程能够在该位置访问到更新后的数据文件。由于更新前后的数据文件的存储空间不同,因而避免了现有技术中必须先删除内存中存储的更新前的数据文件,之后才能在同一内存中加载更新后的数据文件的缺陷,以及由此导致的重启数据库及相关的运维问题。通过本发明提供的数据文件的动态更新方法及装置,实现了在数据库正常运行的过程中动态加载数据文件的技术效果。In the method and device for dynamically updating data files provided by the present invention, the data files before and after the update are respectively stored in different storage spaces, and the location of the updated data file is identified by the preset storage address of the latest data file , so the process can access the updated data file at this location. Because the storage space of the data files before and after the update is different, thus avoiding the defects in the prior art that the data files before the update stored in the internal memory must be deleted first, and then the updated data files can be loaded in the same internal memory, and the resulting Restart the database and related operation and maintenance issues. Through the dynamic update method and device of the data file provided by the invention, the technical effect of dynamically loading the data file during the normal operation of the database is realized.
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other device. Various generic systems can also be used with the teachings based on this. The structure required to construct such a system is apparent from the above description. Furthermore, the present invention is not specific to any particular programming language. It should be understood that various programming languages can be used to implement the content of the present invention described herein, and the above description of specific languages is for disclosing the best mode of the present invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure the understanding of this description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, in order to streamline this disclosure and to facilitate an understanding of one or more of the various inventive aspects, various features of the invention are sometimes grouped together in a single embodiment, figure, or its description. This method of disclosure, however, is not to be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the Detailed Description are hereby expressly incorporated into this Detailed Description, with each claim standing on its own as a separate embodiment of this invention.
本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。Those skilled in the art can understand that the modules in the device in the embodiment can be adaptively changed and arranged in one or more devices different from the embodiment. Modules or units or components in the embodiments may be combined into one module or unit or component, and furthermore may be divided into a plurality of sub-modules or sub-units or sub-assemblies. All features disclosed in this specification (including accompanying claims, abstract and drawings), as well as any method or method so disclosed, may be used in any combination, except that at least some of such features and/or processes or units are mutually exclusive. All processes or units of equipment are combined. Each feature disclosed in this specification (including accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。Furthermore, those skilled in the art will understand that although some embodiments described herein include some features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention. and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的装置中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all functions of some or all components in the device according to the embodiment of the present invention. The present invention can also be implemented as an apparatus or an apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet site, or provided on a carrier signal, or provided in any other form.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words can be interpreted as names.
Claims (8)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310526090.3A CN103530420B (en) | 2013-10-30 | 2013-10-30 | The dynamic updating method and device of data file |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310526090.3A CN103530420B (en) | 2013-10-30 | 2013-10-30 | The dynamic updating method and device of data file |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103530420A CN103530420A (en) | 2014-01-22 |
CN103530420B true CN103530420B (en) | 2017-07-04 |
Family
ID=49932429
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310526090.3A Active CN103530420B (en) | 2013-10-30 | 2013-10-30 | The dynamic updating method and device of data file |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103530420B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104536785B (en) * | 2014-12-23 | 2018-04-06 | 北京国双科技有限公司 | Real-time system update method and device |
CN106936907B (en) * | 2017-03-09 | 2020-07-03 | 腾讯科技(深圳)有限公司 | File processing method, logic server, access server and system |
CN107066303B (en) * | 2017-05-04 | 2020-11-27 | 深圳市欧瑞博科技股份有限公司 | Firmware comparison method and device |
CN108304201B (en) * | 2017-09-14 | 2022-02-22 | 腾讯科技(深圳)有限公司 | Object updating method, device and equipment |
CN107908798A (en) * | 2017-12-20 | 2018-04-13 | 浙江煮艺文化科技有限公司 | The processing method and system of a kind of data file |
CN109710287B (en) * | 2018-12-07 | 2022-04-29 | 中国移动通信集团有限公司 | Hot updating method, device and computer storage medium |
CN111290773B (en) * | 2020-03-12 | 2024-01-19 | 深圳Tcl新技术有限公司 | System upgrade method, device and readable storage medium |
CN115878140A (en) * | 2021-09-29 | 2023-03-31 | 华为技术有限公司 | Application upgrading method and device, network card and equipment |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1908934A (en) * | 2006-08-02 | 2007-02-07 | 华为技术有限公司 | Online updating control method and device of embedded database |
CN101226493A (en) * | 2007-01-19 | 2008-07-23 | 松下电器产业株式会社 | Data backup device and data backup method |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP4104586B2 (en) * | 2004-09-30 | 2008-06-18 | 株式会社東芝 | File system having file management function and file management method |
-
2013
- 2013-10-30 CN CN201310526090.3A patent/CN103530420B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1908934A (en) * | 2006-08-02 | 2007-02-07 | 华为技术有限公司 | Online updating control method and device of embedded database |
CN101226493A (en) * | 2007-01-19 | 2008-07-23 | 松下电器产业株式会社 | Data backup device and data backup method |
Also Published As
Publication number | Publication date |
---|---|
CN103530420A (en) | 2014-01-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103530420B (en) | The dynamic updating method and device of data file | |
CN107544828A (en) | Configuring load application method and device | |
CN106790601B (en) | Service address reading device, system and method | |
CN106789741A (en) | The consuming method and device of message queue | |
CN109379398B (en) | Data synchronization method and device | |
CN106021335A (en) | A database accessing method and device | |
CN105447167A (en) | Processing method and apparatus for node cache data in distributed system | |
WO2019000722A1 (en) | Hypertext markup language webpage loading method and device | |
CN103577552A (en) | Webpage picture processing method and device | |
CN113377289B (en) | Cache management method, system, computing device and readable storage medium | |
CN103631869B (en) | A kind of method and apparatus for alleviating server-side database access pressure | |
CN108897865A (en) | The index copy amount appraisal procedure and device of distributed type assemblies | |
CN111651374A (en) | Data processing method and device, computing equipment and readable storage medium | |
CN103647811B (en) | A method and an apparatus for application's accessing backstage service | |
CN106227769B (en) | Date storage method and device | |
CN104462514B (en) | High Availabitity solution, connection control device and the system of database | |
CN107294986B (en) | A kind of method, apparatus and system of access HTTPS websites | |
JP2016508653A (en) | Method and apparatus for prefetching device drivers for peripheral devices connected to a smartphone prior to high level operating system (HLOS) boot | |
CN113760858A (en) | Memory library data dynamic migration method, device, computing device and storage device | |
CN105630889B (en) | Universal caching method and device | |
JP5093757B2 (en) | Field priority terminal cache storage system, method and program thereof | |
CN116233254A (en) | Business cut-off method, device, computer equipment and storage medium | |
CN116304079A (en) | Timing-based profile data management method, apparatus, and readable storage medium | |
CN108073660B (en) | A method and system for realizing cache data synchronization | |
CN113961730A (en) | Graph data query method, system, computer device and readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20220725 Address after: Room 801, 8th floor, No. 104, floors 1-19, building 2, yard 6, Jiuxianqiao Road, Chaoyang District, Beijing 100015 Patentee after: BEIJING QIHOO TECHNOLOGY Co.,Ltd. Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park) Patentee before: BEIJING QIHOO TECHNOLOGY Co.,Ltd. Patentee before: Qizhi software (Beijing) Co.,Ltd. |