Database capacity expansion method and device, computer equipment and storage medium
By writing incremental and existing data to the message queue and verifying it when the database is expanded, the problems of service interruption and data loss during database expansion are solved, and non-interrupted expansion and data integrity are achieved.
Patent Information
- Application Number
- CN202411567715.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-18
AI Technical Summary
When expanding the database, the database is divided into different tables, the existing technology needs to suspend the database operation, resulting in service interruption, affecting user access, and may lead to data loss.
When the database is expanded, incremental data is written to the first message queue in real time, existing data is written to the second message queue, and the data of the message queue is written to the database subtable according to the subtable strategy, and data verification is performed to ensure that there is no data loss and the database configuration is adjusted to complete the expansion.
It realizes that the database operation is not required to be suspended when the database is expanded, avoids service interruptions and data loss, and ensures the stability and security of the database operation.
Smart Images

Figure CN119645955A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a database expansion method, device, computer equipment and storage medium. Background Art
[0002] With the continuous development of the Internet era, all walks of life have generated more and more data and information. As an open source relational database, MySQL has been widely used. Usually, in the early stage of business development, MySQL often uses a single table to store data. With the rapid development of the business, the database needs to meet the needs of massive data storage and high throughput, while not affecting the normal operation of the business. In this way, it is necessary to realize the online storage capacity of the single table of the database into sub-libraries and sub-tables. As the business continues to expand, it is necessary to consider expanding the database capacity from sub-libraries and sub-tables to more sub-tables.
[0003] Currently, when expanding the database and sharding the database, you can first stop the database, read the database table data, distribute the database table data to the database shards according to the expansion sharding strategy, and then restart the database service. However, pausing the database to expand the database will interrupt the database service and affect user access. The larger the amount of data, the longer the impact. Therefore, how to ensure the normal operation of the database when expanding the database is a problem that needs to be solved. Summary of the invention
[0004] Based on this, it is necessary to provide a database expansion method, device, computer equipment and storage medium that can ensure the normal operation of the database when expanding the database in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for expanding database capacity, the method comprising:
[0006] Step 1: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information;
[0007] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0008] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0009] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0010] In one embodiment, writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy includes:
[0011] Obtaining database incremental data of the target database, and writing the database incremental data into the first message queue;
[0012] Acquire database inventory data of the target database, and write the database inventory data into a second message queue;
[0013] The queue information of the first message queue and the queue information of the second message queue are written into the database sub-table of the target database according to the sub-table strategy.
[0014] In one embodiment, writing the queue information of the first message queue and the queue information of the second message queue into a database sub-table of the target database according to the sub-table strategy includes:
[0015] Adopt the target sub-table algorithm to establish the database sub-table of the target database according to the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and sub-table quantity;
[0016] Writing the queue information of the second message queue into the database sub-table of the target database according to the sub-table field information, the sub-database name prefix and the sub-table name prefix;
[0017] After the queue information of the second message queue is written into the database sub-table of the target database, the queue information of the first message queue is written into the database sub-table of the target database according to the sub-table field information, the sub-library name prefix and the sub-table name prefix.
[0018] In one embodiment, obtaining database incremental data of a target database and writing the database incremental data into a first message queue includes:
[0019] Determine the database incremental data of the target database according to the database information of the target database; the database information of the target database includes the Internet protocol address, port information, database name, database table name, user name and user password of the target database;
[0020] The database incremental data is written into the first message queue through a data processing tool based on the first queue information corresponding to the first message queue; the first queue information includes the first queue name and the Internet Protocol address of the first queue.
[0021] In one embodiment, obtaining the database inventory data of the target database and writing the database inventory data into the second message queue includes:
[0022] Determine the database inventory data of the target database according to the database information of the target database;
[0023] The database inventory data is written into the second message queue through a data processing tool based on the second queue information corresponding to the second message queue; the second queue information includes the second queue name and the Internet Protocol address of the second queue.
[0024] In one embodiment, data verification is performed on the database sub-table based on the original database table of the target database to determine whether there is data loss, including:
[0025] Determine the amount of sub-table data of the database sub-table according to the sub-table strategy;
[0026] Determine the original database table of the target database according to the database information of the target database, and determine the original table data volume of the original database table;
[0027] Performing data verification on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss;
[0028] If not, the data contents of the original database table and the sub-table of the database are verified based on a message digest algorithm, and whether there is a data error phenomenon is determined according to the verification result.
[0029] In one embodiment, data verification is performed on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss, including:
[0030] Determine the data volume difference between the sub-table data volume and the original table data volume;
[0031] If the data volume difference is less than a preset difference threshold, it is determined that there is no data loss phenomenon in the database sub-table;
[0032] If the data volume difference is greater than or equal to a preset difference threshold, it is determined that data loss exists in the database sub-table.
[0033] In a second aspect, the present application further provides a database expansion device, the device comprising:
[0034] A data consumption module, used to write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy;
[0035] A data verification module is used to perform data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss; if there is data loss, return to execute writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss;
[0036] The service update module is used to adjust the configuration information of the target database based on the table partitioning strategy if there is no data loss, so as to complete the expansion of the target database.
[0037] In a third aspect, the present application further provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program:
[0038] Step 1: writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy;
[0039] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0040] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0041] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0042] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0043] Step 1: writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy;
[0044] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0045] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0046] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0047] The above-mentioned database expansion method, device, computer equipment and storage medium write the incremental database data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and sub-table quantity; the routing rules include the target sub-table algorithm and sub-table field information; the database sub-table is verified based on the original database table of the target database to determine whether there is data loss; if there is data loss, it returns to execute the writing of the incremental database data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss; if there is no data loss, the configuration information of the target database is adjusted based on the sub-table strategy to complete the expansion of the target database. The problem that when the database is expanded with sub-databases and sub-tables, suspending the operation of the database to expand the database with sub-databases and sub-tables will interrupt the database service and affect user access is solved, and the problem that creating a new sub-table for the database and abandoning the use of the original single table of the database to store data may cause data loss. The above scheme, when expanding the capacity of the target database, writes the incremental data of the database into the first message queue in real time, writes the database inventory data into the second message queue, writes the queue information of the first message queue and the queue information of the second message queue into the database sub-table established based on the sub-table strategy according to the sub-table strategy, and performs data verification on the data in the database sub-table. After the verification passes, the configuration information of the target database is adjusted without suspending the operation of the database, and avoids the problem of data loss when expanding the capacity of the database, thereby ensuring the stability and security of the database operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 An application environment diagram of a database expansion method in an embodiment;
[0049] Figure 2 A schematic diagram of a process of a method for expanding database capacity in one embodiment;
[0050] Figure 3 A schematic diagram of a flow chart of a method for expanding database capacity in another embodiment;
[0051] Figure 4 A schematic diagram of a flow chart of a method for expanding database capacity in another embodiment;
[0052] Figure 5 It is a structural block diagram of a database expansion device in one embodiment;
[0053] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0055] The database expansion method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The server 104 writes the database incremental data and the database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; based on the database original table of the target database, the database sub-table is verified to determine whether there is data loss; if there is data loss, it returns to execute the database incremental data and the database inventory data of the target database according to the sub-table strategy to write the database sub-table of the target database until there is no data loss; if there is no data loss, the configuration information of the target database is adjusted based on the sub-table strategy to complete the expansion of the target database, and the database expansion result is sent to the terminal 102 through the communication network. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable device may be a smart watch, a smart bracelet, a head-mounted device, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0056] In one embodiment, Figure 2 As shown, a method for expanding the capacity of a database is provided. This embodiment uses the method applied to a terminal as an example for illustration. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0057] S210: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy.
[0058] The table partitioning strategy includes a table partitioning access address, a sub-library name prefix, a table partitioning name prefix, a routing rule, and the number of table partitions; the routing rule includes a target table partitioning algorithm and table partitioning field information.
[0059] Among them, the table partitioning strategy refers to the strategy for expanding the target database when expanding the target database, which can be preset according to actual needs. The target database is a MySQL database, and the database incremental data refers to the incremental data of MySQL, which refers to the change data and update data generated in the database within a period of time. Database inventory data refers to the database table data that already exists in the target database. The target table partitioning algorithm refers to the algorithm used when partitioning the target database, such as a hash algorithm. The table partitioning field information refers to the field according to which the data in the database is written into the table partition.
[0060] S220, performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss; if there is data loss, returning to S210 and executing until there is no data loss.
[0061] Specifically, the original database table of the target database is obtained, and the data volume of the original database table and the data volume of the database sub-table are determined. The database sub-table is verified according to the data volume of the original database table and the data volume of the database sub-table. Exemplarily, if the data volume of the original database table is consistent with the data volume of the database sub-table, there is no data loss phenomenon in the process of migrating the data from the original database table to the database sub-table in the target database; if the data volume of the original database table is inconsistent with the data volume of the database sub-table, there is data loss phenomenon in the process of migrating the data from the original database table to the database sub-table in the target database.
[0062] S230: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0063] Specifically, if there is no data loss during the process of migrating data in the target database from the original database table to the database sharding table, the configuration information of the target database is adjusted based on the sharding strategy, that is, the configuration-related code information of the target database is modified, and after the configuration information of the target database is adjusted, the adjusted information is published to complete the expansion of the target database.
[0064] In the above database expansion method, the incremental database data and the database inventory data of the target database are written into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, the sub-database name prefix, the sub-table name prefix, the routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and the sub-table field information; the database sub-table is verified based on the original database table of the target database to determine whether there is data loss; if there is data loss, the execution is returned to write the incremental database data and the database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss; if there is no data loss, the configuration information of the target database is adjusted based on the sub-table strategy to complete the expansion of the target database. The problem that when expanding the database with sub-databases and sub-tables, suspending the operation of the database to expand the database with sub-databases and sub-tables will interrupt the database service and affect user access is solved, and the problem that creating a new sub-table for the database and abandoning the use of the original single table of the database to store data may cause data loss is solved. The above scheme, when expanding the capacity of the target database, writes the incremental data of the database into the first message queue in real time, writes the database inventory data into the second message queue, writes the queue information of the first message queue and the queue information of the second message queue into the database sub-table established based on the sub-table strategy according to the sub-table strategy, and performs data verification on the data in the database sub-table. After the verification passes, the configuration information of the target database is adjusted without suspending the operation of the database, and avoids the problem of data loss when expanding the capacity of the database, thereby ensuring the stability and security of the database operation.
[0065] In one embodiment, Figure 3 As shown, writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy includes:
[0066] S310: Obtain database incremental data of the target database, and write the database incremental data into the first message queue.
[0067] Among them, the message queue is a component of the messaging middleware solution, which is designed to support information exchange between independent applications and services.
[0068] Specifically, the incremental data of the target database can be extracted by a data processing tool, and the incremental data of the database can be written into the first message queue. Exemplarily, the data processing tool can be MaxWell, which generally refers to an open source tool for data synchronization and data capture in the field of big data.
[0069] S320: Obtain database inventory data of the target database, and write the database inventory data into the second message queue.
[0070] Specifically, the database inventory data of the target database is extracted through a data processing tool, and the database inventory data is written into the second message queue.
[0071] S330: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy.
[0072] Specifically, the queue information of the second message queue is first written into the database sub-table of the target database according to the sub-table strategy. After all the queue information in the second message queue is written into the database sub-table, the queue information of the first message queue is then written into the database sub-table of the target database according to the sub-table strategy.
[0073] The above scheme first writes the existing data of the target database into the database sub-table of the target database, and then writes the incremental data of the target database into the database sub-table, which can ensure data integrity and avoid data loss.
[0074] In one embodiment, writing the queue information of the first message queue and the queue information of the second message queue into a database sub-table of the target database according to the sub-table strategy includes:
[0075] A target sub-table algorithm is adopted to establish a database sub-table of the target database according to the sub-table access address, the sub-library name prefix, the sub-table name prefix, the routing rules and the number of sub-tables; the queue information of the second message queue is written into the database sub-table of the target database according to the sub-table field information, the sub-library name prefix and the sub-table name prefix; after the queue information of the second message queue is written into the database sub-table of the target database, the queue information of the first message queue is written into the database sub-table of the target database according to the sub-table field information, the sub-library name prefix and the sub-table name prefix.
[0076] Specifically, a database sub-table is established according to the sub-database name prefix, the sub-table name prefix, the target sub-table algorithm and the number of sub-tables; the queue information of the second message queue is written into the database sub-table of the target database according to the target sub-table algorithm, the sub-table field information and the sub-table access address; after all the queue information of the second message queue is written into the database sub-table of the target database, the queue information of the first message queue is written into the database sub-table of the target database according to the target sub-table algorithm, the sub-table field information and the sub-table access address.
[0077] The above solution first writes the existing data of the target database into the database shard table of the target database, and then writes the incremental data of the target database into the database shard table, which can ensure data integrity and avoid data loss in the target database during data migration. The target database is expanded according to the preset sharding strategy, which can achieve the expansion of the target database while ensuring the stable operation of the target database.
[0078] In one embodiment, Figure 4 As shown, obtaining the database incremental data of the target database and writing the database incremental data into the first message queue includes:
[0079] S410: Determine database incremental data of the target database according to database information of the target database.
[0080] The database information of the target database includes the Internet protocol address of the target database, port information, database name, database table name, user name and user password.
[0081] Specifically, ETL (Extract-Transform-Load) meta information of the target database is determined according to the database information of the target database, and database incremental data of the target database is determined according to the ETL meta information of the target database.
[0082] S420. Using a data processing tool, based on first queue information corresponding to the first message queue, write the database incremental data into the first message queue.
[0083] The first queue information includes a first queue name and an Internet Protocol address of the first queue.
[0084] The first queue name refers to the topic name of the first message queue, and the Internet Protocol address of the first queue refers to the IP (Internet Protocol Address) of the first message queue.
[0085] The above solution can accurately extract the incremental data of the target database and write the incremental data into the target message queue.
[0086] In one embodiment, obtaining database inventory data of a target database and writing the database inventory data into a second message queue includes:
[0087] Determine the database inventory data of the target database according to the database information of the target database; write the database inventory data into the second message queue based on the second queue information corresponding to the second message queue through the data processing tool; the second queue information includes the second queue name and the Internet Protocol address of the second queue.
[0088] The second queue name refers to the topic name of the second message queue, and the Internet Protocol address of the second queue refers to the IP address of the second message queue.
[0089] The above solution can accurately extract the stock data of the target database and write the incremental data into the target message queue.
[0090] In one embodiment, data verification is performed on the database sub-table based on the original database table of the target database to determine whether there is data loss, including:
[0091] Determine the amount of sub-table data of the database sub-table according to the table partitioning strategy; determine the original database table of the target database according to the database information of the target database, and determine the amount of original table data of the original database table; perform data verification on the database sub-table according to the amount of sub-table data and the amount of original table data to determine whether there is data loss; if not, perform data content verification on the original database table and the database sub-table based on the message digest algorithm, and determine whether there is data error according to the verification result.
[0092] Specifically, the amount of sub-table data of the database sub-table of the target database is calculated according to the sub-table strategy, and the original table of the target database is determined according to the Internet Protocol address, port information, database name, database table name, user name and user password of the target database, and the amount of original table data of the original table of the database is determined. The database sub-table is verified according to the comparison result of the sub-table data amount and the original table data amount. For example, if the amount of sub-table data is consistent with the amount of original table data, it is determined that there is no data loss phenomenon in the process of migrating the data in the target database from the original table of the database to the sub-table of the database; if the amount of sub-table data is inconsistent with the amount of original table data, it is determined that there is data loss phenomenon in the process of migrating the data in the target database from the original table of the database to the sub-table of the database. If there is no data loss phenomenon, some data in the original table of the database is randomly extracted as verification data, for example, 1 / 1000 data in the original table of the database can be randomly extracted as verification data, and the data combination key of the verification data is determined, and the data combination key includes the sub-table field and the table unique key field. The MD5 (Message-Digest Algorithm version 5) algorithm is used to determine the MD5 value of the verification data, and the data to be verified corresponding to the verification data is obtained from the database sub-table. The MD5 algorithm is used to determine the MD5 value of the data to be verified, and the MD5 value of the verification data is compared with the MD5 value of the data to be verified. If the MD5 value of the verification data is consistent with the MD5 value of the data to be verified, it is determined that there is no data loss phenomenon. If the MD5 value of the verification data is inconsistent with the MD5 value of the data to be verified, it is determined that there is data loss phenomenon.
[0093] The above scheme verifies the data of the database sub-table according to the data volume of the sub-table and the data volume of the original table, which can avoid the problem of data loss when the target database is expanded.
[0094] In one embodiment, data verification is performed on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss, including:
[0095] Determine the data volume difference between the sub-table data volume and the original table data volume; if the data volume difference is less than a preset difference threshold, determine that there is no data loss; if the data volume difference is greater than or equal to the preset difference threshold, determine that there is data loss.
[0096] Specifically, the data volume difference between the data volume of the sub-table and the data volume of the original table is determined; if the data volume difference is less than a preset difference threshold, it is determined that there is no data loss phenomenon in the process of migrating the data in the target database from the original database table to the sub-table of the database. If the data volume difference is greater than or equal to the preset difference threshold, it is determined that there is data loss phenomenon in the process of migrating the data in the target database from the original database table to the sub-table of the database.
[0097] It should be noted that during the expansion of the target database, some invalid data may be cleared during data migration. Therefore, verifying the data in the database shard table based on the difference between the data volume in the shard table and the data volume in the original table can improve the reliability of the verification result.
[0098] Exemplarily, based on the above embodiment, the database expansion method includes:
[0099] Determine the ETL meta information of the target database according to the database information of the target database, and determine the database incremental data of the target database according to the ETL meta information of the target database. Write the database incremental data into the first message queue based on the first queue information corresponding to the first message queue through the data processing tool. Determine the database inventory data of the target database according to the database information of the target database; and write the database inventory data into the second message queue based on the second queue information corresponding to the second message queue through the data processing tool.
[0100] A database sub-table is established according to the sub-database name prefix, the sub-table name prefix, the target sub-table algorithm and the number of sub-tables; the queue information of the second message queue is written into the database sub-table of the target database according to the target sub-table algorithm, the sub-table field information and the sub-table access address; after all the queue information of the second message queue is written into the database sub-table of the target database, the queue information of the first message queue is written into the database sub-table of the target database according to the target sub-table algorithm, the sub-table field information and the sub-table access address.
[0101] The sub-table data volume of the database sub-table of the target database is calculated according to the sub-table strategy, and the original table of the target database is determined according to the Internet Protocol address, port information, database name, database table name, user name and user password of the target database, and the original table data volume of the original table of the database is determined. The data volume difference between the sub-table data volume and the original table data volume is determined; if the data volume difference is less than the preset difference threshold, it is determined that the database sub-table verification is passed, that is, it is determined that there is no data loss phenomenon in the process of migrating the data in the target database from the original database table to the database sub-table; if the data volume difference is greater than or equal to the preset difference threshold, it is determined that the database sub-table verification is not passed, that is, it is determined that there is data loss phenomenon in the process of migrating the data in the target database from the original database table to the database sub-table. If there is no data loss phenomenon, some data in the original database table are randomly extracted as verification data, for example, 1 / 1000 data in the original database table can be randomly extracted as verification data, and the data combination key of the verification data is determined, and the data combination key includes the sub-table field and the table unique key field. The MD5 (Message-Digest Algorithm version 5) algorithm is used to determine the MD5 value of the verification data, and the data to be verified corresponding to the verification data is obtained from the database sub-table. The MD5 algorithm is used to determine the MD5 value of the data to be verified, and the MD5 value of the verification data is compared with the MD5 value of the data to be verified. If the MD5 value of the verification data is consistent with the MD5 value of the data to be verified, it is determined that there is no data loss phenomenon. If the MD5 value of the verification data is inconsistent with the MD5 value of the data to be verified, it is determined that there is data loss phenomenon.
[0102] If data loss occurs during the migration of data in the target database from the original database table to the database sub-table, the database incremental data and database inventory data of the target database are written into the database sub-table of the target database again according to the sub-table strategy.
[0103] If it is determined that there is no data loss in the process of migrating the data in the target database from the original database table to the database sharding table, the configuration information of the target database is adjusted based on the sharding strategy, that is, the configuration-related code information of the target database is modified, and after the configuration information of the target database is adjusted, the adjusted information is published to complete the expansion of the target database.
[0104] In the above database expansion method, the incremental database data and the database inventory data of the target database are written into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, the sub-database name prefix, the sub-table name prefix, the routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and the sub-table field information; the database sub-table is verified based on the original database table of the target database to determine whether there is data loss; if there is data loss, the execution is returned to write the incremental database data and the database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss; if there is no data loss, the configuration information of the target database is adjusted based on the sub-table strategy to complete the expansion of the target database. The problem that when expanding the database with sub-databases and sub-tables, suspending the operation of the database to expand the database with sub-databases and sub-tables will interrupt the database service and affect user access is solved, and the problem that creating a new sub-table for the database and abandoning the use of the original single table of the database to store data may cause data loss is solved. The above scheme, when expanding the capacity of the target database, writes the incremental data of the database into the first message queue in real time, writes the database inventory data into the second message queue, writes the queue information of the first message queue and the queue information of the second message queue into the database sub-table established based on the sub-table strategy according to the sub-table strategy, and performs data verification on the data in the database sub-table. After the verification passes, the configuration information of the target database is adjusted without suspending the operation of the database, and avoids the problem of data loss when expanding the capacity of the database, thereby ensuring the stability and security of the database operation.
[0105] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0106] Based on the same inventive concept, the embodiment of the present application also provides a database expansion device for implementing the above-mentioned database expansion method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more database expansion device embodiments provided below can refer to the limitations of the database expansion method above, and will not be repeated here.
[0107] In one embodiment, Figure 5 As shown, a database expansion device is provided, including: a data consumption module 501, a data verification module 502, and a service update module 503, wherein:
[0108] The data consumption module 510 is used to write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, the sub-database name prefix, the sub-table name prefix, the routing rule and the number of sub-tables; the routing rule includes the target sub-table algorithm and the sub-table field information;
[0109] The data verification module 520 is used to perform data verification on the database sub-table based on the database original table of the target database to determine whether there is data loss; if there is data loss, return to execute writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss;
[0110] The service update module 530 is used to adjust the configuration information of the target database based on the table partitioning strategy if there is no data loss, so as to complete the expansion of the target database.
[0111] Exemplarily, the data consumption module 510 includes an incremental extraction module and a stock extraction module, wherein:
[0112] An incremental extraction module, used to obtain database incremental data of a target database and write the database incremental data into a first message queue;
[0113] A stock extraction module, used for obtaining the database stock data of the target database and writing the database stock data into the second message queue;
[0114] The queue information of the first message queue and the queue information of the second message queue are written into the database sub-table of the target database according to the sub-table strategy.
[0115] Exemplarily, the data consumption module 510 includes an existing message consumption module and an incremental message consumption module, wherein:
[0116] The existing message consumption module is used to use the target table partitioning algorithm to establish the database table of the target database according to the table partitioning access address, database partition name prefix, table partition name prefix, routing rules and the number of table partitions;
[0117] The incremental message consumption module is used to write the queue information of the first message queue into the database sub-table of the target database according to the sub-table field information, the sub-library name prefix and the sub-table name prefix after the queue information of the second message queue is written into the database sub-table of the target database.
[0118] Exemplarily, the data consumption module 510 is further specifically used for:
[0119] Determine the database incremental data of the target database according to the database information of the target database; the database information of the target database includes the Internet protocol address, port information, database name, database table name, user name and user password of the target database;
[0120] By means of a data processing tool, the database incremental data is written into the first message queue based on the first queue information corresponding to the first message queue; the first queue information includes the first queue name and the Internet Protocol address of the first queue.
[0121] The exemplary data consumption module 510 is also specifically used for:
[0122] Determine the database inventory data of the target database according to the database information of the target database;
[0123] The database inventory data is written into the second message queue through a data processing tool based on the second queue information corresponding to the second message queue; the second queue information includes the second queue name and the Internet Protocol address of the second queue.
[0124] Exemplarily, the data verification module 520 is specifically used for:
[0125] Determine the amount of sub-table data of the database sub-table according to the sub-table strategy;
[0126] Determine the original database table of the target database according to the database information of the target database, and determine the original table data volume of the original database table;
[0127] Performing data verification on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss;
[0128] If not, the data content of the original database table and the database sub-table is verified based on the message digest algorithm to determine whether there is any data error based on the verification result.
[0129] Exemplarily, the data verification module 520 is further specifically used for:
[0130] Determine the data volume difference between the sub-table data volume and the original table data volume;
[0131] If the data volume difference is less than a preset difference threshold, it is determined that there is no data loss phenomenon;
[0132] If the data volume difference is greater than or equal to a preset difference threshold, it is determined that data loss exists.
[0133] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a database expansion method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0134] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0135] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0136] Step 1: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information;
[0137] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0138] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0139] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0140] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0141] Step 1: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information;
[0142] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0143] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0144] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0145] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0146] Step 1: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information;
[0147] Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss;
[0148] Step 3: If data loss exists, return to step 1 and continue until data loss does not exist.
[0149] Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
[0150] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0151] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0152] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0153] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for expanding database capacity, characterized in that: include: Step 1: Write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information; Step 2: Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss; Step 3: If data loss exists, return to step 1 and continue until data loss does not exist. Step 4: If there is no data loss, the configuration information of the target database is adjusted based on the table partitioning strategy to complete the expansion of the target database.
2. The method according to claim 1, characterized in that Writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy includes: Obtaining database incremental data of the target database, and writing the database incremental data into the first message queue; Acquire database inventory data of the target database, and write the database inventory data into a second message queue; The queue information of the first message queue and the queue information of the second message queue are written into the database sub-table of the target database according to the sub-table strategy.
3. The method according to claim 2, characterized in that Writing the queue information of the first message queue and the queue information of the second message queue into the database sub-table of the target database according to the sub-table strategy includes: Adopt the target sub-table algorithm to establish the database sub-table of the target database according to the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and sub-table quantity; Writing the queue information of the second message queue into the database sub-table of the target database according to the sub-table field information, the sub-database name prefix and the sub-table name prefix; After the queue information of the second message queue is written into the database sub-table of the target database, the queue information of the first message queue is written into the database sub-table of the target database according to the sub-table field information, the sub-library name prefix and the sub-table name prefix.
4. The method according to claim 2, characterized in that: Acquiring database incremental data of a target database and writing the database incremental data into a first message queue includes: Determine the database incremental data of the target database according to the database information of the target database; the database information of the target database includes the Internet protocol address, port information, database name, database table name, user name and user password of the target database; The database incremental data is written into the first message queue through a data processing tool based on the first queue information corresponding to the first message queue; the first queue information includes the first queue name and the Internet Protocol address of the first queue.
5. The method according to claim 2, characterized in that: Acquiring database inventory data of the target database and writing the database inventory data into the second message queue includes: Determine the database inventory data of the target database according to the database information of the target database; The database inventory data is written into the second message queue through a data processing tool based on the second queue information corresponding to the second message queue; the second queue information includes the second queue name and the Internet Protocol address of the second queue.
6. The method according to claim 1, characterized in that Performing data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss, including: Determine the amount of sub-table data of the database sub-table according to the sub-table strategy; Determine the original database table of the target database according to the database information of the target database, and determine the original table data volume of the original database table; Performing data verification on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss; If not, the data contents of the original database table and the sub-table of the database are verified based on a message digest algorithm, and whether there is a data error phenomenon is determined according to the verification result.
7. The method according to claim 6, characterized in that Performing data verification on the database sub-table according to the data volume of the sub-table and the data volume of the original table to determine whether there is data loss, including: Determine the data volume difference between the sub-table data volume and the original table data volume; If the data volume difference is less than a preset difference threshold, it is determined that there is no data loss phenomenon; If the data volume difference is greater than or equal to a preset difference threshold, it is determined that data loss exists.
8. A database expansion device, characterized in that: The database expansion device comprises: A data consumption module is used to write the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy; the sub-table strategy includes the sub-table access address, sub-database name prefix, sub-table name prefix, routing rules and the number of sub-tables; the routing rules include the target sub-table algorithm and sub-table field information; A data verification module is used to perform data verification on the database sub-table based on the original database table of the target database to determine whether there is data loss; if there is data loss, return to execute writing the database incremental data and database inventory data of the target database into the database sub-table of the target database according to the sub-table strategy until there is no data loss; The service update module is used to adjust the configuration information of the target database based on the table partitioning strategy if there is no data loss, so as to complete the expansion of the target database.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.