Sub-library and sub-table switching method, device and system based on proxy mode

Through the proxy mode-based sub-database and sub-table switching method, the problems of complex switching process and poor flexibility in the existing technology are solved, the decoupling of data read/write logic and business logic is realized, and the switching efficiency and flexibility are improved.

CN112181939BActive Publication Date: 2025-01-21SHENZHEN WEIBAO INFORMATION SERVICE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010854101.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-20
Publication Date
2025-01-21
Estimated Expiration
2040-08-20

AI Technical Summary

Technical Problem

When switching single-base single-base tables into sub-base tables in the prior art, two sets of customized logic codes need to be re-edited, resulting in poor flexibility, high coupling, and complex and time-consuming switching process.

Method used

Adopt the sub-database and sub-table switching method based on the proxy mode, load the data source configuration file through the pre-configured data agent component, generate the data source link, and perform the sub-database and sub-table read/write operations according to the data source identification and operation instructions to achieve Decoupling of data source switching.

Benefits of technology

It achieves the decoupling of data read/write logic and business logic. The data read/write logic is transparent to the business, reduces the amount of repeated code development, and improves the efficiency and flexibility of the switching process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112181939B_ABST
    Figure CN112181939B_ABST
Patent Text Reader

Abstract

The embodiment of the present application relates to a method, device and system for switching between sub-libraries and sub-tables based on a proxy mode, the method comprising: loading a pre-configured data source configuration file, generating a link according to the data source configuration file and storing it in a data source set; receiving a pre-configured data source identifier transmitted by a business logic layer; obtaining a data source link corresponding to the data source identifier from the data source set according to the current data read / write operation instruction and the data source identifier, and obtaining data in the data source according to the data source link; and, according to the current data read / write operation instruction, executing sub-libraries and sub-tables read / write operations. Through the above-mentioned method, the decoupling between the data read / write logic layer and the business logic layer is achieved, and the multi-data source switching component can be flexibly plugged in and out without being invasive, which greatly reduces the amount of repeated code development, and truly achieves reliability, speed and simplicity, thereby greatly speeding up the switching process of sub-libraries and sub-tables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, device and system for switching between sub-libraries and sub-tables based on a proxy mode. Background Art

[0002] As time goes by and business develops, there will be more and more tables in the database, and the amount of data in the tables will also increase. This undoubtedly puts a considerable load on the database, affecting the stability and performance of the system. Switching the original single database and single table to a component database and a sub-table is the most common and effective way to solve such problems. In the prior art, every time a single database and a single table needs to be switched to a component database and a sub-table, two sets of logic codes need to be re-edited, one of which is the logic code for business reading / writing based on the old database and asynchronously writing to the new database. The other set is the logic code for reading / writing business based on the new database and asynchronously writing to the old database. Both sets of logic codes are customized logic codes, which cannot be universally implemented for different businesses and have poor flexibility. Once the business code is adjusted, the two sets of codes also need to be adjusted, that is, the business code is coupled, which increases the complexity of the switching process and requires a long switching time.

[0003] So, how to make the business sub-library and sub-table read / write logic code universal, improve flexibility, and decouple it from the business code, reduce the complexity of the switching process, and reduce the switching time becomes the technical problem to be solved by this application. Summary of the invention

[0004] In view of this, in order to solve the technical problems in the prior art, the embodiments of the present application provide a method, device and system for switching between sub-libraries and sub-tables based on a proxy mode.

[0005] The embodiment of the present application provides a method for switching between sub-libraries and sub-tables based on a proxy mode, the method being executed by a preconfigured data proxy component, the method comprising:

[0006] Load the preconfigured data source configuration file, generate a link based on the data source configuration file and store it in the data source collection;

[0007] Receive the pre-configured data source identifier passed by the business logic layer;

[0008] According to the pre-configured data read / write operation instruction and the data source identifier, a data source link corresponding to the data source identifier is obtained from the data source set, and data in the data source corresponding to the data source identifier is obtained according to the data source link;

[0009] According to the data read / write operation instruction and the preconfigured data source indication instruction, the sub-library and sub-table read / write operation is performed on the data in the data source, wherein the data source indication instruction is used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written. In one possible implementation, when the links generated according to the first data source configuration file include multiple links, a first link pool is configured in the data source set to carry the links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files loaded.

[0010] In one possible implementation, the preconfigured data read / write operation instructions include: read old database logic instructions, write old database logic instructions, asynchronously write new database logic instructions, read new database logic instructions, write new database logic instructions, and asynchronously write old database logic instructions.

[0011] In a possible implementation, the data source includes a new data source corresponding to the data in the new database, and an old data source corresponding to the data in the old database; the data source indication instruction includes: a new data source call instruction and an old data source call instruction; according to the preconfigured data read / write operation instruction and the data source identifier, a data source link corresponding to the data source identifier is obtained from the data source set, and data in the data source is obtained according to the data source link, specifically including:

[0012] In the first stage, according to the new data source call instruction and the data source identifier corresponding to the new data source, the new data source link is obtained from the data source set, and the data in the new data source is obtained according to the new data source link;

[0013] In the second stage, according to the old data source calling instruction and the data source identifier corresponding to the old data source, the old data source link is obtained from the data source set, and the data in the old data source is obtained according to the old data source link.

[0014] In a possible implementation, according to the data read / write operation instruction and the preconfigured data source indication instruction, performing the sub-library and sub-table read / write operation on the data in the data source specifically includes:

[0015] In the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and, according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database;

[0016] When the data in the old database reaches consistency with the data in the new database, the second stage begins;

[0017] In the second stage, according to the logical instruction of writing a new database, the data in the new data source is written into the new database;

[0018] And according to the logical instruction of reading the new database and the logical instruction of asynchronously writing the old database, after reading the data in the new database, the data in the new database is asynchronously written into the old database;

[0019] When it is determined that the data writing work in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

[0020] In one possible implementation, the data read / write operation instruction also includes specific location information of the data to be written, so that when a sub-library and sub-table read / write operation is performed on the data in the data source according to the pre-configured data read / write operation instruction and the data source indication instruction, the data corresponding to the data read / write operation instruction is written to the specific location of the sub-library and sub-table.

[0021] In a possible implementation, in the first stage, when data in the new data source is written into the old database according to the write old database logic instruction, and data in the old database is asynchronously written into the new database after the data in the old database is read according to the asynchronous write new database logic instruction and the read old database logic instruction, if the first data in the old database has been stored in the new database, then the update time of the first data in the old database and the new database is respectively determined;

[0022] When the update time of the first data in the old data is the latest update time, the first data in the old database is overwritten and written into the new database;

[0023] Alternatively, when it is determined that the update time of the first data in the old database is later than the update time of the first data in the new database, the first data is abandoned from being written into the new database, wherein the first data is any piece of data in the old database.

[0024] The embodiment of the present application provides a sub-library and sub-table switching device based on a proxy mode, the device comprising:

[0025] A processing unit, used to load a pre-configured data source configuration file, generate a link according to the data source configuration file and store it in a data source set;

[0026] A receiving unit, receiving a pre-configured data source identifier transmitted by the business logic layer;

[0027] an acquisition unit, configured to acquire a data source link corresponding to the data source identifier from the data source set according to a preconfigured data read / write operation instruction and a data source identifier, and acquire data in a data source corresponding to the data source identifier according to the data source link;

[0028] The processing unit is also used to perform sub-library and sub-table read / write operations on data in the data source according to data read / write operation instructions and pre-configured data source indication instructions, wherein the data source indication instruction is used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written.

[0029] In one possible implementation, when the links generated according to the first data source configuration file include multiple links, a first link pool is configured in the data source set to carry the links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files loaded.

[0030] The embodiment of the present application provides a sub-library and sub-table switching system based on a proxy mode, the system comprising:

[0031] A storage module, used to store pre-configured data source configuration files;

[0032] A data source switching module is used to retrieve a pre-configured data source configuration file stored in the memory, generate a link according to the data source configuration file, and store it in a data source set;

[0033] The business logic module is used to pass the pre-configured data source identifier to the data source switching module;

[0034] The data source switching module is further used to obtain a data source link corresponding to the data source identifier from the data source set according to the pre-configured data read / write operation instruction and the data source identifier transmitted by the business logic module, and obtain data in the data source corresponding to the data source identifier according to the data source link;

[0035] The data source switching module is also used to perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions.

[0036] An embodiment of the present application provides a computer device, the computer device comprising:

[0037] at least one processor and memory;

[0038] The processor is used to execute the proxy mode-based sub-library and sub-table switching program stored in the memory to implement the proxy mode-based sub-library and sub-table switching method introduced in any implementation manner of the first aspect.

[0039] An embodiment of the present application provides a computer storage medium, which stores one or more programs. The one or more programs can be executed by the computer device introduced in the third aspect to implement the proxy mode-based library and table switching method introduced in any implementation method of the first aspect.

[0040] The embodiment of the present application provides a method for switching between sub-libraries and sub-tables based on the proxy mode. Through the above method, the decoupling between the data read / write logic layer and the business logic layer is achieved. The data read / write logic is completely transparent to the business logic layer. The business logic layer no longer cares about the data read / write operation. It only needs to pass the data source identifier to the downstream. The multi-data source switching component is used as a proxy to complete the data read / write operation, making the heavy multi-data source operation transparent to the business. Moreover, the multi-data source switching component can be flexibly plugged in and out, and can be completely universal, eliminating the disadvantages of adding a new data source and modifying the code to add a data read / write logic layer corresponding to the new data source. The application is flexible and complies with the open-closed principle. Moreover, the business code is isolated and non-invasive, thereby greatly reducing the amount of repeated code development. At the same time, in the dual-write switching process, you only need to switch the data source configuration to switch the write-read data source, which is truly reliable, fast, and concise, thereby greatly speeding up the switching process of sub-libraries and sub-tables. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A schematic diagram of a process flow of a sub-library and sub-table switching method based on a proxy mode provided in an embodiment of the present application;

[0042] Figure 2 A structural block diagram of the multi-data source proxy component provided in this application obtaining the data to be read / written before executing the sub-library and sub-table switching;

[0043] Figure 3 A schematic diagram of the proxy mode structure provided for this application;

[0044] Figure 4 A structural diagram of the process of switching between sub-libraries and sub-tables performed by the multi-data source proxy component provided in this application;

[0045] Figure 5 A schematic diagram of the structure of a sub-library and sub-table switching device based on a proxy mode provided in an embodiment of the present application;

[0046] Figure 6 A schematic diagram of a sub-library and sub-table switching system architecture based on a proxy mode provided in an embodiment of the present application;

[0047] Figure 7 A schematic diagram of the structure of a computer device is provided for an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0049] To facilitate understanding of the embodiments of the present application, further explanation will be given below with reference to specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present application.

[0050] Figure 1 A schematic diagram of a method for switching between sub-libraries and sub-tables based on a proxy mode is provided in an embodiment of the present application, as shown in FIG. Figure 1 As shown, the method is executed by a multi-data source switching component, and the method includes:

[0051] Step 110, load a pre-configured data source configuration file, generate a link according to the data source configuration file and store it in a data source set.

[0052] Specifically, the data source configuration file may include the user name, password, specific location and other information of the data source. Links are subsequently generated based on this information and stored in the data source collection. The purpose of generating links is to be able to directly find the data source and obtain the corresponding data from it based on the link information.

[0053] Optionally, considering that each call to the same data source may include more than one proxy component, multiple links can be generated based on the data source configuration file, and then the multiple links generated based on the same data source configuration file are added to a link pool. Figure 2 In the example, multiple links generated by the configuration file of data source A are added to the connection pool of data source A, and multiple links generated by the configuration file of data source B are added to the connection pool of data source B. Further, as an alternative, Figure 2 As shown, the data source may include more than one, and may include multiple. Therefore, the data source set may include multiple data source connection pools, and each data source connection pool is connected to its corresponding data source.

[0054] That is, when there are multiple links generated according to the first data source configuration file, a first link pool is configured in the data source set to carry the links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files loaded.

[0055] See Figure 2 As shown, Figure 2The structure diagram of the multi-data source proxy component obtaining the data to be read / written before executing the sub-library and sub-table switching is shown.

[0056] Figure 2 The left side shows the configuration file corresponding to each data source. Figure 2 The figure shows the configuration files corresponding to data source A and data source B. The middle part is the data source switching proxy component, which is used to initialize the data source connection pool, which is actually the process of establishing data source combination and connection between data sources. In addition, it routes the data to the business background to complete the final data sub-library and sub-table reading / writing tasks.

[0057] In step 110, a link is generated according to the data source configuration file and stored in the data source collection. In the following, the process of obtaining data and routing it to the business background to complete the data reading / writing process will be further introduced. Please refer to the following steps for details:

[0058] Step 120: Receive a pre-configured data source identifier transmitted by the business logic layer.

[0059] Specifically, the business layer only needs to pass the pre-configured data source identifier to the multiple data source switching component. The business layer no longer pays attention to the data read / write operation, but only needs to transmit the pre-configured data source identifier.

[0060] Optionally, a database operation handle parameter can also be passed down to instruct the multi-data source switching component to perform operations other than read / write on the data in the data source. The multi-data source switching component replaces the business background to perform multi-data source switching operations, making the heavy multi-data source operations transparent to the business. It is also through this way that the decoupling between data read / write operations and business codes is achieved. The data read / write operation instructions are stored in the multi-data source switching component, which is independent of the business and can be applied to various data source switching businesses, with strong versatility and flexibility.

[0061] Figure 3 The structure diagram of the proxy pattern is shown in . In an object-oriented system, some objects have certain reasons, such as high object creation overhead, or some operations require security control, or require out-of-process access, etc. Direct access will cause a lot of trouble to users or system architecture. Therefore, when accessing this object, you can add an access layer to this object, and then this access layer is the proxy of the object. The proxy pattern provides a proxy for other objects to control access to this object. The proxy object acts as an intermediary between the client and the target object. The proxy pattern can separate the proxy object from the target object called by the real object, which reduces the coupling of the system to a certain extent, thereby improving the scalability of the system. In this embodiment, the multi-data source switching component plays the role of a proxy. The general class diagram of the proxy pattern is shown in the figure. Figure 3 As shown:

[0062] Subject is an abstract class or an interface. It is the most common business type definition with no special requirements.

[0063] RealSubject is a subclass or implementation class of Subject, and it is the proxy role and the specific executor of business logic.

[0064] Proxy is called a proxy class, which is responsible for the application of real objects. It does pre-processing and post-processing before and after the real objects are processed.

[0065] In this embodiment, Figure 3 The Subject in the above code can be understood as the business logic layer. The real execution subject of the business logic layer is the RealSubject, which is the one that performs the real data read and write operations according to the database operation handle parameters. Figure 3 The Proxy in this implementation is the multi-data source switching component.

[0066] Specific operation procedures may include:

[0067] 1. The business logic layer (Subject) obtains the data source identifier and database operation handle from the client (client), and passes the data source identifier and database operation handle to the proxy, that is, the multi-data source switching component (Proxy) through the docking interface.

[0068] 2. The multi-data source switching component (Proxy) obtains the corresponding data source information according to the data source identifier, connects to the database according to the data source information, and calls the read-write module (RealSubject) to execute the database operation handle to perform data read and write operations.

[0069] 3. The multi-data source switching component (Proxy) returns the results of data read and write operations to the business logic layer (Subject).

[0070] In this embodiment, the specific process of obtaining the data source information, connecting to the database according to the data source information, and performing the read and write operations can be referred to steps 130 to 140.

[0071] Step 130, according to the preconfigured data read / write operation instruction and the data source identifier, obtain the data source link corresponding to the data source identifier from the data source set, and obtain the data in the data source according to the data source link.

[0072] Step 140: Perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions.

[0073] Specifically, the data source identifier is used to indicate the data source to be obtained. This facilitates the subsequent matching of the corresponding data source link from the data source set, or the matching of the corresponding data source link pool from the data source set, and then extracting a link from the link pool. The data source identifier includes: data source name, data source ID, etc.

[0074] The data source indication instruction is used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written;

[0075] The preconfigured data read / write operation instructions include: read old database logic instructions, write old database logic instructions, asynchronous write new database logic instructions, read new database logic instructions, write new database logic instructions and asynchronous write old database logic instructions.

[0076] The data source includes a new data source corresponding to the data in the new database and an old data source corresponding to the data in the old database, and the data source indication instruction includes: a new data source calling instruction and an old data source calling instruction.

[0077] When step 130 is specifically performed, it is mainly divided into two stages.

[0078] In the first stage, according to the new data source call instruction and the data source identifier corresponding to the new data source, a new data source link is obtained from the data source set, and data in the new data source is obtained according to the new data source link;

[0079] In the second stage, according to the old data source calling instruction and the data source identifier corresponding to the old data source, the old data source link is obtained from the data source set, and the data in the old data source is obtained according to the old data source link.

[0080] Specifically, the first phase is mainly to write to the old database, supplemented by writing to the new database. The data in the new data table is first written to the old database. At this time, all the data in the old database is asynchronously written to the new database.

[0081] When the data in the old database and the data in the new database reach data consistency, the second stage begins.

[0082] The new database is mainly written, and the old database is used as a supplement. The purpose is to prevent logical errors after the data is written to the new database. In this case, the old database is used as a backup. The data in the database can be read / written to ensure that the business can be executed normally.

[0083] Specifically, if the data reading / writing tasks in the above two stages are completed, please refer to the following:

[0084] In the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database.

[0085] When the data in the old database reaches consistency with the data in the new database, the second stage begins;

[0086] In the second stage, according to the logical instruction of writing a new database, the data in the new data source is written into the new database;

[0087] And according to the new database reading logic instruction and the old database asynchronous writing logic instruction, after reading the data in the new database, the data in the new database source is asynchronously written into the old database;

[0088] When it is determined that the data writing work in the new database is completed, the old database is deleted, and all operation instructions for the old database are deleted, such as the above-mentioned read old database logic instructions, write old database logic instructions, asynchronous write old database logic instructions, and old data source call instructions. At the same time, the asynchronous write new database logic instructions also need to be deleted. Because the writing of data to the old database has been stopped, and the subsequent writing is to the new database, the asynchronous write new database logic instructions are no longer used.

[0089] Specifically, how to determine whether the data in the old database and the new database are consistent, and when the data is no longer written to the old database, needs to be implemented according to the following methods:

[0090] In the first stage, the data is written to the old database and the data in the old database is read asynchronously. When the data is asynchronously written to the new database, if the data in the old database has not been written, but it has been stored in the new database, then the data update time is determined. If the data update time in the old database is the latest update time, the data in the old database is overwritten and written to the new database. If the update time is later than the new database, it means that the data in the old database has already been completely written to the new database, and the data is abandoned and written to the new database. After the data in the old database completes a round of operations (whether it is all written or abandoned according to the above comparison operation, etc.), the data in the new and old databases are compared again to determine whether there is any inconsistency.

[0091] If there is any inconsistency, the data synchronization operation is performed again, and the cycle is repeated until the data is completely consistent, and then the second stage is entered.

[0092] In the second stage, when executing "reading and writing mainly to the new database, asynchronously writing to the old database", as long as it is determined that the business processing is normal and the data is normal, you can remove "asynchronous writing to the old database", and the data will no longer be written to the old database.

[0093] See Figure 4 As shown, Figure 4 The structural diagram of the multi-data source proxy component provided in this application to perform the sub-library and sub-table switching process is shown in Figure 4 The figure shows the process of completing the data double writing at different stages.

[0094] Figure 4 The left side of the middle shows the completion of the first phase of data double writing process. Figure 4 The right side shows the data double writing process that completes the second phase.

[0095] It should be noted that the multi-data source switching component is a component that can be embedded in the business code. As described above, the multi-data source switching component can include data read / write operation instructions and data source indication instructions. Before executing the multi-data source logic switching and read / write operations, the staff only needs to adaptively adjust the data source information indicated in the data source indication instruction, and then insert the multi-data source switching component into the upper layer of the data read / write interface. The business logic layer only needs to pass the pre-configured data source identifier, and optionally, it can also include the database operation handle parameter. In this way, the data read / write logic and the business operation logic are decoupled, and the multi-data source switching component can be dynamically plugged and unplugged, isolate the business code, and be non-invasive, thereby greatly reducing the amount of duplicate code development. At the same time, in the dual-write switching process, only the data source configuration needs to be switched to switch the write and read data source, which is truly reliable, fast, and concise, thereby greatly speeding up the switching process of the sub-library and sub-table. Moreover, the component replaces the business background to perform the multi-data source switching operation, making the heavy multi-data source operation transparent to the business.

[0096] For example, when a new data source is added, there is no need to rewrite a set of data read / write logic corresponding to the new data source. You can directly use the data read / write operation instructions introduced above. And configure an additional set of data source indication instructions, that is, tell the business data read / write instructions when to read the new data source. Generate a link corresponding to the new data source, add it to the data source collection, and configure the data source identifier in the data read / write logic layer, so that you can find the link corresponding to the new data source identifier in the data source collection according to the data source identifier corresponding to the new data source, and obtain the data in the new data source according to the link.

[0097] The proxy-based switching method for sub-libraries and sub-tables provided in the embodiment of the present application realizes the decoupling between the data read / write logic layer and the business logic layer through the above-mentioned method. The data read / write logic is completely transparent to the business logic layer. The business logic layer no longer cares about the data read / write operation. It only needs to pass the data source identifier to the downstream. The multi-data source switching component is used as a proxy to complete the data read / write operation, making the heavy multi-data source operation transparent to the business. Moreover, the multi-data source switching component can be flexibly plugged in and out, and can be completely universal, eliminating the disadvantages of adding a new data source and modifying the code to add a data read / write logic layer corresponding to the new data source. It is flexible in application and complies with the opening and closing principle. Moreover, it isolates the business code and is non-invasive, thereby greatly reducing the amount of repeated code development. At the same time, in the dual-write switching process, you only need to switch the data source configuration to switch the write-read data source, which is truly reliable, fast, and concise, thereby greatly speeding up the switching process of sub-libraries and sub-tables.

[0098] Figure 5 A sub-library and sub-table switching device based on a proxy mode is provided in an embodiment of the present application. The device includes: a processing unit 501, a receiving unit 502 and an acquiring unit 503.

[0099] Processing unit 501 is used to load a pre-configured data source configuration file, generate a link according to the data source configuration file and store it in a data source set;

[0100] A receiving unit 502 receives a pre-configured data source identifier transmitted by the business logic layer;

[0101] The acquisition unit 503 is used to acquire a data source link corresponding to the data source identifier from the data source set according to the pre-configured data read / write operation instruction and the data source identifier, and acquire data in the data source corresponding to the data source identifier according to the data source link;

[0102] The processing unit 501 is also used to perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions, wherein the data source indication instructions are used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instructions is read / written.

[0103] Optionally, when there are multiple links generated according to the first data source configuration file, a first link pool is configured in the data source collection to carry links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files loaded.

[0104] Optionally, the preconfigured data read / write operation instructions include: read old database logical instructions, write old database logical instructions, asynchronously write new database logical instructions, read new database logical instructions, write new database logical instructions and asynchronously write old database logical instructions.

[0105] Optionally, the acquisition unit 503 is specifically configured to: the data source includes a new data source corresponding to the data in the new database, and an old data source corresponding to the data in the old database; the data source indication instruction includes: a new data source call instruction and an old data source call instruction; according to the pre-configured data read / write operation instruction and the data source identifier, obtain a data source link corresponding to the data source identifier from the data source set, and obtain data in the data source according to the data source link, specifically including:

[0106] In the first stage, according to the new data source call instruction and the data source identifier corresponding to the new data source, a new data source link is obtained from the data source set, and data in the new data source is obtained according to the new data source link;

[0107] In the second stage, according to the old data source calling instruction and the data source identifier corresponding to the old data source, the old data source link is obtained from the data source set, and the data in the old data source is obtained according to the old data source link.

[0108] Optionally, the processing unit 501 is specifically configured to, in the first stage, write the data in the new data source into the old database according to the write old database logic instruction; and asynchronously write the data in the old database into the new database after reading the data in the old database according to the asynchronous write new database logic instruction and the read old database logic instruction;

[0109] When the data in the old database reaches consistency with the data in the new database, the second stage begins;

[0110] In the second stage, according to the logical instruction of writing a new database, the data in the new data source is written into the new database;

[0111] And according to the new database reading logic instruction and the old database asynchronous writing logic instruction, after reading the data in the new database, the data in the new database source is asynchronously written into the old database;

[0112] When it is determined that the data writing work in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

[0113] Optionally, the data read / write operation instruction also includes specific location information of the data to be written, so that when a sub-library and sub-table read / write operation is performed on the data in the data source according to the pre-configured data read / write operation instruction and data source indication instruction, the data corresponding to the data read / write operation instruction is written to the specific location of the sub-library and sub-table.

[0114] The functions performed by each functional component in the sub-library and sub-table switching device based on the proxy mode provided in this embodiment are all in Figure 1 The corresponding embodiments have been described in detail, so they will not be described again here.

[0115] The embodiment of the present application provides a sub-library and sub-table switching device based on the proxy mode. Through the above method, the decoupling between the data read / write logic layer and the business logic layer is realized. The data read / write logic is completely transparent to the business logic layer. The business logic layer no longer cares about the data read / write operation. It only needs to pass the data source identifier to the downstream. The multi-data source switching component is used as a proxy to complete the data read / write operation, making the heavy multi-data source operation transparent to the business. Moreover, the multi-data source switching component can be flexibly plugged in and out, and can be completely universal, eliminating the disadvantages of adding a new data source and modifying the code to add a data read / write logic layer corresponding to the new data source. The application is flexible and complies with the opening and closing principle. Moreover, the business code is isolated and non-invasive, thereby greatly reducing the amount of repeated code development. At the same time, in the dual-write switching process, only the data source configuration needs to be switched to switch the write and read data source, which is truly reliable, fast, and concise, thereby greatly speeding up the switching process of sub-library and sub-table.

[0116] Figure 6 A schematic diagram of a sub-library and sub-table switching system architecture based on a proxy mode is provided in the embodiment of the present application. Figure 6 As shown, the system includes: a storage module 601 , a data source switching module 602 and a business logic module 603 .

[0117] Storage module 601, used to store pre-configured data source configuration files;

[0118] The data source switching module 602 is used to retrieve the pre-configured data source configuration file stored in the storage module 601, and generate a link according to the data source configuration file and store it in the data source set;

[0119] The business logic module 603 is used to transmit the pre-configured data source identifier to the data source switching module 602;

[0120] The data source switching module 602 is further used to obtain a data source link corresponding to the data source identifier from the data source set according to the pre-configured data read / write operation instruction and the data source identifier transmitted by the business logic module 603, and obtain data in the data source corresponding to the data source identifier according to the data source link;

[0121] The data source switching module 602 is further used to perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions.

[0122] The functions performed by each functional component in the sub-library and sub-table switching device based on the proxy mode provided in this embodiment are all in Figure 1 The corresponding embodiments have been described in detail, so they will not be described again here.

[0123] The embodiment of the present application provides a sub-library and sub-table switching system based on the proxy mode. Through the above method, the decoupling between the data read / write logic layer and the business logic layer is realized. The data read / write logic is completely transparent to the business logic layer. The business logic module no longer cares about the data read / write operation. It only needs to pass the data source identifier to the downstream. The multi-data source switching module is used as a proxy to complete the data read / write operation, making the heavy multi-data source operation transparent to the business. Moreover, the multi-data source switching module can be flexibly plugged in and out and can be completely universal, eliminating the disadvantages of adding a new data source and modifying the code to add a data read / write logic layer corresponding to the new data source. The application is flexible and complies with the opening and closing principle. Moreover, the business code is isolated and non-invasive, thereby greatly reducing the amount of repeated code development. At the same time, in the dual-write switching process, you only need to switch the data source configuration to switch the write and read data source, which is truly reliable, fast, and concise, thereby greatly speeding up the switching process of sub-library and sub-table.

[0124] Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of the present application is provided. Figure 7 The computer device 700 shown includes: at least one processor 701, a memory 702, at least one network interface 703 and other user interfaces 704. The components in the computer device 700 are coupled together through a bus system 705. It can be understood that the bus system 705 is used to implement link pool communication between these components. In addition to the data bus, the bus system 705 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 705 is not used in the following examples. Figure 7 Various buses are labeled as bus system 705.

[0125] The user interface 704 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).

[0126] It can be understood that the memory 702 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link pool dynamic random access memory (SLDRAM) and direct memory bus random access memory (DRRAM). The memory 702 described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0127] In some implementations, the memory 702 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 7021 and an application program 7022 .

[0128] The operating system 7021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 7022 includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present application can be included in the application 7022.

[0129] In the embodiment of the present application, by calling the program or instruction stored in the memory 702, specifically, the program or instruction stored in the application 7022, the processor 701 is used to execute the method steps provided by each method embodiment, for example, including:

[0130] Load the preconfigured data source configuration file, generate a link based on the data source configuration file and store it in the data source collection;

[0131] Receive the pre-configured data source identifier passed by the business logic layer;

[0132] According to the pre-configured data read / write operation instruction and the data source identifier, a data source link corresponding to the data source identifier is obtained from the data source set, and data in the data source corresponding to the data source identifier is obtained according to the data source link;

[0133] According to the data read / write operation instructions and the pre-configured data source indication instructions, the sub-library and sub-table read / write operations are performed on the data in the data source, wherein the data source indication instruction is used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written.

[0134] Optionally, when there are multiple links generated according to the first data source configuration file, a first link pool is configured in the data source collection to carry links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files loaded.

[0135] Optionally, the preconfigured data read / write operation instructions include: read old database logical instructions, write old database logical instructions, asynchronously write new database logical instructions, read new database logical instructions, write new database logical instructions and asynchronously write old database logical instructions.

[0136] Optionally, the data source includes a new data source corresponding to the data in the new database, and an old data source corresponding to the data in the old database; the data source indication instruction includes: a new data source calling instruction and an old data source calling instruction;

[0137] In the first stage, according to the new data source call instruction and the data source identifier corresponding to the new data source, the new data source link is obtained from the data source set, and the data in the new data source is obtained according to the new data source link;

[0138] In the second stage, according to the old data source calling instruction and the data source identifier corresponding to the old data source, the old data source link is obtained from the data source set, and the data in the old data source is obtained according to the old data source link.

[0139] Optionally, in the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database;

[0140] When the data in the old database reaches consistency with the data in the new database, the second stage begins;

[0141] In the second stage, according to the logical instruction of writing a new database, the data in the new data source is written into the new database;

[0142] And according to the new database reading logic instruction and the old database asynchronous writing logic instruction, after reading the data in the new database, the data in the new database source is asynchronously written into the old database;

[0143] When it is determined that the data writing work in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

[0144] Optionally, the data read / write operation instruction also includes specific location information of the data to be written, so that when a sub-library and sub-table read / write operation is performed on the data in the data source according to the pre-configured data read / write operation instruction and data source indication instruction, the data corresponding to the data read / write operation instruction is written to the specific location of the sub-library and sub-table.

[0145] The method disclosed in the above embodiment of the present application can be applied to the processor 701, or implemented by the processor 701. The processor 701 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 701 or the instruction in the form of software. The above processor 701 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 702, and the processor 701 reads the information in the memory 702 and completes the steps of the above method in combination with its hardware.

[0146] It is understood that the embodiments described herein can be implemented by hardware, software, firmware, middleware, microcode or a combination thereof. For hardware implementation, the processing unit 701701 can be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions of the present application or a combination thereof.

[0147] For software implementation, the technology of this article can be implemented by a unit that performs the functions of this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.

[0148] The computer device provided in this embodiment may be as follows Figure 7 The computer device shown in , can execute Figure 1 All steps of the proxy-based switching method of database and table sharding are implemented Figure 1 The technical effect of the proxy-based switching method of sharding is shown in the figure. For details, please refer to Figure 1 For the sake of brevity, the relevant description is not repeated here.

[0149] The present application also provides a computer storage medium, which stores one or more programs. The one or more programs can be used as follows: Figure 7 The corresponding computer device executes to implement the proxy mode-based sub-library and sub-table switching method introduced in any implementation method of Example 1.

[0150] An embodiment of the present application also provides a computer program including computer instructions, which are stored in a computer-readable storage medium; a processor in a computer device such as the one introduced above reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the proxy mode-based sub-library and sub-table switching method introduced in any implementation method in Example 1.

[0151] The professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0152] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0153] The above specific implementation methods further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above are only specific implementation methods of the present application and are not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. A method for switching between sub-libraries and sub-tables based on proxy mode, characterized in that: The method is applied to a multi-data source switching component, and the method includes: Loading a preconfigured data source configuration file, generating a link according to the data source configuration file and storing the link in a data source set; wherein the data source set includes a plurality of data source connection pools, each of which stores a link generated by the same data source configuration file; Receive the pre-configured data source identifier passed by the business logic layer; According to the preconfigured data read / write operation instruction and the data source identifier, a data source link corresponding to the data source identifier is obtained from the data source set, and data in the data source corresponding to the data source identifier is obtained according to the data source link; According to the data read / write operation instruction and the preconfigured data source indication instruction, perform sub-library and sub-table read / write operations on the data in the data source, wherein the data source indication instruction is used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written; The performing of the sub-library and sub-table read / write operation on the data in the data source according to the data read / write operation instruction and the pre-configured data source indication instruction specifically includes: In the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database; When the data in the old database reaches data consistency with the data in the new database, the second stage is entered; In the second stage, according to the logic instruction of writing a new database, the data in the old data source is written into the new database; And according to the read new database logic instruction and the asynchronous write old database logic instruction, after reading the data in the new database, asynchronously write the data in the new database into the old database; When it is determined that the writing of data in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

2. The method according to claim 1, characterized in that: When there are multiple links generated according to the first data source configuration file, a first link pool is configured in the data source set to carry links corresponding to the first data source configuration file, wherein the first data source configuration file is any one of the preconfigured data source configuration files.

3. The method according to claim 1 or 2, characterized in that: The preconfigured data read / write operation instructions include: read old database logic instructions, write old database logic instructions, asynchronously write new database logic instructions, read new database logic instructions, write new database logic instructions and asynchronously write old database logic instructions.

4. The method according to claim 3, characterized in that The data source includes a new data source corresponding to the data in the new database, and an old data source corresponding to the data in the old database; The data source indication instruction includes: a new data source calling instruction and an old data source calling instruction; The step of acquiring a data source link corresponding to the data source identifier from the data source set according to the preconfigured data read / write operation instruction and the data source identifier, and acquiring data in the data source according to the data source link, specifically includes: In the first stage, according to the new data source calling instruction and the data source identifier corresponding to the new data source, a new data source link is obtained from the data source set, and data in the new data source is obtained according to the new data source link; In the second stage, according to the old data source calling instruction and the data source identifier corresponding to the old data source, the old data source link is obtained from the data source set, and the data in the old data source is obtained according to the old data source link.

5. The method according to claim 1 or 2, characterized in that: The data read / write operation instruction also includes specific location information of the data to be written, so that when performing sub-library and sub-table read / write operations on the data in the data source according to the pre-configured data read / write operation instructions and data source indication instructions, the data corresponding to the data read / write operation instructions are written to the specific location of the sub-library and sub-table.

6. A sub-library and sub-table switching device based on proxy mode, characterized in that: The device is applied to a multi-data source switching component, and the device includes: A processing unit, configured to load a pre-configured data source configuration file, generate a link according to the data source configuration file, and store the link in a data source set; wherein the data source set includes a plurality of data source connection pools, each of which stores a link generated by the same data source configuration file; A receiving unit, receiving a pre-configured data source identifier transmitted by the business logic layer; an acquisition unit, configured to acquire a data source link corresponding to the data source identifier from the data source set according to a preconfigured data read / write operation instruction and the data source identifier, and acquire data in a data source corresponding to the data source identifier according to the data source link; The processing unit is further used to perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions, wherein the data source indication instructions are used to indicate that when performing different business data read / write operations, the data in the data source corresponding to the current data read / write operation instruction is read / written; The performing of the sub-library and sub-table read / write operation on the data in the data source according to the data read / write operation instruction and the pre-configured data source indication instruction specifically includes: In the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database; When the data in the old database reaches data consistency with the data in the new database, the second stage is entered; In the second stage, according to the logic instruction of writing a new database, the data in the old data source is written into the new database; And according to the read new database logic instruction and the asynchronous write old database logic instruction, after reading the data in the new database, asynchronously write the data in the new database into the old database; When it is determined that the writing of data in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

7. A sub-library and sub-table switching system based on proxy mode, characterized in that: The system comprises: A storage module, used to store pre-configured data source configuration files; A data source switching module, used to retrieve the pre-configured data source configuration file stored in the storage module, and generate a link according to the data source configuration file and store it in the data source set; A business logic module, used to transmit a pre-configured data source identifier to the data source switching module; The data source switching module is further configured to obtain a data source link corresponding to the data source identifier from the data source set according to a preconfigured data read / write operation instruction and the data source identifier transmitted by the business logic module, and obtain data in the data source corresponding to the data source identifier according to the data source link; The data source switching module is further used to perform sub-library and sub-table read / write operations on the data in the data source according to the data read / write operation instructions and the pre-configured data source indication instructions; The performing of the sub-library and sub-table read / write operation on the data in the data source according to the data read / write operation instruction and the pre-configured data source indication instruction specifically includes: In the first stage, according to the write old database logic instruction, the data in the new data source is written into the old database; and according to the asynchronous write new database logic instruction and the read old database logic instruction, after reading the data in the old database, the data in the old database is asynchronously written into the new database; When the data in the old database reaches data consistency with the data in the new database, the second stage is entered; In the second stage, according to the logic instruction of writing a new database, the data in the old data source is written into the new database; And according to the read new database logic instruction and the asynchronous write old database logic instruction, after reading the data in the new database, asynchronously write the data in the new database into the old database; When it is determined that the writing of data in the new database is completed, the old database is deleted, and all operation instructions for performing operations on the old database are deleted.

8. A computer device, characterized in that: The computer device comprises: at least one processor and a memory; The processor is used to execute the proxy mode-based sub-library and sub-table switching program stored in the memory to implement the proxy mode-based sub-library and sub-table switching method described in any one of claims 1 to 5.

9. A computer storage medium, characterized in that The computer storage medium stores one or more programs, and the one or more programs can be executed by the computer device as described in claim 8 to implement the proxy mode-based sharding method for switching between sharded libraries and tables as described in any one of claims 1 to 5.

10. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium. The processor of the device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the device executes the proxy-based database and table switching method described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data source read-write separation method and device and computer readable storage medium

    CN110837531A