Message push method, data acquisition method, device, system, equipment and medium
By detecting whether the target data has been synchronized to the slave database at the data publishing end and pushing an update notification message to the client, ensuring that the client obtains the latest target data from the slave database, the problem of inaccurate data in the existing technology is solved, and the data is realized Accurate and effective data acquisition.
Patent Information
- Application Number
- CN202010628346.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-01
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2040-07-01
AI Technical Summary
In the prior art, the message push method does not consider the impact of the read and write separation technology adopted by the data publishing end on the correctness and effectiveness of the data obtained by the mobile shopping terminal, resulting in the problem of inaccuracy of data.
By detecting whether the target data has been synchronized to the slave database, if it is determined that the data has been synchronized, an update notification message is pushed to the client, so that the client can obtain the target data from the slave database based on the message. After writing data to the master database, this method synchronizes to the slave database through the master-slave synchronization mechanism to ensure the accuracy of the data.
This method not only reduces the amount of push data, but also ensures that the target data finally obtained by the client is correct and effective, solving the problem of inaccurate data.
Smart Images

Figure CN113761051B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a message pushing method, a data acquisition method, a device, a system, an electronic device, and a storage medium. Background Art
[0002] With the vigorous development and widespread popularity of mobile Internet e-commerce, more and more people are getting used to online shopping. Therefore, more and more merchants are attracting more customers by personalizing their online stores. In order to pursue the ultimate user shopping experience and reduce the workload and time of merchants' decoration, e-commerce platforms provide merchants with a set of software specifically used for online store decoration. Merchants use this software to decorate their online stores. When the decoration is completed, the decoration data is published through the software, and then the decoration data is pushed to each mobile shopping terminal, so that each mobile shopping terminal can achieve the purpose of displaying the decoration effect.
[0003] In order to share the pressure on the server and improve data reliability, the data publishing end usually adopts read-write separation technology, that is, setting up two databases, namely the master database and the slave database. The master database is responsible for processing transactional add, modify, and delete operations, and the slave database is responsible for processing query operations. Database replication is used to synchronize data changes caused by transactional operations to the slave database. At present, when the merchant publishes the decoration data to the master database, the server will immediately push a message to each mobile shopping terminal, and each mobile shopping terminal will obtain all the decoration data from the slave database based on the received message.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] The existing message push method does not consider the impact of the read-write separation technology adopted by the data publishing end on the correctness and effectiveness of the data finally obtained by the mobile shopping terminal, and there is a problem that the data finally obtained by each mobile shopping terminal is inaccurate. Summary of the invention
[0006] The embodiments of the present invention provide a message push method, a data acquisition method, a device, a system, an electronic device and a storage medium, which not only reduce the amount of pushed data, but also ensure that the target data ultimately acquired by the client is correct and valid.
[0007] In a first aspect, an embodiment of the present invention provides a message push method, including:
[0008] Check whether the target data has been synchronized to the slave database;
[0009] If it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message;
[0010] After the target data is written into the master database, the target data is synchronized to the slave database through a master-slave synchronization mechanism.
[0011] In a second aspect, an embodiment of the present invention further provides a data acquisition method, comprising:
[0012] Receive update notification messages sent by the server;
[0013] After a preset delay time, triggering an operation of acquiring target data from a database according to the update notification message;
[0014] After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0015] In a third aspect, an embodiment of the present invention further provides a message push device, including:
[0016] A detection module is used to detect whether the target data has been synchronized to the slave database;
[0017] A push module, configured to push an update notification message to the client if it is determined that the target data has been synchronized to the slave database, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message;
[0018] After the target data is written into the master database, the target data is synchronized to the slave database through a master-slave synchronization mechanism.
[0019] In a fourth aspect, an embodiment of the present invention further provides a data acquisition device, including:
[0020] A receiving module, used to receive update notification messages sent by the server;
[0021] An acquisition module, used to trigger an operation of acquiring target data from a database according to the update notification message after a preset delay;
[0022] After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0023] In a fifth aspect, an embodiment of the present invention further provides a device, the device comprising:
[0024] one or more processors;
[0025] A memory for storing one or more programs;
[0026] When the one or more programs are executed by the one or more processors, the one or more processors implement the message pushing method steps and data acquisition method steps provided in any embodiment of the present invention.
[0027] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the message pushing method steps and data acquisition method steps provided in any embodiment of the present invention.
[0028] The embodiments of the above invention have the following advantages or beneficial effects:
[0029] By detecting whether the target data has been synchronized to the slave database; if it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers the operation of obtaining the target data from the slave database based on the update notification message; wherein, after the target data is written to the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism, which not only reduces the amount of pushed data, but also ensures that the target data finally obtained by the client is correct and valid. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is a flow chart of a message push method provided by Embodiment 1 of the present invention;
[0031] Figure 2 is a flow chart of a data acquisition method provided by Embodiment 2 of the present invention;
[0032] Figure 3 It is a structural diagram of a message push device provided by Embodiment 3 of the present invention;
[0033] Figure 4 is a structural schematic diagram of a data acquisition device provided by Embodiment 4 of the present invention;
[0034] Figure 5 It is a structural diagram of a message push system provided by Embodiment 5 of the present invention;
[0035] Figure 6 It is a structural schematic diagram of a device provided in Example 6 of the present invention. DETAILED DESCRIPTION
[0036] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0037] Embodiment 1
[0038] Figure 1 This is a flow chart of a message push method provided in Embodiment 1 of the present invention. This embodiment can be applied to the application scenario where the server pushes the decoration data for online stores published by merchants to the mobile shopping terminal. The method can be executed by a message push device, which can be implemented by software and / or hardware and integrated into the server.
[0039] like Figure 1 As shown, the method specifically comprises the following steps:
[0040] Step 110: Check whether the target data has been synchronized to the slave database.
[0041] Exemplarily, the detecting whether the target data has been synchronized to the slave database includes:
[0042] Detect whether the target data has been written into the slave database binary log binlog during the two-phase commit protocol 2PC process of the master-slave synchronization mechanism;
[0043] If the target data has been written into the binary log, it is determined that the target data has been synchronized to the slave database. In the master-slave synchronization mechanism, each time a binary log write operation is performed, an operation of writing the binary log to disk is performed. In this mode, if the target data has been written into the slave database binary log, it means that the target data has been synchronized to the slave database, and other transactions can read the target data. Taking MySQL's innodb database as an example, the isolation level is RR, and the configuration parameters of the database are: binlog_format=row, innodb_flush_log_at_trx_commit=1, sync_binlog=1, which means that each time a binary log write operation is performed, an operation of writing the binary log to disk is performed. The two parameters innodb_flush_log_at_trx_commit and sync_binlog are key parameters for controlling MySQL disk write strategy and data security. If innodb_flush_log_at_trx_commit is set to 1, MySQL will write the data of the buffered log buffer into the binary log and flush it to the disk each time a transaction is committed. The parameter sync_binlog = [N] means that the binary log is synchronized to the disk every time the buffer is written. If N is set to 1, that is, sync_binlog = 1, it means that the binary log is written in a synchronous way. In this case, the binary log write operation does not use the operating system buffer to write. The default value is 0, that is, the operating system mechanism is used to write the binary log (i.e., buffer data synchronization).
[0044] Step 120: If it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers the operation of obtaining the target data from the slave database based on the update notification message. After the target data is written to the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. It takes a certain amount of time for the target data to be synchronized to the slave database. In order to ensure that the client can obtain the latest target data from the slave database, in the technical solution of this embodiment, when it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, informing the client that the latest target data can be obtained from the slave database.
[0045] Furthermore, after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the process further includes:
[0046] Collect binary logs from the database;
[0047] Parsing the binary log to obtain update records of target data;
[0048] The update record is stored so that the client obtains the update record based on the update notification message, and obtains the target data from the secondary database according to the update record.
[0049] Taking the target data as decoration data for online stores released by merchants as an example, the update record specifically refers to the merchant ID, page ID, etc. that released the decoration data.
[0050] Specifically, the collection of binary logs from the database includes:
[0051] A log acquisition request dump is sent to the database instance through the interactive protocol of the slave database. When the database instance receives the log acquisition request, the binary log is collected.
[0052] The technical solution of this embodiment is to detect whether the target data has been synchronized to the slave database; if it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers the operation of obtaining the target data from the slave database based on the update notification message; wherein, after the target data is written to the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism, instead of immediately pushing the update notification message to the client when the target data is written to the master database, thereby achieving the purpose of ensuring that the target data finally obtained by the client is correct and valid, while also reducing the amount of data pushed to the client.
[0053] Embodiment 2
[0054] Figure 2 This is a flow chart of a data acquisition method provided in Embodiment 2 of the present invention. Based on the above embodiments, this embodiment is applied to a client receiving an update notification message sent by a server, and the client acquires target data based on the update notification message. The method can be executed by a data acquisition device, which can be implemented by software and / or hardware and integrated into the client. The explanations of the terms that are the same or corresponding to the above embodiments are not repeated here.
[0055] See also Figure 2 The data acquisition method provided in this embodiment specifically includes the following steps:
[0056] Step 210: Receive an update notification message sent by the server.
[0057] Step 220: after a preset delay, trigger an operation of obtaining target data from a slave database according to the update notification message; wherein, after the target data is written into the master database, the target data is synchronized to the slave database through a master-slave synchronization mechanism, and when it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0058] Specifically, the operation of triggering the acquisition of target data from the database according to the update notification message includes:
[0059] Acquire the update record according to the update notification message;
[0060] Acquire the target data from the slave database through a remote procedure call protocol RPC according to the update record;
[0061] Among them, after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the server collects the binary log of the slave database, parses the binary log to obtain the update record of the target data, and stores the update record. Taking the target data as the decoration data for the online store published by the merchant as an example, the update record specifically refers to the merchant ID, page ID, etc. that publishes the decoration data. The client obtains the specific decoration data from the slave database through RPC calls based on the merchant ID and page ID. The two-phase commit protocol 2PC process of the master-slave synchronization mechanism of the database includes two stages, the preparation stage and the submission stage; the preparation stage is the stage of writing data to the master database. The commit phase includes two steps. The first step is the synchronization operation of the binary log binlog of the database. When this step is completed, it means that the binary log has been written with data and can be sent to the consumer end for consumption, that is, the data acquisition end can read the data; the second step is the commit operation. Only after the commit operation is completed, other transactions can query the data changes generated by the transaction corresponding to the binary log binlog. Therefore, in order to ensure that each consumer end (i.e., the client) can accurately obtain the latest target data, in the data acquisition scheme provided in this embodiment, when the client receives the update notification message, it delays the preset time to obtain the update record according to the update notification message; according to the update record, the target data is obtained from the slave database through the remote procedure call protocol RPC. Exemplarily, the preset time can be 500ms. The second step of the second phase of the two-stage commit protocol 2PC process of the master-slave synchronization mechanism of the database generally takes a relatively short time to commit, and the client delays the consumption preset time, plus the update notification message from pushing to reading the update record, and then to the RPC call requires a certain amount of time overhead, so that the master and slave of the database can be guaranteed to have been synchronized, so that the client can obtain the latest accurate target data, avoiding the risk of heterogeneous distributed systems reading dirty data.
[0062] Furthermore, when receiving the update notification message sent by the server, the method further includes:
[0063] Clear the data in the cache to free up storage space for the target data, prepare for obtaining the target data, and provide guarantees for accurate and stable acquisition of the target data. Even if the message consumer uses caching technology, the correct push of messages can be guaranteed.
[0064] The technical solution of this embodiment, after receiving the update notification message sent by the server, delays for a preset time and then triggers the operation of obtaining the target data from the slave database according to the update notification message; takes into account the delay caused by the submission operation in the submission phase of the two-phase submission protocol 2PC process of the master-slave synchronization mechanism of the database, and the delay caused by the database performing data recovery when the submission operation fails, thereby achieving the purpose of ensuring that the client obtains the correct, valid and latest target data.
[0065] The following is an embodiment of a message push device provided in an embodiment of the present invention. The device and the message push methods of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the message push device, reference can be made to the embodiment of the above message push method.
[0066] Embodiment 3
[0067] Figure 3 This is a schematic diagram of the structure of a message pushing device provided in Embodiment 3 of the present invention. The device specifically includes: a detection module 310 and a pushing module 320.
[0068] Among them, the detection module 310 is used to detect whether the target data has been synchronized to the slave database; the push module 320 is used to push an update notification message to the client if it is determined that the target data has been synchronized to the slave database, so that the client triggers the operation of obtaining the target data from the slave database based on the update notification message; wherein, after the target data is written to the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism.
[0069] Furthermore, the detection module 310 is specifically used to: detect whether the target data has been written into the binary log of the slave database during the two-phase commit protocol 2PC process of the master-slave synchronization mechanism; if the target data has been written into the binary log, determine that the target data has been synchronized to the slave database.
[0070] Furthermore, in the master-slave synchronization mechanism, each time a binary log write operation is performed, an operation of writing the binary log to the disk is performed.
[0071] Furthermore, the device also includes: a collection module, an analysis module and a storage module;
[0072] The acquisition module is used to collect the binary log of the slave database after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client;
[0073] The parsing module is used to parse the binary log to obtain update records of target data;
[0074] The storage module is used to store the update record, so that the client obtains the update record based on the update notification message, and obtains the target data from the secondary database according to the update record.
[0075] Furthermore, the target data includes decoration data of the online store.
[0076] The technical solution of this embodiment is to detect whether the target data has been synchronized to the slave database; if it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers the operation of obtaining the target data from the slave database based on the update notification message; wherein, after the target data is written to the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism, instead of immediately pushing the update notification message to the client when the target data is written to the master database, thereby achieving the purpose of ensuring that the target data finally obtained by the client is correct and valid, while also reducing the amount of data pushed to the client.
[0077] The message pushing device provided in the embodiment of the present invention can execute the message pushing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the message pushing method.
[0078] Embodiment 4
[0079] Figure 4 This is a structural diagram of a data acquisition device provided in Embodiment 4 of the present invention. The device specifically includes: a receiving module 410 and an acquisition module 420.
[0080] Among them, the receiving module 410 is used to receive the update notification message sent by the server; the obtaining module 420 is used to trigger the operation of obtaining the target data from the slave database according to the update notification message after a preset delay; after the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism, and when it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0081] Further, the acquisition module 420 includes: an acquisition unit, configured to acquire an update record according to the update notification message;
[0082] A calling unit is used to obtain the target data from the slave database through a remote procedure call protocol RPC according to the update record; wherein, after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the server collects the binary log of the slave database, parses the binary log to obtain the update record of the target data, and stores the update record.
[0083] Furthermore, the device also includes: a clearing module, used to clear the data in the cache.
[0084] Furthermore, the target data includes decoration data of the online store.
[0085] The technical solution of this embodiment, after receiving the update notification message sent by the server, delays for a preset time and then triggers the operation of obtaining the target data from the slave database according to the update notification message; takes into account the delay caused by the submission operation in the submission phase of the two-phase submission protocol 2PC process of the master-slave synchronization mechanism of the database, and the delay caused by the database performing data recovery when the submission operation fails, thereby achieving the purpose of ensuring that the client obtains the correct, valid and latest target data.
[0086] The data acquisition device provided in the embodiment of the present invention can execute the data acquisition method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the message pushing method.
[0087] Embodiment 5
[0088] Figure 5 This is a structural diagram of a message push system provided in Embodiment 5 of the present invention. The message push system provided in this embodiment can be applicable to an application scenario in which a server pushes decoration data for an online store published by a merchant to a mobile shopping terminal.
[0089] like Figure 5 As shown, the system includes: a first business application module 510 , an event execution module 520 , a database module 530 , a log subscription module 540 , a message distribution module 550 and a second business application module 560 .
[0090] The first business application module 510 is used to receive the user's operation instruction, and based on the operation instruction, send a target data write request to the event execution module 520. For example, merchants decorate their online stores in a personalized way to attract more customers. In order to reduce the workload and time of merchants' decoration, the e-commerce platform provides merchants with a set of software specifically used for online store decoration. Each merchant decorates his own online store through the software. When the decoration is completed, the decoration data is published through the software. The software specifically used for online store decoration is a specific form of the first business application module 510.
[0091] The event execution module 520 executes relevant business codes to write the target data into the main database master of the database module according to the target data write request.
[0092] The database module 530 includes a master database master 531 and a slave database slave 532. The master database 531 is used to store the data written by the event execution module 520 and synchronize the written data to the slave database 532. The slave database 532 is used to synchronize and store the data of the master database 531 for reading by the second business application module 560. After the target data is written into the master database 531, the operation of synchronizing the target data from the master database 531 to the slave database 532 is started through the master-slave synchronization mechanism.
[0093] The log subscription module 540 is used to subscribe to the binary log of the slave database 532 when the target data has been synchronized to the slave database 532 , and send the subscribed binary log to the message distribution module 550 .
[0094] The message distribution module 550 is used to push an update notification message to the second business application module 560 when receiving the binary log.
[0095] The second service application module 560 triggers an operation of acquiring the target data from the secondary database 532 based on the update notification message.
[0096] Furthermore, if the pressure to write to the main database 531 is high at the same time, the event can be written into the task queue to reduce the peak of the task pressure and avoid the exhaustion of resources (such as CPU, memory, etc.). At the same time, in order to reduce the message subscription volume of the log subscription module 540, a representative operation is generally set in the event execution module 520 to indicate that the event execution is complete. Taking the release of the store decoration page as an example, when the decoration page data is released, after the release is successful, the released operation will be recorded in the release history table, and the relevant operations recorded in the release history table will be used as representative operation events. The log subscription module 540 only needs to subscribe to the relevant binary logs of the release history table.
[0097] Exemplarily, the event execution module 520 includes: a task queue unit, which is used to store the write requests that exceed the threshold based on the order of the sending time of each write request when the number of write requests sent to the event execution module exceeds the threshold, so as to reduce the execution pressure of the event execution module.
[0098] The event execution module 520 is also used to: when the target data is written into the master database 531 of the database module 530, the write operation of the target data is recorded in the update history table corresponding to the target data. Correspondingly, the log subscription module 540 is used to subscribe to the binary log corresponding to the update history table in the slave database 532. Specifically, the log subscription module 540 sends a binary log acquisition request dump to the database management instance based on the set interaction protocol (for example, the interaction protocol of MySQL slave), receives the binary log collected by the database management instance according to the request, and sends the received binary log to the message distribution module 550.
[0099] The message distribution module 550 is also used to parse the received binary log, obtain update records, and store the update records before pushing the update notification message to the second business application module 560, so that the second business application module 560 obtains the update records based on the update notification message, and obtains the target data from the slave database according to the update records. Specifically, when the second business application module 560 receives the update notification message, it performs the operation of obtaining the update record after a preset time (for example, a delay of 500ms); and obtains the target data from the slave database through the remote procedure call protocol RPC according to the obtained update record. Taking the example that the target data is the decoration data for the online store published by the merchant, the update record specifically refers to the merchant ID, page ID, etc. that publishes the decoration data. The second business application module 560 obtains specific decoration data from the slave database through RPC calls based on the merchant ID and page ID. Among them, one implementation form of the message distribution module 550 can be Kafka. Kafka is a high-throughput distributed publish-subscribe message system. The message distribution module 550 includes a message distribution unit 551 and a message queue 552. The message distribution unit 551 parses the received binary log, obtains the update record, and sends the update record to the message queue 552. After receiving the update record, the message queue 552 sends an update notification message to the second business application module 560 to inform the second business application module 560 that it can consume data. After receiving the update notification message, the second business application module 560 delays for a preset time and then consumes the message in the message queue 552, that is, the update record.
[0100] The reason why the second business application module 560 starts to execute the operation of obtaining the update record after a preset time (e.g., a delay of 500ms) when receiving the update notification message is that the two-phase commit protocol 2PC process of the master-slave synchronization mechanism of the database includes two stages, the preparation stage and the commit stage; the preparation stage is the stage of writing data to the master database. The commit stage includes two steps, the first step is the synchronization operation of the binary log binlog of the slave database. When this step is completed, it means that the binary log has been written to the data and can be sent to the consumer end for consumption, that is, the data acquisition end can read the data; the second step is the commit operation. Only after the commit operation is completed, other transactions can query the data changes generated by the transaction corresponding to the binary log binlog. Therefore, in order to ensure that the second business application module 560 can accurately obtain the latest target data, the second business application module 560 obtains the update record according to the update notification message after a preset time when receiving the update notification message, and obtains the target data from the slave database through the remote procedure call protocol RPC according to the update record, so as to ensure that the second business application module 560 obtains the correct and effective target data.
[0101] Furthermore, the system also includes: a third business application module 570, which is used to receive a call instruction of the remote procedure call protocol RPC sent by the second business application module 560, and obtain the target data from the database 532 through RPC based on the call instruction.
[0102] The message push system provided in this embodiment reduces the bandwidth usage of the message body and ensures the correct push of the message by constructing data synchronization and message push in read-write separation into a message push solution of serial events. Even if the read-write separation technology is used at the message generating end, or the cache technology is used at the message consuming end, the correct delivery of the message can be guaranteed, and each message consuming end can finally obtain the correct data, avoiding the risk of heterogeneous distributed systems reading dirty data.
[0103] Embodiment 6
[0104] Figure 6 A schematic diagram of the structure of a device provided in Example 6 of the present invention. Figure 6 A block diagram of an exemplary device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 6 The device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0105] like Figure 6As shown, device 12 is in the form of a general purpose computing device. Components of device 12 may include, but are not limited to, one or more processors or processing units 16, system memory 28, and bus 18 that connects various system components (including system memory 28 and processing unit 16).
[0106] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0107] Device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by device 12, including volatile and non-volatile media, removable and non-removable media.
[0108] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, usually called a "hard drive"). Although Figure 6 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set of program modules (e.g., at least one detection module 310 and a push module 320) that are configured to perform the functions of the various embodiments of the present invention.
[0109] A program / utility 40 having a set of program modules 42 (at least one detection module 310 and a push module 320) may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0110] The device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), may communicate with one or more devices that enable a user to interact with the device 12, and / or may communicate with any device that enables the device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via an input / output (I / O) interface 22. Furthermore, the device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with other modules of the device 12 via a bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the device 12, including, but not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0111] The processing unit 16 executes various functional applications and message push by running the program stored in the system memory 28, for example, implementing a message push method provided by an embodiment of the present invention, the method comprising:
[0112] Check whether the target data has been synchronized to the slave database;
[0113] If it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message;
[0114] After the target data is written into the master database, the target data is synchronized to the slave database through a master-slave synchronization mechanism.
[0115] A data acquisition method provided by an embodiment of the present invention is also implemented, the method comprising:
[0116] Receive update notification messages sent by the server;
[0117] After a preset delay time, triggering an operation of acquiring target data from a database according to the update notification message;
[0118] After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0119] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the message pushing method provided by any embodiment of the present invention.
[0120] Embodiment 7
[0121] This embodiment 7 provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the message push method steps and data acquisition method steps provided in any embodiment of the present invention are implemented. The message push method includes:
[0122] Check whether the target data has been synchronized to the slave database;
[0123] If it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message;
[0124] After the target data is written into the master database, the target data is synchronized to the slave database through a master-slave synchronization mechanism.
[0125] The data acquisition method comprises:
[0126] Receive update notification messages sent by the server;
[0127] After a preset delay time, triggering an operation of acquiring target data from a database according to the update notification message;
[0128] After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client.
[0129] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0130] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0131] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0132] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0133] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0134] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A message push method, characterized in that: include: Check whether the target data has been synchronized to the slave database; If it is determined that the target data has been synchronized to the slave database, an update notification message is pushed to the client, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message; After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism; After determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the method further includes: Collect binary logs from the database; Parsing the binary log to obtain update records of target data; The update record is stored so that the client obtains the update record based on the update notification message, and obtains the target data from the secondary database according to the update record.
2. The method according to claim 1, characterized in that: The step of detecting whether the target data has been synchronized to the slave database includes: Detect whether the target data has been written into the slave database binary log during the two-phase commit protocol 2PC process of the master-slave synchronization mechanism; If the target data has been written into the binary log, it is determined that the target data has been synchronized to the slave database.
3. A data acquisition method, characterized in that: include: Receive update notification messages sent by the server; After a preset delay time, triggering an operation of acquiring target data from a database according to the update notification message; After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client. The operation of triggering the acquisition of target data from the database according to the update notification message includes: Acquire the update record according to the update notification message; Acquire the target data from the slave database through a remote procedure call protocol RPC according to the update record; Among them, after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the server collects the binary log of the slave database, parses the binary log to obtain the update record of the target data, and stores the update record.
4. A message push device, characterized in that: include: A detection module is used to detect whether the target data has been synchronized to the slave database; A push module, configured to push an update notification message to the client if it is determined that the target data has been synchronized to the slave database, so that the client triggers an operation of obtaining the target data from the slave database based on the update notification message; After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism; The device also includes: a collection module, an analysis module and a storage module; The acquisition module is used to collect the binary log of the slave database after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client; The parsing module is used to parse the binary log to obtain update records of target data; The storage module is used to store the update record, so that the client obtains the update record based on the update notification message, and obtains the target data from the secondary database according to the update record.
5. A data acquisition device, characterized in that: include: A receiving module, used to receive update notification messages sent by the server; An acquisition module, used to trigger an operation of acquiring target data from a database according to the update notification message after a preset delay; After the target data is written into the master database, the target data is synchronized to the slave database through the master-slave synchronization mechanism. When it is determined that the target data has been synchronized to the slave database, the server pushes the update notification message to the client. The acquisition module comprises: An acquiring unit, configured to acquire an update record according to the update notification message; A calling unit, configured to obtain the target data from the slave database through a remote procedure call protocol RPC according to the update record; Among them, after determining that the target data has been synchronized to the slave database and before pushing the update notification message to the client, the server collects the binary log of the slave database, parses the binary log to obtain the update record of the target data, and stores the update record.
6. A message push system, characterized in that: include: A first business application module, an event execution module, a database module, a log subscription module, a message distribution module, and a second business application module; The first business application module is used to receive an operation instruction from a user, and send a target data write request to the event execution module based on the operation instruction; The event execution module is used to write the target data into the main database of the database module according to the target data write request; The database module includes a master database and a slave database, wherein the master database is used to store the data written by the event execution module and synchronize the written data to the slave database; the slave database is used to synchronize and store the data of the master database for reading by the second business application module; The log subscription module is used to subscribe to the binary log of the slave database when the target data has been synchronized to the slave database, and send the subscribed binary log to the message distribution module; The message distribution module is used to push an update notification message to the second business application module when receiving the binary log; The second business application module triggers an operation of acquiring the target data from the secondary database based on the update notification message; The event execution module is also used for: when the writing of the target data into the main database of the database module is completed, recording the writing operation of the target data in the update history table corresponding to the target data.
7. The system according to claim 6, characterized in that The event execution module includes: a task queue unit, which is used to store the write requests exceeding the threshold based on the order of the sending time of each write request when the number of write requests sent to the event execution module exceeds the threshold, so as to reduce the execution pressure of the event execution module.
8. The system according to claim 6, characterized in that The log subscription module is used to subscribe to the binary log corresponding to the update history table in the slave database.
9. The system according to claim 6, characterized in that The message distribution module is also used to parse the received binary log, obtain update records, and store the update records before pushing the update notification message to the second business application module, so that the second business application module obtains the update records based on the update notification message and obtains the target data from the database according to the update records.
10. The system according to claim 9, characterized in that When the second service application module receives the update notification message, it executes the operation of obtaining the update record after a preset delay; The target data is obtained from the slave database through a remote procedure call protocol RPC according to the obtained update record.
11. The system according to any one of claims 6 to 10, characterized in that: It also includes: a third business application module, which is used to receive a call instruction of the remote procedure call protocol RPC sent by the second business application module, and obtain the target data from the secondary database through RPC based on the call instruction.
12. An electronic device, characterized in that: The electronic device comprises: 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 implement the message pushing method steps as described in any one of claims 1-2 and the data acquisition method steps as described in claim 3.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the message pushing method steps as described in any one of claims 1-2 and the data acquisition method steps as described in claim 3 are implemented.
Citation Information
Patent Citations
Database synchronization method and apparatus
CN105069059A
Master-slave database read-write method and system, storage device and server
CN108038157A