Table division method and device and computer readable storage medium
Through the configuration center management of subtable configuration and dynamic update, the problem of high complexity of subtable configuration of multi-service instances is solved, the sharing of subtable configuration and user experience is improved, and the high concurrency and large data volume scenarios are supported.
Patent Information
- Application Number
- CN202411144316.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2025-01-14
AI Technical Summary
The independent configuration of existing subtable configurations between multiple service instances results in high management complexity, poor user experience, and inconvenient maintenance.
The permission checksum subtable configuration management is performed through the configuration center. The target service registers and pulls subtable configurations at startup, uses subtable algorithms to perform subtable operations, and dynamically updates subtable configurations to support high concurrency and large data volume scenarios.
Simplifies the management of sub-table configuration, realizes configuration sharing, reduces configuration workload, and improves user experience and system response speed and availability.
Smart Images

Figure CN119311663A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of database management, and in particular to a table partitioning method, device, and computer-readable storage medium. Background Art
[0002] Before the advent of sharding technology, databases faced performance bottlenecks caused by the rapid growth of data volume. The storage capacity of a single table was insufficient to handle a large number of concurrent requests, resulting in slow query speeds and system response delays. In addition, as data accumulated, maintenance tasks became more complex, and the backup and recovery process was time-consuming and error-prone, affecting the stability and availability of the business. These challenges prompted developers to look for more effective solutions to improve database performance and management efficiency.
[0003] Table sharding is a database design strategy that improves query performance and management efficiency by splitting the data of a single table into multiple sub-tables. Table sharding usually distributes data to different tables based on specific rules, such as time, range, or hash value, thereby reducing the size of a single table, reducing the database load, and improving data access speed. At the same time, table sharding helps simplify data management and maintenance, making it more efficient when processing large-scale data.
[0004] In the prior art, common sharding solutions are based on the interceptor of mybatis or shardingsphere. However, in the execution of the above solutions, the sharding configuration is placed on the private configuration of the service, and multiple identical service instances need to be independently configured with sharding configuration. If there are many service instances, then the configuration of sharding configuration will be a very large workload, which brings great inconvenience to users and a very bad user experience. Summary of the invention
[0005] The embodiments of the present application provide a table partitioning method, device, and computer-readable storage medium, which can reduce the work of configuring table partitioning, thereby improving user experience.
[0006] A first aspect of an embodiment of the present application provides a table partitioning method, including:
[0007] When the target service is started, a service registration is initiated to the configuration center so that the configuration center performs permission verification on the target service;
[0008] When the permission check is passed, the sub-table configuration is pulled from the configuration center;
[0009] Initialize the table splitting algorithm according to the table splitting configuration;
[0010] The target table is partitioned using the partitioning algorithm to obtain a target partitioned table, where the target table is a data table associated with the target service.
[0011] Optionally, using the table partitioning algorithm to partition the target table to obtain the target partitioned table includes:
[0012] Obtain the sharding start time of the sharding table configuration;
[0013] Whenever the sharding start time arrives, the target table is sharded using the table sharding algorithm to obtain a target sharded table.
[0014] Optionally, after the target table is partitioned by using the table partitioning algorithm, the method further includes:
[0015] When a service request is received, the incoming time of the service request and the initial sharding start time of the sharding table configuration are obtained;
[0016] If the incoming time is later than the initial sharding start time, querying the target sharding table through the sharding algorithm and the service request to obtain a first query result;
[0017] The service request is responded to through the first query result.
[0018] Optionally, querying the target sub-table through the sub-table algorithm and the service request to obtain a first query result includes:
[0019] Determine a shard key according to the service request;
[0020] According to the table partitioning algorithm, the partitioning key is used to determine the partitioning value;
[0021] According to the table partitioning algorithm, using the shard value to determine the table partition name;
[0022] The target sub-table is queried according to the sub-table name to obtain a first query result.
[0023] Optionally, determining the shard value by using the shard key according to the table sharding algorithm includes:
[0024] Determine a hash algorithm according to the sub-table configuration;
[0025] Performing a hash operation on the shard key using the hash algorithm to obtain a hash value;
[0026] According to the table partitioning algorithm, the sharding value is determined using the hash value.
[0027] Optionally, after obtaining the incoming time of the service request and the initial sharding start time of the sharding table configuration, the method further includes:
[0028] If the incoming time is earlier than the initial sharding start time, querying the target table through the service request to obtain a second query result;
[0029] The service request is responded to through the second query result.
[0030] Optionally, after pulling the sub-table configuration from the configuration center, the method further includes:
[0031] Receive a push message for updating sub-table configuration sent by the configuration center;
[0032] Pull the latest sub-table configuration from the configuration center according to the push message;
[0033] Use the latest sharding configuration to update the local sharding configuration.
[0034] A second aspect of the embodiment of the present application provides a meter sub-device, including:
[0035] A registration unit, used to initiate service registration to a configuration center when a target service is started, so that the configuration center performs permission verification on the target service;
[0036] A pulling unit, used to pull the sub-table configuration from the configuration center after the permission check passes;
[0037] An initialization unit, used to initialize a table partitioning algorithm according to the table partitioning configuration;
[0038] The table partitioning unit is used to partition the target table using the table partitioning algorithm to obtain a target partitioned table, where the target table is a data table associated with the target service.
[0039] Optionally, the sub-table unit includes:
[0040] An acquisition module, used to acquire the sharding start time of the sharding table configuration;
[0041] The table partitioning module is used to partition the target table using the table partitioning algorithm to obtain the target partitioned table whenever the partitioning start time arrives.
[0042] Optionally, the sub-meter device further includes:
[0043] An acquiring unit, configured to acquire, when receiving a service request, an incoming time of the service request and an initial sharding start time of the sharding table configuration;
[0044] A first query unit, configured to query the target shard table by using the sharding algorithm and the service request to obtain a first query result if the incoming time is later than the initial sharding start time;
[0045] The first responding unit is configured to respond to the service request through the first query result.
[0046] Optionally, the first query unit includes:
[0047] A first determination module, configured to determine a shard key according to the service request;
[0048] A second determination module is used to determine a shard value using the shard key according to the table sharding algorithm;
[0049] A third determination module, configured to determine a sub-table name using the shard value according to the sub-table algorithm;
[0050] The query module is used to query the target sub-table according to the sub-table name to obtain a first query result.
[0051] Optionally, the second determining module is specifically configured to:
[0052] Determine a hash algorithm according to the sub-table configuration;
[0053] Performing a hash operation on the shard key using the hash algorithm to obtain a hash value;
[0054] According to the table partitioning algorithm, the sharding value is determined using the hash value.
[0055] Optionally, the sub-meter device further includes:
[0056] A second query unit, configured to query the target table through the service request to obtain a second query result if the incoming time is earlier than the initial sharding start time;
[0057] The second responding unit is configured to respond to the service request through the second query result.
[0058] Optionally, the sub-meter device further includes an updating unit, and the updating unit is used to:
[0059] Receive a push message for updating sub-table configuration sent by the configuration center;
[0060] Pull the latest sub-table configuration from the configuration center according to the push message;
[0061] Use the latest sharding configuration to update the local sharding configuration.
[0062] A third aspect of the embodiment of the present application provides a meter sub-device, including:
[0063] Processor, memory, input-output unit, and bus;
[0064] The processor is connected to the memory, the input and output unit, and the bus;
[0065] A program is stored in the memory, and the processor calls the program to execute the method in the first aspect and any possible implementation manner of the first aspect.
[0066] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the computer executes the method in the first aspect and any possible implementation of the first aspect.
[0067] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0068] According to the method provided in the embodiment of the present application, the target service needs to register with the configuration center when it is started, and the configuration center performs permission verification. Only if the verification is passed can the sub-table configuration be pulled from the configuration center for the target service, and the sub-table configuration is handed over to the configuration center for management, which greatly simplifies the configuration of the sub-table configuration, realizes the sharing of the sub-table configuration, reduces the work of configuring the sub-table configuration, and improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] Figure 1 This is a flow chart of an embodiment of the table partitioning method in the embodiment of the present application;
[0070] Figure 2 A flowchart of an embodiment of responding to a service request in an embodiment of the present application;
[0071] Figure 3 A flowchart of an embodiment of querying a target sub-table to obtain a first query result in an embodiment of the present application;
[0072] Figure 4 This is a flow chart of an embodiment of determining a shard value according to a shard key in an embodiment of the present application;
[0073] Figure 5 A flowchart of an embodiment of updating a sub-table configuration in an embodiment of the present application;
[0074] Figure 6 This is a structural diagram of an embodiment of the table division method in the embodiment of the present application;
[0075] Figure 7 It is a structural diagram of another embodiment of the table partitioning method in the embodiments of the present application. DETAILED DESCRIPTION
[0076] The embodiments of the present application provide a table partitioning method, device, and computer-readable storage medium for reducing the workload of configuring table partitioning, thereby improving user experience.
[0077] The method of the present application can be applied to a server, a terminal or other devices with logic processing capabilities, and the present application does not limit this. For the convenience of description, the following description is made by taking the execution subject as a server as an example.
[0078] The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0079] See also Figure 1 In the embodiment of the present application, one embodiment of the table division method includes:
[0080] 101. When the target service is started, service registration is initiated to the configuration center so that the configuration center can perform permission verification on the target service;
[0081] At the initial stage of service startup, the server will initiate a registration request to the configuration center. The configuration center is a component that centrally manages configuration and service status, and is usually used in a microservice architecture. The purpose of the server registering a service is to let the configuration center know the existence of the service and assign it a unique identifier. During this process, the configuration center will perform permission verification on the target service to ensure that the service has the permission to access and use the resources of the configuration center. This mechanism helps improve the security of the system and ensures that only authorized services can access key configurations.
[0082] 102. When the permission check is passed, pull the sub-table configuration from the configuration center;
[0083] Once the server's permission check is passed, the server can pull the required table partitioning configuration from the configuration center. Table partitioning configuration usually includes how to divide data into different tables, for example, the rules and methods for splitting according to certain fields (such as user ID or timestamp). This step is crucial because the correct table partitioning configuration will directly affect the storage and access efficiency of data.
[0084] 103. Initialize the table partitioning algorithm according to the table partitioning configuration;
[0085] After obtaining the table partitioning configuration, the server will initialize the table partitioning algorithm. The table partitioning algorithm is the logical rules and calculation method for implementing data partitioning, which determines how to effectively distribute data to different table partitions. The initialization process may include loading the necessary algorithm parameters, preprocessing the table partitioning rules, and preparing any resources required for subsequent data partitioning operations. This stage ensures that the server can perform efficient data partitioning according to the configuration.
[0086] 104. Use the table partitioning algorithm to partition the target table to obtain the target partitioned table.
[0087] Finally, the server uses the previously initialized table partitioning algorithm to perform actual table partitioning operations on the target table. This means that according to the preset table partitioning rules, the server divides the data in the target table into multiple tables to form a target table. This process can not only optimize the access efficiency of data, but also improve query performance and data management flexibility, helping the system to better handle high concurrency and large data volume scenarios. In this way, data can be stored and retrieved more efficiently, supporting system expansion and maintenance. Among them, the target table is a data table associated with the target service. When registering the target service, the server will report the data table required by the target service (i.e., the target table) to the configuration center at the same time. The configuration center will perform data table permission verification on the target service based on the name of the target service and the name of the target table. The configuration center uses the name of the target service to query the data table permission configuration stored locally. If the information of the target service requested to be registered by the server is consistent with the record in the data table permission configuration, the verification result is characterized as passed, otherwise the verification result is characterized as failed.
[0088] In this embodiment, when the target service is started, the server needs to register with the configuration center, and the configuration center performs permission verification. If the verification is passed, the server can pull the sub-table configuration from the configuration center for the target service. Handing over the sub-table configuration to the configuration center for management greatly simplifies the configuration of the sub-table configuration, realizes the sharing of the sub-table configuration, reduces the work of configuring the sub-table configuration, and improves the user experience.
[0089] Furthermore, the server first obtains the sharding start time from the sharding configuration, which refers to the time point of the data sharding operation, and determines when to start sharding the target table. Whenever the sharding start time arrives, the server will use the previously initialized sharding algorithm to perform sharding operations on the target table. This means that according to the preset sharding rules, the server divides the data in the original table into multiple shards to form the target sharding table. For example, if the sharding start time is 0:00 on the 1st of each month, the server will use the sharding algorithm to shard the target table at 0:00 on the 1st of each month. This process can not only optimize the access efficiency of data, but also improve query performance and data management flexibility, helping the system to better handle scenarios with high concurrency and large data volumes. In this way, data can be stored and retrieved more efficiently, supporting system expansion and maintenance.
[0090] See also Figure 2 In some embodiments of the present application, the table partitioning method may further include the following steps 201 to 203:
[0091] 201. When a service request is received, the incoming time of the service request and the initial sharding start time of the sharding table configuration are obtained;
[0092] When the server receives a service request from a client, it will first record the incoming time of the request. At the same time, the server will also obtain the initial sharding start time from the sharding configuration, which refers to the time point when the sharding operation is first performed. These two time information are very important for subsequent query processing to ensure the accuracy and effectiveness of the query. The incoming time is included in the service request. The incoming time refers to the time in the data record that needs to be queried. Each data record has a corresponding time. The incoming time does not refer to the time when the service request occurs.
[0093] 202. If the input time is later than the initial sharding start time, query the target sharding table through the sharding algorithm and service request to obtain the first query result;
[0094] Next, the server will compare the incoming time with the initial sharding start time. If the incoming time is later than the initial sharding start time, the server will use the previously initialized sharding algorithm and the query conditions contained in the service request to initiate a query to the target sharding table, thereby obtaining the first query result, which is the data filtered from the target sharding table based on the request conditions.
[0095] 203. Respond to the service request through the first query result.
[0096] Finally, the server sends the first query result as a response to the client to satisfy the service request. This process ensures that the client can obtain the required data and maintain the responsiveness and performance of the system while processing the request efficiently. In this way, the server can effectively support the needs of customers while ensuring the consistency and accuracy of the data.
[0097] Furthermore, if the incoming time is earlier than the initial sharding start time, the server will choose to query the target table directly. In this case, the server will use the query conditions in the service request to operate on the target table and obtain the second query result. The server will then return the second query result to the client as the response content. This means that even if the sharding has not yet taken effect, the server can still effectively process the request and provide the required data. This process ensures the flexibility and availability of the system, so that the client's request can be responded to in a timely manner even under different time conditions.
[0098] See also Figure 3 In some embodiments of the present application, if the input time in step 202 in the above embodiment is later than the initial sharding start time, querying the target sharding table through the sharding algorithm and service request to obtain the first query result may include the following steps 301 to 304:
[0099] 301. Determine the shard key according to the service request;
[0100] The server will parse the received service request and identify the information related to the shard. The shard key is a key field, usually an attribute related to data distribution, such as user ID, order ID, etc. The server will extract this shard key based on the content of the request. For example, if the request is for a user's order information, the shard key may be the user's unique identifier. By determining the shard key, the server can know how to distribute the data to different shards.
[0101] 302. According to the table partitioning algorithm, the partitioning key is used to determine the partitioning value;
[0102] After the shard key is determined, the server converts this shard key into a shard value according to the predefined sharding algorithm. The shard value is calculated by inputting the shard key into a specific algorithm, which may be hashing, modulo operation, etc. The value will be used to determine the specific shard table associated with it. For example, if the shard key is a user ID, the server may determine which shard table the user's data is stored in by performing a modulo operation on the user ID (such as user ID% 10).
[0103] 303. According to the table partitioning algorithm, the table partitioning name is determined using the shard value;
[0104] Once the shard value is obtained, the server needs to map it to a specific shard table name. This is usually done through the construction rules in the sharding algorithm. For example, if there are 10 shards, the shard table names may be "orders_0", "orders_1"... "orders_9". The process of determining the shard table name may involve matching the shard value with the naming rules of the shard table to obtain the specific shard table name required for the query.
[0105] 304. Query the target sub-table according to the sub-table name to obtain a first query result.
[0106] Finally, the server uses the sub-table name obtained in the previous step to execute the query. By connecting to the correct sub-table, the server can quickly retrieve data related to the service request. The result of the query will be stored as the first query result, and the server will then return the first query result to the client as a response.
[0107] In this embodiment, it is ensured that with the support of the sharding strategy, the system can efficiently process requests and return accurate data, thereby improving the efficiency of data management and retrieval.
[0108] See also Figure 4 In some embodiments of the present application, step 302 in the above embodiment determines the shard value according to the shard key and includes the following steps 401 to 403:
[0109] 401. Determine the hash algorithm according to the table configuration;
[0110] The server needs to select the appropriate hash algorithm based on the table sharding configuration. The table sharding configuration usually contains detailed information about how to distribute data to different tables, including the type of hash algorithm used. For example, common hash algorithms can be MD5, SHA-1, or simple modulus operations. Choosing the right hash algorithm is very important to ensure that data is evenly distributed across the tables to avoid excessive concentration of data in some tables and uneven load.
[0111] 402. Perform a hash operation on the shard key using a hash algorithm to obtain a hash value.
[0112] Next, the server can hash the shard key using a hashing algorithm. This process usually involves passing the shard key as input to a hash function, which generates a fixed-length hash value. The hash value is a unique numeric representation of the shard key that helps the server determine where to store the data in subsequent steps.
[0113] For example, if the shard key is a user ID, after being processed by a hash algorithm, a numeric value may be obtained, such as 123456789. This hash value will be used for further shard value calculations.
[0114] 403. According to the table partitioning algorithm, the sharding value is determined using the hash value.
[0115] Finally, the server will use the generated hash value to calculate the specific shard value. This is usually done by some form of mapping of the hash value, which depends on the table partitioning algorithm, such as taking the modulus of the hash value or taking a part of the hash value. The shard value will indicate which shard the data should be stored in.
[0116] For example, if the system has 10 sub-tables (i.e., 10 shards), and when the sub-table algorithm determines the shard value through a modulo operation, the server may obtain an integer from 0 to 9 through the hash value % 10. This integer is the shard value, which determines where the data is stored in "Sub-table 0", "Sub-table 1", etc. It should be noted that if the sub-table algorithm determines the shard value through a modulo operation, then the shard value generally starts from 0 and increases by 1, rather than starting from 1 and increasing by 1. However, if the sub-table algorithm needs to perform additional processing after the modulo operation, the corresponding shard value can be set according to the sub-table algorithm. At this time, the shard value does not necessarily start from 0 and increase by 1. This application does not limit this.
[0117] Through the above steps, the server can accurately map the shard key to the specific shard value, so as to efficiently locate and access data in the distributed database. This process not only ensures the uniform distribution of data, but also improves query performance.
[0118] See also Figure 5 In some embodiments of the present application, the table partitioning method may further include the following steps 501 to 503:
[0119] 501. Receive a push message for updating sub-table configuration sent by the configuration center;
[0120] The main task of this step is to monitor and receive push messages from the configuration center. The configuration center is a component that centrally manages system configuration. It is responsible for managing and updating the configuration of shard tables. When the configuration center detects changes in shard table configuration, it sends push messages to related service instances to notify them to update the configuration. This message may include key information such as the number of new shard tables, changes in hash algorithms, and shard table naming rules.
[0121] 502. Pull the latest sub-table configuration from the configuration center according to the push message;
[0122] After receiving the update push message, the server needs to pull the latest table configuration from the configuration center according to the instructions in the message. This usually involves sending a request to the configuration center to obtain the current configuration information. This step ensures that the server can obtain the latest configuration parameters for use in subsequent data processing and query.
[0123] For example, if the push message indicates that the number of shard tables has changed, the server will request the configuration center to obtain all the newly set shard table information, including the name of each shard table and the corresponding shard key processing rules.
[0124] 503. Use the latest sub-table configuration to update the local sub-table configuration.
[0125] Finally, the server applies the received new sharding configuration to the local configuration. This process includes overwriting or merging the newly acquired sharding data into the existing local configuration. After the update, the server will use these latest configurations for subsequent sharding and query operations to ensure that data processing always complies with the current sharding strategy.
[0126] Updating the local configuration usually also includes verifying the validity of the new configuration to ensure that there are no query failures or data inconsistencies due to configuration errors at runtime.
[0127] In this embodiment, the server can dynamically respond to changes in the sub-table configuration, ensuring the flexibility and scalability of data storage and query. This mechanism is particularly important in distributed systems because the amount of data and access patterns may change over time.
[0128] See also Figure 6 In the embodiment of the present application, one embodiment of the sub-meter device includes:
[0129] The registration unit 601 is used to initiate service registration to the configuration center when the target service is started, so that the configuration center performs permission verification on the target service;
[0130] The pulling unit 602 is used to pull the sub-table configuration from the configuration center after the permission check passes;
[0131] Initialization unit 603, used to initialize the table partitioning algorithm according to the table partitioning configuration;
[0132] The table partitioning unit 604 is used to partition the target table using a table partitioning algorithm to obtain a target partitioned table, where the target table is a data table associated with the target service.
[0133] In this embodiment, when the target service is started, the registration unit 601 needs to register with the configuration center, and the configuration center performs permission verification. If the verification is passed, the pulling unit 602 can pull the sub-table configuration from the configuration center for the target service. Handing over the sub-table configuration to the configuration center for management greatly simplifies the configuration of the sub-table configuration, realizes the sharing of the sub-table configuration, reduces the work of configuring the sub-table configuration, and improves the user experience.
[0134] Optionally, the table division unit 604 includes:
[0135] The acquisition module is used to obtain the sharding start time of the sharding table configuration;
[0136] The table partitioning module is used to partition the target table using a table partitioning algorithm to obtain a target partitioned table whenever the partitioning start time arrives.
[0137] Optionally, the sub-meter device also includes:
[0138] An acquisition unit, configured to acquire, when receiving a service request, an incoming time of the service request and an initial sharding start time of the sharding table configuration;
[0139] A first query unit is used to query the target shard table through the sharding algorithm and service request to obtain a first query result if the input time is later than the initial sharding start time;
[0140] The first responding unit is used to respond to the service request through a first query result.
[0141] Optionally, the first query unit includes:
[0142] A first determination module, used to determine a shard key according to a service request;
[0143] The second determination module is used to determine the shard value using the shard key according to the table sharding algorithm;
[0144] A third determination module is used to determine the sub-table name using the shard value according to the sub-table algorithm;
[0145] The query module is used to query the target sub-table according to the sub-table name to obtain a first query result.
[0146] Optionally, the second determining module is specifically used for:
[0147] Determine the hash algorithm based on the table configuration;
[0148] Use the hash algorithm to perform hash operation on the shard key to obtain the hash value;
[0149] According to the table partitioning algorithm, the shard value is determined using the hash value.
[0150] Optionally, the sub-meter device also includes:
[0151] A second query unit is used to query the target table through a service request to obtain a second query result if the input time is earlier than the initial sharding start time;
[0152] The second responding unit is used to respond to the service request through the second query result.
[0153] Optionally, the meter device further includes an updating unit, and the updating unit is used for:
[0154] Receive push messages from the configuration center to update sub-table configurations;
[0155] Pull the latest sub-table configuration from the configuration center based on the push message;
[0156] Use the latest sharding configuration to update the local sharding configuration.
[0157] See also Figure 7 Another embodiment of the sub-meter device in the embodiment of the present application includes:
[0158] Processor 701, memory 702, input and output unit 703 and bus 704;
[0159] The processor 701 is connected to the memory 702, the input and output unit 703 and the bus 704;
[0160] The memory 702 stores a program, and the processor 701 calls the program to execute Figure 1 to Figure 2 Steps in the illustrated embodiment.
[0161] In this embodiment, the function of the processor 701 is the same as that of the aforementioned Figures 1 to 5 The steps in the illustrated embodiments correspond to each other and will not be described again here.
[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0163] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0164] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0165] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0166] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A table partitioning method, characterized in that: include: When the target service is started, a service registration is initiated to the configuration center so that the configuration center performs permission verification on the target service; When the permission check is passed, the sub-table configuration is pulled from the configuration center; Initialize the table splitting algorithm according to the table splitting configuration; The target table is partitioned using the partitioning algorithm to obtain a target partitioned table, where the target table is a data table associated with the target service.
2. The method according to claim 1, characterized in that The method of using the table partitioning algorithm to partition the target table to obtain the target partitioned table includes: Obtain the sharding start time of the sharding table configuration; Whenever the sharding start time arrives, the target table is sharded using the table sharding algorithm to obtain a target sharded table.
3. The method according to claim 1, characterized in that After the target table is partitioned by the partitioning algorithm, the method further includes: When a service request is received, the incoming time of the service request and the initial sharding start time of the sharding table configuration are obtained; If the incoming time is later than the initial sharding start time, querying the target sharding table through the sharding algorithm and the service request to obtain a first query result; The service request is responded to through the first query result.
4. The method according to claim 3, characterized in that The querying the target sub-table through the sub-table algorithm and the service request to obtain the first query result includes: Determine a shard key according to the service request; According to the table partitioning algorithm, the partitioning key is used to determine the partitioning value; According to the table partitioning algorithm, using the shard value to determine the table partition name; The target sub-table is queried according to the sub-table name to obtain a first query result.
5. The method according to claim 4, characterized in that Determining the shard value by using the shard key according to the table sharding algorithm includes: Determine a hash algorithm according to the sub-table configuration; Performing a hash operation on the shard key using the hash algorithm to obtain a hash value; According to the table partitioning algorithm, the sharding value is determined using the hash value.
6. The method according to claim 3, characterized in that After obtaining the incoming time of the service request and the initial sharding start time of the sharding table configuration, the method further includes: If the incoming time is earlier than the initial sharding start time, querying the target table through the service request to obtain a second query result; The service request is responded to through the second query result.
7. The method according to any one of claims 1 to 6, characterized in that After pulling the sub-table configuration from the configuration center, the method further includes: Receive a push message for updating sub-table configuration sent by the configuration center; Pull the latest sub-table configuration from the configuration center according to the push message; Use the latest sharding configuration to update the local sharding configuration.
8. A meter device, characterized in that: include: A registration unit, used to initiate service registration to a configuration center when a target service is started, so that the configuration center performs permission verification on the target service; A pulling unit, used to pull the sub-table configuration from the configuration center after the permission check passes; An initialization unit, used to initialize a table partitioning algorithm according to the table partitioning configuration; The table partitioning unit is used to partition the target table using the table partitioning algorithm to obtain a target partitioned table, where the target table is a data table associated with the target service.
9. A meter device, characterized in that: include: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; A program is stored in the memory, and the processor calls the program to execute the method according to any one of claims 1 to 7. 10 . A computer-readable storage medium having a program stored thereon, wherein when the program is executed on a computer, the computer is caused to execute the method according to claim 1 .