METHOD FOR WRITING DATA TO AND READING DATA FROM A DATABASE

Abstract: The present invention relates to a method of writing data into and reading data from a database in a system where an information entity is read piecewise, after which the information entity is assembled from the read pieces. To ensure that the read information entity has not changed during the reading of the pieces, the information entities are provided with their own counters, the value of the counter of a particular information entity is changed when data changing information in said information entity is written into the database, the value of the information entity counter is checked in connection with the reading of a first and a last piece of the information entity, and it is concluded that the reading has failed if the value of the counter has changed.

Description: Method for writing data to and reading data from a database The present invention relates to a method of writing data into and reading data from a database in a system where a particular information entity is read piecewise from the database, after which the information entity is as- sembled from the pieces that are read separately, and in which system database data may change between the reading of the separate pieces of the information entity. The invention also relates to a system comprising memory means, writing means for writing data into the memory means, reading means for reading, piecewise, an information entity stored in the memory means, and buffer means for assembling the information entity from the pieces read by the reading means. The invention relates to such a database system where only a certain limited amount of data can be read in connection with one read transaction, whereby reading larger information entities from the database requires that the information entities are read piecewise. An example of such a system is a DX-200 exchange system (by Nokia Telecommunications) employing a TDMS database system. The TDMS database system has a limitation of only allowing about one kilobyte of data to be transferred at one read and write transaction interface. However, since it is necessary to read information enti- ties larger than one kilobyte from the database, said information entities must be read piecewise from the database. If writing data into the database in such a database system is not inhibited for the duration of reading a particular information entity, there is a risk that the database data may change between the reading of the pieces of the information entity in such a way that the read information entity is not necessarily correct, since one of its pieces has changed during the reading. Forbidding all write operations for the duration of the whole reading process is often impossible and unwise, for it dramatically reduces database system performance. A solution is previously known according to which an information entity that is read piecewise is checked by calculating a check sum over the whole information entity. If the same check sum is obtained when all the pieces are read, it is assumed that the reading of data has been completed without errors. However, a significant disadvantage of the known solution is that calculating the check sums requires much calculation capacity. In addi- tion, a change in the data does not necessarily appear in the check sum, for example because two change operations may cancel each other out in the calculation of the check sum. Furthermore, a solution is previously known according to which a time stamp is stored in connection with an information entity in the database, the time stamp denoting when said information entity has last been changed. Correctness of the information entity that is read piecewise can then be checked by utilizing the time stamp, in other words, the reading has been successful if the time stamp has not changed between read operations. It is a disadvantage of the known solution that reliable application of the solution requires utilization of a clock that is frequently updated, particularly in a system in which write operations can be executed very rapidly. However, maintaining such a frequently updated clock requires a considerable amount of calculation capacity, for if the clock is updated too slowly, there is a risk that data written by different write operations obtains the same time stamp. In addition, a solution is previously known according to which two database-specific counters are utilized, and the value of a first counter is changed at the start of each write operation, and the value of a second counter is changed at the end of each write operation. In connection with reading data, it is then first checked if the first and the second counter values are the same. If this is not the case, it shows that data is at the moment being written into the database, whereby the reading is interrupted. It is a disadvantage of the known solution that it locks the whole database for the duration of the write operations, in other words, data cannot be read even from an entirely different database portion (a different information entity) from the one to which the write operation in process is directed. An object of the present invention is to solve the above described problem and provide a more reliable and resource-saving solution for reading data from and writing data into a database. These objectives are achieved by the method of the invention, which is characterized by providing the information entities in the database with counters of their own, changing the value of the counter of a particular information entity when data changing information in said information entity is written into the database, checking the value of the information entity counter in connection with the reading of a first piece and in connection with the reading of a last piece, and concluding that the reading of the information entity has failed if the value of the counter has changed between said checking moments. The invention also relates to a system in which the method of the invention can be utilized. The system of the invention is characterized in that the system comprises information-entity-specific counters, that the reading means are arranged to change, in connection with each writing performed to the memory means, the counter values of the information entities affected by the data written by the writing means, and that the reading means are arranged to check the value of the information entity counter in connection with the reading of a first piece and the reading of a last piece of said information entity and to indicate that the reading has failed if the value of the information entity counter has changed between said checks. The invention is based on the idea that when a separate transaction counter is maintained for each information entity that is read from the database, and when the information entity counters are updated each time when write operations affecting said information entities are executed into the data- base, detecting correctness of the information entities that are read piecewise becomes significantly easier, because the correctness can then be detected by comparing the value of the transaction counter of the read information entity at the beginning of the reading with its value at the completion of the reading. If the value of the counter has changed during the reading of the pieces, it shows that the read information entity is erroneous. Therefore, the most significant advantages of the solution of the invention are that it does not lock the whole database for the duration of the writing of the data, that more reliable information can be obtained on whether the information entity has changed during the reading, and that checking whether the reading was successful re- quires a minimum number of resources, since checking does not require maintenance of a clock operation or calculation of specific check sums. In a preferred embodiment of the method of the invention, a database-specific counter is arranged in connection with the database, and the value of the counter is updated each time when a write operation is executed into the database, after which the information entity counters affected by the executed write operation are changed to correspond to the new value of the database-specific counter. In this embodiment, the information entity counters may consist of memory locations wherein the value of a total counter is stored, since actual counter operations are not required to be executed by them. The database-specific counter thus provides a kind of clock function by means of which the order in which different information entities of the database have been updated can be later detected. The preferred embodiments of the method and system of the invention are disclosed in the attached dependent claims 2 and 4 to 5. In the following, the invention will be described in more detail by way of example with reference to the accompanying figures, in which Figure 1 shows a flow diagram of a first preferred embodiment of the method of the invention, Figure 2 shows a block diagram of a first preferred embodiment of the system of the invention, Figure 3 shows a flow diagram of a second preferred embodiment of the method of the invention, and Figure 4 shows a block diagram of a second preferred embodiment of the system of the invention. Figure 1 shows a flow diagram of a first preferred embodiment of the method of the invention. The flow diagram in Figure 1 can be utilized for controlling the reading and writing of database data in a database from which information entities must be read piecewise. In block A, information-entity-specific counters are arranged in the system. An individual information entity counter can consist of, for example, a memory location with a numerical value stored therein and incremented by a write process in connection with each write transaction in which data affecting said information entity is written. In block B, it is checked if unread data exists at said moment. In other words, if an information entity from the database is wholly unread or, al- ternatively, one or more pieces of an information entity are unread, the routine proceeds to block C. If no unread data exists, the routine proceeds to block J. In block C, it is checked if the reading of a first piece of a new information entity is involved. If so, the routine proceeds to block D. In block D, in connection with the reading of the first piece of the new information entity to be read, the value of said information entity counter is checked. Said value is stored, for example, in a given memory location from where it can be later read. In block E, the next information entity piece in turn is read. Then, a portion as large as possible is naturally read from the information entity at a time, in other words, if a small information entity is involved, only one reading may be required. If, in contrast, a larger information entity that cannot be read in full is involved, a portion as large as possible is read from it at a time. In block F, after reading it is checked if the read piece was the last one. If it is then detected that the last piece of the information entity was involved, the routine proceeds to block G where the value of the read informa- tion entity counter is checked. Next, the value of said counter is compared with the value of the same counter in connection with the reading of the first piece (block D). If it is then detected that the value of the counter has changed during the reading of the pieces within the information entity, the routine proceeds from block H to block I where a reading failure is indicated. This can take place, for example, in such a way that reading means indicate that said information entity is unread, whereupon they re-read it from the beginning on the next occasion. In block J, it is checked if unwritten data exists. If unwritten data exists, the routine proceeds to block K where the unwritten data is written into the database. When the data is written, the routine proceeds to block L where the value of the counters of all the information entities affected by the written data are updated. The counters that should be updated while given data is being written can be detected, for example, by maintaining an index about the infor- mation entities of the database, the index showing the information entities whereto the given data written into the database is related. Figure 2 shows a block diagram of a first preferred embodiment of the system of the invention. In the case in Figure 2, a controller 1 is connected to the other parts of the system via three data transmission connections L1 to L3. The controller 1 thus receives and sends data stored in a memory M via said data transmission connections. The data designated to be written into the database is written into the memory M by means of a write unit 2. Said write unit first writes the received data into the database, whereupon it checks which information entities were affected by the data. If it is assumed by way of example that the write unit 2 writes data DATA1 into the memory M, it is detected from Figure 2 that said data affects information entities 1 , 2 and n. Consequently, the write unit 2 updates said information entity counters C1 , C2 and Cn by incrementing their values by one. Correspondingly, if it is assumed that the write unit 2 writes data DATA3 into the memory M, it updates the counters C1 and Cn, since the data DATA3 affects the information entity 1 and the information entity n. The data DATA3 may be related to, for example, a mobile communication system subscriber's subscriber data and affect, for example, the data of the groups (information entity 1 and information entity n) with which said subscriber is associated. The counters C1 to Cn may consist of, for example, memory locations, in which case, the write unit 2 first checks, in connection with the updating of the memory locations, the value stored in the memory locations and, after that, stores a new value therein. In connection with the reading of the data, a read unit 3 checks, in connection with the reading of a first piece, the initial value of said information entity counter, for example C2. Next, the read unit 3 reads the information entity piece by piece (in pieces as large as possible). The read unit 3 stores each read piece in a memory. When the last piece within said information entity is read, and the information entity as a whole is thus in the memory of the read unit 3, the read unit re-checks the value of the counter C2 of the read information entity. If it detects that the value of the counter has changed between the reading of the first and the last piece, then the reading of the information entity has failed, whereby the read unit starts re-reading the information entity from the beginning. If, in contrast, the value of the counter C2 has not changed, the reading has been successful, whereby the read unit further transmits the read information entity to the controller 1 to be forwarded by means of one of the data transmission connections L1 to L3. Figure 3 shows a flow diagram of a second preferred embodiment of the method of the invention. The flow diagram in Figure 3 closely corre- sponds to the flow diagram in Figure 1. However, said flow diagrams differ from one another in that a database-specific counter, in addition to information-entity-specific counters, is also maintained in connection with the flow diagram in Figure 3. Consequently, when data is written into the database in block K', the database-specific counter is thereafter updated in block L' by incrementing its value by one, for example. Said counter is thus updated each time when data is written into the database. In block M', each information entity counter value affected by the written data is updated. Updating is implemented by copying the new value of the database-specific counter (the value obtained by the counter in block L') as the counter value of each information entity to be updated. The order in which the information entities have been updated can thus be detected from the values of the information entity counters, if required. Figure 4 shows a block diagram of a second preferred embodiment of the system of the invention. The block diagram in Figure 4 closely corre- sponds to the block diagram in Figure 2 except that in the case in Figure 4, a database-specific counter C is utilized in addition to the information-entity- specific counters C1 to Cn. When data is written into a memory M', a write unit 2' first updates the database-specific counter C, for example by incrementing its value by one. Next, the write unit 2' updates each information entity counter C1 to Cn value affected by the data that is written, to correspond to the new value of the database-specific counter C. It is to be understood that the above description and the related figures are only intended to illustrate the present invention. It will be apparent to those skilled in the art that many variations and modifications can be made to the invention without departing from the scope and spirit of the invention disclosed in the attached claims.

Claims: CLAIMS 1. A method of writing data into and reading data from a database in a system where a particular information entity is read piecewise from the database, after which the information entity is assembled from the pieces that are read separately, and in which system database data may change between the reading of the separate pieces of the information entity, c h a r a c t e r i z e d by providing the information entities in the database with counters of their own, changing the value of the counter of a particular information entity when data changing information in said information entity is written into the database, checking the value of the information entity counter in connection with the reading of a first piece and in connection with the reading of a last piece, and concluding that the reading of the information entity has failed if the value of the counter has changed between said checking moments. 2. A method as claimed in claim 1 , c h a r a c t e r i z e d by providing a database-specific counter in connection with the database, and changing the value of the database-specific counter when new data is written into the database, and changing the counter values of the information entities affected by data written into the database to correspond to the new value of the database-specific counter. 3. A system comprising memory means (M, M'), writing means (2, 2') for writing data into the memory means (M, M'), reading means (3) for reading, piecewise, an information entity stored in the memory means (M, M'), and buffer means (3) for assembling the information entity from the pieces read by the reading means, c h a r a c t e r i z e d in that the system comprises information-entity-specific counters (C1 to Cn), that the reading means (2, 2') are arranged to change, in connection with each writing performed to the memory means (M, M'), the counter (C1 to Cn) values of the information entities affected by the data written by the writing means, and that the reading means (3) are arranged to check the value of the information entity counter (C1) in connection with the reading of a first piece and the reading of a last piece of said information entity and to indicate that the reading has failed if the value of the information entity counter (C1) has changed between said checks. 4. A system as claimed in claim 3, characterized in that the system further comprises a total counter (C), whereby the writing means (2') are arranged to change the value of the total counter (C) in connection with each write operation executed into the memory means (M') and to change the counter values (C1 ) of the information entities affected by the data written into the memory means (M') by the writing means (2'), to correspond to the new changed value of the total counter (C). 5. A system as claimed in claim 3 or 4, characterized in that said system is part of an exchange system.

Inventors: GRANBACKA JAN-ERIK, HEINO JUKKA, KOLPPO PETTERI, VALLI JYRKI, GRANBACKA, JAN-ERIK, HEINO, JUKKA, KOLPPO, PETTERI, VALLI, JYRKI
Applicants: GRANBACKA JAN ERIK, HEINO JUKKA, KOLPPO PETTERI, NOKIA TELECOMMUNICATIONS OY, VALLI JYRKI, GRANBACKA, JAN-ERIK, HEINO, JUKKA, KOLPPO, PETTERI, VALLI, JYRKI
Application year: 1998
Main classification: G06F17
IPC codes: G06F17