Storage system based on MongoDB, data insertion method and storage medium
By configuring clusters and service clusters to automatically allocate and synchronize data in the MongoDB storage system, it solves the problem of configuration modification and data balancing when adding new nodes, and achieves efficient data insertion and balancing.
Patent Information
- Application Number
- CN202010536891.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-12
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2040-06-12
AI Technical Summary
In the MongoDB storage system, when adding a node, the configuration of the application client needs to be modified, resulting in complicated operations and data imbalance.
By configuring clusters and service clusters, it automatically determines and allocates target shards for data to be inserted or creates new shards to avoid modifying application client configurations, and synchronizes data between application nodes to achieve automatic data balancing.
The operation process of adding new nodes is optimized, reducing the need to modify the application client configuration, realizing automatic data balancing and high availability, and avoiding additional data rebalancing operations.
Smart Images

Figure CN111767282B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of distributed database application, and in particular to a storage system based on MongoDB, a data insertion method and a storage medium. Background Art
[0002] The MongoDB storage system is easy to install and flexible to use. It does not require the creation of databases and tables in advance and has a free mode. It is suitable for scenarios where application client requirements change frequently and the data model cannot be determined.
[0003] The MongoDB storage system is naturally suitable for storing logs in JSON format. It supports JS syntax queries and map-reduce-based analysis methods in data analysis. Therefore, the MongoDB storage system is very suitable for small development teams to store and analyze JSON format logs. When using MongoDB to store massive logs, it involves the need for MongoDB cluster sharding.
[0004] The inventors have discovered that there are at least the following problems in the prior art: when adding a new MongoDB node, it is necessary to modify the configuration of the application client to establish a new database connection. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a storage system, data insertion method and storage medium based on MongoDB. When a new MongoDB node needs to be added later, there is no need to modify the configuration of the application client, thereby optimizing the operation of adding a new MongoDB node later.
[0006] To solve the above technical problems, an embodiment of the present invention provides a storage system based on MongoDB, including: a configuration cluster, a service cluster and multiple application nodes; the configuration cluster is used to store an online application node list and database shard information, the online application node list includes online application nodes among multiple application nodes, and the service cluster is used to interact with application clients for data; the service cluster is used to determine whether there is a target shard into which the data to be inserted exists based on the database shard information stored in the configuration cluster when monitoring that the application client generates data to be inserted, the number of records in the database shard information of the target shard is less than a preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list; if the target shard does not exist, a new shard is created, an application node is selected from the online application node list as the data storage location of the new shard, and the data to be inserted is stored in the data storage location of the new shard; the database shard information of the new shard is uploaded to the configuration cluster, and the database shard information of the new shard includes the newly added data and the data storage location of the new shard.
[0007] An embodiment of the present invention also provides a data insertion method, based on the above MongoDB storage system, including: obtaining the data to be inserted from the application client, and determining whether there is a target shard, the number of records of the target shard is less than a preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list; if the target shard does not exist, creating a new shard, and selecting an application node in the online application node list as the data storage location of the new shard, and storing the data to be inserted in the data storage location of the new shard; uploading the database shard information of the new shard to the configuration cluster, the database shard information of the new shard includes the newly added data and the data storage location of the new shard; returning the insertion result of the data to be inserted to the application client.
[0008] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, and the computer program implements the above data insertion method when executed by a processor.
[0009] Compared with the prior art, the embodiment of the present invention proposes a storage system based on MongoDB, in which the data written by the application client through the service cluster is stored in each shard by the service cluster. When the application client reads data through the service cluster, the service cluster integrates the data of each shard and returns it to the application. The application client is connected to the database through the service cluster. When a new MongoDB node needs to be added later, there is no need to modify the configuration of the application client, which optimizes the subsequent operation of adding a new MongoDB node; in addition, when a new shard is created, the new data of the application client is directly inserted into the new shard, which automatically achieves data balance without the need for additional data rebalancing.
[0010] In addition, based on the database shard information stored in the configuration cluster, it is determined whether there is a target shard into which the data to be inserted can be inserted, including: the service cluster obtains the database shard information stored in the configuration cluster; the service cluster queries the configuration cluster based on the database shard information to obtain a shard list; the service cluster queries the configuration cluster to obtain a list of online application nodes; the service cluster traverses the shard list and determines whether there is a target shard into which the data to be inserted can be inserted based on the list of online application nodes.
[0011] In addition, the storage system based on MongoDB also includes a new application node; the new application node registers the MongoDB shard storage server provided by the new application node with the service cluster; the configuration cluster updates the online application node list, and the updated online application node list includes the new application node; the service cluster is used to use the new application node as the data storage location of the new shard when detecting the existence of the new application node in the online application node list. By creating a new shard in the new application node for storing data, data balance of the application node is automatically achieved without the need for additional data rebalancing.
[0012] In addition, the application node is also used to synchronize the data stored in the MongoDB shard storage server to the MongoDB shard storage servers of other application nodes.
[0013] In addition, the configuration cluster is used to detect whether the configuration cluster is connected to the application node; the configuration cluster is also used to update the MongoDB shard storage server of the application node under the online application node list based on whether the configuration cluster is connected to the application node.
[0014] In addition, the configuration cluster is used to add a MongoDB shard storage server of the application node under the online application node list when it is detected that the configuration cluster is connected to the application node; the configuration cluster is also used to delete the MongoDB shard storage server of the application node under the online application node list when it is detected that the configuration cluster is disconnected from the application node. The configuration cluster updates the application nodes under the online application node in real time through the connection relationship with the application node, ensuring the accuracy of the online application node.
[0015] In addition, the data storage location of the shard includes: a primary data storage location and a backup data storage location; the service cluster selects the application node in the online application node list as the data storage location of the new shard, and stores the data to be inserted in the data storage location of the new shard, including: the service cluster selects at least two application nodes in the online application node list as the primary data storage location of the new shard and the backup data storage location of the new shard. By storing data at the primary data storage location and the backup data storage location at the same time, high data availability is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0017] Figure 1 is a schematic diagram of the structure of a storage system based on MongoDB provided in the first embodiment of the present invention;
[0018] Figure 2 It is a schematic diagram of storing database sharding information provided by the first embodiment of the present invention;
[0019] Figure 3 is a schematic diagram of the structure of a storage system based on MongoDB provided in the second embodiment of the present invention;
[0020] Figure 4 is a flow chart of a data insertion method provided by the third embodiment of the present invention;
[0021] Figure 5 It is a flowchart of a data processing method provided by the fourth embodiment of the present invention. Specific embodiments
[0022] To make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented. The division of the following embodiments is for the convenience of description and should not constitute any limitation on the specific implementation of the present invention. The various embodiments can be combined with each other and quoted from each other without contradiction.
[0023] The first embodiment of the present invention relates to a storage system based on MongoDB, including: a configuration cluster, a service cluster and multiple application nodes; the configuration cluster is used to store an online application node list and database shard information, the online application node list includes online application nodes among multiple application nodes, and the service cluster is used to perform data interaction with an application client; the service cluster is used to determine whether there is a target shard into which the data to be inserted exists based on the database shard information stored in the configuration cluster when monitoring that the application client generates data to be inserted, the number of records in the database shard information of the target shard is less than a preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list; if the target shard does not exist, a new shard is created, an application node is selected in the online application node list as the data storage location of the new shard, and the data to be inserted is stored in the data storage location of the new shard; the database shard information of the new shard is uploaded to the configuration cluster, and the database shard information of the new shard includes the newly added data and the data storage location of the new shard.
[0024] Figure 1 This is a schematic diagram of the structure of the storage system based on MongoDB in this embodiment. Figure 1 A storage system based on MongoDB involved in this embodiment is described in detail.
[0025] The storage system 10 based on MongoDB includes: a configuration cluster 201, a service cluster 301 and a plurality of application nodes.
[0026] In this embodiment, the multiple application nodes are illustrated by three application nodes, namely application node 1 (101), application node 2 (102) and application node 3 (103). In other embodiments, the number of the multiple application nodes can be any number, which can be specifically set according to the storage capacity of the database in the actual application.
[0027] The structures of different application nodes involved in this application are the same. The following is a specific description of the application node based on application node 1 (101) as an example. The application node includes: a storage module 111 and a synchronization module 121. The storage module 111 is used to provide a MongoDB shard storage server, and the MongoDB shard storage server is used as a data storage location to store data. The synchronization module 121 is used to register the information of the MongoDB shard storage server provided by the storage module 111 of the application node 1 (101) to which the synchronization module 121 belongs to the service cluster 301. The synchronization module 121 is also used to maintain a long connection with the configuration cluster 201 to realize a long connection between the application node 1 (101) and the configuration cluster 201.
[0028] In addition, the synchronization module 121 is also used to synchronize the data of the application node to which the synchronization module 121 belongs to other application nodes by detecting Mongo's operation log, that is, the application node is also used to synchronize the data stored in the MongoDB shard storage server to the MongoDB shard storage server of other application nodes.
[0029] The configuration cluster 201 is a metadata service cluster. In an example, the configuration cluster 201 can ensure high availability and data consistency of the configuration cluster 201 through the PAXAS protocol.
[0030] The configuration cluster 201 is used to store the online application node list and database sharding information. In this embodiment, the configuration cluster 201 stores the online application node list and database sharding information in the form of a tree structure. The online application node list is a collection of currently online working nodes, and the database sharding information is used to classify and store data, including the database name and collection name for classifying the shards, and the sharding information includes the number of records and the data storage location.
[0031] The online application node list includes online application nodes among multiple application nodes. In one example, / worker is used to store the online application node list, and the / worker directory is the online working node list, and each application node located under the online working node list is a temporary node. That is, when each application node is started, the synchronization module 121 contained in the application node will call the interface of the configuration cluster 201, create the MongoDB shard storage server information of the storage module 111 of the application node to which the synchronization module 121 belongs in the / worker directory, and maintain a connection with the configuration cluster 201, that is, the application node maintains a connection with the configuration cluster 201.
[0032] In this embodiment, the configuration cluster 201 is also used to detect whether the connection status between the configuration cluster 201 and the application node has changed, and based on the change in the connection status between the configuration cluster 201 and the application node, update the MongoDB shard storage server information of the application node in the online application node list.
[0033] Specifically, when the configuration cluster 201 detects that the connection state between the configuration cluster 201 and the application node has changed from unconnected to connected, the MongoDB shard storage server information provided by the storage module 111 of the application node is added to the online application node list; when the configuration cluster 201 detects that the connection state between the configuration cluster 201 and the application node has changed from connected to unconnected, the MongoDB shard storage server information provided by the storage module 111 of the application node on the online application node list is deleted. That is, when the application node maintains a connection state with the configuration cluster 201, the MongoDB shard storage server information provided by the storage module 111 of the application node can be found from the online application node list. The configuration cluster 201 updates the application node in the online application node list in real time according to the connection relationship with the application node, ensuring the accuracy of the online application node.
[0034] It should be noted that other application nodes or the service cluster 301 can observe the / worker directory to monitor the online or offline status of the application node.
[0035] refer to Figure 2, multiple databases are stored in the directory of database shard information, namely, database 1, database 2...database n, and each database has a database name. Taking database 1 as an example, multiple collections are stored in the directory of the database, namely, collection 1, collection 2...collection n, and each collection has a collection name. Taking collection 1 as an example, multiple shards are stored in the directory of the collection, namely, shard 1, shard 2...shard n. Taking shard 1 as an example, the shard includes the number of records, the data storage location, and the specific data stored; wherein, the number of records of the shard expresses the number of data items stored under the shard, and corresponding to the number of records, each shard has a preset maximum value, that is, the upper limit of the number of data items that the current shard can store. The data storage location of the shard, that is, the address of the shard storage data, is specifically a MongoDB shard storage server provided by a certain application node. Through the tree-structured data storage form, the data storage is readable, and when the data stored in the database is subsequently processed, the "needle in a haystack" type of data search is avoided, which facilitates data acquisition and increases the availability of data.
[0036] In an example, the / db directory is used to store database shard information, db_name is the name of a database, collection is the name of a collection (similar to a MySQL table) under the database db_name, slice0 to 2 are shards of the collection, and the content of slice0 is as follows:
[0037] "name": "collection0"
[0038] "count": "100000"
[0039] "save":"10.144.0.29:27017"
[0040] The "name" field represents the name of the collection in which the shard is located; the "count" field represents the number of data entries in the shard, that is, the number of records in the shard; and the "save" field represents the data storage location of the shard.
[0041] It should be noted that the data storage location of the shard may include multiple locations. In this embodiment, the data storage location of the shard includes: a primary data storage location and a backup data storage location.
[0042] In one example, the contents under "save" are as follows:
[0043] "master":"10.144.0.29:27017"
[0044] "slave":"10.144.0.30:27017"
[0045] The "master" field represents the primary data storage location of the shard, and the "slave" field represents the backup data storage location of the shard. The data stored in a shard is stored in two locations to achieve high data availability.
[0046] Continue to refer Figure 1 The service cluster 301 is used to perform data interaction with the application client 20 .
[0047] Specifically, the service cluster 301 is a stateless service that can be horizontally expanded to increase the concurrency performance of the entire system. The service cluster 301 is used to provide Mongo protocol services to the application client 20. From the application client 20's point of view, the service cluster 301 is a MongoDB storage system.
[0048] The service cluster 301 is used to respond to the relevant operations of the application client 20 on the database, process the data stored in the configuration cluster 201 and the application node, and feed back the result of the data processing to the application client 20. That is, the present invention realizes the connection between the application client 20 and the database through the service cluster 301. This avoids the need to modify the configuration of the application client 20 when a new MongoDB node needs to be added later after the application client 20 is directly connected to the database.
[0049] In an example, the service cluster 301 is configured to insert the data to be inserted into the corresponding shard when detecting that the application client 20 generates the data to be inserted.
[0050] Specifically, when the application client 20 generates data to be inserted into the database, the service cluster 301 connects with the application client 20 . At this time, the service cluster 301 detects that the application client 20 generates data to be inserted.
[0051] The service cluster 301 determines whether there is a target shard into which the data to be inserted can be inserted based on the database shard information stored in the configuration cluster 201, the number of records in the database shard information of the target shard is less than the preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list.
[0052] Specifically, service cluster 301 obtains database shard information stored in configuration cluster 201; service cluster 301 queries configuration cluster 201 based on the database shard information stored in configuration cluster 201 to obtain a shard list; service cluster 301 queries configuration cluster 201 to obtain an online application node list; service cluster 301 traverses the shard list and determines whether there is a target shard where the data to be inserted can be inserted based on the online application node list.
[0053] Based on the above description, it can be known that the database sharding information is stored in a tree structure, that is, each data is classified and stored, and the related data needs to be stored in the shards under the corresponding class collection. The service cluster 301 searches for the shards under the corresponding collection based on the database sharding information stored in the configuration cluster 201, and determines whether the corresponding shard can insert data according to the number of records in the shard and the preset maximum value. If the shard can still insert data and the application node to which the data storage location of the shard belongs is in the online application node list, the shard can be used as the target shard, and the data to be inserted can be inserted into the target shard. Then the service cluster 301 feeds back an insertion result of the data to be inserted to the application client 20, and the insertion of the data to be inserted is completed.
[0054] If the target shard does not exist, a new shard is created. That is, according to the above steps, if the target shard that can be used to store the data to be inserted cannot be found, a new shard needs to be created to store the data to be inserted. Select an application node from the online application node list as the data storage location of the new shard, and store the data to be inserted in the data storage location of the new shard.
[0055] Correspondingly, since the new shard is a newly created shard, the database shard information of the new shard is not stored in the configuration cluster 201. At this time, the service cluster 301 also needs to upload the database shard information of the new shard to the configuration cluster 201. The database shard information of the new shard includes the newly added data and the data storage location of the new shard. In addition, due to the data storage formation of the database shard information, the number of records and the preset maximum value of the new shard, as well as the database name and collection name where the new shard is located will be stored together. After the service cluster 301 completes the upload of the database shard information of the new shard, it feeds back an insertion result of the data to be inserted to the application client 20, and the insertion of the data to be inserted is completed. By setting the number of shard records and the preset maximum value, the uniformity of data insertion is achieved. When there is a new shard, the data to be inserted is inserted into the new shard, and the storage balance of the database data is automatically achieved without the need for rebalancing operations.
[0056] In this embodiment, since the data storage location of the shard may include the primary data storage location and the backup data storage location, in the process of creating a new shard, the service cluster 301 selects at least two application nodes in the online application node list as the primary data storage location of the new shard and the backup data storage location of the new shard, respectively, and stores the data to be inserted in the primary data storage location of the new shard. The storage of the backup data is based on the synchronization module 121, and the synchronization module 121 inserts data through the Mongo operation log when synchronizing database information.
[0057] Compared with the prior art, the present invention proposes a storage system based on MongoDB. The data written by the application client through the service cluster is stored in each shard by the service cluster. When the application client reads data through the service cluster, the service cluster integrates the data of each shard and returns it to the application. The application client is connected to the database through the service cluster. When a new MongoDB node needs to be added later, there is no need to modify the configuration of the application client, which optimizes the subsequent operation of adding a new MongoDB node. In addition, when a new shard is created, the new data of the application client is directly inserted into the new shard, which automatically achieves data balance without the need for additional data rebalancing.
[0058] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0059] The second embodiment of the present invention relates to a storage system based on MongoDB. The difference from the first embodiment is that the first embodiment uses a fixed number of application nodes for illustration, while in this embodiment, the number of application nodes is expandable, that is, the storage space of the MongoDB storage system provided by this embodiment can be increased by adding application nodes.
[0060] The following will be combined Figure 3 A storage system based on MongoDB involved in this embodiment is described in detail.
[0061] In this embodiment, the application nodes include application node 1 (101), application node 2 (102), ..., application node n (10n).
[0062] When a new application node exists in the MongoDB-based storage system 30, the new application node registers the MongoDB shard storage server provided by the new application node with the service cluster 301; specifically, the synchronization module 121 in the new application node registers the MongoDB shard storage server provided by the storage module 111 in the new application node with the service cluster 301. Since the MongoDB-based storage system 30 provided in this embodiment performs information exchange between the application client 20 and the database through the service cluster, it is not necessary to modify the configuration information of the database on the application client 20 side.
[0063] The configuration cluster 201 updates the online application node list, and the updated online application node list includes the new application node. Specifically, the synchronization module 121 in the new application node maintains a long connection with the configuration cluster. When the configuration cluster 201 detects that the connection relationship between the configuration cluster 201 and the new application node changes from unconnected to connected, the MongoDB shard storage server information provided by the storage module 111 of the new application node is added to the online application node list.
[0064] In combination with the data to be inserted in the first embodiment, if the target shard does not exist, a new shard is created. At this time, when the service cluster 201 detects that a new application node exists in the online application node list, the new application node is used as the data storage location of the new shard. That is, when a new application node exists in the online application node list, a new shard is created with the new application node as the data storage location of the new shard, automatically achieving data balance between application nodes.
[0065] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0066] It is not difficult to find that this embodiment is a system embodiment related to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the first embodiment.
[0067] The third embodiment of the present invention relates to a data insertion method based on the above-mentioned MongoDB storage system. Figure 4 The data insertion method provided by the embodiment of the present invention is described in detail.
[0068] Step a01, obtaining the data to be inserted from the application client. Specifically, obtaining the data to be inserted from the application client, and determining the database name and collection name into which the data to be inserted needs to be inserted according to the characteristics of the data to be inserted.
[0069] Step a02: Does the target shard exist?
[0070] According to the database name and the collection name, query the database shard information in the configuration cluster to find out whether the target shard for inserting the data to be inserted can be found, the number of records in the target shard is less than the preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list; specifically, obtain the database shard information stored in the configuration cluster; query the configuration cluster based on the database shard information stored in the configuration cluster to obtain the shard list; query the configuration cluster to obtain the online application node list; traverse the shard list and determine whether there is a target shard for inserting the data to be inserted based on the online application node list.
[0071] If the target shard exists, execute step a03; if the target shard does not exist, execute step a04.
[0072] Step a03, insert the data to be inserted into the data storage location of the target shard. After step a03 is executed, execute step a09; step a09, update the database shard information of the target shard in the configuration cluster. After step a09 is executed, execute step a10; step a10, return the insertion result of the data to be inserted to the application client.
[0073] Step a04: Is there a new application node? Specifically, based on the acquired online application node list, monitor whether there is a new application node in the online application nodes.
[0074] If there is a new application node, execute step a05; if there is no new application node, execute step a06.
[0075] Step a05, using the new application node as the data storage location of the new shard, a new shard is created. Specifically, when a new application node is detected in the online application node list, the new application node is used as the data storage location of the new shard, and a new shard is created. Using the new application node as the data storage location of the new shard to create a new shard automatically achieves data balance between application nodes.
[0076] After step a05 is executed, step a07 is executed; in step a07, the data to be inserted is inserted into the data storage location of the new shard. After step a07 is executed, step a08 is executed; in step a08, the database shard information of the new shard is added to the configuration cluster. After step a08 is executed, step a10 is executed; in step a10, the insertion result of the data to be inserted is returned to the application client.
[0077] Step a06, select an application node in the online application node list as the data storage location of the new shard, and create a new shard. Specifically, if the target shard where the data to be inserted can be placed cannot be found, a new shard needs to be created to place the data to be inserted. Select an application node in the online application node list as the data storage location of the new shard, and create a new shard. By setting the number of shard records and the preset maximum value, the uniformity of data insertion is achieved. When a new shard exists, the data to be inserted is inserted into the new shard, and the storage balance of the database data is automatically achieved without the need for rebalancing operations.
[0078] After step a06 is executed, step a07 is executed; in step a07, the data to be inserted is inserted into the data storage location of the new shard. After step a07 is executed, step a08 is executed; in step a08, the database shard information of the new shard is added to the configuration cluster. After step a08 is executed, step a10 is executed; in step a10, the insertion result of the data to be inserted is returned to the application client.
[0079] Step a10, returns the insertion result of the data to be inserted to the application client. The application client is connected to the database through the service cluster. When a new MongoDB node is needed later, there is no need to modify the configuration of the application client, which optimizes the operation of adding a new MongoDB node later.
[0080] Compared with the prior art, this embodiment realizes the connection between the application client and the database through the service cluster. When a new MongoDB node needs to be added later, there is no need to modify the configuration of the application client, which optimizes the subsequent operation of adding a new MongoDB node. In addition, when a new shard is created, the new data of the application client is directly inserted into the new shard, which automatically achieves data balance without the need for additional data rebalancing.
[0081] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0082] Since the first embodiment and the second embodiment correspond to the present embodiment, the present embodiment can be implemented in cooperation with the first embodiment and the second embodiment. The relevant technical details mentioned in the first embodiment and the second embodiment are still valid in the present embodiment, and the technical effects that can be achieved in the first embodiment and the second embodiment can also be achieved in the present embodiment. In order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in the present embodiment can also be applied in the first embodiment and the second embodiment.
[0083] The fourth embodiment of the present invention relates to a data processing method. The data processing includes data query, data deletion and data modification. Since data query, deletion and modification are different from data insertion and do not require additional data storage space, the data processing method is slightly different from the above-mentioned data insertion method. Figure 5 The data insertion method of the embodiment of the present invention is described in detail.
[0084] Step b01, obtaining data processing information of the application client.
[0085] Specifically, the data processing of the application client involves data query, data deletion, and data modification; correspondingly, the data processing information involves data query conditions, data deletion conditions, and data modification conditions.
[0086] Step b02, obtain the online working node list and database shard information.
[0087] Step b03, traverse the database shard information and add the shards that meet the conditions to the query address list.
[0088] According to the database shard information corresponding to the processed data, the corresponding stored database name and collection name are obtained. According to the collection database name and collection name, each shard under the corresponding collection is obtained. Combined with the online application node list, the application node to which the data storage location of each shard under the corresponding collection belongs is placed in the online application node column, and the data storage location of the shard is added to the query address list. Through step b03, the location of data query is narrowed down, avoiding the "needle in a haystack" type of data search.
[0089] Specifically, if a shard contains multiple data storage locations, if the application node to which the primary data storage location belongs is online, the primary data storage location of the shard is added to the query address list; if the application node to which the primary data storage location of the shard belongs is not online, and the application node to which the primary backup data storage location of the shard belongs is online, the backup data storage location of the shard is added to the query address list; if both the primary data storage location and the backup data storage location of the shard are not online, the database shard information of the shard is recorded in the error log.
[0090] Step b04, traverse the query address list and perform corresponding processing according to the data processing information.
[0091] Specifically, based on the query address list obtained in step b04, corresponding modification instructions, deletion instructions or query instructions are sent according to the processing information to process the database data that meets the conditions.
[0092] Step b05, feeding back the data processing result to the application client.
[0093] According to the data processing result in step b04, the data processing result is fed back to the application client.
[0094] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0095] A fifth embodiment of the present invention relates to a computer-readable storage medium storing a computer program, which implements the above method embodiment when executed by a processor.
[0096] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0097] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present invention, and in practical applications, various changes may be made to them in form and detail without departing from the spirit and scope of the present invention. Any person skilled in the art may make their own changes and modifications without departing from the spirit and scope of the present invention, so the protection scope of the present invention shall be subject to the scope defined in the claims.
Claims
1. A storage system based on MongoDB, characterized in that: include: Configure clusters, service clusters, and multiple application nodes; The configuration cluster is used to store an online application node list and database sharding information, wherein the online application node list includes online application nodes among the multiple application nodes, and the service cluster is used to interact with the application client for data, wherein the service cluster responds to the application client's operation on the database, processes the configuration cluster and the data stored in the application node, and feeds back the data processing result to the application client, and the service cluster is a stateless service; The service cluster is used to determine whether there is a target shard into which the data to be inserted can be inserted when monitoring that the application client generates data to be inserted, based on the database shard information stored in the configuration cluster, the number of records in the database shard information of the target shard is less than a preset maximum value, and the application node to which the data storage location of the target shard belongs is located in the online application node list; If the target shard does not exist, monitoring whether there is a new application node in the online application nodes based on the acquired online application node list; If there is a new application node, use the new application node as the data storage location of the new shard, create a new shard, and store the data to be inserted in the data storage location of the new shard; Upload the database shard information of the new shard to the configuration cluster, wherein the database shard information of the new shard includes the newly added data and the data storage location of the new shard; Also includes new application nodes; The new application node registers the MongoDB shard storage server provided by the new application node with the service cluster; The configuration cluster updates the online application node list, and the updated online application node list includes the new application node; The service cluster is used to use the new application node as the data storage location of the new slice when detecting that the new application node exists in the online application node list.
2. The MongoDB-based storage system according to claim 1, characterized in that: The determining whether there is a target shard into which the data to be inserted can be inserted based on the database shard information stored in the configuration cluster includes: The service cluster obtains the database shard information stored by the configuration cluster; The service cluster queries the configuration cluster based on the database shard information to obtain a shard list; The service cluster queries the configuration cluster to obtain a list of online application nodes; The service cluster traverses the shard list and determines whether there is a target shard into which the data to be inserted exists according to the online application node list.
3. The MongoDB-based storage system according to claim 1, characterized in that: The application node is also used to synchronize the data stored in the MongoDB shard storage server to the MongoDB shard storage servers of other application nodes.
4. The MongoDB-based storage system according to claim 1, characterized in that: The configuration cluster is also used to detect and obtain whether the connection status between the configuration cluster and the application node has changed, and based on the change in the connection status between the configuration cluster and the application node, update the MongoDB shard storage server of the application node under the online application node list.
5. The MongoDB-based storage system according to claim 4, characterized in that: The updating of the MongoDB shard storage server of the application node under the online application node list based on the change of the connection state between the configuration cluster and the application node includes: When the configuration cluster detects that the connection state changes from unconnected to connected, the MongoDB shard storage server of the application node is added to the online application node list; When the configuration cluster detects that the connection state is changed from connected to unconnected, the MongoDB shard storage server of the application node under the online application node list is deleted.
6. The MongoDB-based storage system according to claim 1, characterized in that: The data storage locations of the shards include: a primary data storage location and a backup data storage location; The service cluster selects the application node in the online application node list as the data storage location of the new shard, and stores the to-be-inserted data in the data storage location of the new shard, including: The service cluster selects at least two application nodes from the online application node list as the primary data storage location of the new shard and the backup data storage location of the new shard respectively.
7. A data insertion method, based on the MongoDB storage system according to any one of claims 1 to 6, characterized in that: include: Obtain the data to be inserted from the application client, and determine whether there is a target shard, the number of records in the target shard is less than a preset maximum value, and the application node to which the data storage location of the target shard belongs is in the online application node list; If the target shard does not exist, monitoring whether there is a new application node in the online application nodes based on the acquired online application node list; If there is a new application node, use the new application node as the data storage location of the new shard, create a new shard, and store the data to be inserted in the data storage location of the new shard; Upload the database shard information of the new shard to the configuration cluster, wherein the database shard information of the new shard includes the newly added data and the data storage location of the new shard; Return the insertion result of the data to be inserted to the application client.
8. A data insertion method according to claim 7, characterized in that: include: The service cluster is used to use the new application node as the data storage location of the new slice when detecting that the new application node exists in the online application node list.
9. A non-volatile storage medium for storing a computer-readable program, characterized in that: When the computer-readable program is executed by a processor, the data insertion method according to any one of claims 7 or 8 is implemented.
