Data Processing Method, Apparatus, Device, and Storage Medium Based on Cache Coherence
By setting mark bits in Zookeeper and application servers, determining the data write request status and blocking or resetting, the data consistency problem of databases and caches in distributed systems is solved, ensuring the accuracy and performance of data processing.
Patent Information
- Application Number
- CN202111504077.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-10
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-10
AI Technical Summary
In distributed systems, the consistency of the data between the database and cache is difficult to guarantee, especially in the case of concurrent requests. The existing cache double-deletion scheme may lead to problems in reading old data due to the difficulty in determining the delay time.
By setting the first mark bit and the second mark bit of the application server in the Zookeeper server, the status of the data write request is judged, and the data is written to the database master library and the slave library are synchronized asynchronously using the log listening service to block or reset the mark bit during the data write request to ensure data consistency.
It realizes that only one data write request is used to modify the data at any point in time, avoiding the inconsistency problem caused by reading old data, and improving the performance and consistency of data processing.
Smart Images

Figure CN114168636B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a data processing method, apparatus, device, and storage medium based on cache consistency. Background Art
[0002] Zookeeper is an open-source distributed coordination application service. Based on Zookeeper, functions such as data publishing / subscribing, distributed coordination, and synchronization in a distributed system can be realized. Through the multi-node deployment method, high availability of data is achieved, and the data processing speed is improved. However, cache consistency of data in a distributed system needs to be ensured. Consistency generally means that each read operation on data must return the value last written to this position. However, due to concurrent requests, multiple requests may operate on the same data simultaneously, resulting in inconsistent data in the database and the cache.
[0003] To solve the above problems, the "double cache deletion" scheme has been proposed in Internet technologies, that is: when a write request to the database reaches the server, the server first deletes the data in the cache, then modifies the database, and after a certain time delay, deletes the cache again, so as to ensure the consistency between the database and the cache. However, due to the difficulty in determining the delay time, it is also possible that after the write request deletes the cache and before writing to the database, if a read request reads the old data first and fills it into the cache, the problem of inconsistent data will also occur. Summary of the Invention
[0004] The purpose of the embodiments of this application is to provide a data processing method, apparatus, device, and storage medium based on cache consistency to solve the problem of data consistency between the database and the cache.
[0005] In a first aspect, the embodiments of this application provide a data processing method based on cache consistency, which is applied to an application server. The application server is respectively connected to a Zookeeper server, a cache server, and a database server. The method includes: receiving a data write request sent by a client, where the data write request includes data to be operated; deleting the cache data corresponding to the data to be operated in the cache server, and determining whether a first flag bit corresponding to the data to be operated stored in the Zookeeper server is modified. The first flag bit is used to identify whether the data to be operated is being written; if the first flag bit is not modified, modifying the first flag bit and a second flag bit corresponding to the data to be operated in the service memory of the application server, and writing the data to be operated into the main database of the database server, and using the main database to synchronize the data to be operated to the slave database of the database server; if the first flag bit is modified, blocking the data write request.
[0006] In an embodiment of the present application, first, a data write request sent by a client is received. The write request includes data to be operated on. First, the cached data in the cache is deleted. Then, by determining whether the first flag bit corresponding to the data to be operated on stored in the Zookeeper server has been modified, the first identification bit is used to identify whether the data to be operated on is being written, and the first flag bit and the second flag bit in the service memory are modified. The second flag bit is used to mark in the service memory and has the same function as the first flag bit. Then, data synchronization is performed. If it has been modified, the data write request is blocked. By judging the states of the first flag bit and the second flag bit to process whether there is a data write request for the current data, it is ensured that there is only one data write request to modify the current data to be operated on at any time, thus ensuring the data consistency between the database and the cache.
[0007] Further, a data read request for reading data to be read sent by the client is received; if the cached data corresponding to the data to be read is not read from the cache server according to the data read request, the data to be read is read from the slave database, and it is determined whether the third flag bit corresponding to the data to be read in the service memory of the application server has been modified; if so, the cached data corresponding to the data to be read in the cache server is not updated; if not, the data to be read is updated to the cached data.
[0008] In an embodiment of the present application, by receiving a data read request for reading data to be read sent by a client, if the cached data corresponding to the data to be read is not read from the cache server according to the data read request, the data to be read is read from the slave database of the database, and it is determined whether the third flag bit corresponding to the data to be read in the service memory of the application server has been modified. The third flag bit is the flag bit of the data to be read in the service memory. If it has been modified, the cached data in the cache server is not updated. If it has not been modified, the data to be read is updated to the cached data. By judging whether the third flag bit has been modified to determine whether to update the cached data, the problem of data inconsistency caused by reading the old value stored in the database to update the cached data during the process of processing the data write request is avoided.
[0009] Further, after writing the data to be operated on into the master database of the database server and using the master database to synchronize the data to be operated on to the slave database of the database server, the method further includes: resetting the first flag bit and the second flag bit.
[0010] In the embodiment of the present application, after writing the data to be operated into the main database and synchronizing the slave database, the first flag bit and the second flag bit can also be reset. By resetting, the first flag bit and the second flag bit can be restored to the unmodified state, which is to be able to continue to execute the next data write request after writing the data to be operated, and avoid the data write request from being blocked.
[0011] Further, a log listening service is running on the application server. The step of writing the data to be operated into the main database of the database server and synchronizing the data to be operated to the slave database of the database server by using the main database includes: writing the data to be operated into the main database and generating an update log; if the log listening service monitors the update log, synchronizing the data to be operated to the slave database according to the update log.
[0012] In the embodiment of the present application, since a log listening service is running on the application server, by writing the data to be operated into the main database and generating an update log, when the log listening service monitors the update log, the data to be operated is synchronized to the slave database according to the update log. By the way of the log listening service monitoring the update log, the write operation and the synchronization operation of the data to be operated can be separated. As long as the update log of the data to be operated is generated, the write operation of the data to be operated can be recorded. The subsequent synchronization step can be carried out asynchronously by using the log listening service, and the final consistency effect of the data can also be achieved, and the performance of the application is improved.
[0013] Further, after the step of if the log listening service monitors the update log and synchronizing the data to be operated to the slave database according to the update log, the method further includes: obtaining the synchronization result of the data to be operated, where the synchronization result is the result of whether the synchronization of the data to be operated to the slave database is successful or not; if the synchronization result is not successful, resetting the first flag bit and the second flag bit.
[0014] In the embodiment of the present application, after synchronizing the data to be operated to the slave database through the update log, the synchronization result of the written data can also be obtained. The synchronization result is the result of whether the synchronization of the data to be operated to the slave database is successful or not. If the synchronization result is not successful, the first flag bit and the second flag bit are also reset. By resetting the first flag bit and the second flag bit when the synchronization result is not successful, it can be realized that when a synchronization failure result occurs, the data write request is directly ended, and subsequent data write requests are prevented from being blocked due to the previous write request not being ended, resulting in program crashes.
[0015] Further, obtain the execution result of the data write request, where the execution result is the result indicating whether the data write request is successfully executed; if the execution result is unsuccessful, reset the first flag bit and the second flag bit.
[0016] In the embodiment of the present application, the data write request may also have an unsuccessful execution result. When the data write request has an unsuccessful execution result, the data write request can be terminated in time, and the first flag bit and the second flag bit are reset, so that the execution process of the next data write request can be entered as soon as possible, improving the data processing speed.
[0017] Further, a flag bit monitoring service is running in the application server. The modification of the first flag bit and the second flag bit corresponding to the data to be operated in the service memory of the application server includes: if the flag bit monitoring service monitors that the first flag bit is modified, synchronously modify the second flag bit with the first flag bit.
[0018] In the embodiment of the present application, since a flag bit monitoring service is also running in the application server, which is used to synchronously modify the second flag bit and the first flag bit when the first flag bit is modified. By using the flag bit monitoring service for synchronous modification, the modification of the first flag bit and the second flag bit can be made more timely, ensuring the normal operation of the program.
[0019] In a second aspect, an embodiment of the present application provides a data processing device based on cache consistency. The device includes: a receiving module, configured to receive a data write request sent by a client, where the data write request includes data to be operated; a judging module, configured to delete the cache data corresponding to the data to be operated in the cache server, and judge whether the first flag bit corresponding to the data to be operated stored in the Zookeeper server is modified; a flag bit unmodified module, configured to, if the first flag bit is not modified, modify the first flag bit and the second flag bit corresponding to the data to be operated in the service memory of the application server, and write the data to be operated into the main database of the database server, and use the main database to synchronize the data to be operated to the slave database of the database server; a flag bit modified module, configured to, if the first flag bit is modified, block the data write request.
[0020] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a bus, where the processor and the memory complete mutual interaction through the bus;
[0021] The memory stores program instructions executable by the processor, and the processor can execute the method of the first aspect by calling the program instructions.
[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, including:
[0023] The computer-readable storage medium stores computer instructions, and the computer instructions cause the computer to execute the method of the first aspect.
[0024] Other features and advantages of the present application will be described in the subsequent specification, and partly become apparent from the specification, or be understood by implementing the embodiments of the present application. The objectives and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written specification, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0026] Figure 1 A schematic flowchart of a data processing method based on cache coherence provided for an embodiment of the present application;
[0027] Figure 2 Another schematic flowchart of a data processing method based on cache coherence provided for an embodiment of the present application;
[0028] Figure 3 A schematic structural diagram of a data processing device based on cache coherence provided for an embodiment of the present application;
[0029] Figure 4 A schematic structural diagram of an electronic device entity provided for an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0030] The following will describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application.
[0031] Before introducing the data processing method based on cache coherence provided for the embodiments of the present application, some concepts involved in the embodiments of the present application will be introduced first:
[0032] Distributed system: A system composed of a group of computer service nodes that communicate through a network and coordinate to complete common tasks. The emergence of a distributed system is to use inexpensive and ordinary machines to complete computing and storage tasks that cannot be completed by a single computer. Its purpose is to utilize more machines to process more data.
[0033] Zookeeper: A distributed system coordination service that provides a way for each service node to register its address with the coordination center, enabling communication among service nodes.
[0034] Load Balance: Distribute processing tasks across multiple service nodes for execution, avoiding the single point of failure problem of servers.
[0035] Strong Consistency: It means that at any moment, any request can obtain the most recently successfully updated data from the system or cannot read valid data, ensuring data accuracy.
[0036] Weak Consistency: It means that after an update operation is completed, the system does not guarantee that subsequent access operations will return the most recently updated value, nor does it guarantee how long it will take to access the most recently updated value.
[0037] Transaction: An execution unit of operations in a database. For example, in a personnel management system, when deleting a person, it is necessary to delete the person's basic information and also delete related information such as mailboxes and articles. In this way, these database operation statements form a transaction.
[0038] Figure 1 The following is a schematic flowchart of a data processing method based on cache consistency provided by an embodiment of the present application. As Figure 1 shown, this method can be applied to an application server, which is a server deploying a distributed system and can include multiple service nodes for completing the coordinated operation of the entire distributed system. The method includes:
[0039] Step 101: Receive a data write request sent by a client, where the data write request includes the data to be operated on.
[0040] In a specific implementation process, in a distributed system, the data write request sent by the client is executed on a service node of the application server through a load balancing method. The data write request can be an update, insertion, or deletion operation on the data to be operated on. The present application does not limit the specific operation type of the data write request. For example, if the data to be operated on is the order status of order number 1, the data write request can be to modify the order status from uncompleted to completed in the order service system.
[0041] Step 102: Delete the cache data corresponding to the data to be operated on in the cache server, and determine whether the first flag bit corresponding to the data to be operated on stored in the Zookeeper server has been modified.
[0042] In the specific implementation process, since the data stored in the cache server is temporary data, first, the cache data corresponding to the data to be operated on stored in the cache server is deleted. As a distributed system coordination service, each service node stores a unique path identifier in Zookeeper, and through this path identifier, the data memory of the data to be operated on by the corresponding service node can be determined. The first flag bit can be a Boolean value in the data to be operated on by the service node stored in the Zookeeper server, used to mark whether there is currently a write request operating on the data to be operated on. For example, when the first flag bit is true (the first flag bit has not been modified), as the initial state, there is no data write request operating on the data, and when the first flag bit is false (the first flag bit has been modified), it indicates that the data to be operated on is currently in the writing process. The meaning of the Boolean value can also be exchanged.
[0043] Step 103: If the first flag bit has not been modified, modify the first flag bit and the second flag bit corresponding to the data to be operated on in the service memory of the application server, and write the data to be operated on into the main database of the database server, and use the main database to synchronize the data to be operated on to the slave database of the database server.
[0044] In the specific implementation process, according to the foregoing description, if the first flag bit has not been modified, it means that there is currently no data write request to write the data to be operated on, so the data write request for the data to be operated on can be executed. First, modify the first flag bit and the second flag bit. The second flag bit is used to identify whether the cache data can be updated using the data to be operated on when receiving a data read request for reading the data to be operated on. Corresponding to the first flag bit, the second flag bit can be a Boolean value in the data to be operated on stored in the service memory of the service node of the application server, including two states: true and false, used to mark the unmodified state and the modified state. This is to prevent the data in the database from not being written completely when the data write request is executed, and the data write request reads the original value in the database and updates it to the cache, avoiding data inconsistency. Then write the data to be operated on into the main database in the database, and use the main database to synchronize the data to be operated on to the slave database in the database. After the update operation and the synchronization operation are completed, the transaction of the database operation can be considered completed. If the transaction completion fails, the transaction needs to be rolled back to ensure strong data consistency.
[0045] Step 104: If the first flag bit has been modified, block the data write request.
[0046] In a specific implementation process, according to the above description, when the first flag bit is modified, it indicates that there is a prior data write request to write the data to be operated on currently. Then, block the data write request to ensure that the data to be operated on can only be written by one data write request at the same time, avoiding data inconsistency caused by concurrent requests.
[0047] Based on the above embodiment, receive a data read request sent by the client for reading data to be read; if the cached data corresponding to the data to be read is not read from the cache server according to the data read request, then read the data to be read from the slave database, and determine whether the third flag bit corresponding to the data to be read in the service memory of the application server is modified; if so, do not update the cached data corresponding to the data to be read in the cache server; if not, update the data to be read to the cached data.
[0048] In a specific implementation manner, the database adopts a master-slave replication deployment method. The master database is responsible for receiving write requests of the database to update data, and the slave database is a backup of the master database and is responsible for receiving read requests, thereby realizing read-write separation of the database and improving the application performance of the database.
[0049] The data to be read can be the above-mentioned data to be operated on. In this case, the third flag bit corresponding to the data to be read in the service memory of the application server is also the second flag bit corresponding to the data to be operated on. That is to say, while executing a data write request for the data to be operated on, a read operation can also be performed simultaneously. To ensure the consistency during the reading process of the data to be operated on, it can be determined whether the second flag bit of the data to be operated on in the service memory of the current application server is modified. If the second flag bit is modified, it indicates that the current data to be operated on is being written, and the cached data of the data to be operated on has been deleted previously. To prevent the read request from affecting the data consistency between the database and the cache, the data to be operated on is not updated to the cache. If it is not modified, it indicates that the current data to be operated on is not being written, then the data can be directly updated to the cache, and at this time, it will not affect the data consistency between the database and the cache.
[0050] If the data to be read is not the above-mentioned data to be operated on, it can also be determined whether the data to be read needs to be updated to the cache according to the third flag bit of the data to be read. The reason is the same as above and will not be elaborated here.
[0051] Based on the above embodiment, after writing the data to be operated on into the master database of the database server and synchronizing the data to be operated on to the slave database of the database server by using the master database, the method further includes:
[0052] The first flag bit and the second flag bit are reset.
[0053] In the specific implementation process, the reset can be to restore the first mark bit and the second mark bit to the unmodified initial state. After the write request is executed, it can be considered that the transaction of the data write request is successfully executed. By resetting the first mark bit and the second mark bit, the blocking state of the next data write request can be released, so that the next data write request can continue to be executed, thereby ensuring the normal execution of the write request in the application server.
[0054] On the basis of the above embodiment, a log monitoring service is running on the application server, and the data to be operated is written into the master library of the database server, and the data to be operated is synchronized to the slave library of the database server by using the master library, including:
[0055] Writing the data to be operated into the main database and generating an update log;
[0056] If the log monitoring service monitors the update log, the data to be operated is synchronized to the slave library according to the update log.
[0057] In the specific implementation process, the log monitoring service can be a synchronization service provided by the application server. For example, in a non-strong consistency scenario, it is not necessary for both the master and slave databases to synchronize data before the transaction is considered to be submitted successfully. The log monitoring service can monitor the binlog log of the master database in the database. Binlog is a binary file that records the SQL statement information of the user's update to the database. It is mainly used for the master-slave replication of the database and the incremental recovery of data. For example, SQL statements that change database tables and change content will be recorded in the binlog. Synchronizing the binlog log to the log monitoring service can also be considered that the subsequent slave database has synchronized the data to be operated from the master database. It is suitable for application scenarios with weak consistency and can effectively improve the performance of database reading and writing.
[0058] On the basis of the above embodiment, if the log monitoring service monitors the update log, after synchronizing the data to be operated to the slave library according to the update log, the method further includes:
[0059] Acquire the synchronization result of the data to be operated, where the synchronization result is the result of whether the synchronization of the data to be operated to the slave database is successful or not;
[0060] If the synchronization result is unsuccessful, the first mark bit and the second mark bit are reset.
[0061] In a specific implementation process, the synchronization result of the data write request is the execution result synchronized to the slave database. For example, during the synchronization process of the slave database, some incorrect operations or abnormal network conditions may occur, resulting in the failure or timeout of the slave database synchronization. In the application scenario of strong consistency, since the synchronization operation in the data write request fails to be executed successfully, the data write request fails to be executed, which may lead to transaction rollback. If the data write request fails to be executed, the first flag bit and the second flag bit are reset, which is also to prevent subsequent data write requests from being blocked all the time, thus causing application anomalies.
[0062] Based on the above embodiments, obtain the execution result of the data write request, where the execution result is the result of whether the data write request is successfully executed;
[0063] If the execution result is unsuccessful, reset the first flag bit and the second flag bit.
[0064] In a specific implementation process, the data write request may also fail to be executed. For example, network anomalies or database anomalies may cause the write to be unsuccessful. In this case, the first flag bit and the second flag bit should be reset, so that other data write requests can be executed normally, and data read requests can normally read data from the database and write the data back to the cache.
[0065] Based on the above embodiments, a flag bit monitoring service runs in the application server. The modification of the first flag bit and the second flag bit corresponding to the data to be operated in the service memory of the application server includes:
[0066] If the flag bit monitoring service monitors that the first flag bit is modified, synchronously modify the second flag bit with the first flag bit.
[0067] In a specific implementation process, a flag bit monitoring service runs in the application server. The flag bit monitoring service is used to monitor the synchronous modification of the first flag bit and the second flag bit. For example, after the operation of the data write request is completed, the first flag bit in Zookeeper is modified. When the flag bit monitoring service monitors that the first flag bit is modified, the flag bit monitoring service will synchronously modify the second flag bit in the service memory of each service node in the application server to keep the second flag bit consistent with the first flag bit. Therefore, for subsequent data read requests, if the data in the cache is not hit, after reading the data from the database, it will be synchronized to the cache; and for subsequent data write requests, after reading that the first flag bit is reset, the data write request process can continue to be executed, thus achieving data consistency.
[0068] Figure 2Another schematic diagram of the data processing method based on cache coherence provided by the embodiments of the present application is as follows Figure 2 As shown, the specific process can be described as the synchronous execution of data write requests and data read requests. The main execution steps are divided into two aspects: write requests and read requests. The steps of the read requests are marked with D in front. For example, D201 represents the first step of the read request.
[0069] The specific implementation manner of the write request can be:
[0070] Step 201: Receive a write request from the client for writing the data to be operated on;
[0071] Step 202: Delete the cache data corresponding to the data to be operated on;
[0072] Step 203: Determine whether the first flag bit corresponding to the data to be operated on in Zookeeper has been modified;
[0073] Among them, if it has not been modified, modify the first flag bit; if the first flag bit has been modified, block the write request;
[0074] Step 204: Modify the second flag bit of the data to be operated on in the application server in the application server;
[0075] Step 205: Write the data to be operated on into the main database, and use the main database to synchronize the data to be operated on to the slave database;
[0076] Step 206: After the synchronization is completed, reset the first flag bit;
[0077] Step 207: Reset the second flag bit;
[0078] Step 208: If the write request or the synchronous execution fails, also reset the second flag bit.
[0079] The specific implementation manner of the read request can be:
[0080] D201: Receive a read request from the client for reading the data to be operated on;
[0081] D202: First read from the cache;
[0082] D203: If not read, continue to read from the slave database of the database;
[0083] D204: Determine whether to write back according to the second flag bit corresponding to the data to be operated on in the application server;
[0084] Among them, if the second flag bit has not been modified, write back the data to be operated on to the cache; if the second flag bit has been modified, do not write back.
[0085] Figure 3 This is a schematic structural diagram of a data processing device based on cache coherence provided by an embodiment of the present application. This device can be a module, a program segment, or code on an electronic device. It should be understood that this device corresponds to the above Figure 1 method embodiment and can execute Figure 1 each step involved in the method embodiment. The specific functions of this device can be seen in the above description. To avoid repetition, the detailed description is appropriately omitted here. An embodiment of the present application provides a data processing device based on cache coherence, and this device includes:
[0086] A receiving module 301, configured to receive a data write request sent by a client, where the data write request includes data to be operated on;
[0087] A judging module 302, configured to delete the cache data corresponding to the data to be operated on in the cache server, and judge whether a first flag bit corresponding to the data to be operated on stored in the Zookeeper server is modified. The first flag bit is used to identify whether the data to be operated on is in the process of being written;
[0088] A non-modified flag bit module 303, configured to, if the first flag bit is not modified, modify the first flag bit and a second flag bit corresponding to the data to be operated on in the service memory of the application server, and write the data to be operated on into the main database of the database server, and use the main database to synchronize the data to be operated on to the slave database of the database server;
[0089] A modified flag bit module 304, configured to block the data write request if the first flag bit is modified.
[0090] Based on the above embodiment, the device further includes a read request operation module, configured to:
[0091] Receive a data read request sent by the client for reading data to be read;
[0092] If the cache data corresponding to the data to be read is not read from the cache server according to the data read request, read the data to be read from the slave database, and judge whether a third flag bit corresponding to the data to be read in the service memory of the application server is modified;
[0093] If so, do not update the cache data corresponding to the data to be read in the cache server;
[0094] If not, update the data to be read to the cache data.
[0095] Based on the above embodiment, a log listening service is running on the application server.
[0096] Based on the above embodiments, the flag modification module 303 is specifically configured to:
[0097] Write the data to be operated on into the main database and generate an update log;
[0098] If the log monitoring service monitors the update log, synchronize the data to be operated on to the slave database according to the update log.
[0099] Based on the above embodiments, the device further includes a synchronization result judgment module, which is used to:
[0100] Obtain the synchronization result of the data to be operated on, where the synchronization result is the result of whether the synchronization of the data to be operated on to the slave database is successful;
[0101] If the synchronization result is unsuccessful, reset the first flag bit and the second flag bit.
[0102] Based on the above embodiments, the device further includes an execution result judgment module, which is used to:
[0103] Obtain the execution result of the data write request, where the execution result is the result of whether the execution of the data write request is successful;
[0104] If the execution result is unsuccessful, reset the first flag bit and the second flag bit.
[0105] Based on the above embodiments, a flag monitoring service runs in the application server.
[0106] Based on the above embodiments, the device further includes a flag monitoring module, which is used to:
[0107] If the flag monitoring service monitors that the first flag bit is modified, synchronously modify the second flag bit with the first flag bit.
[0108] Figure 4 It is a schematic diagram of the entity structure of the electronic device provided by the embodiment of the present application. As Figure 4 shown, the electronic device includes: a processor 401, a memory 402, and a bus 403; wherein,
[0109] The processor 401 and the memory 402 complete mutual interaction through the bus 403;
[0110] The processor 401 is used to call program instructions in the memory 402 to execute the data processing method based on cache coherence provided by the above method embodiments.
[0111] The processor 401 may be an integrated circuit chip with signal processing capabilities. The aforementioned processor 401 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0112] The memory 402 may include, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), etc.
[0113] This embodiment discloses a computer program product. The computer program product includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the data processing method based on cache coherence provided in each of the above method embodiments.
[0114] This embodiment provides a computer-readable storage medium. The computer-readable storage medium stores computer instructions. The computer instructions cause the computer to execute the data processing method based on cache coherence provided in each of the above method embodiments.
[0115] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or interactive connection between each other can be through some interactive interfaces, and the indirect coupling or interactive connection of the devices or units can be in electrical, mechanical or other forms.
[0116] In addition, the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0117] Furthermore, in each embodiment of the present application, the functional modules can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.
[0118] In this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0119] The above are only the embodiments of the present application and are not used to limit the protection scope of the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data processing method based on cache coherence, characterized in that, Applied to an application server, the application server is respectively connected to a Zookeeper server, a cache server, and a database server, and includes: Receiving a data write request sent by a client, the data write request including data to be operated on; Deleting the cache data corresponding to the data to be operated on in the cache server, and determining whether the first flag bit corresponding to the data to be operated on stored in the Zookeeper server is modified, the first flag bit being used to identify whether the data to be operated on is in the process of being written; If the first flag bit is not modified, modifying the first flag bit and the second flag bit corresponding to the data to be operated on in the service memory of the application server, and writing the data to be operated on into the primary database of the database server, and synchronizing the data to be operated on to the slave database of the database server by using the primary database; wherein, the second flag bit is used to identify whether the cache data can be updated by using the operation data when receiving a data read request for reading the data to be operated on; the second flag bit corresponds to the first flag bit; If the first flag bit is modified, blocking the data write request.
2. The method according to claim 1, characterized in that The method further includes: Receiving a data read request sent by the client for reading data to be read; If the cache data corresponding to the data to be read is not read from the cache server according to the data read request, reading the data to be read from the slave database, and determining whether the third flag bit corresponding to the data to be read in the service memory of the application server is modified; If so, not updating the cache data corresponding to the data to be read in the cache server; If not, updating the data to be read to the cache data.
3. The method according to claim 1, characterized in that After writing the data to be operated on into the primary database of the database server and synchronizing the data to be operated on to the slave database of the database server by using the primary database, the method further includes: Resetting the first flag bit and the second flag bit.
4. The method according to claim 1, wherein A log monitoring service is running on the application server, and writing the data to be operated on into the primary database of the database server and synchronizing the data to be operated on to the slave database of the database server by using the primary database includes: Writing the data to be operated on into the primary database and generating an update log; If the log monitoring service monitors the update log, synchronizing the data to be operated on to the slave database according to the update log.
5. The method according to claim 4, characterized in that After if the log monitoring service monitors the update log and synchronizes the data to be operated on to the slave database according to the update log, the method further includes: Obtaining the synchronization result of the data to be operated on, the synchronization result being the result of whether the synchronization of the data to be operated on to the slave database is successful or not; If the synchronization result is not successful, resetting the first flag bit and the second flag bit.
6. The method according to claim 1, characterized in that The method further includes: Obtaining the execution result of the data write request, the execution result being the result of whether the data write request is executed successfully or not; When the execution result is unsuccessful, reset the first flag bit and the second flag bit.
7. The method according to any one of claims 1-6, characterized in that, A flag bit monitoring service runs in the application server. Modifying the first flag bit and the second flag bit corresponding to the data to be operated in the service memory of the application server includes: When the flag bit monitoring service monitors that the first flag bit is modified, synchronously modify the second flag bit with the first flag bit.
8. A data processing device based on cache coherence, characterized in that, It includes: A receiving module, configured to receive a data write request sent by a client, where the data write request includes data to be operated; A judging module, configured to delete the cached data corresponding to the data to be operated in the cache server, and judge whether the first flag bit corresponding to the data to be operated stored in the Zookeeper server is modified, where the first flag bit is used to identify whether the data to be operated is being written; A module for unmodified flag bit, configured to, if the first flag bit is not modified, modify the first flag bit and the second flag bit corresponding to the data to be operated in the service memory of the application server, and write the data to be operated into the main database of the database server, and synchronize the data to be operated to the slave database of the database server by using the main database; where the second flag bit is used to identify whether the cached data can be updated by using the operation data when a data read request for reading the data to be operated is received; the second flag bit corresponds to the first flag bit; A module for modified flag bit, configured to block the data write request if the first flag bit is modified.
9. An electronic device, characterized in that, It includes: A processor, a memory, and a bus, where The processor and the memory communicate with each other through the bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1-7 by invoking the program instructions.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and when the computer instructions are run by the computer, the computer executes the method according to any one of claims 1-7.
Citation Information
Patent Citations
Cloud storage service client high-efficiency fine-granularity data caching system and method
CN102014158A
Mail extracting method
CN104702700A