Data reading method, data updating method and database system
By introducing caching and update log mechanisms into the slave database, the problem of data inconsistency in the MySQL master-slave architecture is solved, the accuracy of data query and the stability of the system are improved, and the consistency of the data is ensured.
Patent Information
- Application Number
- CN202410778507.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-08-30
AI Technical Summary
In a distributed database system, the MySQL master-slave architecture may cause data inconsistency in the master-slave database, affecting the accuracy of data queries. Especially when the data in the slave database has not been updated, read requests may return inconsistent data.
By introducing caching and update log mechanisms into the slave database, when the data to be read is in the cache, the read request is routed to the master database to ensure that the data is synchronized before returning. The slave database updates the data according to the preset expiration time to avoid the master database. The data from the database is inconsistent.
It improves the accuracy of data query, avoids query anomalies caused by inconsistencies in master-slave database data, and ensures data consistency and system stability.
Smart Images

Figure CN118568097A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a data reading method, a data updating method and a database system. Background Art
[0002] At present, distributed systems have been widely used. In order to improve data reading and writing efficiency, MYSQL master-slave architecture is usually used in distributed systems to update and read data. MYSQL master-slave architecture usually consists of a master database and multiple slave databases, which synchronize data from the master database to ensure data consistency between the master and slave databases.
[0003] In the related art, after receiving a request from a client to submit a transaction, the MySQL master database will first write to the binlog, then submit the transaction, update the data in the storage engine, and after the data update is completed, return a successful response to the client, and the slave database will perform asynchronous data updates based on the binlog. However, if the data update is requested during this process, the data in the slave database may not be updated completely or the data in the master database may not be updated completely, resulting in inconsistencies in the data in the master and slave databases, affecting the accuracy of data queries. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a data reading method, a data updating method and a database system to improve the accuracy of data query.
[0005] According to one aspect of the present invention, a data reading method is provided, which is applied to a slave database, wherein the slave database is used to update data in the slave database based on target data in an update log, wherein the target data in the update log is data stored in the update log after the master database updates the target data to be updated according to a received data update request; and the master database simultaneously stores the updated target data in a cache;
[0006] The method comprises:
[0007] Obtaining a data read request, wherein the data read request includes data to be read;
[0008] In the case that the data to be read is in the cache, the data read request is sent to the main database, so that the main database reads the data to be read and returns the data to be read to the sender of the data read request.
[0009] In a possible embodiment, when the data to be read is stored in the slave database, the data to be read is read from the slave database, and the data to be read is returned to the sender of the data read request.
[0010] In a possible embodiment, the slave database is used to update the data in the slave database based on the target data in the update log according to a preset expiration time.
[0011] According to another aspect of the present invention, there is provided a data updating method, which is applied to a master database, and the method comprises:
[0012] Obtaining a data update request, wherein the data update request includes target data to be updated and an update type;
[0013] Based on the data update request, updating the target data;
[0014] The updated target data is stored in a cache, and the updated target data is written into an update log, so that the target data is updated from the database based on the update log.
[0015] In a possible embodiment, the method further includes:
[0016] Performing expiration processing on the updated target data stored in the cache based on a preset expiration time;
[0017] The step of writing the updated target data into an update log so that the slave database updates the target data based on the update log includes:
[0018] The updated target data is written into an update log, so that the slave database updates the target data based on the update log according to the preset expiration time.
[0019] In a possible embodiment, writing the updated target data into the update log includes:
[0020] The data identifier and data value of the updated target data are correspondingly written into the update log.
[0021] According to another aspect of the present invention, a data reading device is provided, which is applied to a slave database, wherein the slave database is used to update data in the slave database based on target data in an update log, wherein the target data in the update log is data stored in the update log after the master database updates the target data to be updated according to a received data update request; the master database simultaneously stores the updated target data in a cache; the device comprises:
[0022] A first acquisition module, used to acquire a data read request, wherein the data read request includes data to be read;
[0023] The sending module is used to send the data reading request to the main database when the data to be read is in the cache, so that the main database reads the data to be read, and returns the data to be read to the sender of the data reading request.
[0024] According to another aspect of the present invention, there is provided a data updating device, which is applied to a main database, and the device comprises:
[0025] A second acquisition module, used to acquire a data update request, wherein the data update request includes target data to be updated and an update type;
[0026] An updating module, used for updating the target data based on the data update request;
[0027] The storage module is used to store the updated target data into a cache and write the updated target data into an update log, so that the target data is updated from the database based on the update log.
[0028] According to another aspect of the present invention, there is provided a database system, the system comprising a master database and a slave database;
[0029] The master database is used to obtain a data update request, wherein the data update request includes target data to be updated and an update type; based on the data update request, the target data is updated; the updated target data is stored in a cache, and the updated target data is written into an update log;
[0030] The slave database is used to update the target data based on the update log.
[0031] In a possible embodiment, the slave database is used to obtain a data read request, wherein the data read request includes the data to be read; and when the data to be read is in the cache, the data read request is sent to the master database;
[0032] The main database is used to read the data to be read based on the data reading request, and return the data to be read to the sender of the data reading request.
[0033] According to another aspect of the present invention, there is provided an electronic device, comprising:
[0034] Processor; and
[0035] Memory for storing programs,
[0036] The program includes instructions, and when the instructions are executed by the processor, the processor executes any of the above-mentioned data reading methods or data updating methods.
[0037] According to another aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute any of the above-mentioned data reading methods or data updating methods.
[0038] One or more technical solutions provided in the embodiments of the present invention receive a data read request from a database, and when the data to be read is in the cache, route the data read request to the master database, and the master database reads the corresponding data based on the data read request. The data in the cache is data that has changed and may not have been synchronized to the slave database. By routing the read request for the cached data to the master database for processing, data query anomalies that may be caused by inconsistency between the master and slave databases are avoided, thereby improving data query accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Further details, features and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0040] Figure 1 A schematic diagram of a flow chart of a data reading method provided by an embodiment of the present invention;
[0041] Figure 2 An interactive schematic diagram of a data reading method provided by an embodiment of the present invention;
[0042] Figure 3 An interactive schematic diagram of a data updating method provided by an embodiment of the present invention;
[0043] Figure 4 A schematic diagram of a flow chart of a data updating method provided by an embodiment of the present invention;
[0044] Figure 5 A schematic diagram of the structure of a data reading device provided by an embodiment of the present invention;
[0045] Figure 6 A schematic diagram of the structure of a data updating device provided by an embodiment of the present invention;
[0046] Figure 7 A schematic diagram of the structure of a database system provided by an embodiment of the present invention;
[0047] Figure 8 A block diagram of an exemplary electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0048] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.
[0049] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0050] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0051] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0052] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.
[0053] In order to improve the accuracy of data query, the embodiments of the present invention provide a data reading method, a data updating method, a device, an electronic device, a storage medium and a database system. The data reading method provided by the embodiments of the present invention can be applied to any electronic device with a data reading function, and the electronic device can be a server, a computer or a mobile terminal, etc. The scheme of the present invention is described below with reference to the accompanying drawings:
[0054] Figure 1A flow chart of a data reading method provided by an embodiment of the present invention, the method can be applied to a slave database, the slave database is used to update the data in the slave database based on the target data in the update log, the target data in the update log is: the master database updates the target data to be updated according to the received data update request and stores the data in the update log; the master database stores the updated target data in the cache at the same time. The method may include:
[0055] S101, obtaining a data reading request, wherein the data reading request includes data to be read;
[0056] S102: When the data to be read is in the cache, send the data read request to the primary database, so that the primary database reads the data to be read, and returns the data to be read to the sender of the data read request.
[0057] By applying the embodiment of the present invention, a data read request is received from a database, and when the data to be read is in the cache, the data read request is routed to the master database, and the master database reads the corresponding data based on the data read request. The data in the cache is data that has changed and may not have been synchronized to the slave database. By routing the read request for the cached data to the master database for processing, data query anomalies that may be caused by inconsistency between the master and slave databases are avoided, thereby improving data query accuracy.
[0058] In the embodiment of the present invention, the master database is a master database in the MYSQL master-slave architecture, and the slave database can be any slave database in the MYSQL master-slave architecture. The slave database can perform asynchronous synchronization on the data in the master database.
[0059] In a possible embodiment, after receiving a data update request, the primary database may update the target data included in the data update request according to the update type included in the data update request, and store the updated target data in the cache while writing the updated target data into the update log.
[0060] The above data update request can be obtained through a unified API, or different APIs can be set in advance for different types of requests, and fixed types of requests can be received through the corresponding API, and the request type can include update, query (i.e., read) request, etc. Accordingly, the above data update request can be received by updating the corresponding API.
[0061] The data update request may include the target data to be updated and the update type, where the update type may include modification, addition, etc. The target data may be present in the data update request in the form of a keyword and a data value, where the keyword refers to the target data identifier, such as a data ID, such as account_id, user_id, or data name, etc. The data value may include the updated data value, or the data value before the update and the data value after the update, which may be determined according to the actual application scenario.
[0062] After receiving the data update request, the master database can update the target data to be updated according to the data update request. As a possible implementation method, a transaction can be started after receiving the data update request. A transaction is an operation sequence unit executed in a database management system, and is composed of one or more SQL statements. The operations corresponding to these SQL statements are executed together as a whole. In an embodiment of the present invention, the correspondence between the update type and the operation sequence can be preset. After receiving the data update request, the corresponding transaction can be started based on the update type and the target data included in the data update request, and the transaction can be committed after the update is completed. Committing the transaction means that all operations in the transaction have been successfully completed, and all changes made to the database will be permanently saved. Once the transaction is committed, these changes are visible to other users and transactions.
[0063] When the transaction is submitted, the information of the data update request can be recorded in the update log. As a possible implementation method, the keyword in the data update request can be extracted, and the update information of this time can be recorded in the corresponding relationship between the keyword and the data value.
[0064] At the same time, the main database may record the target data in the cache. Specifically, the keyword of the target data and the updated target data value may be correspondingly stored in the cache in the form of a table.
[0065] By targeting the diversity of various business scenarios, clearly defining key IDs and scientifically designing table structures, we can meet different business needs while solving various data inconsistency problems that may arise.
[0066] In a possible embodiment, in order to improve the utilization rate of cache space, an expiration time can be set for the data in the cache, and the cache data that reaches the expiration time can be deleted. The expiration time can be set according to the actual business scenario, such as the maximum time of asynchronous synchronization between the master and slave databases. The database administrator can dynamically configure the expiration time of the cache keyword according to actual needs to balance data real-time and system performance.
[0067] In the embodiment of the present invention, a transaction processing method is adopted for write requests. All write requests are received by the main database, and the write request is processed by starting a transaction. After the main database completes the processing of the write request, it commits the transaction to ensure the atomicity of data processing. Atomicity is the original attribute of the transaction, which means that the program included in the transaction is the logical working unit of the database. All data update operations it performs must be executed or not executed at all. After the transaction is successfully committed, the cache is recorded, and the keyword and the corresponding data are stored in the cache.
[0068] The slave database may synchronize data with the information recorded in the update log. As a possible implementation, the slave database may synchronize data in the cache according to a preset time period. The interval of the preset time period is not greater than the expiration time.
[0069] The data read request received from the database may be obtained from the above-mentioned unified API, or may be obtained from an API corresponding to the read request. The data read request may include the data to be read, such as the data identifier of the data to be read.
[0070] After receiving the data read request, the slave database can query whether the data to be read exists in the cache. If the data is in the cache, it means that the data may not have been synchronized to the slave database. Therefore, the data read request can be forwarded to the master database, and the master database obtains the data to be read from the cache based on the data identifier to be read and returns it to the sender of the data read request.
[0071] As a possible implementation method, the exception information and the exception mechanism corresponding to the exception information can be preset. The database system administrator can customize the trigger conditions and processing methods of the exception triggering the main database according to the actual business situation to meet the needs of specific business scenarios. For example, the data in the cache can be set as an exception, and an automatic retry mechanism can be set for the exception. The automatic retry mechanism specifically sends the data read request to the main database through a preset interface. When the exception is found, the database system can automatically trigger the automatic retry mechanism and route the data read request to the main database. The preset interface is pre-customized by the administrator and can be adapted to different database systems.
[0072] If the data to be read is not in the cache, it means that the data has not been newly changed, so the slave database can directly query the data to be read and return it. That is, the slave database can read the data to be read from the slave database and return the data to the sender of the data read request.
[0073] like Figure 2 As shown, Figure 2An interactive schematic diagram of a data reading method provided by an embodiment of the present invention, wherein there are multiple data to be read during the reading process, and the following steps may be included:
[0074] S201, when a read request is received from a database, determine whether data A hits the cache, if it hits the cache, execute S202, if it does not hit the cache, query data A and execute S203;
[0075] S202: an error code for automatic retry is thrown, and the read request is routed to the primary database, which starts a transaction to query data A.
[0076] S203, query whether data B hits the cache, if it hits, execute S204, if not, execute S205.
[0077] S204: an error code for automatic retry is thrown, and the read request is routed to the primary database, which starts a transaction to query data B.
[0078] S205. Query data B.
[0079] Figure 3 An interactive schematic diagram of updating data in an embodiment of the present invention may include the following steps:
[0080] S301, the main database receives an update request;
[0081] S302: Update the business table, that is, update the data according to the update request. The business table stores business-related data.
[0082] S303: Commit the transaction, record the updated data in the cache, and set an expiration time for the updated data stored in the cache.
[0083] S304, writing the data update into binlog, i.e. the update log mentioned above, so that the binlog is read from the database and asynchronous data synchronization is performed based on the binlog.
[0084] The embodiments of the present invention are suitable for distributed business scenarios, especially when read operations have high requirements for data consistency, and solve the problem caused by master-slave data synchronization delay through caching and automatic retry mechanisms. In a heterogeneous database environment, this solution provides a universal interface that allows administrators to easily adapt to different database systems. This flexibility ensures the system's compatibility with future database upgrades or switches, and provides sustainable support for the evolution of the system.
[0085] Based on the same inventive concept, the embodiment of the present invention also provides a data updating method, which is applied to a main database, such as Figure 4 As shown, the method includes:
[0086] S401, obtaining a data update request, wherein the data update request includes target data to be updated and an update type;
[0087] S402, updating the target data based on the data update request;
[0088] S403: Store the updated target data in a cache, and write the updated target data into an update log, so that the target data is updated from the database based on the update log.
[0089] In a possible embodiment, the method further includes:
[0090] Performing expiration processing on the updated target data stored in the cache based on a preset expiration time;
[0091] The step of writing the updated target data into an update log so that the slave database updates the target data based on the update log includes:
[0092] The updated target data is written into an update log, so that the slave database updates the target data based on the update log according to the preset expiration time.
[0093] In a possible embodiment, writing the updated target data into the update log includes:
[0094] The data identifier and data value of the updated target data are correspondingly written into the update log.
[0095] By applying the embodiment of the present invention, an innovative selective master read strategy is introduced specifically for read traffic that may cause data inconsistency. The strategy can wisely choose when to read data from the master database to ensure the accuracy of data obtained by this part of the traffic, effectively solve the problem of master-slave data inconsistency, and provide a key guarantee for the stable operation of the system.
[0096] In order to deal with abnormal situations that may occur when reading data from the database, the present invention introduces an automatic retry mechanism. When the system detects abnormal reading from the database, it automatically switches the read request to the main database and re-reads the data. This intelligent automatic processing method reduces the need for manual intervention and improves the overall robustness and reliability of the system.
[0097] In addition, by combining cache keywords and setting expiration time, the present invention successfully achieves effective management of master-slave delay. Setting the cache expiration time equal to the master-slave delay time ensures that the data in the cache is always up to date. This innovative method effectively improves data consistency and provides a reliable data management mechanism for the system.
[0098] According to another aspect of the present invention, there is provided a data reading device, which is applied to a slave database, wherein the slave database is used to update the data in the slave database based on target data in an update log, wherein the target data in the update log is: the data stored in the update log after the master database updates the target data to be updated according to the received data update request; the master database simultaneously stores the updated target data in a cache; Figure 5 As shown, the device 500 includes:
[0099] A first acquisition module 501 is used to acquire a data read request, wherein the data read request includes data to be read;
[0100] The sending module 502 is used to send the data reading request to the main database when the data to be read is in the cache, so that the main database reads the data to be read, and returns the data to be read to the sender of the data reading request.
[0101] According to another aspect of the present invention, there is provided a data updating device, which is applied to a main database, such as Figure 6 As shown, the device 600 includes:
[0102] The second acquisition module 601 is used to acquire a data update request, wherein the data update request includes target data to be updated and an update type;
[0103] An updating module 602, configured to update the target data based on the data update request;
[0104] The storage module 603 is used to store the updated target data into a cache, and write the updated target data into an update log, so that the slave database updates the target data based on the update log.
[0105] According to another aspect of the present invention, a database system is provided. Figure 7 As shown, the system includes a master database 701 and a slave database 702;
[0106] The master database is used to obtain a data update request, wherein the data update request includes target data to be updated and an update type; based on the data update request, the target data is updated; the updated target data is stored in a cache, and the updated target data is written into an update log;
[0107] The slave database is used to update the target data based on the update log.
[0108] In a possible embodiment, the slave database is used to obtain a data read request, wherein the data read request includes the data to be read; and when the data to be read is in the cache, the data read request is sent to the master database;
[0109] The main database is used to read the data to be read based on the data reading request, and return the data to be read to the sender of the data reading request.
[0110] Among them, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the present invention are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0111] The exemplary embodiment of the present invention further provides an electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program that can be executed by the at least one processor, and the computer program is used to enable the electronic device to perform a method according to an embodiment of the present invention when executed by the at least one processor.
[0112] Exemplary embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present invention.
[0113] An exemplary embodiment of the present invention further provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor of a computer, the computer is used to enable the computer to perform a method according to an embodiment of the present invention.
[0114] refer to Figure 8 , a block diagram of an electronic device 800 that can be used as a server or client of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0115] like Figure 8As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0116] A plurality of components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 may be any type of device capable of inputting information to the electronic device 800, and the input unit 806 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 807 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 may include, but is not limited to, a disk, an optical disk. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0117] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above. For example, in some embodiments, the above-mentioned data reading method and data updating method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via the ROM 802 and / or the communication unit 809. In some embodiments, the computing unit 801 may be configured to perform the above-mentioned data reading method and data updating method by any other appropriate means (e.g., by means of firmware).
[0118] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0119] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, 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 foregoing.
[0120] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0121] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0122] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0123] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
Claims
1. A data reading method, characterized in that: Applied to a slave database, the slave database is used to update the data in the slave database based on target data in an update log, the target data in the update log being data stored in the update log after the master database updates the target data to be updated according to a received data update request; The main database simultaneously stores the updated target data in the cache; The method comprises: Obtaining a data read request, wherein the data read request includes data to be read; In the case that the data to be read is in the cache, the data read request is sent to the main database, so that the main database reads the data to be read and returns the data to be read to the sender of the data read request.
2. The method according to claim 1, characterized in that In a case where the data to be read is stored in the slave database, the data to be read is read from the slave database, and the data to be read is returned to the sender of the data read request.
3. The method according to claim 1, characterized in that: The slave database is used to update the data in the slave database based on the target data in the update log according to a preset expiration time.
4. A data updating method, characterized in that: Applied to the main database, the method comprises: Obtaining a data update request, wherein the data update request includes target data to be updated and an update type; Based on the data update request, updating the target data; The updated target data is stored in a cache, and the updated target data is written into an update log, so that the target data is updated from the database based on the update log.
5. The method according to claim 4, characterized in that The method further comprises: Performing expiration processing on the updated target data stored in the cache based on a preset expiration time; The step of writing the updated target data into an update log so that the slave database updates the target data based on the update log includes: The updated target data is written into an update log, so that the slave database updates the target data based on the update log according to the preset expiration time.
6. The method according to claim 4, characterized in that The step of writing the updated target data into the update log comprises: The data identifier and data value of the updated target data are correspondingly written into the update log.
7. A data reading device, characterized in that: Applied to a slave database, the slave database is used to update the data in the slave database based on target data in an update log, the target data in the update log being data stored in the update log after the master database updates the target data to be updated according to a received data update request; The main database simultaneously stores the updated target data in the cache; The device comprises: A first acquisition module, used to acquire a data read request, wherein the data read request includes data to be read; The sending module is used to send the data reading request to the main database when the data to be read is in the cache, so that the main database reads the data to be read, and returns the data to be read to the sender of the data reading request.
8. A data updating device, characterized in that: Applied to a main database, the device comprises: A second acquisition module, used to acquire a data update request, wherein the data update request includes target data to be updated and an update type; An updating module, used for updating the target data based on the data update request; The storage module is used to store the updated target data into a cache and write the updated target data into an update log, so that the target data is updated from the database based on the update log.
9. A database system, characterized in that: The system includes a master database and a slave database; The master database is used to obtain a data update request, wherein the data update request includes target data to be updated and an update type; based on the data update request, the target data is updated; Storing the updated target data into a cache, and writing the updated target data into an update log; The slave database is used to update the target data based on the update log.
10. The system according to claim 9, characterized in that The slave database is used to obtain a data read request, wherein the data read request includes the data to be read; when the data to be read is in the cache, the data read request is sent to the master database; The main database is used to read the data to be read based on the data reading request, and return the data to be read to the sender of the data reading request.
11. An electronic device, comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1-3 or 4-6.
12. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1-3 or 4-6.
