Database scaling method, device and storage equipment
By implementing multi-state evaluation and cyclical management of database sub-clusters, the complexity and availability issues of database scaling in existing technologies are resolved, enabling a smooth database scaling process and improving the reliability and efficiency of scaling.
Patent Information
- Application Number
- CN202310600886.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-25
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2043-05-25
AI Technical Summary
Existing technologies require external programs and storage space to scale up and down databases, which makes the operation complex and error-prone, unable to achieve high availability, and the number of operations per scaling up or down is limited, affecting the user experience.
By adopting a database sub-cluster approach, the working status of the database sub-cluster is evaluated by setting multiple working states and cycle periods. The parameter values are gradually increased to achieve smooth expansion and reduce data transfer time and the impact of node failures.
It enables gradual expansion of database capacity without interrupting data access, improving the reliability and efficiency of expansion, reducing the impact of node failures on the expansion process, and meeting the needs of massive data storage.
Smart Images

Figure CN116541379B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data processing, in particular to a database expansion and contraction method and device and storage medium. BACKGROUND
[0002] For enterprises, in recent years, with the increase of user quantity and access quantity, the user data to be stored will also increase explosively, and the access and operation of massive data become the design bottleneck of the system. When the database pressure is too large or fails, it will affect the user experience of all routes to the database, and if it cannot be quickly self-healed, it may cause an avalanche due to user retries, so it is imperative to perform database expansion and contraction to relieve the database pressure and self-heal.
[0003] The expansion and contraction method in the prior art can basically realize the expansion and contraction functions of the database. Then, on the one hand, in the process of database expansion and contraction, in order not to interfere with the running of other database sub-nodes, a stop service operation is needed, and after the database expansion and contraction management is completed, the access to the database is restarted. Although the above process can complete the database expansion and contraction, the data access needs to be temporarily interrupted, and after the database is restarted, all accesses need to be restored, the whole process is more prone to errors, and high availability cannot be achieved. In addition, part of the prior art can realize the expansion and contraction of high availability, but the number of single expansion and contraction operations is limited, and the number of spaces needs to be expanded and contracted by 2 each time, and the process is relatively complex, which needs to rely on a large number of external programs and storage spaces. SUMMARY
[0004] Therefore, the present application provides a database expansion and contraction method, device and storage medium to reduce the use of external programs and external storage spaces in the process of database expansion and contraction, increase the smoothness of the expansion and contraction process, and meet the application requirements of massive data storage and management.
[0005] The first aspect of the present application provides a database expansion and contraction method, which specifically comprises:
[0006] setting a database sub-cluster to a first state, the first state being an online initial state, and all spaces of the database sub-cluster being in an unavailable state in the first state;
[0007] calculating a working state score of the database sub-cluster in the first state;
[0008] setting the database sub-cluster to a second state based on the working state score in the first state, the second state being an online intermediate state, part of the spaces of the database sub-cluster being in an available state in the second state, and setting a second period corresponding to the second state;
[0009] taking the second period as a cycle period, calculating a working state score of the database sub-cluster in the second state when the second period is reached;
[0010] increasing a parameter value of the parameter of the database sub-cluster based on the working state score in the second state to update the parameter of the database sub-cluster until the parameter of the database sub-cluster reaches a threshold value, setting the database sub-cluster to a third state, and the third state is a complete online state.
[0011] Preferably, the database sub-cluster includes a plurality of working states, and the plurality of working states at least include a first state, a second state and a third state,
[0012] Each working state corresponds to a different online stage of the database sub-cluster,
[0013] The parameter values of the parameters of the database sub-cluster in different states are different, and the parameter values of the parameters of the database sub-cluster in different periods of the same state are different.
[0014] Preferably, the parameter values at least include a weight of the database sub-cluster;
[0015] The database sub-cluster includes attribute information, and the attribute information at least includes a sub-cluster identifier and an online state identifier of the database sub-cluster,
[0016] The online state identifier includes an online state and an offline state, and is used to identify whether the corresponding database sub-cluster can be accessed.
[0017] Preferably, after setting the database sub-cluster to the second state, the method further includes:
[0018] Generating an order number based on the sub-cluster identifier of the database sub-cluster;
[0019] Generating a data access request based on the order number;
[0020] Positioning a target database sub-cluster based on the data access request to realize data access.
[0021] Preferably, a weighted random algorithm is used to determine a to-be-visited database sub-cluster from a plurality of database sub-clusters of a database,
[0022] The plurality of database sub-clusters of the database include a database sub-cluster in the second state and a database sub-cluster in the third state;
[0023] Generating an order number according to the sub-cluster identifier of the to-be-visited database sub-cluster and request information;
[0024] Embedding the order number in a data access request, and sending the data access request;
[0025] After receiving a data access request, the server extracts the order number, parses the target database sub-cluster based on the order number, and accesses the data based on the weight of the target database sub-cluster.
[0026] Preferably, the second period is set as a cycle period.
[0027] Each time the second cycle is reached, the working status score of the database sub-cluster in the second state is calculated;
[0028] If the working status score in the second state is greater than the threshold, the parameter value of the database sub-cluster is increased to update the parameters of the database sub-cluster.
[0029] If the updated parameter values of the database sub-cluster do not reach the threshold, the database sub-cluster remains in the second state, and the working status score of the database sub-cluster in the second state continues to be calculated with the second cycle as the cycle period.
[0030] If the parameter values of the updated database sub-cluster reach the threshold, set the data sub-cluster to the third state;
[0031] If the working status score in the second state is less than or equal to the threshold, the database sub-cluster is set to the first state.
[0032] Preferably, based on the requirement to take down a database sub-cluster, the status of the database sub-cluster to be taken down is set to the fourth state.
[0033] The fourth state is the waiting-to-go-off state.
[0034] In the fourth state, the database sub-cluster to be taken offline will not generate new access routes;
[0035] Update the status of the database sub-cluster to be taken offline based on the business scenario and the data types stored in the database sub-cluster.
[0036] A second aspect of the present invention provides a database scaling device, specifically comprising:
[0037] The mounting module is used to set the database sub-cluster to the first state, which is the initial online state. In the first state, all space of the database sub-cluster is in an unavailable state.
[0038] The calculation module is used to calculate the working status score of the database sub-cluster in the first state;
[0039] The switching module is configured to set the database sub-cluster to a second state based on the working state score in the first state, the second state being an intermediate state of being online, and part of the space of the database sub-cluster being in an available state in the second state, and set a second period corresponding to the second state;
[0040] The monitoring module is configured to calculate the working state score of the database sub-cluster in the second state with the second period as a cycle period, and calculate the working state score of the database sub-cluster in the second state every time the second period is reached.
[0041] The expansion module is configured to increase the parameter value of the database sub-cluster based on the working state score in the second state to update the parameter of the database sub-cluster until the parameter of the database sub-cluster reaches a threshold value, and set the database sub-cluster to a third state, the third state being a complete online state.
[0042] The third aspect of the present application provides a computer readable storage medium, which stores a computer program, and the program is executed by a processor to implement the steps of the database expansion and contraction method.
[0043] The database expansion and contraction method, device and storage medium provided by the present application increase the capacity of the database by using the database sub-cluster mode to increase the nodes, without the need for backup, migration and other operations on the data in the database, thereby reducing the data handling time. In addition, by introducing the database sub-cluster to increase the database space, the database expansion and contraction method provided by the present application can cyclically evaluate the working state of the database sub-cluster under different parameter settings according to a cycle period, and gradually add the database sub-cluster to the database by using multiple cycles until the final complete online state. Compared with the method of directly adding nodes to the database, the present application can expand the database in a more smooth manner, reduce the influence of node failure on the expansion process, and improve the reliability of database expansion. BRIEF DESCRIPTION OF DRAWINGS
[0044] Figure 1 A flowchart of a database expansion method according to an exemplary embodiment of the present application is shown.
[0045] Figure 2 A flowchart of a database contraction method according to an exemplary embodiment of the present application is shown.
[0046] Figure 3 A schematic block diagram of a database expansion device according to an exemplary embodiment of the present application is shown.
[0047] Figure 4 A schematic block diagram of a database contraction device according to an exemplary embodiment of the present application is shown.
[0048] Figure 5 FIG. 1 shows a schematic diagram of an electronic device according to an example embodiment of the present application. DETAILED DESCRIPTION
[0049] The example embodiments will be described in detail with reference to the accompanying drawings. In the following description, unless otherwise indicated, like numbers in the different drawings represent similar or analogous elements. The embodiments described in the following example embodiments are not meant to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the present application as detailed in the appended claims.
[0050] The terminology used in the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application. As used in the present application and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0051] It should be noted that the terms "first", "second", and the like, herein do not necessarily have an ordinal or chronological significance. Rather, these terms are used to distinguish different components or steps in the present application from each other. It is to be understood that the terms "comprise", "comprising", "comprises", "including", "include", "includes" and / or the like are used herein in their open-ended, conventional sense, that is, they are used to mean "including, but not limited to", one or more steps or other features. It is also to be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0052] In the prior art, in order to realize the expansion and contraction of the database, an external program is usually needed to judge the state of the newly added / to-be-deleted node at any time, and an external space is needed to store the intermediate information of the judgment process. If a large number of database sub-nodes are simultaneously expanded and contracted, the program running resources and external storage space needed will increase massively. On the other hand, in the prior art, as an example of CN106777031A, the database expansion method is to directly add a node and set the weight attribute of the node, so that the data request can directly access the newly added node. The above expansion method directly increases the node to the database cluster in a fixed ratio, and the expansion and contraction process is harsh, without paying attention to whether the database node can be normally used, and the use rate of the database node also does not change after the node is added, resulting in low utilization rate of the newly added database node.
[0053] In view of the technical problems of the above-mentioned expansion and contraction process, the first embodiment of the present application provides a database expansion and contraction method, as shown in the following formula: Figure 1 The database expansion and contraction method specifically includes:
[0054] Setting a database sub-cluster to a first state, the first state being an online initial state, all spaces of the database sub-cluster being in an unusable state in the first state;
[0055] Calculating a working state score of the database sub-cluster in the first state;
[0056] Setting the database sub-cluster to a second state based on the working state score in the first state, the second state being an online intermediate state, part of the spaces of the database sub-cluster being in a usable state in the second state, and setting a second period corresponding to the second state;
[0057] Taking the second period as a cycle period, calculating the working state score of the database sub-cluster in the second state whenever the second period is reached;
[0058] Increasing the parameter value of the database sub-cluster based on the working state score in the second state to update the parameter of the database sub-cluster until the parameter of the database sub-cluster reaches a threshold, and setting the database sub-cluster to a third state, the third state being a complete online state.
[0059] The database expansion and contraction method provided by the present application increases the nodes in the form of database sub-cluster to expand the capacity of the database, without the need for backup, migration and other operations on the data in the database, thereby reducing the data handling time. In addition, by introducing the database sub-cluster to increase the database space, the database expansion and contraction method provided by the present application can cyclically evaluate the working state of the database sub-cluster under different parameter settings according to a cycle period, and gradually add the database sub-cluster to the database by using the cycle of multiple periods until the final complete online state. Compared with the method of directly adding nodes to the database, the present application can expand the database in a more smooth manner, reduce the influence of node failure on the expansion process, and improve the reliability of database expansion.
[0060] Specifically, the database sub-cluster comprises a plurality of working states, the plurality of working states at least comprising a first state, a second state and a third state, each working state corresponding to a different online stage of the database sub-cluster, and corresponding to the first state, the second state and the third state, the first state corresponds to an initial online state, the second state corresponds to an intermediate online state, and the third state corresponds to a complete online state, the parameter values of the parameters of the database sub-cluster are different in different states, and the parameter values of the database sub-cluster are different in different periods of the same state. The database sub-cluster has a parameter, and the value of the parameter is used to represent the space accessible by the database sub-cluster, and the value range of the parameter is [a, b], a < b. In the first state, the database sub-cluster parameter has a first value a; in the first period of the second state, the database sub-cluster parameter has a second value a+k1, in the second period of the second state, the database sub-cluster parameter has a third parameter value a+k2, and in the nth period of the second state, the database sub-cluster parameter has a parameter value a+k n In the third state, the database sub-cluster parameter has a value b, wherein a < a+k1 < a+k2 < a+k n As an optional embodiment, a = 0, b = 100, the parameter value of the parameter is different in each period, and the parameter value of the parameter shows a growth trend as the number of periods increases. The parameter value at least includes the weight of the database sub-cluster. In the first state, the weight of the database sub-cluster is a, in the third state, the weight of the database sub-cluster is b, and in the second state, the weight of the database sub-cluster gradually increases from a. When a user issues a data request, the database management module will allocate a data processing amount corresponding to the weight to each database sub-cluster according to the weight of each database sub-cluster, that is, the weight of the database sub-cluster is used to represent the space accessible by the database sub-cluster. The present application gradually expands the database capacity by gradually releasing the accessible space of the database sub-cluster within a time period, which can meet the data request processing demand and relieve the data processing pressure on the one hand, and can continuously check whether the database sub-cluster can work normally in the process of gradual expansion on the other hand, thereby avoiding introducing faulty nodes into the database to increase the data processing pressure or causing the database to crash, and improving the reliability of database expansion.
[0061] As an optional embodiment, before setting the database sub-cluster to the first state, the method further comprises detecting the data processing speed of the database; calculating the space utilization state of the database based on the data processing speed of the database, determining the joining time of the database sub-cluster; and setting the database sub-cluster to the first state if the joining time of the database sub-cluster is reached. In use, the database is usually used to complete the reading and writing of data based on requests, and when the capacity of the database is insufficient, the speed of the database in processing data reading and writing is greatly reduced, at which time the demand for database expansion is generated. Therefore, first, the data processing speed of the database is detected, and if the data processing speed of the database is less than a first preset value, the detection of the space of the database is triggered, and the space utilization state of the database is calculated. The space utilization state of the database is specifically the ratio of the size of the unused space in the database to the size of the total space of the database; if the space utilization state of the database is less than a preset value, the database sub-cluster is triggered to be added at a first time point, otherwise the database sub-cluster is added at a second time point, the second time point being later than the first time point. The slow speed of the database in processing data is caused by many reasons, such as slow network speed and insufficient storage space. In order to further analyze the reasons for the slow processing speed, the size of the remaining unused space in the database is directly calculated, and for the case where the remaining unused space is insufficient, the database is expanded.
[0062] The database sub-cluster is set to the first state, and the first state at least includes setting the parameters of the database sub-cluster to the minimum endpoint of the parameter interval, for example, setting the weight of the database sub-cluster to 0. The first state at least further includes referring to the configuration information of the existing sub-cluster of the database, setting the configuration parameters of the database sub-cluster. Generally, the database sub-cluster is composed of one master and two slaves, and the configuration information of the newly added sub-cluster can be set by referring to the configuration information of the existing sub-cluster. Before setting the database sub-cluster to the first state, the database sub-cluster needs to be mounted on the database at this time, and the database to be expanded is determined as the database to be expanded; the existing sub-cluster of the database to be expanded is confirmed, the master-slave domain name address of the newly added database sub-cluster is set, the empty database table of the same size as the existing sub-cluster is created, and the access control list same as the existing sub-cluster is configured.
[0063] As an optional embodiment, the database sub-cluster includes attribute information, which at least includes a sub-cluster identifier (subID) of the database sub-cluster and an online state identifier, the sub-cluster identifier being a unique identifier under a cluster, used to identify a specific database sub-cluster; when the database sub-cluster is addressed using the sub-cluster identifier, a flag bit of the database sub-cluster is written into a business order routed to the database sub-cluster, used for routing when data is deleted, modified or inquired, the identifier can be automatically generated or manually configured. The online state identifier includes an online state and an offline state, used to identify whether the corresponding database sub-cluster can be accessed, and the value can be selected as online or offline. When the online state identifier of the database sub-cluster is the online state, the server initializes the database connection pool, starts the database heartbeat detection, verifies the ACL configuration, and supports data access; when the online state identifier of the database sub-cluster is the offline state, the server no longer performs the database heartbeat detection, and destroys the database connection, waiting to be removed from the database sub-cluster.
[0064] In some optional embodiments, if it is necessary to expand the database, the database sub-cluster is set to a first state, the first state being an online initial state, specifically, the online state identifier of the database sub-cluster is set to the online state, the weight of the database sub-cluster is 0, and all spaces of the database sub-cluster are in an unavailable state, at this time the database sub-cluster has been connected to the database, but since the weight is 0, no corresponding request will be sent to the newly added database sub-cluster when data is requested, thereby realizing the state of being online but not in use. As an optional embodiment, the configuration center or the zookeeper can be used to store the configurations of each sub-cluster under the cluster A and perform dynamic listening, such as the open source configuration center Apollo, Spring Cloud Config, Nacos, and the configuration center or the zookeeper cluster researched by the enterprise.
[0065] The working state score of the database sub-cluster in the first state is calculated, specifically, the working state score of the database sub-cluster in the first state is calculated based on the setting information of the database sub-cluster in the first state, and the working state score at least includes a score of communication ability and a score of data read-write ability. Whether the database sub-cluster can work normally is determined based on the working state score in the first state. If the working state score in the first state is greater than a preset value, it is indicated that the database sub-cluster can work normally, the performance evaluation of the database sub-cluster is completed, and the database sub-cluster is set to a second state. As an optional embodiment, a first period corresponding to the first state is set, the time length of the first period is less than the time length of the second period, and since the database sub-cluster is set to the first state, if the time reaches the first period, the working state score of the database sub-cluster in the first state is triggered to be calculated. If the working state score in the first state is less than or equal to the preset value, the database sub-cluster is kept in the first state.
[0066] The database expansion and contraction method provided by the application can automatically trigger the working state score of the database sub-cluster when the first period arrives, so that the communication ability and the data read-write ability of the database sub-cluster are checked when the database sub-cluster is in the online state but temporarily does not receive data requests, so that the database sub-cluster nodes that can work normally are selected for expansion, and the faulty nodes are avoided to be introduced into the expansion system, and the reliability of the database expansion is improved.
[0067] The database sub-cluster is set to a second state, specifically including: setting the parameter of the database sub-cluster to have a second value, for example, a+k1, based on the change of the parameter value, the second state is an online intermediate state, and part of the space of the database sub-cluster in the second state is in an available state. For example, the parameter data value of the database sub-cluster can be set to 1%, and the 1% space of the database sub-cluster can be used for data request processing, and the online state identifier of the database sub-cluster is set to an online state.
[0068] Since the database sub-cluster can receive a data request after being set to the second state, after the database sub-cluster is set to the second state, the method further includes: generating an order number based on the sub-cluster identifier of the database sub-cluster; generating a data access request based on the order number; locating a target database sub-cluster based on the data access request to realize data access. The database includes at least one database sub-cluster, and the data access request is usually for a specific database sub-cluster. Therefore, a weighted random algorithm is used to determine a to-be-accessed database sub-cluster from a plurality of database sub-clusters of the database, the plurality of database sub-clusters of the database including a database sub-cluster in the second state and a database sub-cluster in the third state; an order number is generated according to the sub-cluster identifier of the to-be-accessed database sub-cluster and request information, and the generated order number has a format of 20230208000XY00ABC, wherein XY is the obtained database sub-cluster identifier, the database sub-cluster identifier is generally a number, but is not limited to a number, a letter, etc., and ABC can be used for a database and table routing rule; the order number is embedded in the data access request, and the data access request is sent; the server receives the data access request and extracts the order number therefrom, parses the target database sub-cluster according to the order number, and realizes data access according to the weight of the target database sub-cluster. The database sub-cluster in the second state can receive a data access request, that is, there is a log corresponding to the received data access request.
[0069] A second period corresponding to the second state is set, and a value of the second period is greater than or equal to a first period triggering calculation of a working state score of the database sub-cluster in the first state. After the database sub-cluster enters the second state, the database sub-cluster starts to gradually increase the parameter value of the parameter with the second period as a cycle period. Specifically, the second period is set as the cycle period, and the working state score of the database sub-cluster in the second state is calculated every time the second period is reached. If the working state score in the second state is greater than a threshold value, it indicates that the database sub-cluster can work normally, and the parameter value of the database sub-cluster is increased to update the parameter of the database sub-cluster. If the parameter value of the database sub-cluster after the update does not reach the threshold value, the database sub-cluster is still in the second state, and the working state score of the database sub-cluster in the second state is calculated with the second period as the cycle period. If the parameter value of the database sub-cluster after the update reaches the threshold value, it indicates that the database sub-cluster can work normally under each data access amount, and the database sub-cluster is set to a third state. If the working state score in the second state is less than or equal to the threshold value, it indicates that the database sub-cluster cannot work normally under the access amount corresponding to the current parameter value, and the database sub-cluster is set to the first state, that is, the online state is maintained but data access cannot be performed. The database sub-cluster can participate in database expansion again after re-checking.
[0070] The database expansion and contraction method provided by the application can roll back the expansion if the monitored database sub-cluster cannot work normally in the process of smooth expansion. Since the space expansion ratio is low, even if there is data impact, only a small amount of data will be affected. After the weight is set to 0%, no new data will be routed to the sub-cluster, no incremental abnormal data will be generated, and the probability of expansion failure can be ignored.
[0071] The database includes a plurality of database sub-clusters, and each database sub-cluster has a weight value. For data access, the amount of data written in each database sub-cluster is calculated according to the proportion of the weight value of each database sub-cluster in the sum of the weight values of all database sub-clusters. For example, assuming that the weight of database sub-cluster A1 is 100%, and the weight of database sub-cluster A2 is 10%, the data ratio to be written into A1 and A2 is 10:1.
[0072] The working state score of the database sub-cluster in the second state is calculated, specifically including: obtaining a working log of the database sub-cluster in the second state, and calculating the working state score in the second state based on the working log.
[0073] As an optional embodiment, the parameter value of the database sub-cluster increases by the same amount each time the second period is reached, for example, the parameter value of the database sub-cluster is increased by 1% each time the second period is reached, that is, when the database sub-cluster enters the second state, the parameter value of the database sub-cluster is a+1% the first time the second period is reached, if the parameter value of the database sub-cluster is 1% when the second state is entered, the parameter value of the database sub-cluster is 2% the first time the second period is reached, the parameter value of the database sub-cluster is 3% the second time the second period is reached, and so on. As another optional embodiment, the parameter value of the database sub-cluster increases by the same amount each time the second period is reached, for example, the parameter value of the database sub-cluster is increased by a preset function each time the second period is reached, the preset function can be a linear function, an exponential function, etc., based on the setting of the preset function, the closer the parameter value of the database sub-cluster is to the maximum endpoint value of the parameter, the greater the parameter value increment, that is, when the database sub-cluster enters the second state, the parameter value of the database sub-cluster is a+1% the first time the second period is reached, the parameter value of the database sub-cluster is a+1%+2% the second time the second period is reached, if the parameter value of the database sub-cluster is 1% when the second state is entered, the parameter value of the database sub-cluster is 2% the first time the second period is reached, the parameter value of the database sub-cluster is 4% the second time the second period is reached, and so on.
[0074] Setting the weight of the database sub-cluster to the maximum value b completes a database expansion. It can be seen that, by adding a database sub-cluster and configuring its weight and online state, the present application can realize smooth expansion of the database without stopping service. Of course, the present application is not limited to expansion in the case of a single sub-cluster, and the present application is realized by adding a database sub-cluster for expansion, and is not limited to regular expansion in the form of powers of 2, thereby improving the applicability of the database expansion and contraction method. The expansion process of the entire database sub-cluster is simple to operate and less prone to errors, and smooth expansion and contraction is realized without stopping service, thereby improving the data expansion and contraction efficiency.
[0075] As shown in Figure 2 The database expansion and contraction method further includes: setting the state of the to-be-offlined database sub-cluster to a fourth state based on the offlining demand of the database sub-cluster, the fourth state being a waiting-offline state, in which the to-be-offlined database sub-cluster does not generate new access routes; and updating the state of the to-be-offlined database sub-cluster based on the business scenario and the type of data stored in the database sub-cluster.
[0076] Specifically, the working states of the database sub-cluster further include at least a fourth state and a fifth state, the database sub-cluster includes a database sub-cluster identifier, an online state identifier of the database sub-cluster, and a parameter of the database sub-cluster, wherein the online state identifier corresponding to the fourth state is online, and the parameter of the database sub-cluster is a minimum endpoint value, for example, 0; the online state identifier corresponding to the fifth state is offline, and the parameter of the database sub-cluster is a minimum endpoint value, for example, 0. In the fourth state, the database sub-cluster to be offline does not generate a new access route; in the fifth state, the database sub-cluster to be offline is removed from the database.
[0077] If there is a database sub-cluster offline requirement in the database, the database sub-cluster to be offline is determined at this time, and the fourth state of the database sub-cluster to be offline is set. The business scenario and data type of the database sub-cluster to be offline in the fourth state are judged, if the business scenario is less than a threshold or the data type meets a preset condition, it is indicated that the database sub-cluster stores infrequently used and irrelevant data, at this time, the online state identifier is set to offline first, and then the parameter of the database sub-cluster is set to the minimum endpoint value, so as to set the database sub-cluster to be offline to the fifth state. As an optional embodiment, the business scenario at least includes an electronic red packet, if the timeliness of the related information of the electronic red packet is less than a threshold, it is indicated that the database sub-cluster should be offline to free up space. The data type includes cold data and hot data; if the data type stored in the database sub-cluster to be offline is cold data, it is indicated that the database sub-cluster should be offline to free up space, the database sub-cluster to be offline is set to the fifth state, and the data of the cold data type is backed up and archived.
[0078] The shrinkage method provided by the embodiment of the application removes the sub-cluster database, and then performs data cold backup or archiving, without the help of an archiving program for data migration. The merchant method is not limited to shrinkage processing when the business volume is low, and can also realize data cold backup and archiving. Obviously, when a certain database sub-cluster has a large pressure, the weight of the database sub-cluster can be reduced to reduce data writing; when the sub-cluster fails, the weight of the sub-cluster can be set to 0%, so that no incremental abnormal data is generated, and the influence of service failure and user experience is further reduced. The database expansion and shrinkage method provided by the application can realize the addition and removal of the database sub-cluster, realize database fault self-healing, and reduce the influence on user experience.
[0079] The second embodiment of the application provides a database expansion and shrinkage device, as shown in the figure, the database expansion and shrinkage device specifically includes: Figure 3
[0080] The mounting module is configured to set the database sub-cluster to a first state, the first state is an online initial state, and all spaces of the database sub-cluster in the first state are in an unusable state.
[0081] a computing module configured to calculate a working state score of the database sub-cluster in the first state;
[0082] a switching module configured to set the database sub-cluster to a second state based on the working state score in the first state, the second state being an intermediate state of going online, and part of the space of the database sub-cluster in the second state being in an available state, and set a second period corresponding to the second state;
[0083] a monitoring module configured to take the second period as a cycle period, and calculate a working state score of the database sub-cluster in the second state whenever the second period is reached;
[0084] an expansion module configured to increase the parameter value of the database sub-cluster based on the working state score in the second state to update the parameter of the database sub-cluster until the parameter of the database sub-cluster reaches a threshold value, and set the database sub-cluster to a third state, the third state being a complete online state.
[0085] It can be found that the present embodiment is a device embodiment corresponding to the first embodiment, and the present embodiment can be implemented in cooperation with the first embodiment. The related technical details mentioned in the first embodiment are still valid in the present embodiment. In order to reduce repetition, they will not be described here. Correspondingly, the related technical details mentioned in the present embodiment can also be applied in the first embodiment.
[0086] As shown in Figure 4 the database expansion and contraction device further comprises at least:
[0087] an offline module configured to set a fourth state of a database sub-cluster to be offline if there is a database sub-cluster offline demand in the database, judge the business scenario and data type of the memory access in the database sub-cluster to be offline in the fourth state, and if the business scenario timeliness is lower than a threshold value or the data type meets a preset condition, set the online state identifier to offline, and then set the parameter of the database sub-cluster to be offline to a minimum endpoint value, so as to set the database sub-cluster to be offline to a fifth state.
[0088] It is worth mentioning that each module involved in the present embodiment is a logical module. In actual application, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present application, units not closely related to solving the technical problems proposed in the present application are not introduced in the present embodiment, but this does not mean that there are no other units in the present embodiment.
[0089] The specification also provides a computer readable storage medium storing a computer program, which can be used to execute the database scaling method provided in the foregoing Figure 1 、 2 The specification also provides a schematic structural diagram of an electronic device as shown in the foregoing
[0090] The specification also provides a schematic structural diagram of an electronic device as shown in the foregoing Figure 5 As described in the foregoing Figure 5 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and of course can also include other hardware required by a business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs to implement the database scaling method described in the foregoing Figure 1 Of course, in addition to the software implementation, the specification does not exclude other implementation manners, such as a logic device or a combination of software and hardware, that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or a logic device.
[0091] The specification is described with reference to flowcharts and / or block diagrams of the method, device (system), and computer program product according to the embodiments of the specification. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of the flows and / or blocks in the flowcharts and / or block diagrams 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 produce a device that implements the functions specified in the flow Figure 1 The functions specified in one flow or multiple flows and / or blocks Figure 1 The functions specified in one flow or multiple flows and / or blocks
[0092] These computer program instructions can also be stored in a computer readable memory that can guide the computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including instruction devices that implement the functions specified in the flow Figure 1 The functions specified in one flow or multiple flows and / or blocks Figure 1 The functions specified in one flow or multiple flows and / or blocks
[0093] Each embodiment in the specification is described in a progressive manner, and the same and similar parts between each embodiment can be referred to each other, and each embodiment mainly describes the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts can be referred to the part of the method embodiment.
[0094] The above merely provides the example of the present application, but does not serve to limit the present application. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application should be included in the scope of claims of the present application.
Claims
1. A database scaling method, characterized in that, The database scaling method specifically includes: Set the database sub-cluster to the first state, which is the initial online state. In the first state, all space of the database sub-cluster is unavailable. Calculate the setting information of the database sub-cluster in the first state, and calculate the working status score of the database sub-cluster in the first state. The working status score includes at least a score for communication capability and a score for data read and write capability. Based on the working status score in the first state, the database sub-cluster is set to the second state, which is the intermediate online state. In the second state, part of the space of the database sub-cluster is available. A second period corresponding to the second state is set. Using the second cycle as the cycle period, each time the second cycle is reached, the working status score of the database sub-cluster in the second state is calculated; Based on the working status score in the second state, the parameter values of the database sub-cluster are increased to update the parameters of the database sub-cluster until the parameters of the database sub-cluster reach a threshold, and the database sub-cluster is set to the third state, which is the fully online state. Each working state corresponds to a different online stage of the database sub-cluster. The parameter values of the database sub-cluster are different in different periods within the same state. As the number of periods increases, the parameter values increase. The parameter values include at least the weight of the database sub-cluster, which is used to characterize the accessible space of the database sub-cluster. In the first state, the weight of the database sub-cluster is 'a'. In the third state, the weight of the database sub-cluster is 'b'. In the second state, the weight of the database sub-cluster increases from 'a'. When a user issues a data request, the database management module allocates a data processing volume corresponding to the weight of each database sub-cluster.
2. The database scaling method according to claim 1, characterized in that, The database sub-cluster includes multiple working states, which at least include a first state, a second state, and a third state. Each working state corresponds to a different online phase of the database sub-cluster. The parameter values of the database sub-cluster are different under different states, and the parameter values of the database sub-cluster are different under different periods in the same state.
3. The database scaling method according to claim 1, characterized in that, The parameter values include at least the weights of the database sub-clusters; The database sub-cluster includes attribute information, which includes at least the sub-cluster identifier and the online status identifier. The online status identifier includes online and offline status, which are used to indicate whether the corresponding database sub-cluster can be accessed.
4. The database scaling method according to claim 1, characterized in that, Setting the database sub-cluster to the second state also includes: An order number is generated based on the sub-cluster identifier of the database sub-cluster; Generate a data access request based on the order number; Based on the data access request, the target database sub-cluster is located and data access is achieved.
5. The database scaling method according to claim 4, characterized in that, A weighted random algorithm is used to determine the database sub-cluster to be accessed from multiple database sub-clusters. The database includes multiple database sub-clusters in a second state and database sub-clusters in a third state. An order number is generated based on the sub-cluster identifier of the database sub-cluster to be accessed and the request information; Embed the order number in the data access request and send the data access request; After receiving a data access request, the server extracts the order number, parses the target database sub-cluster based on the order number, and accesses the data based on the weight of the target database sub-cluster.
6. The database scaling method according to claim 1, characterized in that, Set the second period as the cycle period. Each time the second cycle is reached, the working status score of the database sub-cluster in the second state is calculated; If the working status score in the second state is greater than the threshold, the parameter value of the database sub-cluster is increased to update the parameters of the database sub-cluster. If the parameter values of the updated database sub-cluster do not reach the threshold, the database sub-cluster remains in the second state, and the working status score of the database sub-cluster in the second state continues to be calculated with the second cycle as the cycle period. If the parameter values of the updated database sub-cluster reach the threshold, set the data sub-cluster to the third state; If the working status score in the second state is less than or equal to the threshold, the database sub-cluster is set to the first state.
7. The database scaling method according to claim 1, characterized in that, Based on the requirement to take a database sub-cluster offline, the status of the database sub-cluster to be taken offline is set to the fourth state. The fourth state is the waiting-to-go-off state. In the fourth state, the database sub-cluster to be taken offline will not generate new access routes; Update the status of the database sub-cluster to be taken offline based on the business scenario and the data types stored in the database sub-cluster.
8. A database scaling device, characterized in that, The database scaling device specifically includes: The mounting module is used to set the database sub-cluster to the first state, which is the initial online state. In the first state, all space of the database sub-cluster is in an unavailable state. The calculation module is used to calculate the setting information of the database sub-cluster in the first state and to calculate the working status score of the database sub-cluster in the first state. The working status score includes at least a score for communication capability and a score for data read and write capability. The switching module is used to set the database sub-cluster to a second state based on the working status score in the first state. The second state is an online intermediate state. In the second state, part of the space of the database sub-cluster is available. The module also sets a second period corresponding to the second state. The monitoring module is used to calculate the working status score of the database sub-cluster in the second state each time the second cycle is reached, with the second cycle as the cycle period. The expansion module is used to increase the parameter values of the database sub-cluster based on the working status score in the second state to update the parameters of the database sub-cluster until the parameters of the database sub-cluster reach a threshold, and then set the database sub-cluster to the third state, which is the fully online state. Each working state corresponds to a different online stage of the database sub-cluster. The parameter values of the database sub-cluster are different in different periods within the same state. As the number of periods increases, the parameter values increase. The parameter values include at least the weight of the database sub-cluster, which is used to characterize the accessible space of the database sub-cluster. In the first state, the weight of the database sub-cluster is 'a'. In the third state, the weight of the database sub-cluster is 'b'. In the second state, the weight of the database sub-cluster increases from 'a'. When a user issues a data request, the database management module allocates a data processing volume corresponding to the weight of each database sub-cluster.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that... When the program is executed by the processor, it implements the steps of the database scaling method according to any one of claims 1-7.
Citation Information
Patent Citations
Database capacity expansion method and device
CN106777031A
Transaction processing method and device, computer equipment and storage medium
CN111338766A
Elastic scaling method and device based on Kubernetes container cloud platform and application
CN115237610A