Data processing method, device, system and storage medium

文档序号:7641 发布日期:2021-09-17 浏览:33次 中文

1. A data processing method applied to a data processing system, the data processing system including a database and a plurality of service nodes, each service node corresponding to a local cache copy, the database being configured to store data entries and maintain latest version numbers of incremental updates corresponding to the data entries, the method comprising:

a first service node responds to a query request for a first data entry initiated by a client, queries a corresponding first cache copy, and sends a corresponding query instruction to the database under the condition that the first data entry does not exist in the first cache copy;

the database returns the first data content and the first version number of the first data entry to the first service node in response to the query indication;

the first service node obtains a second version number of the first data entry in the first cache copy under the condition that the first data entry currently exists in the first cache copy, and if the first version number is larger than the second version number, the first service node updates the data content of the first data entry in the first cache copy according to the first data content.

2. The method of claim 1, further comprising:

and when the first service node determines that the first version number is smaller than the second version number, returning the second data content corresponding to the second version number to the client, and forbidding updating of the data content of the first data entry in the first cache copy according to the first data content.

3. The method of claim 1, after the first serving node queries the corresponding first cached copy, further comprising:

and the first service node returns the data content corresponding to the first data entry in the first cache copy to the client under the condition that the first data entry is determined to exist in the first cache copy.

4. The method of claim 1, further comprising:

the first service node responds to an update request for a second data entry initiated by a client and sends a corresponding update indication to the database;

the database responds to the updating indication, updates the data content in a second data entry in the database, and incrementally modifies the corresponding version number;

the first service node acquires a third data content and a third version number of the second data entry from the database, acquires a fourth version number of the second data entry in the second cache copy under the condition that the second data entry currently exists in the first cache copy, and updates the data content of the second data entry in the first cache copy according to the third data content if the third version number is greater than the fourth version number.

5. The method of claim 4, further comprising, after incrementally modifying the corresponding version number by the database:

the database takes the updated third data content and the updated third version number corresponding to the second data entry as a message and writes the message into a preset message queue;

and the second service node consumes the messages in the preset message queue in real time and updates the corresponding data entries in the second cache copy according to the consumption condition.

6. The method of claim 5, wherein the second service node consumes the messages in the preset message queue in real time and updates the data entries in the corresponding second cached copy according to the consumption condition, comprising:

the second service node acquires a first message in the preset message queue in real time, wherein the first message comprises a fifth data content and a fifth version number corresponding to a third data entry;

and the second service node acquires a sixth version number of the third data entry in the second cache copy under the condition that the third data entry currently exists in the corresponding second cache copy, and updates the data content of the third data entry in the second cache copy according to the fifth data content if the fifth version number is greater than the sixth version number.

7. The method of claim 5, further comprising:

after determining that the second service node consumes the second message successfully, the database adds a consumption identifier corresponding to the second service node to the second message in the preset message queue; when the second service node consumes the messages in the preset message queue in real time, inquiring a consumption identifier corresponding to the second service node in the preset message queue, and consuming the first message without the consumption identifier corresponding to the second service node;

and after determining that the third message in the preset message queue is successfully consumed by a preset number of service nodes in the data processing system, the database deletes the third message from the preset message queue.

8. A data processing apparatus integrated into a data processing system, the data processing system including a database and a plurality of service nodes, each service node corresponding to a local cached copy, the database being configured to store data entries and to maintain updated latest version numbers of incremental updates corresponding to the data entries, the apparatus comprising:

a query module integrated in the first service node, configured to query, in response to a query request for a first data entry initiated by a client, a corresponding first cached copy, and send, in a case that it is determined that the first data entry does not exist in the first cached copy, a corresponding query indication to the database;

a query response module, integrated in the database, for returning the first data content and the first version number of the first data entry to the first service node in response to the query indication;

the cache updating module is integrated in the first service node, and configured to, when it is determined that the first data entry currently exists in the first cache copy, obtain a second version number of the first data entry in the first cache copy, and update the data content of the first data entry in the first cache copy according to the first data content if the first version number is greater than the second version number.

9. A data processing system comprising a database and a plurality of service nodes, each service node corresponding to a local cached copy, the database being configured to store data entries and to maintain updated latest version numbers corresponding to the data entries, the database being implemented by a first computer device, the service nodes being implemented by a second computer device, the first computer device and the second computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the respective steps of the data processing method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-7.

Background

At present, a cache and a database are combined for use, and the method is a common method for improving the service performance of the internet. A small amount of hot spot data is stored in the cache, when data query is needed, the cache is queried first, if the cache is hit, the database does not need to be queried, so that the pressure of the database can be effectively relieved, the cache query speed is higher, and the service performance can be effectively improved.

For the cache, the hot data is used for storing the hot data, so when the service node queries the cache, there is a cache miss, and it is a common practice to synchronize the data in the database to the cache when the cache miss occurs, and in addition, after the service node updates the data, the service node synchronizes the new data to the cache. However, when there are multiple copies in the cache, for example, there are multiple service nodes, each service node corresponds to a cache, and when the multiple service nodes update the database in parallel, data synchronization is performed between the caches, and a certain time is required for synchronizing data in the database to the cache, so that data inconsistency between the multiple cache copies and between the cache and the database is easily caused, and it is difficult to ensure accuracy of the data in the cache.

Therefore, the existing processing scheme for caching data is still not perfect, and needs to be improved.

Disclosure of Invention

The embodiment of the invention provides a data processing method, a data processing device, a data processing system and a storage medium, which can optimize a processing scheme aiming at cache data.

In a first aspect, an embodiment of the present invention provides a data processing method applied to a data processing system, where the data processing system includes a database and multiple service nodes, each service node corresponds to a local cache copy, and the database is used to store data entries and maintain latest version numbers of incremental updates corresponding to the data entries, where the method includes:

a first service node responds to a query request for a first data entry initiated by a client, queries a corresponding first cache copy, and sends a corresponding query instruction to the database under the condition that the first data entry does not exist in the first cache copy;

the database returns the first data content and the first version number of the first data entry to the first service node in response to the query indication;

the first service node obtains a second version number of the first data entry in the first cache copy under the condition that the first data entry currently exists in the first cache copy, and if the first version number is larger than the second version number, the first service node updates the data content of the first data entry in the first cache copy according to the first data content.

In a second aspect, an embodiment of the present invention provides a data processing apparatus integrated in a data processing system, where the data processing system includes a database and a plurality of service nodes, each service node corresponds to a local cache copy, and the database is configured to store data entries and maintain latest version numbers of incremental updates corresponding to the data entries, and the apparatus includes:

a query module integrated in the first service node, configured to query, in response to a query request for a first data entry initiated by a client, a corresponding first cached copy, and send, in a case that it is determined that the first data entry does not exist in the first cached copy, a corresponding query indication to the database;

a query response module, integrated in the database, for returning the first data content and the first version number of the first data entry to the first service node in response to the query indication;

the cache updating module is integrated in the first service node, and configured to, when it is determined that the first data entry currently exists in the first cache copy, obtain a second version number of the first data entry in the first cache copy, and update the data content of the first data entry in the first cache copy according to the first data content if the first version number is greater than the second version number.

In a third aspect, an embodiment of the present invention provides a data processing system, including a database and a plurality of service nodes, where each service node corresponds to a local cache copy, the database is configured to store data entries and maintain latest version numbers of incremental updates corresponding to the data entries, the database is implemented by a first computer device, and the service nodes are implemented by a second computer device, where the first computer device and the second computer device include a memory, a processor, and a computer program stored in the memory and operable on the processor, where the processor implements corresponding steps in the data processing method according to the embodiment of the present invention when executing the computer program.

In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements a data processing method according to an embodiment of the present invention.

The data processing scheme provided in the embodiment of the invention is applied to a data processing system, the data processing system comprises a database and a plurality of service nodes, each service node corresponds to a local cache copy, the database is used for storing data entries and maintaining the latest version numbers of incremental updates corresponding to the data entries, a first service node responds to a query request initiated by a client for a first data entry, queries the corresponding first cache copy, sends a corresponding query instruction to the database under the condition that the first data entry does not exist in the first cache copy, the database responds to the query instruction, returns a first data content and a first version number of the first data entry to the first service node, and acquires a second version number of the first data entry in the first cache copy under the condition that the first data entry currently exists in the first cache copy, and if the first version number is larger than the second version number, updating the data content of the first data entry in the first cache copy according to the first data content. By adopting the technical scheme, the database in the data processing system stores the corresponding latest version number while storing the data entries, the version number is maintained in an incremental updating mode, when the service node responds to the query request of the data entries of the client, if the cache is not hit, the database is queried, and the database returns the latest version number and the latest data content at the moment, but the process of querying the database generally needs a period of time, and the data entries obtained by means of synchronization between caches and the like are probably added into the cache in the period of time, at the moment, the more accurate data content can be rapidly determined in a version number comparison mode, so that the cache data are updated, and the accuracy of the cache data is improved.

Drawings

Fig. 1 is a scene architecture diagram of an application scene to which a data processing method according to an embodiment of the present invention is applied.

Fig. 2 is a schematic flow chart of a data processing method according to an embodiment of the present invention;

FIG. 3 is a flow chart illustrating a further data processing method according to an embodiment of the present invention;

fig. 4 is a schematic flowchart of another data processing method according to an embodiment of the present invention;

fig. 5 is a block diagram of a data processing apparatus according to an embodiment of the present invention;

FIG. 6 is a block diagram of a data processing system according to an embodiment of the present invention;

fig. 7 is a block diagram of a computer device according to an embodiment of the present invention.

Detailed Description

The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures. In addition, the embodiments and features of the embodiments in the present invention may be combined with each other without conflict.

It should be noted that the concepts of "first", "second", and the like mentioned in the embodiments of the present invention are only used for distinguishing different items (such as data entries, service nodes, data contents, version numbers, and the like in the following) and do not limit the order or interdependence relationship between different items.

Fig. 1 is a scene architecture diagram of an application scene to which a data processing method according to an embodiment of the present invention is applied. Specifically, referring to fig. 1, the application scenario may include a data processing system and a client 40, the data processing system includes a service node 10 and a database 30, the service node may be implemented by a device such as a server, the number of the service nodes is multiple, the specific number is not limited (for example, 3 in fig. 1), optionally, the service nodes may be equivalent, that is, there may not be a master-slave partition, and of course, a master service node and at least one slave service node may also be provided, which is not limited specifically. The service node 10 corresponds to a local cached copy 20, which can be understood as a one-to-one relationship between the service node and the local cached copy. A database (DateBase, DB) may be used to provide a persistent storage service, which may also be referred to as a database layer, where a specific type of stored data is not limited, and data is generally stored in units of data entries, that is, each data entry may be referred to as a data entry, and the data entries stored in the database are generally all data entries in the system. The cached copy may be used to provide a transient high-speed data storage service, which may also be referred to as a cache, a local cache, or a local cache layer, and the like, and a part of data entries in the system, which are generally hot data entries, for example, data entries with a high access frequency, are stored in the cached copy, and how to determine the hot data entries is not limited. In the embodiment of the invention, the implementation forms of the database and the cache are not limited. The service node can synchronize the data in the corresponding cache copy with the data in the database. Data synchronization can be performed between different cache copies, and a specific synchronization mode is not limited. Each service node can independently receive and respond to the request of the client, that is, the operations of updating and the like of the same data entry in the database by different service nodes can have a parallel condition.

In the prior art, when a service node queries a cache, the service node queries a database and synchronizes data in the database to the cache, but when the cache has multiple copies, the multiple service nodes may update the database in parallel, but the process of querying the database generally requires a period of time, and in this period of time, a data entry to be queried, which is obtained by means of synchronization between caches and the like, is likely to be added to the cache, and at this time, a locally existing data entry of the cache and a data entry queried from the database are likely to be inconsistent and are not known to be more accurate, so that problems of data consistency and data accuracy exist.

In the embodiment of the invention, the database in the data processing system stores the corresponding latest version number while storing the data items, the version number is maintained in an incremental updating mode, and when data is queried, more accurate data content can be rapidly determined in a version number comparison mode, so that the cache data is updated, and the accuracy of the cache data is improved.

Fig. 2 is a flowchart of a data processing method according to an embodiment of the present invention, which may be executed by a data processing apparatus, wherein the apparatus may be implemented by software and/or hardware, and may be generally integrated in a computer device in a data processing system. The data processing system comprises a database and a plurality of service nodes, wherein each service node corresponds to a local cache copy, and the database is used for storing data entries and maintaining the latest version numbers of incremental updates corresponding to the data entries.

As shown in fig. 2, the method includes:

step 201, in response to a query request for a first data entry initiated by a client, a first service node queries a corresponding first cached copy, and sends a corresponding query instruction to the database when it is determined that the first data entry does not exist in the first cached copy.

In this embodiment of the present invention, the first service node may be any service node in the data processing system. The client may be any client for which the first service node can provide a service, and the client may be installed in any computer device such as a mobile phone, a tablet computer or a desktop computer. The first data entry may be any data entry, the data entry generally includes an identifier (or data name) and corresponding data content, and if the data entry is stored in the form of a key-value pair (key-value), the identifier may be a key (k), and the data content may be a value (v). Of course, the data entry may also be stored in other forms, and is not limited specifically.

For example, when the client needs to query for the first data entry, a corresponding query request may be sent to the first service node. The query request may include an identity of the first data entry. The first service node may first query whether there is a first data entry in the corresponding local first cache copy, for example, query whether there is a data entry whose identity is consistent with the identity in the query request, if so, it may be considered that there is the first data entry, and if not, it may be considered that there is no first data entry. And under the condition that the first data entry does not exist in the first cache copy, sending a corresponding query indication to the database so as to realize query of the first data entry in the database.

Step 202, the database returns the first data content and the first version number of the first data entry to the first service node in response to the query indication.

Illustratively, the query indication may also include an identity of the first data entry. In the embodiment of the present invention, the database may be implemented by an independent database, or may be implemented by a database cluster, and is not particularly limited, and each service node communicates with the database when operations such as data query or data update are required, that is, the database in the data processing system may exist uniformly for each service node. The database is used for storing the data entries and maintaining the latest version numbers of the incremental updates corresponding to the data entries. Illustratively, when a database needs to modify its stored data entries, the version number is incrementally modified so that the version numbers of the data entries in the database are up-to-date. After receiving the query instruction sent by the first service node, the database queries the first data entry in the database, and sends the corresponding data content (marked as the first data content) and the latest version number (marked as the first version number) to the first service node.

Step 203, the first service node obtains a second version number of the first data entry in the first cache copy under the condition that it is determined that the first data entry currently exists in the first cache copy, and if the first version number is greater than the second version number, updates the data content of the first data entry in the first cache copy according to the first data content.

For example, a certain time interval generally exists between the time when the first service node sends the query instruction to the database and the time when the first data content and the first version number returned by the database are received, because the database needs to consume a certain time during query, and a small amount of time is also needed for communication between the first service node and the database, during which the first data entry may be synchronized to the first cached copy by the cached copies corresponding to other service nodes, and therefore, the first data entry may already exist in the first cached copy currently, for example, the first data entry currently existing in the first cached copy is synchronized to the first cached copy by the second cached copy corresponding to the second service node. In this way, there may be a case where the data content of the first data entry currently existing in the first cached copy and the first data content just returned by the database to the first service node are inconsistent, and it cannot be determined which data content is the latest. In the embodiment of the invention, under the condition that the first data entry currently exists in the first cache copy, the second version number of the first data entry in the first cache copy is obtained, the second version number is compared with the first version number, and if the first version number is greater than the second version number, the first data content returned by the database is new and more accurate compared with the data content of the existing first data entry in the first cache, so that the data content of the first data entry in the first cache copy is updated according to the first data content, and the accuracy of the first data entry in the cache copy is ensured.

Optionally, in order to improve the response speed of the first service node to the query request, when it is determined that the first version number is greater than the second version number, the first data content may be returned to the client, and the data content of the first data entry in the first cache copy may be updated according to the first data content. Of course, the first data content may also be returned to the client after updating the data content of the first data entry in the first cached copy according to the first data content.

Optionally, in order to further improve the response speed of the first service node to the query request, the first service node may also return the first data content to the client after receiving the first data content returned by the database, and then determine whether the first data entry currently exists in the first cache copy.

Optionally, the first service node returns the first data content to the client when determining that the first data entry does not currently exist in the first cached copy.

The data processing method provided in the embodiment of the invention is applied to a data processing system, the data processing system comprises a database and a plurality of service nodes, each service node corresponds to a local cache copy, the database is used for storing data entries and maintaining the latest version number of incremental update corresponding to the data entries, a first service node responds to a query request initiated by a client for a first data entry, queries the corresponding first cache copy, sends a corresponding query instruction to the database under the condition that the first data entry does not exist in the first cache copy, the database responds to the query instruction, returns the first data content and the first version number of the first data entry to the first service node, the first service node obtains the second version number of the first data entry in the first cache copy under the condition that the first data entry currently exists in the first cache copy, and if the first version number is larger than the second version number, updating the data content of the first data entry in the first cache copy according to the first data content. By adopting the technical scheme, the database in the data processing system stores the corresponding latest version number while storing the data entries, the version number is maintained in an incremental updating mode, when the service node responds to the query request of the data entries of the client, if the cache is not hit, the database is queried, and the database returns the latest version number and the latest data content at the moment, but the process of querying the database generally needs a period of time, and the data entries obtained by means of synchronization between caches and the like are probably added into the cache in the period of time, at the moment, the more accurate data content can be rapidly determined in a version number comparison mode, so that the cache data are updated, and the accuracy of the cache data is improved.

In some embodiments, the method may further comprise: and when the first service node determines that the first version number is smaller than the second version number, returning the second data content corresponding to the second version number to the client, and forbidding updating of the data content of the first data entry in the first cache copy according to the first data content. The method has the advantages that if the first data entry is modified by other service nodes before the first service node receives the first data content returned by the database and is quickly synchronized to the first cache copy, the data content of the first data entry currently existing in the first cache copy is more accurate, namely the first version number is smaller than the second version number, so that the second data content corresponding to the first data entry currently existing in the first cache copy is returned to the client, the accurate data content is guaranteed to be fed back to the client, the data content of the first data entry in the first cache copy is prohibited to be updated according to the first data content, and the situation that the old data content covers the new data content is avoided.

It should be noted that, if the first version number is equal to the second version number, the first data content and the second data content may be considered to be the same, and any one of the first data content and the second data content may be returned to the client.

In some embodiments, after the first service node queries the corresponding first cached copy, the method further comprises: and the first service node returns the data content corresponding to the first data entry in the first cache copy to the client under the condition that the first data entry is determined to exist in the first cache copy. The advantage of such an arrangement is that if the first service node determines that the first data entry exists in the first cache copy before querying the database, the data content corresponding to the first data entry in the first cache copy may be directly returned to the client without performing comparison of the version numbers, so as to ensure that the first service node can quickly respond to the query request, and reduce the pressure on the database.

Fig. 3 is a schematic flowchart of another data processing method according to an embodiment of the present invention, as shown in fig. 3, the method may include:

step 301, the first service node queries the corresponding first cache copy in response to a query request for the first data entry initiated by the client.

Step 302, the first service node determines whether a first data entry exists in the first cache copy, if yes, step 303 is executed; otherwise, step 304 is performed.

Step 303, the first service node returns the data content of the first data entry stored in the first cache copy to the client, and the process is ended.

Step 304, the first service node sends a query indication corresponding to the query request to the database.

Step 305, the database returns the first data content and the first version number of the first data entry to the first service node in response to the query indication.

Step 306, the first service node determines whether a first data entry currently exists in the first cache copy, if yes, step 307 is executed; otherwise, step 311 is performed.

Step 307, the first service node obtains a second version number of the first data entry in the first cache copy.

Step 308, the first service node determines whether the first version number is greater than the second version number, if so, step 309 is executed; otherwise, step 310 is performed.

Step 309, the first service node returns the first data content to the client, and updates the data content of the first data entry in the first cache copy according to the first data content, and the process is ended.

In step 310, the first service node finishes the process by using the data content corresponding to the first data entry currently stored in the first cache copy.

Optionally, before ending the flow, the method further includes: and forbidding updating the data content of the first data entry in the first cache copy according to the first data content, and avoiding the old data content from covering the new data content.

Step 311, the first service node returns the first data content to the client, and stores the first data entry with the data content as the first data content in the first cache copy.

Alternatively, only the first data content may be returned to the client without adding the first data entry in the first cached copy.

According to the data processing method provided by the embodiment of the invention, when a service node responds to a query request of a data entry of a client, a cache copy is queried firstly, if the cache is hit, the data content in the cache can be directly and quickly returned, if the cache is not hit, a database is queried again, the version number and the data content returned by the database are received, if the first data entry still does not exist in the cache at the moment, the data content returned by the database can be directly returned to the client, if the first data entry appears in the cache at the moment, the comparison of the version number is needed, the data content with the newer version number is returned to the client, whether the data content in the cache is updated or not is determined according to the comparison result, and the accuracy of cache data is improved.

On the basis of the above optional embodiments, in some embodiments, the data processing method may further include: the first service node responds to an update request for a second data entry initiated by a client and sends a corresponding update indication to the database; the database responds to the updating indication, updates the data content in a second data entry in the database, and incrementally modifies the corresponding version number; the first service node acquires a third data content and a third version number of the second data entry from the database, acquires a fourth version number of the second data entry in the second cache copy under the condition that the second data entry currently exists in the first cache copy, and updates the data content of the second data entry in the first cache copy according to the third data content if the third version number is greater than the fourth version number. The method has the advantages that after the service node updates a certain data entry, the data in the corresponding local cache copy is updated in time, and the version number is compared before updating, so that the accuracy of the data in the cache is ensured.

Illustratively, the second data entry may be any data entry, and may be the same as or different from the previous first data entry. When the client needs to update the second data entry, a corresponding update request may be sent to the first serving node. The identity of the second data entry and the data content that needs to be updated (which may be denoted as the target data content) may be included in the update request. The first service node (it should be noted that the first service node herein may be any service node, may be the service node responding to the query request, and may also be another service node, and for convenience of description, it is also referred to as the first service node herein), after receiving the update request, sends an update indication to the database, and likewise, the update indication may include the identity of the second data entry and the target data content. After receiving the update indication, the database updates the data content in the second data entry in the database to the target data content, and incrementally modifies the corresponding version number (e.g., from the original V5 to V6).

For example, after the database completes updating of the data content and the version number, the database may return update success information corresponding to the update indication to the first service node, the first service node then obtains a third data content and a third version number of the second data entry from the database, at this time, the third data content and the third version number are the latest data content and the latest version number stored in the database, the first service node performs comparison of the version numbers before updating the data content of the second data entry in the first cached copy into the third data content, because there is generally a certain time interval between the time when the first service node sends the update indication to the database and the time when the third data content and the third version number returned by the database are received, during this time, the cached copies corresponding to other service nodes may synchronously update the data content of the first data entry to the first cached copy, therefore, in order to avoid the old data from overwriting the new data, the version numbers are compared, and if the third version number is greater than the fourth version number, the data content returned by the database is more accurate, so that the data content of the second data entry in the first cache copy can be updated according to the third data content.

Optionally, if the third version number is smaller than the fourth version number, the data content existing in the first cache copy at present is more accurate, so that the data content of the second data entry in the first cache copy may not be updated, that is, the data content of the second data entry in the first cache copy is prevented from being updated according to the third data content.

In some embodiments, after incrementally modifying the corresponding version number, the database further comprises: the database takes the updated third data content and the updated third version number corresponding to the second data entry as a message and writes the message into a preset message queue; and the second service node consumes the messages in the preset message queue in real time and updates the corresponding data entries in the second cache copy according to the consumption condition. The method has the advantages that the preset message queue is additionally arranged in the database, the updating records of all data items in the database are sequentially stored through the preset message queue, the updating records are convenient to be consumed by all service nodes in real time, the data in the cache copy are updated, the condition of data missing updating is avoided, and the accuracy of the cache data is further ensured.

Further, the consuming, by the second service node, the message in the preset message queue in real time, and updating the data entry in the corresponding second cache copy according to the consumption condition may include: the second service node acquires a first message in the preset message queue in real time, wherein the first message comprises a fifth data content and a fifth version number corresponding to a third data entry; and the second service node acquires a sixth version number of the third data entry in the second cache copy under the condition that the third data entry currently exists in the corresponding second cache copy, and updates the data content of the third data entry in the second cache copy according to the fifth data content if the fifth version number is greater than the sixth version number. The method has the advantages that when the cache is updated in a mode of consuming the preset message queue, the newer data content is confirmed in a version number comparison mode, and the accuracy of the updated data content is guaranteed while timely and non-missing updating is guaranteed.

In some embodiments, the method may further comprise: after determining that the second service node consumes the second message successfully, the database adds a consumption identifier corresponding to the second service node to the second message in the preset message queue; when the second service node consumes the messages in the preset message queue in real time, inquiring a consumption identifier corresponding to the second service node in the preset message queue, and consuming the first message without the consumption identifier corresponding to the second service node; and after determining that the third message in the preset message queue is successfully consumed by a preset number of service nodes in the data processing system, the database deletes the third message from the preset message queue. The advantage of such an arrangement is that, because the preset message queue is a uniform message queue, and multiple service nodes all need to consume the same message, and consumption opportunities of different service nodes for the same message may be different, in order to facilitate distinguishing which service node or service nodes have successfully consumed a certain message, a consumption identifier corresponding to the second service node may be added at the second message in the preset message queue by the database after it is determined that the second service node has successfully consumed the second message, and a one-to-one correspondence relationship may exist between the consumption identifier and the service node, for example, an identity identifier of the service node. When the second service node needs to search the current message needing to be consumed in the preset message queue, the first message without the consumption identifier corresponding to the second service node can be searched in sequence for consumption. And after determining that the third messages in the preset message queue are successfully consumed by the preset number of service nodes in the data processing system, the database deletes the third messages from the preset message queue, wherein the preset number may be smaller than or equal to the total number of the service nodes in the data processing system, for example, may be equal to the total number of the service nodes, so that if a small number of abnormal service nodes are present, when the abnormal service nodes are recovered to be normal, the accuracy of the data content in the corresponding cache copy can still be ensured by continuously consuming the preset message queue.

Fig. 4 is a schematic flowchart of another data processing method according to an embodiment of the present invention, as shown in fig. 4, the method includes:

step 401, in response to a query request for a first data entry initiated by a client, a first service node queries a corresponding first cache copy, and sends a corresponding query instruction to a database when determining that the first data entry does not exist in the first cache copy.

Step 402, the database returns the first data content and the first version number of the first data entry to the first service node in response to the query indication.

Step 403, the first service node obtains a second version number of the first data entry in the first cache copy when it is determined that the first data entry currently exists in the first cache copy, and if the first version number is greater than the second version number, updates the data content of the first data entry in the first cache copy according to the first data content.

Step 404, the first service node sends a corresponding update indication to the database in response to an update request for the second data entry initiated by the client.

Step 405, the database responds to the update instruction, updates the data content in the second data entry in the database, incrementally modifies the corresponding version number, and writes the updated third data content and the updated third version number corresponding to the second data entry into a preset message queue as the first message.

The database adds a consumption identifier corresponding to the second service node at a second message position in the preset message queue after determining that the second service node consumes the second message successfully. And after determining that the third message in the preset message queue is successfully consumed by the preset number of service nodes in the data processing system, the database deletes the third message from the preset message queue.

Step 406, the first service node obtains a third data content and a third version number of the second data entry from the database, and obtains a fourth version number of the second data entry in the second cache copy when it is determined that the second data entry currently exists in the first cache copy.

Optionally, if the first service node determines that the second data entry does not currently exist in the first cache copy, the process may be ended or step 409 may be executed.

Optionally, if the first service node determines that the second data entry does not currently exist in the first cache copy, the second data entry whose data content is the third data content may also be stored in the first cache copy.

Optionally, after the data of the second data entry in the database is updated, the first service node may immediately obtain a third data content and a third version number of the second data entry from the database, and perform comparison and cache update on the version numbers, so that the database may add a consumption identifier corresponding to the first service node at the first message in the preset message queue while returning the third data content and the third version number of the second data entry to the first service node, thereby reducing the consumption times of the first service node to the preset message queue.

Step 407, the first service node determines whether the third version number is greater than the fourth version number, if so, step 408 is executed; otherwise, step 409 is performed.

Step 408, the first service node updates the data content of the second data entry in the first cache copy according to the third data content.

Step 409, the second service node obtains a second message in the preset message queue in real time, wherein the second message includes a fifth data content and a fifth version number corresponding to the third data entry.

When the second service node consumes the message in the preset message queue in real time, the consumption identifier corresponding to the second service node is inquired in the preset message queue, the first message without the consumption identifier corresponding to the second service node is consumed, and the second message is consumed if the first message without the consumption identifier corresponding to the second service node is the second message.

Step 410, the second service node obtains a sixth version number of the third data entry in the second cache copy when determining that the third data entry currently exists in the corresponding second cache copy, and updates the data content of the third data entry in the second cache copy according to the fifth data content if the fifth version number is greater than the sixth version number.

Optionally, the second service node may consume a next message in the preset message queue when determining that the third data entry does not currently exist in the corresponding second cache copy, or may consume the next message in the preset message queue after adding the third data entry whose data content is the fifth data content to the second cache copy.

According to the data processing method provided by the embodiment of the invention, the database in the data processing system stores the data entries and also stores the corresponding latest version number, the version number is maintained in an incremental updating mode, when the service node responds to the query request of the data entries of the client, if the cache is not hit, the database is queried, and if the data entries exist in the cache after query, more accurate data content is rapidly determined in a version number comparison mode, so that the cache data is updated, and the accuracy of the cache data is improved. In addition, after the data updating operation of the database is completed, the service node inquires the latest version number of the updated data entry, and if the updated version number exists, the cache is updated according to the updated data content, so that the accuracy of the cache data in the data updating process is improved. Finally, when data is updated in the database, corresponding messages are written in the message queues, and the message queues are consumed in real time by each service node in the system, so that the accuracy of the updated data content is ensured while timely and non-missing updating is ensured, namely the accuracy of the cached data is further ensured, and the problems of data inconsistency between caches and data inconsistency between the cache and the database are effectively solved.

Fig. 5 is a block diagram of a data processing apparatus according to an embodiment of the present invention, where the apparatus may be implemented by software and/or hardware, and may be generally integrated in a computer device in a data processing system, and may perform data processing by executing a data processing method. The data processing system comprises a database and a plurality of service nodes, wherein each service node corresponds to a local cache copy, and the database is used for storing data entries and maintaining the latest version numbers of incremental updates corresponding to the data entries. The apparatus may include: a query module integrated in the first service node, a query response module integrated in the database, and a cache update module integrated in the first service node. Specifically, as shown in fig. 5, the apparatus includes:

a query module 501, configured to query, in response to a query request for a first data entry initiated by a client, a corresponding first cache copy, and send a corresponding query instruction to the database when it is determined that the first data entry does not exist in the first cache copy;

a query response module 502, configured to return the first data content and the first version number of the first data entry to the first service node in response to the query indication;

a cache updating module 503, configured to, when it is determined that the first data entry currently exists in the first cache copy, obtain a second version number of the first data entry in the first cache copy, and if the first version number is greater than the second version number, update the data content of the first data entry in the first cache copy according to the first data content.

According to the data processing device provided by the embodiment of the invention, the database in the data processing system stores the data entries and also stores the corresponding latest version number, the version number is maintained in an incremental updating mode, when the service node responds to the query request of the data entries of the client, if the cache is not hit, the database is queried, and the database returns the latest version number and the latest data content at the moment, but the process of querying the database generally needs a period of time, and the data entries obtained by means of synchronization between caches and the like are probably added into the cache in the period of time, at the moment, more accurate data content can be rapidly determined in a version number comparison mode, so that the cache data are updated, and the accuracy of the cache data is improved.

The embodiment of the invention provides a data processing system, which comprises a database and a plurality of service nodes, wherein each service node corresponds to a local cache copy, the database is used for storing data entries and maintaining the latest version numbers of incremental updates corresponding to the data entries, the database is realized by a first computer device, the service nodes are realized by a second computer device, the first computer device and the second computer device comprise a memory, a processor and a computer program which is stored on the memory and can run on the processor, and the processor realizes the corresponding steps in the data processing method according to the embodiment of the invention when executing the computer program.

Fig. 6 is a block diagram of a data processing system according to an embodiment of the present invention, and as shown in fig. 6, the data processing system includes a database 601, a first service node 602, and a second service node 602. It should be noted that fig. 6 is only an exemplary illustration, and more or fewer service nodes may exist.

The embodiment of the invention provides computer equipment, and modules in the data processing device provided by the embodiment of the invention can be integrated in the computer equipment. Fig. 7 is a block diagram of a computer device according to an embodiment of the present invention. The computer device 700 comprises a memory 701, a processor 702 and a computer program stored on the memory 701 and executable on the processor 702, wherein the processor 702 implements corresponding steps in the data processing method provided by the embodiment of the invention when executing the computer program.

Embodiments of the present invention also provide a storage medium containing computer-executable instructions, which are used to execute the data processing method provided by the embodiments of the present invention when executed by a computer processor.

The data processing device, system, device and storage medium provided in the above embodiments may execute the data processing method provided in any embodiment of the present invention, and have corresponding functional modules and beneficial effects for executing the method. For technical details that are not described in detail in the above embodiments, reference may be made to a data processing method provided in any embodiment of the present invention.

Note that the above is only a preferred embodiment of the present invention. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in more detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the claims.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:基于多链NFT跨链方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!