CN113672682A - Synchronous frame based quantity synchronization method and synchronization device - Google Patents

Synchronous frame based quantity synchronization method and synchronization device Download PDF

Info

Publication number
CN113672682A
CN113672682A CN202110949465.1A CN202110949465A CN113672682A CN 113672682 A CN113672682 A CN 113672682A CN 202110949465 A CN202110949465 A CN 202110949465A CN 113672682 A CN113672682 A CN 113672682A
Authority
CN
China
Prior art keywords
synchronization
database
statistical
full
statistical objects
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
CN202110949465.1A
Other languages
Chinese (zh)
Other versions
CN113672682B (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.)
Guangzhou Youxin Technology Co ltd
Original Assignee
Guangzhou Youxin Technology 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 Guangzhou Youxin Technology Co ltd filed Critical Guangzhou Youxin Technology Co ltd
Priority to CN202110949465.1A priority Critical patent/CN113672682B/en
Publication of CN113672682A publication Critical patent/CN113672682A/en
Application granted granted Critical
Publication of CN113672682B publication Critical patent/CN113672682B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a quantity synchronization method and a synchronization device based on a synchronization frame, wherein the method initiates a quantity update request to a second device after acquiring a quantity update event message of a first device, and the second device updates the quantity according to the quantity update request; when the number of the second devices is updated successfully, updating the number of the synchronous databases according to the names of the statistical objects and the change number to obtain a first statistical number; generating a synchronization frame according to the first statistic amount and the name of the statistical object and sending the synchronization frame to the second equipment, so that the second equipment feeds back the current amount of the statistical object in the second database at the current moment when receiving the synchronization frame; calculating a difference value between the first statistical quantity and the current quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference value when the difference value is not zero; the method and the device can improve the accuracy of quantity synchronization.

Description

Synchronous frame based quantity synchronization method and synchronization device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a number synchronization method and a synchronization apparatus based on synchronization frames.
Background
In the development of application software in a specific field, particularly in a multi-tenant-oriented SaaS platform, data of tenants (such as the number of commodities, hospital beds, the number of remaining consumption cards, and the like) are hosted on the platform, and sources of the data may come from other external systems, and it is required to ensure that the data of the internal system is consistent with that of the external system, and real-time and accurate data are required.
Data synchronization of an internal system with an external system is generally divided into two parts: one is that when the number of objects to be counted (for example, the number of commodities, hospital beds, the number of remaining consumer cards, and the like) changes, the internal system needs to synchronize the changed data with the external system. And secondly, when the number of the statistical objects changes, the external system needs to synchronize the changed data to the external system. Taking the quantity of commodities in the e-commerce field as an example, if the commodity inventory data depends on an external system, data synchronization of two aspects is generally needed; one aspect is that when the stock data of the internal system changes (e.g., a user places an order, cancels an order, etc.), the stock data after the change of the internal system needs to be synchronized with the external system. Another aspect is that when the stock data of the external system changes (for example, the number of products is considered to be added), the stock data after the change of the external system needs to be synchronized with the internal system.
In order to solve the problem of the number synchronization of the statistical objects between the internal system and the external system, in the prior art, a method is adopted, on one hand, when the number of the statistical objects changes, the internal system sends a number updating request to the external system, so that the external system updates the number of the statistical objects in the external system after receiving the number updating request, and the data synchronization when the number of the statistical objects in the internal system changes is completed through the step. On the other hand, a timing task is set, the internal system acquires the latest data of the external system at intervals, full synchronization is carried out, the number of the statistical objects of the database corresponding to the external system is covered on the database of the internal system, and the change situation of the number of the statistical objects in the external system can be synchronized to the internal system through the step.
However, with the above method, the external system database and the internal system data are synchronized in full by the timing task, and once the number of the statistical objects in the internal system changes many times in a short time, a synchronization error may occur. For example, in the initial state, the inventory of the product a in both the external system and the internal system is 10. In a short time, a user makes two orders, the first order making quantity is 2, the second order making quantity is 3, the stock quantity of the commodity A in the internal system changes for many times in a short time, the stock quantity of the commodity A is immediately deducted twice to be 5, and two quantity updating requests are sent to the external system in sequence, the external system updates the quantity after receiving the first quantity updating request, the stock quantity of the commodity A in the external system is updated to 8, the second quantity updating request is received and then is deducted continuously, if the external system receives the first quantity updating request and does not receive the second quantity updating request, a timing task is started, the external system synchronizes the stock quantity after receiving the first quantity updating request to the internal system, namely, the stock quantity of the commodity A in the external system is 8, and the stock quantity of the commodity A in the internal system is covered by the stock quantity of the commodity A in the internal system 5, this changes the stock amount of the article a in the internal system from 5 to 8, which causes a problem of a quantity synchronization error.
Disclosure of Invention
The embodiment of the invention provides a quantity synchronization method based on a synchronization frame, which can improve the accuracy of quantity synchronization.
An embodiment of the present invention provides a number synchronization method based on a synchronization frame, including: acquiring a quantity updating event message of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: counting object names and change quantity;
initiating a quantity updating request to second equipment according to the quantity updating event message so that the second equipment updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity when receiving the quantity updating request; the second database is a database corresponding to the second device;
when the number of the statistical objects stored in the second database is successfully updated, updating the number of the statistical objects stored in the synchronous database according to the names of the statistical objects and the change number to obtain a first statistical number of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database and the synchronization database;
generating a synchronization frame according to the first statistical amount and the statistical object name, and sending the synchronization frame to the second device, so that the second device feeds back the current amount of the statistical objects in the second database at the current moment when receiving the synchronization frame;
and calculating a difference value between the current quantity and the first statistical quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference value when the difference value is not zero.
Further, before acquiring the number update event message of the first device, the method further includes:
receiving a full-quantity synchronous application instruction sent by first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization;
initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request;
according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame;
and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
Further, when the number of the statistical objects stored in the second database fails to be updated, feeding back number update failure information to the first device, so that the first device cancels the update of the number of the statistical objects stored in the first database after receiving the number update failure information.
Further, if the quantity update event message of the first device is not obtained within a preset time, initiating a second full-quantity synchronization request to the second device, so that the second device feeds back the existing quantity of the statistical objects when receiving the second full-quantity synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame.
Further, the acquiring the number update event message of the first device specifically includes:
acquiring the quantity updating event message from a preset message queue; and after generating the quantity updating event message, the first device stores the quantity updating event message in the preset message queue.
On the basis of the embodiment of the method item, the invention correspondingly provides a number synchronization device based on the synchronization frame, and the number synchronization device comprises: the device comprises an update event message acquisition module, a quantity update request initiating module, a local quantity update module, a synchronous frame generation module and a difference increment synchronization module;
the update event message acquisition module is used for acquiring the number update event messages of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: counting object names and change quantity;
the quantity updating request initiating module is configured to initiate a quantity updating request to a second device according to the quantity updating event message, so that when the second device receives the quantity updating request, the second device updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity; the second database is a database corresponding to the second device;
the local quantity updating module is used for updating the quantity of the statistical objects stored in the synchronous database according to the name of the statistical object and the quantity of the change when the quantity of the statistical objects stored in the second database is successfully updated, so as to obtain a first statistical quantity of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database and the synchronization database;
the synchronization frame generation module is configured to generate a synchronization frame according to the first statistical amount and the statistical object name, and send the synchronization frame to the second device, so that the second device feeds back the current number of statistical objects in the second database at the current time when receiving the synchronization frame;
and the difference increment synchronization module is used for calculating the difference between the current quantity and the first statistical quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference when the difference is not zero.
Further, the device for synchronizing based on the number of the synchronization frames further comprises: an initial quantity full-scale synchronization module;
the initial quantity and total quantity synchronization module is used for receiving a total quantity synchronization application instruction sent by the first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization;
initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request;
according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame;
and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
Further, the device for synchronizing based on the number of the synchronization frames further comprises: a quantity update reset module;
the quantity updating and resetting module is configured to, when the quantity updating of the statistical objects stored in the second database fails, feed back quantity updating failure information to the first device, so that the first device cancels the updating of the quantity of the statistical objects stored in the first database after receiving the quantity updating failure information.
Further, the device for synchronizing based on the number of the synchronization frames further comprises: a cold data synchronization module;
the cold data synchronization module is configured to initiate a second full-scale synchronization request to the second device if the quantity update event message of the first device is not obtained within a preset time length, so that the second device feeds back the existing quantity of the statistical object when receiving the second full-scale synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a quantity synchronization method and a synchronization device based on a synchronization frame, wherein the method initiates a quantity update request to second equipment after acquiring a quantity update event message of first equipment, and then the second equipment updates the quantity according to the quantity update request; when the number of the second equipment is successfully updated, updating the number of the synchronous database according to the name of the statistical object and the changed number to obtain a first statistical number, then generating a synchronous frame according to the first statistical number and the name of the statistical object and sending the synchronous frame to the second equipment, so that the second equipment feeds back the current number of the statistical object in the second database at the current moment when receiving the synchronous frame; finally, calculating a difference value between the first statistical quantity and the current quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference value when the difference value is not zero; compared with the prior art, when the number of the statistical objects of the second equipment is synchronized to the first equipment, the full synchronization is not performed through the timing task, but the difference value of the statistical number in the synchronization database and the second database corresponding to the second equipment is calculated, and then the synchronization is performed according to the difference value, so that the problem of number synchronization error caused by the full synchronization performed through the timing task when the number of the statistical objects in the first equipment changes for multiple times in a short time is solved.
Drawings
Fig. 1 is a flowchart illustrating a synchronization frame-based quantity synchronization method according to an embodiment of the present invention.
Fig. 2 is a schematic structural diagram of a synchronization apparatus based on the number of synchronization frames according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the synchronization frame-based quantity synchronization method according to any embodiment of the present invention may be executed by a synchronization component, and the synchronization component may be provided to a user in an SDK manner, or may be independently deployed as a service, and used as a synchronization device to execute the synchronization frame-based quantity synchronization method.
As shown in fig. 1, an embodiment of the present invention provides a synchronization method based on the number of synchronization frames, which at least includes the following steps:
step S101: acquiring a quantity updating event message of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: and counting the object names and the change quantity.
Step S102, initiating a quantity updating request to a second device according to the quantity updating event message, so that the second device updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity when receiving the quantity updating request; and the second database is a database corresponding to the second equipment.
Step S103, when the number of the statistical objects stored in the second database is successfully updated, updating the number of the statistical objects stored in the synchronous database according to the name of the statistical object and the change number to obtain a first statistical number of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database, and the synchronization database.
Step S104, generating a synchronization frame according to the first statistical amount and the statistical object name, and sending the synchronization frame to the second device, so that the second device feeds back the current amount of the statistical objects in the second database at the current time when receiving the synchronization frame.
Step S105 calculates a difference between the current number and the first statistical number, and synchronizes the number of statistical objects in the first database according to the difference when the difference is not zero.
For step S101, in a preferred embodiment, before acquiring the number update event message of the first device, the method further includes: receiving a full-quantity synchronous application instruction sent by first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization; initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request; according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame; and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
In a preferred embodiment, the acquiring the number update event message of the first device specifically includes:
acquiring the quantity updating event message from a preset message queue; and after generating the quantity updating event message, the first device stores the quantity updating event message in the preset message queue.
Specifically, in the present invention, the second device is a device for storing a data source, and may be a server for storing a data source of an article quantity (that is, may be understood as an external system mentioned in the background), the second device provides raw data of a statistical object for the first device (that is, may be understood as an internal system mentioned in the background), the first device implements various functions based on the data source provided by the second device, and the first device may be a server, a mobile phone terminal, a computer, or the like. Data of the first device is stored in a first database. The data of the second device is stored in a second database. The statistical objects include, but are not limited to, inventory of goods, hospital beds, remaining times of consumption cards, and the like.
Firstly, initializing data in first equipment, and synchronizing the initial number of statistical objects stored in a second database in second equipment to a first database by the first equipment in a full-scale pulling mode to finish the initialization of the data in the first equipment. After the data in the first device is initialized, the initial number of the statistical objects stored in the second database is synchronized to the synchronous database, and at the moment, the number of the statistical objects in the first database, the number of the statistical objects in the second database and the number of the statistical objects in the synchronous database are kept consistent. The synchronization database is an independent database which is corresponding to the synchronization component executing the synchronization frame-based quantity synchronization method of the invention. Taking the inventory of the commodity as an example, assuming that the inventory of the commodity a stored in the second database corresponding to the second device is 10, the above operation is performed; the stock of the article a stored in the first database is also 10, and the stock of the article a stored in the synchronization database is also 10.
When a user performs ordering operation through the first device, for example, 3 a commodities are purchased, the stock quantity of the a commodity is changed, the stock quantity of the a commodity stored in the first database is updated through the first device, and after the update, the stock quantity of the a commodity stored in the first database is changed to 7, assuming that the stock quantity of the a commodity stored in the first database is 10 originally; meanwhile, generating a quantity updating event message, wherein the quantity updating event message comprises the following statistical object names: inventory of A goods, change quantity 3; then, the quantity updating event message is stored in the message queue, and a quantity updating event message is generated and stored in the message queue every time the quantity is changed, for example, a user performs a second ordering operation through the first device, for example, a purchase of 4 a commodities occurs, at this time, the stock quantity of the a commodity is changed twice, at this time, the first device updates the stock quantity of the a commodity stored in the first database to 3, and then a second quantity updating event message is generated, wherein the second quantity updating event message comprises a statistical object name: the stock of the A goods, change the quantity 4; and then stored in a message queue.
And the synchronization component starts to consume the quantity updating event message in the message queue after the preset time length, so as to obtain the quantity updating event message of the first device.
For step S102, initiating a quantity update request to the second device every time the quantity update event message is consumed, and still taking the above example as an example, after the first quantity update event message is consumed, initiating a first quantity update request to the second device, where the first quantity update request includes the statistical object name: stock of article a, and change amount: 3; after receiving the quantity updating request, the second device updates the inventory of the commodity A stored in the corresponding second database, so that the inventory of the commodity A stored in the second database is also updated to 7; then after the updating is successful, a message of successful updating is fed back to the synchronization component;
as for step S103, still taking the above example as an example, after receiving the message of successful update, it is determined that the inventory of the article a stored in the second database is successfully updated, and then the inventory of the article a stored in the synchronous database is updated, at this time, the inventory of the article a in the synchronous database is also updated to 7; and then 7 as the first statistical amount of inventory for item a.
For step S104, still taking the above example as an example, according to the first statistical amount: 7, and statistical object name: the inventory of the commodity A generates a synchronous frame, and then the synchronous frame is sent to the second equipment; after receiving the synchronization frame, the second device counts the current quantity of the inventory of the commodity A; in practical situations, the data source corresponding to the second device may be used by other devices except the first device, so that the stock quantity of the article a in the second database may be reduced due to ordering actions of the other devices, and in addition, some users may perform replenishment, and then modify the stock quantity of the article a in the second database, resulting in an increase in the stock quantity of the article a in the second database, so that in practical situations, the current quantity may be in the following three situations:
1. if the inventory of the commodity A in the second database is not changed in the period from the completion of the update of the inventory quantity of the commodity A stored in the second database to the reception of the synchronization frame, the current quantity is still 7;
2. if the inventory of the article a in the second database is increased (if the user performs replenishment, which causes the change of the inventory quantity of the article a in the second database) in the period from the completion of updating the inventory quantity of the article a stored in the second database to the reception of the synchronization frame, if the inventory quantity of the article a in the second database is increased by 4, the current quantity is 11 at this time.
3. If the inventory of the article a in the second database is reduced (for example, ordering behavior of other devices) by 4, for example, during the period from the completion of updating the inventory quantity of the article a stored in the second database to the reception of the synchronization frame, the current quantity is 3 at this time.
In step S105, still taking the above example as an example, if the inventory of the item a in the second database does not change during the period from the completion of the update of the inventory quantity of the item a stored in the second database to the reception of the synchronization frame, the current quantity and the first statistical quantity are both 7 at this time, and the difference is O, which indicates that the inventory quantity of the item a in the second database is not affected by other factors other than the change in inventory in the first device and changes, and at this time, the inventory quantity of the item a stored in the first database and the inventory quantity of the item a stored in the second first database are still the same, so synchronization is not necessary.
If the inventory of the article a in the second database is increased in the period from the update of the inventory quantity of the article a stored in the second database to the reception of the synchronization frame, if the inventory quantity of the article a in the second database is increased by 4, it indicates that the inventory quantity of the article a in the second database is influenced by other reasons except the change of the inventory in the first device, and needs to be synchronized, and the current quantity is 10 at this time, and the first statistical quantity is 7, and the difference between the current quantity and the first statistical quantity is +3, then a quantity synchronization message is sent to the first device, and after receiving the quantity synchronization message, the first device changes the inventory quantity of the article a stored in the first database from 7 to 11 according to the difference, and completes the quantity synchronization.
If the inventory of the product a in the second database is reduced in the period from the update of the inventory quantity of the product a stored in the second database to the reception of the synchronization frame, if the inventory quantity of the product a in the second database is reduced by 3, it indicates that the inventory quantity of the product a in the second database is influenced by other reasons except the change of the inventory in the first device, and needs to be synchronized, and the current quantity is 4 at this time, and the first statistical quantity is 7, and the difference between the current quantity and the first statistical quantity is-3, then a quantity synchronization message is sent to the first device at this time, and after receiving the quantity synchronization message, the first device changes the inventory quantity of the product a stored in the first database from 7 to 4 according to the difference, and completes the quantity synchronization.
By implementing the above embodiment of the present invention, even if the number of the statistical objects of the first device changes for multiple times in a short time, no number synchronization error will be caused, and to better illustrate the beneficial effects of the present invention, the following is described with specific examples:
assuming that the initial quantity of the inventory of the commodity A in the first database, the synchronous database and the second database is 10;
a user performs a ordering operation in a short time through first equipment, and orders 3A commodities for the first time; at this time, the stock quantity of the A commodity stored in the first database is immediately reduced to 7; generating a first number of update event messages to a message queue; after consuming the first quantity update event message, the synchronization component sends a first quantity update request to the second device, and the second device changes the inventory quantity of the commodity a in the second database to 7 according to the first quantity update request. If the user orders for the second time at the time node, purchasing 4 commodities A; at the moment, the stock quantity of the commodity A stored in the first database is immediately reduced to 3, and a second quantity updating message is generated; after the second device finishes updating the inventory of the commodity A in the second database according to the first quantity updating request, the inventory quantity 7 of the commodity A in the second database is not directly synchronized into the first database, but an updating success message is fed back to the synchronization component, then the synchronization component changes the inventory quantity of the commodity A in the synchronization database to 7 to obtain a first statistical quantity, then a synchronization frame is generated and sent to the second device, the current quantity of the inventory of the commodity A in the second device feedback is calculated by the synchronization component, if the inventory quantity of the commodity A in the second database is not influenced by other reasons except the change of the inventory in the first device, the difference is 0 at the moment, the inventory quantity of the commodity A in the first database cannot be synchronized, the inventory quantity of the commodity A in the first database is still 3 and is real and accurate inventory data, the inventory quantity of the commodity A in the second database and the inventory quantity of the commodity A in the synchronous database are changed into 3 after the second quantity updating message is subsequently consumed, the data are kept consistent, if the inventory quantity of the commodity A in the second database is increased by 3 due to other reasons except the change of the inventory in the first equipment, the inventory quantity of the commodity A in the second database is 10 before the second quantity updating message is consumed, and the calculated difference value is 3; the stock quantity of item a in the first database is then 6 by adding 3 to the difference, which is then also taken exactly, and after the second quantity update message is consumed, the stock quantity of item a in the second database is also changed back to 6, which is consistent with the data in the first database. Therefore, the problem of inaccurate quantity synchronization in the prior art can be solved, and in addition, due to the message queue and the decoupling of the synchronization component, even if the second device is temporarily unavailable, the normal deduction logic processing of the first device is not influenced.
In a preferred embodiment, further comprising: when the number of the statistical objects stored in the second database fails to be updated, feeding back number update failure information to the first device, so that the first device cancels the updating of the number of the statistical objects stored in the first database after receiving the number update failure information. In this embodiment, if the second device updates the data in the second database according to the quantity update request, but the update fails, the second device feeds back a quantity update failure message to the synchronization component, and then the synchronization component forwards the quantity update failure message to the first device, and the first device cancels the update of the data in the first database after receiving the quantity update failure message, and resets the updated data in the original first database. For example: initially, the inventory of the commodity a stored in the first database is 10; the user performs ordering operation through the first device, for example, 3 a commodities are purchased, and at the moment, the first device updates the stock quantity of the commodity a stored in the first database to 7; and sending a generated quantity updating event message, sending a quantity updating request to the second equipment by the synchronous component consuming quantity updating event message, updating the quantity by the second equipment according to the quantity updating request, generating quantity updating failure information if the updating fails, then feeding back the quantity updating failure information to the first equipment by the synchronous component, and resetting the inventory quantity of the A commodity stored in the first database to 10 after the first equipment receives the quantity updating failure information.
In a preferred embodiment, further comprising: if the quantity updating event message of the first equipment is not acquired within a preset time length, initiating a second full-quantity synchronization request to the second equipment so that the second equipment feeds back the existing quantity of the statistical objects when receiving the second full-quantity synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame. By the embodiment, the data corresponding to the second equipment can be synchronized to the first equipment when the data is cold.
On the basis of the above method item embodiments, the present invention correspondingly provides apparatus item embodiments;
as shown in fig. 2, an embodiment of the present invention provides a synchronization device based on the number of synchronization frames, including: the device comprises an update event message acquisition module, a quantity update request initiating module, a local quantity update module, a synchronous frame generation module and a difference increment synchronization module;
the update event message acquisition module is used for acquiring the number update event messages of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: counting object names and change quantity;
the quantity updating request initiating module is configured to initiate a quantity updating request to a second device according to the quantity updating event message, so that when the second device receives the quantity updating request, the second device updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity; the second database is a database corresponding to the second device;
the local quantity updating module is used for updating the quantity of the statistical objects stored in the synchronous database according to the name of the statistical object and the quantity of the change when the quantity of the statistical objects stored in the second database is successfully updated, so as to obtain a first statistical quantity of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database and the synchronization database;
the synchronization frame generation module is configured to generate a synchronization frame according to the first statistical amount and the statistical object name, and send the synchronization frame to the second device, so that the second device feeds back the current number of statistical objects in the second database at the current time when receiving the synchronization frame;
and the difference increment synchronization module is used for calculating the difference between the current quantity and the first statistical quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference when the difference is not zero.
In a preferred embodiment, further comprising: an initial quantity full-scale synchronization module;
the initial quantity and total quantity synchronization module is used for receiving a total quantity synchronization application instruction sent by the first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization;
initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request;
according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame;
and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
In a preferred embodiment, further comprising: a quantity update reset module;
the quantity updating and resetting module is configured to, when the quantity updating of the statistical objects stored in the second database fails, feed back quantity updating failure information to the first device, so that the first device cancels the updating of the quantity of the statistical objects stored in the first database after receiving the quantity updating failure information.
In a preferred embodiment, further comprising: a cold data synchronization module;
the cold data synchronization module is configured to initiate a second full-scale synchronization request to the second device if the quantity update event message of the first device is not obtained within a preset time length, so that the second device feeds back the existing quantity of the statistical object when receiving the second full-scale synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame.
It should be noted that the above apparatus embodiment corresponds to the method embodiment of the present invention, and any one of the synchronization frame-based number synchronization methods described in this invention can be implemented, and the above described apparatus embodiment is only illustrative, wherein the units described as the separation component may or may not be physically separated, and the components displayed as the units may or may not be physical units, that is, may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. In addition, in the drawings of the embodiment of the apparatus provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, and may be specifically implemented as one or more communication buses or signal lines. One of ordinary skill in the art can understand and implement it without inventive effort.
While the foregoing is directed to the preferred embodiment of the present invention, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention.

Claims (9)

1. A synchronization frame-based quantity synchronization method is characterized by comprising the following steps:
acquiring a quantity updating event message of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: counting object names and change quantity;
initiating a quantity updating request to second equipment according to the quantity updating event message so that the second equipment updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity when receiving the quantity updating request; the second database is a database corresponding to the second device;
when the number of the statistical objects stored in the second database is successfully updated, updating the number of the statistical objects stored in the synchronous database according to the names of the statistical objects and the change number to obtain a first statistical number of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database and the synchronization database;
generating a synchronization frame according to the first statistical amount and the statistical object name, and sending the synchronization frame to the second device, so that the second device feeds back the current amount of the statistical objects in the second database at the current moment when receiving the synchronization frame;
and calculating a difference value between the current quantity and the first statistical quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference value when the difference value is not zero.
2. The synchronization frame-based number synchronization method of claim 1, further comprising, before acquiring the number update event message of the first device:
receiving a full-quantity synchronous application instruction sent by first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization;
initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request;
according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame;
and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
3. The sync frame based number synchronization method as claimed in claim 1, further comprising:
when the number of the statistical objects stored in the second database fails to be updated, feeding back number update failure information to the first device, so that the first device cancels the updating of the number of the statistical objects stored in the first database after receiving the number update failure information.
4. The sync frame based number synchronization method as claimed in claim 1, further comprising: if the quantity updating event message of the first equipment is not acquired within a preset time length, initiating a second full-quantity synchronization request to the second equipment so that the second equipment feeds back the existing quantity of the statistical objects when receiving the second full-quantity synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame.
5. The synchronization frame-based quantity synchronization method according to claim 1, wherein the acquiring the quantity update event message of the first device specifically includes:
acquiring the quantity updating event message from a preset message queue; and after generating the quantity updating event message, the first device stores the quantity updating event message in the preset message queue.
6. A synchronization frame based quantity synchronization apparatus, comprising: the device comprises an update event message acquisition module, a quantity update request initiating module, a local quantity update module, a synchronous frame generation module and a difference increment synchronization module;
the update event message acquisition module is used for acquiring the number update event messages of the first equipment; when the number of the statistical objects is changed, the first device updates the number of the statistical objects stored in the first database and generates the number updating event message; the first database is a database corresponding to the first equipment; the quantity update event message includes: counting object names and change quantity;
the quantity updating request initiating module is configured to initiate a quantity updating request to a second device according to the quantity updating event message, so that when the second device receives the quantity updating request, the second device updates the quantity of the statistical objects stored in a second database according to the names of the statistical objects and the change quantity; the second database is a database corresponding to the second device;
the local quantity updating module is used for updating the quantity of the statistical objects stored in the synchronous database according to the name of the statistical object and the quantity of the change when the quantity of the statistical objects stored in the second database is successfully updated, so as to obtain a first statistical quantity of the statistical objects; wherein the initial number of the statistical objects is consistent among the first database, the second database and the synchronization database;
the synchronization frame generation module is configured to generate a synchronization frame according to the first statistical amount and the statistical object name, and send the synchronization frame to the second device, so that the second device feeds back the current number of statistical objects in the second database at the current time when receiving the synchronization frame;
and the difference increment synchronization module is used for calculating the difference between the current quantity and the first statistical quantity, and synchronizing the quantity of the statistical objects in the first database according to the difference when the difference is not zero.
7. The sync frame based number synchronizer as recited in claim 6, further comprising: an initial quantity full-scale synchronization module;
the initial quantity and total quantity synchronization module is used for receiving a total quantity synchronization application instruction sent by the first equipment; the full-quantity synchronization application instruction comprises the name of a statistical object needing full-quantity synchronization;
initiating a full-quantity synchronization request to the second equipment according to a full-quantity synchronization application instruction so that the second equipment feeds back the initial quantity of the statistical objects when receiving the full-quantity synchronization request;
according to the initial number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a full-scale synchronization frame;
and sending the full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the initial number of the statistical objects after receiving the full-scale synchronization frame.
8. The sync frame based number synchronizer as recited in claim 6, further comprising: a quantity update reset module;
the quantity updating and resetting module is configured to, when the quantity updating of the statistical objects stored in the second database fails, feed back quantity updating failure information to the first device, so that the first device cancels the updating of the quantity of the statistical objects stored in the first database after receiving the quantity updating failure information.
9. The sync frame based number synchronizer as recited in claim 6, further comprising: a cold data synchronization module;
the cold data synchronization module is configured to initiate a second full-scale synchronization request to the second device if the quantity update event message of the first device is not obtained within a preset time length, so that the second device feeds back the existing quantity of the statistical object when receiving the second full-scale synchronization request;
according to the existing number of the statistical objects, carrying out full-scale synchronization on the number of the statistical objects in the synchronization database, and generating a second full-scale synchronization frame;
and sending the second full-scale synchronization frame to the first equipment so that the first equipment performs full-scale synchronization on the number of the statistical objects in the first database according to the existing number of the statistical objects after receiving the second full-scale synchronization frame.
CN202110949465.1A 2021-08-18 2021-08-18 Synchronous frame based quantity synchronization method and synchronization device Active CN113672682B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110949465.1A CN113672682B (en) 2021-08-18 2021-08-18 Synchronous frame based quantity synchronization method and synchronization device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110949465.1A CN113672682B (en) 2021-08-18 2021-08-18 Synchronous frame based quantity synchronization method and synchronization device

Publications (2)

Publication Number Publication Date
CN113672682A true CN113672682A (en) 2021-11-19
CN113672682B CN113672682B (en) 2022-04-01

Family

ID=78543639

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110949465.1A Active CN113672682B (en) 2021-08-18 2021-08-18 Synchronous frame based quantity synchronization method and synchronization device

Country Status (1)

Country Link
CN (1) CN113672682B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080290162A1 (en) * 2007-05-22 2008-11-27 Sanjeev Siotia Inventory management system and method
US20100241763A1 (en) * 2009-03-20 2010-09-23 Research In Motion Limited Synchronization between a mobile device and a computing terminal
CN103199980A (en) * 2013-04-07 2013-07-10 浙江中控技术股份有限公司 Synchronous control method, synchronous control device and synchronous control system
US20130185373A1 (en) * 2011-11-18 2013-07-18 Apple Inc. Group formation within a synchronized hierarchy of peer-to-peer devices
US20150006633A1 (en) * 2013-06-28 2015-01-01 Apple Inc. Operating a cluster of peer-to-peer devices
CN104699712A (en) * 2013-12-09 2015-06-10 阿里巴巴集团控股有限公司 Method and device for updating stock record information in database
CN108694241A (en) * 2018-05-14 2018-10-23 平安科技(深圳)有限公司 A kind of storage method and equipment of data
CN108962289A (en) * 2018-06-29 2018-12-07 北京同方光盘股份有限公司 Method and device based on the additional hiding mark data of CD synchronization frame
CN111741038A (en) * 2019-03-25 2020-10-02 华为技术有限公司 Data transmission method and data transmission device

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080290162A1 (en) * 2007-05-22 2008-11-27 Sanjeev Siotia Inventory management system and method
US20100241763A1 (en) * 2009-03-20 2010-09-23 Research In Motion Limited Synchronization between a mobile device and a computing terminal
US20130185373A1 (en) * 2011-11-18 2013-07-18 Apple Inc. Group formation within a synchronized hierarchy of peer-to-peer devices
CN103199980A (en) * 2013-04-07 2013-07-10 浙江中控技术股份有限公司 Synchronous control method, synchronous control device and synchronous control system
US20150006633A1 (en) * 2013-06-28 2015-01-01 Apple Inc. Operating a cluster of peer-to-peer devices
CN104699712A (en) * 2013-12-09 2015-06-10 阿里巴巴集团控股有限公司 Method and device for updating stock record information in database
CN108694241A (en) * 2018-05-14 2018-10-23 平安科技(深圳)有限公司 A kind of storage method and equipment of data
CN108962289A (en) * 2018-06-29 2018-12-07 北京同方光盘股份有限公司 Method and device based on the additional hiding mark data of CD synchronization frame
CN111741038A (en) * 2019-03-25 2020-10-02 华为技术有限公司 Data transmission method and data transmission device

Also Published As

Publication number Publication date
CN113672682B (en) 2022-04-01

Similar Documents

Publication Publication Date Title
US20160012389A1 (en) Method, apparatus, and system for synchronizing inventory information
CN105915308A (en) Time synchronization method, device and system
CN107871221B (en) Method and device for acquiring amount of marketable inventory
CN112347111A (en) Data updating method and device
CN113193947B (en) Method, apparatus, medium, and program product for implementing distributed global ordering
KR20150137977A (en) Electronic shelf label tag, electronic shelf label system and operation method thereof
CN112486707A (en) Redis-based message asynchronous consumption method and device
CN113672682B (en) Synchronous frame based quantity synchronization method and synchronization device
US8509751B2 (en) System and method of object simulation in an intermittently connected mobile application
CN108874531B (en) Method, device and system for fusing service and electronic equipment
CN109660310B (en) Clock synchronization method and device, computing equipment and computer storage medium
CN107578327A (en) Method, equipment and the system that information pushes in a kind of link of bidding
EP2025133A1 (en) Repository synchronization in a ranked repository cluster
CN111626802A (en) Method and apparatus for processing information
CN111582996B (en) Service information display method and device
CN114328739A (en) Data synchronization method, data reading method, data synchronization device, data reading device, electronic equipment, storage medium and product
CN110750424B (en) Resource inspection method and device
CN113159680A (en) Inventory pre-occupation method, device, electronic equipment and computer readable medium
CN112905335A (en) Switching method for calling multiple sets of system same services and business processing system
CN114841651A (en) Schedule reminding method and device, electronic equipment and storage medium
WO2020195612A1 (en) Information processing device, information processing method, recording medium, and flagship store terminal
CN219107454U (en) Timing system
CN107979643B (en) Data interaction method and device and readable storage medium
US11277473B1 (en) Coordinating breaking changes in automatic data exchange
CN117290441A (en) Data synchronization method and device

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