[go: up one dir, main page]

CN110858194A - Method and device for expanding database - Google Patents

Method and device for expanding database Download PDF

Info

Publication number
CN110858194A
CN110858194A CN201810936192.5A CN201810936192A CN110858194A CN 110858194 A CN110858194 A CN 110858194A CN 201810936192 A CN201810936192 A CN 201810936192A CN 110858194 A CN110858194 A CN 110858194A
Authority
CN
China
Prior art keywords
database
data
expanded
rule
tables
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810936192.5A
Other languages
Chinese (zh)
Inventor
邹兴生
王彪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810936192.5A priority Critical patent/CN110858194A/en
Publication of CN110858194A publication Critical patent/CN110858194A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据库扩容的方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容;若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表;根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。该方法在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移。

Figure 201810936192

The invention discloses a database expansion method and device, and relates to the technical field of computers. A specific implementation of the method includes: acquiring database monitoring information, and determining whether the database needs to be expanded according to preconfigured expansion rules and the database monitoring information; if the database needs to be expanded, according to the current database classification The slice rule establishes at least one new library table; according to the preset routing read and write rules, the original data and newly added data of the database are respectively written into the corresponding library table; wherein, the library table includes the new library surface. After determining that the database needs to be expanded, the method adds a new database table according to the current database sharding rules, and writes data into the corresponding database table based on the routing read and write rules, and can realize automatic database sharding and data migration without downtime for deployment .

Figure 201810936192

Description

一种数据库扩容的方法和装置Method and device for database expansion

技术领域technical field

本发明涉及计算机领域,尤其涉及一种数据库扩容的方法和装置。The invention relates to the field of computers, and in particular, to a method and device for database expansion.

背景技术Background technique

在开发企业级应用过程中,关系型数据库在大于一定数据量的情况下检索性能会急剧下降。当需要对海量数据进行操作时,如果将所有数据保存在一张数据表中,往往会超出数据表可以存储的阈值,另外,过多的并发请求访问同一个数据库时,数据库的响应也会变慢。现有技术中通过分库分表策略,将并发请求分发到不同的数据库以及数据表中,从而解决了大数据量和高并发所导致的数据库检索性能差和数据库响应慢的问题。In the process of developing enterprise-level applications, the retrieval performance of relational databases will drop sharply when the amount of data is larger than a certain amount. When you need to operate on massive data, if you save all the data in one data table, it will often exceed the threshold that the data table can store. In addition, when too many concurrent requests access the same database, the response of the database will also change. slow. In the prior art, concurrent requests are distributed to different databases and data tables through the strategy of sub-database and sub-table, thereby solving the problems of poor database retrieval performance and slow database response caused by large data volume and high concurrency.

在实现本发明过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art:

(1)在实现分库分表过程中,每次增库增表均需要修改数据库文件,且需要停止服务器的运行并在服务器上重新部署应用,增加了线上业务系统的风险;(1) In the process of implementing sub-database and sub-table, each time adding a database and adding a table needs to modify the database file, and it is necessary to stop the operation of the server and redeploy the application on the server, which increases the risk of the online business system;

(2)增库增表后,原始库表的数据量较大,新库表的数据量较少,导致数据存储不均衡;(2) After the database is added and the table is added, the data volume of the original database table is large, and the data volume of the new database table is small, resulting in unbalanced data storage;

(3)在实现分库分表过程中,需人工进行数据迁移,耗费大量的人力成本,而且在数据迁移过程中还会影响数据的正确性。(3) In the process of implementing sub-database and sub-table, manual data migration is required, which consumes a lot of labor costs, and also affects the correctness of data during the data migration process.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明实施例提供一种数据库扩容的方法和装置,在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移。In view of this, an embodiment of the present invention provides a method and device for database expansion. After determining that the database needs to be expanded, a new database table is added according to the current database fragmentation rules, and data is written into the corresponding database table based on routing read-write rules. , automatic database sharding and data migration can be realized without downtime for deployment.

为实现上述目的,根据本发明实施例的一个方面,提供了一种数据库扩容的方法。To achieve the above object, according to an aspect of the embodiments of the present invention, a method for expanding the capacity of a database is provided.

本发明实施例的一种数据库扩容的方法,包括:获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容;若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表;根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。A method for database expansion according to an embodiment of the present invention includes: acquiring database monitoring information, and determining whether to expand the database according to preconfigured expansion rules and the database monitoring information; if the database needs to be expanded, Then at least one new database table is established according to the current database fragmentation rules; according to the preset routing read and write rules, the original data and newly added data of the database are respectively written into the corresponding library table; wherein, the library table Include the new library table.

可选地,所述数据库监控信息包括下列至少一项:数据存储容量、连接利用率和单表数据量;所述扩容规则包括下列至少一项:当所述数据存储容量大于第一阈值时,需要对所述数据库进行扩容;当所述连接利用率大于第二阈值时,需要对所述数据库进行扩容;以及当所述单表数据量大于第三阈值时,需要对所述数据库进行扩容。Optionally, the database monitoring information includes at least one of the following: data storage capacity, connection utilization, and data volume of a single table; the capacity expansion rule includes at least one of the following: when the data storage capacity is greater than a first threshold, The database needs to be expanded; when the connection utilization rate is greater than the second threshold, the database needs to be expanded; and when the data volume of the single table is greater than the third threshold, the database needs to be expanded.

可选地,数据库分片规则中设置有扩容后的数据库和数据表的数量;所述根据当前数据库分片规则建立至少一个新库表,包括:根据所述数据库的数量、所述数据库中数据表的数量,以及当前数据库分片规则中设置的扩容后的数据库和数据表的数量,新建对应数量的数据库和数据表。Optionally, the database fragmentation rule is provided with the number of expanded databases and data tables; the establishing at least one new database table according to the current database fragmentation rule includes: according to the number of the databases, the data in the database The number of tables, and the number of expanded databases and data tables set in the current database sharding rules, create a corresponding number of databases and data tables.

可选地,所述根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中,包括:根据预设的路由读写规则,确定所述数据库的每条数据所归属的库表;对原始库表中的原始数据进行过滤,将过滤得到的数据写入归属的所述新库表中,记录当前过滤开始时间;判断所述原始数据是否过滤完成,如果未过滤完成,则根据所述当前过滤开始时间和过滤间隔确定下一次过滤开始时间,以继续进行下一次过滤,直至所述原始数据全部过滤完成;将所述新增数据写入到归属的所述库表中。Optionally, according to the preset routing reading and writing rules, the original data and the newly added data of the database are respectively written into the corresponding library tables, including: according to the preset routing reading and writing rules, determining the The library table to which each piece of data in the database belongs; filter the original data in the original library table, write the data obtained by filtering into the new library table of the attribution, and record the current filtering start time; determine whether the original data is The filtering is completed. If the filtering is not completed, the next filtering start time is determined according to the current filtering start time and the filtering interval, so as to continue the next filtering until all the original data are filtered; the newly added data is written into into the attribution of the library table.

可选地,所述路由读写规则基于下述任意一种算法得到:环状哈希算法、散列算法和取模算法。Optionally, the routing read-write rule is obtained based on any one of the following algorithms: a ring hash algorithm, a hash algorithm, and a modulo algorithm.

可选地,所述方法还包括:判断是否扩容成功,如果扩容成功,则更新所述扩容规则。Optionally, the method further includes: judging whether the capacity expansion is successful, and if the capacity expansion is successful, updating the capacity expansion rule.

为实现上述目的,根据本发明实施例的另一方面,提供了一种数据库扩容的装置。To achieve the above object, according to another aspect of the embodiments of the present invention, an apparatus for expanding the capacity of a database is provided.

本发明实施例的一种数据库扩容的装置,包括:判定模块,用于获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容;建立模块,用于若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表;写入模块,用于根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。A database capacity expansion device according to an embodiment of the present invention includes: a determination module for acquiring database monitoring information, and determining whether the database needs to be expanded according to a preconfigured capacity expansion rule and the database monitoring information; a building module for using If the database needs to be expanded, then at least one new database table is established according to the current database fragmentation rules; the writing module is used to convert the original data and newly added data of the database according to the preset routing read and write rules. are respectively written into the corresponding library table; wherein, the library table includes the new library table.

可选地,所述数据库监控信息包括下列至少一项:数据存储容量、连接利用率和单表数据量;所述扩容规则包括下列至少一项:当所述数据存储容量大于第一阈值时,需要对所述数据库进行扩容;当所述连接利用率大于第二阈值时,需要对所述数据库进行扩容;以及当所述单表数据量大于第三阈值时,需要对所述数据库进行扩容。Optionally, the database monitoring information includes at least one of the following: data storage capacity, connection utilization, and data volume of a single table; the capacity expansion rule includes at least one of the following: when the data storage capacity is greater than a first threshold, The database needs to be expanded; when the connection utilization rate is greater than the second threshold, the database needs to be expanded; and when the data volume of the single table is greater than the third threshold, the database needs to be expanded.

可选地,数据库分片规则中设置有扩容后的数据库和数据表的数量;所述建立模块,还用于:根据所述数据库的数量、所述数据库中数据表的数量,以及当前数据库分片规则中设置的扩容后的数据库和数据表的数量,新建对应数量的数据库和数据表。Optionally, the database fragmentation rule is provided with the number of expanded databases and data tables; the establishment module is also used for: according to the number of the databases, the number of data tables in the database, and the current database partition. According to the number of expanded databases and data tables set in the slice rule, create a corresponding number of databases and data tables.

可选地,所述写入模块,还用于:根据预设的路由读写规则,确定所述数据库的每条数据所归属的库表;对原始库表中的原始数据进行过滤,将过滤得到的数据写入归属的所述新库表中,记录当前过滤开始时间;判断所述原始数据是否过滤完成,如果未过滤完成,则根据所述当前过滤开始时间和过滤间隔确定下一次过滤开始时间,以继续进行下一次过滤,直至所述原始数据全部过滤完成;以及将所述新增数据写入到归属的所述库表中。Optionally, the writing module is further configured to: determine the library table to which each piece of data in the database belongs according to a preset routing read-write rule; filter the original data in the original library table, and filter the The obtained data is written in the described new library table of attribution, and the current filtering start time is recorded; it is judged whether the filtering of the original data is completed, if not, the next filtering start time is determined according to the current filtering start time and the filtering interval. time, so as to continue the next filtering until all the filtering of the original data is completed; and write the newly added data into the attributable library table.

可选地,所述路由读写规则基于下述任意一种算法得到:环状哈希算法、散列算法和取模算法。Optionally, the routing read-write rule is obtained based on any one of the following algorithms: a ring hash algorithm, a hash algorithm, and a modulo algorithm.

可选地,所述装置还包括:更新模块,用于判断是否扩容成功,如果扩容成功,则更新所述扩容规则。Optionally, the apparatus further includes: an update module configured to determine whether the capacity expansion is successful, and if the capacity expansion is successful, update the capacity expansion rule.

为实现上述目的,根据本发明实施例的再一方面,提供了一种电子设备。To achieve the above object, according to yet another aspect of the embodiments of the present invention, an electronic device is provided.

本发明实施例的一种电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种数据库扩容的方法。An electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, The one or more processors are caused to implement a method for expanding the capacity of a database according to an embodiment of the present invention.

为实现上述目的,根据本发明实施例的再一方面,提供了一种计算机可读介质。To achieve the above object, according to yet another aspect of the embodiments of the present invention, a computer-readable medium is provided.

本发明实施例的一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种数据库扩容的方法。A computer-readable medium according to an embodiment of the present invention stores a computer program thereon, and when the program is executed by a processor, a method for expanding a database according to an embodiment of the present invention is implemented.

上述发明中的一个实施例具有如下优点或有益效果:在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移;根据业务需求预先配置扩容规则所包含的内容,在数据库监控信息满足所述扩容规则后触发扩容处理过程,以实现自动扩容;根据当前数据库分片规则中设置的数据库和数据表的数量、以及当前业务系统对应的数据库数量和数据表数量新建数据库和数据表,实现了自动增库增表;基于路由读写规则,确定所述数据库的每条数据所归属的库表,根据确定的库表进行过滤复制实现自动数据迁移;通过环状哈希算法实现路由读写规则,能够保证数据均衡分配到每个库表中;通过更新扩容规则,以正确、方地便判定扩容后的数据库是否需要再次进行扩容处理。One embodiment of the above invention has the following advantages or beneficial effects: after it is determined that the database needs to be expanded, a new database table is added according to the current database fragmentation rules, and data is written into the corresponding database table based on routing read-write rules, without downtime Deployment can realize automatic sub-database sub-table and data migration; pre-configure the content contained in the expansion rules according to business requirements, and trigger the expansion process after the database monitoring information satisfies the expansion rules to realize automatic expansion; according to the current database fragmentation The number of databases and data tables set in the rules, as well as the number of databases and data tables corresponding to the current business system, create new databases and data tables, and realize automatic database and table addition; based on routing read and write rules, determine each entry in the database The database table to which the data belongs is filtered and copied according to the determined database table to realize automatic data migration; the routing read and write rules are implemented through the ring hash algorithm, which can ensure the balanced distribution of data to each database table; Correctly and conveniently determine whether the expanded database needs to be expanded again.

上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.

附图说明Description of drawings

附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:

图1是根据本发明实施例的数据库扩容的方法的主要步骤的示意图;1 is a schematic diagram of main steps of a method for database expansion according to an embodiment of the present invention;

图2是根据本发明实施例的数据库扩容的方法的主要流程示意图;FIG. 2 is a schematic flowchart of a main flow of a method for database expansion according to an embodiment of the present invention;

图3是本发明实施例的由四库四表裂变为四库八表的裂变前结果示意图;3 is a schematic diagram of the results before fission from four libraries and four tables to four libraries and eight tables according to an embodiment of the present invention;

图4是本发明实施例的由四库四表裂变为四库八表的裂变后结果示意图;4 is a schematic diagram of the results after fission from four libraries and four tables to four libraries and eight tables according to an embodiment of the present invention;

图5为本发明实施例的由四库四表裂变为八库八表的裂变后结果示意图;5 is a schematic diagram of the results after fission from four pools and four tables to eight pools and eight tables according to an embodiment of the present invention;

图6是本发明实施例的将数据库的原始数据和新增数据写入到对应的库表的主要步骤示意图;6 is a schematic diagram of the main steps of writing original data and newly added data of a database into a corresponding library table according to an embodiment of the present invention;

图7为本发明实施例的将从数据表中的数据写入新库表的实现原理示意图;7 is a schematic diagram of an implementation principle of writing data from a data table into a new library table according to an embodiment of the present invention;

图8是本发明实施例的数据库扩容的装置的主要模块的示意图;8 is a schematic diagram of main modules of an apparatus for database expansion according to an embodiment of the present invention;

图9是本发明实施例的数据库扩容系统的主要模块的示意图;9 is a schematic diagram of main modules of a database capacity expansion system according to an embodiment of the present invention;

图10本发明实施例可以应用于其中的示例性系统架构图;FIG. 10 is an exemplary system architecture diagram to which an embodiment of the present invention can be applied;

图11是适用于来实现本发明实施例的电子设备的计算机装置的结构示意图。FIG. 11 is a schematic structural diagram of a computer device suitable for implementing the electronic device according to the embodiment of the present invention.

具体实施方式Detailed ways

以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.

图1是根据本发明实施例的数据库扩容的方法的主要步骤的示意图。如图1所示,本发明实施例的数据库扩容的方法,主要包括如下步骤:FIG. 1 is a schematic diagram of main steps of a method for database expansion according to an embodiment of the present invention. As shown in FIG. 1 , the method for database expansion according to the embodiment of the present invention mainly includes the following steps:

步骤S101:获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容。其中,所述数据库监控信息包括下列至少一项:数据存储容量、连接利用率和单表数据量;所述扩容规则包括下列至少一项:当所述数据存储容量大于第一阈值时,需要对所述数据库进行扩容;当所述连接利用率大于第二阈值时,需要对所述数据库进行扩容;以及当所述单表数据量大于第三阈值时,需要对所述数据库进行扩容。当数据库监控信息满足上述任一项扩容规则后触发步骤S102的扩容处理过程。Step S101: Obtain database monitoring information, and determine whether the database needs to be expanded according to a preconfigured expansion rule and the database monitoring information. Wherein, the database monitoring information includes at least one of the following: data storage capacity, connection utilization, and data volume of a single table; the capacity expansion rule includes at least one of the following: when the data storage capacity is greater than a first threshold, it is necessary to The database is expanded; when the connection utilization rate is greater than the second threshold, the database needs to be expanded; and when the data volume of the single table is greater than the third threshold, the database needs to be expanded. When the database monitoring information satisfies any of the above-mentioned expansion rules, the expansion process of step S102 is triggered.

步骤S102:若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表。所述当前数据库分片规则设置有扩容后的数据库的数量和数据表的数量。根据所述数据库的数量、所述数据库中数据表的数量,以及当前数据库分片规则中设置的扩容后的数据库的数量和数据表的数量,新建对应数量的数据库和数据表。比如,假设原来是两库两表,当前数据库分片规则中需要扩容为两库四表,则新建两个数据表;假设原来是两库两表,当前数据库分片规则中需要扩容为四库四表,则新建两个数据库和两个数据表。Step S102: If the database needs to be expanded, at least one new database table is established according to the current database fragmentation rules. The current database fragmentation rule is set with the number of expanded databases and the number of data tables. According to the number of databases, the number of data tables in the database, and the number of expanded databases and the number of data tables set in the current database sharding rule, a corresponding number of databases and data tables are newly created. For example, assuming the original two databases and two tables, the current database sharding rules need to expand to two databases and four tables, then create two new data tables; assuming the original two databases and two tables, the current database sharding rules need to be expanded to four databases Four tables, then create two new databases and two data tables.

步骤S103:根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。所述路由读写规则基于下述任意一种算法得到:环状哈希算法、散列算法和取模算法。具体写入过程为:根据预设的路由读写规则,确定所述数据库的每条数据所归属的库表;对原始库表中的原始数据进行过滤,将过滤得到的数据写入归属的所述新库表中,记录当前过滤开始时间;判断所述原始数据是否过滤完成,如果未过滤完成,则根据所述当前过滤开始时间和过滤间隔确定下一次过滤开始时间,以继续进行下一次过滤,直至所述原始数据全部过滤完成;将所述新增数据写入到归属的所述库表中。记录当前过滤开始时间能够保证数据迁移过程中的正确性。Step S103: Write the original data and the newly added data of the database into the corresponding library table respectively according to the preset routing reading and writing rules; wherein, the library table includes the new library table. The routing read-write rule is obtained based on any one of the following algorithms: a ring hash algorithm, a hash algorithm and a modulo algorithm. The specific writing process is as follows: according to the preset routing read and write rules, determine the library table to which each piece of data in the database belongs; filter the original data in the original library table, and write the filtered data into the home table. In the new library table, record the current filtering start time; determine whether the original data is filtered and complete, if not, then determine the next filtering start time according to the current filtering start time and the filtering interval, to continue the next filtering , until all the original data is filtered; write the newly added data into the attributable library table. Recording the current filtering start time can ensure the correctness of the data migration process.

图2是根据本发明实施例的数据库扩容的方法的主要流程示意图。如图2所示,本发明实施例的数据库扩容的方法,主要包括如下步骤:FIG. 2 is a schematic flowchart of a main flow of a method for database expansion according to an embodiment of the present invention. As shown in FIG. 2, the method for database expansion according to the embodiment of the present invention mainly includes the following steps:

步骤S201:将数据库信息和业务系统信息存储到管理控制平台,并在所述管理控制平台配置扩容规则和数据库分片规则。其中,数据库信息包括域名、端口号、用户名和密码。所述业务系统信息包括业务系统基础信息和配置信息,所述业务系统基础信息包括业务系统标识(比如全局唯一的英文名)、中文名、隶属部门、研发负责人、联系电话、邮箱和项目组成员列表;所述配置信息用于配置数据库和数据表,包括业务系统标识(比如全局唯一的英文名)、域名、用户名和密码。所述数据库分片规则中设置有扩容后的数据库的数量和数据表的数量。Step S201: Store database information and business system information in a management and control platform, and configure expansion rules and database fragmentation rules on the management and control platform. The database information includes domain name, port number, user name and password. The business system information includes business system basic information and configuration information, and the business system basic information includes business system identifiers (such as globally unique English names), Chinese names, affiliation departments, R&D leaders, contact numbers, email addresses, and project teams. Member list; the configuration information is used to configure databases and data tables, including business system identifiers (such as globally unique English names), domain names, user names and passwords. The number of expanded databases and the number of data tables are set in the database fragmentation rule.

所述扩容规则包括下列至少一项:当所述数据存储容量大于第一阈值时,需要对所述数据库进行扩容;当所述连接利用率大于第二阈值时,需要对所述数据库进行扩容;以及当所述单表数据量大于第三阈值时,需要对所述数据库进行扩容。其中,所述第一阈值可以是数据最大存储容量乘以预设第一比例,比如数据最大存储容量为10G,第一比例为80%,则第一阈值为8G;所述第二阈值可以是最大连接数或者当前连接数乘以预设第二比例,比如最大连接数为100,第二比例为80%,则第二阈值为80;所述第三阈值可以是单表最大数据量乘以预设第三比例,比如单表最大数据量为500W条数据,第三比例为80%,则第三阈值为400W条数据。其中,第一比例、第二比例和第三比例根据实际需求确定,三者可以相同,可以不同。The capacity expansion rule includes at least one of the following: when the data storage capacity is greater than a first threshold, the database needs to be expanded; when the connection utilization rate is greater than a second threshold, the database needs to be expanded; And when the amount of data in the single table is greater than the third threshold, the database needs to be expanded. The first threshold may be the maximum data storage capacity multiplied by a preset first ratio. For example, if the maximum data storage capacity is 10G and the first ratio is 80%, the first threshold may be 8G; the second threshold may be The maximum number of connections or the current number of connections is multiplied by a preset second ratio. For example, if the maximum number of connections is 100 and the second ratio is 80%, the second threshold is 80; the third threshold may be the maximum data volume of a single table multiplied by The third ratio is preset, for example, the maximum data volume of a single table is 500W pieces of data, and the third ratio is 80%, then the third threshold is 400W pieces of data. The first ratio, the second ratio and the third ratio are determined according to actual needs, and the three may be the same or different.

步骤S202:所述管理控制平台将所述数据库信息和所述数据库分片规则同步至数据注册中心,将所述数据库信息和所述扩容规则同步至数据监控中心。实施例中,业务系统从配置节点中获取配置信息,以将所述配置信息存储至数据注册中心。业务系统监听所述配置信息,如果所述配置信息发生修改,则将修改后的配置信息存储至数据注册中心。其中,所述配置节点可使用Zookeeper(是一种分布式的,开放源码的分布式应用程序协调服务)、Etcd(是一个分布式的键值存储系统)等实现,所述配置信息包括数据库信息和数据库分片规则。Step S202: The management control platform synchronizes the database information and the database fragmentation rules to a data registration center, and synchronizes the database information and the expansion rules to a data monitoring center. In an embodiment, the service system acquires configuration information from the configuration node, so as to store the configuration information in the data registration center. The business system monitors the configuration information, and if the configuration information is modified, stores the modified configuration information in the data registration center. The configuration node can be implemented using Zookeeper (a distributed, open source distributed application coordination service), Etcd (a distributed key-value storage system), etc., and the configuration information includes database information and database sharding rules.

配置信息修改后,配置节点会将最新的配置信息同步到配置中心。每次业务系统的应用会监听配置中心的通知,当监听发生变化后,会将修改后的配置信息同步到本地缓存,达到不重启就可以刷新配置信息的目的,进而可以动态增减数据库和修改数据库分片规则。After the configuration information is modified, the configuration node will synchronize the latest configuration information to the configuration center. Every time the application of the business system will listen to the notification of the configuration center, when the monitoring changes, the modified configuration information will be synchronized to the local cache, so that the configuration information can be refreshed without restarting, and then the database can be dynamically increased or decreased and modified Database sharding rules.

步骤S203:启动业务系统的应用,以从所述数据注册中心获取所述业务系统对应的数据库信息和数据库分片规则。应用启动后,需判断获取的数据库信息和数据库分片规则是否正确,即判断应用启动是否有异常,是否能够正常访问数据库,如果应用启动正常且能够正常访问数据库,则说明获取的数据正确。在一优选的实施例中,在应用刚部署到业务系统时,业务系统需从数据注册中心拉取配置信息。Step S203: Start the application of the business system to obtain the database information and database fragmentation rules corresponding to the business system from the data registration center. After the application starts, it is necessary to judge whether the obtained database information and database sharding rules are correct, that is, whether the application starts abnormally and whether it can access the database normally. If the application starts normally and can access the database normally, it means that the obtained data is correct. In a preferred embodiment, when the application is just deployed to the business system, the business system needs to pull the configuration information from the data registration center.

步骤S204:所述管理控制平台通过所述数据监控中心监控数据库。数据监控中心按照管理控制平台中设置的第一至第三阈值,分别监控数据库的数据存储容量、连接利用率和单表数据量,将监控得到的数据库监控信息反馈至管理控制平台。数据监控中心监控的内容不限于上述三种,具体监控内容由用户确定,比如还可以监控数据库性能、服务器性能等。Step S204: the management control platform monitors the database through the data monitoring center. According to the first to third thresholds set in the management control platform, the data monitoring center monitors the data storage capacity, connection utilization rate and single-table data volume of the database respectively, and feeds back the database monitoring information obtained by monitoring to the management control platform. The content monitored by the data monitoring center is not limited to the above three, and the specific monitoring content is determined by the user, such as database performance, server performance, etc. can also be monitored.

步骤S205:所述管理控制平台根据监控得到的数据库监控信息和所述扩容规则,判定是否需要对所述数据库进行扩容,如果不需要,则执行步骤S204;如果需要,则执行步骤S206。当数据库的数据存储容量大于第一阈值,或者连接利用率大于第二阈值,或者单表数据量大于第三阈值时,说明需要对所述数据库进行扩容。Step S205: The management control platform determines whether the database needs to be expanded according to the database monitoring information obtained by monitoring and the capacity expansion rule, and if not, executes step S204; if necessary, executes step S206. When the data storage capacity of the database is greater than the first threshold, or the connection utilization rate is greater than the second threshold, or the data volume of a single table is greater than the third threshold, it indicates that the database needs to be expanded.

步骤S206:所述管理控制平台暂停对所述数据库的监控,根据新数据库分片规则建立至少一个新库表。其中,所述新数据库分片规则即当前数据库分片规则,需从配置信息中获取。所述根据当前数据库分片规则建立至少一个新库表,包括:根据所述数据库的数量、所述数据库中数据表的数量,以及当前数据库分片规则中设置的扩容后的数据库的数量和数据表的数量,新建对应数量的数据库和数据表。比如,假设原来是两库两表,扩容后为两库四表,则需要新建两个数据表;假设原来是两库两表,扩容后为四库四表,则需要新建两个数据库和两个数据表。Step S206: The management control platform suspends monitoring of the database, and establishes at least one new database table according to the new database fragmentation rule. Wherein, the new database fragmentation rule, that is, the current database fragmentation rule, needs to be obtained from the configuration information. The establishment of at least one new database table according to the current database fragmentation rule includes: according to the number of the database, the number of data tables in the database, and the number and data of the expanded database set in the current database fragmentation rule The number of tables, create a corresponding number of databases and data tables. For example, if the original two databases and two tables are expanded into two databases and four tables, then two new data tables need to be created; if the original two databases and two tables are expanded into four databases and four tables, then two new databases and two new data tables need to be created. data table.

所述新数据库分片规则中涉及三种裂变方式:数据表的裂变、数据库库的裂变以及库表均发生裂变。其中,裂变是指数据从一个源头分流至多个源头。所述数据表的裂变适用于数据量大,且数据并发量能够满足当前业务场景的情况;所述数据库库的裂变适用于数据并发量不能够满足当前业务场景的情况;所述库表均发生裂变适用于数据量大,且数据并发量不能够满足当前业务场景的情况。具体采用哪种方式进行裂变需根据数据量和数据并发量来确定,裂变产生的数据库和数据表的数量可以根据业务需求自行定义。The new database fragmentation rules involve three fission modes: fission of data table, fission of database library, and fission of library table. Among them, fission refers to the shunting of data from one source to multiple sources. The fission of the data table is suitable for the situation that the amount of data is large, and the data concurrency can meet the current business scenario; the fission of the database database is suitable for the situation that the data concurrency cannot meet the current business scenario; the database table all occurs Fission is suitable for situations where the amount of data is large and the amount of data concurrency cannot meet the current business scenario. The specific method for fission should be determined according to the amount of data and the amount of data concurrency. The number of databases and data tables generated by fission can be defined according to business needs.

所述数据量大是指当前数据量大于预设第三阈值,比如第三阈值为500W条数据,如果当前数据量大于500W条数据,则进行数据表的裂变。图3和图4分别为本发明实施例的由四库四表裂变为四库八表的裂变前后结果。如图3所示,裂变前的四个数据库分别为DB1-DB4,每个数据库有四个数据表分别为Tb0-Tb3。数据表的裂变后,如图4所示,数据库不变,每个数据库有八个数据表分别为Tb0-Tb7。The large amount of data means that the current amount of data is greater than the preset third threshold. For example, the third threshold is 500W pieces of data. If the current amount of data is greater than 500W pieces of data, fission of the data table is performed. FIG. 3 and FIG. 4 are respectively the results before and after the fission from four libraries and four tables to four libraries and eight tables according to an embodiment of the present invention. As shown in Figure 3, the four databases before fission are DB1-DB4, and each database has four data tables, Tb0-Tb3. After the fission of the data table, as shown in Figure 4, the database remains unchanged, and each database has eight data tables respectively Tb0-Tb7.

所述数据并发量能够满足当前业务场景是指当前数据并发量(对应于连接利用率)大于第二阈值,比如第二阈值为500,如果当前数据并发量大于500,则进行数据库的裂变。图5为本发明实施例的由四库四表裂变为八库八表的裂变后结果。裂变前的四库四表仍旧如图3所示,包括DB1-DB4共四个数据库、每个数据库有Tb0-Tb3共四个数据表。数据库的裂变后,如图5所示,数据库增加四个,即共八个数据库分别为DB1-DB8,每个数据库有Tb0-Tb3共四个数据表。The data concurrency amount that can satisfy the current business scenario means that the current data concurrency amount (corresponding to the connection utilization rate) is greater than the second threshold, for example, the second threshold is 500. If the current data concurrency amount is greater than 500, the database is fissioned. FIG. 5 is the result of fission from four pools and four tables to eight pools and eight tables according to an embodiment of the present invention. The four databases and four tables before fission are still as shown in Figure 3, including four databases DB1-DB4, and four data tables Tb0-Tb3 in each database. After the fission of the database, as shown in Figure 5, four databases are added, that is, a total of eight databases are DB1-DB8, and each database has a total of four data tables Tb0-Tb3.

步骤S207:所述管理控制平台根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中。其中,所述库表包括原始库表和所述新库表。下面以路由读写规则基于环状哈希算法得到为例进行说明。所述环状哈希算法的实现原理为:通过哈希函数计算原始数据、新增数据和数据库的键值(Key),将原始数据和新增数据的Key以及数据库的Key分别映射到一个2^32的环上;之后从原始数据和新增数据的Key在环上的位置顺时针查找,把该Key存储到第一个数据库上。上述算法将数据库按顺时针方向均匀的分布在这个环上,原始数据和新增数据的Key将会归属于该环上的某个数据库。该算法的核心代码如下:Step S207: The management and control platform respectively writes the original data and the newly added data of the database into the corresponding library table according to the preset routing read and write rules. Wherein, the library table includes the original library table and the new library table. The following is an example of how the routing read and write rules are obtained based on the ring hash algorithm. The realization principle of the ring hash algorithm is: calculate the key value (Key) of the original data, the new data and the database through the hash function, and map the Key of the original data and the new data and the Key of the database to a 2 respectively. On the ring of ^32; then search clockwise from the position of the key of the original data and the new data on the ring, and store the key in the first database. The above algorithm evenly distributes the databases on the ring in a clockwise direction, and the keys of the original data and the new data will belong to a database on the ring. The core code of the algorithm is as follows:

Figure BDA0001767898620000101
Figure BDA0001767898620000101

Figure BDA0001767898620000111
Figure BDA0001767898620000111

步骤S208:所述管理控制平台判断是否扩容成功,如果否,则执行步骤S209;如果是,则执行步骤S211。管理控制平台在扩容过程中会记录可回滚时间点,如果扩容未成功,可通过回滚机制,将所述数据库的原始数据恢复到可回滚时间点,以重新进行扩容。Step S208: The management control platform determines whether the expansion is successful, and if not, executes step S209; if yes, executes step S211. The management control platform will record the rollback time point during the expansion process. If the expansion is unsuccessful, the original data of the database can be restored to the rollback time point through the rollback mechanism to re-expand the capacity.

步骤S209:所述管理控制平台通过回滚机制,将所述数据库的原始数据恢复到可回滚时间点,执行步骤S210。Step S209: The management control platform restores the original data of the database to a rollbackable time point through a rollback mechanism, and executes step S210.

步骤S210:所述管理控制平台将所述回滚时间点对应的原始数据重新写入到对应的新库表中,执行步骤S208。Step S210: The management control platform rewrites the original data corresponding to the rollback time point into the corresponding new library table, and executes step S208.

步骤S211:所述管理控制平台更新所述扩容规则得到新扩容规则,将所述新数据库分片规则同步至所述数据注册中心,将所述新扩容规则同步至所述数据监控中心。经过扩容处理后,数据库的数据存储容量和/或最大连接值会增加,因此需更新扩容规则中的第一阈值和/或第二阈值。Step S211: The management control platform updates the expansion rules to obtain new expansion rules, synchronizes the new database fragmentation rules to the data registration center, and synchronizes the new expansion rules to the data monitoring center. After the expansion process, the data storage capacity and/or the maximum connection value of the database will increase, so the first threshold and/or the second threshold in the expansion rule need to be updated.

步骤S212:所述业务系统从所述数据注册中心中拉取所述新数据分片规则,以根据所述新数据分片规则向扩容后的所述数据库发起访问。通过上述处理完成了数据的自动监控、自动扩容、自动数据迁移、无需重新部署应用,降低了维护成本,提升了研发效率和业务处理能力。Step S212: The business system pulls the new data fragmentation rule from the data registration center to initiate access to the expanded database according to the new data fragmentation rule. Through the above processing, automatic data monitoring, automatic expansion, automatic data migration, and no need to redeploy applications are completed, maintenance costs are reduced, and R&D efficiency and business processing capabilities are improved.

图6是本发明实施例的将数据库的原始数据和新增数据写入到对应的库表的主要步骤示意图。如图6所示,步骤S207包括:FIG. 6 is a schematic diagram of main steps for writing original data and newly added data of a database into a corresponding library table according to an embodiment of the present invention. As shown in Figure 6, step S207 includes:

步骤S601:根据预设的路由读写规则,确定所述数据库的每条数据所归属的库表。以一个主数据表、两个从数据表的MySQL(是一种开放源代码的关系型数据库管理系统)数据库为例,将主数据表的其中一个从数据表进行下线处理,对所述下线后的从数据表按照路由读写规则,确定该从数据表中每条数据所归属的库表。Step S601: Determine the library table to which each piece of data in the database belongs according to a preset routing read-write rule. Taking a MySQL (which is an open-source relational database management system) database with one master data table and two slave data tables as an example, one of the slave data tables of the master data table is offline processed, and the slave data table of the master data table is processed offline. The slave data table after the line determines the library table to which each data in the slave data table belongs according to the routing read and write rules.

步骤S602:对原始库表中的原始数据进行过滤,将过滤得到的数据写入归属的所述新库表中,记录当前过滤开始时间。根据确定好的库表,从从数据表中过滤出相应的数据并复制到新库表中,并删除从数据表中原来的数据,以保持数据的一致性。Step S602: Filter the original data in the original library table, write the filtered data into the new library table to which it belongs, and record the current filtering start time. According to the determined library table, filter the corresponding data from the data table and copy it to the new library table, and delete the original data from the data table to maintain the consistency of the data.

图7为本发明实施例的将从数据表中的数据写入新库表的实现原理示意图。如图7所示,假设有两个数据库DB0和DB1,DB0中有主数据表Tb00和Tb01,主数据表Tb00有两个从数据表Tb0,主数据表Tb01有两个从数据表Tb1;DB1中有主数据表Tb00和Tb01,主数据表Tb00有两个从数据表Tb0,主数据表Tb01有两个从数据表Tb1。根据业务需求需要将两库两表扩充为两库四表,即将DB0扩充为四个数据表Tb0、Tb1、Tb2、Tb3;将DB1扩充为四个数据表Tb0、Tb1、Tb2、Tb3。将每个主数据表的其中一个从数据表进行下线处理后,将该从数据表的数据过滤复制到DB0和DB1的数据表中。FIG. 7 is a schematic diagram of an implementation principle of writing data from a data table into a new library table according to an embodiment of the present invention. As shown in Figure 7, suppose there are two databases DB0 and DB1, DB0 has master data tables Tb00 and Tb01, master data table Tb00 has two slave data tables Tb0, and master data table Tb01 has two slave data tables Tb1; DB1 There are master data tables Tb00 and Tb01, the master data table Tb00 has two slave data tables Tb0, and the master data table Tb01 has two slave data tables Tb1. According to business requirements, the two databases and two tables need to be expanded into two databases and four tables, that is, DB0 is expanded into four data tables Tb0, Tb1, Tb2, Tb3; DB1 is expanded into four data tables Tb0, Tb1, Tb2, Tb3. After one of the slave data tables of each master data table is offline processed, the data of the slave data table is filtered and copied to the data tables of DB0 and DB1.

步骤S603:判断所述原始数据是否全部过滤完成,如果是,则结束本流程;如果不是,则根据所述当前过滤开始时间和过滤间隔确定下一次过滤开始时间,以继续进行下一次过滤,直至所述原始数据全部过滤完成。过滤完成时,所述库表中的数据与所述原始数据和新增数据相一致。实施例中,过滤完成后,将下线的从数据库表重新上线,并从对应的主数据表中同步数据。Step S603: Determine whether all the filtering of the original data is completed, and if so, end the process; if not, determine the next filtering start time according to the current filtering start time and filtering interval, so as to continue the next filtering until All the raw data are filtered. When the filtering is completed, the data in the library table is consistent with the original data and the newly added data. In the embodiment, after the filtering is completed, the offline slave database table is brought back online, and data is synchronized from the corresponding master data table.

步骤S604:将所述新增数据写入到归属的所述库表中。本实施例中步骤S604用于把新增数据写入到对应的库表,步骤S602至步骤S603用于把原始数据迁移到对应的新库表中,实施例中并不限定步骤S604的执行顺序,其可以在步骤S601与步骤S602之间执行。Step S604: Write the newly added data into the attributable library table. In this embodiment, step S604 is used to write the newly added data into the corresponding library table, and steps S602 to S603 are used to migrate the original data to the corresponding new library table. The embodiment does not limit the execution order of step S604 , which can be executed between step S601 and step S602.

假设业务系统的应用根据订单标识(orderId)将订单数据初始化到两库两表中,因业务发展的需要,需将库表扩展为两库四表。下面以环状哈希算法为例,对上例中如何将数据库的原始数据和新增数据写入到对应的库表的原理进行说明。It is assumed that the application of the business system initializes the order data into two tables and two databases according to the order ID (orderId). Due to the needs of business development, the database tables need to be expanded into two databases and four tables. Taking the ring hash algorithm as an example, the principle of how to write the original data and newly added data of the database into the corresponding database table in the above example will be described.

假设有16条订单数据,每条订单数据的末尾两位数编号分别为00、01、……、15,经环状哈希算法,将订单数据初始化到两库两表中所得到的分配结果如表1所示,将订单数据写入到两库四表中所得到的分配结果如表2所示(下述分配结果中每个订单数据平均分布,只是为了方便说明,实际分配结果经环状哈希算法即可得出)。Suppose there are 16 pieces of order data, and the last two-digit numbers of each order data are 00, 01, . As shown in Table 1, the distribution results obtained by writing the order data into the two databases and four tables are shown in Table 2 (each order data in the following distribution results is evenly distributed, just for the convenience of description, the actual distribution results are can be obtained by the hash algorithm).

表1为两库两表的订单数据分配结果Table 1 shows the order data allocation results of two databases and two tables

库名library name 表名Table Name orderIdorderId DB0DB0 Table_00Table_00 00、04、08、1200, 04, 08, 12 DB0DB0 Table_01Table_01 01、05、09、1301, 05, 09, 13 DB1DB1 Table_00Table_00 02、06、10、1402, 06, 10, 14 DB1DB1 Table_01Table_01 03、07、11、1503, 07, 11, 15

表2为两库四表的订单数据分配结果Table 2 shows the order data allocation results of two databases and four tables

库名library name 表名Table Name orderIdorderId DB0DB0 Table_00Table_00 00、0800, 08 DB0DB0 Table_01Table_01 01、0901, 09 DB0DB0 Table_02Table_02 02、1002, 10 DB0DB0 Table_03Table_03 03、1103, 11 DB1DB1 Table_00Table_00 04、1204, 12 DB1DB1 Table_01Table_01 05、1305, 13 DB1DB1 Table_02Table_02 06、1406, 14 DB1DB1 Table_03Table_03 07、1507, 15

但是在将原始库表的原始数据全部迁移完成之前,会存在插入新数据的情况,此时插入的新数据会按照新数据库分片规则写入库表中。由于原始数据没有完全迁移至新库新表,读取的时候会从原始库表和新库表中读取。例如,订单标识为15的订单数据,按照两库两表的处理逻辑,该订单数据会被写入数据库1(DB1)的01表(Table_01)中,但分库分表后会被写入数据库1(DB1)的03表(Table_03)中。数据迁移过程中,插入新数据的订单数据分配结果如表3所示。However, before all the original data of the original database table is migrated, new data will be inserted, and the new data inserted at this time will be written into the database table according to the new database sharding rules. Since the original data is not completely migrated to the new database and new table, it will be read from the original database table and the new database table when reading. For example, the order data with the order ID of 15, according to the processing logic of two databases and two tables, the order data will be written to the 01 table (Table_01) of database 1 (DB1), but it will be written to the database after the database is divided into the table. 1 (DB1) in the 03 table (Table_03). During the data migration process, the order data allocation results for inserting new data are shown in Table 3.

表3为插入新数据的订单数据分配结果Table 3 is the result of order data assignment for inserting new data

库名library name 表名Table Name orderIdorderId DB0DB0 Table_00Table_00 00、04、08、1200, 04, 08, 12 DB0DB0 Table_01Table_01 01、05、09、1301, 05, 09, 13 DB0DB0 Table_02Table_02 DB0DB0 Table_03Table_03 DB1DB1 Table_00Table_00 02、06、10、1402, 06, 10, 14 DB1DB1 Table_01Table_01 03、07、11、1503, 07, 11, 15 DB1DB1 Table_02Table_02 DB1DB1 Table_03Table_03 1515

在数据迁移过程中(即数据迁移尚未完成时),如果需要在数据库中查询数据,则查询原始数据库分片规则和新数据库分片规则对应的生成的库表。仍旧以订单标识为15的订单数据为例,在数据迁移过程中,需要查询DB1的Table_01和DB1的Table_03。During the data migration process (that is, when the data migration has not been completed), if data needs to be queried in the database, the generated database table corresponding to the original database sharding rule and the new database sharding rule is queried. Still taking the order data whose order ID is 15 as an example, during the data migration process, it is necessary to query Table_01 of DB1 and Table_03 of DB1.

在数据迁移完成后,如果需要在数据库中查询数据,则查询新数据库分片规则对应的生成的库表即可。仍旧以订单标识为15的订单数据为例,在数据迁移完成后,仅需要查询DB1的Table_03。After the data migration is completed, if you need to query the data in the database, you can query the generated database table corresponding to the new database sharding rule. Still taking the order data whose order ID is 15 as an example, after the data migration is completed, only Table_03 of DB1 needs to be queried.

通过本发明实施例的数据库扩容的方法可以看出,在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移;根据业务需求预先配置扩容规则所包含的内容,在数据库监控信息满足所述扩容规则后触发扩容处理过程,以实现自动扩容;根据当前数据库分片规则中设置的数据库和数据表的数量、以及当前业务系统对应的数据库数量和数据表数量新建数据库和数据表,实现了自动增库增表;基于路由读写规则,确定所述数据库的每条数据所归属的库表,根据确定的库表进行过滤复制实现自动数据迁移;通过环状哈希算法实现路由读写规则,能够保证数据均衡分配到每个库表中;通过更新扩容规则,以正确、方地便判定扩容后的数据库是否需要再次进行扩容处理。It can be seen from the database expansion method of the embodiment of the present invention that, after determining that the database needs to be expanded, a new database table is added according to the current database fragmentation rules, and data is written into the corresponding database table based on the routing read and write rules, without downtime Deployment can realize automatic sub-database sub-table and data migration; pre-configure the content contained in the expansion rules according to business requirements, and trigger the expansion process after the database monitoring information satisfies the expansion rules to realize automatic expansion; according to the current database fragmentation The number of databases and data tables set in the rules, as well as the number of databases and data tables corresponding to the current business system, create new databases and data tables, and realize automatic database and table addition; based on routing read and write rules, determine each entry in the database The database table to which the data belongs is filtered and copied according to the determined database table to realize automatic data migration; the routing read and write rules are implemented through the ring hash algorithm, which can ensure the balanced distribution of data to each database table; Correctly and conveniently determine whether the expanded database needs to be expanded again.

图8是根据本发明实施例的数据库扩容的装置的主要模块的示意图。如图8所示,本发明实施例的数据库扩容的装置800,主要包括:FIG. 8 is a schematic diagram of main modules of an apparatus for database expansion according to an embodiment of the present invention. As shown in FIG. 8 , an apparatus 800 for database expansion according to an embodiment of the present invention mainly includes:

判定模块801,用于获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容。其中,所述数据库监控信息包括下列至少一项:数据存储容量、连接利用率和单表数据量;所述扩容规则包括下列至少一项:当所述数据存储容量大于第一阈值时,需要对所述数据库进行扩容;当所述连接利用率大于第二阈值时,需要对所述数据库进行扩容;以及当所述单表数据量大于第三阈值时,需要对所述数据库进行扩容。当数据库监控信息满足上述任一项扩容规则后触发建立模块802的扩容处理过程。The determining module 801 is configured to obtain database monitoring information, and determine whether the database needs to be expanded according to a preconfigured expansion rule and the database monitoring information. Wherein, the database monitoring information includes at least one of the following: data storage capacity, connection utilization, and data volume of a single table; the capacity expansion rule includes at least one of the following: when the data storage capacity is greater than a first threshold, it is necessary to The database is expanded; when the connection utilization rate is greater than the second threshold, the database needs to be expanded; and when the data volume of the single table is greater than the third threshold, the database needs to be expanded. When the database monitoring information satisfies any of the above-mentioned expansion rules, the expansion processing process of the establishment module 802 is triggered.

建立模块802,用于若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表。所述当前数据库分片规则设置有当前扩容后的数据库的数量和数据表的数量。根据所述数据库的数量、所述数据库中数据表的数量,以及当前数据库分片规则中设置的扩容后的数据库的数量和数据表的数量,新建对应数量的数据库和数据表。比如,假设原来是两库两表,当前数据库分片规则中需要扩容为两库四表,则新建两个数据表;假设原来是两库两表,当前数据库分片规则中需要扩容为四库四表,则新建两个数据库和两个数据表。The establishment module 802 is configured to establish at least one new database table according to the current database fragmentation rules if the database needs to be expanded. The current database fragmentation rule is set with the current number of expanded databases and the number of data tables. According to the number of databases, the number of data tables in the database, and the number of expanded databases and the number of data tables set in the current database sharding rule, a corresponding number of databases and data tables are newly created. For example, assuming the original two databases and two tables, the current database sharding rules need to expand to two databases and four tables, then create two new data tables; assuming the original two databases and two tables, the current database sharding rules need to be expanded to four databases Four tables, then create two new databases and two data tables.

写入模块803,用于根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。所述路由读写规则基于下述任意一种算法得到:环状哈希算法、散列算法和取模算法。具体写入过程为:根据预设的路由读写规则,确定所述数据库的每条数据所归属的库表;对原始库表中的原始数据进行过滤,将过滤得到的数据写入归属的所述新库表中,记录当前过滤开始时间;判断所述原始数据是否过滤完成,如果未过滤完成,则根据所述当前过滤开始时间和过滤间隔确定下一次过滤开始时间,以继续进行下一次过滤,直至所述原始数据全部过滤完成;将所述新增数据写入到归属的所述库表中。记录当前过滤开始时间能够保证数据迁移过程中的正确性。The writing module 803 is configured to write the original data and newly added data of the database into the corresponding library table respectively according to the preset routing reading and writing rules; wherein, the library table includes the new library table. The routing read-write rule is obtained based on any one of the following algorithms: a ring hash algorithm, a hash algorithm and a modulo algorithm. The specific writing process is as follows: according to the preset routing read and write rules, determine the library table to which each piece of data in the database belongs; filter the original data in the original library table, and write the filtered data into the home table. In the new library table, record the current filtering start time; determine whether the original data is filtered and complete, if not, then determine the next filtering start time according to the current filtering start time and the filtering interval, to continue the next filtering , until all the original data is filtered; write the newly added data into the attributable library table. Recording the current filtering start time can ensure the correctness of the data migration process.

另外,本发明实施例的数据库扩容的装置800还可以包括:更新模块(图8中未示出),该模块用于判断是否扩容成功,如果扩容成功,则更新所述扩容规则。In addition, the apparatus 800 for database expansion according to the embodiment of the present invention may further include: an update module (not shown in FIG. 8 ), the module is used to determine whether the expansion is successful, and if the expansion is successful, update the expansion rule.

图9是本发明实施例的数据库扩容系统的主要模块的示意图。如图9所示,本发明实施例的数据库扩容系统900主要包括业务系统集群901、数据库集群902、数据注册中心903、管理控制平台904(即数据库扩容的装置800,具体实现功能如前所述)和数据监控中心905。FIG. 9 is a schematic diagram of main modules of a database capacity expansion system according to an embodiment of the present invention. As shown in FIG. 9 , the database capacity expansion system 900 according to the embodiment of the present invention mainly includes a business system cluster 901, a database cluster 902, a data registration center 903, and a management control platform 904 (ie, a database capacity expansion device 800. The specific implementation functions are as described above. ) and data monitoring center 905.

业务系统集群901包括至少一个业务系统,每个业务系统包括至少一个业务实例,每个业务实例分别接收配置节点的配置信息、路由读写规则,业务实例通过笛卡尔乘积算法进行内部SQL(Structured Query Language,结构化查询语言)流转,并通过数据引擎与数据库集群相连接。业务系统从配置节点中获取配置信息,将所述配置信息存储至数据注册中心。所述笛卡尔乘积算法是一种数学模型,用于将任意两个不相关的数据表连接起来。假设集合A={a,b},集合B={0,1,2},则两个集合的笛卡尔积为{(a,0),(a,1),(a,2),(b,0),(b,1),(b,2)}。The business system cluster 901 includes at least one business system, each business system includes at least one business instance, and each business instance receives configuration information of the configuration node, routing read and write rules, and the business instance performs internal SQL (Structured Query) through the Cartesian product algorithm. Language, Structured Query Language) flows and connects with the database cluster through the data engine. The business system obtains configuration information from the configuration node, and stores the configuration information in the data registration center. The Cartesian product algorithm is a mathematical model used to join any two unrelated data tables. Assuming set A={a,b}, set B={0,1,2}, then the Cartesian product of the two sets is {(a,0),(a,1),(a,2),( b,0),(b,1),(b,2)}.

数据库集群902包括至少一个数据库,每个数据库中包括至少一个数据表。业务系统集群901和数据库集群902之间可以通过DDL(Data Definition Language,数据定义语言)和DML(Data Manipulation Language,数据操作语言)语言实现数据交互。The database cluster 902 includes at least one database, and each database includes at least one data table. Data interaction can be implemented between the business system cluster 901 and the database cluster 902 through DDL (Data Definition Language, data definition language) and DML (Data Manipulation Language, data manipulation language).

数据注册中心903用于接收来自管理控制平台904的数据库信息和数据库分片规则,以及用于将来自业务系统集群901的配置信息进行存储。所述数据库信息中包括业务系统标识。数据注册中心903和业务系统集群901之间通过订阅(Subscribe)和通知(Notify)的方式进行数据交互。The data registration center 903 is used for receiving database information and database sharding rules from the management control platform 904 , and for storing the configuration information from the business system cluster 901 . The database information includes the service system identifier. Data interaction is performed between the data registration center 903 and the business system cluster 901 by means of subscription (Subscribe) and notification (Notify).

数据监控中心905用于监控数据库集群,并将获取的监控数据库信息反馈至管理控制平台904。监控的内容可以是数据库的数据存储容量、连接利用率、单表数据量、数据库性能、服务器性能等。数据监控中心905和数据库集群902之间通过监控(Monitor)和通知(Notify)的方式进行数据交互。The data monitoring center 905 is used for monitoring the database cluster, and feeding back the acquired monitoring database information to the management control platform 904 . The content to be monitored can be the data storage capacity of the database, connection utilization, data volume of a single table, database performance, server performance, etc. Data interaction is performed between the data monitoring center 905 and the database cluster 902 by means of monitoring (Monitor) and notification (Notify).

从以上描述可以看出,在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移;根据业务需求预先配置扩容规则所包含的内容,在数据库监控信息满足所述扩容规则后触发扩容处理过程,以实现自动扩容;根据当前数据库分片规则中设置的数据库和数据表的数量、以及当前业务系统对应的数据库数量和数据表数量新建数据库和数据表,实现了自动增库增表;基于路由读写规则,确定所述数据库的每条数据所归属的库表,根据确定的库表进行过滤复制实现自动数据迁移;通过环状哈希算法实现路由读写规则,能够保证数据均衡分配到每个库表中;通过更新扩容规则,以正确、方地便判定扩容后的数据库是否需要再次进行扩容处理。As can be seen from the above description, after it is determined that the database needs to be expanded, a new database table is added according to the current database fragmentation rules, and data is written into the corresponding database table based on the routing read and write rules, and automatic database partitioning can be realized without downtime for deployment Table sharding and data migration; pre-configure the content contained in the expansion rules according to business requirements, and trigger the expansion process after the database monitoring information satisfies the expansion rules to realize automatic expansion; according to the database and data set in the current database sharding rules The number of tables, as well as the number of databases and data tables corresponding to the current business system, create new databases and data tables, and realize automatic database and table addition; Automatic data migration is realized by filtering and duplicating the determined database table; the routing read and write rules are implemented through the ring hash algorithm, which can ensure the balanced distribution of data to each database table; by updating the expansion rules, the expansion can be determined correctly and conveniently. Whether the subsequent database needs to be expanded again.

图10示出了可以应用本发明实施例的数据库扩容的方法或数据库扩容的装置的示例性系统架构1000。FIG. 10 shows an exemplary system architecture 1000 of a method for database expansion or an apparatus for database expansion according to an embodiment of the present invention.

如图10所示,系统架构1000可以包括终端设备1001、1002、1003,网络1004和服务器1005。网络1004用以在终端设备1001、1002、1003和服务器1005之间提供通信链路的介质。网络1004可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 10 , the system architecture 1000 may include terminal devices 1001 , 1002 , and 1003 , a network 1004 and a server 1005 . The network 1004 is a medium used to provide a communication link between the terminal devices 1001 , 1002 , 1003 and the server 1005 . The network 1004 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.

用户可以使用终端设备1001、1002、1003通过网络1004与服务器1005交互,以接收或发送消息等。终端设备1001、1002、1003上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。The user can use the terminal devices 1001, 1002, 1003 to interact with the server 1005 through the network 1004 to receive or send messages and the like. Various communication client applications can be installed on the terminal devices 1001 , 1002 and 1003 , such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, and the like.

终端设备1001、1002、1003可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The terminal devices 1001, 1002, 1003 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

服务器1005可以是提供各种服务的服务器,例如对用户利用终端设备1001、1002、1003所浏览的购物类网站提供支持的后台管理服务器。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息)反馈给终端设备。The server 1005 may be a server that provides various services, for example, a background management server that provides support for shopping websites browsed by the terminal devices 1001 , 1002 and 1003 . The background management server can analyze and process the received product information query request and other data, and feed back the processing results (eg, target push information, product information) to the terminal device.

需要说明的是,本申请实施例所提供的数据库扩容的方法一般由服务器1005执行,相应地,数据库扩容的装置一般设置于服务器1005中。It should be noted that the method for expanding the database capacity provided by the embodiments of the present application is generally performed by the server 1005 , and accordingly, the apparatus for expanding the database capacity is generally set in the server 1005 .

应该理解,图10中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 10 are only illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.

根据本发明的实施例,本发明还提供了一种电子设备和一种计算机可读介质。According to an embodiment of the present invention, the present invention further provides an electronic device and a computer-readable medium.

本发明的电子设备包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种数据库扩容的方法。The electronic device of the present invention comprises: one or more processors; storage means for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more programs Multiple processors implement a method for expanding the capacity of a database according to an embodiment of the present invention.

本发明的计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种数据库扩容的方法。The computer-readable medium of the present invention stores a computer program thereon, and when the program is executed by the processor, a method for expanding the capacity of a database according to an embodiment of the present invention is implemented.

下面参考图11,其示出了适用于来实现本发明实施例的电子设备的计算机系统1100的结构示意图。图11示出的电子设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring next to FIG. 11 , it shows a schematic structural diagram of a computer system 1100 suitable for implementing an electronic device according to an embodiment of the present invention. The electronic device shown in FIG. 11 is only an example, and should not impose any limitation on the function and scope of use of the embodiments of the present invention.

如图11所示,计算机系统1100包括中央处理单元(CPU)1101,其可以根据存储在只读存储器(ROM)1102中的程序或者从存储部分1108加载到随机访问存储器(RAM)1103中的程序而执行各种适当的动作和处理。在RAM 1103中,还存储有计算机系统1100操作所需的各种程序和数据。CPU 1101、ROM 1102以及RAM 1103通过总线1104彼此相连。输入/输出(I/O)接口1105也连接至总线1104。As shown in FIG. 11, a computer system 1100 includes a central processing unit (CPU) 1101, which can be loaded into a random access memory (RAM) 1103 according to a program stored in a read only memory (ROM) 1102 or a program from a storage section 1108 Instead, various appropriate actions and processes are performed. In the RAM 1103, various programs and data necessary for the operation of the computer system 1100 are also stored. The CPU 1101 , the ROM 1102 , and the RAM 1103 are connected to each other through a bus 1104 . An input/output (I/O) interface 1105 is also connected to the bus 1104 .

以下部件连接至I/O接口1105:包括键盘、鼠标等的输入部分1106;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分1107;包括硬盘等的存储部分1108;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分1109。通信部分1109经由诸如因特网的网络执行通信处理。驱动器1110也根据需要连接至I/O接口1105。可拆卸介质1111,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1110上,以便于从其上读出的计算机程序根据需要被安装入存储部分1108。The following components are connected to the I/O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc. ; and a communication section 1109 including a network interface card such as a LAN card, a modem, and the like. The communication section 1109 performs communication processing via a network such as the Internet. Drivers 1110 are also connected to I/O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1110 as needed so that a computer program read therefrom is installed into the storage section 1108 as needed.

特别地,根据本发明公开的实施例,上文主要步骤图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行主要步骤图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分1109从网络上被下载和安装,和/或从可拆卸介质1111被安装。在该计算机程序被中央处理单元(CPU)1101执行时,执行本发明的系统中限定的上述功能。In particular, according to the disclosed embodiments of the present invention, the processes described in the main step diagrams above may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods illustrated in the main step diagrams. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 1109, and/or installed from the removable medium 1111. When the computer program is executed by the central processing unit (CPU) 1101, the above-described functions defined in the system of the present invention are executed.

需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.

描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括判定模块、建立模块和写入模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,判定模块还可以被描述为“获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容的模块”。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described modules can also be provided in the processor, for example, it can be described as: a processor includes a determination module, a creation module and a writing module. Among them, the names of these modules do not constitute a limitation of the module itself under certain circumstances. For example, the determination module can also be described as "obtaining database monitoring information, and determining whether to Modules that need to expand the database".

作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:获取数据库监控信息,根据预先配置的扩容规则和所述数据库监控信息判定是否需要对所述数据库进行扩容;若需要对所述数据库进行扩容,则根据当前数据库分片规则建立至少一个新库表;根据预设的路由读写规则,将所述数据库的原始数据和新增数据分别写入到对应的库表中;其中,所述库表包括所述新库表。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes: acquiring database monitoring information, and determining according to preconfigured expansion rules and the database monitoring information. Whether the database needs to be expanded; if the database needs to be expanded, at least one new database table is established according to the current database fragmentation rules; according to the preset routing read and write rules, the original data of the database and the new The incremental data are respectively written into the corresponding library table; wherein, the library table includes the new library table.

从以上描述可以看出,在判定数据库需要扩容后,根据当前数据库分片规则增加新库表,并基于路由读写规则将数据写入到对应库表中,无需停机部署即可实现自动分库分表和数据迁移;根据业务需求预先配置扩容规则所包含的内容,在数据库监控信息满足所述扩容规则后触发扩容处理过程,以实现自动扩容;根据当前数据库分片规则中设置的数据库和数据表的数量、以及当前业务系统对应的数据库数量和数据表数量新建数据库和数据表,实现了自动增库增表;基于路由读写规则,确定所述数据库的每条数据所归属的库表,根据确定的库表进行过滤复制实现自动数据迁移;通过环状哈希算法实现路由读写规则,能够保证数据均衡分配到每个库表中;通过更新扩容规则,以正确、方地便判定扩容后的数据库是否需要再次进行扩容处理。As can be seen from the above description, after it is determined that the database needs to be expanded, a new database table is added according to the current database fragmentation rules, and data is written into the corresponding database table based on the routing read and write rules, and automatic database partitioning can be realized without downtime for deployment Table sharding and data migration; pre-configure the content contained in the expansion rules according to business requirements, and trigger the expansion process after the database monitoring information satisfies the expansion rules to realize automatic expansion; according to the database and data set in the current database sharding rules The number of tables, as well as the number of databases and data tables corresponding to the current business system, create new databases and data tables, and realize automatic database and table addition; Automatic data migration is realized by filtering and duplicating the determined database table; the routing read and write rules are implemented through the ring hash algorithm, which can ensure the balanced distribution of data to each database table; by updating the expansion rules, the expansion can be determined correctly and conveniently. Whether the subsequent database needs to be expanded again.

上述产品可执行本发明实施例所提供的方法,具备执行方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本发明实施例所提供的方法。The above product can execute the method provided by the embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the method. For technical details not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.

上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims (12)

1. A method for expanding database, comprising:
acquiring database monitoring information, and judging whether the database needs to be expanded according to a preset expansion rule and the database monitoring information;
if the database needs to be expanded, establishing at least one new database table according to the current database fragmentation rule;
respectively writing the original data and the newly added data of the database into corresponding base tables according to a preset routing read-write rule; wherein the library table comprises the new library table.
2. The method of claim 1, wherein the database monitoring information comprises at least one of: data storage capacity, connection utilization rate and single-table data volume;
the capacity expansion rule comprises at least one of the following items: when the data storage capacity is larger than a first threshold value, the capacity of the database needs to be expanded; when the connection utilization rate is greater than a second threshold value, the capacity of the database needs to be expanded; and when the data volume of the single table is larger than a third threshold value, the capacity of the database needs to be expanded.
3. The method according to claim 1, wherein the database sharding rule sets the number of the database and the data table after capacity expansion;
the establishing of at least one new base table according to the current database fragmentation rule comprises: and newly building a database and a data table with corresponding quantity according to the quantity of the databases, the quantity of the data tables in the databases and the quantity of the expanded databases and data tables set in the current database fragmentation rule.
4. The method according to claim 1, wherein the writing the original data and the new data of the database into corresponding database tables according to a preset routing read-write rule comprises:
determining a base table to which each piece of data of the database belongs according to a preset routing read-write rule;
filtering original data in an original base table, writing the filtered data into the new base table to which the data belongs, and recording the current filtering starting time;
judging whether the original data is filtered or not, if not, determining the next filtering start time according to the current filtering start time and the filtering interval so as to continue to filter the next time until the original data is completely filtered;
and writing the newly added data into the attributive library table.
5. The method according to any one of claims 1 to 4, further comprising: and judging whether the capacity expansion is successful or not, and if the capacity expansion is successful, updating the capacity expansion rule.
6. An apparatus for expanding a database, comprising:
the judging module is used for acquiring database monitoring information and judging whether the database needs to be expanded or not according to a preset expansion rule and the database monitoring information;
the establishing module is used for establishing at least one new base table according to the current database fragmentation rule if the database needs to be expanded;
the writing module is used for respectively writing the original data and the newly added data of the database into corresponding base tables according to a preset routing read-write rule; wherein the library table comprises the new library table.
7. The apparatus of claim 6, wherein the database monitoring information comprises at least one of: data storage capacity, connection utilization rate and single-table data volume;
the capacity expansion rule comprises at least one of the following items: when the data storage capacity is larger than a first threshold value, the capacity of the database needs to be expanded; when the connection utilization rate is greater than a second threshold value, the capacity of the database needs to be expanded; and when the data volume of the single table is larger than a third threshold value, the capacity of the database needs to be expanded.
8. The apparatus according to claim 6, wherein the database sharding rule sets the number of the expanded databases and data tables;
the establishing module is further configured to: and newly building a database and a data table with corresponding quantity according to the quantity of the databases, the quantity of the data tables in the databases and the quantity of the expanded databases and data tables set in the current database fragmentation rule.
9. The apparatus of claim 6, wherein the write module is further configured to:
determining a base table to which each piece of data of the database belongs according to a preset routing read-write rule;
filtering original data in an original base table, writing the filtered data into the new base table to which the data belongs, and recording the current filtering starting time;
judging whether the original data is filtered or not, if not, determining the next filtering start time according to the current filtering start time and the filtering interval so as to continue to filter the next time until the original data is completely filtered; and
and writing the newly added data into the attributive library table.
10. The apparatus of any of claims 6 to 9, further comprising: and the updating module is used for judging whether the capacity expansion is successful or not, and updating the capacity expansion rule if the capacity expansion is successful.
11. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201810936192.5A 2018-08-16 2018-08-16 Method and device for expanding database Pending CN110858194A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810936192.5A CN110858194A (en) 2018-08-16 2018-08-16 Method and device for expanding database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810936192.5A CN110858194A (en) 2018-08-16 2018-08-16 Method and device for expanding database

Publications (1)

Publication Number Publication Date
CN110858194A true CN110858194A (en) 2020-03-03

Family

ID=69634833

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810936192.5A Pending CN110858194A (en) 2018-08-16 2018-08-16 Method and device for expanding database

Country Status (1)

Country Link
CN (1) CN110858194A (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111797102A (en) * 2020-07-06 2020-10-20 亿度慧达教育科技(北京)有限公司 Data writing method and device and electronic equipment
CN111858765A (en) * 2020-07-24 2020-10-30 中国工商银行股份有限公司 Data processing method, device and system applied to database expansion scenario
CN112784120A (en) * 2021-01-25 2021-05-11 浪潮云信息技术股份公司 KV memory database storage management method based on range fragmentation mode
CN112965956A (en) * 2021-03-18 2021-06-15 上海东普信息科技有限公司 Database horizontal capacity expansion method, device, equipment and storage medium
CN113094353A (en) * 2021-04-08 2021-07-09 中国工商银行股份有限公司 Database capacity expansion method and device
CN113239011A (en) * 2021-05-11 2021-08-10 京东数字科技控股股份有限公司 Database capacity expansion method, device and system
CN113407112A (en) * 2021-05-11 2021-09-17 浙江大华技术股份有限公司 Capacity expansion method, electronic equipment and computer readable storage medium
CN113448940A (en) * 2020-03-24 2021-09-28 北京京东振世信息技术有限公司 Method and device for expanding database
CN114443619A (en) * 2022-01-27 2022-05-06 中国电信股份有限公司 Database capacity expansion method and device, electronic equipment and storage medium
CN115129687A (en) * 2022-03-16 2022-09-30 希望知舟技术(深圳)有限公司 Abnormal condition database management-based method, related device, medium and program
CN115510073A (en) * 2022-10-27 2022-12-23 深圳市路通网络技术有限公司 Distribution method and distribution device for data warehousing and storage medium
CN117056311A (en) * 2023-08-16 2023-11-14 中国工商银行股份有限公司 Method, device, equipment and storage medium for storing business data
CN117076422A (en) * 2023-08-14 2023-11-17 京东科技信息技术有限公司 Database management method and device

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105955662A (en) * 2016-04-22 2016-09-21 浪潮(北京)电子信息产业有限公司 Method and system for expansion of K-DB data table space
CN106294421A (en) * 2015-05-25 2017-01-04 阿里巴巴集团控股有限公司 A kind of data write, read method and device
CN106843745A (en) * 2015-12-03 2017-06-13 南京中兴新软件有限责任公司 Capacity expansion method and device
CN107357896A (en) * 2017-07-13 2017-11-17 北京小度信息科技有限公司 Expansion method, device, system and the data base cluster system of data-base cluster
CN108132949A (en) * 2016-12-01 2018-06-08 腾讯科技(深圳)有限公司 The method and device of Data Migration in data-base cluster

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106294421A (en) * 2015-05-25 2017-01-04 阿里巴巴集团控股有限公司 A kind of data write, read method and device
CN106843745A (en) * 2015-12-03 2017-06-13 南京中兴新软件有限责任公司 Capacity expansion method and device
CN105955662A (en) * 2016-04-22 2016-09-21 浪潮(北京)电子信息产业有限公司 Method and system for expansion of K-DB data table space
CN108132949A (en) * 2016-12-01 2018-06-08 腾讯科技(深圳)有限公司 The method and device of Data Migration in data-base cluster
CN107357896A (en) * 2017-07-13 2017-11-17 北京小度信息科技有限公司 Expansion method, device, system and the data base cluster system of data-base cluster

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113448940A (en) * 2020-03-24 2021-09-28 北京京东振世信息技术有限公司 Method and device for expanding database
CN113448940B (en) * 2020-03-24 2023-09-22 北京京东振世信息技术有限公司 Database capacity expansion method and device
CN111797102A (en) * 2020-07-06 2020-10-20 亿度慧达教育科技(北京)有限公司 Data writing method and device and electronic equipment
CN111858765A (en) * 2020-07-24 2020-10-30 中国工商银行股份有限公司 Data processing method, device and system applied to database expansion scenario
CN112784120A (en) * 2021-01-25 2021-05-11 浪潮云信息技术股份公司 KV memory database storage management method based on range fragmentation mode
CN112784120B (en) * 2021-01-25 2023-02-21 浪潮云信息技术股份公司 KV memory database storage management method based on range fragmentation mode
CN112965956A (en) * 2021-03-18 2021-06-15 上海东普信息科技有限公司 Database horizontal capacity expansion method, device, equipment and storage medium
CN113094353A (en) * 2021-04-08 2021-07-09 中国工商银行股份有限公司 Database capacity expansion method and device
CN113407112A (en) * 2021-05-11 2021-09-17 浙江大华技术股份有限公司 Capacity expansion method, electronic equipment and computer readable storage medium
CN113239011A (en) * 2021-05-11 2021-08-10 京东数字科技控股股份有限公司 Database capacity expansion method, device and system
CN113239011B (en) * 2021-05-11 2024-10-18 京东科技控股股份有限公司 Database capacity expansion method, device and system
CN114443619A (en) * 2022-01-27 2022-05-06 中国电信股份有限公司 Database capacity expansion method and device, electronic equipment and storage medium
CN114443619B (en) * 2022-01-27 2024-11-05 中国电信股份有限公司 Database expansion method, device, electronic equipment and storage medium
CN115129687A (en) * 2022-03-16 2022-09-30 希望知舟技术(深圳)有限公司 Abnormal condition database management-based method, related device, medium and program
CN115510073A (en) * 2022-10-27 2022-12-23 深圳市路通网络技术有限公司 Distribution method and distribution device for data warehousing and storage medium
CN117076422A (en) * 2023-08-14 2023-11-17 京东科技信息技术有限公司 Database management method and device
CN117056311A (en) * 2023-08-16 2023-11-14 中国工商银行股份有限公司 Method, device, equipment and storage medium for storing business data

Similar Documents

Publication Publication Date Title
CN110858194A (en) Method and device for expanding database
US11379428B2 (en) Synchronization of client machines with a content management system repository
CN103098024B (en) Member Tracking and Data Eviction in Mobile Middleware Scenarios
US10097659B1 (en) High performance geographically distributed data storage, retrieval and update
WO2018233364A1 (en) Index update method, system and related device
CN111061680B (en) A method and device for data retrieval
CN115185966A (en) Method and device for processing data consistency in distributed cluster
CN106354566A (en) Command processing method and server
WO2024067832A1 (en) Data processing method and apparatus, electronic device, and storage medium
CN111984686A (en) Data processing method and device
CN110795494A (en) Automatic testing method and device for synchronous and asynchronous cache data
CN113760966A (en) Data processing method and device based on heterogeneous database system
CN112069137A (en) Method and device for generating information, electronic equipment and computer readable storage medium
CN106716400B (en) Method and device for partition management of data table
CN113760860B (en) Data reading method and device
CN111694801A (en) Data deduplication method and device applied to fault recovery
CN112148705A (en) Data migration method and device
CN112115206B (en) A method and device for processing object storage metadata
CN117389475A (en) A data processing method and device
CN114756173B (en) Method, system, apparatus and computer readable medium for file merging
CN110196854A (en) Data processing method and device
CN106407320B (en) File processing method, device and system
CN119149590A (en) Inventory snapshot generation method and device
CN113377795B (en) A message processing method and device
CN113807054B (en) Method, device, apparatus and computer-readable medium for processing data

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200303

RJ01 Rejection of invention patent application after publication