CN113572850B - Data synchronization method, device, server and storage medium - Google Patents

Data synchronization method, device, server and storage medium Download PDF

Info

Publication number
CN113572850B
CN113572850B CN202110863371.2A CN202110863371A CN113572850B CN 113572850 B CN113572850 B CN 113572850B CN 202110863371 A CN202110863371 A CN 202110863371A CN 113572850 B CN113572850 B CN 113572850B
Authority
CN
China
Prior art keywords
identifier
request
area
data
login
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110863371.2A
Other languages
Chinese (zh)
Other versions
CN113572850A (en
Inventor
汪军
肖朗
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Pudong Development Bank Co Ltd
Original Assignee
Shanghai Pudong Development Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Pudong Development Bank Co Ltd filed Critical Shanghai Pudong Development Bank Co Ltd
Priority to CN202110863371.2A priority Critical patent/CN113572850B/en
Publication of CN113572850A publication Critical patent/CN113572850A/en
Application granted granted Critical
Publication of CN113572850B publication Critical patent/CN113572850B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention discloses a data synchronization method, a data synchronization device, a server and a storage medium. The method is applied to the first service end and comprises the following steps: when a first request from a client is received, acquiring a first area identifier of a first area where a first service end is located, and acquiring a second area identifier from the first identifier carried in the first request; if the first area identifier is different from the second area identifier, determining a second server deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server to the second server; receiving first data returned by the second server, and adjusting a second area identifier in the first identifier to be the first area identifier to obtain a second identifier; and storing the received first data based on the second identification, and returning the second identification to the client. According to the technical scheme provided by the embodiment of the invention, the data between the multi-area service ends can be synchronized.

Description

Data synchronization method, device, server and storage medium
Technical Field
The embodiment of the invention relates to the technical field of electronic information, in particular to a data synchronization method, a data synchronization device, a server and a storage medium.
Background
With the continuous development of internet technology, more and more application systems are developed towards large-scale, distributed and multi-machine collaboration during deployment. Moreover, session functions are provided in most application systems for storing session data generated when a user operates the application system during a session life cycle.
Currently, due to the large number of users and the high concurrency, and in view of disaster recovery, many application servers are configured as multi-zone distributed servers, i.e. servers distributed in different zones. However, the existing session data storage method can only store session data of a certain user in a server deployed in a certain area, but cannot synchronize the session data among servers deployed in various areas.
Disclosure of Invention
The embodiment of the invention provides a data synchronization method, a device, a server and a storage medium, which are used for realizing the effect of data synchronization in a server deployed in different areas.
In a first aspect, an embodiment of the present invention provides a data synchronization method, which is applied to a first service end, and may include:
when a first request from a client is received, acquiring a first area identifier of a first area where the first service end is located, and acquiring a second area identifier from the first identifier carried in the first request;
If the first area identifier is inconsistent with the second area identifier, determining a second service end deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second service end to the second service end;
Receiving first data returned by the second server, and adjusting a second area identifier in the first identifier to be the first area identifier to obtain a second identifier;
the received first data is stored based on the second identification, and the second identification is returned to the client.
In a second aspect, an embodiment of the present invention further provides a data synchronization device, configured at a first service end, and may include:
The area identification acquisition module is used for acquiring a first area identification of a first area where the first service end is located when a first request from the client is received, and acquiring a second area identification from the first identification carried in the first request;
the request sending module is used for determining a second server deployed on a second area corresponding to the second area identifier if the first area identifier is inconsistent with the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server to the second server;
The identification obtaining module is used for receiving the first data returned by the second server and adjusting the second area identification in the first identification to the first area identification to obtain a second identification;
And the data storage module is used for storing the received first data based on the second identification and returning the second identification to the client.
In a third aspect, an embodiment of the present invention further provides a first server, which may include:
one or more processors;
a memory for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the data synchronization method provided by any embodiment of the present invention.
In a fourth aspect, embodiments of the present invention further provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the data synchronization method provided by any of the embodiments of the present invention.
According to the technical scheme provided by the embodiment of the invention, when the first service end receives the first request from the client end, the first service end can acquire the first area identifier of the first area where the first service end is located, and acquire the second area identifier from the first identifier carried in the first request; if the first area identifier is inconsistent with the second area identifier, the second server storing the first data required by the request and the first server receiving the first request are server deployed on different areas, so that the first server can send the second request for requesting the first data corresponding to the first identifier to the second server, and the second server can send the first data stored by itself to the first server according to the received second request; when the first service end receives first data returned by the second service end, the second area identifier in the first identifier can be adjusted to be the first area identifier, so that a second identifier corresponding to the first data to be stored in the first service end is obtained; and storing the received first data based on the second identifier, and returning the second identifier to the client so that the server can directly read the corresponding first data from the server according to the received first request no matter which server receives the first request sent by the client. According to the technical scheme, the data synchronization effect between the multi-region servers is achieved by accessing the different-region servers based on the region identification based on the architecture of the single client and the multi-region servers (i.e. the servers deployed on different regions).
Drawings
FIG. 1 is a flow chart of a data synchronization method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of a data synchronization method in a second embodiment of the invention;
FIG. 3 is a flow chart of a data synchronization method in a third embodiment of the invention;
FIG. 4 is a schematic diagram of an alternative example of a data synchronization method in accordance with the third embodiment of the present invention;
FIG. 5 is a block diagram of a data synchronizer according to a fourth embodiment of the present invention;
Fig. 6 is a schematic structural diagram of a first server in a fifth embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Example 1
Fig. 1 is a flowchart of a data synchronization method according to a first embodiment of the present invention. The embodiment is applicable to the case of data synchronization, and is particularly applicable to the case of synchronizing data stored in each server with respect to servers deployed on different areas. The method may be performed by a data synchronization device provided by the embodiment of the present invention, where the device may be implemented by software and/or hardware, and the device may be integrated on a first server, and optionally, the first server may be a distributed cache server, such as a redis server, an ETCD server, etc., and a server disposed on the first server may be referred to as a first server.
Referring to fig. 1, the method of the embodiment of the present invention specifically includes the following steps:
S110, when a first request from a client is received, a first area identifier of a first area where a first service end is located is obtained, and a second area identifier is obtained from the first identifier carried in the first request.
The client may be an Application system that is disposed in a terminal device (such as a mobile phone, a computer, etc.) and can be operated by a user, and may be presented to the user in various manners, such as web pages, application (APP), etc. The first request may be a request transmitted by the client for responding to a user operation when the user operates the client (which may be referred to as a user operation), and, for example, may be a request for reading, writing, or updating session data corresponding to the click operation, assuming that the user operation is a click operation acting on the transfer function module. In practical application, optionally, the request content of the first request may be divided according to an operation type of the user operation, for example, a session request, a registration request, an access request, or a logout request; still alternatively, the first request may be represented by an http request.
The first area may be an area where the first service end that receives the first request is located, such as the Shanghai, the He-Fei, or the Tianjin area, and further such as the Shanghai Huangpu area, xuhui area, or the Changning area; the number of the first service terminals deployed on the first area may be one, two or more; the first area identifier may be an area identifier set in advance for the first area, such as 0 for Shanghai, 1 for joint fertilizer, 2 for Tianjin, or the like. The first identifier may be information for identifying the current user operation, which is set in the first request, and may embody multiple meanings, such as a second area identifier, a user identity identifier, a request timestamp identifier, etc., where the second area identifier may be an area identifier of a second area where a second service end storing data (such as session data, login data, etc.) that needs to be operated at this time is located, and the first service end and the second service end may be service ends deployed in the same area or different areas, which is not specifically limited herein.
And S120, if the first area identifier is inconsistent with the second area identifier, determining a second server deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server to the second server.
When the first area identifier and the second area identifier are different, this means that the first service end and the second service end are service ends deployed in different areas, that is, the first service end accessed by the user this time and the second service end storing data required by the operation this time are service ends deployed in different areas, which may be caused by various reasons, such as that the operations of the user before and after the two times are allocated to the service ends deployed in different areas due to the change of the routing policy, the change of the user position (such as moving from Shanghai to joint fertilizer) of the user, and the like. Because the data (which may be referred to as first data) required by the present operation is the data corresponding to the first identifier, the second request for requesting the first data may be sent to the second server, so that after the second request is received by the second server, the first data corresponding to the second request may be returned to the first server, and further, the first server may respond to the first request according to the received first data.
S130, receiving first data returned by the second server, and adjusting the second area identifier in the first identifier to be the first area identifier to obtain a second identifier.
Wherein the area identifier in the first identifier is a second area identifier, because the first data corresponding to the first identifier is stored in a second server disposed on the second area (i.e., the area corresponding to the second area identifier). But now the second server has received the first data, then it may store the first data in itself later, which means that the first data may also be stored in the first server in the future, so that the second area identity in the first identity may be adjusted to the first area identity, resulting in the second identity, so that it is indicated by the second identity that the first data is also stored in the first server.
And S140, storing the received first data based on the second identification, and returning the second identification to the client.
The received first data is stored based on the second identifier, namely the second identifier and the first data are stored in the first service end as a pair, so that the corresponding first data can be read in the first service end through the second identifier later. Meanwhile, the second identifier can be returned to the client, so that the first request sent by the client subsequently can carry the first identifier and the second identifier at the same time. On the basis, as the first data are stored in the two service ends at the same time, and the first request sent again by the client end carries the first identifier and the second identifier at the same time, no matter which service end receives the first request, the service end can read the corresponding first data in itself according to the identifier carried in the first request.
According to the technical scheme provided by the embodiment of the invention, when the first service end receives the first request from the client end, the first service end can acquire the first area identifier of the first area where the first service end is located, and acquire the second area identifier from the first identifier carried in the first request; if the first area identifier is inconsistent with the second area identifier, the second server storing the first data required by the request and the first server receiving the first request are server deployed on different areas, so that the first server can send the second request for requesting the first data corresponding to the first identifier to the second server, and the second server can send the first data stored by itself to the first server according to the received second request; when the first service end receives first data returned by the second service end, the second area identifier in the first identifier can be adjusted to be the first area identifier, so that a second identifier corresponding to the first data to be stored in the first service end is obtained; and storing the received first data based on the second identifier, and returning the second identifier to the client so that the server can directly read the corresponding first data from the server according to the received first request no matter which server receives the first request sent by the client. According to the technical scheme, the data synchronization effect between the multi-region servers is achieved by accessing the different-region servers based on the region identification based on the architecture of the single client and the multi-region servers (i.e. the servers deployed on different regions).
Example two
Fig. 2 is a flowchart of a data synchronization method according to a second embodiment of the present invention. The present embodiment is optimized based on the above technical solutions. In this embodiment, optionally, after the second area identifier is obtained from the first identifier carried in the first request, the data synchronization method may further include: and if the first area identifier is consistent with the second area identifier, reading second data corresponding to the first identifier from the first service end. Wherein, the explanation of the same or corresponding terms as the above embodiments is not repeated herein.
Referring to fig. 2, the method of this embodiment may specifically include the following steps:
S210, when a first request from a client is received, a first area identifier of a first area where a first service end is located is obtained, and a second area identifier is obtained from the first identifier carried in the first request.
And S220, if the first area identifier is consistent with the second area identifier, reading second data corresponding to the first identifier from the first service end, and exiting.
When the first area identifier and the second area identifier are the same, this indicates that the first service end stores second data corresponding to the first identifier, where the second data may be data directly stored in the first service end at the beginning or may be data acquired by the first service end after accessing the remote service end. Thus, the first service end can directly read the second data corresponding to the first identifier from the first service end.
And S230, if the first area identifier is inconsistent with the second area identifier, determining a second server deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server to the second server.
S240, receiving first data returned by the second server side, and adjusting the second area identifier in the first identifier to be the first area identifier to obtain a second identifier.
S250, storing the received first data based on the second identification, and returning the second identification to the client.
According to the technical scheme provided by the embodiment of the invention, when the first area identifier is consistent with the second area identifier, the second data corresponding to the first identifier is stored in the first service end, so that the first service end can directly read the second data corresponding to the first identifier from the first service end, and the effect of accurately reading the data is achieved.
An optional technical scheme includes that at least two first identifiers are carried in a first request, and each first identifier respectively comprises a second area identifier; if the first area identifier is consistent with the second area identifier, reading the second data corresponding to the first identifier from the first service end may include: if the target area identifiers consistent with the first area identifiers exist in the second area identifiers, determining the target identifiers containing the target area identifiers in the first identifiers, and reading second data corresponding to the target identifiers from the first service end. It may be known from the foregoing description that the first request may carry at least two first identifiers, where each first identifier includes a respective second area identifier, that is, it may be determined, according to the second area identifier in the first identifier, that the first identifier is associated with a server deployed on which area. After the first server side obtains each second area identifier, if it is determined that the target area identifier consistent with the first area identifier exists in each second area identifier, which means that second data required by the user operation is stored in the first server side, and for each target identifier including the target area identifier in each first identifier, the second data corresponding to the target identifier can be read in the first server side, so that the effect of accurately reading the data is achieved.
Example III
Fig. 3 is a flowchart of a data synchronization method provided in the third embodiment of the present invention. The present embodiment is optimized based on the above technical solutions. In this embodiment, optionally, after receiving the first request from the client, the data synchronization method may further include: if the first request does not carry the first identifier, session data corresponding to the first request is acquired, and a session identifier corresponding to the first request is generated; taking the session identifier as a first identifier, storing the first identifier and the session data in a first service end, and returning the first identifier to the client;
And/or the number of the groups of groups,
The first identifier carried in the first request is a session identifier, and after the first request from the client is received, the data synchronization method may further include: if the first request is a login request, login data corresponding to the login request is obtained, and a login identifier corresponding to the login request is generated; and taking the login identification as a first identification, storing the first identification and login data in a first service end, and returning the first identification to the client. Wherein, the explanation of the same or corresponding terms as the above embodiments is not repeated herein.
Referring to fig. 3, the method of this embodiment may specifically include the following steps:
S310, when a first request from a client is received, determining whether a first identifier is carried in the first request, if not, executing S320, otherwise, executing S330.
Determining whether the first request carries a first identifier, wherein in a normal case, when a user operates the client for the first time, the first request sent by the client does not carry any first identifier; otherwise, the first request carries the first identifier. It should be noted that, when the time interval between the last operation performed by the user on the client and the current operation has exceeded the preset session life cycle, the current operation may be used as the first operation.
S320, session data corresponding to the first request is obtained, a session identifier corresponding to the first request is generated, the session identifier is used as a first identifier, the first identifier and the session data are stored in a first service end, and the first identifier is returned to the client.
When the first request does not carry the first identifier, this indicates that no identifier and no data associated with the current operation are stored in any service end, and the current operation is likely to be an operation of the starting client, and the data corresponding to the operation may be referred to as session data. Accordingly, session data corresponding to the first request may be acquired and a session identifier corresponding to the first request may be generated, the session identifier may be used as the first identifier, the first identifier and the session data may be stored in the first server (i.e., the session data may be stored in the first server based on the first identifier), and the first identifier may be returned to the client. Therefore, the first request sent by the client in the session life cycle can carry the first identifier, and only the first identifier is required to be carried, and the whole session data is not required to be carried; meanwhile, after the first server side obtains the first identifier from the first request, the first server side can directly read corresponding session data from the first server side.
S330, the first identifier carried in the first request comprises a session identifier, whether the first request is a login request is determined, if yes, S340 is executed, and if not, S350 is executed.
When the first identifier includes the session identifier, it indicates that the user has started the client in the session life cycle, and at this time, it may further be determined whether the user has logged into the client in the preset login life cycle by determining whether the first request is a login request. It should be noted that, the session life cycle may be a life cycle related to a session operation, and the login life cycle may be a life cycle related to a login operation, which may be the same or different in cycle value, and is not specifically limited herein.
S340, obtaining login data corresponding to the login request, generating a login identifier corresponding to the login request, taking the login identifier as a first identifier, storing the first identifier and the login data in a first service end, and returning the first identifier to the client.
If the first request is a login request, this indicates that the user has not logged into the client in the login lifecycle, that is, the first identifier does not include the login identifier, and no login data related to the current login operation is stored in any service end. Accordingly, the login data corresponding to the login request can be acquired, the login identifier corresponding to the login request is generated, the login identifier is used as the first identifier, the first identifier and the login data are stored in the first service end (namely, the login data are stored in the first service end based on the login identifier), and the first identifier is returned to the client. Therefore, the first request sent by the client in the login life cycle can carry the first identifier, and only the first identifier is required to be carried, so that the whole login data is not required to be carried; meanwhile, after the first server side obtains the first identifier from the first request, the first server side can directly read corresponding login data from the first server side, so that the effect of keeping the login state of the user is achieved.
Execution continues with S350.
S350, acquiring a first area identifier of a first area where the first service end is located, and acquiring a second area identifier from the first identifier carried in the first request.
And S360, if the first area identifier is inconsistent with the second area identifier, determining a second server side deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server side to the second server side.
When the step S340 is executed to step S360, the first identifier carried in the first request is a session identifier, and the session identifier may be an identifier generated by the first service end or an identifier generated by a service end deployed on a remaining area except the first area, so that there may be a case where the first area identifier and the second area identifier in the session identifier are inconsistent.
S370, receiving the first data returned by the second server, and adjusting the second area identifier in the first identifier to the first area identifier to obtain a second identifier.
And S380, storing the received first data based on the second identification, and returning the second identification to the client.
According to the technical scheme, whether the session identifier and the session data corresponding to the first request are obtained can be determined by judging whether the first request carries the first identifier or not, if so, the obtained session data are stored in the first service end, and the session identifier is returned to the client, so that the session identifier can be carried in the first request which is subsequently sent by the client, and the first service end can directly read the session data in itself according to the session identifier; whether the first request is a login request or not can be determined whether login identification and login data corresponding to the login request are obtained or not, if so, the obtained login data are stored in the first service end, the login identification is returned to the client end, the login identification can be carried in the first request which is subsequently sent by the client end, and the first service end can directly read the login data in itself according to the login identification.
On this basis, optionally, generating a session identifier corresponding to the first request may include: a session identifier corresponding to the first request is generated based on the first region identifier, a request timestamp of the first request, and a concatenation result between virtual random generated media/MEDIA ACCESS Control (MAC) addresses. The request timestamp may be a timestamp when the first request is triggered, and the session identifier may be a concatenation result between the first area identifier, the request timestamp and the MAC address. Still alternatively, generating the login identifier corresponding to the login request may include: and generating a login identifier corresponding to the login request based on the first area identifier, the request timestamp of the login request and the splicing result between the MAC addresses. The request timestamp may be a timestamp when the login request is triggered, and the login identifier may be a concatenation result among the first area identifier, the request timestamp and the MAC address, so that the generated login identifier can have global uniqueness and regionality.
Still alternatively, storing the first identifier and the session data in the first service may include: the first identifier is used as a session key, the session data is used as a session value, and the session key and the session value are stored in the first service end in a key value opposite mode. That is, the first identifier and the session data are stored in the first server in a key-value mode, so that the first server can directly read the corresponding session data from the first server according to the acquired first identifier. Still alternatively, storing the first identifier and the login data in the first service end may include: the first identifier is used as a login key, login data is used as a login value, and the login key and the login value are stored in the first service end in a key value mode. That is, the first identifier and the login data are stored in the first server in a key-value mode, so that the first server can directly read the corresponding login data from the first server according to the acquired first identifier.
In order to better understand the specific implementation procedure of the above steps, an exemplary description will be given below of the data synchronization method set forth in each of the above embodiments in connection with a specific example. By way of example, fig. 4 shows an application architecture of a single Client and a multi-zone Server (i.e., servers deployed on different zones, hereinafter referred to as servers), which includes 1 Client (Client) and n servers (servers) located on different zones, each Server having its own redis Server. The following custom vocabulary is explained:
① Ticket: the Ticket data (i.e., the login data set forth above) is the only credential for the user's login status, i.e., login credentials.
② TicketId: part of the socket data is a universal unique identification code (Universally Unique Identifier, uuid) (i.e. login identifier) generated by a user after the internet banking system (which is an example of an application system) logs in successfully, and is used for uniquely identifying the login state of the user and also used as a login key (key) for storing the socket data. uuid can be generated according to a specific factory method (128-bit 16-ary number, first region identification [ 0-Shanghai 1-joint fertilizer ], i.e., 0uuid, 1uuid, which is used to distinguish whether the area of the server where the user is processing the login transaction is Shanghai or syndicated.
③ GlobalSessionId: the user generates when requesting the server for the first time, and is mainly used for storing session data (including non-login and session data after login) in the whole session life cycle. The uuid may be generated according to a specific factory method (128-bit 16-ary number, the first is an area identifier [ 0-Shanghai 1-Hefei ], i.e. 0uuid, 1uuid, which is used to distinguish whether the area where the server processing the request is located is Shanghai or Hefei when the user requests for the first time.
It should be noted that the generation times GlobalSessionId and TicketId may be different, because the user may initially operate in an unregistered state. In addition, the expiration times GlobalSessionId and TicketId may be refreshed during each request. Still further, in addition to the above-described method,
The Ticket data may contain the following (which may change as business rules change):
TicketId Login identification
GlobalSessionId Session identification
LoginId: logon credential numbers, e.g. nicknames, card numbers, etc
MasterId: customer number
UniqueId: user unique ID (login type/client number)
Logined: sign of success or failure of user login, step login for dynamic password login
LoginMode: login mode (entity/electron)
LoginType: login type
CurrentUserType: current login authentication type
LoginDate: login date
LoginOsVer: user login windows version number
Mfm: user login machine code
HostName: login host number
Reserve: login version
On this basis, assuming that the session request of the user for the first time is located at an offshore server (the first service end may be a service end deployed on the offshore server at this time), globalSessionId generated by the offshore server is (08 a66223D1D6D11E8989E5F86861DC1E 1), globalSessionId and corresponding session data are stored in key-value form in an offshore redis server (hereinafter abbreviated as offshore redis) within the offshore server, respectively, while GlobalSessionId is returned to the client.
Similarly, taking the Shanghai server as an example, assuming that the first login request of the user is located at the Shanghai server (where the first service end is a service end deployed on the Shanghai server), the Shanghai server generates TicketId (08A 66223D1D6D11E8989E5F86861DC1E 2), respectively stores TicketId and the packet data containing the user basic information in the Shanghai redis in the Shanghai server in the form of key-value, and returns TicketId to the client.
Further, taking TicketId as an example (GlobalSessionId is similar), synchronization of the Ticket data among redis servers deployed on different areas is performed according to the area identification in TicketId. In particular, the method comprises the steps of,
If the user's second request is still interacting with the server at sea, the client carries the unique TicketId (08A 66223D1D6D11E8989E5F86861DC1E 2) to make the request. Since TicketId and socket data of the user are already stored in the Shanghai server, the user can be directly read from Shanghai redis.
If the second request of the user is to interact with the fertilizer combination server deployed on the fertilizer combination server, at this time, the client still carries TicketId (08 a66223D1D6D11E8989E5F86861DC1E 2) to request (the first server may be the server deployed on the fertilizer combination server, the second server may be the server deployed on the seaside server), after the fertilizer combination server receives the request (i.e., the first request), the fertilizer combination server determines that the area identifier (1) of the client and the area identifier (0) in TicketId (i.e., the second area identifier) are different, so that the fertilizer combination rediss in the fertilizer combination server may request the seadis first, the request TicketId is 08a66223D1D6D11E8989E5F86861DC1E 2's Ticket data, and stores the requested Ticket data in a new TicketId (18 a66223D1D 11E8989E 3489E 5E 2) in the Ticket data, and simultaneously realizes access to the different places by the client. The new TicketId can be understood as a second identifier, which is an identifier obtained by adjusting the second area identifier (0) in the first identifier to the first area identifier (1).
If the user continues to request next time, at this time, both the Shanghai redis and the synthetic fertilizer redis store the Ticket data of the user, and the client stores TicketId associated with Shanghai redis and the new TicketId associated with synthetic fertilizer redis of the user, so that the user request can bring TicketId (08A 66223D1D6D11E8989E5F86861DC1E2 and 18A66223D1D6D11E8989E5F86861DC1E 2) with two different areas at the same time, and therefore, regardless of which area redis the user requests, the Ticket data can be directly acquired in the redis, and the distributed data sharing effect of the multi-area application cluster is realized.
Note that, in addition to the socket data and the session data, login registration information and service cache data may be involved, and the life cycle of these data will be briefly described.
Ticket data:
Login registration information:
Time of deposit Timing of taking out Time to failure refresh Deletion timing
After successful login / When obtaining binding relationship from redis Automatic destruction of dead time
Service cache data:
session data:
example IV
Fig. 5 is a block diagram of a data synchronization device according to a fourth embodiment of the present invention, where the data synchronization device is configured to execute the data synchronization method according to any of the foregoing embodiments. The device and the data synchronization method of each embodiment belong to the same invention conception, and the details of the embodiment of the data synchronization device, which are not described in detail, can be referred to the embodiment of the data synchronization method. Referring to fig. 5, the apparatus is configured at the first service end, and may specifically include: the system comprises a region identification acquisition module 410, a request transmission module 420, an identification acquisition module 430 and a data storage module 440.
The area identifier obtaining module 410 is configured to obtain, when receiving a first request from a client, a first area identifier of a first area where a first service end is located, and obtain a second area identifier from the first identifier carried in the first request;
The request sending module 420 is configured to determine a second server disposed on a second area corresponding to the second area identifier if the first area identifier and the second area identifier are inconsistent, and send a second request for requesting first data corresponding to the first identifier stored in the second server to the second server;
The identifier obtaining module 430 is configured to receive the first data returned by the second server, and adjust the second area identifier in the first identifier to be the first area identifier, so as to obtain a second identifier;
the data storage module 440 is configured to store the received first data based on the second identifier, and return the second identifier to the client.
Optionally, on the basis of the above device, the device may further include:
the data reading module is used for reading the second data corresponding to the first identifier from the first service end if the first region identifier is consistent with the second region identifier after the second region identifier is obtained from the first identifier carried in the first request.
On the basis, optionally, the first request may carry at least two first identifiers, where each first identifier includes a second area identifier, and the data reading module may specifically be used to:
if the target area identifiers consistent with the first area identifiers exist in the second area identifiers, determining the target identifiers containing the target area identifiers in the first identifiers, and reading second data corresponding to the target identifiers from the first service end.
Optionally, the data synchronization device may further include:
the session identifier generation module is used for acquiring session data corresponding to the first request and generating a session identifier corresponding to the first request if the first request does not carry the first identifier;
And the session data storage module is used for taking the session identifier as a first identifier, storing the first identifier and the session data in the first service end, and returning the first identifier to the client.
Optionally, the first identifier carried in the first request is a session identifier, and the data synchronization device may further include:
The login identification generation module is used for acquiring login data corresponding to the login request and generating a login identification corresponding to the login request if the first request is the login request after receiving the first request from the client;
And the login data storage module is used for taking the login identification as a first identification, storing the first identification and the login data in the first service end, and returning the first identification to the client.
On this basis, optionally, the session identifier generating module may include:
A session identifier generating unit, configured to generate a session identifier corresponding to the first request based on the first area identifier, a request timestamp of the first request, and a concatenation result between the virtually randomly generated media access control addresses;
Or, the login identification generating module may include:
And the login identifier generating unit is used for generating a login identifier corresponding to the login request based on the first area identifier, the request timestamp of the login request and the splicing result between the media access control addresses.
Still alternatively, the session data storage module may include:
A session data storage unit, configured to use the first identifier as a session key and session data as a session value, and store the session key and the session value in a first service end in a key value mode;
alternatively, the login data storage module may include:
and the login data storage unit is used for taking the first identifier as a login key and login data as a login value, and storing the login key and the login value in a first service end in a key value mode.
According to the data synchronization device provided by the fourth embodiment of the invention, when the first request from the client is received through the region identifier acquisition module in the first service end, the first region identifier of the first region where the data synchronization device is located can be acquired, and the second region identifier is acquired from the first identifier carried in the first request; if the first area identifier and the second area identifier are different, the request sending module in the first service end indicates that the second service end storing the first data required by the request and the first service end receiving the first request are service ends deployed on different areas, so that the second request for requesting the first data corresponding to the first identifier can be sent to the second service end, and the second service end can send the first data stored by itself to the first service end according to the received second request; when receiving first data returned by the second service end, the identifier obtaining module in the first service end can adjust a second area identifier in the first identifier to be the first area identifier, thereby obtaining a second identifier corresponding to the first data to be stored in the first service end; the data storage module in the first service end stores the received first data based on the second identifier, and returns the second identifier to the client end, so that the service end can directly read the corresponding first data from the service end according to the received first request when any subsequent service end receives the first request sent by the client end. The device is realized based on the architecture of the single client and the multi-region server (namely, the servers deployed on different regions), and based on the region identification, the effect of data synchronization among the multi-region servers is realized by accessing the different-region servers.
The data synchronization device provided by the embodiment of the invention can execute the data synchronization method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
It should be noted that, in the above embodiment of the data synchronization device, each unit and module included are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present invention.
Example five
Fig. 6 is a schematic structural diagram of a first server according to a fifth embodiment of the present invention, as shown in fig. 6, the server includes a memory 510, a processor 520, an input device 530, and an output device 540. The number of processors 520 in the server may be one or more, and one processor 520 is taken as an example in fig. 6; the memory 510, processor 520, input device 530, and output device 540 in the server may be connected by a bus or other means, for example by bus 550 in fig. 6.
The memory 510 is a computer readable storage medium, and may be used to store software programs, computer executable programs, and modules, such as program instructions/modules corresponding to the data synchronization method in the embodiment of the present invention (for example, the area identifier obtaining module 410, the request sending module 420, the identifier obtaining module 430, and the data storage module 440 in the data synchronization device). The processor 520 executes various functional applications of the server and data processing, i.e., implements the data synchronization method described above, by running software programs, instructions, and modules stored in the memory 510.
The memory 510 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, at least one application program required for functions; the storage data area may store data created according to the use of the server, etc. In addition, memory 510 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some examples, memory 510 may further include memory located remotely from processor 520, which may be connected to the device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 530 may be used to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the device. The output 540 may include a display device such as a display screen.
Example six
A sixth embodiment of the present invention provides a storage medium containing computer executable instructions, which when executed by a computer processor, are configured to perform a data synchronization method, applied to a first service side, and may include:
when a first request from a client is received, acquiring a first area identifier of a first area where the first service end is located, and acquiring a second area identifier from the first identifier carried in the first request;
If the first area identifier is inconsistent with the second area identifier, determining a second service end deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second service end to the second service end;
Receiving first data returned by the second server, and adjusting a second area identifier in the first identifier to be the first area identifier to obtain a second identifier;
the received first data is stored based on the second identification, and the second identification is returned to the client.
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present invention is not limited to the method operations described above, and may also perform the related operations in the data synchronization method provided in any embodiment of the present invention.
From the above description of embodiments, it will be clear to a person skilled in the art that the present invention may be implemented by means of software and necessary general purpose hardware, but of course also by means of hardware, although in many cases the former is a preferred embodiment. In light of such understanding, the technical solution of the present invention may be embodied essentially or in part in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, read-Only Memory (ROM), random-access Memory (Random Access Memory, RAM), FLASH Memory (FLASH), hard disk, optical disk, or the like, of a computer, which may be a personal computer, a server, a network device, or the like, including instructions for causing a computer device (which may be a personal computer, a server, or the like) to perform the methods described in the various embodiments of the present invention.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (12)

1. A data synchronization method, applied to a first service end, the method comprising:
When a first request from a client is received, acquiring a first area identifier of a first area where the first service end is located, and acquiring a second area identifier from the first identifier carried in the first request;
If the first area identifier is inconsistent with the second area identifier, determining a second service end deployed on a second area corresponding to the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second service end to the second service end;
Receiving the first data returned by the second server, and adjusting the second area identifier in the first identifier to be the first area identifier to obtain a second identifier;
and storing the received first data based on the second identification, and returning the second identification to the client.
2. The method of claim 1, further comprising, after the obtaining the second area identifier from the first identifier carried in the first request:
And if the first area identifier is consistent with the second area identifier, reading second data corresponding to the first identifier from the first service end.
3. The method according to claim 2, wherein the first request carries at least two first identifiers, and each first identifier includes one second area identifier;
and if the first area identifier is consistent with the second area identifier, reading second data corresponding to the first identifier from the first service end, including:
and if the target area identifiers consistent with the first area identifiers exist in the second area identifiers, determining the target identifiers containing the target area identifiers in the first identifiers, and reading second data corresponding to the target identifiers from the first service end.
4. The method of claim 1, further comprising, after the receiving the first request from the client:
If the first request does not carry the first identifier, session data corresponding to the first request is obtained, and a session identifier corresponding to the first request is generated;
The session identifier is used as the first identifier, the first identifier and the session data are stored in the first service end, and the first identifier is returned to the client.
5. The method of claim 1, wherein the first identifier carried in the first request is a session identifier, and further comprising, after the receiving the first request from the client:
If the first request is a login request, login data corresponding to the login request is obtained, and a login identifier corresponding to the login request is generated;
And taking the login identification as the first identification, storing the first identification and the login data in the first server, and returning the first identification to the client.
6. The method of claim 4, wherein the generating a session identification corresponding to the first request comprises:
And generating a session identifier corresponding to the first request based on the first area identifier, the request time stamp of the first request and a splicing result among the media access control addresses generated in a pseudo-random mode.
7. The method of claim 5, wherein the generating a login identification corresponding to the login request comprises:
and generating a login identifier corresponding to the login request based on the first area identifier, the request time stamp of the login request and a splicing result among the media access control addresses generated in a pseudo-random mode.
8. The method of claim 4, wherein the storing the first identification and the session data in the first server comprises:
And taking the first identifier as a session key and the session data as a session value, and storing the session key and the session value in the first server side in a key value mode.
9. The method of claim 5, wherein storing the first identification and the login data in the first server comprises:
and taking the first identifier as a login key and the login data as a login value, and storing the login key and the login value in the first server in a key value mode.
10. A data synchronization device, configured at a first service end, the device comprising:
The area identification acquisition module is used for acquiring a first area identification of a first area where the first service end is located when a first request from the client is received, and acquiring a second area identification from the first identification carried in the first request;
The request sending module is used for determining a second server deployed on a second area corresponding to the second area identifier if the first area identifier is inconsistent with the second area identifier, and sending a second request for requesting first data corresponding to the first identifier stored in the second server to the second server;
The identifier obtaining module is used for receiving the first data returned by the second server and adjusting the second area identifier in the first identifier to be the first area identifier to obtain a second identifier;
and the data storage module is used for storing the received first data based on the second identification and returning the second identification to the client.
11. A first server, comprising:
one or more processors;
a memory for storing one or more programs;
The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the data synchronization method of any of claims 1-9.
12. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the data synchronization method according to any one of claims 1-9.
CN202110863371.2A 2021-07-29 2021-07-29 Data synchronization method, device, server and storage medium Active CN113572850B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110863371.2A CN113572850B (en) 2021-07-29 2021-07-29 Data synchronization method, device, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110863371.2A CN113572850B (en) 2021-07-29 2021-07-29 Data synchronization method, device, server and storage medium

Publications (2)

Publication Number Publication Date
CN113572850A CN113572850A (en) 2021-10-29
CN113572850B true CN113572850B (en) 2024-05-03

Family

ID=78168909

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110863371.2A Active CN113572850B (en) 2021-07-29 2021-07-29 Data synchronization method, device, server and storage medium

Country Status (1)

Country Link
CN (1) CN113572850B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109635020A (en) * 2018-10-29 2019-04-16 阿里巴巴集团控股有限公司 A kind of processing method of business, device, equipment and system
CN109936523A (en) * 2017-12-15 2019-06-25 腾讯科技(深圳)有限公司 Transregional domain service processing method
CN110795443A (en) * 2019-10-08 2020-02-14 中国建设银行股份有限公司 Method, device, equipment and computer readable medium for data synchronization
WO2020044097A1 (en) * 2018-08-27 2020-03-05 优视科技新加坡有限公司 Method and apparatus for implementing location-based service
CN111556153A (en) * 2020-04-28 2020-08-18 中国工商银行股份有限公司 Information processing method, apparatus, device and medium executed by first server
CN111683045A (en) * 2020-04-28 2020-09-18 中国平安财产保险股份有限公司 Session information processing method, device, equipment and storage medium
CN112612625A (en) * 2020-12-26 2021-04-06 中国农业银行股份有限公司 Service calling method and device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109936523A (en) * 2017-12-15 2019-06-25 腾讯科技(深圳)有限公司 Transregional domain service processing method
WO2020044097A1 (en) * 2018-08-27 2020-03-05 优视科技新加坡有限公司 Method and apparatus for implementing location-based service
CN109635020A (en) * 2018-10-29 2019-04-16 阿里巴巴集团控股有限公司 A kind of processing method of business, device, equipment and system
CN110795443A (en) * 2019-10-08 2020-02-14 中国建设银行股份有限公司 Method, device, equipment and computer readable medium for data synchronization
CN111556153A (en) * 2020-04-28 2020-08-18 中国工商银行股份有限公司 Information processing method, apparatus, device and medium executed by first server
CN111683045A (en) * 2020-04-28 2020-09-18 中国平安财产保险股份有限公司 Session information processing method, device, equipment and storage medium
CN112612625A (en) * 2020-12-26 2021-04-06 中国农业银行股份有限公司 Service calling method and device

Also Published As

Publication number Publication date
CN113572850A (en) 2021-10-29

Similar Documents

Publication Publication Date Title
CN106713391B (en) Session information sharing method and sharing system
CN103621049A (en) System and method for automatically addressing devices in multi-drop network
CN107800733B (en) Method and equipment for generating session identifier in distributed system
CN111327637A (en) Service key management method and system
CN105072608B (en) A kind of method and device of administrative authentication token
CN112118322B (en) Data synchronization method of network equipment, network equipment and system
CN113691646A (en) Domain name service resource access method, device, electronic equipment and medium
CN114338223A (en) User authentication method, system, device, equipment and storage medium
CN111209349A (en) Method and device for updating session time
CN105592083B (en) Method and device for terminal to access server by using token
CN102769677B (en) Towards IPv6 address setting method and the server of real user identity information
CN110311855B (en) User message processing method and device, electronic equipment and storage medium
CN113572850B (en) Data synchronization method, device, server and storage medium
CN114124812A (en) Method and device for maintaining consistency of table items and electronic equipment
CN110868466B (en) Storage method, system and equipment for distributed storage network
CN111327680B (en) Authentication data synchronization method, device, system, computer equipment and storage medium
US7933962B1 (en) Reducing reliance on a central data store while maintaining idempotency in a multi-client, multi-server environment
CN109088918A (en) A kind of exchange method, client device and server device
CN110555040A (en) Data caching method and device and server
CN106959975B (en) Transcoding resource cache processing method, device and equipment
CN109669642B (en) Node joining method, system and device of storage system and readable storage medium
CN106936940A (en) Lease information backup method and system in a kind of Dynamic Host Configuration Protocol server
CN113806447B (en) Data synchronization method, device, equipment and medium
CN112242979A (en) IP address prefix authentication method and equipment based on block chain system
CN113760519B (en) Distributed transaction processing method, device, system and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant