Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for storing data during dual-computer backup, which achieve optimization of storage space as much as possible on the premise of performing data synchronization at a faster speed.
In order to achieve the above purpose, the invention provides the following specific technical scheme:
a data storage method during dual-computer backup comprises the following steps:
acquiring the current stable state of the dual-host server system;
determining a target data storage mode corresponding to the current stable state of the dual-host server system according to a preset corresponding relation between the stable state and the data storage mode, wherein the data storage mode comprises an ordered storage mode and an unordered storage mode;
and storing data according to the target data storage mode.
Optionally, the determining, according to a preset corresponding relationship between a stable state and a data storage manner, a target data storage manner corresponding to the stable state where the dual-host server system is currently located includes:
searching in a preset corresponding relation between the stable state and the data storage mode to obtain a target data storage method corresponding to the current stable state of the dual-host server system;
specifically, when the current stable state of the dual-host server system is a single server state, the corresponding target data storage mode is an unordered storage mode;
when the current stable state of the dual-host server system is a main/standby synchronous state, the corresponding target data storage mode is an unordered storage mode;
when the current stable state of the dual-host server system is the master-slave abnormal gait, the corresponding target data storage mode is an ordered storage mode.
Optionally, the method further includes:
when the stable state of the dual-host server system changes, determining a target stable state to which the dual-host server system needs to be switched from the current stable state;
determining a data storage mode corresponding to the target stable state according to a preset corresponding relation between the stable state and the data storage mode;
and when the double-host server system is switched from the current stable state to the target stable state, storing data according to the data storage mode corresponding to the target stable state.
Optionally, the method further includes:
and recording the time and reasons for switching the stable state and the data storage mode of the dual-host server system.
A data storage device during dual-computer backup comprises:
the stable state obtaining unit is used for obtaining the current stable state of the dual-host server system;
the data storage mode determining unit is used for determining a target data storage mode corresponding to the current stable state of the dual-host server system according to a preset corresponding relation between the stable state and the data storage mode, wherein the data storage mode comprises an ordered storage mode and an unordered storage mode;
and the data storage unit is used for storing data according to the target data storage mode.
Optionally, the data storage mode determining unit is specifically configured to search a preset corresponding relationship between a stable state and a data storage mode to obtain a target data storage method corresponding to the stable state where the dual-host server system is currently located; specifically, when the current stable state of the dual-host server system is a single server state, the corresponding target data storage mode is an unordered storage mode; when the current stable state of the dual-host server system is a main/standby synchronous state, the corresponding target data storage mode is an unordered storage mode; when the current stable state of the dual-host server system is the master-slave abnormal gait, the corresponding target data storage mode is an ordered storage mode.
Optionally, the apparatus further comprises:
the stable state switching control unit is used for determining a target stable state to which the dual-host server system needs to be switched from the current stable state when the stable state of the dual-host server system changes; determining a data storage mode corresponding to the target stable state according to a preset corresponding relation between the stable state and the data storage mode; and when the double-host server system is switched from the current stable state to the target stable state, storing data according to the data storage mode corresponding to the target stable state.
Optionally, the apparatus further comprises:
and the data recording unit is used for recording the time and reasons for switching the stable state and the data storage mode of the dual-host server system.
Compared with the prior art, the invention has the following beneficial effects:
the invention discloses a data storage method and a device during dual-host backup, which determine a target data storage mode corresponding to the current stable state of a dual-host server system according to the preset corresponding relation between the stable state and the data storage mode, solve the problems of slow data synchronization rate or large storage space occupation caused by only adopting an ordered storage mode or only adopting an unordered storage mode in the prior art, enable the dual-host server system to adopt the data storage mode which is most matched with the current stable state, and realize the optimization of the storage space as much as possible on the premise of carrying out data synchronization at a higher speed.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, the present embodiment discloses a data storage method during dual-host backup, which is applied to a dual-host server system, and specifically includes the following steps:
s101: acquiring the current stable state of the dual-host server system;
the stable state is a relatively stable state in which the dual-host server system is located, and the dual-host server system has three stable states: single server state, master-slave synchronous state and master-slave different gaits.
The single server state is that only a single server is arranged in the double-host server system, and all operations of the client are directly sent to the server through the controller; the master and slave synchronous state is that the master and slave servers are in a synchronous state, and data synchronization is not needed between the two servers; the master server and the slave server are in different gaits, namely the master server and the slave server are in an asynchronous state, and data synchronization needs to be carried out between the two servers subsequently.
S102: determining a target data storage mode corresponding to the current stable state of the dual-host server system according to a preset corresponding relation between the stable state and the data storage mode;
the data storage mode comprises an ordered storage mode and an unordered storage mode. The ordered storage means that the data recorded in the server has a plurality of versions and is stored according to the storage or modification sequence. Unordered storage refers to the fact that the data recorded in the server has only one version.
The dual-host server system stores a preset corresponding relationship between a stable state and a data storage mode, and the corresponding relationship can be stored in a table mode.
Searching in a preset corresponding relation between the stable state and the data storage mode to obtain a target data storage method corresponding to the current stable state of the dual-host server system;
specifically, when the current stable state of the dual-host server system is a single server state, the corresponding target data storage mode is an unordered storage mode;
when the current stable state of the dual-host server system is a main/standby synchronous state, the corresponding target data storage mode is an unordered storage mode;
when the current stable state of the dual-host server system is the master-slave abnormal gait, the corresponding target data storage mode is an ordered storage mode.
S103: and storing data according to the target data storage mode.
Only a single server is arranged in the double-host server system, the data are stored into uniform unordered data, in a single-server state, after the other server is on line, all data need to be synchronized to keep data consistency, and the versions of the data do not need to be distinguished, so that the data storage space can be reduced by selecting an unordered storage mode.
If the main server and the standby server are in a synchronous state, the data are stored into uniform unordered data, and in the main server and the standby synchronous state, the two servers do not need to be synchronized, so that the data storage space can be reduced by selecting an unordered storage mode.
If the main server and the standby server are in an asynchronous state, the ordered data is selected as a storage mode of the newly added data, increment synchronization is needed between the two servers in the follow-up process under the condition of the asynchronous state of the main server and the standby server, and the version of the newly added data needs to be distinguished in the increment synchronization, so that the increment synchronization can be completed quickly and efficiently by selecting the ordered storage mode.
According to the data storage method during dual-host backup, the target data storage mode corresponding to the current stable state of the dual-host server system is determined according to the preset corresponding relationship between the stable state and the data storage mode, so that the problems of slow data synchronization rate or large storage space occupation caused by only adopting an ordered storage mode or only adopting an unordered storage mode in the prior art are solved, the dual-host server system can adopt the data storage mode which is most matched with the current stable state, and the storage space is optimized as much as possible on the premise of carrying out data synchronization at a higher speed.
It should be noted that, on the basis of the data storage method during dual-host backup disclosed in the foregoing embodiment, this embodiment discloses another data storage method during dual-host backup, which controls a data storage manner when a stable state of a dual-host server system changes, please refer to fig. 2, and the method specifically includes the following steps:
s201: when the stable state of the dual-host server system changes, determining a target stable state to which the dual-host server system needs to be switched from the current stable state;
s202: determining a data storage mode corresponding to the target stable state according to a preset corresponding relation between the stable state and the data storage mode;
s203: and when the double-host server system is switched from the current stable state to the target stable state, storing data according to the data storage mode corresponding to the target stable state.
When the stable state of the dual-host server system changes, the original storage mode may not ensure the data consistency or waste the storage space, so the storage mode needs to be adjusted.
When the dual-host server system is switched from the main-standby synchronous state to the main-standby different gait, the newly added data is recorded as sequential data. After the dual-host server system is switched from the main-standby synchronous state to the main-standby different gait, data synchronization between the two servers is needed subsequently, so that in order to complete synchronization at a higher speed, a sequential storage mode is selected to record data, namely an ordered storage mode is adopted.
When the dual-host server system enters the main and standby different gaits from the single server state, the newly added data is recorded as sequential data. When the dual-host server system enters the main-standby different gait from the single server state, data synchronization between the two servers is needed subsequently, so that in order to complete synchronization at a higher speed, a sequential storage mode is selected to record data, namely an ordered storage mode is adopted.
When the dual-host server system enters a single-server state from a main-standby asynchronous state, the sequential data is transferred to be the unordered data, and when the sequential data is transferred to be stored, the multi-version data is subject to the latest version. After the single server state is entered, data synchronization is not needed, and therefore the storage space can be reduced by selecting unordered storage.
When the dual-host server system enters the main and standby synchronous state from the main and standby asynchronous state, the sequential data is transferred to the unordered data, and when the sequential data is transferred to the main and standby synchronous state, the multi-version data is subject to the latest version. After the main and standby synchronization state is entered, the data of the two servers are synchronized in real time, and data updating is not needed between the servers, so that the storage space can be reduced by selecting the unordered storage.
When the dual-host server system enters a single-server state from a main-standby synchronous state, the storage mode does not need to be changed, and the dual-host server system can be stored out of order;
when the double-host server system enters the main and standby synchronous state from the single server state, the storage mode does not need to be changed, and the double-host server system can be stored out of order.
It should be further noted that, in this embodiment, the time and reason for switching the stable state and switching the data storage mode of the dual-host server system may also be recorded, and according to the record, the necessity of switching the data storage mode is evaluated, and the balance relationship between the server load and the value brought by such operations is measured.
In the data storage method during dual-host backup disclosed in this embodiment, when the dual-host server system is in a steady state change, the data storage manner is also changed accordingly. On the premise of carrying out data synchronization at a higher speed, the storage space is optimized as much as possible.
In order to further describe the data storage method during dual-computer backup disclosed in the foregoing embodiment, a detailed description is given below by using an embodiment of a scenario application.
Referring to fig. 3, the controller, the server 1 and the server 2 form a dual-host server system, and the client communicates data with the server through the controller. The controller maintains an arbitration state machine of the main server and the standby server, acquires the states of the server 1 and the server 2 at regular time through an inquiry mode, and receives an operation result returned by the server.
Specifically, the controller determines the current stable state of the dual-host server system by acquiring the states of the server 1 and the server 2, when the dual-host server system is in the single-server state currently, and after another server is on-line, all data needs to be synchronized to keep data consistency, and the versions of the data do not need to be distinguished, so that an unordered storage mode is selected to reduce the data storage space; when the dual-host server system is currently in a master-slave synchronization state, data synchronization is not needed between the two servers, so that the data storage space can be reduced by selecting an unordered storage mode; when the dual-host server system is currently in main-standby different gaits, incremental synchronization needs to be carried out between the two servers subsequently, and the incremental synchronization needs to distinguish the versions of newly-added data, so that the incremental synchronization is completed quickly and efficiently by selecting an ordered storage mode.
When the stable state of the dual-host server system changes, the original storage mode may not ensure the data consistency, or the problem of wasting storage space exists, and at this time, the storage mode needs to be adjusted.
Specifically, when the dual-host server system is switched from a main-standby synchronous state to a main-standby abnormal gait, the original unordered storage mode is switched to an ordered storage mode; when the dual-host server system enters the main and standby different gaits from the single server state, the original unordered storage mode is switched to the ordered storage mode; when the dual-host server system enters a single-server state from a main/standby asynchronous state, switching the original ordered storage mode into an ordered storage mode; when the dual-host server system enters a main and standby synchronous state from a main and standby asynchronous state, switching the original ordered storage mode into an ordered storage mode; when the dual-host server system enters a single-server state from a main-standby synchronous state, the storage mode does not need to be changed, and the dual-host server system can be stored out of order; when the double-host server system enters the main and standby synchronous state from the single server state, the storage mode does not need to be changed, and the double-host server system can be stored out of order.
Referring to fig. 4, the present embodiment discloses a data storage method during dual-computer backup, which correspondingly discloses a data storage device during dual-computer backup, including:
a stable state obtaining unit 401, configured to obtain a stable state in which the dual-host server system is currently located;
a data storage mode determining unit 402, configured to determine, according to a preset correspondence between a stable state and a data storage mode, a target data storage mode corresponding to the stable state where the dual-host server system is currently located, where the data storage mode includes an ordered storage mode and an unordered storage mode;
a data storage unit 403, configured to store data according to the target data storage manner.
Optionally, the data storage mode determining unit 402 is specifically configured to search a preset corresponding relationship between a stable state and a data storage mode to obtain a target data storage method corresponding to the stable state where the dual-host server system is currently located; specifically, when the current stable state of the dual-host server system is a single server state, the corresponding target data storage mode is an unordered storage mode; when the current stable state of the dual-host server system is a main/standby synchronous state, the corresponding target data storage mode is an unordered storage mode; when the current stable state of the dual-host server system is the master-slave abnormal gait, the corresponding target data storage mode is an ordered storage mode.
Optionally, the apparatus further comprises:
the stable state switching control unit is used for determining a target stable state to which the dual-host server system needs to be switched from the current stable state when the stable state of the dual-host server system changes; determining a data storage mode corresponding to the target stable state according to a preset corresponding relation between the stable state and the data storage mode; and when the double-host server system is switched from the current stable state to the target stable state, storing data according to the data storage mode corresponding to the target stable state.
Optionally, the apparatus further comprises:
and the data recording unit is used for recording the time and reasons for switching the stable state and the data storage mode of the dual-host server system.
The data storage device during dual-host backup disclosed in this embodiment determines a target data storage mode corresponding to a current stable state of a dual-host server system according to a preset corresponding relationship between the stable state and the data storage mode, so as to solve the problem in the prior art that the data synchronization rate is slow or the storage space occupation amount is large due to only adopting an ordered storage mode or only adopting an unordered storage mode, so that the dual-host server system can adopt a data storage mode that is most matched with the current stable state, and the storage space is optimized as much as possible on the premise of performing data synchronization at a higher speed.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.