Background technology
Along with the fast development of current network technology, a lot of traditional services have been transferred in the network environment and have been implemented such as financial transaction, business administration etc.Because the fragility of network environment often causes server to need to safeguard, in case server is in maintenance state, does not take necessary measure if having, the service that provides so will be interrupted the long time.And for the application of enterprise-level, the interruption of so long service is unacceptable.
In order to overcome the problems referred to above, high availability cluster now can move server system incessantly, and this server system generally is comprised of two or more nodes.If certain node needs to safeguard that the service processes on this node can be continued service by real-time migration to secondary node.
Service processes is carried out real-time migration, need to suspend this process to be migrated at server, and with this process execution state information be saved in the file of checkpoint (checkpoint), then stop this process.A newly-built process and from inspection file obtained above, read in the execution state information of original process on secondary node afterwards, thus continue to provide service.
Service processes often comprises one and monitors socket and receive the connection of client in running, and have some sockets of opening just with the client transmissions data that connected.Therefore in the process that service processes is moved, also need the socket of opening of this service processes is moved, therefore need the socket state information of opening of this service processes is saved in the check point file.
In the process that socket is moved, network protocol stack still works.Migration since a service processes, to the migration of this service processes finish (namely this service processes is rebulid on secondary node) during in, packet can't normally receive, but client not can be appreciated that again the packet that it sends is not normally received, so the packet that client sends during the period will be lost.
In addition, in transition process, will stop former service processes, client will be received the FIN packet that server sends, and close simultaneously the socket of the service processes that stops, client is owing to perceive connection that the migration of process causes and disconnect therefore and need to reconnect server.
Summary of the invention
In view of this, the object of the present invention is to provide a kind of data communications method based on socket and device, can avoid because the phenomenon of the data-bag lost that process migration causes.
For achieving the above object, one embodiment of the present of invention provide a kind of data communications method based on socket, comprising:
Behind the packet that receives the client transmission, seek host's socket of this packet;
Seek the packet of tail end of the receiving queue of described host's socket, the checkpoint flag bit of judging the packet of described tail end whether be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file;
If the checkpoint flag bit of described endian data bag be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file, then directly abandon the packet that receives.
On the other hand, the embodiment of the invention also provides a kind of data communication equipment, comprising:
The packet receiving element is used for receiving the packet that client sends;
Socket is searched the unit, is used for seeking host's socket of the described packet that receives;
Packet is searched the unit, is used for seeking the packet of tail end of the receiving queue of described host's socket;
Whether judging unit, the checkpoint flag bit that is used for judging the packet of described tail end are set to that this receiving queue content of expression is tested makes an inventory of the value that process is saved in check point file;
Discarding unit, the judged result that is used for when described judging unit is yes, then abandons the packet that receives.
According to the embodiment of the invention, after receiving packet, at first check the checkpoint flag bit in the packet of receiving queue tail end of host's socket of this packet, the receiving queue content that whether is set to this host's socket of the expression tested process of making an inventory of is saved in value in the check point file, if, then can be with the data packet discarding that receives, and then can be so that client recognizes that the data that this client sends are not normally received, carry out follow-up retransmission steps, can not produce the problem of packet loss.
Embodiment
For the purpose, technical scheme and the advantage that make the embodiment of the invention clearer, below in conjunction with the accompanying drawing in the embodiment of the invention, technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that obtains under the creative work prerequisite.
The embodiment of the invention provides a kind of data communications method based on socket, and as shown in Figure 1, the method comprises the steps:
Step S101: behind the packet that receives the client transmission, seek host's socket of this packet;
Step S102: the packet of seeking the receiving queue tail end of host's socket;
Step S103: the checkpoint flag bit of the packet of the tail end that searches out among the determining step S102 whether be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file;
Step S104: when the judged result of step S103 when being, directly abandon the packet that receives.
In the data communications method that the embodiment of the invention provides, the receiving queue content that has increased the host's socket that is used for representing this packet in the packet that client sends the tested process of making an inventory of is saved in flag bit (can be abbreviated as CKPT) in the check point file.When the value of CKPT flag bit tested when making an inventory of process and being saved in value in the check point file for the receiving queue content of host's socket of this packet of expression, represent current reception packet host's socket the receiving queue content the tested process of making an inventory of be saved in the check point file, that is to say that this host's socket is moved, this moment can be with the data packet discarding that receives, and then can be so that client recognizes that the data that this client sends are not normally received, carry out follow-up retransmission steps, can not produce the problem of packet loss.
Below describe specific implementation of the present invention in detail with a concrete example.
As shown in Figure 2, this scheme comprises the steps:
Step S201: the socket to process moves;
Step S202: if the receiving queue of the socket that should move is not empty, then checkpointing is saved in the receiving queue content of this socket in the check point file, and with the value of the CKPT flag bit in the packet of this receiving queue tail end be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file.
In addition, the receiving queue that it is also conceivable that the socket that is moved in the present embodiment is empty situation, at this moment, just construct the packet of a sky, here so-called empty packet refers to not comprise the packet of real data, and the value of the CKPT flag bit in should the packet of sky be set to expression the tested process of making an inventory of be saved in value in the check point file.
In embodiments of the present invention, can revise the form of tcp data bag, use a reservation bit position of original tcp data bag as the CKPT flag bit.A kind of concrete scheme can be referring to Fig. 3 and Fig. 4.The form of the tcp data bag before revising has been shown among Fig. 3, and Fig. 4 shows the form of amended tcp data bag, and comparison diagram 4 and Fig. 3 have utilized in some reservation bits position of original tcp data bag one as the CKPT flag bit as can be known in this scheme.
When the reservation bit position of adopting original tcp data bag during as the CKPT flag bit, can not exert an influence to the performance of network protocol stack and other links in the network service process.
Step S203: when receiving the packet of client transmission, the packet that receives is carried out the correctness verification.
The correctness verification can comprise whether correct etc. whether packet belong to local, stem verification and.
Step S204: whether the correctness verification among the determining step S203 is passed through, and if so, then continues execution in step S205, if not, and direct execution in step S210 then: packet discard.
Step S205: host's socket of seeking this packet that receives.
Can from deposit the Hash table of opening socket, seek in practice the transmit control block under this packet, and find host's socket by this transmit control block.In fact, each opens socket and receiving queue is safeguarded in a Hash (hash) table, and the key assignments of four-tuple (source IP, purpose IP, source port, destination interface) in Hash table that belongs to the packet of same socket is identical, therefore can determine the socket that it is affiliated, i.e. host's socket according to the four-tuple of the packet that receives.
Step S206: after finding host's socket, seek the packet of the receiving queue tail end of this host's socket.
Step S207: the value of CKPT flag bit of judging the packet of this tail end whether be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file, if judged result is yes, direct execution in step S210 then: packet discard; If the determination result is NO, then continue execution in step S208.
Step S208: the tail end that the packet that receives is suspended to the receiving queue of its host's socket.
Step S209: to client feedback ACK acknowledge message, this packet that the expression client sends serviced often rectifying receives.
In the process that process is moved, can finish former process, all of closing simultaneously former process are opened socket, another embodiment of the present invention also is optimized the flow process of closing socket, as shown in Figure 5, also comprise the following step of closing socket that illustrates in the data communications method that the embodiment of the invention provides:
Step S501: the value of the CKPT flag bit of the packet of the receiving queue tail end of the socket that inspection will be closed whether be set to this receiving queue content of expression the tested process of making an inventory of be saved in value in the check point file.
If the judged result among the step S501 is yes, then execution in step S502: the buffering area and the structure of cancelling this socket of closing that directly discharge this socket of closing.Thereby skip the step that sends FIN message and directly close this socket.In this case, client does not receive FIN message, also just can not perceive ServerSocket is closed, if be successfully completed the migration of process at the tcp connect timeout in setting time, then can recover to open the state of socket, except time-delay was to a certain degree arranged, client can not perceive network connection and once be interrupted.
If the determination result is NO among the step S501, then according to traditional socket closing flow path socket is closed, be execution in step S503: send FIN message to client, after waiting for the affirmation of client, discharge the buffering area of this socket of closing, and cancel the structure of this socket of closing.Client also will be closed the related port of this socket simultaneously.
The embodiment of the invention is also corresponding to provide a kind of data communication equipment, and as shown in Figure 6, this device comprises:
Packet receiving element 601 is used for receiving the packet that client sends;
Socket is searched unit 602, is used for searching host's socket of the packet that receives;
Packet is searched unit 603, be used for to seek the packet of tail end of the receiving queue of host's socket;
Whether judging unit 604, the checkpoint flag bit that is used for judging the packet of tail end are set to and represent that this receiving queue content is tested and make an inventory of the value that process is saved in check point file;
Discarding unit 605, the judged result that is used for when judging unit 604 is yes, then abandons the packet that receives.
In addition, data communication equipment in the present embodiment can also comprise that packet hangs into unit 606, when the determination result is NO for judging unit 604, the packet that receives is suspended to the tail end of the receiving queue of host's socket, and returns the affirmation information that the expression packet has normally been received to client.
The above only is preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.