Disclosure of Invention
In view of the above, the present invention provides a method for implementing multi-machine database synchronization in an electric energy quality management system, which aims to overcome the above-mentioned defects in the prior art.
In order to achieve the purpose, the technical scheme of the invention is realized as follows:
a method for realizing synchronization of a plurality of databases of a power quality management system comprises the following steps:
s1, setting a plurality of servers, wherein each server runs the same set of power quality management system software, and monitoring the state of each server by using a main control module in the power quality management system;
s2, dividing the server roles into a host and a standby, operating the main control module process, monitoring the role change among the servers, and controlling the servers to perform role switching work;
s3, the server starts a file receiving module and a file sending module, and the main control module judges whether the running power quality management system server is in a host role or not;
s4, when the main control module judges that the server is the host, starting the acquisition module and sending the data file to the standby file receiving module;
and S5, when the main control module judges that the server is the standby machine, the standby machine file receiving module receives the data file from the host machine.
Further, in step S2, a data caching folder Doc1, a data sending folder Doc2, and a database warehousing folder Doc3 are created in the server.
Further, the specific method of step S4 is as follows:
s401, generating a database file and putting the database file into Doc 3;
s402, the storage module sequentially writes the files into a local database from Doc3, copies the files and stores the files into Doc1, and then deletes the files in Doc 3;
s403, the master control module copies the files in the Doc1 to the Doc2 and deletes the files in the Doc 1;
s404, the file sending module sends the Doc2 file to all standby machines.
Further, in step S401, the acquisition module performs data acquisition on the underlying device, generates different data files according to different data types after analyzing the acquired data, and puts the generated data files into Doc3, where the data files are sql lite type files.
Further, in step S404, the file sending module in the power quality management system detects that a data file exists in Doc2, and immediately obtains all files and sequentially sends the files to the file receiving modules of other servers.
Further, the specific method of step S5 is as follows:
s501, the file receiving module puts the received data file into Doc 3;
s502, the storage module sequentially writes the files into a local database from the Doc3, copies the files to the Doc1, and then deletes the files in the Doc 3;
s503, the main control module deletes all files in the Doc 1.
Compared with the prior art, the invention has the following advantages:
the invention provides a method for realizing the synchronization of a plurality of machine databases of an electric energy quality management system, which adopts a proprietary file sending module and a proprietary file receiving module to finish the synchronization work of data files between a main server and a standby server, and can freely and flexibly configure the information of a connection server; in addition, in the operation scheme of writing a large amount of data into the database, data synchronous transmission is carried out by adopting a data file which can be conveniently written into the sqlite type of the database, so that a large amount of communication message analysis work is avoided, frequent data writing is avoided, further, the method does not need to carry out any role transformation operation on the database, the roles of the databases running in all servers are consistent, database problems are further avoided, and the stability of the power quality management system is improved.
Detailed Description
It should be noted that the embodiments and features of the embodiments of the present invention may be combined with each other without conflict.
In the description of the present invention, it is to be understood that the terms "central," "longitudinal," "lateral," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," and the like are used in the orientation or positional relationship indicated in the drawings, which are merely for convenience in describing the invention and to simplify the description, and are not intended to indicate or imply that the referenced device or element must have a particular orientation, be constructed and operated in a particular orientation, and are therefore not to be construed as limiting the invention. Furthermore, the terms "first", "second", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first," "second," etc. may explicitly or implicitly include one or more of that feature. In the description of the invention, the meaning of "a plurality" is two or more unless otherwise specified.
In the description of the invention, it is to be noted that, unless otherwise explicitly specified or limited, the terms "mounted", "connected" and "connected" are to be construed broadly, e.g. as being fixed or detachable or integrally connected; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meaning of the above terms in the creation of the present invention can be understood by those of ordinary skill in the art through specific situations.
The invention will be described in detail with reference to the following embodiments with reference to the attached drawings.
As shown in fig. 2, the communication structure of the active/standby server in the embodiment of the present invention is as follows:
1. power quality management system server > =2 stations.
2. The main control module is a module which is mainly responsible for monitoring role changes among servers and implementing role switching work of the servers in the existing power quality management system.
3. The server role is divided into a host machine and a standby machine.
4. The data files collected and generated by the host are stored in a local database warehousing folder Doc3, and the storage module is mainly used for acquiring the data files from the Doc3 and sequentially writing the data files into the database.
5. During the process of writing into the database, the data file is copied to the data cache folder Doc1, and the file in the original Doc3 is deleted.
6. When the server is in the role of the host, the master control module copies the data files in the Doc1 to the data sending folder Doc2 and deletes the files in the Doc 1.
7. When the server role is the standby machine, only the file in the Doc1 is deleted, and at this time, no data file exists in the Doc2, so the file sending module cannot send the data file to other servers until the server role changes from the standby machine to the host machine, and the file sending module does not detect that the data file sent to other servers exists in the Doc 2.
8. Each server runs a file sending module and a file receiving module process. The file sending module regularly detects whether a file exists in Doc2, and immediately sends the file to all other servers if the file exists. The file receiving module is used for receiving the data files sent from all other servers and then placing the data files into the Doc 3.
As shown in fig. 3, the data file interaction structure of the power quality management system in the embodiment of the present invention is formed as follows:
1. and a file sending module and a file receiving module are operated in each server. The file sending module in the server is connected with the receiving modules of all other servers; the file receiving module in the server is also connected with the sending modules in all other servers; the connection information configures the ip and the port numbers of all servers before the power quality management system operates; the power quality management system loads the configuration information after being started, and the file sending module and the file receiving module acquire the configuration information and establish connection with other modules for sending and receiving data files.
2. The solid line in fig. 3 is the connection of the real transmission data file and the reception data file of the system. The dotted line is that a connection has been established but no actual data file is sent and received.
3. In fig. 3, not only the case of one host and two standby devices is limited, but also a case of one host and a plurality of standby devices may be provided.
As shown in fig. 1, a specific method for implementing synchronization of databases of the power quality management system in the embodiment of the present invention is as follows:
1. and the master control module runs the process. All servers run the same set of power quality management system software, the master control module monitors the states of all servers of the power quality management system in real time, and when the servers need to switch roles, the master control module switches the roles of the servers. The main control module is responsible for coordinating and completing data synchronization operation of the server.
2. A data caching folder Doc1, a data sending folder Doc2, and a database warehousing folder Doc3 are created. Doc1 is mainly an intermediate folder for data synchronization between a host and a standby host, and only the host can further send data to be synchronized to other server receiving modules, so that repeated cyclic sending of data files among multiple servers is prevented, and the load of a power quality management system is increased to affect use.
3. The file receiving module and the file sending module are started. The ip and port numbers of all servers are configured by the power quality management system, and connection between the file sending module and the file receiving module between the servers is respectively established, which is shown in detail in fig. 3.
4. And judging whether the running power quality management system server is in a host role or not. If the host is the host, the process proceeds to step 5, and if the standby is the standby, the process proceeds to step 10.
5. And starting the acquisition module for the first time. If the power quality management system is in initial operation, the acquisition module is started under the condition that the power quality management system is judged to be configured as the host, and the acquisition module is a module used for acquiring data of bottom equipment in the existing power quality management system.
6. The resulting database file is placed in Doc 3. The acquisition module carries out data acquisition on the bottom equipment, then generates different data files according to different data types after analyzing the acquired data, and the data files are sqlite type files, so that the data files can be conveniently written into a database. The collection module places the generated data file into Doc 3. Doc3 is a folder for the power quality management system to obtain data files for writing into the database.
7. The storage module writes the files from Doc3 into the local database in sequence, copies the files to Doc1, and deletes the files in Doc 3. The storage module is responsible for writing data files from Doc3 to the native database, then copying the data files to Doc1, and deleting the post-database files in Doc 3.
8. The master module copies the files in Doc1 to Doc2 and deletes the files in Doc 1. When the power quality management system judges that the local computer is in the host role, the power quality management system regularly detects whether data files exist in Doc1 in the local computer, if so, the files in Doc1 are all copied into Doc2, and the files in Doc1 are deleted.
9. The file sending module sends the Doc2 file to all standby machines. And the file sending module in the power quality management system detects that the data file exists in the Doc2, immediately acquires all the files and sequentially sends the files to the file receiving modules of other servers.
10. The database file receiving module receives a file. At the moment, the server of the power quality management system takes the role of a standby machine. The standby file receiving module continuously receives data files from the host.
11. Put into the database repository folder Doc 3. The file receiving module places the received data file into Doc 3.
12. The storage module writes the file from Doc3 to the database for storage in Doc1 and deletes the file in Doc 3; the storage module is a module used for reading and writing data in the existing power quality management system.
13. The master control module deletes all files in Doc 1. When the power quality management system detects that the local machine has the role of a standby machine, the data files in the Doc1 are completely deleted, and the operation of assigning the Doc1 to the Doc2 in the host machine is not performed, so that the data files generated by the acquisition module can be sent to other servers only under the condition of the host machine.
The invention provides a method for realizing the synchronization of a plurality of databases of an electric energy quality management system, which is mainly completed by a main control module, a storage module, a file sending module and a file receiving module of the electric energy quality management system, wherein the main control module is mainly responsible for coordinating and controlling the work of each process module of a server and completing the role task of each server, and the independent file sending module and the independent file receiving module are adopted, so that the data interaction work among the servers can be flexibly customized and completed, and meanwhile, the data interaction is carried out by adopting a sqlite file mode, so that the data volume sending and the data analysis work of the system are reduced, the work load of the server is lightened, the data interaction efficiency is improved, and the data synchronization work of the main server and the standby server is ensured.
The invention provides a method for realizing the synchronization of a plurality of machine databases of an electric energy quality management system, which adopts a proprietary file sending module and a proprietary file receiving module to finish the synchronization work of data files between a main server and a standby server, and can freely and flexibly configure the information of a connection server; in addition, in the operation scheme of writing a large amount of data into the database, data synchronous transmission is carried out by adopting a data file which can be conveniently written into the sqlite type of the database, so that a large amount of communication message analysis work is avoided, frequent data writing is avoided, further, the method does not need to carry out any role transformation operation on the database, the roles of the databases running in all servers are consistent, database problems are further avoided, and the stability of the power quality management system is improved.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and should not be taken as limiting the invention, so that any modifications, equivalents, improvements and the like, which are within the spirit and principle of the present invention, should be included in the scope of the present invention.