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

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

Info

Publication number
CN113572850A
CN113572850A CN202110863371.2A CN202110863371A CN113572850A CN 113572850 A CN113572850 A CN 113572850A CN 202110863371 A CN202110863371 A CN 202110863371A CN 113572850 A CN113572850 A CN 113572850A
Authority
CN
China
Prior art keywords
identifier
request
area
data
server
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.)
Granted
Application number
CN202110863371.2A
Other languages
Chinese (zh)
Other versions
CN113572850B (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

Images

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 a 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 a second server, and adjusting a second area identifier in the first identifier into a first area identifier to obtain a second identifier; and storing the received first data based on the second identifier, and returning the second identifier to the client. The technical scheme of the embodiment of the invention can synchronize the data between the multi-region service terminals.

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 the large-scale, distributed and multi-computer collaborative direction when deployed. Moreover, most application systems are provided with a session function for storing session data generated when a user operates the application system during a session lifecycle.
Currently, due to the existence of large user volume and high concurrency, and in consideration of disaster recovery, the servers of many application systems are made into multi-area distributed servers, i.e. servers distributed in different areas. However, the conventional session data storage method can only store session data of a certain user in a server deployed in a certain area, and 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 data synchronization device, a server and a storage medium, which are used for achieving the effect of data synchronization in servers 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 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 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;
receiving first data returned by a second server, and adjusting a second area identifier in the first identifier to the first area identifier to obtain a second identifier;
and storing the received first data based on the second identifier, and returning the second identifier to the client.
In a second aspect, an embodiment of the present invention further provides a data synchronization apparatus, configured at a first service end, and including:
the system comprises an area identifier acquisition module, a first service module and a second service module, wherein the area identifier acquisition module is used for acquiring a first area identifier of a first area where a first service terminal is located when receiving a first request from a client, and acquiring a second area identifier from the first identifier carried in the first request;
the request sending module is used for determining a second server deployed on a second area corresponding to a 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, which is stored in the second server, to the second server;
the identification obtaining module is used for receiving first data returned by the second server and adjusting a second area identification in the first identification into a 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 identifier and returning the second identifier 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, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the data synchronization method provided in any embodiment of the present invention.
According to the technical scheme of the embodiment of the invention, when receiving a first request from a client, a first service end can obtain a first area identifier of a first area where the first service end is located, and obtain a second area identifier from the first identifier carried in the first request; if the first area identifier is not consistent with the second area identifier, it indicates that the second server storing the first data required by the request and the first server receiving the first request are servers deployed in different areas, so that the first server can send a second request for requesting the first data corresponding to the first identifier to the second server, so that the second server sends the first data stored by the second server to the first server according to the received second request; when receiving first data returned by the second service side, the first service side may adjust a second area identifier in the first identifier to the first area identifier, thereby obtaining a second identifier corresponding to the first data to be stored in the first service side; and storing the received first data based on the second identifier, and returning the second identifier to the client, so that no matter which subsequent server receives the first request sent by the client, the server can directly read corresponding first data from the server according to the received first request. The technical scheme is realized based on a single client and a multi-region server (namely, servers deployed in different regions) framework, and achieves the effect of data synchronization among the multi-region servers by accessing different-place servers according to the region identification.
Drawings
Fig. 1 is a flowchart of a data synchronization method according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a data synchronization method according to a second embodiment of the present invention;
FIG. 3 is a flow chart of a data synchronization method according to a third embodiment of the present invention;
fig. 4 is a schematic diagram of an alternative example of a data synchronization method in a third embodiment of the present invention;
fig. 5 is a block diagram of a data synchronization apparatus according to a fourth embodiment of the present invention;
fig. 6 is a schematic structural diagram of a first server according to a fifth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
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 for servers deployed in different areas. The method may be performed by the data synchronization apparatus provided in the embodiment of the present invention, and the apparatus may be implemented in software and/or hardware, and the apparatus may be integrated on a first server, and optionally, the first server may be a distributed cache server, such as a redis server, an etc server, and a server deployed 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 provided in a terminal device (e.g., a mobile phone, a computer, etc.) and can be operated by a user, and may be presented to the user in various ways, such as a web page, an Application (APP), etc. The first request may be a request sent by the client to respond to a user operation when the user operates the client (which may be referred to as a user operation), and for example, assuming that the user operation is a click operation acting on the transfer function module, the first request may be a request for reading, writing or updating session data corresponding to the click operation. In practical application, optionally, the request content of the first request may be divided according to the operation type of the user operation, such as 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 server receiving the first request is located, such as shanghai, tianjin, etc., and further such as huangpu area, xu hui area, or chaning area, etc. of shanghai; the number of the servers of the first server deployed on the first area can be one, two or more; the first area identifier may be an area identifier previously set for the first area, such as shanghai is 0, compost is 1, or tianjin is 2. The first identifier may be information that is set in the first request and used to identify the user operation at this time, and may embody multiple meanings, such as a second area identifier, a user identity identifier, a request timestamp identifier, and the like, where the second area identifier may be an area identifier of a second area where a second server storing data (such as session data, login data, and the like) that needs to be operated at this time is located, and the first server and the second server may be servers 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 indicates that the first service end and the second service end are service ends deployed in different areas, that is, the first service end visited 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, for example, two operations of the user before and after caused by a change in routing policy, a change in user location (for example, moving from shanghai to becoming fertile), and the like are allocated to service ends deployed in different areas. Since the data (which may be referred to as first data) required by the 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 the second server may return the first data corresponding to the second request to the first server after receiving the second request, and further allow the first server to respond to the first request according to the received first data.
S130, receiving first data returned by the second server, and adjusting a second area identifier in the first identifier to the first area identifier to obtain a second identifier.
Wherein the area identifier in the first identifier is the second area identifier because the first data corresponding to the first identifier is stored in the second server deployed on the second area (i.e. the area corresponding to the second area identifier). However, now the second server has received the first data, then it may subsequently store the first data in itself, which means that the first data may also be stored in the first server in the future, so that the second area identifier in the first identifier may be adjusted to the first area identifier, resulting in the second identifier, so as to indicate that the first data is also stored in the first server through the second identifier.
S140, storing the received first data based on the second identifier, and returning the second identifier to the client.
The received first data is stored based on the second identifier, that is, the second identifier and the first data are stored as a pair in the first service end, so that corresponding first data can be read in the first service end through the second identifier in the following. Meanwhile, the second identifier may also be returned to the client, so that the first request subsequently sent by the client may simultaneously carry the first identifier and the second identifier. On this basis, because the two service ends store the first data at the same time, and the first request sent again by the client end simultaneously carries the first identifier and the second identifier, whichever service end receives the first request can read the corresponding first data in the service end according to the identifier carried in the first request.
According to the technical scheme of the embodiment of the invention, when receiving a first request from a client, a first service end can obtain a first area identifier of a first area where the first service end is located, and obtain a second area identifier from the first identifier carried in the first request; if the first area identifier is not consistent with the second area identifier, it indicates that the second server storing the first data required by the request and the first server receiving the first request are servers deployed in different areas, so that the first server can send a second request for requesting the first data corresponding to the first identifier to the second server, so that the second server sends the first data stored by the second server to the first server according to the received second request; when receiving first data returned by the second service side, the first service side may adjust a second area identifier in the first identifier to the first area identifier, thereby obtaining a second identifier corresponding to the first data to be stored in the first service side; and storing the received first data based on the second identifier, and returning the second identifier to the client, so that no matter which subsequent server receives the first request sent by the client, the server can directly read corresponding first data from the server according to the received first request. The technical scheme is realized based on a single client and a multi-region server (namely, servers deployed in different regions) framework, and achieves the effect of data synchronization among the multi-region servers by accessing different-place servers according to the region identification.
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 obtaining the second area identifier from the first identifier carried in the first request, the data synchronization method may further include: and if the first area identification is consistent with the second area identification, reading second data corresponding to the first identification from the first service end. The same or corresponding terms as those in the above embodiments are not explained in detail herein.
Referring to fig. 2, the method of the present 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 identification is consistent with the second area identification, reading second data corresponding to the first identification from the first service end, and exiting.
When the first area identifier and the second area identifier are the same, this indicates that second data corresponding to the first identifier is stored in the first service end, where the second data may be data that is initially directly stored in the first service end, or may be data that is acquired by the first service end after accessing a different service end. Therefore, the first server side can directly read the second data corresponding to the first identification from the first server side.
And S230, if the first area identifier is not consistent 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, and adjusting a second area identifier in the first identifier to the first area identifier to obtain a second identifier.
And S250, storing the received first data based on the second identifier, and returning the second identifier to the client.
According to the technical scheme of the embodiment of the invention, when the first area identifier is consistent with the second area identifier, the first service end stores the second data corresponding to the first identifier, 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.
In an optional technical solution, the first request carries at least two first identifiers, and each first identifier includes a second area identifier; 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, which may include: and if the target area identification consistent with the first area identification exists in the second area identifications, determining the target identification containing the target area identification in the first identifications, and reading second data corresponding to the target identification from the first service terminal. As can be known from the above description, 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 the server deployed in which area. After the first server obtains each second area identifier, if it is determined that a target area identifier consistent with the first area identifier exists in each second area identifier, which indicates that second data required by the user operation at this time is stored in the first server, second data corresponding to the target identifier can be read in the first server for the target identifier of each first identifier including the target area identifier, so that an effect of accurately reading the data is achieved.
EXAMPLE III
Fig. 3 is a flowchart of a data synchronization method according to a 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, acquiring session data corresponding to the first request, and generating a session identifier corresponding to the first request; taking the session identifier as a first identifier, storing the first identifier and session data in the first service end, and returning the first identifier to the client;
and/or the presence of a gas in the gas,
the first identifier carried in the first request is a session identifier, and after receiving the first request from the client, the data synchronization method may further include: if the first request is a login request, obtaining login data corresponding to the login request, and generating a login identifier corresponding to the login request; and 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. The same or corresponding terms as those in the above embodiments are not explained in detail 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 the first request carries a first identifier, if not, executing S320, otherwise, executing S330.
Determining whether the first request carries a first identifier, wherein in a normal condition, 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 on the client by the user and the current operation exceeds the preset session life cycle, the current operation may be the first operation.
S320, obtaining the session data corresponding to the first request, generating a session identifier corresponding to the first request, using 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.
When the first request does not carry the first identifier, this indicates that no identifier and data associated with the current operation are stored in any server, and the current operation is likely to be an operation for starting the client, and data corresponding to the operation may be referred to as session data. Accordingly, session data corresponding to the first request may be obtained 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 service end (i.e., the session data may be stored in the first service end 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 needs to be carried, and the whole session data does not need to be carried; meanwhile, after the first server acquires the first identifier from the first request, the corresponding session data can be directly read from the first server.
S330, determining whether the first request is a login request or not, if so, executing S340, and if not, executing S350, wherein the first identifier carried in the first request comprises a session identifier.
When the first identifier includes the session identifier, this indicates that the user has started the client within the session lifecycle, and at this time, it may be further determined whether the user has logged into the client within a preset login lifecycle by determining whether the first request is a login request. It should be noted that the session lifecycle may be a lifecycle related to a session operation, and the login lifecycle may be a lifecycle related to a login operation, which may be the same or different in cycle value, and are not specifically limited herein.
S340, obtaining login data corresponding to the login request, generating a login identification corresponding to the login request, 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.
If the first request is a login request, this indicates that the user has not logged in the client within the login life cycle, that is, the first identifier does not include a login identifier, and login data related to the current login operation is not stored in any server. Accordingly, it is possible to obtain login data corresponding to the login request and generate a login identifier corresponding to the login request, take the login identifier as the first identifier, store the first identifier and the login data in the first server (i.e., store the login data in the first server based on the login identifier), and return the first identifier 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 needs to be carried, so that the whole login data does not need to be carried; meanwhile, after the first server acquires the first identifier from the first request, the corresponding login data can be directly read from the first server, so that the effect of keeping the login state of the user is achieved.
Execution continues with S350.
S350, a first area identification of a first area where the first service end is located is obtained, and a second area identification is obtained from the first identification carried in the first request.
And S360, if the first area identifier is not consistent 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 S340 goes to S360, the first identifier carried in the first request is a session identifier, where the session identifier may be an identifier generated by the first server or an identifier generated by a server deployed in the other area except the first area, and therefore there may be a case where the first area identifier and the second area identifier in the session identifier are not consistent.
And 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 the second identifier.
And S380, storing the received first data based on the second identifier, and returning the second identifier to the client.
According to the technical scheme of the embodiment of the invention, 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, 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 first request sent by the client subsequently can carry the session identifier and the first service end can directly read the session data in the first service end according to the session identifier; whether a login identification and login data corresponding to the login request are obtained or not can be determined by judging whether the first request is the login request or not, if yes, the obtained login data are stored in the first service end and the login identification is returned to the client, so that the login identification can be carried in the first request sent by the client subsequently, and the first service end can directly read the login data in the first service end according to the login identification.
On this basis, optionally, generating the session identifier corresponding to the first request may include: based on the first region identifier, the request timestamp of the first request, and a splicing result between Medium/Media Access Control (MAC) addresses generated virtually randomly, a session identifier corresponding to the first request is generated. Wherein, the request timestamp may be a timestamp when the first request is triggered, and the session identifier may be a concatenation result among the first region identifier, the request timestamp, and the MAC address. Optionally, generating a login identifier corresponding to the login request may include: and generating a login identification corresponding to the login request based on the first area identification, the request timestamp of the login request and the splicing result among 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 locality.
Still optionally, storing the first identifier and the session data in the first service end may include: and taking the first identification as a session key and the session data as a session value, and storing the session key and the session value in the first service end in a key-value pair mode. That is to say, the first identifier and the session data are stored in the first service end in a key-value pair manner, so that the first service end can directly read the corresponding session data from the first service end according to the acquired first identifier. Optionally, the storing the first identifier and the login data in the first service end may include: 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 service end in a key-value pair mode. That is to say, the first identifier and the login data are stored in the first service end in a key value pair manner, so that the first service end can directly read corresponding login data from the first service end according to the acquired first identifier.
In order to better understand the specific implementation process of the above steps, the data synchronization method set forth in the above embodiments is exemplarily described below with reference to specific examples. By way of example, fig. 4 illustrates an application architecture of a single Client and a plurality of servers (i.e., servers deployed in different areas, hereinafter referred to as servers), which includes 1 Client (Client) and n servers (servers) located in different areas, each having its own redis Server. Firstly, the following self-defined words are explained:
ticket: ticket data (i.e., login data as set forth above) is the only credential for the user's login status, i.e., login credentials.
② TicketId: part of the Ticket data is a universal Unique Identifier (uuid) generated after the user successfully logs in the online banking system (which is an example of an application system), and is used for uniquely identifying the login state of the user and also used as a login key (key) for storing the Ticket data. uuid can be generated according to a specific factory method (128-bit 16-system number, the first is area identification [ 0-shanghai 1-compost ], i.e. 0uuid, 1uuid, which is used to distinguish whether the area where the server for user processing login transaction is located is shanghai or compost.
③ GlobalSessionId: the user generates when first requesting the server, and is mainly used for storing session data (including non-login and post-login session data) in the whole session life cycle. uuid can be generated according to a specific factory method (128-bit 16-system number, the first is area identifier [ 0-shanghai 1-compost ], namely 0uuid and 1uuid, which is used for distinguishing whether the area where the server processing the request is located is shanghai or compost when the user requests for the first time.
It should be noted that the generation times of the GlobalSessionId and the TicketId may be different because the user may initially operate in an unregistered state. In addition, the expiration times for the GlobalSessionId and the TicketId may be refreshed during each request. In addition to the above, the present invention is,
the Ticket data may contain the following (which may change as business rules change):
TicketId Login identifier
GlobalSessioncold session identification
loginnid: registration credential numbers, e.g. nicknames, card numbers, etc
master id: customer number
uniqueId: user unique ID (login type/client number)
logic: mark for success or failure of user login, step-by-step login for dynamic password login
logincode: login mode (entity/electronic)
loginType: type of login
currentUserType: type of current login authentication
loginDate: date of login
loginOsVer: user login windows version number
mfm: user login machine code
The hostName: login host number
Reserve: login version
On this basis, assuming that the first session request of the user is located in the shanghai server in shanghai (at this time, the first server may be a server deployed on the shanghai server), the GlobalSessionId generated by the shanghai server is (08a66223D1D6D11E8989E5F86861DC1E1), and the GlobalSessionId and the corresponding session data are stored in the shanghai reidis server (hereinafter, abbreviated as shanghai reidis) in the shanghai server in a key-value form, respectively, while the GlobalSessionId is returned to the client.
Similarly, also taking the shanghai server as an example, assuming that the first login request of the user is located in the shanghai server in shanghai (the first server is the server deployed on the shanghai server at this time), the TicketId generated by the shanghai server is (a)08a66223D1D6D11E8989E5F86861DC1E2), respectively storing the Ticket id and the Ticket data containing the user basic information in key-value form in shanghai redis in the shanghai server, while returning the Ticket id to the client.
Further, taking the Ticket id as an example (GlobalSessionId is similar), the synchronization of the Ticket data between the redis servers deployed in different areas is performed according to the area identifier in the Ticket id. In particular, the method comprises the following steps of,
if the user's second request is still interacting with the Shanghai Server, the client carries a unique TicketId(s) ((s))08a66223D1D6D11E8989E5F86861DC1E 2). Since the nickeld server stores the Ticket id and Ticket data of the user, the user can directly read from the shanghai redis.
If the second request of the user is to interact with the fertilizer mixing server deployed in the fertilizer mixing process, the client still carries TicketId (a)08A66223D1D6D11E8989E5F86861DC1E2) makes a request (the second time at this timeOne server can be a server deployed on a fertilizer combination server, the second server can be a server deployed on a shanghai server, and after receiving a request (i.e., a first request), the fertilizer combination server determines that an area identifier (1, i.e., a first area identifier) of the server is different from an area identifier (0, i.e., a second area identifier) in the ticktid, so that the fertilizer combination rediss in the fertilizer combination server can request the shanghai redis first, and the ticktid is a request0Ticket data of 8A66223D1D6D11E8989E5F86861DC1E2, and the Ticket data requested back is added with a new TicketId (S) ((S))18A66223D1D6D11E8989E5F86861DC1E2) is stored in the fertile redis, and simultaneously, the new TicketId is returned to the client, thereby realizing the sharing of Ticket data by accessing a remote server. The new TicketId can be understood as a second identifier, which is 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 reidis and the combined fertilizer reidis store the Ticket data of the user, and the client side stores the TicketId of the user associated with the shanghai reidis and the new TicketId associated with the combined fertilizer reidis, so that the user request can simultaneously bring two different TicketIds (a) in two areas08A66223D1D6D11E8989E5F86861DC1E2,18a66223D1D6D11E8989E5F86861DC1E2), thereby regardless of which area's redis is requested by the user, the Ticket data can be directly acquired in the redis, thereby achieving the effect of distributed data sharing of a multi-area application cluster.
It should be noted that besides the Ticket data and the session data, login registration information and service cache data may be involved, and the life cycles of these data will now be briefly described.
Ticket data:
Figure BDA0003186602380000161
login registration information:
timing of deposit Timing of taking out Dead time refresh Timing of deletion
After login is successful / When obtaining binding relationship from redis Automatic destruction of time to failure
Service cache data:
Figure BDA0003186602380000171
conversation data:
Figure BDA0003186602380000172
example four
Fig. 5 is a block diagram of a data synchronization apparatus according to a fourth embodiment of the present invention, which is configured to execute a data synchronization method according to any of the foregoing embodiments. The device and the data synchronization method of the above embodiments belong to the same inventive concept, and details that are not described in detail in the embodiments of the data synchronization device may refer to the embodiments of the data synchronization method. Referring to fig. 5, the apparatus is configured at the first service end, and specifically may include: the system comprises an area identification acquisition module 410, a request sending module 420, an identification acquisition module 430 and a data storage module 440.
The area identifier obtaining module 410 is configured to, when receiving a first request from a client, obtain 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;
a request sending module 420, configured to determine, if the first area identifier is inconsistent with the second area identifier, a second server deployed in a second area corresponding to the second area identifier, and send a second request for requesting first data corresponding to the first identifier stored in the second server to the second server;
an identifier obtaining module 430, configured to receive first data returned by the second server, and adjust a second area identifier in the first identifier to the first area identifier to obtain a second identifier;
and 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 apparatus, the apparatus may further include:
and the data reading module is used for reading second data corresponding to the first identifier from the first service terminal if the first area identifier is consistent with the second area identifier after the second area identifier is obtained from the first identifier carried in the first request.
On this basis, optionally, the first request may carry at least two first identifiers, each first identifier includes a second area identifier, and the data reading module may be specifically configured to:
and if the target area identification consistent with the first area identification exists in the second area identifications, determining the target identification containing the target area identification in the first identifications, and reading second data corresponding to the target identification from the first service terminal.
Optionally, the data synchronization apparatus 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 apparatus may further include:
the login identification generation module is used for acquiring login data corresponding to a login request and generating a login identification corresponding to the login request if the first request is the login request after the first request from the client is received;
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, the request timestamp of the first request, and a splicing result between the virtual randomly generated mac addresses;
or, the login identifier generating module may include:
and the login identification generating unit is used for generating a login identification corresponding to the login request based on the first area identification, the request timestamp of the login request and the splicing result among the media access control addresses.
Still optionally, the session data storage module may include:
the session data storage unit is used for 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 service end in a key-value pair mode;
or, 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 the login data as a login value, and storing the login key and the login value in the first service end in a key-value pair mode.
In the data synchronization apparatus provided in the fourth embodiment of the present invention, when receiving a first request from a client through an area identifier obtaining module in a first server, a first area identifier of a first area where the data synchronization apparatus is located may be obtained, and a second area identifier is obtained 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 server indicates that the second server storing the first data required by the request and the first server receiving the first request are servers deployed in different areas, so that a second request for requesting the first data corresponding to the first identifier can be sent to the second server, and the second server can send the first data stored by the second server to the first server according to the received second request; when receiving first data returned by a second server, an identifier obtaining module in the first server may adjust a second area identifier in the first identifier to the first area identifier, thereby obtaining a second identifier corresponding to the first data to be stored in the first server; and 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, so that when any subsequent service end receives the first request sent by the client, the service end can directly read corresponding first data from the service end according to the received first request. The device is realized based on the architectures of a single client and a plurality of region servers (namely, the servers deployed in different regions), and realizes the effect of data synchronization among the plurality of region servers by accessing different region servers according to the region identifiers.
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 corresponding functional modules and beneficial effects of the execution method.
It should be noted that, in the embodiment of the data synchronization apparatus, the included units and modules are only divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting 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 first server includes a memory 510, a processor 520, an input device 530, and an output device 540. The number of the processors 520 in the server may be one or more, and fig. 6 illustrates one processor 520 as an example; the memory 510, processor 520, input device 530, and output device 540 in the server may be connected by a bus or other means, such as by bus 550 in fig. 6.
The memory 510 is used as a computer-readable storage medium for storing 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 region identification obtaining module 410, the request sending module 420, the identification obtaining module 430, and the data storage module 440 in the data synchronization apparatus). The processor 520 executes various functional applications of the server and data processing by executing software programs, instructions, and modules stored in the memory 510, that is, implements the above-described data synchronization method.
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, an application program required for at least one function; the storage data area may store data created according to the use of the server, and the like. Further, the 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 devices through 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 generate key signal inputs related to user settings and function control of the device. The output device 540 may include a display device such as a display screen.
EXAMPLE six
An embodiment of the present invention provides a storage medium containing computer-executable instructions, where the computer-executable instructions are used to execute a data synchronization method when executed by a computer processor, and the method is applied to a first server, and may include:
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 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;
receiving first data returned by a second server, and adjusting a second area identifier in the first identifier to the first area identifier to obtain a second identifier;
and storing the received first data based on the second identifier, and returning the second identifier to the client.
Of course, the storage medium provided by the embodiment of the present invention contains computer-executable instructions, and the computer-executable instructions are not limited to the operations of the method described above, and may also perform related operations in the data synchronization method provided by any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. With this understanding, the technical solutions of the present invention may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. 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, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A data synchronization method is applied to a first service end, and the method 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 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;
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 storing the received first data based on the second identifier, and returning the second identifier to the client.
2. The method according to claim 1, further comprising, after obtaining the second area identifier from the first identifier carried in the first request:
and if the first area identification is consistent with the second area identification, reading second data corresponding to the first identification 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;
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:
if a target area identifier consistent with the first area identifier exists in each second area identifier, determining that each first identifier contains the target identifier of the target area identifier, and reading second data corresponding to the target identifier from the first service terminal.
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, acquiring session data corresponding to the first request, and generating a session identifier corresponding to the first request;
taking the session identifier as the first identifier, storing the first identifier and the session data in the first service end, and returning the first identifier to the client.
5. The method of claim 1, wherein the first identifier carried in the first request is a session identifier, and after the receiving the first request from the client, the method further comprises:
if the first request is a login request, obtaining login data corresponding to the login request, and generating a login identifier corresponding to the login request;
and taking the login identification as the first identification, storing the first identification and the login data in the first service end, and returning the first identification to the client.
6. The method according to claim 4 or 5, characterized in that:
the generating a session identifier corresponding to the first request includes: generating a session identifier corresponding to the first request based on the first region identifier, the request timestamp of the first request, and a splicing result among the virtual randomly generated media access control addresses;
or the light source is used for emitting light,
the generating of the login identification corresponding to the login request includes: and generating a login identification corresponding to the login request based on the first area identification, the request timestamp of the login request and the splicing result among the media access control addresses.
7. The method according to claim 4 or 5, characterized in that:
the storing the first identifier and the session data in the first service side includes:
taking the first identification 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 in a key-value pair mode;
or the light source is used for emitting light,
the storing the first identifier and the login data in the first service side includes:
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 pair mode.
8. A data synchronization apparatus configured at a first service end, the apparatus comprising:
the system comprises an area identifier acquisition module, a first service module and a second service module, wherein the area identifier acquisition module is used for acquiring a first area identifier of a first area where a first service terminal is located when receiving a first request from a client, and acquiring a second area identifier from the first identifier carried in the first request;
a request sending module, configured to determine, if the first area identifier is inconsistent with the second area identifier, a second server deployed in a second area corresponding to the second area identifier, and send a second request for requesting first data corresponding to the first identifier, stored in the second server, to the second server;
an identifier obtaining module, configured to receive the first data returned by the second server, and adjust the second area identifier in the first identifier to 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 identifier and returning the second identifier to the client.
9. A first server, comprising:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a data synchronization method as recited in any of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the data synchronization method according to any one of claims 1 to 7.
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 true CN113572850A (en) 2021-10-29
CN113572850B 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
CN113572850B (en) 2024-05-03

Similar Documents

Publication Publication Date Title
CN109684414B (en) Method, device and equipment for synchronizing block data and storage medium
US10187445B2 (en) System, method and browser client for enabling browser data synchronization
CN111489256B (en) Cross-chain processing method, device and system for multi-chain block chain system
CN111091429A (en) Electronic bill identification distribution method and device and electronic bill generation system
CN106713391B (en) Session information sharing method and sharing system
CN103621049A (en) System and method for automatically addressing devices in multi-drop network
US20210158310A1 (en) Blockchain-based transaction processing methods and apparatuses and electronic devices
CN112714192B (en) Data synchronization method and device, computer readable medium and electronic equipment
CN109120614B (en) Service processing method and device based on distributed system
CN109040263B (en) Service processing method and device based on distributed system
CN111464356B (en) Block consensus period switching method and device and computer equipment
CN112118322B (en) Data synchronization method of network equipment, network equipment and system
CN112738294B (en) Domain name resolution method and device based on block chain, electronic equipment and storage medium
CN113746641B (en) ODX protocol processing method based on distributed storage
CN112087401A (en) Method and device for realizing service quality in distributed storage
CN113886743B (en) Method, device and system for refreshing cache resources
CN110708390A (en) Data processing method, device, apparatus and medium based on inter-node data sharing
CN111092958B (en) Node access method, device, system and storage medium
CN111327680B (en) Authentication data synchronization method, device, system, computer equipment and storage medium
CN110868466B (en) Storage method, system and equipment for distributed storage network
CN113572850A (en) Data synchronization method, device, server and storage medium
CN111767481A (en) Access processing method, device, equipment and storage 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
CN115422184A (en) Data acquisition method, device, equipment and storage medium

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