A data center access application method and system based on scalable distributed lock
By adopting a method based on extensible distributed locks in the data center access application system, combined with the unique index of Mysql, the existing distributed locks cannot flexibly set the time length and potential cache unavailability are solved, and data uniqueness and system stability are achieved.
Patent Information
- Application Number
- CN202111484195.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-07
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2041-12-07
AI Technical Summary
The existing distributed locks have the problem of single setting, and they cannot flexibly choose the length of use according to their own needs. At the same time, there is a potential risk of cache unavailability due to server downtime and other reasons, and it is impossible to effectively avoid the problem of innate data.
The data center access application method based on extensible distributed locks is adopted. By setting the minimum time granularity, users can flexibly select the application time interval, and use the unique index of Mysql as the underlying protection to deal with unexpected situations such as server downtime.
The scalability of distributed locks is realized, and users can flexibly select time intervals according to their needs, improving the stability of the system and data uniqueness, and avoiding the problem of data being indifferent.
Smart Images

Figure CN114218237B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data access management, and in particular to a data center access application method and system based on an extensible distributed lock. Background Art
[0002] Nowadays, more and more work relies on the support of large amounts of data, especially in fields such as the financial industry, where the reliance on data is increasing day by day. In order to cope with a large number of data access requests, an independent query server is generally used to handle access requests, serving as an intermediate bridge connecting the application end and the data end to reduce the workload of the data server. The ability and stability of the query server to manage data access requests often determines the operating efficiency and reliability of the entire data system.
[0003] For systems involving multiple applicants operating simultaneously, when applying for resources concurrently in a fixed time interval, there is a problem that multiple people share the same data and the data is not unique. In this regard, a common solution is to add a distributed lock to the access time interval to lock it so that the specific time period only matches a single access application. However, the existing distributed locks have the problem of single settings. The developer must pre-set the selectable time segments. When using them, applicants can only choose according to the pre-set segments and cannot flexibly choose the length of time to be used according to their own needs; at the same time, commonly used distributed locks, such as distributed locks using Redis cache, have the potential risk of cache unavailability due to server downtime and other reasons, which makes the distributed locks unable to function normally in some cases and cannot avoid the problem of data non-uniqueness. Summary of the invention
[0004] In order to address the deficiencies of the prior art, the present invention proposes a data center access application method and system based on scalable distributed locks. By setting the minimum time granularity, the time interval selected by the user for application can support any number of distributed locks, without the need to set different distributed locks for time intervals of different lengths, thereby simply realizing the scalability of distributed locks without the assistance of professional developers; at the same time, by using a unique index based on MySQL as the overall underlying protection, it can fully cope with distributed lock failures caused by unexpected situations such as server crashes, thereby improving system stability.
[0005] To achieve the above objectives, the technical solutions adopted by the present invention include:
[0006] A data center access application method based on an extensible distributed lock, characterized by comprising:
[0007] Configure Redis distributed locks with a preset minimum time granularity;
[0008] Set one or more Redis distributed locks based on the minimum time granularity configuration for the user's application time interval;
[0009] Set the user application time interval as a unique index and store it in the MySQL database;
[0010] After the user's application time interval ends, the corresponding one or more Redis distributed locks and the unique index stored in the MySQL database are released.
[0011] Furthermore, it also includes:
[0012] Use the set Redis distributed lock and the unique index stored in the MySQL database to check whether the user's application time interval conflicts;
[0013] When a conflict is detected, the time interval requested by the conflicting user will be rejected.
[0014] Furthermore, it also includes:
[0015] After setting one or more Redis distributed locks based on the minimum time granularity configuration for the user application time interval, check whether all the set Redis distributed locks conflict, and, after setting the user application time interval as a unique index and storing it in the MySQL database, check whether all the stored unique indexes conflict;
[0016] When a conflict is detected, the time interval requested by the conflicting user will be rejected.
[0017] Furthermore, it also includes:
[0018] When the Redis distributed lock and unique index check results are inconsistent, the unique index check result is used for execution, or, when the Redis distributed lock and unique index check results are inconsistent, the user's application for the time interval is rejected.
[0019] Furthermore, it also includes:
[0020] After the user application time interval ends, the corresponding one or more Redis distributed locks and the unique index stored in the MySQL database are released, and all remaining set Redis distributed locks after the release are checked for conflicts, and all remaining stored unique indexes are checked for conflicts.
[0021] Furthermore, it also includes:
[0022] When a conflict is detected, adjust the configuration of the Redis distributed lock according to the preset minimum time granularity.
[0023] The present invention also relates to a data center access application system based on an extensible distributed lock, which is characterized by comprising:
[0024] Redis distributed lock configuration module, used to configure Redis distributed locks with a preset minimum time granularity;
[0025] Mysql database module, used to store unique indexes;
[0026] A user application processing module, used to set one or more Redis distributed locks configured based on the minimum time granularity for the user application time interval, and set the user application time interval as a unique index;
[0027] Check module, used to check for conflicts.
[0028] Furthermore, the inspection module includes:
[0029] Redis distributed lock check submodule, used to check whether Redis distributed locks conflict;
[0030] The unique index check submodule is used to check whether the unique index conflicts;
[0031] The unique index check submodule has a higher execution priority than the Redis distributed lock check submodule.
[0032] The present invention also relates to a computer-readable storage medium, characterized in that a computer program is stored on the storage medium, and the computer program implements the above method when executed by a processor.
[0033] The present invention also relates to an electronic device, characterized in that it comprises a processor and a memory;
[0034] The memory is used to store operation instructions;
[0035] The processor is used to execute the above method by calling the operation instruction.
[0036] The beneficial effects of the present invention are:
[0037] The data center access application method and system based on scalable distributed locks described in the present invention realizes the uniqueness of data applied for by users within a specified time interval through distributed locks and unique indexes, and the variability of the minimum application time interval is realized by time interval splitting, thereby realizing the uniqueness, reliability and scalability of application changes of user application data. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 The present invention is a flow chart of a data center access application method based on an extensible distributed lock.
[0039] Figure 2 This is a structural diagram of a data center access application system based on an extensible distributed lock according to the present invention. DETAILED DESCRIPTION
[0040] In order to more clearly understand the content of the present invention, it will be described in detail with reference to the drawings and embodiments.
[0041] like Figure 1 The figure shows a flow chart of a data center access application method based on an extensible distributed lock of the present invention, which mainly includes the following steps:
[0042] Configure Redis distributed locks with a preset minimum time granularity;
[0043] User application time interval;
[0044] Use the set Redis distributed lock and the unique index stored in the MySQL database to check whether the user's application time interval conflicts;
[0045] When a conflict is detected, the time interval applied by the conflicting user will be rejected, and the user can apply for the time interval again;
[0046] When no conflict is detected, one or more Redis distributed locks based on the minimum time granularity are set for the user's application time interval; the user's application time interval is set as a unique index and stored in the MySQL database;
[0047] Check whether all Redis distributed locks that have been set conflict with each other, and check whether all unique indexes that have been stored conflict with each other;
[0048] When a conflict is detected, the time interval applied by the conflicting user will be rejected, and the user can apply for the time interval again;
[0049] When no conflict is detected, the time interval requested by the user is approved;
[0050] After the user's application time interval ends, the corresponding one or more Redis distributed locks and the unique index stored in the MySQL database are released;
[0051] Check whether all remaining Redis distributed locks that have been set after the release conflict, and check whether all remaining stored unique indexes that have been set after the release conflict. If a conflict is detected, adjust the configuration of the Redis distributed lock according to the preset minimum time granularity.
[0052] Preferably, the unique index stored in the MySQL database has a higher execution priority than the Redis distributed lock, forming a bottom-level protection for the system. In particular, when encountering abnormal situations such as server downtime, the Redis distributed lock using cache processing will lose information and cannot guarantee data uniqueness. The unique index can ensure the basic security of system data access.
[0053] According to different data access requirements, you can pre-set the appropriate minimum time granularity for configuring Redis distributed locks. For example, if the minimum time granularity is 30 minutes, each Redis distributed lock is responsible for locking a time interval of 30 minutes. When users apply, they can choose any integer multiple of 30 minutes as the application time interval. When the system needs to be adjusted, you only need to adjust the minimum time granularity to directly change the dimension of the time interval available for application. There is no need for complex Redis distributed lock configuration, which greatly reduces the manpower and material resources required for operation, maintenance and debugging.
[0054] The present invention also relates to a Figure 2 The data center access application system based on scalable distributed locks shown includes:
[0055] Redis distributed lock configuration module, used to configure Redis distributed locks with a preset minimum time granularity;
[0056] Mysql database module, used to store unique indexes;
[0057] A user application processing module, used to set one or more Redis distributed locks configured based on the minimum time granularity for the user application time interval, and set the user application time interval as a unique index;
[0058] The checking module is used to check conflicts, which also includes a Redis distributed lock checking submodule, which is used to check whether the Redis distributed lock conflicts; a unique index checking submodule, which is used to check whether the unique index conflicts; and the unique index checking submodule has a higher execution priority than the Redis distributed lock checking submodule.
[0059] By applying the system, the above method can be executed to manage the user application time interval, ensure the uniqueness of the data, and ensure the effectiveness, reliability and scalability of the data system operation.
[0060] Taking the example of a user applying for a "number checking room" from the enterprise WeChat user data center, the actual application of the method of the present invention may include the following steps:
[0061] The user randomly applies for a "counting room" and selects the time period of 2020-05-21 13:00:00~14:00:00;
[0062] According to the method of the present invention, the time interval is split with half an hour as the minimum time granularity, and is split into 2020-05-21 13:00:00-13:30:00 and 2020-05-21 13:30:00-14:00:00. Combined with the randomly applied "number checking room" unique identifier, the unique index record stored in the Mysql database is retrieved to determine whether the "number checking room" application conflicts. If there is no conflict, the "number checking room" unique identifier and the time interval are used to generate two Redis locks;
[0063] The application is stored in the database at the split time interval, and the unique identification field of the "Counting Room" and the time interval field are set as the unique index. The MySQL database stores the unique index of the application record.
[0064] After the "Counting Room" in the specified time period is used, the unique index of the Mysql database and the Redis lock are released; at the same time, a timing logic is added to loop through the unique index of the Mysql application record. If the current time is greater than the end time of the application time period, the corresponding Mysql data and Redis lock are released.
[0065] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A data center access application method based on an extensible distributed lock, characterized in that: include: Configure Redis distributed locks with a preset minimum time granularity; Set one or more Redis distributed locks based on the minimum time granularity configuration for the user's application time interval; Set the user application time interval as a unique index and store it in the MySQL database; After the user's application time interval ends, the corresponding one or more Redis distributed locks and the unique index stored in the MySQL database are released; After setting the Redis distributed lock and unique index, the conflicts between the two are checked respectively. When the check results of the Redis distributed lock and the unique index are inconsistent, the operation is performed according to the check result of the unique index. And after releasing the lock and the unique index, checking the conflicts of the remaining locks and indexes, and dynamically adjusting the preset minimum time granularity according to the conflict situation.
2. The method according to claim 1, characterized in that Also includes: Use the set Redis distributed lock and the unique index stored in the MySQL database to check whether the user's application time interval conflicts; When a conflict is detected, the time interval requested by the conflicting user will be rejected.
3. The method according to claim 2, characterized in that Also includes: After setting one or more Redis distributed locks based on the minimum time granularity configuration for the user application time interval, check whether all the set Redis distributed locks conflict, and, after setting the user application time interval as a unique index and storing it in the MySQL database, check whether all the stored unique indexes conflict; When a conflict is detected, the time interval requested by the conflicting user will be rejected.
4. The method according to claim 2 or 3, characterized in that Also includes: When the Redis distributed lock and unique index check results are inconsistent, the unique index check result is used for execution, or, when the Redis distributed lock and unique index check results are inconsistent, the user's application for the time interval is rejected.
5. The method according to claim 1, characterized in that Also includes: After the user application time interval ends, the corresponding one or more Redis distributed locks and the unique index stored in the MySQL database are released, and all remaining set Redis distributed locks after the release are checked for conflicts, and all remaining stored unique indexes are checked for conflicts.
6. The method according to claim 5, characterized in that Also includes: When a conflict is detected, adjust the configuration of the Redis distributed lock according to the preset minimum time granularity.
7. A data center access application system based on scalable distributed locks, characterized in that: include: Redis distributed lock configuration module, used to configure Redis distributed locks with a preset minimum time granularity; Mysql database module, used to store unique indexes; A user application processing module, used to set one or more Redis distributed locks configured based on the minimum time granularity for the user application time interval, and set the user application time interval as a unique index; Check module, used to check conflicts; After setting the Redis distributed lock and unique index, the conflicts between the two are checked respectively. When the check results of the Redis distributed lock and the unique index are inconsistent, the operation is performed according to the check result of the unique index. And after releasing the lock and the unique index, checking the conflicts of the remaining locks and indexes, and dynamically adjusting the preset minimum time granularity according to the conflict situation.
8. The system according to claim 7, characterized in that The inspection module comprises: Redis distributed lock check submodule, used to check whether Redis distributed locks conflict; The unique index check submodule is used to check whether the unique index conflicts; The unique index check submodule has a higher execution priority than the Redis distributed lock check submodule.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. An electronic device, characterized in that: including a processor and a memory; The memory is used to store operation instructions; The processor is used to execute the method according to any one of claims 1 to 6 by calling the operation instruction.
Citation Information
Patent Citations
Control method and device of distributed-type lock
CN107818018A
Service request processing method and device
CN108683692A