Database updating method and device, equipment and medium
Patent Information
- Application Number
- CN202311453178.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-02
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2043-11-02
AI Technical Summary
[0013]根据本公开的一个或多个实施例,可以提升数据库更新的便捷性,减少对硬件资源的占用。
Smart Images

Figure CN117472926B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to the field of database technology, specifically to a database updating method, apparatus, electronic device, computer-readable storage medium, and computer program product. Background Technology
[0002] Cloud computing refers to a technology system that provides access to a shared pool of physical or virtual resources via a network. These resources can include servers, operating systems, networks, software, applications, and storage devices, and can be deployed and managed on demand and in a self-service manner. Cloud computing technology can provide efficient and powerful data processing capabilities for applications such as artificial intelligence and blockchain, as well as for model training.
[0003] With the continuous development of database technology, database-based applications and services can be applied to various scenarios. To ensure the effectiveness of various tasks implemented based on databases, it is necessary to update the data in the database in a timely and efficient manner.
[0004] The methods described in this section are not necessarily methods that had been previously conceived or adopted. Unless otherwise specified, no method described in this section should be assumed to be prior art simply because it is included in this section. Similarly, unless otherwise specified, the issues mentioned in this section should not be considered to be accepted in any prior art. Summary of the Invention
[0005] This disclosure provides a database update method, a data query method and apparatus applied to a database, an electronic device, a computer-readable storage medium, and a computer program product.
[0006] According to one aspect of this disclosure, a method for updating a database is provided, the database including a first partition and a second partition, the method comprising: writing first newly added data including a first data identifier and second newly added data including the first data identifier into the first partition; recording a first write time of the first newly added data and a second write time of the second newly added data; and updating the data in the second partition based on the first newly added data and the second newly added data in response to determining that a first time interval between the current time and the first write time or a second time interval between the current time and the second write time satisfies a preset condition.
[0007] According to one aspect of this disclosure, a data query method for a database is provided, wherein the database is updated using the aforementioned database update method. The method includes: receiving a data query request for a target data identifier; obtaining first query data from a first partition based on the target data identifier; obtaining second query data from a second partition based on the target data identifier; and determining a data query result based on the first query data and the second query data.
[0008] According to one aspect of this disclosure, a database update apparatus is provided, the database including a first partition and a second partition, the apparatus comprising: a writing unit configured to write first newly added data including a first data identifier and second newly added data including the first data identifier into the first partition; a recording unit configured to record a first write time of the first newly added data and a second write time of the second newly added data; and an update unit configured to update the data in the second partition based on the first newly added data and the second newly added data in response to determining that a first time interval between the current time and the first write time or a second time interval between the current time and the second write time satisfies a preset condition.
[0009] According to one aspect of this disclosure, a data query apparatus for a database is provided, the database being updated using the aforementioned database update apparatus. The apparatus includes: a receiving unit configured to receive a data query request for a target data identifier; a first query unit configured to obtain first query data from a first partition based on the target data identifier; a second query unit configured to obtain second query data from a second partition based on the target data identifier; and a determining unit configured to determine a data query result based on the first query data and the second query data.
[0010] According to one aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform any of the methods described above.
[0011] According to one aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause the computer to perform any of the methods described above.
[0012] According to one aspect of this disclosure, a computer program product is provided, including a computer program, wherein the computer program, when executed by a processor, is capable of implementing any of the methods described above.
[0013] According to one or more embodiments of this disclosure, the ease of database updates can be improved and the consumption of hardware resources can be reduced.
[0014] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0015] The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0016] Figure 1 A schematic diagram of an exemplary system in which various methods described herein may be implemented, according to exemplary embodiments of the present disclosure;
[0017] Figure 2 A flowchart illustrating a database update method according to an exemplary embodiment of the present disclosure is shown;
[0018] Figure 3 A flowchart is shown of a data query method applied to a database according to an exemplary embodiment of the present disclosure;
[0019] Figure 4 A schematic diagram of the structure of a data query system according to an exemplary embodiment of the present disclosure is shown;
[0020] Figure 5 A structural block diagram of a database updating apparatus according to an exemplary embodiment of the present disclosure is shown;
[0021] Figure 6 A structural block diagram of a data query apparatus applied to a database according to an exemplary embodiment of the present disclosure is shown;
[0022] Figure 7 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0023] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0024] In this disclosure, unless otherwise stated, the use of terms such as "first," "second," etc., to describe various elements is not intended to limit the positional, temporal, or importance relationships of these elements; such terms are merely used to distinguish one element from another. In some examples, the first element and the second element may refer to the same instance of that element, while in other cases, based on the context, they may refer to different instances.
[0025] The terminology used in the description of the various examples described in this disclosure is for the purpose of describing particular examples only and is not intended to be limiting. Unless the context explicitly indicates otherwise, an element may be one or more unless the number of elements is specifically limited. Furthermore, the term "and / or" as used in this disclosure covers any one of the listed items and all possible combinations thereof.
[0026] In related technologies, one approach is to acquire new data at fixed time intervals and update all data in the database accordingly. However, this method has poor timeliness and cannot guarantee the real-time accuracy of the database. Another approach is to continuously acquire new data and update the database in real time, but this method consumes too much data computation and read / write channels and is more difficult to implement.
[0027] Based on this, this disclosure provides a database update method, which divides the database into a first partition for storing new data and a second partition for long-term data storage. After the new data is written to the first partition, the write time is recorded. Based on the time interval between the current time and the write time, it is determined whether to update the new data to the second partition. This enables updates to be performed on the same data identifier based on preset conditions, thereby ensuring data timeliness while reducing the occupation of hardware resources and improving the convenience of data updates.
[0028] The embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.
[0029] Figure 1 A schematic diagram of an exemplary system 100 in which the various methods and apparatus described herein can be implemented according to embodiments of this disclosure is shown. Reference Figure 1 The system 100 includes one or more client devices 101, 102, 103, 104, 105 and 106, a server 120, and one or more communication networks 110 coupling the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105 and 106 can be configured to execute one or more applications.
[0030] In embodiments of this disclosure, server 120 may run one or more services or software applications that enable the execution of at least one of database update methods and data query methods.
[0031] In some embodiments, server 120 may also provide other services or software applications, which may include non-virtual and virtual environments. In some embodiments, these services may be provided as web-based services or cloud services, such as to users of client devices 101, 102, 103, 104, 105, and / or 106 under a Software as a Service (SaaS) model.
[0032] exist Figure 1 In the configuration shown, server 120 may include one or more components that implement the functions performed by server 120. These components may include software components, hardware components, or combinations thereof that can be executed by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and / or 106 can sequentially interact with server 120 using one or more client applications to utilize the services provided by these components. It should be understood that various different system configurations are possible and may differ from system 100. Therefore, Figure 1 This is an example of a system used to implement the various methods described herein, and is not intended to be limiting.
[0033] Users can use client devices 101, 102, 103, 104, 105, and / or 106 to send new data or data query requests. The client devices can provide an interface that allows users to interact with the client devices. The client devices can also output information to the user through this interface. Although... Figure 1 Only six client devices are described, but those skilled in the art will understand that this disclosure can support any number of client devices.
[0034] Client devices 101, 102, 103, 104, 105, and / or 106 may include various categories of computer devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptops), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, gaming systems, thin clients, various messaging devices, sensors, or other sensing devices. These computer devices can run various categories and versions of software applications and operating systems, such as Microsoft Windows, Apple iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as Google Chrome OS); or include various mobile operating systems, such as Microsoft Windows Mobile OS, iOS, Windows Phone, and Android. Portable handheld devices may include cellular phones, smartphones, tablets, personal digital assistants (PDAs), etc. Wearable devices may include head-mounted displays (such as smart glasses) and other devices. Gaming systems may include various handheld gaming devices, internet-enabled gaming devices, etc. Client devices can run a variety of different applications, such as various Internet-related applications, communication applications (e.g., email applications), short message service (SMS) applications, and can use various communication protocols.
[0035] Network 110 can be any type of network well known to those skilled in the art, and can use any of a variety of available protocols (including but not limited to TCP / IP, SNA, IPX, etc.) to support data communication. By way of example only, one or more networks 110 can be a local area network (LAN), an Ethernet-based network, a token ring network, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a blockchain network, a public switched telephone network (PSTN), an infrared network, a wireless network (e.g., Bluetooth, WIFI), and / or any combination of these and / or other networks.
[0036] Server 120 may include one or more general-purpose computers, special-purpose server computers (e.g., PC (personal computer) servers, UNIX servers, mid-range servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and / or combination. Server 120 may include one or more virtual machines running a virtual operating system, or other computing architectures involving virtualization (e.g., one or more flexible pools of logical storage devices that can be virtualized to maintain virtual storage devices for servers). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.
[0037] The computing unit in server 120 can run one or more operating systems, including any of the aforementioned operating systems and any commercially available server operating system. Server 120 can also run any of a variety of additional server applications and / or middleware applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.
[0038] In some implementations, server 120 may include one or more applications to analyze and merge data feeds and / or event updates received from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 may also include one or more applications to display data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and 106.
[0039] In some implementations, server 120 can be a server for a distributed system or a server integrated with blockchain. Server 120 can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. A cloud server is a host product in the cloud computing service system, designed to address the shortcomings of traditional physical hosts and Virtual Private Server (VPS) services, such as high management difficulty and weak business scalability.
[0040] System 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of the databases 130 may be used to store information such as audio files and video files. Databases 130 may reside in various locations. For example, a database used by server 120 may be local to server 120, or it may be located away from server 120 and may communicate with server 120 via a network-based or dedicated connection. Databases 130 may be of different categories. In some embodiments, the database used by server 120 may be, for example, a relational database. One or more of these databases may store, update, and retrieve data from and from the databases in response to commands.
[0041] In some embodiments, one or more of the databases 130 may also be used by an application to store application data. The databases used by the application may be different categories of databases, such as key-value stores, object stores, or regular stores supported by a file system.
[0042] Figure 1The system 100 can be configured and operated in various ways to enable the application of the various methods and apparatus described in this disclosure.
[0043] Figure 2 A flowchart of a database update method 200 according to an exemplary embodiment of the present disclosure is shown, the database including a first partition and a second partition. Figure 2 As shown, method 200 includes:
[0044] Step S201: Write the first newly added data including the first data identifier and the second newly added data including the first data identifier into the first partition;
[0045] Step S202: Record the first write time of the first newly added data and the second write time of the second newly added data; and
[0046] Step S203: In response to determining that the first time interval between the current time and the first write time or the second time interval between the current time and the second write time meets a preset condition, update the data of the second partition based on the first newly added data and the second newly added data.
[0047] By applying the above method 200, the database is divided into a first partition and a second partition. After receiving new data, it is written to the first partition and the write time is recorded. That is, the first partition is used to store new data. Then, based on the time interval between the current time and the write time of the new data, it is determined whether to update the new data to the second partition. That is, the second partition is used to store data for a long time. By combining the use of two data partitions and using the above methods to update data, it is possible to perform updates based on preset conditions for the same data identifier. This reduces the occupation of hardware resources while ensuring data timeliness and improves the convenience of data updates.
[0048] In some examples, the database is a key-value database, meaning that data identifiers are used as keys and the actual data content is stored as values to facilitate data management and retrieval.
[0049] In some examples, the database stores user behavior data, such as user browsing, clicking, and rating of different objects. These objects can include various types of content, such as web pages, documents, videos, and images. In other examples, this database can be applied to the field of object recommendation. By utilizing the database to store user behavior data, it is possible to analyze user preferences more comprehensively and accurately based on historical data, thereby achieving more accurate object recommendations.
[0050] In some examples, data processing can be performed based on newly added data, and the processing results can be written to the first partition or updated to the second partition. For example, statistical results of the original data can be stored in the database. When new data is received, statistical calculations can be performed based on the old statistical results stored in the database and the new data, and then the new statistical results can be updated to the database. Understandably, the specific type of statistical results and the specific implementation method of statistical calculations can be set according to actual needs, and this disclosure does not limit them. In some examples, the data processing results described above can be stored in both the first and second partitions, or the data processing results can be stored permanently only in the second partition, and this disclosure does not limit them.
[0051] In some examples, the operation of recording the write time in step S202 can be implemented based on the time synchronization module, that is, generating a timestamp for each data write record in the first partition.
[0052] In some examples, the preset condition can be a preset time interval threshold, which determines whether a data update needs to be performed by comparing the relative size of the time interval between the time when the new data was written and the current time with the time interval threshold.
[0053] In one example, multiple new data entries corresponding to multiple data identifiers can be continuously and in real-time acquired. For example, data A1 with identifier 'a', data B1 with identifier 'b', data A2 with identifier 'a', and data B2 with identifier 'b' can be acquired sequentially in chronological order. The write time of each new data entry to the first partition needs to be recorded. When the time interval between a write time corresponding to identifier 'a' and the current time reaches a preset threshold, it is equivalent to detecting that the first received data A1 in the first partition has met the update condition. Therefore, all new data entries with identifier 'a' (data A1 and data A2) need to be merged and updated in the second partition. Similarly, when the time interval between a write time corresponding to identifier 'a' and the current time reaches a preset threshold, all new data entries with identifier 'a' (data A1 and data A2) need to be merged and updated in the second partition. It can be seen that the long-term data corresponding to each data identifier in the second partition is updated based on the preset time interval threshold. Compared to traditional data update methods that update all data in the second partition based on fixed time intervals and require a large amount of data throughput resources for each update, the data update method provided in this disclosure can achieve better data timeliness with lower data update throughput and less hardware resources.
[0054] According to some embodiments, method 200 further includes: in response to determining that the second partition stores first historical data corresponding to the first data identifier, obtaining a first update time of the first historical data, wherein the step of updating the data of the second partition based on the first newly added data and the second newly added data in response to determining that the first time interval between the current time and the first write time or the second time interval between the current time and the second write time satisfies a preset condition includes: updating the data of the second partition based on the first newly added data and the second newly added data in response to determining that at least one of the first time interval between the current time and the first write time, the second time interval between the current time and the second write time, and the third time interval between the current time and the first update time satisfies the preset condition. When the second partition already stores historical data with the same data identifier as the newly added data, by applying the above means, the update time of the newly added data can be more accurately controlled by combining the update time of the historical data, ensuring the timeliness of the data.
[0055] According to some embodiments, recording the first write time of the first newly added data and the second write time of the second newly added data in step S202 includes: writing a first message consisting of the first data identifier and the first write time into a message queue; and writing a second message consisting of the first data identifier and the second write time into the message queue. Method 200 further includes: obtaining a message to be processed located at the exit of the message queue; and moving the message to be processed to the entry of the message queue in response to determining that the time interval between the current time and the write time in the message to be processed does not meet the preset condition. Therefore, a message queue can be used to store newly added data information, and messages at the queue exit can be detected sequentially. When a preset condition is met, data updates are performed; otherwise, the message is written back to the queue entry, thus conveniently enabling the monitoring of newly added data.
[0056] In some examples, the newly added data information, which includes the data identifier and the write time, can be stored in a preset location, and the determination of whether a data update needs to be performed can be made by continuously traversing each newly added data information in the preset location.
[0057] According to some embodiments, when the second partition stores first historical data corresponding to the first data identifier, method 200 further includes: after updating the first historical data based on the first newly added data and the second newly added data, recording a second update time; and in response to determining that the write time in the message to be processed is before the second update time, discarding the message to be processed. Thus, after a data update has been performed, it is possible to determine whether a message needs to be discarded by detecting the chronological relationship between the write time and the update time recorded in the message, thereby achieving efficient management of the message queue and ensuring the accuracy of monitoring new data.
[0058] In some examples, new data can be written to the first partition sequentially according to time. When a data update is needed, only a certain range of data needs to be read. However, in real-world applications, there may be latency or out-of-order data writing, which can affect the accuracy of data updates.
[0059] Based on this, according to some embodiments, method 200 further includes: determining a first sequence code for the first newly added data and a second sequence code for the second newly added data, wherein step S201 of writing the first newly added data and the second newly added data into the first partition includes: writing the first newly added data and the first sequence code together into the first partition, and writing the second newly added data and the second sequence code together into the first partition, and step S203 of updating the data in the second partition based on the first newly added data and the second newly added data includes: searching for the first newly added data and the second newly added data in the first partition based on the first sequence code and the second sequence code. Thus, a sequence code can be added to the newly added data and stored in the first partition to find the data to be updated based on the sequence code. By searching for data based on the sequence code, the correctness of data updates can be avoided due to data transmission delays or out-of-order delivery.
[0060] In some examples, the sequence code for each new data entry can be determined by a pipelined auto-incrementing encoding method. This sequence code, along with the data identifier and the write time, is then stored as the new data information. Alternatively, it can be stored in a message queue in the manner described above, thereby enabling convenient and accurate control of the data update process.
[0061] In some examples, when the second partition stores first historical data corresponding to the first data identifier, the sequence code corresponding to the first historical data can be further obtained. Based on this, the data to be updated can be found in the first partition by combining the first newly added data and the second newly added data, thereby improving the accuracy and convenience of data updates.
[0062] According to some embodiments, method 200 further includes: cleaning up the data stored in the first partition based on a preset time interval. This allows the first partition to be cleaned up at a preset interval, saving hardware resources. When multiple sets of newly added data received in real time are written to the first partition in chronological order, this method also ensures that the storage space of the first partition is managed based on a continuous data storage area, improving the convenience of data space management.
[0063] Understandably, the time interval for cleaning the first partition should be longer than the time interval for data updates in the second partition to avoid data loss.
[0064] In some examples, the data in the second group could be updated based on a set of new data, and then the new data in that group could be deleted from the first partition to save hardware resources.
[0065] According to one aspect of this disclosure, a data query method applied to a database is also provided. Figure 3 A flowchart is shown of a data query method 300 applied to a database according to an exemplary embodiment of the present disclosure, wherein the database is updated using the database update method 200 described above. Figure 3 As shown, method 300 includes:
[0066] Step S301: Receive a data query request for the target data identifier;
[0067] Step S302: Obtain first query data from the first partition based on the target data identifier;
[0068] Step S303: Obtain second query data from the second partition based on the target data identifier; and
[0069] Step S304: Determine the data query result based on the first query data and the second query data.
[0070] By applying the above method 300, the data query results can be obtained by combining the newly added data in the first partition and the long-term data in the second partition, thus ensuring the accuracy of the query.
[0071] According to some embodiments, when the first partition stores the sequence code of newly added data, step S302, which involves obtaining the first query data from the first partition based on the target data identifier, includes: obtaining the most recently updated target sequence code corresponding to the target data identifier in the second partition; and obtaining the first query data from the first partition based on the target data identifier and the target sequence code. When the first partition stores the sequence code of newly added data, by applying the above method, the data in the first partition that has not yet been updated can be accurately determined based on the most recently updated target sequence code in the second partition (i.e., the difference between the data in the first partition and the data in the second partition), avoiding redundant data from occupying hardware resources and improving query efficiency.
[0072] Figure 4 A schematic diagram of the structure of a data query system according to an exemplary embodiment of the present disclosure is shown. In this example, the database may store user behavior data or the processing results obtained by pre-defined data processing based on user behavior data.
[0073] See Figure 4 As shown, the new data can be obtained by the user behavior data collection system based on the user's behavior information on the front end. When the amount of user behavior data is large, it can be cached sequentially in a data message queue, and then the real-time computing module of the database can read the new data sequentially from the data message queue to achieve asynchronous processing of the new data. When the real-time computing module writes a new piece of data to the first partition, it can generate a notification message including the data identifier of the new data, the writing time, and the sequence code, and store it in the notification message queue.
[0074] Based on this, the nearline computing module can monitor newly added data in the first partition by listening to the notification message queue. In one example, the nearline computing module can use the method described above to determine the operation for each notification message based on the content included in the notification message, the data identifier in the second partition, the latest update time and the latest update sequence code corresponding to each data identifier, such as performing data updates based on the notification message, writing the notification message back to the notification message queue, or discarding the notification message.
[0075] In some examples, a limit can be pre-set on the frequency at which the nearline compute module subscribes to messages in the notification message queue to avoid an invalid loop where the nearline compute module continuously consumes notification messages and writes them back to the notification message queue.
[0076] In some examples, the data identifiers in the second partition, the latest update time and the latest update sequence code for each data identifier can be stored in a preset location for easy querying.
[0077] When it is necessary to query data in the database, a data query request can be obtained from the external query server. Based on this, query data can be obtained from the first partition and the second partition respectively. Then, the data can be merged in the query data merging module to obtain the data query result, and then the data query result can be returned to the query server.
[0078] In some examples, the query data merging module can perform various data processing operations on the query data, such as data deduplication, statistical calculations, and data merging, to meet the data query requirements of real-world application scenarios. In some examples, the query server may include a cache queue for data query requests. When multiple data query requests for the same data identifier are received within a certain time period, these requests can be merged, and the data query can be performed only once for the merged request, returning the result and saving hardware resources.
[0079] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0080] According to one aspect of this disclosure, a database updating apparatus is also provided, the database including a first partition and a second partition. Figure 5 A structural block diagram of a database update apparatus 500 according to an exemplary embodiment of the present disclosure is shown, such as... Figure 5 As shown, the device 500 includes:
[0081] The write unit 501 is configured to write first newly added data including a first data identifier and second newly added data including the first data identifier to the first partition;
[0082] Recording unit 502 is configured to record the first write time of the first newly added data and the second write time of the second newly added data; and
[0083] The update unit 503 is configured to update the data of the second partition based on the first newly added data and the second newly added data in response to determining that a first time interval between the current time and the first write time or a second time interval between the current time and the second write time meets a preset condition.
[0084] According to some embodiments, the device 500 further includes: an acquisition unit configured to acquire a first update time of the first historical data in response to determining that the second partition stores first historical data corresponding to the first data identifier, wherein the update unit 503 is configured to update the data of the second partition based on the first newly added data and the second newly added data in response to determining that at least one of a first time interval between the current time and the first write time, a second time interval between the current time and the second write time, and a third time interval between the current time and the first update time satisfies the preset condition.
[0085] According to some embodiments, the recording unit 502 is configured to: write a first message consisting of the first data identifier and the first write time into a message queue; and write a second message consisting of the first data identifier and the second write time into the message queue. The device further includes a message processing unit configured to: acquire a message to be processed located at the exit of the message queue; and move the message to be processed to the entry of the message queue in response to determining that the time interval between the current time and the write time in the message to be processed does not meet the preset condition.
[0086] According to some embodiments, when the second partition stores first historical data corresponding to the first data identifier, the recording unit 502 is further configured to record a second update time after updating the first historical data based on the first new data and the second new data, wherein the message processing unit is further configured to discard the message to be processed in response to determining that the write time in the message to be processed is before the second update time.
[0087] According to some embodiments, the apparatus 500 further includes: an encoding unit configured to determine a first sequence code of the first newly added data and a second sequence code of the second newly added data, wherein the writing unit 501 is configured to: write the first newly added data and the first sequence code together into the first partition, and write the second newly added data and the second sequence code together into the first partition, and wherein the updating unit 503 is configured to: search for the first newly added data and the second newly added data in the first partition based on the first sequence code and the second sequence code.
[0088] According to some embodiments, the apparatus 500 further includes a cleaning unit configured to clean up data stored in the first partition based on a preset time interval.
[0089] It should be understood that Figure 5 The operation of each unit of the database update device 500 shown can be synchronized with... Figure 2The steps in the described database update method 200 correspond to each other. Therefore, the operations, features, and advantages described above for method 200 also apply to apparatus 500 and its constituent units. For the sake of brevity, some operations, features, and advantages will not be repeated here.
[0090] According to one aspect of this disclosure, a data query apparatus for a database is also provided, wherein the database is updated using the database update apparatus 400 described above. Figure 6 A structural block diagram of a data query apparatus 600 according to an exemplary embodiment of the present disclosure is shown. Figure 6 As shown, the device 600 includes:
[0091] The receiving unit 601 is configured to receive a data query request for a target data identifier;
[0092] The first query unit 602 is configured to obtain first query data from the first partition based on the target data identifier;
[0093] The second query unit 603 is configured to retrieve second query data from the second partition based on the target data identifier; and
[0094] The determining unit 604 is configured to determine the data query result based on the first query data and the second query data.
[0095] According to some embodiments, when the first partition stores the sequence code of newly added data, the first query unit 603 is configured to: obtain the most recently updated target sequence code corresponding to the target data identifier in the second partition; and obtain the first query data from the first partition based on the target data identifier and the target sequence code.
[0096] It should be understood that Figure 6 The operation of each unit of the data query device 600 shown can be combined with... Figure 3 The steps in the described data query method 300 correspond to each other. Therefore, the operations, features, and advantages described above for method 300 also apply to device 600 and its constituent units. For the sake of brevity, some operations, features, and advantages will not be repeated here.
[0097] According to one aspect of this disclosure, an electronic device is also provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform at least one of the above-described database update method and data query method.
[0098] According to one aspect of this disclosure, a non-transitory computer-readable storage medium storing computer instructions is also provided, wherein the computer instructions are used to cause the computer to perform at least one of the above-described database update method and data query method.
[0099] According to one aspect of this disclosure, a computer program product is also provided, comprising a computer program, wherein the computer program, when executed by a processor, implements at least one of the above-described database update method and data query method.
[0100] refer to Figure 7 The present invention describes a structural block diagram of an electronic device 700 that can serve as a server or client of the present disclosure, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, 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 processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0101] like Figure 7 As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 702 or a computer program loaded from storage unit 708 into random access memory (RAM) 703. RAM 703 may also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. Input / output (I / O) interface 705 is also connected to bus 704.
[0102] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, output unit 707, storage unit 708, and communication unit 709. Input unit 706 can be any type of device capable of inputting information to device 700. Input unit 706 can receive input numerical or character information and generate key signal inputs related to user settings and / or function control of the electronic device, and may include, but is not limited to, a mouse, keyboard, touchscreen, trackpad, trackball, joystick, microphone, and / or remote control. Output unit 707 can be any type of device capable of presenting information, and may include, but is not limited to, a monitor, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 708 may include, but is not limited to, a hard disk and an optical disk. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth devices, 802.11 devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.
[0103] The computing unit 701 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as at least one of the database update method and the data query method. For example, in some embodiments, at least one of the database update method and the data query method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of at least one of the database update method and the data query method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured by any other suitable means (e.g., by means of firmware) to perform at least one of a database update method and a data query method.
[0104] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0105] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0106] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0107] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, 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 sound input, voice input, or tactile input).
[0108] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
[0109] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0110] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0111] While embodiments or examples of this disclosure have been described with reference to the accompanying drawings, it should be understood that the methods, systems, and devices described above are merely exemplary embodiments or examples, and the scope of the invention is not limited to these embodiments or examples. Various elements in the embodiments or examples may be omitted or replaced by their equivalents. Furthermore, the steps may be performed in a different order than that described in this disclosure. Further, various elements in the embodiments or examples may be combined in various ways. Importantly, as the technology evolves, many elements described herein can be replaced by equivalents that appear after this disclosure.
Claims
1. A method for updating a database, the database comprising a first partition and a second partition, the method comprising: Write the first newly added data, which includes the first data identifier, and the second newly added data, which includes the first data identifier, into the first partition; Record the first write time of the first newly added data and the second write time of the second newly added data, including: Write the first message, consisting of the first data identifier and the first write time, into the message queue; and The second message, consisting of the first data identifier and the second write time, is written to the message queue. Retrieve the pending messages located at the exit of the message queue; In response to the determination that the time interval between the current time and the write time in the message to be processed does not meet a preset condition, the message to be processed is moved to the entry of the message queue; and In response to determining that the first time interval between the current time and the first write time or the second time interval between the current time and the second write time meets a preset condition, the data of the second partition is updated based on the first newly added data and the second newly added data.
2. The method of claim 1, further comprising: In response to determining that the second partition stores first historical data corresponding to the first data identifier, the first update time of the first historical data is obtained. The step of updating the data of the second partition based on the first newly added data and the second newly added data in response to determining that the first time interval between the current time and the first write time or the second time interval between the current time and the second write time meets a preset condition includes: In response to determining that at least one of the first time interval between the current time and the first write time, the second time interval between the current time and the second write time, and the third time interval between the current time and the first update time satisfies the preset condition, the data of the second partition is updated based on the first newly added data and the second newly added data.
3. The method of claim 1, wherein when the second partition stores first historical data corresponding to the first data identifier, the method further comprises: After updating the first historical data based on the first newly added data and the second newly added data, record the second update time; as well as In response to determining that the write time in the pending message is before the second update time, the pending message is discarded.
4. The method according to any one of claims 1-3, further comprising: Determine the first sequence code of the first newly added data and the second sequence code of the second newly added data. The step of writing the first newly added data and the second newly added data into the first partition includes: The first newly added data and the first sequence code are written together to the first partition, and the second newly added data and the second sequence code are written together to the first partition. Furthermore, the step of updating the data in the second partition based on the first newly added data and the second newly added data includes: Based on the first sequence code and the second sequence code, the first newly added data and the second newly added data are retrieved from the first partition.
5. The method according to any one of claims 1-3, further comprising: Based on a preset time interval, clean up the data stored in the first partition.
6. A data query method applied to a database, wherein the database is updated using the method described in any one of claims 1-5, the method comprising: Receive data query requests targeting a data identifier; Based on the target data identifier, obtain the first query data from the first partition; The second query data is obtained from the second partition based on the target data identifier; as well as Based on the first query data and the second query data, the data query result is determined.
7. The method of claim 6, wherein, When the first partition stores the sequence code of newly added data, obtaining the first query data from the first partition based on the target data identifier includes: Obtain the most recently updated target sequence code corresponding to the target data identifier in the second partition; and Based on the target data identifier and the target sequence code, the first query data is obtained from the first partition.
8. A database update apparatus, the database comprising a first partition and a second partition, the apparatus comprising: The write unit is configured to write first new data including a first data identifier and second new data including the first data identifier to the first partition; A recording unit is configured to record the first write time of the first newly added data and the second write time of the second newly added data, wherein the recording unit is configured to: Write the first message, consisting of the first data identifier and the first write time, into the message queue; and The second message, consisting of the first data identifier and the second write time, is written to the message queue. A message processing unit is configured to: acquire a message to be processed located at the exit of the message queue; and, in response to determining that the time interval between the current time and the write time in the message to be processed does not meet a preset condition, move the message to be processed to the entry of the message queue; and The update unit is configured to update the data of the second partition based on the first newly added data and the second newly added data in response to determining that a first time interval between the current time and the first write time or a second time interval between the current time and the second write time meets a preset condition.
9. The apparatus of claim 8, further comprising: The acquisition unit is configured to, in response to determining that the second partition stores first historical data corresponding to the first data identifier, acquire the first update time of the first historical data. The update unit is configured as follows: In response to determining that at least one of the first time interval between the current time and the first write time, the second time interval between the current time and the second write time, and the third time interval between the current time and the first update time satisfies the preset condition, the data of the second partition is updated based on the first newly added data and the second newly added data.
10. The apparatus of claim 8, wherein when the second partition stores first historical data corresponding to the first data identifier, the recording unit is further configured to: After updating the first historical data based on the first newly added data and the second newly added data, record the second update time. in, The message processing unit is further configured to: In response to determining that the write time in the pending message is before the second update time, the pending message is discarded.
11. The apparatus of any one of claims 8-10, further comprising: The encoding unit is configured to determine a first sequence code for the first newly added data and a second sequence code for the second newly added data. The writing unit is configured as follows: The first newly added data and the first sequence code are written together to the first partition, and the second newly added data and the second sequence code are written together to the first partition. Furthermore, the update unit is configured as follows: Based on the first sequence code and the second sequence code, the first newly added data and the second newly added data are retrieved from the first partition.
12. The apparatus of any one of claims 8-10, further comprising: The cleaning unit is configured to clean up the data stored in the first partition based on a preset time interval.
13. A data query apparatus for a database, wherein the database is updated using the apparatus according to any one of claims 8-12, the apparatus comprising: The receiving unit is configured to receive data query requests for a target data identifier; The first query unit is configured to obtain first query data from the first partition based on the target data identifier; The second query unit is configured to obtain second query data from the second partition based on the target data identifier; as well as The determining unit is configured to determine the data query result based on the first query data and the second query data.
14. The apparatus of claim 13, wherein, When the first partition stores the sequence code of newly added data, the first query unit is configured as follows: Obtain the most recently updated target sequence code in the second partition that corresponds to the target data identifier; as well as Based on the target data identifier and the target sequence code, the first query data is obtained from the first partition.
15. An electronic device comprising: At least one processor; as well as A memory that is communicatively connected to the at least one processor; in The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.
16. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-7.
17. A computer program product comprising a computer program, wherein, The computer program, when executed by a processor, implements the method according to any one of claims 1-7.
Citation Information
Patent Citations
Data renewing method and device
CN104750740A
Data storage method and device, equipment, storage medium and program product
CN116450638A
Lazy updates to indexes in a database
US20090089334A1