Database fragment switching method and device, equipment and medium

By counting the number of concurrent accesses, identifying abnormal database shards and triggering master-subsidiary switches, the problem of global failure caused by the detection delay in database sharding exceptions is solved, and fast switching and high availability are achieved.

CN119646094APending Publication Date: 2025-03-18CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411786606.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

When database sharding is abnormal, the existing technology has a global failure problem caused by activation delay, especially when the task volume is large, all connections from the application server to the main database are filled, resulting in a global error.

Method used

By counting the number of concurrent accesses to each database shard by the application server, identifying abnormal database shards, and sending switching instructions to the database, directly contacting the switching of the main and backup databases, avoiding the delay in the database itself to detect the activity.

Benefits of technology

It realizes rapid switching when database sharding is abnormal, avoids global failures, and ensures high availability and performance stability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646094A_ABST
    Figure CN119646094A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, in particular to a database fragment switching method and device, equipment and a medium, which are used for directly triggering main-standby switching of database fragments when the database fragments are abnormal and avoiding global faults caused by delay of activity detection of a database. The method comprises the following steps: determining a concurrent access number of each database fragment according to the database fragment accessed by a task of an application server; according to the concurrent access number of each database fragment, screening out a target database fragment from each database fragment; and sending a switching instruction to the database, wherein the switching instruction is used for triggering the database to switch the target database fragment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a database shard switching method, device, equipment and medium. Background Art

[0002] Under normal circumstances, database shards use the primary database. When the primary database records are updated, the data will be synchronized to the standby database in real time. If an exception occurs in a database shard, the database will automatically switch access to the database shard to the standby database to ensure that the database data is available and avoid impact on the business. Therefore, if a database shard is abnormal, the database can automatically switch to the standby database in real time.

[0003] When a database shard fails, the database internal master-slave switch has two stages: In the master database detection stage, the database system continuously monitors the status of the master database, but has not yet determined whether the master database is abnormal. At this time, the application system will time out when accessing the master database. In the master-slave switch stage, the database has detected the failure of the master database, but has not yet switched to the standby database. At this time, the application will directly report an error when accessing the master database.

[0004] Therefore, the master-slave switching mechanism when the database already has abnormal shards has the following problems: During the master database detection phase, if the task volume is large, the large number of tasks of the application accessing the master database has occupied all connections from the application server to the master database, which will cause a global error, not limited to the faulty shard. It will not return to normal until the master-slave switching phase is completed and the switch is made to the standby database. Summary of the invention

[0005] The embodiments of the present application provide a database shard switching method, apparatus, device and medium, which are used to directly trigger the master-slave switching of the database shard when the database shard is abnormal, thereby avoiding global failures caused by delays in the database's own detection.

[0006] In a first aspect, the present application provides a database shard switching method, which is applied to an application server, and the method includes:

[0007] Determine the number of concurrent accesses to each database shard based on the database shards accessed by the application server's tasks;

[0008] According to the number of concurrent accesses to each database shard, select the target database shard from each database shard;

[0009] A switching instruction is sent to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

[0010] The database shard switching method provided in this embodiment counts the number of concurrent accesses of the application server to each database shard to identify database shard anomalies, and when it is determined that the database shard is abnormal, a switching instruction is sent to the database to directly trigger the switching of the primary and standby databases, thereby avoiding the delay of the database's own activation.

[0011] In a possible embodiment, the database shard accessed by the task of the application server is determined in the following manner:

[0012] Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table;

[0013] The shard configuration information includes location information of the database shard to which the database table belongs.

[0014] In a possible embodiment, determining the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server includes:

[0015] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0016] In a possible embodiment, the step of selecting a target database shard from each database shard according to the number of concurrent accesses to each database shard includes:

[0017] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0018] In a possible embodiment, sending the switching instruction to the database includes:

[0019] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0020] In a second aspect, the present application provides a database shard switching device, the device comprising:

[0021] The flow control module is used to determine the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server;

[0022] The anomaly identification module is used to select the target database shard from each database shard according to the number of concurrent accesses to each database shard;

[0023] The trigger switching module is used to send a switching instruction to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

[0024] In a possible embodiment, the traffic control module is specifically used to determine the database shard accessed by the task of the application server in the following manner:

[0025] Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table;

[0026] The shard configuration information includes location information of the database shard to which the database table belongs.

[0027] In a possible embodiment, the flow control module is specifically used for:

[0028] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0029] In a possible embodiment, the abnormality identification module is specifically used to:

[0030] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0031] In a possible embodiment, the trigger switching module is specifically used to:

[0032] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0033] In a third aspect, the present application provides an application server, including:

[0034] A memory for storing program instructions;

[0035] The processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods in the first aspect according to the obtained program instructions.

[0036] In a fourth aspect, the present application provides an electronic device, including:

[0037] A memory for storing program instructions;

[0038] The processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods in the first aspect according to the obtained program instructions.

[0039] In a fifth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes any one of the methods described in the first aspect.

[0040] In a sixth aspect, the present application provides a computer program product, comprising: a computer program code, when the computer program code is run on a computer, the computer executes any one of the methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A schematic diagram of a normal database access provided by an embodiment of the present application;

[0042] Figure 2 A schematic diagram of a database sharding anomaly provided in an embodiment of the present application;

[0043] Figure 3 A schematic diagram of switching to a standby database when a database shard is abnormal provided in an embodiment of the present application;

[0044] Figure 4 A flowchart of a method for switching database shards provided in an embodiment of the present application;

[0045] Figure 5 A schematic diagram of database access during an online transaction provided by an embodiment of the present application;

[0046] Figure 6 A flowchart of an implementation of a database access entry program provided in an embodiment of the present application;

[0047] Figure 7 A structural diagram of a database shard switching device provided in an embodiment of the present application;

[0048] Figure 8 A structural diagram of an electronic device provided in an embodiment of the present application;

[0049] Fig. 9 A structural diagram of an application server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0051] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.

[0052] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description. It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0053] In the technical solution of this application, the acquisition, transmission, storage, and use of data are in compliance with the requirements of relevant national laws and regulations.

[0054] Before introducing the database shard switching method provided in the embodiment of the present application, in order to facilitate understanding, the technical background of the embodiment of the present application is first introduced in detail.

[0055] As businesses move from host platforms to distributed platforms, a large number of business functions will be run based on distributed databases. Distributed databases have compute nodes (CN) for processing application server requests and data nodes (DN) for storing data. In the case of sharded data storage, each data node is used to store data for one shard. Application servers and compute nodes, as well as compute nodes and data nodes, are connected through connection pools. Figure 1 As shown, this embodiment provides a schematic diagram of normal database access. Under normal circumstances, for online transactions sent to application servers, database access is in milliseconds, so the connections between application servers and computing nodes, and between computing nodes and data nodes will not be fully occupied, and the system can operate normally. Figure 2 As shown, this embodiment also provides a schematic diagram of database shard anomaly. In the scenario where a shard of a data node is abnormal, the computing node will time out when accessing the faulty data node. If the transaction volume sent to the application server is large, the connection between the computing node and the faulty shard node will be full, and the application server will not be able to get a response. In this scenario, the connection between the application server and the computing node will also be full, which will cause a global failure.

[0056] Currently, distributed databases have a high availability mechanism based on master and standby databases. Under normal circumstances, database shards use the master database, and when the master database records are updated, the data is synchronized to the standby database in real time. If an exception occurs in a database shard, the database will automatically switch access to the database shard to the standby database to ensure that the data in the database is available and avoid impacting the business. Therefore, see Figure 3 A schematic diagram of switching to a standby database when a database shard is abnormal is provided. If a database shard is abnormal, the database can automatically switch to the standby database in real time. When a database shard fails, there are two stages of master-slave switching within the database: In the master database detection stage, the database system continuously monitors the status of the master database, but has not yet determined whether the master database is abnormal. At this time, the application system will time out when accessing the master database. In the master-slave switching stage, the database has detected the failure of the master database, but has not yet switched to the standby database. At this time, the application will directly report an error when accessing the master database.

[0057] Although the database has a master-slave switching mechanism when sharding is abnormal, this master-slave switching mechanism has the following problems: When a shard fails, the master-slave switching inside the database has two stages:

[0058] Phase 1, main database detection phase: In this phase, the database system continuously monitors the status of the main database, but it is not clear whether the main database is abnormal. At this time, the application system will time out when accessing the database. This phase lasts about 30 seconds.

[0059] Phase 2, master-slave switch phase: In this phase, the database has detected the failure of the master database, but has not yet switched to the slave database. At this time, the application will directly report an error when accessing the database. This phase lasts about 30 seconds.

[0060] During the primary database detection phase, if the task volume is large, the large number of tasks of the application accessing the primary database will have occupied all connections from the application server to the primary database, which will cause a global error, not limited to the faulty shard. Normal operation can only be restored after the primary-standby switchover phase is completed and the switch to the standby database is completed.

[0061] In order to solve the above technical problems, this embodiment provides a method for switching database shards. The core idea is to identify database shard anomalies by counting the number of concurrent accesses of the application server to each database shard, and when it is determined that the database shard is abnormal, a switching instruction is sent to the database to directly trigger the switching of the primary and standby databases, thereby avoiding the delay of the database's own detection.

[0062] like Figure 4 As shown, this embodiment provides a method for switching database shards, which is applied to an application server. An application server refers to a program that exposes business logic to a client through various protocols, and provides a way to access the business logic for use by client applications. The specific implementation process of the method is as follows:

[0063] Step 400: Determine the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server;

[0064] In practice, the tasks in this embodiment include but are not limited to trading business or other business, and this embodiment does not make too many restrictions on this. The number of concurrent accesses in this embodiment refers to the total number of tasks when multiple tasks access the same database shard at the same time. It should be noted that the "simultaneous access" here does not just mean access at the same time, but also multiple tasks accessing a database shard within a preset period of time.

[0065] It should be noted that database sharding refers to splitting a large database into multiple smaller, independent database instances, each of which is responsible for storing and managing a portion of the data. These small database instances are called "shards", and each shard contains part of the data and the corresponding index. The main purpose of database sharding is to solve the problem that a single database cannot meet the needs of large-scale data storage and high concurrent access. By splitting a large database into multiple small database instances, each instance is only responsible for the storage and query of a portion of the data, the performance and scalability of the system can be improved, the pressure on a single database can be reduced, and the security and reliability of the data can be improved. Database sharding mainly includes the following types:

[0066] Horizontal sharding: Divide the rows in the table into different database instances according to a sharding key (such as user ID, geographic location, etc.). This method is suitable for scenarios with large amounts of data and frequent query operations.

[0067] Vertical sharding: Divide the columns in a table into different database instances. This is suitable for scenarios where the data structure is complex and the table contains a large number of fields.

[0068] Hybrid sharding: A method that combines horizontal and vertical sharding, suitable for scenarios with large data volumes and complex data structures.

[0069] In some embodiments, the database shard accessed by the task of the application server is determined in the following manner:

[0070] The database shard accessed by the task of the application server is determined according to the database table accessed by the task of the application server and the shard configuration information of each database table; wherein the shard configuration information includes the location information of the database shard to which the database table belongs.

[0071] In some embodiments, each database table is configured with a shard configuration information, such as a shard configuration table, and the shard configuration information includes but is not limited to: shard calculation field offset, shard calculation field length, shard range i starting value, shard range i ending value, database shard number, etc., wherein the shard calculation field offset is used to indicate the starting position of the key value; the shard calculation field length is used to indicate the key value length, and i is an integer greater than or equal to 0.

[0072] In implementation, this embodiment configures calculation rules for the database shards where the database table accessed by the application server is located. For each database table, calculation rules need to be configured. When a transaction accesses the database table, the field value used to calculate the shards in the database table can be intercepted according to the "shard calculation field offset" and "shard calculation field length", and then i is searched to make the shard field value belong to the "shard range i start" and "shard range i end". At this time, the "shard range i value" is the database shard number. That is, according to the key value of the database table, it is determined which database shard it falls on.

[0073] Table 1 Sharding configuration information of database table

[0074]

[0075]

[0076] In some embodiments, this embodiment determines the number of concurrent accesses to each database shard in the following manner:

[0077] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0078] It should be noted that concurrent access to a database refers to the situation where two or more users or programs access or operate the same database at the same time. Concurrent access is one of the important characteristics of a database system, which can significantly improve system performance and resource utilization.

[0079] Step 401: Filter out a target database shard from each database shard according to the number of concurrent accesses to each database shard;

[0080] In this embodiment, the target database shard is used to represent an abnormal database shard.

[0081] In some embodiments, the present embodiment selects the target database shards in the following manner:

[0082] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0083] In implementation, the thresholds corresponding to different database shards may be different or the same. The threshold of a database shard is determined based on the access performance of the database, where the access performance of the database includes but is not limited to the maximum number of concurrent accesses. Only when the number of concurrent accesses to a database shard exceeds the threshold corresponding to the database shard, the database shard is determined to be abnormal, and the database shard at this time is determined as the target database shard.

[0084] This embodiment adds a "shard access configuration" to set the threshold for concurrent access of each application server to each database shard. If this threshold is exceeded, the database shard is considered abnormal. For each database table in the database, a new set of "table shard calculation configuration" is added to set the shard calculation rules of this table, that is, to calculate the location of the database shard where the database table is located. When the system is running, two functions are added to the memory. One function is that each application server uses a "shard access global counter" to record the number of concurrent accesses to the database shards accessed by the current task of the application server. The other function is to use a "shard access list" when each task is executed to record the database shards involved in the access of the task. When the task is executed, the database shards accessed by the task are registered. The format can be an array, and each element is the number of the database shard accessed by the task. The task is released at the end of the task, and the database shards accessed by the task are cleared from the shard access list. Add a function to the database access entry program to calculate the database shard accessed this time, modify the "shard access global counter", and register the "shard access list" at the same time. In the database access entry program, if the number of concurrent accesses from the current application server to a database shard exceeds the threshold, the database shard is judged to be faulty. At this time, the access counter of the database shard is cleared and an error is reported, and then the database operation is asynchronously called to force the master-slave database switch. At the end of the task, for the database shard accessed this time, the "shard access global counter" is modified and the "shard access list" is cleared.

[0085] like Figure 5 As shown, this embodiment also provides a schematic diagram of database access during online transactions, wherein, after the transaction starts, when the transaction accesses database table A, the database shard where database table A is located is calculated as database shard 1, and the number of concurrent accesses to the database shard 1 is determined according to the shard access counter (i.e., flow control is performed on the database shard 1, and the number of concurrent accesses to the database shard 1 is controlled not to exceed the threshold), and the read and write operations of the database table A are performed; wherein, the shard access counter is used to count the number of concurrent accesses to the current database shard, one database shard corresponds to one shard access counter, and the shard access counters of all database shards are added to the shard access global counter. When the transaction accesses database table B, the database shard where database table B is located is calculated as database shard 2, and the number of concurrent accesses to the database shard 2 is determined according to the shard access counter (i.e., flow control is performed on the database shard 2, and the number of concurrent accesses to the database shard 2 is controlled not to exceed the threshold), and the read and write operations of the database table B are performed. When the transaction ends, the shard access counter is updated.

[0086] In some embodiments, the threshold of concurrent access of a single application server to each database shard is set in the following manner: Optionally, the application servers in this embodiment may be of different types, and the threshold of concurrent access of each type of application server to each database shard is the same.

[0087] Table 2 Concurrent access threshold configuration of application server

[0088]

[0089]

[0090] In some embodiments, the present embodiment can also modify the database access entry program, in which the calculation of the database shard is added, and the flow control of the database shard (used to determine the number of concurrent accesses) and memory registration (used to record the current number of concurrent accesses) are performed. Among them, the location of the currently accessed database shard is calculated, the number of concurrent accesses to the database shard is obtained, and it is determined whether the database shard is abnormal. When the database shard is abnormal, a switching command is sent to the database to execute the switching of the database shard.

[0091] Step 402: Send a switching instruction to the database, where the switching instruction is used to trigger the database to switch the target database shard.

[0092] In implementation, when the application server detects that a database shard is abnormal, this embodiment directly sends a switching instruction to the database, instructing the database to switch the target database shard to another normal database shard.

[0093] In some embodiments, the switching instruction is sent to the database in the following manner:

[0094] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0095] Optionally, the distributed locks in this embodiment include but are not limited to: redis locks (distributed locks based on redis), mysql locks (distributed locks based on database tables), zookeeper locks (distributed locks based on zookeeper), etc.

[0096] like Figure 6 As shown, this embodiment also provides an implementation process of a database access entry program, as shown below:

[0097] Step 600: Determine the database shards involved in the current task access based on the shard configuration information of each database table;

[0098] The location of the database shard involved in the task access may be determined by reading the shard configuration information of the database table accessed by the task.

[0099] Step 601, determine whether the database shard involved in the access already exists in the shard access list, if so, execute step 606, otherwise execute step 602;

[0100] In implementation, if the database shard involved in the access already exists in the shard access list, it means that the task has accessed the same database shard multiple times. In this case, it does not affect the number of concurrent accesses to the database shard, so the database can be accessed normally. If the database shard involved in the access does not exist in the shard access list, the number of concurrent accesses to the current database shard needs to be increased.

[0101] The shard access list is used to record the database shards involved in the task access. The database shards accessed by the task are registered when each task is executed. When the task ends, the database shards accessed by the task are cleared from the shard access list.

[0102] Step 602: Determine whether the number of concurrent accesses in the shard access global counter of the database shard exceeds a threshold. If so, execute step 603; otherwise, execute step 605.

[0103] The shard access global counter is used to record the number of concurrent accesses to each database shard accessed by the application server's tasks. If the threshold is not exceeded, normal database shard access is performed, and the shard access list and shard access global counter are updated. If the threshold is exceeded, it means that the database shard is abnormal at this time, and the database shard is switched.

[0104] Step 603: clear the shard access counter of the database shard, and report an error for this task;

[0105] The shard access global counter includes the number of concurrent accesses to each database shard. Each database shard corresponds to a shard access counter, which is used to count the number of concurrent accesses to the database shard. At this time, the shard access counter of the database shard whose concurrent access number exceeds the threshold is cleared.

[0106] Step 604: add a redis lock, use a thread different from the one that executes the application server task, send a switch instruction to the database, and execute the switch of the primary and standby database shards;

[0107] In implementation, after the task is completed, the triggering of the primary and standby database shard switching is initiated asynchronously (reusing a new thread), and redis locks are added before and after the triggering to prevent multiple tasks from triggering the switching of the primary and standby database shards at the same time.

[0108] Step 605: Update the shard access list and the shard access global counter;

[0109] When the number of concurrent accesses to the database shard does not exceed the threshold, the shard access counter of the database shard accessed this time is incremented by 1 in the shard access global counter. The shard number of the database shard accessed this time is added to the shard access list. The shard access global counter is used to record the number of concurrent accesses to all database shards, where one database shard corresponds to one shard access counter, which is used to record the number of concurrent accesses to the database shard.

[0110] Step 606: Access the database shard.

[0111] During implementation, at the end of the main process of the task, the corresponding database shard in the shard access global counter of the database shard accessed by the task is modified, and the value of the concurrent access number of the database shard is reduced by 1; then, the shard access list of the database shard is cleared, that is, all the database shard numbers accessed by this task are cleared.

[0112] This embodiment controls the traffic of database shard access by counting the number of concurrent accesses to the database shards, so that the application server can identify whether a specific database shard has failed. In this way, when a database shard fails, the database can be promptly controlled to switch between the primary and standby database shards, avoiding global failures caused by long database switching times. In actual use, if each application server is configured to connect to the database as n, the database shard access traffic (number of concurrent accesses) configuration can be set to 2n / 3. At this time, the timeout connection caused by the failure of a single database shard is at most 2n / 3. When it exceeds 2n / 3, the switching of the primary and standby database shards is triggered. After the switch, the application server will no longer time out when connected to the database shard, thus avoiding global failures.

[0113] Based on the same inventive concept, the present application embodiment provides a database shard switching device, please refer to Figure 7 , the device comprises:

[0114] The flow control module 700 is used to determine the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server;

[0115] The abnormality identification module 701 is used to select a target database shard from each database shard according to the number of concurrent accesses to each database shard;

[0116] The switching triggering module 702 is used to send a switching instruction to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

[0117] In a possible embodiment, the traffic control module 700 is specifically used to determine the database shard accessed by the task of the application server in the following manner:

[0118] Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table;

[0119] The shard configuration information includes location information of the database shard to which the database table belongs.

[0120] In a possible embodiment, the flow control module 700 is specifically used for:

[0121] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0122] In a possible embodiment, the abnormality identification module 701 is specifically used for:

[0123] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0124] In a possible embodiment, the trigger switching module 702 is specifically configured to:

[0125] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0126] Based on the same inventive concept, the embodiment of the present application provides an electronic device, which can implement the database shard switching function discussed above, please refer to Figure 8 , the device includes a processor 801 and a memory 802, wherein:

[0127] Memory 802, used to store program instructions;

[0128] The processor 801 is configured to call the program instructions stored in the memory and execute the following steps according to the obtained program instructions:

[0129] Determine the number of concurrent accesses to each database shard based on the database shards accessed by the application server's tasks;

[0130] According to the number of concurrent accesses to each database shard, select the target database shard from each database shard;

[0131] A switching instruction is sent to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

[0132] In a possible embodiment, the processor 801 is specifically configured to determine the database shard accessed by the task of the application server in the following manner:

[0133] Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table;

[0134] The shard configuration information includes location information of the database shard to which the database table belongs.

[0135] In a possible embodiment, the processor 801 is specifically configured to execute:

[0136] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0137] In a possible embodiment, the processor 801 is specifically configured to execute:

[0138] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0139] In a possible embodiment, the processor 801 is specifically configured to execute:

[0140] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0141] Based on the same inventive concept, the embodiment of the present application provides an application server, which can implement the database shard switching function discussed above, please refer to Fig. 9 , the device includes a processor 901 and a memory 902, wherein:

[0142] Memory 902, used to store program instructions;

[0143] The processor 901 is configured to call the program instructions stored in the memory and execute the following steps according to the obtained program instructions:

[0144] Determine the number of concurrent accesses to each database shard based on the database shards accessed by the application server's tasks;

[0145] According to the number of concurrent accesses to each database shard, select the target database shard from each database shard;

[0146] A switching instruction is sent to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

[0147] In a possible embodiment, the processor 901 is specifically configured to determine the database shard accessed by the task of the application server in the following manner:

[0148] Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table;

[0149] The shard configuration information includes location information of the database shard to which the database table belongs.

[0150] In a possible embodiment, the processor 901 is specifically configured to execute:

[0151] The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

[0152] In a possible embodiment, the processor 901 is specifically configured to execute:

[0153] If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

[0154] In a possible embodiment, the processor 901 is specifically configured to execute:

[0155] Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

[0156] Based on the same inventive concept, the embodiment of the present application provides a computer-readable storage medium, and the computer program product includes: computer program code, when the computer program code is executed on a computer, the computer executes any of the database shard switching methods discussed above. Since the principle of solving the problem by the above computer-readable storage medium is similar to that of the database shard switching method, the implementation of the above computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.

[0157] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the database shard switching methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of the database shard switching method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.

[0158] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0159] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0160] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of user-operated steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0162] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for switching database shards, characterized in that: Applied to an application server, the method comprises: Determine the number of concurrent accesses to each database shard based on the database shards accessed by the application server's tasks; According to the number of concurrent accesses to each database shard, select the target database shard from each database shard; A switching instruction is sent to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

2. The method according to claim 1, characterized in that The database shards accessed by the application server's tasks are determined as follows: Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table; The shard configuration information includes location information of the database shard to which the database table belongs.

3. The method according to claim 1, characterized in that Determining the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server includes: The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

4. The method according to claim 1, characterized in that The step of selecting a target database shard from each database shard according to the number of concurrent accesses to each database shard comprises: If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

5. The method according to claim 1, characterized in that The sending of the switching instruction to the database includes: Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

6. A database shard switching device, characterized in that: The device includes: The flow control module is used to determine the number of concurrent accesses to each database shard according to the database shard accessed by the task of the application server; The anomaly identification module is used to select the target database shard from each database shard according to the number of concurrent accesses to each database shard; The trigger switching module is used to send a switching instruction to the database, wherein the switching instruction is used to trigger the database to switch the target database shard.

7. The device according to claim 6, characterized in that The flow control module is specifically used to determine the database shard accessed by the task of the application server in the following manner: Determine the database shard accessed by the task of the application server according to the database table accessed by the task of the application server and the shard configuration information of each database table; The shard configuration information includes location information of the database shard to which the database table belongs.

8. The device according to claim 6, characterized in that The flow control module is specifically used for: The number of concurrent accesses to each database shard is determined based on the number of tasks that concurrently access each database shard in the application server's tasks.

9. The device according to claim 6, characterized in that The abnormality identification module is specifically used for: If the number of concurrent accesses to a database shard exceeds a threshold corresponding to the database shard, the database shard is determined as a target database shard.

10. The device according to claim 6, characterized in that The trigger switching module is specifically used for: Add distributed locks and use a different thread from the one that executes the application server's tasks to send a switch instruction to the database.

11. An application server, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods of claims 1-5 according to the obtained program instructions.

12. An electronic device, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods of claims 1-5 according to the obtained program instructions.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method according to any one of claims 1 to 5.

14. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 5.

Citation Information

Cited By

  • Fragmented probing method and device, traffic scheduling method and device, equipment and storage medium

    CN120768940A