Detailed Description
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present specification, the technical solutions in the embodiments of the present specification will be described in detail below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all the embodiments. All other embodiments that can be derived by one of ordinary skill in the art from the embodiments given herein are intended to be within the scope of protection.
The terminology used in the description herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the description. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used herein to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, the first information may also be referred to as second information, and similarly, the second information may also be referred to as first information, without departing from the scope of the present specification. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
When the database is in error, the database needs to be backed from the current version to a correct historical target version so as to be able to continue to use the database to process the service.
The database records data of each version so as to be convenient for follow-up handling of historical data query business, and meanwhile, the database also stores modification operation records so as to back up the database. At present, when a database is rolled back, the following method is generally adopted: when the database has errors, the database administrator can determine the correct target database version, send a rollback instruction to the database and indicate the database to rollback to the correct target database version, after the rollback instruction is received by the database, call a modification operation record stored in the database, obtain the modification operation between the correct version and the current version in the record, convert the modification operation into reverse modification operation, modify the data in the current database by using the reverse modification operation, and then rollback the data in the current database to the correct target version.
For example, the version number of the current database version is 100, the administrator wants to rollback the database from the version with the current version number of 100 to the version with the version number of 50, after receiving the rollback instruction of the administrator, the database needs to call the modification operation record stored in the database, obtain the modification operation between the version 50 and the version 100 in the record, convert all the obtained operations into reverse operations, modify the data of the version 100 by using the reverse modification operation, and then rollback the data in the current database to the version 50. It can be seen that, in the data rollback process, modification operation records need to be acquired, and reverse modification operations need to be sequentially executed, that is, a database needs to execute rollback write-in operations, which is tedious in the overall process and long in consumed time.
In view of the above technical problems, the present specification provides the following solutions:
after receiving the backspacing instruction, the database does not execute backspacing writing operation on the database, generates backspacing information for each backspacing instruction, associates the backspacing information with the current version, continues to process the service after the association is completed, determines a formal database version for executing operation according to the backspacing information in subsequent service processing, and further executes corresponding operation aiming at the determined formal database version. Therefore, the time consumption of the rollback process is greatly shortened, the interruption of database service processing is avoided, and the influence on the database service processing is reduced.
Based on the above description, a method for processing a rollback instruction proposed in the present specification is first described:
in the solution provided in this specification, after receiving a rollback instruction sent by a database administrator, the database does not execute a rollback write operation, that is, does not acquire a modification operation record between a rollback target version and a current version and does not execute a reverse modification operation.
After receiving the rollback instruction, generating rollback information aiming at the current database version, and associating the rollback information with the version number of the current database; the rollback information includes at least a version number of the rollback target version.
For example, if the current version number is 100, the database administrator needs to rollback the database version to a version with a version number of 50, i.e., send a rollback instruction to the database for rolling back the current database version to a version with a version number of 50. After receiving the rollback instruction, the database does not execute rollback write operation, but generates a piece of rollback information for the current database version, that is, generates a piece of rollback information for the version with the current version number of 100, where the rollback information is used to describe that the current version is rolled back to the version number of 50, and associates the generated rollback information with the version number of the current database. As shown in fig. 1, a schematic diagram of associating rollback information with a current version, that is, a version with a version number of 100, where "50" is used to represent the rollback information, and the rollback information is used to describe that the current version, that is, the version with the version number of 100, is rolled back to a target rollback version, that is, the version with the version number of 50, and a specific form of the rollback information may be to identify a corresponding relationship between the current version number 100 and the version number 50; also, because the fallback information is associated with the current version number, only the version number of the fallback target version, i.e. version number 50, may be identified in the description information. The present specification does not limit the specific form of the fallback information.
After the association is complete, a rollback complete message may be returned to the database administrator so that the database administrator may allow the database to continue processing the business.
Therefore, in the process, after the database receives the rollback instruction, only the rollback information needs to be generated and associated with the version number of the current database, and the time consumption of the whole process is short.
Based on the above description, as shown in fig. 2, the present specification provides an implementation method of database operations, as follows:
s201, after receiving a database operation request, determining an initial version number corresponding to the operation request; determining the initial version number as an alternative target version number;
the operation request of the database may be mainly divided into a write operation request and a read operation request, where the read operation request may be a read operation performed on a historical version of the database or a read operation performed on a current version of the database. And the write operation request can only be a write operation performed on the current version of the database. Regardless of whether the operation is a read operation or a write operation, the operation request sent to the database contains an initial version number, i.e., a version number corresponding to the version that the data operator desires to read or write. For a write operation request, the initial version number is the current version number of the database.
After the database obtains the initial version number, the initial version number may be used as a candidate target version number, and subsequent operations may be performed. In connection with fig. 1, it is determined, for example, that the initial version number for which the operation request is directed is 100.
S202, judging whether the current alternative target version number is associated with rollback information or not;
in this step, different steps may be executed according to the determination result, and when it is determined that the current candidate target version number is not associated with the fallback information, S203 may be executed, and when it is determined that the current candidate target version number is associated with the fallback information, S204 may be executed.
Referring to fig. 1, for example, if the initial version number 100 is determined to be the alternative target version number, it may be determined whether the version number 100 is associated with fallback information by querying, as shown in fig. 1, where the version number 100 is associated with fallback information.
Referring to fig. 3, for example, if the initial version number 100 is determined to be the alternative target version number, it may be determined whether the version number 100 is associated with fallback information by querying, as shown in fig. 3, the version number 100 is not associated with fallback information.
S203, determining the current alternative target version number as the formal target version number
In this step, when the current candidate target version number is not associated with the rollback information, it may be directly determined as the formal target version number. In conjunction with the above example of fig. 3, if the current alternative target version number is 100, the version number 100 may be directly determined as the formal target version number.
S204, determining a rollback target version number in the rollback information as an alternative target version number;
in this step, when the current candidate target version number is associated with the fallback information, the fallback information may be further queried, and the fallback target version number in the fallback information may be determined as the new candidate target version number. With reference to fig. 1, when the current candidate target version number 100 is determined to be associated with the fallback information, it may further determine, by querying, that the fallback target version number in the fallback information is 50, replace the version number 100 with the version number 50, and determine that the current candidate target version number is the current candidate target version number, then continue to execute step S202 with the version number 50, and as can be seen from fig. 1, if the version number 50 is not associated with the fallback information, then execute S203 to determine that the version number 50 is the formal target version number.
After the formal target version number is determined, S205 may be performed.
And S205, after the formal target version number is determined, the database operation request is executed according to the database version corresponding to the formal target version number.
After the formal target version number is determined, the received operation request may be executed for the database version corresponding to the determined formal version number, and as described above, the operation request may be a read operation request or a write operation request. The manner in which operations are performed for different operation requests may be as described below and will not be described in detail herein.
Based on the scheme, after the database receives the rollback instruction, the database does not execute rollback writing operation, generates rollback information for each rollback instruction, associates the rollback information with the current version, can continue to process the business after the association is completed, can determine a formal database version for executing the operation according to the rollback information in subsequent business processing, and further executes corresponding operation for the determined formal database version. Because the database can be operated based on the rollback information without executing the rollback writing operation, the time consumption of the rollback process is greatly shortened, and the interruption of the database service processing can be avoided as much as possible, namely the influence on the service processing capacity of the database is avoided as much as possible.
In S205, a manner of executing the database operation request for the database version corresponding to the determined formal target version number is described as follows:
as can be seen from the above description in S201, the operation request of the database is mainly divided into a write operation request and a read operation request, where the read operation request may be a read operation performed on the historical version of the database or a read operation performed on the current version of the database.
First, when the operation request is a read operation request, the specific execution method in S205 is described as follows:
when the operation request is a read request for any database version, after the formal target version number is determined, the database version corresponding to the determined formal target version number can be read.
For example, when the formal target version determined in S203 is the current database version, the current database version may be directly read.
If the formal target version determined in S203 is a certain historical data version, the database version corresponding to the formal target version may be read from the history record in which the historical version is stored.
After the execution mode for the read operation request is introduced, when the operation request is a write operation request, a specific execution mode in S205 is described as follows:
when the operation request is a write operation request for a current database version, if the formal target version determined in S203 is the current database version number, directly writing the current database version according to the write request; for example, operations such as adding and deleting are directly performed on the current data of the database.
In conjunction with fig. 3, the current database version is 100 and has no associated rollback information. After the above processing, it may be determined that the formal target version is the current version number 100 of the database, and the current version of the database may be directly written according to the write operation request.
And if the formal target version number determined in the step S203 is not the current database version number, reading the database version corresponding to the formal target version number from the history record, updating the read version according to the write request, and replacing the current database version with the updated version.
With reference to fig. 1, if the determined final version number is 50 and is not the current database version number 100, the version corresponding to the version number 50 may be read into the memory from the storage location of the historical version, the version corresponding to the read version number 50 is updated according to the write request, after the update is completed, the updated version replaces the current database version, that is, the data corresponding to the current database version is globally replaced with the updated database version, and the version number of the updated version is recorded as the new version 101.
In order to facilitate the administrator to check each version of data or to rollback the current version to a certain historical version, the administrator needs to actively or passively generate the new version and record the corresponding relationship between the new version and the data in the database.
When the operation request is a write operation request, the current data stored in the database can be updated, so that after the database is written according to the database write operation, the current data in the database can be marked as a new version, and the new version is not associated with rollback information. With reference to the newly generated version 101 in the above example, since the new version does not have a rollback relationship with a certain version, rollback information is not associated with the new version.
In addition to generating the new version because of the write operation, the new version may be generated in other ways. For example, the current data in the database may be marked as the new version when the current version data in the database is not updated and a preset version generation condition is met.
For example, one version generation condition may be that, after the database performs data backup according to a manual backup operation of a database administrator, the version manually backed up by the database administrator needs to be marked as a new version even if the data of the current version in the database is not updated.
Another version generation condition may be that, when a preset version generation period is reached, the current data in the database is recorded as a new version, and the database will regularly backup the data in the database, and it can be understood that after each backup, even if there is no data update, the data is recorded as a new version. For example, every 2 hours, a new version is generated after each backup.
In order to apply the solution proposed in the present specification to the new version generated without updating the data in the database, the following processing method is proposed:
and recording the current data in the database as a new version under the condition that the current version data in the database is not updated and meets the preset version generation condition, and associating the rollback information associated with the current version number to the new version number.
As described above, the preset version generation condition may be that a version generation period is reached, a manual backup request of an administrator is received, and the like, and after the new version is generated, the rollback information of the current version of the database may be associated with the new version of the database, that is, in a case where data between the new version and the old version is unchanged, the new version is allowed to inherit the rollback information of the old version, and from this point of view, the new version and the old version are required to be kept "completely consistent".
Referring to fig. 1, if the current version number is 100, after a preset period is reached, the data in the current database is marked as a new version, the version number is 101, and the data corresponding to the version number 101 is identical to the data corresponding to the version 100. The rollback information associated with version number 100 may be associated with version number 101 at this point. It is understood that, in this embodiment, although the rollback information is associated with the version number 101, it does not mean that the rollback information associated with the version number 100 is deleted, and the version number 100 is associated with the rollback information, and in this case, the version corresponding to the version number 100 and the rollback information associated with the version number 101 have the same meaning, and all versions are backed back to the version corresponding to the version number 50.
With reference to the above description, since the rollback information may be in the form of a "corresponding relationship between the current version number and the rollback target version number", or may only include the "rollback target version number", in this embodiment, when the new version needs to inherit the rollback information of the old version, if the rollback information is in the form of a corresponding relationship, the current version number in the rollback information is directly modified to the new version number when the new version inherit the rollback information. If the rollback information is in the form of only including the rollback target version number, the rollback information can be directly inherited without any modification. As shown in fig. 1, if the version generation cycle is reached and the new version 101 is generated, the version number 101 may be directly associated with the rollback information "50".
In order to more clearly illustrate the solution proposed in this specification, the following describes an implementation method of the database operation proposed in this specification by taking fig. 4 as an example:
the current version of the database is 100, and the version number 100 and the version number 50 are respectively associated with rollback information.
For example, after receiving a database write request, the database determines that the initial version number is 100, determines that the initial version number 100 is an alternative target version number, and determines whether the current alternative target version number 100 is associated with rollback information; determining that the version number of the current alternative target is associated with rollback information through inquiry, and determining that the rollback target version number in the rollback information associated with the version number of the current alternative target 100 is 50, replacing 100 with the version number 50 as the version number of the current alternative target;
judging whether the current alternative target version number 50 is associated with rollback information or not; determining that the current alternative target version number 50 is associated with rollback information through inquiry, and determining that the rollback target version number in the rollback information associated with the current alternative target version number 50 is 30, replacing 50 with the version number 30 as the current alternative target version number;
judging whether the current alternative target version number 30 is associated with rollback information or not; and determining that the current alternative target version number 30 is not associated with rollback information through inquiry, determining that the current alternative target version number 30 is a formal target version number, further reading data corresponding to the version number 30 from the history record into a memory, updating the read data according to the received data writing operation request, replacing the currently stored data version of the database by using the updated result, and recording the replaced result as a new version 101, wherein the new version 101 is not associated with the rollback information. Subsequently, if a write operation for version 101 is received, the current version data of the database may be directly written.
Referring to fig. 5, corresponding to the foregoing method for implementing database operations, the present specification further provides an apparatus for implementing database operations, where after receiving a rollback instruction, a rollback message is generated for a current database version without performing a rollback write operation on the database, and the rollback message is associated with a current database version number; the rollback information at least comprises: rolling back the version number of the target version; the device comprises:
an operation request receiving module 510, configured to determine, after receiving a database operation request, an initial version number to which the operation request is directed;
a formal version determining module 520, configured to determine the initial version number as an alternative target version number, and perform the following operations in a loop until a formal target version number is determined:
judging whether the current alternative target version number is associated with rollback information or not;
if so, determining a rollback target version number in the rollback information as an alternative target version number;
if not, determining the current alternative target version number as a formal target version number;
an operation request executing module 530, configured to, after determining the formal target version number, execute the database operation request according to the database version corresponding to the formal target version number.
In an embodiment, the operation request is a read request for any database version, and the operation request executing module 530 is specifically configured to read, according to the database read request, the database version corresponding to the determined formal target version number.
In an embodiment, the operation request is a write request for a current database version, and the operation request executing module 530 is specifically configured to, when the determined formal target version number is the current database version number, write the current database version according to the write request;
and under the condition that the determined formal target version number is not the current version number of the database, reading the database version corresponding to the determined formal target version number, updating the read version according to the write request, and replacing the current version of the database by using the updated version.
As shown in fig. 6, in one embodiment, the apparatus further comprises: the version generation module 540 is configured to mark the current data in the database as a new version and associate the rollback information associated with the current version number to the new version number when the current version data in the database is not updated and a preset version generation condition is met.
In an embodiment, the version generation module 540 is further configured to, after the database is written according to the database writing operation, mark the current data in the database as a new version, and not associate the new version number with the rollback information.
The implementation processes of the functions and actions of the components in the above device are specifically described in the implementation processes of the corresponding steps in the above method, and are not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described apparatus embodiments are merely illustrative. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution in the specification. One of ordinary skill in the art can understand and implement it without inventive effort.
Embodiments of the present specification also provide a computer device, which at least includes a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the aforementioned method when executing the program. The method at least comprises an implementation method of the database operation as shown in fig. 2.
Fig. 7 is a more specific hardware structure diagram of a computing device provided in an embodiment of the present specification, where the device may include: a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050. Wherein the processor 1010, memory 1020, input/output interface 1030, and communication interface 1040 are communicatively coupled to each other within the device via bus 1050.
The processor 1010 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided in the embodiments of the present disclosure.
The Memory 1020 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, or the like. The memory 1020 may store an operating system and other application programs, and when the technical solution provided by the embodiments of the present specification is implemented by software or firmware, the relevant program codes are stored in the memory 1020 and called to be executed by the processor 1010.
The input/output interface 1030 is used for connecting an input/output module to input and output information. The i/o module may be configured as a component in a device (not shown) or may be external to the device to provide a corresponding function. The input devices may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output devices may include a display, a speaker, a vibrator, an indicator light, etc.
The communication interface 1040 is used for connecting a communication module (not shown in the drawings) to implement communication interaction between the present apparatus and other apparatuses. The communication module can realize communication in a wired mode (such as USB, network cable and the like) and also can realize communication in a wireless mode (such as mobile network, WIFI, Bluetooth and the like).
Bus 1050 includes a path that transfers information between various components of the device, such as processor 1010, memory 1020, input/output interface 1030, and communication interface 1040.
It should be noted that although the above-mentioned device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040 and the bus 1050, in a specific implementation, the device may also include other components necessary for normal operation. In addition, those skilled in the art will appreciate that the above-described apparatus may also include only those components necessary to implement the embodiments of the present description, and not necessarily all of the components shown in the figures.
Embodiments of the present specification also provide a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements the foregoing method. The method at least comprises an implementation method of the database operation as shown in fig. 2.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
From the above description of the embodiments, it is clear to those skilled in the art that the embodiments of the present disclosure can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the embodiments of the present specification may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments of the present specification.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to some descriptions of the method embodiment for relevant points. The above-described apparatus embodiments are merely illustrative, and the modules described as separate components may or may not be physically separate, and the functions of the modules may be implemented in one or more software and/or hardware when implementing the embodiments of the present disclosure. And part or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is only a specific embodiment of the embodiments of the present disclosure, and it should be noted that, for those skilled in the art, a plurality of modifications and decorations can be made without departing from the principle of the embodiments of the present disclosure, and these modifications and decorations should also be regarded as the protection scope of the embodiments of the present disclosure.