Read-write method based on dual-network redundant database

By configuring a dual-network redundant database connection pool and realizing automatic switching, the problem of inability to switch automatically in the existing technology in case of network failure is solved, and the integrity of high-reliability database reading and writing and automatic network switching is achieved.

CN120021200APending Publication Date: 2025-05-20HIWING TECH ACAD OF CASIC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311552588.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-20
Publication Date
2025-05-20

AI Technical Summary

Technical Problem

The prior art cannot automatically and reliably switch to another network for database communication when one of the networks fails, resulting in problems such as high reliability of database reading and writing and automatic network switching.

Method used

By configuring a dual-network redundant database connection pool, the first and second database connection pools are set at the first and second addresses that can be accessed respectively during the first loading, and the database client is acquired and read and/or write operations are performed. When one network fails, it automatically switches to another network, and network switching is achieved by adjusting the location of the database connection pool and counting judgment.

Benefits of technology

It realizes automatic switching in the event of network failure, ensures high reliability of database reading and writing, and ensures automatic switching of access networks and complete data reading and writing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120021200A_ABST
    Figure CN120021200A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of system software communication, and discloses a read-write method based on a dual-network redundant database. The method comprises the following steps: S100, configuring a first database connection pool and a second database connection pool when loading for the first time, and arranging the first database connection pool and the second database connection pool in an accessible first address and a second address respectively; s102, acquiring a database client from a database connection pool corresponding to the first address; s104, judging whether the acquisition is successful or not, if so, turning to S106, otherwise, turning to S110; s106, returning to the database client; s108, performing reading and / or writing operation on the database server side by using the returned database client side; s110, exchanging positions of the first database connection pool and the second database connection pool, and counting exchange times; and S112, judging whether the current count value exceeds the maximum number of times or not, if so, prompting that the database client is failed to obtain, and otherwise, returning to S102. Therefore, high-reliability reading and writing of the database can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system software communication, and particularly to a dual-network redundant database read-write method. Background Art

[0002] Database technology is currently very mature. Databases are generally divided into two categories: relational databases and non-relational databases. To improve the high reliability of database reading and writing, technologies such as master-slave replication, read-write separation, master-backup switching, and clustering can be used. These technologies mainly aim to reduce the pressure on database servers, improve read-write speeds, and handle high traffic volumes, thereby enhancing the user data access experience.

[0003] For some industrial control systems, strict requirements are imposed on the stability and reliability of the system. The communication between devices also adopts a dual-network redundancy design (also known as red and blue networks), that is, a dual-network and dual-channel communication method is used between two systems. This can ensure that when one link fails, normal data transmission and reception can be carried out through the other link.

[0004] However, for the dual-network communication client system and the database server using a dual-network connection, it is currently impossible to ensure that when one network fails, it can automatically and reliably switch to the other network for communication. Summary of the Invention

[0005] The present invention provides a dual-network redundant database read-write method, which can solve the technical problems in the prior art.

[0006] The present invention provides a dual-network redundant database read-write method, which includes:

[0007] S100, configuring a first database connection pool and a second database connection pool during the first loading. The first database connection pool and the second database connection pool are respectively placed at accessible first and second addresses;

[0008] S102, obtaining a database client from the database connection pool corresponding to the first address;

[0009] S104, determining whether the obtaining is successful. If successful, go to S106; otherwise, go to S110;

[0010] S106, returning the database client;

[0011] S108, using the returned database client to perform read and / or write operations on the database server;

[0012] S110, swapping the positions of the first database connection pool and the second database connection pool, and counting the number of swaps;

[0013] S112. Determine whether the current count value exceeds the maximum number of times. If so, prompt that the database client acquisition fails; otherwise, return to S102.

[0014] Preferably, the read and / or write operations performed on the database server using the returned database client include:

[0015] For the read operation, determine whether the read is successful. If successful, end the process; otherwise, return to S102.

[0016] Preferably, the read and / or write operations performed on the database server using the returned database client include:

[0017] For the write operation, determine whether the write is successful. If successful, end the process; otherwise, write the data to the buffer area and transfer to S102.

[0018] Preferably, the first database connection pool is the main network database connection pool, and the second database connection pool is the standby network database connection pool.

[0019] Preferably, the first database connection pool is the standby network database connection pool, and the second database connection pool is the main network database connection pool.

[0020] Preferably, the database client includes a read-only client, a write-only client, and a read-write client.

[0021] Preferably, the accessible first address and second address include arrays and lists.

[0022] Through the above technical solutions, it can be ensured that when one of the networks fails, the system automatically switches to the other network for communication, thereby achieving highly reliable database reading and writing, and realizing the automatic switching of the access network and the integrity of data reading and writing. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The accompanying drawings included herein are used to provide a further understanding of the embodiments of the present invention, which form a part of the specification, are used to illustrate the embodiments of the present invention, and together with the written description, explain the principles of the present invention. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0024] Figure 1 FIG. shows a flowchart of a method for reading and writing a dual-network redundant database according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and in no way limits the present invention and its application or use. Based on the embodiments in the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

[0026] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0027] Unless otherwise specifically stated, the relative arrangements of components and steps, numerical expressions, and numerical values set forth in these embodiments do not limit the scope of the present invention. At the same time, it should be understood that, for the sake of convenience of description, the dimensions of the various parts shown in the drawings are not drawn in actual proportional relationships. Technologies, methods, and devices known to those of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and devices should be regarded as part of the authorization specification. In all the examples shown and discussed herein, any specific value should be construed as merely exemplary and not as a limitation. Therefore, other examples of the exemplary embodiments may have different values. It should be noted that: like reference numerals and letters denote like items in the following drawings, and thus, once an item is defined in one drawing, it does not need to be further discussed in subsequent drawings.

[0028] Figure 1 The flowchart of a method for reading and writing a dual-network redundant database according to an embodiment of the present invention is shown.

[0029] As Figure 1 shown, an embodiment of the present invention provides a method for reading and writing a dual-network redundant database, where the method includes:

[0030] S100, when first loaded, configure the first database connection pool and the second database connection pool (i.e., the dual-network database connection pool), and place the first database connection pool and the second database connection pool in the accessible first address and second address respectively;

[0031] Among them, a database client can be efficiently obtained through a database connection pool.

[0032] S102, obtain a database client from the database connection pool corresponding to the first address;

[0033] S104, determine whether the obtaining is successful. If successful, go to S106; otherwise, go to S110;

[0034] That is, if successful, subsequent read and write operations can be performed; if failed, it means that the network cannot connect to the database server and the client cannot be obtained.

[0035] S106, return the database client;

[0036] That is, send the obtained database client to the requester.

[0037] S108, perform read and / or write operations on the database server using the returned database client;

[0038] S110, swap the positions of the first database connection pool and the second database connection pool, and count the number of swaps;

[0039] That is, swap the positions of the two connection pools (i.e., reverse the database connection pool array), and record the number of reversals (switches).

[0040] S112, determine whether the current count value N exceeds the maximum number MaxCount (N>MaxCount). If so, prompt that the database client cannot be obtained (i.e., the database connection pool corresponding to the first address cannot obtain the client); otherwise, return to S102 (continue the loop process).

[0041] Through the above technical solution, it can be ensured that when one of the networks fails, it will automatically switch to the other network for communication, so as to achieve high-reliability reading and writing of the database, and realize automatic switching of the access network and the integrity of data reading and writing.

[0042] That is, as long as one of the two networks is available, the reading and writing of the database can be carried out normally. For example, if either network is forcibly interrupted, the program can still run stably. For example, if the red network is interrupted, the blue network can stably receive data.

[0043] According to an embodiment of the present invention, performing read and / or write operations on the database server using the returned database client includes:

[0044] For the read operation, determine whether the reading is successful. If successful, end the process; otherwise, return to S102.

[0045] According to an embodiment of the present invention, performing read and / or write operations on the database server by using the returned database client includes:

[0046] For the write operation, determine whether the write is successful. If successful, end the process; otherwise, write the data to the buffer and go to S102.

[0047] Thus, when the write fails (usually occurring during network switching), the data can be stored in the cache to ensure that the data does not disappear. Until it can be written, the cached data is written to the database.

[0048] According to an embodiment of the present invention, the first database connection pool is the main network database connection pool, and the second database connection pool is the standby network database connection pool.

[0049] According to an embodiment of the present invention, alternatively, the first database connection pool is the standby network database connection pool, and the second database connection pool is the main network database connection pool.

[0050] According to an embodiment of the present invention, the database client includes a read-only client, a write-only client, and a read-write client.

[0051] Take Figure 1 as an example, where the obtained database client is a read-write client. Accordingly, both read operations and write operations can be performed subsequently. If the obtained database client is a read-only client, then only read operations are included subsequently; similarly, if the obtained database client is a write-only client, then only write operations are included subsequently.

[0052] According to an embodiment of the present invention, the accessible first address and second address include an array and a list.

[0053] In the present invention, taking the array as an example, the first address is array 0 (array[0]), the second address is array 1 (array[1]), array[0] corresponds to the first database connection pool, and array[1] corresponds to the second database connection pool.

[0054] In the description of the present invention, it should be understood that the orientation or positional relationship indicated by orientation words such as "front, back, up, down, left, right", "horizontal, vertical, perpendicular, horizontal" and "top, bottom", etc. is usually based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description. Without contrary instructions, these orientation words do not indicate and imply that the device or element referred to must have a specific orientation or be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the protection scope of the present invention; the orientation words "inside, outside" refer to the inside and outside relative to the contour of each component itself.

[0055] For ease of description, spatial relative terms such as "above", "over", "on the upper surface", "upper" etc. may be used herein to describe the spatial positional relationship of one device or feature to other devices or features as shown in the figures. It should be understood that the spatial relative terms are intended to encompass different orientations in use or operation in addition to the orientation depicted in the figures. For example, if the device in the figures is inverted, a device described as "above" or "over" other devices or structures will then be positioned "below" or "under" the other devices or structures. Thus, the exemplary term "above" can include both the orientations of "above" and "below". The device may also be positioned in other different ways (rotated 90 degrees or in other orientations), and corresponding interpretations of the spatial relative descriptions used herein will be made accordingly.

[0056] In addition, it should be noted that the use of terms such as "first" and "second" to define components is only for the convenience of differentiating the corresponding components. Without additional statements, the above terms have no special meanings, and thus should not be construed as limiting the protection scope of the present invention.

[0057] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention can have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A dual-network redundant database reading and writing method, characterized in that: The method includes: S100, configuring a first database connection pool and a second database connection pool when loading for the first time, and placing the first database connection pool and the second database connection pool at an accessible first address and a second address respectively; S102, obtaining a database client from a database connection pool corresponding to the first address; S104, determine whether the acquisition is successful, if successful, go to S106, otherwise go to S110; S106, returning to the database client; S108, using the returned database client to perform read and / or write operations on the database server; S110, swapping the positions of the first database connection pool and the second database connection pool, and counting the number of swaps; S112, determining whether the current count value exceeds the maximum number of times, if so, prompting that the acquisition of the database client fails, otherwise returning to S102.

2. The method according to claim 1, characterized in that Using the returned database client to perform read and / or write operations on the database server includes: For the read operation, determine whether the read is successful, if successful, end the process, otherwise return to S102.

3. The method according to claim 2, characterized in that Using the returned database client to perform read and / or write operations on the database server includes: For the write operation, it is determined whether the write is successful. If successful, the process ends; otherwise, the data is written into the buffer area and the process goes to S102.

4. The method according to any one of claims 1 to 3, characterized in that The first database connection pool is the primary network database connection pool, and the second database connection pool is the backup network database connection pool.

5. The method according to any one of claims 1 to 3, characterized in that: The first database connection pool is the backup network database connection pool, and the second database connection pool is the main network database connection pool.

6. The method according to any one of claims 1 to 3, characterized in that Database clients include read-only clients, write-only clients, and read-write clients.

7. The method according to any one of claims 1 to 3, characterized in that The accessible first addresses and second addresses include arrays and lists.