Background
An Operation Management Center (OMC) is used as a unified platform for commodity attribute Management in warehousing projects, and a lot of authority Management is contained in the OMC, and manages commodity attributes or authority relations between commodity modules and managers or administrators thereof. When the administrator of the OMC system authorizes the user (i.e., the administrator of the goods or modules), it is necessary to ensure the consistency of the authorization that all users accessing the OMC system (i.e., the administrator of the goods or modules) should have the latest authority, otherwise, a confusion in management occurs.
The currently used method for synchronizing the authority data cache is based on a session manager built in a web server (web server) to perform synchronization management. Such as semsionmanager, tomcat, etc. Generally, the authority management based on the web server stores the authority data of the user in the session information built in the web server in an encrypted or plaintext manner, and then the session manager of the web server stores the respective session information in a database, and shares the stored session data to all cache servers in the system cluster to implement the authority data cache synchronization. For example: assuming that the web server 1 provides services at the time of initial login, the user refreshes the system after performing some operations (such as adding goods to a shopping cart), and the web server 2 may be replaced to provide services according to the load balancing principle of the OMC system. Because the previous operation information is saved in the session and is synchronously updated to the cache servers of other web servers, the condition that no commodity is newly added in the shopping cart can not occur, and cache synchronization is realized.
Because the OMC system has the load balancing function, in the distributed system cluster, the caching synchronization of the authority of each user (namely, a manager of goods or modules) in the caching servers of all the OMC systems can be realized. However, if there are too many cache servers, the administrator of the OMC system may be stuck or even delayed in setting the user's rights. For example: if n cache servers exist, the permission data of the user configured by the administrator needs to be cached to all the cache servers under normal conditions, and then a prompt of 'operation success' is returned to the administrator. In practical situations, when there are too many cache servers, on one hand, the administrator may not wait for all the cache servers to be synchronized and prompt that the operation is successful before performing other operations; on the other hand, most web applications, which basically set the timeout time, may have timed out without waiting for the synchronization to be completed. This results in a very poor user experience and has some impact on the robustness of the system and data consistency.
In addition, in the using process, the dependence of the existing permission data cache synchronization method on the web server is too strong, and once the web server goes down, the permission data cannot be updated. For example: when the administrator modifies the authority data of one user (namely, the administrator of the goods or the modules), but the administrator goes down when updating to the 5 th web server, so that the 5 th web server is not updated successfully; when the user logs in the product management system next time, if the web server provides the service, the right data may be wrong, that is: the web server does not acquire the latest rights data. Especially for the OMC system, there may be other systems to read the authority data of the user (i.e. the manager of the goods or modules) at any time, so the synchronization of the authority data cache is more important.
Therefore, a mechanism is needed to ensure that the administrator can execute the fastest write operation during the synchronous cache, so as to accelerate the update speed, and ensure that the latest permission of each user can be obtained during each reading.
Disclosure of Invention
In view of the above, the present invention provides a method and an apparatus for implementing permission data cache synchronization based on a Quorum mechanism, wherein a cache server is used to store user permission data, so as to implement session management decoupling with a web server, and avoid strong dependence on the web server; meanwhile, a Quorum mechanism is adopted to achieve permission data cache synchronization, the problem of system delay can be effectively solved, and updating efficiency is improved.
To achieve the above object, according to an aspect of the present invention, a method for implementing permission data cache synchronization based on a Quorum mechanism is provided.
A method for realizing authority data cache synchronization based on a Quorum mechanism, wherein n cache servers are provided, n is a positive integer, the method comprises the following steps: determining an integer k, k being greater than 0 and less than or equal to n; updating the authority data to be updated to k cache servers, and then prompting the success of the updating, wherein the authority data comprises a version number; after the prompt of successful update, when an authority data acquisition request sent by a user is received, the authority data is read from any n-k +1 cache servers to acquire n-k +1 groups of authority data, and the authority data with the latest version number is returned to the user.
Optionally, the method further comprises: and after the prompt of successful update, updating the authority data to the rest n-k cache servers in the background.
Optionally, the step of updating the permission data to the remaining n-k cache servers in the background includes: reading the authority data from any n-k +1 cache servers according to a background asynchronous processing mechanism to obtain n-k +1 groups of authority data; finding the authority data with the latest version number from the n-k +1 groups of authority data; and updating the authority data with the latest version number to the rest n-k cache servers.
According to another aspect of the present invention, an apparatus for implementing authority data cache synchronization based on a Quorum mechanism is provided.
A device for realizing authority data cache synchronization based on a Quorum mechanism comprises: the system comprises a foreground updating module, a cache updating module and a display module, wherein the foreground updating module is used for updating authority data to be updated into k cache servers and then prompting the success of the updating, the authority data comprise version numbers, the number of the cache servers is n, and k is a determined integer which is larger than 0 and smaller than or equal to n; and the data reading module is used for reading the authority data from any n-k +1 cache servers to obtain n-k +1 groups of authority data after prompting that the updating is successful and when receiving an authority data obtaining request sent by a user, and returning the authority data with the latest version number to the user.
Optionally, the method further comprises: and the background synchronization module is used for updating the authority data to the rest n-k cache servers in the background after prompting that the updating is successful.
Optionally, the background synchronization module is further configured to: reading the authority data from any n-k +1 cache servers according to a background asynchronous processing mechanism to obtain n-k +1 groups of authority data; finding the authority data with the latest version number from the n-k +1 groups of authority data; and updating the authority data with the latest version number to the rest n-k cache servers.
According to another aspect of the invention, an electronic device for realizing permission data cache synchronization based on a Quorum mechanism is provided.
An electronic device for realizing permission data cache synchronization based on a Quorum mechanism comprises: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the method for realizing the permission data cache synchronization based on the Quorum mechanism.
According to yet another aspect of the present invention, a computer-readable medium is provided.
A computer readable medium, on which a computer program is stored, said program when being executed by a processor implements the method for implementing permission data cache synchronization based on the Quorum mechanism provided by the present invention.
According to the technical scheme of the invention, the permission data of the user is stored by using the cache server, so that the session management decoupling with the web server is realized, and the strong dependence on the web server can be avoided; meanwhile, a Quorum mechanism is adopted to achieve permission data cache synchronization, the problem of system delay can be effectively solved, and updating efficiency is improved.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The technical scheme of the invention realizes data synchronization by adopting a Quorum mechanism.
Known Quorum mechanisms are used to address load balancing of reads and writes in the read-write model. Assuming there are a total of N data copies, k of which are already updated (k < N) and N-k are not, then when N-k +1 data copies are read arbitrarily, at least 1 of which must be updated (pigeon nest principle). The latest updated data can be obtained by comparing and selecting the data with the latest version in the read N-k +1 data.
According to the invention, under the condition that the authority data of n cache servers need to be updated, when k cache servers are updated, the authority data of n-k +1 cache servers are read arbitrarily, wherein one of the data is the latest data. The present invention can use an open source framework developed based on Quorum to solve the problem of data synchronization.
Fig. 1 is a schematic diagram of main steps of a method for implementing permission data cache synchronization based on a Quorum mechanism according to an embodiment of the present invention. As shown in fig. 1, the method for implementing authority data cache synchronization based on the Quorum mechanism of the present invention mainly includes the following steps S11 and S12.
Assuming that there are n cache servers, n is a positive integer, and an integer k is selected, k being greater than 0 and less than or equal to n. According to the invention, the value of k can be set according to the requirement of data consistency in the specific requirements of the distributed system.
At step S11: and updating the authority data needing to be updated into k cache servers, and prompting the success of the updating after the k cache servers finish the updating of the authority data, wherein the authority data comprises a version number. The version number reflects the freshness of the rights data.
At step S12: after the update is prompted to be successful, when an authority data acquisition request sent by a user is received, the authority data is respectively read from any n-k +1 cache servers to acquire n-k +1 groups of authority data, and the authority data with the latest version number is returned to the user.
The efficient data read/write synchronization can be realized in the steps S11 and S12. In addition, after prompting that the update is successful, step S13 (not shown in the figure) may be further included: and updating the authority data to the rest n-k cache servers in the background. However, the operation performed in the background in step S13 is transparent to the user, and is not necessary for responding to the user' S permission data request. In fact, as long as k cache servers are updated with the latest authority data, the latest updated authority data can be obtained by reading the authority data in any n-k +1 cache servers. However, in order to maintain consistency of the rights data on all cache servers and enhance reliability of the read rights data, the rights data on other cache servers need to be updated asynchronously in the background.
The method of updating the permission data to the remaining n-k cache servers in the background in step S13 may be performed in the following order:
step S131: reading the authority data from any n-k +1 cache servers according to a background asynchronous processing mechanism to obtain n-k +1 groups of authority data;
step S132: finding the authority data with the latest version number from the n-k +1 groups of authority data;
step S133: and updating the authority data with the latest version number to the rest n-k cache servers.
According to the steps S131 to S133, asynchronous execution of the background updating permission data and the user acquisition permission data can be realized, and background updating can be executed when the system is idle, so that the response efficiency of the system is improved.
Fig. 2 is a schematic diagram illustrating an implementation process of a method for implementing permission data cache synchronization based on a Quorum mechanism according to an embodiment of the present invention. Referring to fig. 2, first, an administrator of the OMC system assigns rights to a user (i.e., an administrator of a relevant module) on the OMC platform. After the modules or corresponding contents which can be managed by each user are distributed, the distributed authority data are synchronously updated to the cache server, so that session management decoupling with the web server is realized. Compared with the method for realizing the permission synchronization under the cluster environment by depending on the session management mechanism and the session copy function of the web server in the prior art, the permission data is directly stored in the cache server of the OMC server without depending on the web server for permission management, so that the influence on the permission data updating caused by the change or the migration of the web server is avoided, and the dependence on the web server is reduced.
In addition, the invention adopts a Quorum mechanism to realize the synchronization of the authority data. Under the condition that the authority data of users (such as managers of commodities or modules) need to be updated for n cache servers in total, when the authority data are updated for k cache servers, the authority data of any n-k +1 cache servers are read, wherein one of the data is the latest data. Wherein k is an integer greater than 0 and less than or equal to n.
According to the invention, the value of k can be set according to the requirement of data consistency in the specific requirements of the distributed system.
The process of updating data is shown in the upper left dotted line frame in fig. 2, after the administrator updates the user authority, only the authority data RS [1] to RS [ k ] of the k cache servers need to be updated, and then the system will prompt that the updating is successful, and the administrator can perform other operations.
The process of reading data is shown in the dashed box at the lower left of fig. 2, after a user requests to acquire permission data, the system reads permission data RS [1, n-k +1] from n-k +1 cache servers, and finds permission data with the latest version number, such as RS [ i ], i e [1, k ], from the data, and then returns the permission data to the user.
For n-k cache servers that have not previously been synchronized with the rights data, the rights data updates will be performed by a background synchronization process, which is transparent to the administrator or user of the OMC system. As shown in the right dashed line box of FIG. 2, according to a background asynchronous processing mechanism, firstly, RS [1, n-k +1], n-k +1 groups of data are read, authority data with the latest version number, such as RS [ i ], i ∈ [1, k ], are found from the data, and then the system traverses all n cache servers and executes authority data updating operation on n-k cache servers which do not finish authority data updating.
As can be seen from the above, the processes of reading data and background synchronization are both after the process of updating data, but there is no chronological precedence relationship between the reading data and the background synchronization, and they can also be performed simultaneously. When the administrator writes the authority data, the situation of busy writing can be relieved by adopting the mode; when a user reads own authority data, the characteristics of a Quorum mechanism are adopted, n-k +1 data are randomly selected, and the latest data of the version is selected to be returned to the user, so that the data is correct data. By adopting the method to update the authority data, the latest user authority can not be influenced no matter whether the updating is successful or not when other cache servers are synchronized in the background. Therefore, the writing pressure is relieved, and the accuracy of data acquisition is ensured.
Fig. 3 is a schematic diagram of main modules of an apparatus for implementing permission data cache synchronization based on a Quorum mechanism according to an embodiment of the present invention. As shown in fig. 3, the apparatus 30 for implementing authority data cache synchronization based on the Quorum mechanism of the present invention mainly includes a foreground updating module 31 and a data reading module 32. In addition, a background synchronization module 33 may also be included.
The foreground updating module 31 is configured to update the authority data that needs to be updated to k cache servers, and then prompt that the update is successful, where the authority data includes a version number, the number of the cache servers is n, and k is a determined integer greater than 0 and less than or equal to n.
The data reading module 32 is configured to, after prompting that the update is successful, read the permission data from any n-k +1 cache servers to obtain n-k +1 sets of permission data when receiving a permission data obtaining request sent by a user, and return the permission data with the latest version number to the user.
The background synchronization module 33 is configured to update the permission data to the remaining n-k cache servers in the background after prompting that the update is successful.
The background synchronization module 33 may also be configured to read permission data from any n-k +1 cache servers according to a background asynchronous processing mechanism to obtain n-k +1 sets of permission data; finding the authority data with the latest version number from the n-k +1 groups of authority data; and updating the authority data with the latest version number to the rest n-k cache servers.
According to the technical scheme of the embodiment of the invention, the permission data is stored by using the cache server, so that session management decoupling with the web server is realized, and strong dependence on the web server can be avoided; meanwhile, a Quorum mechanism is adopted to achieve permission data cache synchronization, the problem of system delay can be effectively solved, and updating efficiency is improved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.