A data updating method, device and electronic equipment
By generating transaction identifiers during transaction processing and using a cache pool to store data, the problem of data inconsistency between the Elasticsearch index and the transactional database is solved, achieving consistent data synchronization and saving memory resources.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-23
- Publication Date
- 2026-04-14
AI Technical Summary
When using Elasticsearch as a data storage solution, if a business system update fails, the data in the index becomes inconsistent with the data in the transactional database, making it impossible to restore the original state.
By generating transaction identifiers during transaction processing and pre-storing data in a cache pool, the data is only written to the index database after the transaction is successfully committed, ensuring data consistency.
It achieves synchronization between the index and the transactional database, maintaining data consistency and saving memory resources.
Smart Images

Figure CN115422213B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus and electronic device for updating data. Background Technology
[0002] With the rapid development of computing technology and continuous innovation in related fields, enterprises are becoming increasingly reliant on big data. In the era of big data, analyzing massive amounts of data and utilizing storage databases to quickly process large volumes of records can effectively solve many problems faced by enterprises. Therefore, current enterprise solutions typically employ big data solutions to address these challenges.
[0003] Elasticsearch is a popular system component in enterprise big data solutions, combining data storage and search engine functionalities. When using Elasticsearch as a data storage solution, data in the business system is typically updated according to the business system's logic.
[0004] In the business system logic, the updated data in the business system is first successfully written to the Elasticsearch index, and then the subsequent processing logic is executed. If the subsequent processing logic fails, the entire business system logic will fail, and the business system needs to be returned to its original state.
[0005] However, when it is necessary to return the business system to its original state, the data that has been successfully written to the Elasticsearch index cannot be restored to its original state, resulting in inconsistency between the data in the index and the corresponding data in the transactional database. Summary of the Invention
[0006] This application provides a method, apparatus, and electronic device for updating data, to solve the problem of inconsistency between data in an index and corresponding data in a transactional database. The specific implementation scheme is as follows:
[0007] In a first aspect, this application provides a method for updating data, the method comprising:
[0008] In response to starting a transaction, a transaction identifier is added to the thread corresponding to the transaction.
[0009] The operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool. The operation data is the data and operation type for operating on the index library.
[0010] Determine whether any abnormalities occur during the processing of the transaction;
[0011] If not, the data that operates on the index library is written into the index library according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool;
[0012] If so, delete the encapsulated data corresponding to the transaction identifier in the cache pool.
[0013] A transaction identifier is generated through the database connection, and this transaction identifier also contains the source data information in the data source corresponding to the transaction. Based on the transaction identifier, the data to be written to the index is saved in the cache pool in advance. Only after the transaction is successfully committed to the transactional database is the data in the cache pool written to the index, so that the data in the index and the corresponding data in the transactional database are synchronized and the data consistency is maintained.
[0014] In one possible design, adding a transaction identifier to the thread corresponding to the transaction includes:
[0015] Generate a transaction identifier based on the database connection corresponding to the transaction;
[0016] Record the source data information from the data source corresponding to the transaction into the transaction identifier;
[0017] Add the transaction identifier to the thread corresponding to the transaction.
[0018] A transaction identifier is generated based on the database connection, and this transaction identifier also contains source data information from the data source corresponding to the transaction. Through the transaction identifier, operations on multiple databases can be distinguished in the same request, and when the data is finally processed, the transaction can be processed according to the specific data source.
[0019] In one possible design, the step of encapsulating the operation data corresponding to the transaction according to the transaction identifier to obtain encapsulated data, and writing the encapsulated data into a cache pool, includes:
[0020] Determine whether the transaction identifier exists in the thread when writing data that operates on the index database in the transaction to the index database according to the operation type of the operation on the index database;
[0021] If not, write the data that operates on the index database in the transaction into the index database according to the operation type;
[0022] If so, the operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool.
[0023] By checking whether a transaction flag exists in the thread when writing data that needs to be manipulated into the index, it can be confirmed whether a transaction has been initiated during the index write operation, thus allowing for the execution of different operations. Simultaneously, by encapsulating the operation data and writing it to a cache pool, data from the transaction processing process is pre-saved, preparing for subsequent operations.
[0024] In one possible design, after writing the data for operating on the index database according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool, the method further includes:
[0025] Obtain the transaction identifier;
[0026] The encapsulated data is deleted from the cache pool according to the transaction identifier.
[0027] By deleting the encapsulated data corresponding to the transaction identifier in the cache pool after the data insertion task is completed, memory occupation is avoided and memory resources are saved.
[0028] In one possible design, before deleting the encapsulated data corresponding to the transaction identifier in the cache pool, the following method is further included:
[0029] Restore all changes that occurred during the processing of the transaction to their original state.
[0030] By restoring all changes that occurred during the transaction to their original state after an anomaly is detected during the transaction processing, the atomicity of the transaction is guaranteed. This ensures that the transaction either completes successfully or remains completely unchanged, thus restoring the integrity of the database.
[0031] Secondly, this application also provides a data updating device, the device comprising:
[0032] Add a module to add a transaction identifier to the thread corresponding to the transaction in response to starting a transaction;
[0033] The caching module is used to encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain the encapsulated data, and write the encapsulated data into the cache pool, wherein the operation data is the data and operation type for operating on the index library;
[0034] The processing module is used to determine whether any abnormalities occur during the processing of the transaction;
[0035] If not, the data that operates on the index library is written into the index library according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool;
[0036] If so, delete the encapsulated data corresponding to the transaction identifier in the cache pool.
[0037] In one possible design, the adding module is specifically used to generate a transaction identifier according to the database connection corresponding to the transaction;
[0038] Record the source data information from the data source corresponding to the transaction into the transaction identifier;
[0039] Add the transaction identifier to the thread corresponding to the transaction.
[0040] In one possible design, the caching module is specifically used to determine whether the transaction identifier exists in the thread when the data that operates on the index database in the transaction is written to the index database according to the operation type of the operation on the index database.
[0041] If not, write the data that operates on the index database in the transaction into the index database according to the operation type;
[0042] If so, the operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool.
[0043] In one possible design, the processing module is specifically used to obtain the transaction identifier;
[0044] The encapsulated data is deleted from the cache pool according to the transaction identifier.
[0045] In one possible design, the processing module is specifically used to restore all changes that occurred during the processing of the transaction back to their original state.
[0046] Thirdly, this application provides an electronic device, comprising:
[0047] Memory, used to store computer programs;
[0048] When a processor executes a computer program stored in the memory, it implements the above-described data update method steps.
[0049] Fourthly, this application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-described data update method steps.
[0050] For the various aspects of the second to fourth aspects mentioned above, and the technical effects that each aspect may achieve, please refer to the above description of the technical effects that can be achieved for the first aspect or the various possible solutions in the first aspect, which will not be repeated here. Attached Figure Description
[0051] Figure 1 A flowchart of a data update method provided in this application;
[0052] Figure 2 The flowchart for writing index database data is shown in the example.
[0053] Figure 3 This is a flowchart illustrating the transaction processing scenario in the example.
[0054] Figure 4 This is a schematic diagram illustrating the data update process.
[0055] Figure 5 A schematic diagram of a data update device provided in this application;
[0056] Figure 6 A schematic diagram of an electronic device provided in this application. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The specific operational methods in the method embodiments can also be applied to the device embodiments or system embodiments. It should be noted that in the description of this application, "multiple" is understood as "at least two". "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. A connected to B can represent: A and B directly connected, and A and B connected through C. Furthermore, in the description of this application, terms such as "first" and "second" are used only for distinguishing the purpose of description and should not be construed as indicating or implying relative importance or order.
[0058] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0059] Currently, in the business system logic, updated data is first successfully written to the Elasticsearch index before subsequent processing logic is executed. If a failure occurs in the subsequent processing logic, the entire business system logic will fail, requiring the system to revert to its original state. However, data successfully written to the Elasticsearch index cannot be restored to its original state, leading to inconsistencies between the data in the index and the corresponding data in the transactional database.
[0060] Therefore, this application proposes a data update method that pre-saves transaction data through a cache pool. Only after the transaction is successfully committed to the transactional database is the data written to the index, thereby synchronizing the data in the index with the corresponding data in the transactional database.
[0061] Reference Figure 1 The diagram shown is a flowchart of a data update method provided in an embodiment of this application. The method includes:
[0062] S1, in response to starting a transaction, adds a transaction identifier to the thread corresponding to the transaction;
[0063] Since transactions in business system logic are typically performed within the same request and processed within the same thread, a transaction identifier is recorded in the thread when a transaction is initiated. As long as the same transaction identifier is used within the same request, the data can be categorized and stored according to this transaction identifier when writing data to the cache pool.
[0064] Specifically, the first step is to initiate a transaction;
[0065] After a transaction is initiated, a transaction identifier is generated according to the database connection corresponding to the transaction.
[0066] Furthermore, the source data information from the data source corresponding to the transaction is recorded in the transaction identifier;
[0067] Finally, add a transaction identifier in the thread corresponding to the transaction.
[0068] By recording transaction identifiers in the above manner, operations on multiple databases can be distinguished within the same request. When processing the data, transactions can also be processed according to specific data sources.
[0069] It should be noted that when passing database operation transactions to threads, the transaction identifier also needs to be passed to the aforementioned threads. This ensures that the data written to the cache pool according to the transaction identifier is consistent with the data in the database receiving the transaction.
[0070] S2, encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain the encapsulated data, and write the encapsulated data into the cache pool;
[0071] Specifically, after the transaction identifier generated by the database and data source corresponding to the transaction has been written into the thread according to step S1, when the data that operates on the index database in the transaction is written into the index database according to the operation type of the operation on the index database, it is determined whether there is a transaction identifier in the above thread.
[0072] If not, write the data that operates on the index in the transaction to the index based on the type of operation performed on the index.
[0073] If so, encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain the encapsulated data, and write the encapsulated data into the cache pool.
[0074] Using the above method, when writing data that needs to be operated on into the index database, the presence of a transaction flag in the thread can determine whether a transaction has been started, and then different operations can be performed accordingly.
[0075] For example, such as Figure 2 In the flowchart of the index database data writing process shown, when an Elasticsearch data write request is received, it is determined whether a transaction unique identifier exists in the thread. If no transaction unique identifier exists in the thread, it means that the write operation to the Elasticsearch index database has not started a transaction. In this case, the write operation is directly called to write the data to the Elasticsearch index database. If a transaction unique identifier exists in the thread, it means that the write operation to the Elasticsearch index database has started a transaction. In this case, the operation data is encapsulated and written to the cache pool.
[0076] The operation data refers to the data and operation type used to operate on the index database. For example, if the operation type is update, then an update operation needs to be performed on the index database.
[0077] It's important to note that when encapsulating operation data, the index identifier, operation type, and operation data identifier must all be encapsulated and saved. By encapsulating the operation type of the data, the processing logic for the index can be implemented, such as adding, deleting, and updating. The input parameters received by this processing logic are the encapsulated data format.
[0078] For example, in the business system logic, if the currently obtained transaction identifier is "12345678", and a new data insertion operation needs to be performed on the index "index1", the operation data corresponding to the transaction identifier "12345678" is encapsulated to obtain encapsulated data. The encapsulated data that needs to be written to the cache pool is:
[0079]
[0080] In other words, for the encapsulated data corresponding to the transaction identifier "12345678", according to the "add" operation type, it is necessary to insert "'cGuid' as '0001' and 'cName' as 'name' into the data with dataId "0001" in the index library "index1".
[0081] The operation data is encapsulated in the above manner to obtain encapsulated data, which is then written into the cache pool. This pre-stores the data during the transaction processing, preparing it for subsequent operations.
[0082] It should be noted that in this embodiment, the cache pool can use a remote dictionary server (Redis) or directly write data into memory, depending on the system's concurrency and the amount of business data. When the system has high concurrency or a large amount of business data, in order not to reduce the speed of transaction processing or consume too much system memory, the cache pool uses a Redis cache server.
[0083] S3 determines whether an exception occurs during the transaction processing;
[0084] After the operation data is saved to the cache pool according to the transaction identifier, there are two subsequent operations for the encapsulated data in these cache pools: insertion and deletion. The subsequent processing logic needs to be determined based on the transaction processing status.
[0085] Specifically, after saving the encapsulated data to the cache pool according to the transaction identifier, it is determined whether there are any exceptions during the transaction processing.
[0086] If not, proceed to step S4;
[0087] If so, proceed to step S5.
[0088] For example, such as Figure 3 In the transaction scenario processing flowchart shown, after a transaction is started and a unique identifier is generated, it is necessary to determine whether the business has ended normally to determine the subsequent processing logic. In other words, it is necessary to determine whether there are any exceptions during the transaction processing.
[0089] If the business ends normally (i.e. there are no exceptions during the transaction processing), the transaction is committed to the relational database. Then, the ingestion task is triggered to retrieve the data corresponding to the unique identifier and write the data to the Elasticsearch index. Then, the deletion task is triggered to delete the data corresponding to the unique identifier from the cache pool (i.e., step S4 is executed).
[0090] If the business does not end normally (i.e. there is an exception during the transaction processing), the transaction is rolled back and a deletion task is triggered to delete the data corresponding to the unique identifier from the cache pool (i.e., execute step S5).
[0091] S4. Based on the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool, write the data that will operate on the index database into the index database.
[0092] Specifically, after confirming that there are no exceptions in the process of a transaction, the transaction identifier is obtained first;
[0093] Next, the transaction is committed to the transactional database;
[0094] After a transaction is successfully committed to a transactional database, an ingestion task is triggered. This means that, based on the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool, the data that will operate on the index is written into the index.
[0095] After completing the ingestion task, the deletion task is called, which means deleting the encapsulated data corresponding to the transaction identifier in the cache pool according to the transaction identifier.
[0096] For example, such as Figure 3 In the transaction processing flowchart shown, when the business ends normally, the transaction is committed to the relational database; after the transaction is successfully committed to the relational database, an ingestion task is triggered to retrieve the data corresponding to the unique identifier and write the data to the Elasticsearch index; finally, a deletion task is triggered to delete the data corresponding to the unique identifier from the cache pool.
[0097] It should be noted that, in this embodiment, the transactional database refers to a database that can receive transactions. It can be a relational database or a distributed database. This embodiment does not limit the specific transactional database.
[0098] For example, for the transaction identifier "12345678", the encapsulated data corresponding to this transaction identifier in the cache pool is as follows:
[0099]
[0100] If no exceptions occur during the transaction processing, the transaction is first committed to the relational database. Then, based on the "delete" operation type in the encapsulated data, all data with dataId "0001" in the "index2" index is deleted. Finally, the encapsulated data mentioned above is deleted from the cache pool.
[0101] By using the above method, after the data insertion task is completed, the encapsulated data corresponding to the transaction identifier in the cache pool is deleted according to the transaction identifier, which avoids memory occupation and saves memory resources.
[0102] S5, delete the encapsulated data corresponding to the transaction identifier in the cache pool;
[0103] Specifically, once an anomaly is detected during the processing of a transaction, the transactional database operation will first call a rollback operation, which means that all changes that occurred during the processing of the transaction will be restored to the original state.
[0104] Next, obtain the transaction identifier;
[0105] Finally, the encapsulated data corresponding to the transaction identifier is deleted from the cache pool according to the transaction identifier.
[0106] For example, such as Figure 3 In the transaction scenario processing flowchart shown, when the business does not end normally, the transaction is rolled back (that is, all changes that occurred during the transaction processing are restored to the original state), and a deletion task is triggered to delete the data corresponding to the unique identifier from the cache pool.
[0107] It should be noted here that restoring all changes that occurred during the transaction processing to the original state includes restoring a series of data and operations generated during the transaction processing to the original state. In other words, after performing the rollback operation, the transaction is exactly the same as the original transaction.
[0108] By employing the above method, once an anomaly is identified during transaction processing, all changes that occurred during the transaction are restored to their original state, ensuring the atomicity of the transaction. This guarantees that the transaction either completes completely successfully or remains entirely unchanged, thus restoring the integrity of the database. Furthermore, the encapsulated data corresponding to the transaction identifier is deleted from the cache pool according to the transaction identifier, avoiding memory consumption.
[0109] For example, for the transaction identifier "12345678", the encapsulated data corresponding to this transaction identifier in the cache pool is as follows:
[0110]
[0111]
[0112] During the transaction processing, parameter A has been passed to function B, and the value of C has been changed to the value of D. However, an exception occurred during the transaction processing. At this time, the series of changes that occurred during the transaction processing are restored to their original state, that is, the value of D is restored to the original value of C, the execution process of function B is cleared, function A is restored to its original position, and the above-mentioned encapsulated data in the cache pool is deleted.
[0113] In summary, the data update method proposed in this application generates a transaction identifier based on the database connection. This transaction identifier also contains source data information from the data source corresponding to the transaction. Data to be written to the index is pre-stored in a cache pool based on the transaction identifier. Only after the transaction is successfully committed to the transactional database is the data in the cache pool written to the index. This method ensures that the data in the index and the corresponding data in the transactional database are synchronized, maintaining data consistency. Furthermore, the transaction identifier allows for data operations across multiple databases and data sources.
[0114] The technical solution of this application will be further explained below with reference to a specific application process.
[0115] like Figure 4 The diagram shows the processing steps of the data update method. First, a transaction is started, and a unique identifier is added to the thread.
[0116] When writing data to the Elasticsearch index, check if a unique identifier exists in the thread;
[0117] If not, directly call the write operation to write the data to the Elasticsearch index database;
[0118] If so, encapsulate the operation data and write it to the cache pool;
[0119] After encapsulating the operation data and writing it to the cache pool, determine whether the business has ended normally;
[0120] If so, commit the transaction to the relational database, then trigger the ingest task to retrieve the identification data and write it to the Elasticsearch index, and then trigger the delete task to delete the identification data from the cache pool;
[0121] If not, perform a transaction rollback, which restores all changes after the transaction occurred to the original state and triggers a deletion task to remove the identifier data from the cache pool.
[0122] By writing operation data to a cache pool, and only writing the data in the cache pool to the index database after the business is completed normally, the data in the index database is synchronized with the corresponding data in the transactional database, thus maintaining data consistency.
[0123] Based on the same inventive concept, this application also provides a data updating device, such as... Figure 5 The diagram shown is a structural schematic of a data update device provided in this application. The device includes:
[0124] Add module 501 to add a transaction identifier in the thread corresponding to the transaction in response to starting a transaction;
[0125] The cache module 502 is used to encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain the encapsulated data, and write the encapsulated data into the cache pool. The operation data is the data and operation type of the operation on the index.
[0126] Processing module 503 is used to determine whether an exception occurs during the processing of a transaction;
[0127] If not, the data that will operate on the index will be written to the index based on the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool.
[0128] If so, delete the encapsulated data corresponding to the transaction identifier in the cache pool.
[0129] In one possible design, module 501 is added, which is specifically used to generate a transaction identifier according to the database connection corresponding to the transaction.
[0130] Record the source data information from the data source corresponding to the transaction into the transaction identifier;
[0131] Add a transaction identifier to the thread corresponding to the transaction.
[0132] In one possible design, the cache module 502 is specifically used to determine whether a transaction identifier exists in the thread when writing data that operates on the index database in a transaction to the index database according to the operation type of the operation on the index database.
[0133] If not, write the data that operates on the index in the transaction to the index, based on the operation type;
[0134] If so, encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain the encapsulated data, and write the encapsulated data into the cache pool.
[0135] In one possible design, processing module 503 is specifically used to obtain the transaction identifier;
[0136] Deleting encapsulated data from the cache pool based on the transaction identifier.
[0137] In one possible design, the processing module 503 is specifically used to restore all changes that occur during the processing of a transaction back to their original state.
[0138] Based on the same inventive concept, this application also provides an electronic device that can realize the function of the aforementioned data update device, see reference. Figure 6 Electronic devices include:
[0139] At least one processor 601 and a memory 602 connected to at least one processor 601. In this embodiment, the specific connection medium between the processor 601 and the memory 602 is not limited. Figure 6 The example shown is the connection between processor 601 and memory 602 via bus 600. Bus 600 is... Figure 6 The connections between other components are indicated by thick lines and are for illustrative purposes only, not as limiting information. The 600 bus can be divided into address bus, data bus, control bus, etc., for ease of representation. Figure 6 The term is represented by a single thick line, but this does not imply that there is only one bus or one type of bus. Alternatively, the processor 601 can also be called a controller; there is no restriction on the name.
[0140] In this embodiment, memory 602 stores instructions executable by at least one processor 601. By executing the instructions stored in memory 602, at least one processor 601 can perform the data update method described above. Processor 601 can implement... Figure 6 The functions of each module in the device shown.
[0141] The processor 601 is the control center of the device. It can connect to various parts of the control device through various interfaces and lines. By running or executing instructions stored in memory 602 and calling data stored in memory 602, the processor can perform various functions and process data, thereby monitoring the device as a whole.
[0142] In one possible design, processor 601 may include one or more processing units. Processor 601 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into processor 601. In some embodiments, processor 601 and memory 602 may be implemented on the same chip; in some embodiments, they may also be implemented on separate chips.
[0143] Processor 601 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit, field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the data update method disclosed in the embodiments of this application can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0144] Memory 602, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 602 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, magnetic disk, optical disk, etc. Memory 602 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. In the embodiments of this application, memory 602 may also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.
[0145] By designing and programming the processor 601, the code corresponding to the data update method described in the foregoing embodiments can be embedded into the chip, enabling the chip to execute it during operation. Figure 4 The steps of the data update method in the illustrated embodiment are as follows. How to design and program the processor 601 is a technique well-known to those skilled in the art and will not be described further here.
[0146] Based on the same inventive concept, embodiments of this application also provide a storage medium storing computer instructions that, when executed on a computer, cause the computer to perform the data update method described above.
[0147] In some possible implementations, various aspects of the data update method provided in this application may also be implemented in the form of a program product, which includes program code that, when the program product is run on a device, causes the control device to perform the steps in the data update method according to the various exemplary embodiments of this application described above.
[0148] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0149] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0150] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0151] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0152] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for updating data, characterized in that, include: In response to starting a transaction, a transaction identifier is added to the thread corresponding to the transaction. The operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool. The operation data is the data and operation type for operating on the index library; the encapsulated data includes the identifier of the index library. Determine whether any abnormalities occur during the processing of the transaction; If not, commit the transaction to the transactional database; after successful commit, write the data that will operate on the index database into the index database according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool; If so, delete the encapsulated data corresponding to the transaction identifier in the cache pool.
2. The method as described in claim 1, characterized in that, Adding a transaction identifier to the thread corresponding to the transaction includes: Generate a transaction identifier based on the database connection corresponding to the transaction; Record the source data information from the data source corresponding to the transaction into the transaction identifier; Add the transaction identifier to the thread corresponding to the transaction.
3. The method as described in claim 1, characterized in that, The step of encapsulating the operation data corresponding to the transaction according to the transaction identifier, obtaining encapsulated data, and writing the encapsulated data into the cache pool includes: Determine whether the transaction identifier exists in the thread when writing data that operates on the index database in the transaction to the index database according to the operation type of the operation on the index database; If not, write the data that operates on the index database in the transaction into the index database according to the operation type; If so, the operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool.
4. The method as described in claim 1, characterized in that, After writing the data for operating on the index database according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool, the method further includes: Obtain the transaction identifier; The encapsulated data is deleted from the cache pool according to the transaction identifier.
5. The method as described in claim 1, characterized in that, Before deleting the encapsulated data corresponding to the transaction identifier in the cache pool, the method further includes: Restore all changes that occurred during the processing of the transaction to their original state.
6. A data update device, characterized in that, include: Add a module to add a transaction identifier to the thread corresponding to the transaction in response to starting a transaction; A caching module is used to encapsulate the operation data corresponding to the transaction according to the transaction identifier, obtain encapsulated data, and write the encapsulated data into a cache pool. The operation data consists of data and operation types for operating on the index database; the encapsulated data includes the identifier of the index database. The processing module is used to determine whether any abnormalities occur during the processing of the transaction; If not, commit the transaction to the transactional database; after successful commit, write the data that will operate on the index database into the index database according to the operation type in the encapsulated data corresponding to the transaction identifier in the cache pool; If so, delete the encapsulated data corresponding to the transaction identifier in the cache pool.
7. The apparatus as claimed in claim 6, characterized in that, The adding module is used to generate a transaction identifier according to the database connection corresponding to the transaction; Record the source data information from the data source corresponding to the transaction into the transaction identifier; Add the transaction identifier to the thread corresponding to the transaction.
8. The apparatus as claimed in claim 6, characterized in that, The caching module is used to determine whether the transaction identifier exists in the thread when writing data that operates on the index database in the transaction to the index database according to the operation type of the operation on the index database. If not, write the data that operates on the index database in the transaction into the index database according to the operation type; If so, the operation data corresponding to the transaction is encapsulated according to the transaction identifier to obtain encapsulated data, and the encapsulated data is written into the cache pool.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a computer program stored in the memory, implements the method steps of any one of claims 1-5.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-5.
Citation Information
Patent Citations
Distributed transaction processing method and distributed system
CN108491252A