Summary of the invention
The objective of the invention is to, in embedded system,, provide a kind of method for protecting consistency of memory database, realize the low expense of system resource and the high-level efficiency of service based on the seizing under the scheduling strategy of priority.
To achieve these goals, the invention provides the method for protecting consistency of memory database under a kind of embedded environment, one group of database application process is hereinafter to be referred as database process, the priority of database process is all identical, other application processes identical with database process priority are designated hereinafter simply as first kind application process, the process inequality with database process priority is designated hereinafter simply as the second class application process, wherein first kind application process is called the first kind interface of database, calls corresponding database operating function interface function by event number and directly finishes database manipulation; The second class application process is called second class interface of database, send the corresponding database access request message by event number to the database manipulation process, and call corresponding database operating function interface function by the database manipulation process according to the database access request message and finish database manipulation.
The method for protecting consistency of memory database under the above-mentioned embedded environment; wherein; after database was finished database manipulation, first kind interface returned to first kind application process with the data structure of return results by output parameter, and second class interface returns to the second class application process with response message.
The method for protecting consistency of memory database under the above-mentioned embedded environment, wherein, the step that first kind application process is finished database manipulation by first kind interface specifically comprises:
Step 101, first kind application process are called first kind interface primitive, and input parameter comprises the data structure of the output parameter of the input parameter value of event number, database manipulation of database manipulation and database manipulation;
Step 102, whether the event number of judgment data storehouse operation is legal, if illegal, then arrives step 104, directly returns; If it is legal then enter step 103 and continue to carry out;
Step 103 is called associated databases operating function interface function according to the event number of database manipulation and is carried out database manipulation, and for returning first kind application process behind the variable assignments in the output parameter data structure.
The method for protecting consistency of memory database under the above-mentioned embedded environment, wherein, the step that the second class application process is finished database manipulation by second class interface specifically comprises:
Step 201, application process are called the second class interface primitive, and input parameter comprises the output parameter data structure of database manipulation event number, database manipulation input parameter value and database manipulation;
Step 202, whether the event number of judgment data storehouse operation is legal, if illegal, then directly returns; Otherwise entering step 203 continues to carry out;
Step 203, call corresponding forwards function according to the event number of database manipulation and send the database manipulation request message to the database manipulation process, the database manipulation request message comprises database manipulation message number, the input parameter value of request, the data structure of output parameter;
Step 204, function call finishes, and returns;
Step 301, database manipulation process process database operations request message;
Step 302 judges whether message number is legal, if illegal, then arrives step 305, if legal then enter step 303;
Step 303 according to given message number, is called corresponding database operating function interface function and is carried out database manipulation, and is each variable assignments in the output parameter data structure, and sends response message for the originating process of initiating to call specifically;
Step 304, function returns, and the call flow of second class interface is finished fully;
Step 305 abandons this message, directly returns.
The method for protecting consistency of memory database under the above-mentioned embedded environment; wherein; in the described step 201; the second class application process is called the second class interface primitive by the synchronization message mode and is then hung up the second class application process, if call the second class interface primitive by the asynchronous message mode then enter step 202.
The method for protecting consistency of memory database under the above-mentioned embedded environment, wherein, described database manipulation carries out data access, renewal, interpolation or deletion by database manipulation functional interface function by input parameter in database.
Compared with prior art, the present invention is process seizing under the scheduling strategy based on priority, the access interface of form unanimity is provided to other processes, what adopt is low expense, high efficiency message mechanism, rather than the locking method of the complexity of common consumes resources, thereby simplified the design of data base consistency(-tance) support method, guaranteed the performance of memory database system.
Embodiment
One group of process of memory database itself is referred to as database process, has consistent process priority, other application processes are undertaken by the standard interface that database provides access of database, in the method for the present invention, the standard interface of database module is divided into two class interfaces: first kind interface is only for calling with the application process of the database process level that has that All factors being equal, preference will be give to; Second class interface for and the application process accessing database of database process different priorities use, both comprised high priority, also comprise low priority.
The first kind interface and second class interface have accordant interface primitive and call form, are mapped to certain function by event number, and the required input parameter of the functional definition that provides according to data-interface and the data structure of output parameter.
First kind interface function encapsulation be actual database manipulation power function, the encapsulation of the second class interface function be the forwards function, send the database access request message to the database manipulation process.
First kind process is initiated database manipulation by the primitive that calls first kind interface function, this interface primitive calls database manipulation functional interface function by event number and directly finishes database manipulation, and return results is returned by the data structure of output parameter.
The second class application process is initiated database manipulation by the primitive that calls second class interface, this interface primitive is transmitted function by the event number message call, the unactual database manipulation that carries out of this function, but send the corresponding database access request message to the database manipulation process, the content of database access request message comprises event number, the input parameter data structure.After the database manipulation process is received the database manipulation request message, forward in the database manipulation functional interface function by event number is diffusing, carry out database manipulation, finish back transmission response message to the application process of calling this database interface primitive, the content of this response message comprises event number, the output parameter data structure.
Simultaneously in order to improve the dirigibility of Application of Interface, second class interface provides two kinds of access modes: synchronization message mode and asynchronous message mode, and specifically use which kind of mode can be given in the input parameter data structure of interface.
As shown in Figure 1, the invoked procedure of first kind interface is as described below:
When first kind process need be called database manipulation, embodiments of the invention carry out according to following standard interface: dbCall (EventNo, iParam, oParam), wherein EventNo provides the event number of this database manipulation that calls, input parameter, the oParam that iParam is database manipulation is the data structure of the output parameter of database manipulation.
As shown in Figure 1, the invoked procedure of first kind interface comprises the steps:
Step 101, first kind application process are called first kind interface primitive, and input parameter comprises the event number of the database manipulation that this calls, the data structure of the input parameter value of database manipulation and the output parameter of database manipulation;
Step 102, whether decision event is number legal, if illegal, then arrives step 104, directly returns; If it is legal then enter step 103 and continue to carry out;
Step 103, event number according to database manipulation calls the database manipulation that associated databases operating function interface function carries out reality, database manipulation functional interface function carries out operations such as data access, renewal, interpolation or deletion by the input parameter value in database, and is each variable assignments in the output parameter data structure;
Step 104, function returns, and finishes the call flow to first kind interface.
As shown in Figure 2, the interface function invoked procedure of second class interface is as described below:
When the second class application process more high or low than database manipulation priority called database manipulation, present embodiment provides following standard interface: dbAccess (EventNo, iParam, oParam), wherein EventNo provides the event number of this database manipulation that calls, input parameter, the oParam that iParam is database manipulation is the data structure of the output parameter of database manipulation, and having a member msgtype to indicate this message in the iParam structure simultaneously is synchronization message or asynchronous message.
As shown in Figure 2, the forwards function calls process of second class interface comprises the steps:
Step 201, the second class application process is called the second class interface primitive, and input parameter comprises the data structure of the output parameter of the input parameter value of event number, database manipulation of the database manipulation that this calls and database manipulation;
Step 202, whether decision event is number legal, if illegal, then arrives step 204, directly returns; If it is legal then enter step 203 and continue to carry out;
Step 203, according to given event number, call corresponding forwards function and send the database manipulation request message to the database manipulation process, this request message comprises following parameter: the database manipulation event number of being asked, comprise to indicate and use synchronously or the input parameter value of asynchronous message type, the data structure of output parameter.
Step 204, function returns, and finishes the forwards function calls flow process to second class interface.
As shown in Figure 3, the database manipulation process function call flow in second class interface is as follows:
Standard interface in the present embodiment is: pZDB_ACCESS (MsgId, Msg_iparam, Msg_oparam), wherein message number MsgId unique identification this message database manipulation of asking, consistent with the EventNo in the interface function, Msg_iparam is consistent with iParam and oParam in second class interface language respectively with the Msg_oparam structure.
As shown in Figure 3, the function treatment scheme comprises the steps:
Step 301, the database manipulation process begins the process database operations request message, and the process input parameter comprises message number, input parameter value and output parameter data structure;
Step 302 judges whether message number is legal, if illegal, then arrives step 305, if legal then enter step 303;
Step 303, according to given message number, call corresponding database operating function interface function and carry out actual database manipulation, database manipulation functional interface function carries out operations such as data access, renewal, interpolation or deletion by the value of input parameter in database, be each variable assignments in the output parameter data structure, and send response message for the originating process of initiating to call specifically, response message comprises following parameter: the database manipulation event number of this time execution, the input parameter value that comprises synchronous or asynchronous message, the value of output parameter, originating process;
Step 304, function returns, and the call flow of second class interface is finished fully;
Step 305 abandons this message, directly returns.
Based on the seizing under the scheduling strategy of process priority, the process of high priority guarantees that by calling second class interface conforming disposal route of memory database specifically may further comprise the steps in operating system in the present invention:
Step 1, high priority process A calls the second class interface primitive, and current database operation process B hangs up, the legitimacy of the second class interface call function decision event number, if legal, call subfunction and send the particular data access request message in the message queue of database access process P; If illegal, return wrong back and finish; If the synchronization message mode, then A hangs up, if the asynchronous message mode, then process A continuation operation is finished;
Step 2 because process P and B are in same priority, do not exist and seizes, and continues the B process that is suspended in the treatment step 1 behind A hang-up or the end of run;
Step 3, after the B process disposes, the message queue of operating system scan database process, the processing messages of acquisition P process;
Step 4 begins to carry out the function of database access process P, if the event number that message is given is legal, then loosing forwards database manipulation functional interface function to, carries out database manipulation, if illegal, directly abandon invalid message and finishes;
Step 5, the interface function function is finished, and sends echo reply message to the process A that initiates this operation.
As shown in Figure 4, the process switching of different priorities and message transmitting process are as follows:
In this embodiment, process A priority is higher than database manipulation, has the ability of grabbing database manipulation, and process B priority and database manipulation are equal to, and process P mentions the database access process above being.So three process priority situations are: process A>process B=process P.
In the T1 moment, database process B is carrying out the database access operation;
In the T2 moment, process A need operate database, calls the dbAccess interface, because A priority is higher than database manipulation, then this moment, the B process was suspended;
T3 constantly, the dbAccess interface sends database manipulation request message REQ in the message queue of process P, if what process A sent is synchronization message, then process A is suspended at this moment, if asynchronous message, then process A continues down to carry out (shown in empty arrow among the figure), and level that the process B that process P and T2 are suspended constantly has that All factors being equal, preference will be give to is so continue execution B process;
In the T4 moment, process B is finished, and operating system scans the message of process P, begins to carry out database access process P;
The T5 moment: the database access process P that is caused by process A is finished, and return to A response message ACK, process A receives response message, if T3 constantly, what process A sent is synchronization message, then this moment, process A can become executing state by suspended state, and the data base call operation of process A is finished.
Equally, priority is lower than the application process of database process, call database manipulation request corresponding behind second class interface, send in the database manipulation process as message, because database manipulation process and other database process same priorities, so operating process can not interrupted by other database processes, so calling the high still low practical operation to database of priority of the application process of second class interface all is to finish in the database manipulation process, can not cause database to be reentried.
Certainly; the present invention also can have other various embodiments; under the situation that does not deviate from spirit of the present invention and essence thereof; those of ordinary skill in the art work as can make various corresponding changes and distortion according to the present invention, but these corresponding changes and distortion all should belong to the protection domain of the appended claim of the present invention.