CN101430705A - Memory method and apparatus based on embedded database - Google Patents
Memory method and apparatus based on embedded database Download PDFInfo
- Publication number
- CN101430705A CN101430705A CNA2008101795392A CN200810179539A CN101430705A CN 101430705 A CN101430705 A CN 101430705A CN A2008101795392 A CNA2008101795392 A CN A2008101795392A CN 200810179539 A CN200810179539 A CN 200810179539A CN 101430705 A CN101430705 A CN 101430705A
- Authority
- CN
- China
- Prior art keywords
- storage area
- data
- sign
- group data
- embedded database
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 74
- 238000012545 processing Methods 0.000 claims description 9
- 230000005055 memory storage Effects 0.000 claims 1
- 230000008569 process Effects 0.000 abstract description 34
- 238000013500 data storage Methods 0.000 description 8
- 230000006870 function Effects 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 238000012795 verification Methods 0.000 description 4
- 125000004122 cyclic group Chemical group 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000008520 organization Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种基于嵌入式数据库的存储方法和装置,其中,该方法包括:在存储器上预先设置第一存储区域和第二存储区域,其中,存储器用于存储嵌入式数据库的数据;对嵌入式数据库的多组数据进行更新操作,并且,对于完成更新的每组数据,分别存储到第一存储区域;如果将完成更新的多组数据都成功存储到第一存储区域,则将第一存储区域中存储的多组数据拷贝到第二存储区域中。借助于本发明的技术方案,通过在存储器上设置两个存储区域,并将数据分别保存在这两个区域上,保证了系统在存盘过程中发生严重错误时能够重新恢复,并且可以监控错误数据发生的位置。
The invention discloses a storage method and device based on an embedded database, wherein the method includes: presetting a first storage area and a second storage area on a memory, wherein the memory is used to store data of the embedded database; Multiple sets of data in the embedded database are updated, and each set of updated data is stored in the first storage area; if the updated multiple sets of data are successfully stored in the first storage area, the first Multiple sets of data stored in the storage area are copied to the second storage area. With the help of the technical solution of the present invention, by setting two storage areas on the memory and storing the data in these two areas respectively, it is ensured that the system can recover when a serious error occurs during the storage process, and the error data can be monitored where it happened.
Description
技术领域 technical field
本发明涉及通信领域,尤其涉及一种基于嵌入式数据库的存储方法和装置。The invention relates to the communication field, in particular to a storage method and device based on an embedded database.
背景技术 Background technique
嵌入式数据库以表为单位保存在存储器上,如果要修改嵌入式数据库在内存中的数据,需要将新数据重新保存到存储器上,但在将新数据保存到存储器的过程中,如果出现系统掉电或复位,会导致保存到存储器中的部分是新数据,部分是旧数据的情况,这样会破坏数据的一致性。The embedded database is stored in the storage in units of tables. If you want to modify the data in the embedded database in the memory, you need to save the new data to the storage again. However, during the process of saving the new data to the storage, if the system crashes Power-on or reset will cause some new data and some old data to be stored in the memory, which will destroy the consistency of the data.
目前,主要采用XML的方式存储数据,过去的方法是修改了一张表后将新数据以一种中间格式保存到存储器,然后将中间格式的文件更名为XML的文件。如果同时修改了3张表,当第1、2张表都保存完成,而保存第3张表的时候系统复位,那么第1、2张表的数据就是修改之后,第3张表数据是修改之前的。这样不能保证嵌入式数据库数据的一致性和正确性。At present, XML is mainly used to store data. The past method is to save the new data in an intermediate format to the memory after modifying a table, and then rename the intermediate format file to an XML file. If 3 tables are modified at the same time, when the 1st and 2nd tables are all saved, and the system resets when the 3rd table is saved, then the data of the 1st and 2nd tables are modified, and the data of the 3rd table is modified previous. This cannot guarantee the consistency and correctness of the embedded database data.
发明内容 Contents of the invention
考虑到相关技术中存在的在嵌入式数据库的数据存储过程中,不能保证嵌入式数据库数据的一致性和正确性的问题而提出本发明,为此,本发明的主要目的在于提供一种基于嵌入式数据库的存储方法及装置,以解决上述问题。In consideration of the problems existing in the related art in the data storage process of the embedded database, the consistency and correctness of the embedded database data cannot be guaranteed and the present invention is proposed. For this reason, the main purpose of the present invention is to provide a A storage method and device for a database to solve the above problems.
根据本发明的一个方面,提供一种基于嵌入式数据库的存储方法。According to one aspect of the present invention, a storage method based on an embedded database is provided.
根据本发明的基于嵌入式数据库的存储方法包括:在存储器上预先设置第一存储区域和第二存储区域,其中,存储器用于存储嵌入式数据库的数据;对嵌入式数据库的多组数据进行更新操作,并且,对于完成更新的每组数据,分别存储到第一存储区域;如果将完成更新的多组数据都成功存储到第一存储区域,则将第一存储区域中存储的多组数据拷贝到第二存储区域中。The storage method based on the embedded database according to the present invention includes: presetting the first storage area and the second storage area on the memory, wherein the memory is used to store the data of the embedded database; updating multiple sets of data of the embedded database operation, and, for each set of data that has been updated, store them in the first storage area; if the multiple sets of data that have been updated are all successfully stored in the first storage area, copy the multiple sets of data stored in the first storage area to the second storage area.
进一步地,方法还包括:如果将多组数据存储到第一存储区域中失败,则重新对嵌入式数据库的多组数据进行更新操作。Further, the method further includes: if storing the multiple sets of data in the first storage area fails, re-updating the multiple sets of data of the embedded database.
另外,在进行更新操作之前,该方法还包括:预先设置指示将修改的多组数据存储到第一存储区域下的第一标识,及指示将第一存储区域中的修改后的多组数据存储到第二存储区域下的第二标识;将嵌入式数据库中修改的多组数据存储到第一存储区域中包括:在内存中写入第一标识,并将嵌入式数据库中修改的多组数据存储到第一存储区域中;将第一存储区域中存储的多组数据拷贝到第二存储区域中包括:在内存中写入第二标识,并将第一存储区域中存储的多组数据拷贝到第二存储区域中。In addition, before performing the update operation, the method also includes: presetting a first flag indicating to store the modified multiple sets of data in the first storage area, and instructing to store the modified multiple sets of data in the first storage area To the second identification under the second storage area; storing the multiple sets of data modified in the embedded database into the first storage area includes: writing the first identification in the memory, and storing the multiple sets of data modified in the embedded database Stored in the first storage area; copying the multiple sets of data stored in the first storage area to the second storage area includes: writing the second identification in the internal memory, and copying the multiple sets of data stored in the first storage area to the second storage area.
优选地,在写入第一标识之后,该方法还包括:计算并保存第一标识对应的校验码,并将第一标识和第一标识对应的校验码复制到存储器中;在写入第二标识之后,该方法还包括:在内存中写入第二标识覆盖第一标识,计算并保存第二标识对应的校验码,并将第二标识和第二标识对应的校验码复制到存储器中覆盖第一标识和第一标识对应的校验码。Preferably, after writing the first identification, the method further includes: calculating and saving the check code corresponding to the first identification, and copying the first identification and the check code corresponding to the first identification to the memory; After the second identification, the method further includes: writing the second identification in the memory to cover the first identification, calculating and saving the verification code corresponding to the second identification, and copying the second identification and the verification code corresponding to the second identification Overwrite the first identifier and the check code corresponding to the first identifier in the memory.
进一步地,该方法还包括:读取内存中当前的标识,并计算读取的标识的参考校验码,如果计算的参考校验码与内存中存储的标识对应的校验码一致,则读取标识所指示的存储区域,其中,标识为第一标识或第二标识。Further, the method further includes: reading the current identification in the memory, and calculating the reference check code of the read identification, and if the calculated reference check code is consistent with the check code corresponding to the identification stored in the memory, then reading Get the storage area indicated by the identifier, where the identifier is the first identifier or the second identifier.
其中,如果在内存中读取的参考校验码与标识对应的校验码不一致,该方法还包括:读取存储器中当前的标识,并计算读取的标识的参考校验码,如果计算的参考校验码与存储器中存储的标识对应的校验码一致,则读取标识所指示的存储区域,其中,标识为第一标识或第二标识。Wherein, if the reference check code read in the memory is inconsistent with the check code corresponding to the logo, the method further includes: reading the current logo in the memory, and calculating the reference check code of the read logo, if the calculated The reference check code is consistent with the check code corresponding to the identifier stored in the memory, and then the storage area indicated by the identifier is read, wherein the identifier is the first identifier or the second identifier.
进一步地,上述方法还包括:为多组数据分别设置相应的数据标识,数据标识在其对应的数据被存储到第一存储区域时被写入到内存并覆盖在前写入的数据标识;在将完成更新的多组数据存储到第一存储区域失败时,从内存中读取数据标识,并将读取的数据标识的数据确定为存储失败的数据。Further, the above method also includes: respectively setting corresponding data identifiers for multiple sets of data, and the data identifiers are written into the memory when the corresponding data is stored in the first storage area and overwrite the previously written data identifiers; When storing the updated multiple sets of data in the first storage area fails, the data identification is read from the memory, and the data of the read data identification is determined as the data that fails to be stored.
根据本发明的另一个方面,提供一种基于嵌入式数据库的存储装置。According to another aspect of the present invention, a storage device based on an embedded database is provided.
根据本发明的基于嵌入式数据库的存储装置包括:第一设置模块,用于在存储器上预先设置第一存储区域和第二存储区域,其中,存储器用于存储嵌入式数据库的数据;更新模块,用于对嵌入式数据库的多组数据进行更新操作,并且,对于完成更新的每组数据,分别存储到第一存储区域;处理模块,用于完成更新的多组数据都成功存储到第一存储区域时,将第一存储区域中存储的多组数据拷贝到第二存储区域中。The storage device based on the embedded database according to the present invention includes: a first setting module, which is used to pre-set the first storage area and the second storage area on the memory, wherein the memory is used to store data of the embedded database; an update module, It is used to update multiple sets of data in the embedded database, and each set of updated data is stored in the first storage area; the processing module is used to successfully store multiple sets of updated data in the first storage When the area is selected, multiple sets of data stored in the first storage area are copied to the second storage area.
进一步地,该装置还包括:第二设置模块,用于设置指示将修改的多组数据存储到第一存储区域下的第一标识,及指示将第一存储区域中的修改后的多组数据存储到第二存储区域下的第二标识;写入模块,用于在内存中写入第一标识和/或第二标识;相应地,处理模块用于将嵌入式数据库中修改的多组数据存储到第一存储区域中,和/或将第一存储区域中存储的多组数据拷贝到第二存储区域中。Further, the device further includes: a second setting module, configured to set a first flag indicating to store the modified multiple sets of data in the first storage area, and indicate to store the modified multiple sets of data in the first storage area The second identification stored in the second storage area; the writing module is used to write the first identification and/or the second identification in the memory; correspondingly, the processing module is used to write multiple sets of data modified in the embedded database Store in the first storage area, and/or copy multiple sets of data stored in the first storage area to the second storage area.
通过本发明的上述至少一个技术方案,通过在存储器上设置两个存储区域,并将数据分别保存在这两个区域上,保证了系统在存盘过程中发生严重错误时能够重新恢复,并且可以监控错误数据发生的位置。Through at least one of the above-mentioned technical solutions of the present invention, by setting two storage areas on the memory and storing data in these two areas respectively, it is ensured that the system can be restored when a serious error occurs during the storage process, and can monitor The location where the erroneous data occurred.
附图说明 Description of drawings
附图用来提供对本发明的进一步理解,并且构成说明书的一部分,与本发明的实施例一起用于解释本发明,并不构成对本发明的限制。在附图中:The accompanying drawings are used to provide a further understanding of the present invention, and constitute a part of the description, and are used together with the embodiments of the present invention to explain the present invention, and do not constitute a limitation to the present invention. In the attached picture:
图1是根据本发明方法实施例的基于嵌入式数据库的存储方法的流程图;Fig. 1 is the flow chart of the storage method based on embedded database according to the method embodiment of the present invention;
图2是根据本发明方法实施例的数据存储过程的处理流程图;Fig. 2 is the processing flowchart of the data storage procedure according to the method embodiment of the present invention;
图3是根据本发明方法实施例的数据加载过程的处理流程图;Fig. 3 is the processing flowchart of the data loading process according to the method embodiment of the present invention;
图4是根据本发明装置实施例的基于嵌入式数据库的存储装置的结构框图;Fig. 4 is the structural block diagram of the storage device based on embedded database according to the device embodiment of the present invention;
图5是根据本发明装置实施例的基于嵌入式数据库的存储装置的优选结构框架图。Fig. 5 is a preferred structural frame diagram of the storage device based on the embedded database according to the device embodiment of the present invention.
具体实施方式 Detailed ways
功能概述Functional Overview
如上述描述,数据的正确性对嵌入式数据库来说至关重要,当在内存中对数据进行改写之后,如果不能正确地将改写后的数据存储在存储器上,系统再次加载时会加载错误的数据,从而导致系统运行错误。基于此,本发明提供了一种运用双目录的结构,保证在数据存储过程中发生错误也可以进行系统回滚,并且增加三个标识文件用于标示系统存储过程中发生错误的位置,方便对系统错误进行定位。As described above, the correctness of the data is very important to the embedded database. After the data is rewritten in the memory, if the rewritten data cannot be stored in the memory correctly, the system will load the wrong data when it is loaded again. data, resulting in system errors. Based on this, the present invention provides a structure using double directories to ensure that the system can be rolled back even if an error occurs during the data storage process, and three identification files are added to mark the location of the error during the system storage process, which is convenient for System error in positioning.
术语“存储介质”可以表示用于存储数据的一种或多种装置,包括只读存储器(ROM)、随机存取存储器(RAM)、磁RAM、磁心存储器、磁盘存储介质、光存储介质、闪存装置和/或用于存储信息的其他机器可读介质。术语“机器可读介质”包括但不限于便携式或固定存储装置、光存储装置、无线通道或能够存储、容纳、或承载指令和/或数据的各种其他介质。The term "storage medium" may refer to one or more devices for storing data, including read-only memory (ROM), random-access memory (RAM), magnetic RAM, magnetic core memory, magnetic disk storage media, optical storage media, flash memory device and/or other machine-readable medium for storing information. The term "machine-readable medium" includes, but is not limited to, portable or fixed storage devices, optical storage devices, wireless channels, or various other media capable of storing, containing, or carrying instructions and/or data.
另外,可以通过硬件、软件、固件、中间件、微码、硬件描述语言或其组合来实现实施例。当用软件、固件、中间件或微码来实现时,可以在诸如存储介质的机器可读介质中存储用于执行必要任务的程序代码或码段。(多个)处理器可以执行必要任务。码段可以表示进程、函数、子程序、程序、例行程序、子例行程序、模块、对象、软件包、类、或指令、数据结构、或程序语言的任意组合。通过传输和/或接收信息、数据、自变量、或存储内容来将码段耦合到另一码段或硬件电路。信息、自变量、参数、数据等可以经由包括存储器共享、消息传递、令牌传递、网络传输等的任意合适方式来传递、传输、或传送。Additionally, embodiments may be implemented by hardware, software, firmware, middleware, microcode, hardware description languages, or combinations thereof. When implemented in software, firmware, middleware or microcode, the program code or code segments for performing the necessary tasks may be stored in a machine-readable medium such as a storage medium. The processor(s) can perform the necessary tasks. A code segment may represent a process, function, subroutine, program, routine, subroutine, module, object, software package, class, or any combination of instructions, data structures, or programming languages. A code segment is coupled to another code segment or a hardware circuit by transmitting and/or receiving information, data, arguments, or stored content. Information, arguments, parameters, data, etc. may be communicated, transmitted, or communicated via any suitable means including memory sharing, message passing, token passing, network transmission, and the like.
在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。In the case of no conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.
下面将结合附图详细描述本发明。The present invention will be described in detail below with reference to the accompanying drawings.
方法实施例method embodiment
根据本发明实施例,提供了一种基于嵌入式数据库的存储方法。According to an embodiment of the present invention, a storage method based on an embedded database is provided.
需要说明的是,为了便于描述,在下文中以步骤的形式示出并描述了本发明的方法实施例的技术方案,在下文中所示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行。虽然在相关的附图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。It should be noted that, for the convenience of description, the technical solutions of the method embodiments of the present invention are shown and described below in the form of steps, and the steps shown below can be executed in a computer system such as a set of computer-executable instructions implement. Although a logical order is shown in the associated figures, in some cases the steps shown or described may be performed in an order different from that herein.
图1是根据本发明实施例的基于嵌入式数据库的存储方法的流程图,如图1所示,该方法包括以下步骤(步骤S102至步骤S106):Fig. 1 is the flowchart of the storage method based on embedded database according to the embodiment of the present invention, as shown in Fig. 1, this method comprises the following steps (step S102 to step S106):
步骤S102,在存储器上预先设置第一存储区域和第二存储区域,其中,存储器用于存储嵌入式数据库的数据;Step S102, presetting a first storage area and a second storage area on the memory, wherein the memory is used to store data of the embedded database;
步骤S104,对嵌入式数据库的多组数据进行更新操作,并且,对于完成更新的每组数据,分别存储到第一存储区域;Step S104, performing an update operation on multiple sets of data in the embedded database, and storing each set of updated data in the first storage area;
步骤S106,如果将完成更新的多组数据都成功存储到第一存储区域,则将第一存储区域中存储的多组数据拷贝到第二存储区域中;如果将多组数据存储到第一存储区域中失败,则重新对嵌入式数据库的多组数据进行更新操作。Step S106, if the updated multiple sets of data are successfully stored in the first storage area, copy the multiple sets of data stored in the first storage area to the second storage area; if the multiple sets of data are stored in the first storage area If it fails in the region, it will re-update multiple sets of data in the embedded database.
在具体实施过程中,可以预先设置指示将修改的多组数据存储到第一存储区域下的第一标识,及指示将第一存储区域中的修改后的多组数据存储到第二存储区域下的第二标识;这样,将嵌入式数据库中修改的多组数据存储到第一存储区域中包括:在内存中写入第一标识,并将嵌入式数据库中修改的多组数据存储到第一存储区域中,计算并保存第一标识对应的校验码,并将第一标识和第一标识对应的校验码复制到存储器中;将第一存储区域中存储的多组数据拷贝到第二存储区域中包括:在内存中写入第二标识,在内存中写入第二标识覆盖第一标识,计算并保存第二标识对应的校验码,并将第二标识和第二标识对应的校验码复制到存储器中覆盖第一标识和第一标识对应的校验码,并将第一存储区域中存储的多组数据拷贝到第二存储区域中。In the specific implementation process, the first flag indicating to store the modified multiple sets of data in the first storage area can be preset, and the modified multiple sets of data in the first storage area can be stored in the second storage area. In this way, storing the multiple sets of data modified in the embedded database into the first storage area includes: writing the first identifier in the memory, and storing the multiple sets of data modified in the embedded database into the first storage area. In the storage area, calculate and save the check code corresponding to the first identification, and copy the first identification and the check code corresponding to the first identification to the memory; copy the multiple sets of data stored in the first storage area to the second The storage area includes: writing the second identification in the memory, writing the second identification in the memory to cover the first identification, calculating and saving the check code corresponding to the second identification, and storing the second identification and the corresponding The verification code is copied into the memory to cover the first identification and the verification code corresponding to the first identification, and multiple sets of data stored in the first storage area are copied to the second storage area.
在系统上电时,读取内存中当前的标识,并计算读取的标识的参考校验码,如果计算的参考校验码与内存中存储的标识对应的校验码一致,则读取标识所指示的存储区域,其中,标识为第一标识或第二标识,如果在内存中读取的参考校验码与标识对应的校验码不一致,读取存储器中当前的标识,并计算读取的标识的参考校验码,如果计算的参考校验码与存储器中存储的标识对应的校验码一致,则读取标识所指示的存储区域,其中,标识为第一标识或第二标识。When the system is powered on, read the current logo in the memory, and calculate the reference check code of the read logo, if the calculated reference check code is consistent with the check code corresponding to the logo stored in the memory, then read the logo The indicated storage area, wherein the identification is the first identification or the second identification, if the reference check code read in the memory is inconsistent with the check code corresponding to the identification, read the current identification in the memory, and calculate the read The reference check code of the identification, if the calculated reference check code is consistent with the check code corresponding to the identification stored in the memory, read the storage area indicated by the identification, wherein the identification is the first identification or the second identification.
通过本发明实施例提供的技术方案,通过在存储器上设置两个存储区域,并将数据分别保存在这两个区域上,保证了系统在存盘过程中发生严重错误时能够重新恢复,并且可以监控错误数据发生的位置。Through the technical solution provided by the embodiment of the present invention, by setting two storage areas on the memory and storing data in these two areas respectively, it is ensured that the system can be restored when a serious error occurs during the storage process, and can monitor The location where the erroneous data occurred.
下面对本发明实施例进行详细说明,在具体实施过程中,主要分为文件组织形式过程(对应于上述的步骤S102)、数据存储(对应于上述的步骤S104)和数据加载(对应于上述的步骤S106)三个过程,下面对各过程进行描述。The embodiment of the present invention will be described in detail below. In the specific implementation process, it is mainly divided into file organization process (corresponding to the above-mentioned step S102), data storage (corresponding to the above-mentioned step S104) and data loading (corresponding to the above-mentioned step S104). S106) Three processes, each process will be described below.
第一、文件组织形式过程First, the file organization process
关于存储器:在系统的运行目录下增加两个平级的目录,一个目录用于保存当前数据,称为备份目录(即,上文所述的第一存储器),另一个目录用于保存备份数据,成为当前目录(即,上文所述的第二存储器)。About storage: Add two flat directories under the system's running directory, one directory is used to save the current data, called the backup directory (that is, the first storage mentioned above), and the other directory is used to save the backup data , becomes the current directory (that is, the second storage described above).
关于保留内存(即,上文所述的内存):设置标识位,根据标志文件的系统标志位来判断系统是从当前目录加载数据,还是从备份目录加载数据。在系统的保留内存上开辟一块区域用于保存存盘过程的标志文件,在运行目录下以二进制形式保存嵌入式数据库的数据的副本,正常情况下,备份目录和当前目录下保存的数据的副本与保留内存中的数据内容完全一致。其中,保留内存中保存了循环冗余校验(Cyclic Redundancy Check,简称为CRC)校验值,嵌入式数据库中的表的总个数,上述设置的标志位,每张表数据存储的标志位(即,上文所述的数据标识)。Regarding the reserved memory (that is, the memory mentioned above): set the flag bit, and judge whether the system loads data from the current directory or from the backup directory according to the system flag bit of the flag file. Open up an area on the reserved memory of the system to save the logo file of the saving process, and save a copy of the data of the embedded database in binary form under the running directory. Under normal circumstances, the copy of the data saved in the backup directory and the current directory is the same as Keep the data content in the memory exactly the same. Among them, the cyclic redundancy check (Cyclic Redundancy Check, referred to as CRC) check value is saved in the reserved memory, the total number of tables in the embedded database, the flag bits set above, and the flag bits stored in each table data (i.e., the data flags described above).
第二、数据存储过程Second, the data storage process
预先将整个数据的存储过程分为三个阶段:第一阶段为初始阶段,对数据进行存储,其中,上一次存储数据的过程没有发生错误,在保留内存中存储的数据为正确的数据;第二阶段为保存阶段,将需要更新的数据保存到备份目录下;第三阶段为拷贝阶段,将备份目录中更新成功的数据拷贝到当前目录下。The entire data storage process is divided into three stages in advance: the first stage is the initial stage, and the data is stored, in which, no error occurred in the last process of storing data, and the data stored in the reserved memory is correct data; The second stage is the saving stage, saving the data to be updated to the backup directory; the third stage is the copying stage, copying the successfully updated data in the backup directory to the current directory.
系统提供了一个存储数据的接口,该接口以集合为单位,可以对单个表和批量的表进行存储。由于系统目前支持的最大表个数为256,因此集合有256位,每一位代表一张表,如果某一张表需要保存,就将相应的bit置为有效。函数体内会解析这个集合来判断哪些表需要保存。The system provides an interface for storing data, which can store single tables and batch tables in units of collections. Since the maximum number of tables currently supported by the system is 256, the set has 256 bits, and each bit represents a table. If a certain table needs to be saved, the corresponding bit is set to valid. The function body will parse this collection to determine which tables need to be saved.
在具体实施过程中,将系统标志位和需要保存的表的标志位置为第一阶段,开始将内存中的数据以XML的数据格式保存到备份目录中,保存完一张表就将该表的标志位置成第二阶段,即已经成功将数据保存到备份目录中的表,如果在将表存储到备份目录的过程中发生错误,该表的标志位为第一阶段,即没有将数据保存到备份目录中的表,当所有需要保存的表都已经保存完成之后,将系统标识位置为第三阶段。将所有需要保存的表上的数据从备份目录拷贝到当前目录,拷贝成功一张表就将相应的表标志位置为第一阶段,如果在将表从备份目录拷贝到当前目录的过程中发生错误,该表的标志位为第三阶段,即没有将数据从备份目录拷贝到当前目录中的表,当所有的表都已经拷贝成功之后,将系统标志位置为第一阶段,存储过程结束。In the specific implementation process, the system flag and the flag position of the table to be saved are the first stage, and the data in the memory is saved to the backup directory in XML data format. After saving a table, the table's The flag position is the second stage, that is, the table that has successfully saved the data to the backup directory. If an error occurs during the process of storing the table to the backup directory, the flag of the table is the first stage, that is, the data has not been saved to the backup directory. Back up the tables in the directory. After all the tables that need to be saved have been saved, the system identifies the position as the third stage. Copy the data on all the tables that need to be saved from the backup directory to the current directory. If a table is copied successfully, the corresponding table will be marked as the first stage. If an error occurs during the process of copying the table from the backup directory to the current directory , the flag bit of the table is the third stage, that is, the table that has not copied data from the backup directory to the current directory, when all the tables have been successfully copied, the system flag position is set to the first stage, and the storage process ends.
下面结合图2对数据存储过程进行描述。The data storage process is described below in conjunction with FIG. 2 .
步骤S201,先读取系统标志位,根据系统标志位判断数据存储过程所处的阶段,如果标志位不正常就说明系统上次存盘发生错误。如果系统标志位为用于指示初始阶段的系统标志位,则进入到步骤S202,如果系统标志位为用于指示第二阶段的系统标志位,则进入到步骤S209,如果系统标志位为用于指示第三阶段的系统标志位,则进入到步骤S210;Step S201, first read the system flag, judge the stage of the data storage process according to the system flag, if the flag is not normal, it means that the system has an error in the last save. If the system flag bit is used to indicate the system flag bit of the initial stage, then enter step S202, if the system flag bit is used to indicate the system flag bit of the second stage, then enter step S209, if the system flag bit is used to indicate the second stage Indicate the system flag bit of the third stage, then enter step S210;
步骤S202,写入用于指示第二阶段的系统标志位;Step S202, writing the system flag bit used to indicate the second stage;
步骤S203,判断是否还有表需要保存,如果判断结果为是,进入到步骤S204,否则进入到步骤S205;Step S203, judging whether there are tables to be saved, if the judging result is yes, go to step S204, otherwise go to step S205;
步骤S204,将修改后的所有数据保存到备份目录下,并写入用于指示第三阶段的系统标志位;Step S204, save all the modified data to the backup directory, and write into the system flag for indicating the third stage;
步骤S205,写入用于指示第三阶段的系统标志位;Step S205, writing the system flag bit used to indicate the third stage;
步骤S206,判断是否还有表需要拷贝,如果判断结果为是,进入到步骤S207,否则进入到步骤S208;Step S206, judging whether there are tables to be copied, if the judging result is yes, go to step S207, otherwise go to step S208;
步骤S207,将数据拷贝到当前目录,并写入用于指示第一阶段的系统标志位;Step S207, copy the data to the current directory, and write the system flag for indicating the first stage;
步骤S208,写入用于指示第一阶段的系统标志位;Step S208, write the system flag bit used to indicate the first stage;
步骤S209,如果读取的系统标志位为第二阶段,说明错误发生在将数据保存到备份目录下时,需要先将错误的数据恢复,将发生错误的表保存到备份目录,然后将表拷贝到当前目录,即将标识文件中标示为第二阶段的表从备份目录拷贝到当前目录,并相应地修改标志文件;Step S209, if the read system flag is the second stage, it means that an error occurred when saving the data to the backup directory, it is necessary to restore the wrong data first, save the error table to the backup directory, and then copy the table Go to the current directory, that is, copy the table marked as the second stage in the identification file from the backup directory to the current directory, and modify the identification file accordingly;
步骤S210,如果读取的系统标志位为第三阶段,说明错误发生在将数据拷贝到当前目录时,将发生错误的表重新拷贝到当前目录下。然后开始存盘过程,先将标志文件的标志位置为第二阶段,把数据保存到备份目录,将标志文件置第三阶段,把数据从备份目录拷贝到当前目录,最后将标志文件置为第一阶段。In step S210, if the read system flag is the third stage, it means that an error occurred when copying data to the current directory, and the table in which the error occurred is copied to the current directory again. Then start the save process, first set the logo position of the logo file as the second stage, save the data to the backup directory, put the logo file in the third stage, copy the data from the backup directory to the current directory, and finally set the logo file as the first stage.
第三过程、数据加载过程The third process, data loading process
数据加载是根据标志文件中的系统标志位来判断,如果标志文件的系统标志位为第一阶段和第二阶段,就表明可用的完整数据在当前目录下,此时加载当前目录下的数据,如果标志文件的系统标志位为第三阶段,就表明可用的完整数据在备份目录下,此时加载备份目录下的数据;如果标志文件不存在就初始化标志文件为第一阶段,加载相应目录下的数据。三个标志文件的同步,由于三个标志文件在正常情况下都是相等的,因此不管对哪个标志文件进行了操作,都必须同步到其他两个标志文件中。在数据库上电的时候,会提供一个标志文件选择的函数,该函数不带参数,功能是用于将三个标志文件中的有效文件选择出来。选择的原则是以保留内存中保存的系统标志位为先,然后再判断其他两个标志文件的副本,具体过程为:首先通过CRC校验判断保留内存中的系统标志位是否有效,因为如果出现系统掉电的情况,保留内存中的内容会被随机改写,如果保留内保存的标志位有效,则根据保留中保存的标志文件的标志位来判断系统从当前目录还是从备份目录加载数据。如果保留内存内容无效,则判断保留内存的副本,如果副本有效,则根据标志文件副本的系统标志位来加载数据,如果保留内存和其副本都无效,则重新初始化保留内存和保留内存的副本,都初始化为第一阶段。Data loading is judged according to the system flag bit in the flag file. If the system flag bit of the flag file is the first stage and the second stage, it indicates that the available complete data is in the current directory. At this time, the data in the current directory is loaded. If the system flag bit of the flag file is the third stage, it indicates that the available complete data is in the backup directory, and the data in the backup directory is loaded at this time; if the flag file does not exist, the flag file is initialized to the first stage, and the corresponding directory is loaded The data. Synchronization of the three logo files, since the three logo files are equal under normal circumstances, no matter which logo file is operated, it must be synchronized to the other two logo files. When the database is powered on, it will provide a function for selecting a logo file. This function does not have parameters, and its function is to select a valid file from the three logo files. The principle of selection is to reserve the system flags stored in the memory first, and then judge the copies of the other two flag files. The specific process is as follows: first, judge whether the system flags in the reserved memory are valid through CRC check, because if there is When the system is powered off, the content in the reserved memory will be rewritten randomly. If the flag bit saved in the reserved memory is valid, the system can judge whether the system loads data from the current directory or the backup directory according to the flag bit of the flag file saved in the reserved memory. If the content of the reserved memory is invalid, judge the copy of the reserved memory. If the copy is valid, load the data according to the system flag bit of the flag file copy. If both the reserved memory and its copy are invalid, reinitialize the reserved memory and the copy of the reserved memory. Both are initialized to the first stage.
下面结合图3对该数据加载过程进行说明。The data loading process will be described below with reference to FIG. 3 .
步骤S301,判断标志文件是否存在,如果判断结果为是,进入到步骤S302,否则进入步骤S305;Step S301, judging whether the flag file exists, if the judging result is yes, go to step S302, otherwise go to step S305;
步骤S302,读取标志文件的存储标志位;Step S302, read the storage flag bit of the flag file;
步骤S303,标志位为第一阶段和第二阶段;Step S303, the flag bit is the first stage and the second stage;
步骤S304,从系统的当前目录中加载数据;Step S304, loading data from the current directory of the system;
步骤S305,创建标志文件并且初始化为存储过程的第一阶段;Step S305, creating a flag file and initializing it as the first stage of the stored procedure;
步骤S306,从系统的备份目录中加载数据。Step S306, loading data from the backup directory of the system.
装置实施例Device embodiment
根据本发明实施例,提供一种基于嵌入式数据库的存储装置。According to an embodiment of the present invention, a storage device based on an embedded database is provided.
图4示出了根据本发明实施例的基于嵌入式数据库的存储装置示意图,如图4所示,该装置包括设置模块10、更新模块20和处理模块30。FIG. 4 shows a schematic diagram of a storage device based on an embedded database according to an embodiment of the present invention. As shown in FIG. 4 , the device includes a setting module 10 , an updating module 20 and a processing module 30 .
第一设置模块10,用于在存储器上预先设置第一存储区域和第二存储区域,其中,存储器用于存储嵌入式数据库的数据;更新模块20,连接至第一设置模块10,用于对嵌入式数据库的多组数据进行更新操作,并且,对于完成更新的每组数据,分别存储到第一存储区域;处理模块30,连接至第一设置模块10和更新模块20,用于完成更新的多组数据都成功存储到第一存储区域时,将第一存储区域中存储的多组数据拷贝到第二存储区域中。The first setting module 10 is used to pre-set the first storage area and the second storage area on the memory, wherein the memory is used to store the data of the embedded database; the update module 20 is connected to the first setting module 10 and is used for Multiple sets of data in the embedded database are updated, and each set of data that completes the update is stored in the first storage area respectively; the processing module 30 is connected to the first setting module 10 and the update module 20, and is used to complete the update. When multiple sets of data are successfully stored in the first storage area, the multiple sets of data stored in the first storage area are copied to the second storage area.
图5示出了根据本发明实施例的基于嵌入式数据库的存储装置的优选结构框架图,如图5所示,在图4所示装置的基础上,该装置还包括第二设置模块40和写入模块50。Fig. 5 shows a preferred structural frame diagram of a storage device based on an embedded database according to an embodiment of the present invention. As shown in Fig. 5, on the basis of the device shown in Fig. 4, the device also includes a second setting module 40 and Write module 50.
第二设置模块40,用于设置指示将修改的多组数据存储到第一存储区域下的第一标识,及指示将第一存储区域中的修改后的多组数据存储到第二存储区域下的第二标识;写入模块50,连接至第二设置模块40,用于在内存中写入第二设置模块40设置的第一标识和/或第二标识;处理模块30,连接至写入模块50,用于在写入模块50写入第一标识之后,将嵌入式数据库中修改的多组数据存储到第一存储区域中,和/或在写入模块50写入第二标识之后,将第一存储区域中存储的多组数据拷贝到第二存储区域中。The second setting module 40 is used to set the first flag indicating to store the modified multiple sets of data under the first storage area, and indicate to store the modified multiple sets of data in the first storage area under the second storage area The second identification of; write module 50, be connected to the second setting module 40, be used for writing the first identification and/or the second identification that the second setting module 40 sets in memory; Processing module 30, be connected to write A module 50, configured to store multiple sets of data modified in the embedded database into the first storage area after the writing module 50 writes the first identification, and/or after the writing module 50 writes the second identification, Multiple sets of data stored in the first storage area are copied to the second storage area.
通过本发明实施例提供的基于嵌入式数据库的存储装置,通过在存储器上设置两个存储区域,并将数据分别保存在这两个区域上,保证了系统在存盘过程中发生严重错误时能够重新恢复,并且可以监控错误数据发生的位置。Through the storage device based on the embedded database provided by the embodiment of the present invention, by setting up two storage areas on the memory and saving the data in these two areas respectively, it is ensured that the system can be restarted when a serious error occurs during the storage process. recovery, and can monitor where erroneous data occurs.
如上所述,借助于本发明提供的基于嵌入式数据库的存储方法和/或装置,通过在存储器上设置两个存储区域,并将数据分别保存在这两个区域上,保证了系统在存盘过程中发生严重错误时能够重新恢复,并且可以监控错误数据发生的位置。例如在电子盘中保存两套数据,在保存数据的过程中,如果发生错误,那么数据可以进行回滚;新增存盘的标志文件,可以标示存储过程在哪一步发生错误,和发生错误的表。As mentioned above, with the help of the storage method and/or device based on the embedded database provided by the present invention, by setting two storage areas on the memory and storing the data in these two areas respectively, it is guaranteed that the system can save data during the storage process. It can be recovered when a serious error occurs in the system, and it can monitor the location of the wrong data. For example, if two sets of data are saved in the electronic disk, if an error occurs during the process of saving the data, the data can be rolled back; the new logo file for saving can indicate the step where the error occurred in the storage process, and the error table .
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2008101795392A CN101430705B (en) | 2008-11-29 | 2008-11-29 | Storage method and device based on embedded database |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2008101795392A CN101430705B (en) | 2008-11-29 | 2008-11-29 | Storage method and device based on embedded database |
Publications (2)
Publication Number | Publication Date |
---|---|
CN101430705A true CN101430705A (en) | 2009-05-13 |
CN101430705B CN101430705B (en) | 2011-01-19 |
Family
ID=40646099
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2008101795392A Expired - Fee Related CN101430705B (en) | 2008-11-29 | 2008-11-29 | Storage method and device based on embedded database |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN101430705B (en) |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103391246A (en) * | 2013-08-02 | 2013-11-13 | 盛科网络(苏州)有限公司 | Message processing method and device |
WO2014169649A1 (en) * | 2013-04-16 | 2014-10-23 | 华为技术有限公司 | Data processing method and device, and computer system |
CN104866388A (en) * | 2014-02-24 | 2015-08-26 | 腾讯科技(北京)有限公司 | Data processing method and device |
CN106649654A (en) * | 2016-12-12 | 2017-05-10 | 京信通信技术(广州)有限公司 | Data updating method and device |
CN107257281A (en) * | 2017-05-31 | 2017-10-17 | 百富计算机技术(深圳)有限公司 | NOR FLASH store method, device and the computer-readable recording medium of key data record |
CN111143899A (en) * | 2018-11-06 | 2020-05-12 | 中兴通讯股份有限公司 | Method and device for storing data, storage medium and electronic device |
CN111221474A (en) * | 2020-01-02 | 2020-06-02 | 广州虎牙科技有限公司 | Data storage method, device, equipment and storage medium |
CN112667650A (en) * | 2020-12-28 | 2021-04-16 | 北京华大智宝电子系统有限公司 | Database updating method and device |
CN113434338A (en) * | 2021-06-25 | 2021-09-24 | 苏州伟创电气科技股份有限公司 | Fault-tolerant method, device and equipment for data storage and storage medium |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
ATE475139T1 (en) * | 1999-06-10 | 2010-08-15 | Belle Gate Invest B V | DEVICE FOR STORING DIFFERENT VERSIONS OF DATA SETS IN SEPARATE DATA AREAS AND METHOD FOR UPDATE A DATA SET IN A MEMORY |
US7885921B2 (en) * | 2004-11-18 | 2011-02-08 | International Business Machines Corporation | Managing atomic updates on metadata tracks in a storage system |
CN100590606C (en) * | 2005-12-14 | 2010-02-17 | 兆日科技(深圳)有限公司 | Flash memory data integrity protection method |
-
2008
- 2008-11-29 CN CN2008101795392A patent/CN101430705B/en not_active Expired - Fee Related
Cited By (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2014169649A1 (en) * | 2013-04-16 | 2014-10-23 | 华为技术有限公司 | Data processing method and device, and computer system |
US9824011B2 (en) | 2013-04-16 | 2017-11-21 | Huawei Technologies Co., Ltd. | Method and apparatus for processing data and computer system |
CN103391246A (en) * | 2013-08-02 | 2013-11-13 | 盛科网络(苏州)有限公司 | Message processing method and device |
CN104866388A (en) * | 2014-02-24 | 2015-08-26 | 腾讯科技(北京)有限公司 | Data processing method and device |
CN104866388B (en) * | 2014-02-24 | 2021-04-09 | 腾讯科技(北京)有限公司 | Data processing method and device |
CN106649654A (en) * | 2016-12-12 | 2017-05-10 | 京信通信技术(广州)有限公司 | Data updating method and device |
CN107257281B (en) * | 2017-05-31 | 2020-07-28 | 百富计算机技术(深圳)有限公司 | Method, device and computer-readable storage medium for NOR FLASH storage key record |
CN107257281A (en) * | 2017-05-31 | 2017-10-17 | 百富计算机技术(深圳)有限公司 | NOR FLASH store method, device and the computer-readable recording medium of key data record |
WO2020094063A1 (en) * | 2018-11-06 | 2020-05-14 | 中兴通讯股份有限公司 | Data storage method and device, storage medium and electronic device |
CN111143899A (en) * | 2018-11-06 | 2020-05-12 | 中兴通讯股份有限公司 | Method and device for storing data, storage medium and electronic device |
CN111221474A (en) * | 2020-01-02 | 2020-06-02 | 广州虎牙科技有限公司 | Data storage method, device, equipment and storage medium |
CN112667650A (en) * | 2020-12-28 | 2021-04-16 | 北京华大智宝电子系统有限公司 | Database updating method and device |
CN112667650B (en) * | 2020-12-28 | 2024-05-28 | 北京华大智宝电子系统有限公司 | Database updating method and device |
CN113434338A (en) * | 2021-06-25 | 2021-09-24 | 苏州伟创电气科技股份有限公司 | Fault-tolerant method, device and equipment for data storage and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN101430705B (en) | 2011-01-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN101430705A (en) | Memory method and apparatus based on embedded database | |
CN102165422B (en) | Firmware update device and method | |
KR100750132B1 (en) | How to boot, automatically update software and recover from errors, and the system and computer-readable recording media recording the method | |
JP4901095B2 (en) | Fail-safe way to apply custom software image updates to non-volatile storage | |
CN102270144B (en) | Embedded network equipment and method for upgrading firmware by using same | |
US6892255B2 (en) | Program install method, file renewal method, program and computer system | |
CN109086078B (en) | Android system upgrading method and device, server and mobile terminal | |
US8176009B2 (en) | Performing a pre-update on a non volatile memory | |
TW200414042A (en) | Firmware architecture supporting safe updates and multiple processor types | |
US11144299B2 (en) | Firmware updating method | |
CN101188516A (en) | A method for high-reliability self-adaptive remote update of network equipment software system | |
CN113806139B (en) | Operating system recovery method, operating system recovery device, storage medium and computer program product | |
CN114116023A (en) | Operating system starting method, operating system starting device, storage medium and computer program product | |
CN105138430A (en) | Embedded operating system backup and restoration method and device | |
CN101923500A (en) | Backup and update method and device of bootstrap program in embedded equipment | |
CN113900673B (en) | System installation package management method, device, storage medium and program product | |
CN114995852A (en) | Device upgrade method, device and computer-readable storage medium | |
CN107436783B (en) | Differential upgrading method for mobile terminal, storage medium and mobile terminal | |
CN113467797B (en) | Program updating method, device and system and computer readable storage medium | |
CN104834574A (en) | Method and device for solving damage of system partition | |
CN119046249B (en) | A mirror file processing method, system and product | |
CN101004692A (en) | Virtual executing method installed by software, and system | |
CN114489717B (en) | A system upgrade method, device and system | |
TWI407371B (en) | Embedded networking device and firmware updating method | |
CN117270914B (en) | System upgrading method, device, equipment and medium of terminal equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20110119 |