Data management method and device, storage medium and electronic device
By employing distributed caching and conditional write mechanisms, the problem of low data management stability caused by cross-regional data transmission is solved, enabling efficient data management and sharing, and improving the stability and availability of data management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-11-27
- Publication Date
- 2026-05-29
AI Technical Summary
In data management scenarios, cross-regional data transmission and frequent database write operations lead to low data management stability.
A distributed caching approach is adopted, where data is first written to the cache library in each region, and then written to the central database according to the conditions. The cache library reduces direct write operations to the database, and optimistic locking and version number mechanisms are used to ensure data consistency and integrity.
It reduces database load and concurrency conflicts, improves the stability and availability of data management, simplifies data management processes, and ensures data sharing and consistency.
Smart Images

Figure CN122111972A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more specifically, to a data management method, apparatus, storage medium, and electronic device. Background Technology
[0002] In data management scenarios, data is often generated from multiple different operating regions. If this data is directly written to a shared database, cross-regional data transfer can lead to severe concurrency conflicts. Furthermore, frequent database write operations can place an excessive burden on the database, resulting in low data management stability. Therefore, the issue of low data management stability exists.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This application provides a data management method, apparatus, storage medium, and electronic device to at least solve the technical problem of low data management stability.
[0005] According to one aspect of the embodiments of this application, a data management method is provided, comprising: writing data generated in a first running region into a first cache library as cached data for the first running region for subsequent use; writing data generated in a second running region into a second cache library as cached data for the second running region for subsequent use; wherein the data already written into the first cache library and the data already written into the second cache library are configured to be conditionally written into a central database, and the first running region and the second running region are configured to share the data stored in the central database.
[0006] According to another aspect of the embodiments of this application, a data management device is also provided, comprising: a first writing unit, configured to write data generated in a first operating region into a first cache library for subsequent use of the first operating region cache data; a second writing unit, configured to write data generated in a second operating region into a second cache library for subsequent use of the second operating region cache data; a first setting unit, configured to set the data already written into the first cache library and the data already written into the second cache library as conditional writes to a central database; and a second setting unit, configured to set the first operating region and the second operating region to share the data stored in the central database.
[0007] As an optional solution, the first writing unit includes: a first sorting module, used to, after writing the data generated in the first running area into the first cache library for subsequent use, sequentially place the data written into the first cache library into the first data queue according to the writing time order; and a first writing module, used to sequentially write the data already placed in the first data queue into the central database according to the enqueue time, wherein the enqueue time is the time when the data is placed into the first data queue.
[0008] As an optional solution, the first write module includes: a first determining submodule, used to determine the latest data from the first data queue according to the enqueue time, wherein the latest data is located at the head of the first data queue; a first write submodule, used to write the latest data into the central database to obtain a first write result; and a first sorting submodule, used to place the latest data into the tail of the first data queue if the first write result indicates that the latest data failed to be written into the central database.
[0009] As an optional solution, the first writing unit includes: a second sorting module, used to, upon obtaining the first data generated in the first operating area, place the first data into a second data queue according to the generation time order, wherein the first data is new data generated by an online account in the first operating area, and the data in the second data queue is set to be written to the first cache library sequentially according to the queue order; and a third sorting module, used to, upon obtaining the second data generated in the first operating area, place the second data at the head of the second data queue, wherein the second data is data when an online account in the first operating area chooses to log out, and the queue order at the head of the queue is the queue order in which the data is processed first.
[0010] As an optional solution, the third sorting module includes: a second writing submodule, used to write the second data to the first cache after placing the second data at the head of the second data queue, to obtain a second writing result; a second sorting submodule, used to place the second data at the head of the second data queue if the second writing result indicates that the second data failed to be written to the first cache; and a determining submodule, used to determine that the account online in the first running area is in a logged-out state if the second writing result indicates that the second data was successfully written to the first cache.
[0011] As an optional solution, the second write submodule includes: a sorting subunit, used to place the second data at the head of the second data queue after the second write result indicates that the second data failed to be written to the first cache and the cumulative number of failures is less than a preset threshold; and a removal subunit, used to remove the second data from the second data queue and record it as an exception when the second write result indicates that the second data failed to be written to the first cache and the cumulative number of failures is greater than or equal to the preset threshold.
[0012] As an optional approach, the aforementioned first data management device further includes: a third writing unit, used to employ an optimistic locking mechanism to conditionally write the data already written to the aforementioned first cache library and the data already written to the aforementioned second cache library into the aforementioned central database.
[0013] As an optional approach, the third writing unit includes: a first acquisition module, used to acquire third data that has been written from the first cache to the central database, and a first version number carried by the third data; a second acquisition module, used to acquire fourth data that has been written to the second cache, and a second version number carried by the fourth data; and a prohibition module, used to prohibit the writing of the fourth data to the central database when the fourth data and the third data belong to the same account, but the first version number and the second version number are different.
[0014] As an optional approach, the first writing unit further includes: a third acquisition module, used to acquire a first writing frequency of the first cache library after the data generated in the first running area is written into the first cache library for subsequent use; and a second writing module, used to set the first cache library to conditionally write the data already written to the first cache library into the central database according to a second writing frequency based on the first writing frequency, wherein the second writing frequency is less than the first writing frequency.
[0015] As an optional approach, the aforementioned first data management device further includes: an acquisition unit, configured to acquire at least one first database configured in a first data management region and at least one second database configured in a second data management region; a first determination unit, configured to determine the first database as the central database when the first operating region and the second operating region are operating regions within the first data management region; and a second determination unit, configured to determine the second database as the central database when the first operating region and the second operating region are operating regions within the second data management region.
[0016] According to another aspect of the embodiments of this application, another data management device is also provided, comprising: a first reading unit, configured to read cached data that matches the first target data from a first cache library that caches data for the first running area for subsequent use, in response to a retrieval request triggered by first target data generated in a first running area; a second reading unit, configured to read cached data that matches the second target data from a second cache library that caches data for the second running area for subsequent use, in response to a second retrieval request triggered by second target data generated in a second running area; a third setting unit, configured to set the data already written to the first cache library and the data already written to the second cache library as conditionally written to a central database; and a fourth setting unit, configured to set the first running area and the second running area to share data stored in the central database.
[0017] As an optional approach, the first reading unit includes: a first reading module, configured to, after reading cached data that matches the first target data from a first cache library that caches data for the first running area for subsequent use in response to an acquisition request triggered by the first target data generated in the first running area, read data that matches the first target data from the central database if the first target data does not match data already written in the first cache library.
[0018] According to another aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the data management method described above.
[0019] According to another aspect of the embodiments of this application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above-described data management method through the computer program.
[0020] In this embodiment, data generated in the first running region is written into a first cache library for later use; data generated in the second running region is written into a second cache library for later use; wherein, data already written into the first cache library and data already written into the second cache library are conditionally written into the central database, and the first running region and the second running region are configured to share data stored in the central database.
[0021] Specifically, this embodiment first establishes independent first and second cache libraries to provide temporary storage space for data generated in the first and second running regions, respectively. This distributed caching method reduces direct write operations to the central database, thereby reducing the database load. Furthermore, since data is first temporarily stored in its respective cache library, it avoids large-scale cross-regional data transfers and direct database writes, thus reducing the possibility of concurrency conflicts.
[0022] Secondly, by implementing a conditional write mechanism, this application embodiment also ensures that data in the cache library will only be written to the central database when specific conditions are met, which not only optimizes the efficiency and timing of data writing, but also further reduces the write pressure on the database.
[0023] Furthermore, this embodiment of the application achieves data sharing through a central database, while ensuring data consistency and integrity. Since data from each operating region ultimately converges in the central database, any region can access and use this data without complex cross-regional data transfer. This centralized storage and sharing mechanism simplifies the data management process, thereby improving data availability and reliability, and ultimately achieving the technical effect of improving data management stability, thus solving the technical problem of low data management stability. Attached Figure Description
[0024] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0025] Figure 1 This is a schematic diagram of an application environment for an optional data management method according to an embodiment of this application;
[0026] Figure 2 This is a schematic diagram of the flow of an optional data management method according to an embodiment of this application;
[0027] Figure 3 This is a schematic diagram of an optional data management method according to an embodiment of this application;
[0028] Figure 4 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0029] Figure 5 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0030] Figure 6 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0031] Figure 7 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0032] Figure 8 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0033] Figure 9 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0034] Figure 10 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0035] Figure 11 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0036] Figure 12 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0037] Figure 13 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0038] Figure 14 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0039] Figure 15 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0040] Figure 16 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0041] Figure 17 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0042] Figure 18 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0043] Figure 19 This is a schematic diagram of another optional data management method according to an embodiment of this application;
[0044] Figure 20 This is a schematic diagram of an optional data management device according to an embodiment of this application;
[0045] Figure 21 This is a schematic diagram of another optional data management device according to an embodiment of this application;
[0046] Figure 22 This is a schematic diagram of the structure of an optional electronic device according to an embodiment of this application. Detailed Implementation
[0047] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0048] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0049] According to one aspect of the embodiments of this application, a data management method is provided. Optionally, as an optional implementation, the above-described data management method may be applied to, but is not limited to, [examples of other methods]. Figure 1 The environment shown may include, but is not limited to, user equipment 102 and server 112. User equipment 102 may include, but is not limited to, a display 104, a processor 106 and a memory 108. Server 112 includes a database 114 and a processing engine 116.
[0050] The specific process can be summarized in the following steps:
[0051] Step S102: User equipment 102 obtains a data write request;
[0052] Step S104: Send the data write request to the server 112 via network 110;
[0053] In steps S106-S110, server 112 processes data write requests, writes data generated in the first running area and the second running area into the first cache library and the second cache library respectively, sets the data written into the cache library as conditional writes to the central database, and sets the running area to share the data in the central database.
[0054] In step S112, the data writing result is sent to the user equipment 102 via the network 110. The user equipment 102 processes the data writing result through the processor 106 and displays it on the display 104, and stores the data writing result in the memory 108.
[0055] remove Figure 1 Beyond the examples shown, the terminal devices described above can be terminal devices configured with target clients, including but not limited to at least one of the following: mobile phones (such as Android phones, iOS phones, etc.), laptops, tablets, PDAs, MIDs (Mobile Internet Devices), PADs, desktop computers, smart TVs, etc. The target client can be a video client, instant messaging client, browser client, educational client, etc. The networks described above can include, but are not limited to, wired networks and wireless networks. The wired networks include local area networks (LANs), metropolitan area networks (MANs), and wide area networks (WANs). The wireless networks include Bluetooth, Wi-Fi, and other networks that enable wireless communication. The server described above can be a single server, a server cluster consisting of multiple servers, or a cloud server. The above is merely an example, and no limitations are imposed in this embodiment.
[0056] Alternatively, as an alternative implementation method, such as Figure 2 As shown, the data management method can be executed by an electronic device, such as... Figure 1 The user equipment or server shown includes the following specific steps:
[0057] S202, write the data generated in the first running area into the first cache library as cache data for the first running area for subsequent use;
[0058] S204, write the data generated in the second running area into the second cache library as cache data for the second running area for subsequent use;
[0059] S206, set the data already written to the first cache library and the data already written to the second cache library as conditions for writing to the central database, and set the first running area and the second running area to share the data stored in the central database.
[0060] In optional embodiments, the above data management method can be applied, but is not limited to, data transmission operations performed when the location where the user uploads data is far from the location of the data center where the data is actually written. For example, when the user is located in location A and data transmission is required, but the data center is actually located in location B, the user will transmit the data to a cache library corresponding to the current user's location when uploading data, and then the cache library will upload the data to the data center.
[0061] In an optional embodiment, the first operating area may be, but is not limited to, the area where the user is located when generating data that needs to be stored, and the data that needs to be stored may be, but is not limited to, text data, image data, video data, game data, and other data that the user needs to save; the first cache library may be, but is not limited to, used to cache data generated when the user is in the first area.
[0062] In an optional embodiment, the second running area may be, but is not limited to, the area where the user is located when generating data that needs to be stored, and the data that needs to be stored may be, but is not limited to, text data, image data, video data, game data, and other data that the user needs to save; the second cache library may be, but is not limited to, used to cache data generated by the user when the user is in the second area.
[0063] Further examples, such as Figure 3 As shown, user equipment 302 and user equipment 304 are located in operating areas 306 and 308, respectively. Operating areas 306 and 308 have cache libraries 310 and 312, respectively. When user equipment 302 in operating area 306 generates data, it will cache the generated data in cache library 310. When user equipment 304 in operating area 308 generates data, it will cache the generated data in cache library 312.
[0064] In an optional embodiment, the data already written to the first cache library and the data already written to the second cache library are set as conditions for writing to the central database. This can be, but is not limited to, retrieving cached data from the first and second cache libraries by the server and conditionally writing the retrieved cached data to the central database containing the first and second cache libraries. The conditional writing can be, but is not limited to, writing cached data from the cache library to the central database based on conditions such as data size, data type, data caching time, frequency of user data caching to the cache library, frequency of data from the cache library being written to the central database, and data version number.
[0065] Further examples, such as Figure 4As shown, cache library 404 located in running area 402 and cache library 408 located in running area 406 belong to the same central database 410. The data in cache library 404 and cache library 408 are set to be conditionally written to the central database 410.
[0066] To illustrate further, suppose the conditional writing requires a specific data size condition to be met before data can be written. For example, if a certain piece of data in the cache needs to be written to the central database, then the data must meet a data size threshold before it can be written to the central database. Meeting the data size threshold can be, but is not limited to, being greater than or equal to the data size threshold, or being less than or equal to the data size threshold.
[0067] It should be noted that, in addition to writing cached data from the cache library into itself, the central database can also perform security checks, logical checks, data backups, and data analysis on the cached data to be written. This helps the central database administrators better manage the data to be written, prevents the written data from causing security risks to the central database, and can also analyze the data to be written through data analysis, assisting administrators in data management.
[0068] In an optional embodiment, setting the first running area and the second area as a shared central database can, but is not limited to, allow all cache libraries in the first running area and the second running area to obtain the required data from the central database and store the obtained data in the cache library.
[0069] Through the embodiments provided in this application, data generated in the first running area is written into a first cache library as cache data for the first running area for subsequent use; data generated in the second running area is written into a second cache library as cache data for the second running area for subsequent use; wherein, the data already written into the first cache library and the data already written into the second cache library are set to be conditionally written into the central database, and the first running area and the second running area are set to share the data stored in the central database.
[0070] Specifically, this embodiment first establishes independent first and second cache libraries to provide temporary storage space for data generated in the first and second running regions, respectively. This distributed caching method reduces direct write operations to the central database, thereby reducing the database load. Furthermore, since data is first temporarily stored in its respective cache library, it avoids large-scale cross-regional data transfers and direct database writes, thus reducing the possibility of concurrency conflicts.
[0071] Secondly, by implementing a conditional write mechanism, this application embodiment also ensures that data in the cache library will only be written to the central database when specific conditions are met, which not only optimizes the efficiency and timing of data writing, but also further reduces the write pressure on the database.
[0072] Furthermore, this embodiment of the application achieves data sharing through a central database, while ensuring data consistency and integrity. Since data from each operating region ultimately converges in the central database, any region can access and use this data without complex cross-regional data transfer. This centralized storage and sharing mechanism simplifies the data management process, thereby improving data availability and reliability, and ultimately enhancing the technical stability of data management.
[0073] As an optional approach, after writing the data generated in the first running region into the first running region cache data for subsequent use in the first cache library, the method further includes:
[0074] S1-2, according to the writing time order, put the data written to the first cache into the first data queue in sequence;
[0075] S1-4: Write the data that has been placed in the first data queue into the central database in sequence according to the enqueue time, where the enqueue time is the time when the data was placed in the first data queue.
[0076] Optionally, in this embodiment, the first data queue may be used, but is not limited to, to store data that needs to be written to the cache of the central database. According to the writing time order of the cache data, the data that needs to be written to the central database is put into the queue in order, and according to the enqueue time, the data with the earlier enqueue time is written first.
[0077] The embodiments provided in this application achieve the goal of writing cached data to the central database in chronological order by placing the data to be written into the queue in the order of the cached time, and then writing the cached data to the central database according to the enqueue time. This achieves the technical effect of writing cached data to the central database in an orderly manner.
[0078] As an optional approach, after writing the data already placed in the first data queue into the central database sequentially according to their enqueue time, the method also includes:
[0079] S2-2, Based on the enqueue time, determine the latest data from the first data queue, where the latest data is located at the head of the first data queue;
[0080] S2-4: Write the latest data into the central database to obtain the first write result;
[0081] S2-6: If the first write result indicates that the latest data failed to be written to the central database, the latest data is placed at the tail of the first data queue.
[0082] Optionally, in this embodiment, the latest data may be, but is not limited to, the data at the head of the data queue. The data at the head of the data queue means that the data was enqueued earliest, and thus, according to the order of the queue, the data is written to the central database first.
[0083] It should be noted that the latest data is only the latest data in terms of the data queue, that is, the earliest data put into the queue, and does not mean the earliest cached data. In data management scenarios, not all cached data needs to be written to the central database. Instead, cached data that meets certain conditions is put into the data queue and written according to the order of the queue. The earliest cached data may not meet the writing conditions and therefore will not be written to the central database.
[0084] Optionally, in this embodiment, the first write result may be, but is not limited to, a successful write or a failed write. In the event of a failed write, the failed data is put back into the data queue, but at the end of the data queue.
[0085] It should be noted that during the process of writing cached data to the central database, network fluctuations, server fluctuations, and other factors may affect the data writing process, resulting in data writing failure. In order to reduce the impact of data writing failures caused by reasons other than the data itself, it is necessary to arrange a data rewriting process. However, in order to reduce the impact on the writing of other data, the data that needs to be rewritten is placed at the end of the data queue to wait for rewriting.
[0086] To further illustrate, optional examples include... Figure 5 As shown, assuming that there are cached data 504, cached data 506, and cached data 508 in data queue 502, if the write of cached data 504 fails when writing cached data 504 to the central database 510, then cached data 504 will be put back into data queue 502, but at the tail of the queue.
[0087] The embodiments provided in this application prioritize writing the data at the head of the queue to the central database and obtain the writing result. If the writing result shows failure, the data is arranged to re-enter the queue. Subsequently, when the data is back at the head of the queue, it is rewritten to the central database, thereby achieving the purpose of rewriting the failed data. This achieves the technical effect of reducing the impact of data writing failures caused by reasons other than the data itself.
[0088] As an optional approach, in the process of writing the data generated in the first running area into the first cache library for subsequent use, the method further includes at least one of the following:
[0089] S3-2, upon obtaining the first data generated in the first running area, the first data is placed into the second data queue according to the generation time order. The first data is new data generated by the online account in the first running area. The data in the second data queue is set to be written to the first cache library in the order of the queue.
[0090] S3-4, upon obtaining the second data generated in the first running area, the second data is placed at the head of the second data queue. The second data is the data when an online account in the first running area chooses to log out, and the queue order at the head of the queue is the queue order in which the data is processed first.
[0091] Optionally, in this embodiment, the first data is new data generated by an online account in the first operating area. It can be, but is not limited to, new data generated when a user uses an online account in the first area and performs operations other than logging out on that online account. The new data is then placed into the second data queue in the order of its generation, and the data in the queue is written into the first cache according to the second data queue.
[0092] Optionally, in this embodiment, the second data is the data when an account in the first operating area chooses to log out. It may be, but is not limited to, the data generated when a user chooses to log out of an account that is online in the first area. This data is placed at the head of the second data queue, that is, the data is written first.
[0093] It's important to note that data generated by user actions on online accounts is queued sequentially by generation time. This is because new data is continuously generated while the account is online. Even if a data write fails and fails to be written to the cache, subsequent new data can compensate for the data loss. However, data generated when a user logs out of the account means no new data is generated. If this data isn't promptly stored in the cache, it could lead to data loss. Since no new data is generated, it cannot be compensated for by other data, thus reducing the data integrity of data generated when logging out.
[0094] To further illustrate, optional examples include... Figure 6As shown, assume that user A generates data 602 through a non-logout operation of an online account, and user B generates data 604 through a logout operation of an online account. The accounts used by users A and B are located in the same operating area, and the generated data are added to a unified data queue 606. When data 602 is added to data queue 606, it is added to the tail of the queue, and when data 604 is added to data queue 606, it is added to the head of the queue.
[0095] By placing the data generated when a user logs out of their account at the head of the data queue through the embodiments provided in this application, the purpose of prioritizing the writing of data generated when a user logs out of their account is achieved, thereby ensuring the data integrity of the data generated when a user logs out of their account.
[0096] As an alternative approach, after placing the second data at the head of the second data queue, the method further includes:
[0097] S4-2, Write the second data into the first cache library to obtain the second write result;
[0098] S4-4, if the second write result indicates that the second data failed to be written to the first cache, the second data is placed at the head of the second data queue;
[0099] S4-6, if the second write result indicates that the second data was successfully written to the first cache library, determine that the account online in the first running area is in a logged-out state.
[0100] Optionally, in this embodiment, the second data may be, but is not limited to, data generated when a user performs a logout operation on an account. The generated data is written into a cache library to obtain the writing result. If the writing fails, the data is put back into the head of the second data queue. If the writing is successful, the account is confirmed to be in a logout state again.
[0101] It should be noted that since no new data is generated after a user logs out of their account, if the data at the time of login fails to be successfully cached in the cache library, there may be a problem of incomplete cached login data. In addition, in order to reduce the impact of network and server fluctuations on data writing, the data is put back into the queue. Furthermore, since no new data is generated after an account logs out, even if the login data writing fails, the login data is not placed at the end of the data queue, but at the head of the queue. Priority is given to ensuring the successful writing of login data, which further ensures the data integrity of the data generated by the logged-out account.
[0102] To further illustrate, optional examples include... Figure 7As shown, assuming that data 702 is data generated when a user logs out of their account, if the write operation fails when data 702 is written from data queue 704 to cache 706, then data 702 is placed back at the head of data queue 704 and the data is written again.
[0103] The embodiments provided in this application achieve the goal of prioritizing the rewriting of logout data by placing failed logout data back at the head of the data queue, thereby further ensuring the data integrity of data generated by the logout account.
[0104] As an optional approach, after writing the second data to the first cache and obtaining the second write result, the method further includes:
[0105] S5-2, if the second write result indicates that the second data failed to be written to the first cache library, and the cumulative number of failures is less than a preset threshold, the second data is placed at the head of the second data queue;
[0106] S5-4, if the second write result indicates that the second data failed to be written to the first cache library, and the cumulative number of failures is greater than or equal to a preset threshold, the second data is removed from the second data queue and recorded as an exception.
[0107] Optionally, in this embodiment, the cumulative number of failures may include, but is not limited to, the number of failures when writing the second data to the first cache library. If the cumulative number of failures is less than a preset threshold, the rewriting of the second data will continue. If the cumulative number of failures has reached the preset threshold, the writing of the second data will be terminated and the second data will be marked as abnormal data.
[0108] Optionally, the cumulative number of failures can be used, but is not limited to, to accumulate all write failures that occur when writing data, and the preset threshold can be used, but is not limited to, to limit the number of times all data that needs to be rewritten can be rewritten.
[0109] It should be noted that rewriting one piece of data will inevitably affect the writing of other data. If the number of rewrites is not limited, other data may fail to be written normally. At the same time, if a certain piece of data keeps failing to be written under the influence of no external factors, it may be because the data itself is abnormal and cannot be written normally. If the number of rewrites is not limited, the repeated rewriting of this data may prevent other data from being written normally, thus affecting the overall data writing.
[0110] By limiting the number of times failed data can be rewritten and marking data with a failure count reaching a threshold as abnormal data, the purpose of filtering abnormal data is achieved, thereby reducing the impact of abnormal data on the overall data writing.
[0111] As an alternative approach, the method also includes:
[0112] S6-2 uses an optimistic locking mechanism to conditionally write data already written to the first cache database and data already written to the second cache database into the central database.
[0113] Optionally, in this embodiment, optimistic locking can be, but is not limited to, a mechanism implemented in the database to solve concurrency control problems. When reading data, no lock other than optimistic locking is applied to the data. Instead, when updating data, it checks whether the data has been modified by other tasks or transactions during this period.
[0114] It should be noted that optimistic locking is suitable for scenarios with high-concurrency read and write operations, especially when data is read frequently but modified relatively infrequently. It avoids long lock wait times and improves the system's concurrency performance. At the same time, optimistic locking does not require additional locking, so it can also avoid deadlocks.
[0115] Optionally, optimistic locking can, but is not limited to, using version numbers as optimistic locking.
[0116] To illustrate further, assuming a version number field is used as an optimistic lock, when updating or writing data, a version number field is appended to the data. When the data is read, the version number is read along with it. When updating or writing data, if the version number of the updated or written data matches the version number of the currently read data, the update is successful and the version number is incremented by one; otherwise, the update or write fails.
[0117] Optionally, optimistic locking can, but is not limited to, using timestamps as optimistic locks.
[0118] To illustrate further, assuming a timestamp field is used as an optimistic lock, when updating or writing data, a timestamp field is appended to the data. When the data is read, the timestamp is read along with it. When updating or writing data, if the timestamp of the written data is later than the timestamp of the currently read data, the update is successful, and the timestamp is updated to the timestamp of the written data. Otherwise, the update or write fails.
[0119] Optionally, the first cache library and the second cache library may be cache libraries belonging to different regions but belonging to the same central database.
[0120] The embodiments provided in this application achieve the technical effect of preventing old data from overwriting new data by setting optimistic locking for the central database, thereby ensuring that the updated or written data is new data.
[0121] As an optional solution, an optimistic locking mechanism is used to conditionally write data already written to the first cache database and data already written to the second cache database into the central database, including:
[0122] S7-2, retrieve the third data that has been written from the first cache library to the central database, and the first version number carried by the third data;
[0123] S7-4, retrieve the fourth data that has been written to the second cache library, and the second version number carried by the fourth data;
[0124] S7-6, where the fourth data and the third data belong to the same account, and the first version number and the second version number are the same, the fourth data is allowed to be written to the central database.
[0125] S7-8: If the fourth data and the third data belong to the same account, but the first version number and the second version number are different, the fourth data is prohibited from being written to the central database.
[0126] Optionally, in this embodiment, the first version number and the second version number may be different, but are not limited to the first version number being greater than the second version number. When the first version number is equal to the second version number, the fourth data corresponding to the second version number is allowed to be written from the first cache library to the central database. If the first version number is greater than the second version number, the data corresponding to the second version number is prohibited from being written to the central database.
[0127] It should be noted that, within the same account's third and fourth data sets, the third data set represents data already written to the central database, with the corresponding version number being the first version number. The fourth data set represents data not yet written to the central database, with the corresponding version number being the second version number. When the first version number is greater than the second version number, it means that the third data set is newer than the fourth data set. In this case, it is necessary to prevent the older fourth data set from overwriting the newer third data set. Conversely, if the first version number is less than or equal to the second version number, it means that the fourth data set is newer than the third data set, and the fourth data set needs to be written to the central database to overwrite the third data set.
[0128] To further illustrate, optional examples include... Figure 8As shown, when the cache database 802 corresponding to the user's current account malfunctions, and the cache database 802 contains data 804 of the user's current account with a version number of 10, but the cache database 802 cannot continue to write data to the central database 806, the database corresponding to the user's current account is switched to the cache database 808. After a period of time, the cache database 808 writes data 810 of the user's current account to the central database. At this time, the version number of data 810 is 15. After a period of time, the cache database 802 resumes its writing function. Now, if it wants to write data 804 to the central database, it compares the version number of data 810 belonging to the same user account in the central database 806 with the version number of data 804. If it finds that the version number of data 810 is greater than the version number of data 804, it prevents data 804 from being written to the central database 806.
[0129] The embodiments provided in this application compare the version numbers of data in the central database with those in the cache database under the same account, thereby preventing outdated data from overwriting existing data in the central database. This achieves the technical effect of ensuring that the data written to the central database is the latest data compared to the existing data in the central database.
[0130] As an optional approach, after writing the data generated in the first running region into the first running region cache data for subsequent use in the first cache library, the method further includes:
[0131] S8-2, obtain the first write frequency of the first cache library;
[0132] S8-4, based on the first write frequency, sets the first cache library to write the data already written to the first cache library to the central database according to the second write frequency, wherein the second write frequency is less than the first write frequency.
[0133] Optionally, in this embodiment, the first write frequency may be, but is not limited to, the frequency at which data is retrieved from a user account and written to the first cache library, and the second write frequency is the frequency at which data is retrieved from the first cache library and written to the central database.
[0134] It should be noted that setting the second write frequency to be lower than the first write frequency can prevent the central database from retrieving data from the cache from a frequency higher than the frequency at which the cache retrieves data from user accounts, resulting in a lack of data in the cache that needs to be written to the central database, thus avoiding a waste of computing resources.
[0135] The embodiments provided in this application achieve the goal of setting the second write frequency to be lower than the first write frequency by obtaining the first write frequency, thereby avoiding the technical effect of wasting computing resources.
[0136] As an alternative approach, the method also includes:
[0137] S9-2, Obtain at least one first database of the first data management region configuration and at least one second database of the second data management region configuration;
[0138] S9-4, if the first operating area and the second operating area are operating areas within the first data management region, the first database is determined as the central database;
[0139] S9-6, where the first operating area and the second operating area are operating areas within the second data management region, the second database is designated as the central database.
[0140] Optionally, in this embodiment, the data management region may be, but is not limited to, a country or a continent. For example, the first data management region may be, but is not limited to, location S or continent A, and the second data management region may be, but is not limited to, location T or continent B.
[0141] Optionally, when the operating region is located in a certain data management region, the central database corresponding to the cache library existing in the operating region is the central database set up in the data management region where the operating region is located.
[0142] It should be noted that, in order to reduce the latency of long-distance data transmission and writing, data management regions and corresponding central databases are set up in different countries or continents. The central database corresponding to the cache library of the operating area located in the data management region is set as the central database of the data management region. This avoids the latency or even inability to write data caused by the distance between the user account's location and the actual central database. It reduces the data transmission distance and improves the efficiency of data transmission and writing.
[0143] The embodiments provided in this application achieve the goal of reducing data transmission distance by setting up central databases in different data management regions and setting the central database corresponding to the cache library of the running region as the central database of the data management region where the running region is located. This improves the technical effect of data transmission and writing.
[0144] According to one aspect of the embodiments of this application, another data management method is also provided. Optionally, as an optional implementation, the above data management method may include, but is not limited to, the following:
[0145] S10-2, in response to the retrieval request triggered by the first target data generated in the first running area, read the cached data that matches the first target data from the first cache library that caches data for the first running area for subsequent use;
[0146] S10-4, in response to the second acquisition request triggered by the second target data generated in the second running area, read the cached data that matches the second target data from the second cache library that caches data for the second running area for subsequent use;
[0147] S10-6, wherein the data already written to the first cache library and the data already written to the second cache library are set to be conditionally written to the central database, and the first running area and the second running area are set to share the data stored in the central database.
[0148] In an optional embodiment, the first operating area may be, but is not limited to, the area where the user is located when generating the data that needs to be obtained, and the data that needs to be obtained may be, but is not limited to, text data, image data, video data, game data, and other data that the user needs to obtain; the first cache library may be, but is not limited to, used to cache the data that the user needs to obtain when he / she is in the first area.
[0149] In an optional embodiment, the second running area may be, but is not limited to, the area where the user is located when generating the data that needs to be obtained, and the data that needs to be obtained may be, but is not limited to, text data, image data, video data, game data, and other data that the user needs to obtain; the second cache library may be, but is not limited to, used to cache the data that the user needs to obtain when he / she is in the second area.
[0150] In an optional embodiment, the cached data that is hit may be, but is not limited to, cached data that the user's account filters and finds from the cache library according to certain conditions. In this process, the cached data found must be cached data that fully meets the conditions and is completely consistent with the account's needs.
[0151] Through the embodiments provided in this application, when the user's account retrieves data from the cache library, the cached data in the cache library is hit, thereby achieving the purpose of transferring the hit cached data to the user's account. This achieves the technical effect of accurately transferring the data that the user's account needs to retrieve to the user's account.
[0152] As an optional approach, after reading the cached data that matches the first target data from a first cache library that caches data for the first running region in response to a retrieval request triggered by the first target data generated in the first running region, the method further includes:
[0153] If the first target data does not match any data already written in the first cache library, the data that matches the first target data is read from the central database.
[0154] It should be noted that since user account data is ultimately uploaded to the central database, and the cache library cannot permanently cache certain data, when a user account needs to retrieve certain data, if the data is not in the cache library, the cache library needs to retrieve and cache the data from the central database, and then the user account retrieves the data from the cache library.
[0155] Through the embodiments provided in this application, when a user's account does not find the required data when retrieving data from the cache library, the data is retrieved from the central database through the cache library, thereby achieving the goal of not needing to cache all data in the cache library, and thus realizing the technical effect of reducing the caching pressure of the cache library.
[0156] As an optional solution, for ease of understanding, we will use the above data management method as an example to illustrate the scenario of writing game data back to the database:
[0157] In online games centered around game battle servers, players' game data often needs to be written to a central database (DB) frequently. However, in the global architecture of online games, writing players' game data back to the central database often results in problems such as high latency, low bandwidth, high cost, and low stability due to the long write-back distance.
[0158] Optionally, in this embodiment, it is possible, but not limited to, splitting a single central database into multiple central databases, setting up corresponding central databases in different regions or continents, and setting up different operating regions in different areas of each region or continent where a corresponding central database is set up. In each operating region, a cache database (Redis) is set up to cache the data generated by user accounts located in that operating region into the cache database, and then write the data already cached into the cache database into the central database.
[0159] Further examples, such as Figure 9 As shown, the specific steps are as follows:
[0160] S902, new data is generated for the user's game account;
[0161] S904, If the data type generated by the user's game account is the data generated when the account is normally online, then execute S906; otherwise execute S908.
[0162] S906, place the data at the end of data queue A;
[0163] S908, place the data at the head of data queue A;
[0164] S910 will cache the data at the head of the data queue into the cache library according to the data queue;
[0165] S912, if the cached result is successful, then execute S914; otherwise, execute S916.
[0166] S914, put the data in the cache library into the tail of the data queue B according to the cache time;
[0167] S916, determine whether the data is generated when the user's game account is online normally. If yes, execute S918; otherwise, execute S920.
[0168] S918, put the data back to the end of data queue A;
[0169] S920, determine whether the number of times the data is re-cached is less than a preset threshold. If yes, execute S922; otherwise, execute S924.
[0170] S922, put the data back at the head of data queue A;
[0171] S924 marks the data as anomalous and discards the cache;
[0172] S926, according to the data queue B, write the data at the head of the queue into the central database.
[0173] Optionally, in this embodiment, to prevent the inability to upload user game data to the central database due to a failure of the current cache library, when the cache library fails to upload cached data to the central database, the cache library will be automatically switched to another cache library to cache the user account data that the failed cache library originally needed to cache. If the failed cache library recovers in the subsequent process, it can be automatically switched back to the original cache library, and the data in the original cache library belonging to the same account can be compared with the data already written to the central database.
[0174] To further illustrate, such as Figure 10 As shown, the specific steps are as follows:
[0175] S1002, cache the user's game account data a in cache library A;
[0176] S1004, write data a from cache library A to the central database;
[0177] S1006, determine whether the write was successful. If yes, execute S1008; otherwise, execute S1010.
[0178] S1008 returns a successful write result;
[0179] S1010, cache the user's game account data b in cache library B, and mark cache library A as faulty;
[0180] S1012, Write data b from cache library B into the central database;
[0181] S1014, determine whether cache library A has been restored. If yes, execute S1016; otherwise, execute S1018.
[0182] S1016, obtain the version numbers of data a and data b. If the version number of data a is less than the version number of data b, then execute S1020; otherwise, execute S1022.
[0183] S1018, Continue to cache subsequent data of the user's account in cache library B;
[0184] S1020, prohibit data a from being written to the central database;
[0185] S1022, Write data a into the central database.
[0186] Optionally, in this embodiment, the above data management method is also used in scenarios where a user's account reads data from a cache library:
[0187] Optional, such as Figure 11 As shown, the specific steps are as follows:
[0188] S1102, the user's account retrieves the required data from the cache;
[0189] If the acquisition is successful, proceed to S1106; otherwise, proceed to S1108.
[0190] S1106, transfers data to the user's account;
[0191] S1108, the cache library retrieves the required data from the central database;
[0192] S1110, the cache library will transfer the data obtained from the central database to the user's account.
[0193] Optionally, in this embodiment, when the user's account successfully retrieves the required data 'a' from the cache, specifically as follows: Figure 12 The steps also include:
[0194] S1202, retrieve the version number 1 of data a obtained from the cache library;
[0195] S1204, retrieve version number 2 of data b in the central database that belongs to the same account as data a;
[0196] S1206, If the version number 1 of data a is inconsistent with the version number 2 of data b, then execute S1208; otherwise execute S1210.
[0197] S1208, the cache library reads data b from the central database;
[0198] S1210, the cache library transfers data a to the user's account;
[0199] S1212, data b in the cache is transferred to the user's account.
[0200] Optionally, in this embodiment, Redis is introduced to cache hot data, reducing the number of DB reads. Simultaneously, the dbagent directly reads and writes to Redis, improving the speed and stability of data write-back. Redis handles data merging, further reducing DB writes. A data center is divided into multiple regions, each corresponding to a Redis cluster. A separate subscription process, syncsvr, is added to asynchronously write (including retries on failure) data from Redis to the DB. This logic is decoupled from the dbagent, avoiding excessive intrusion into the dbagent's code. (See attached...) Figure 13 As shown, in the lobby cluster of location A, there are zonesvr, router, lobby, tconnd, and dbagent. Among them, dbagent can interact with data centers in Southeast Asia. At the same time, the zonesvr of the lobby cluster in location A can transmit transoceanic business messages to dcenters in regions of other continents. In each region of each continent, there are redis, syncsvr, dbagent, decenter, dsagent, and DS. Redis writes data back to the data center through syncsvr. dbagent can read and write local cache data from redis. dbagent can also read data from the data center.
[0201] Optionally, in this embodiment, as shown in the appendix Figure 14As shown, in scenario one of dsagent, if dbagent does not find the data in Redis when retrieving data, dbagent reads the data from the database and then sends it back to dsagent. In scenario two of dsagent, if dbagent finds the data in Redis, dbagent first receives the data from Redis, then reads the version number from the database. If the version number is inconsistent with the one obtained from Redis, the data obtained from the database is then sent back to dsagent.
[0202] Optionally, in this embodiment, as shown in the appendix Figure 15 As shown, in the update scenario, dsagent first sends the update request and data to dbagent, then dbagent saves the data to Redis and returns a successful save result; syncsvr reads the data to be written back from Redis via tick and returns the result, then saves the returned result and data with version number to DB, then returns the new version number, and finally stores the new version number in Redis.
[0203] Optionally, in this embodiment, as shown in the appendix Figure 16 As shown, Redis contains idset-zset, sceneData-kv, and sceneversion-kv. ds-dbagent writes idset to idset-zset and then writes data to sceneData-kv. When the database write fails, syncsvr writes the id back to idset-zset. If the database read / write is successful, it writes the latest ver. idset-zset reads the id from idset through syncsvr, sceneData-kv reads the data from syncsvr, and sceneversion-kv reads the ver from syncsvr.
[0204] Optionally, in this embodiment, as shown in the appendix Figure 17As shown, when a player logs out, `dsagent` adds the player to the logout queue and simultaneously sends a save request to `dbagent` via the tick logout queue. `dbagent` saves the data to `redis`, sets the score of the inserted `zset id` to 0, and returns a successful save result. `syncsvr` then reads the offline player data from `redis` via the tick, saves the data with a version number to `DB`, returns the new version number, and stores the version number in `redis`. Then, the player is removed from the logout queue. In another logout scenario, when a player logs out, `dsagent` adds the player to the logout queue and simultaneously sends a save request to `dbagent` via the tick logout queue. `dbagent` saves the data to `redis`, sets the score of the inserted `zset id` to 0, and returns a failed save result. After backtracking, the tick logout queue resends the save request, which fails again. After multiple failures, the player is removed from the queue.
[0205] Optionally, in this embodiment, as shown in the appendix Figure 18 As shown, to prevent players from logging out and then logging back in before the Redis cached data has been written back to the database, and especially if the re-login DS is not in the same region as the previous login DS, which could result in two Redis caches of the same data, leading to concurrent database writes and data conflicts, a login lock mechanism can be used to solve this problem. This mechanism ensures that players log back into the original region within a certain period of time, ensuring the reuse of the original Redis cache and thus avoiding the occurrence of multiple cached data.
[0206] Optionally, in this embodiment, as shown in the appendix Figure 19As shown, to prevent concurrent read / write operations on the database from multiple cached data, when modifying data, in addition to writing the data, a data version number must also be included. The database will compare the version number requested for writing with the version number of the record in the database. If the version number of the record is equal to the requested version number, it means that the write can proceed; otherwise, it means that the data has been modified by other caches, indicating a write conflict, and the write request will fail. This effectively avoids old data overwriting new data. For example, when the player is continuously online, the data is continuously saved to Redis in region1, and then written back to the database via region1-syncsvr. If the write-back fails and continues for 3 minutes, the player logs into region2 to retrieve scene data. After a period of time, the failure in region1 is repaired, and writing can continue, so the data is written to the database. When the player is in region2 and continuously online, the data is continuously saved to Redis. region2-syncsvr retrieves the data from Redis and writes it to the database for the first time. If the version number of the data being written conflicts with the version number of the data in the database, the player is kicked offline.
[0207] The embodiments provided in this application split the central DB into multiple data centers and introduce additional caching to achieve delayed writing of scene data through cache reading and merging. This ensures that the data is stored in real time and reduces network transmission volume through cache reading and merged writing, thereby achieving the technical effect of reducing network storage bandwidth.
[0208] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0209] According to another aspect of the embodiments of this application, a data management apparatus for implementing the above-described data management method is also provided. For example... Figure 20 As shown, the device includes:
[0210] The first writing unit 2002 is used to write the data generated in the first running area into the first cache library for subsequent use as cache data in the first running area.
[0211] The second writing unit 2004 is used to write the data generated by the second running area into the second cache library as cache data of the second running area for subsequent use.
[0212] The first setting unit 2006 is used to set the data already written to the first cache library and the data already written to the second cache library as conditions for writing to the central database.
[0213] The second setting unit 2008 is used to set the first running area and the second running area to share the data stored in the central database.
[0214] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0215] As an optional solution, the first writing unit 2002 includes: a first sorting module, used to, after writing the data generated in the first running area into the first cache library for subsequent use, sequentially put the data written into the first cache library into the first data queue according to the writing time order; and a first writing module, used to sequentially write the data already put into the first data queue into the central database according to the enqueue time, wherein the enqueue time is the time when the data is put into the first data queue.
[0216] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0217] As an optional solution, the first write module includes: a first determining submodule, used to determine the latest data from the first data queue according to the enqueue time, wherein the latest data is located at the head of the first data queue; a first writing submodule, used to write the latest data into the central database to obtain a first write result; and a first sorting submodule, used to place the latest data into the tail of the first data queue if the first write result indicates that the latest data failed to be written to the central database.
[0218] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0219] As an optional solution, the first writing unit 2002 includes: a second sorting module, used to place the first data into a second data queue according to the generation time order when the first data generated in the first running area is obtained, wherein the first data is new data generated by an online account in the first running area, and the data in the second data queue is set to be written to the first cache library in the order of the queue; and a third sorting module, used to place the second data into the head of the second data queue when the second data generated in the first running area is obtained, wherein the second data is the data when an online account in the first running area chooses to log out, and the queue order at the head of the queue is the queue order in which the data is processed first.
[0220] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0221] As an optional solution, the third sorting module includes: a second writing submodule, used to write the second data to the first cache after placing the second data at the head of the second data queue, to obtain a second writing result; a second sorting submodule, used to place the second data at the head of the second data queue if the second writing result indicates that the second data failed to be written to the first cache; and a determination submodule, used to determine that the account online in the first running area is in a logged-out state if the second writing result indicates that the second data was successfully written to the first cache.
[0222] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0223] As an optional solution, the second write submodule includes: a sorting subunit, used to place the second data at the head of the second data queue after writing the second data to the first cache and obtaining the second write result, if the second write result indicates that the second data failed to write to the first cache and the cumulative number of failures is less than a preset threshold; and a removal subunit, used to remove the second data from the second data queue and record it as an exception if the second write result indicates that the second data failed to write to the first cache and the cumulative number of failures is greater than or equal to a preset threshold.
[0224] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0225] As an optional approach, the first data management device further includes: a third writing unit, used to conditionally write data already written to the first cache and data already written to the second cache into the central database using an optimistic locking mechanism.
[0226] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0227] As an optional approach, the third writing unit includes: a first acquisition module, used to acquire third data that has been written from the first cache to the central database, and the first version number carried by the third data; a second acquisition module, used to acquire fourth data that has been written to the second cache, and the second version number carried by the fourth data; and a prohibition module, used to prohibit the writing of the fourth data to the central database when the fourth data and the third data belong to the same account, but the first version number and the second version number are different.
[0228] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0229] As an optional approach, the first writing unit 2002 further includes: a third acquisition module, used to acquire the first writing frequency of the first cache library after writing the data generated in the first running area into the first cache library for subsequent use; and a second writing module, used to set the first cache library to conditionally write the data already written to the first cache library into the central database according to the second writing frequency based on the first writing frequency, wherein the second writing frequency is less than the first writing frequency.
[0230] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0231] As an optional approach, the first data management device further includes: an acquisition unit, configured to acquire at least one first database configured in a first data management region and at least one second database configured in a second data management region; a first determination unit, configured to determine the first database as a central database when the first operating region and the second operating region are operating regions within the first data management region; and a second determination unit, configured to determine the second database as a central database when the first operating region and the second operating region are operating regions within the second data management region.
[0232] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0233] According to another aspect of the embodiments of this application, another data management device is also provided, such as Figure 21 The following are included:
[0234] The first reading unit 2102 is used to read cached data that matches the first target data from the first cache library that caches data for the first running area for subsequent use in response to a request triggered by the first target data generated in the first running area.
[0235] The second reading unit 2104 is used to read cached data that matches the second target data from the second cache library that caches data for the second running area for subsequent use in response to a second acquisition request triggered by the second target data generated in the second running area.
[0236] The third setting unit 2106 is used to set the data already written to the first cache library and the data already written to the second cache library as conditions for writing to the central database.
[0237] The fourth setting unit 2108 is used to set the first running area and the second running area to share the data stored in the central database.
[0238] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0239] As an optional approach, the first reading unit 2102 includes: a first reading module, configured to, in response to a request triggered by first target data generated in the first running area, read cached data that matches the first target data from a first cache library that caches data for the first running area for subsequent use, and if the first target data does not match data already written in the first cache library, read data that matches the first target data from a central database.
[0240] For specific implementation examples, please refer to the examples shown in the data management method above. These examples will not be repeated here.
[0241] According to another aspect of the embodiments of this application, an electronic device for implementing the above-described data management method is also provided. This electronic device may, but is not limited to, […]. Figure 1 The user equipment 102 or server 112 shown in the figure, in this embodiment, is taken as an example of an electronic device, namely user equipment 102. Further, as shown in the figure... Figure 22 As shown, the electronic device includes a memory 2202 and a processor 2204. The memory 2202 stores a computer program, and the processor 2204 is configured to execute the steps of any of the above method embodiments through the computer program.
[0242] In an optional embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
[0243] In an optional embodiment, the processor described above may be configured to perform the following steps via a computer program:
[0244] S1, write the data generated in the first running area into the first running area cache data for subsequent use in the first cache library;
[0245] S2, write the data generated in the second running area into the second running area cache data for later use in the second cache library;
[0246] S3, wherein the data already written to the first cache library and the data already written to the second cache library are set to be conditionally written to the central database, and the first running area and the second running area are set to share the data stored in the central database.
[0247] Alternatively, as those skilled in the art will understand, Figure 22 The structure shown is for illustrative purposes only. Figure 22 This does not limit the structure of the aforementioned electronic devices. For example, the electronic device may also include components that are more... Figure 22The more or fewer components shown (such as network interfaces, etc.), or having the same Figure 22 The different configurations shown.
[0248] The memory 2202 can be used to store software programs and modules, such as the program instructions / modules corresponding to the data management method and apparatus in this embodiment. The processor 2204 executes various functional applications and data processing by running the software programs and modules stored in the memory 2202, thereby realizing the aforementioned data management method. The memory 2202 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 2202 may further include memory remotely located relative to the processor 2204, and these remote memories can be connected to electronic devices via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Specifically, the memory 2202 may be used, but is not limited to, to store information such as a first operating area, a second operating area, a first cache library, a second cache library, and a central database. As an example, such as... Figure 22 As shown, the memory 2202 may include, but is not limited to, the first write unit 2002, the second write unit 2004, the first setting unit 2006, and the second setting unit 2008 from the data management device, and the first read unit 2102, the second read unit 2104, the third setting unit 2106, and the fourth setting unit 2108 from another data management device. Furthermore, it may include, but is not limited to, other module units from the data management device, which will not be elaborated upon in this example.
[0249] Optionally, the transmission device 2206 described above is used to receive or send data via a network. Specific examples of the network described above may include wired networks and wireless networks. In one example, the transmission device 1506 includes a Network Interface Controller (NIC), which can be connected to other network devices and routers via a network cable to communicate with the Internet or a local area network. In one example, the transmission device 2206 is a radio frequency (RF) module, used for wireless communication with the Internet.
[0250] In addition, the aforementioned electronic device also includes: a display 2208 for displaying information such as the storage of the first operating area, the second operating area, the first cache library, the second cache library, and the central database; and a connection bus 2210 for connecting the various module components in the aforementioned electronic device.
[0251] In other embodiments, the aforementioned user equipment or server can be a node in a distributed system, wherein the distributed system can be a blockchain system, which is a distributed system formed by connecting multiple nodes through network communication. The nodes can form a peer-to-peer network, and any form of computing device, such as a server, user equipment, or other electronic device, can become a node in the blockchain system by joining this peer-to-peer network.
[0252] According to one aspect of this application, a computer program product is provided, comprising a computer program / instructions containing program code for performing the methods shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit, it performs various functions provided in embodiments of this application.
[0253] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0254] It should be noted that the computer system of the electronic device is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0255] A computer system includes a Central Processing Unit (CPU), which performs various appropriate actions and processes based on programs stored in Read-Only Memory (ROM) or loaded from RAM. ROM also stores various programs and data required for system operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output interfaces (I / O interfaces) are also connected to the bus.
[0256] The following components are connected to the input / output interface: input sections including keyboards, mice, etc.; output sections including cathode ray tubes (CRTs), liquid crystal displays (LCDs), and speakers; storage sections including hard drives; and communication sections including network interface cards such as LAN cards and modems. The communication section performs communication processing via a network such as the Internet. Drives are also connected to the input / output interface as needed. Removable media, such as disks, optical discs, magneto-optical discs, semiconductor memories, etc., are installed on the drive as needed so that computer programs read from them can be installed into the storage section as required.
[0257] Specifically, according to embodiments of this application, the processes described in the various method flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit, it performs various functions defined in the system of this application.
[0258] According to one aspect of this application, a computer-readable storage medium is provided, wherein a processor of a computer device reads computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the methods provided in the various alternative implementations described above.
[0259] In an optional embodiment, the computer-readable storage medium described above may be configured to store a computer program for performing the following steps:
[0260] S1, write the data generated in the first running area into the first running area cache data for subsequent use in the first cache library;
[0261] S2, write the data generated in the second running area into the second running area cache data for later use in the second cache library;
[0262] S3, wherein the data already written to the first cache library and the data already written to the second cache library are set to be conditionally written to the central database, and the first running area and the second running area are set to share the data stored in the central database.
[0263] Optionally, in embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0264] In optional embodiments, those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware of an electronic device. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0265] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0266] If the integrated units in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in the aforementioned computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.
[0267] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0268] In the several embodiments provided in this application, it should be understood that the disclosed user equipment can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.
[0269] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0270] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0271] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A data management method, characterized in that, include: The data generated in the first running area is written into the first cache library as cache data for the first running area for subsequent use; The data generated in the second running area is written into the second cache library as cache data for the second running area for subsequent use; The data already written to the first cache library and the data already written to the second cache library are set to be conditionally written to the central database, and the first running area and the second running area are set to share the data stored in the central database.
2. The method according to claim 1, characterized in that, After writing the data generated in the first running region into the first cache library for subsequent use in the first running region cache, the method further includes: According to the writing time order, the data written to the first cache library is sequentially placed into the first data queue; The data already placed in the first data queue is written to the central database sequentially according to the enqueue time, wherein the enqueue time is the time when the data is placed in the first data queue.
3. The method according to claim 2, characterized in that, In the process of writing the data already placed in the first data queue into the central database sequentially according to the enqueue time, the method further includes: According to the enqueue time, the latest data is determined from the first data queue, wherein the latest data is located at the head of the first data queue; The latest data is written into the central database to obtain the first write result; If the first write result indicates that the latest data failed to be written to the central database, the latest data is placed at the tail of the first data queue.
4. The method according to claim 1, characterized in that, In the process of writing the data generated in the first running region into the first cache library as cache data for subsequent use in the first running region, the method further includes at least one of the following: Upon obtaining the first data generated in the first operating area, the first data is placed into the second data queue according to the generation time order. The first data is new data generated by the online account in the first operating area. The data in the second data queue is set to be written into the first cache library in the order of the queue. Upon obtaining the second data generated by the first operating area, the second data is placed at the head of the second data queue, wherein the second data is the data of an online account in the first operating area when it chooses to log out, and the queue order at the head of the queue is the queue order in which the data is processed first.
5. The method according to claim 4, characterized in that, After placing the second data at the head of the second data queue, the method further includes: Write the second data into the first cache library to obtain the second write result; If the second write result indicates that the second data failed to be written to the first cache library, the second data is placed at the head of the second data queue; If the second write result indicates that the second data was successfully written to the first cache library, it is determined that the account online in the first running area is in a logged-out state.
6. The method according to claim 5, characterized in that, After writing the second data into the first cache library and obtaining the second write result, the method further includes: If the second write result indicates that the second data failed to be written to the first cache library, and the cumulative number of failures is less than a preset threshold, the second data is placed at the head of the second data queue. If the second write result indicates that the second data failed to be written to the first cache library, and the cumulative number of failures is greater than or equal to the preset threshold, the second data is removed from the second data queue and recorded as an exception.
7. The method according to claim 1, characterized in that, The method further includes: An optimistic locking mechanism is used to conditionally write the data already written to the first cache database and the data already written to the second cache database into the central database.
8. The method according to claim 7, characterized in that, The optimistic locking mechanism is used to conditionally write data already written to the first cache database and data already written to the second cache database into the central database, including: Obtain the third data that has been written from the first cache library to the central database, and the first version number carried by the third data; Obtain the fourth data that has been written to the second cache library, and the second version number carried by the fourth data; If the fourth data and the third data belong to the same account, and the first version number and the second version number are the same, then the fourth data is allowed to be written into the central database. If the fourth data and the third data belong to the same account, but the first version number and the second version number are different, then writing the fourth data into the central database is prohibited.
9. The method according to any one of claims 1 to 8, characterized in that, After writing the data generated in the first running region into the first cache library for subsequent use in the first running region cache, the method further includes: Obtain the first write frequency of the first cache library; Based on the first write frequency, the first cache library is configured to write data already written to the first cache library to the central database at a second write frequency, wherein the second write frequency is less than the first write frequency.
10. The method according to any one of claims 1 to 8, characterized in that, The method further includes: Obtain at least one first database of the first data management region configuration and at least one second database of the second data management region configuration; If the first operating area and the second operating area are operating areas within the first data management region, the first database is determined as the central database; If the first operating region and the second operating region are operating regions within the second data management region, then the second database is determined as the central database.
11. A data management method, characterized in that, include: In response to a request triggered by the first target data generated in the first running region, cached data that matches the first target data is read from the first cache library that caches data for the first running region for subsequent use; In response to a second acquisition request triggered by second target data generated in the second running region, cached data that matches the second target data is read from a second cache library that caches data for the second running region for subsequent use; The data already written to the first cache library and the data already written to the second cache library are set to be conditionally written to the central database, and the first running area and the second running area are set to share the data stored in the central database.
12. The method according to claim 11, characterized in that, After reading cached data matching the first target data from a first cache library that caches data for the first running region for subsequent use, in response to a retrieval request triggered by the first target data generated in the first running region, the method further includes: If the first target data does not match any data already written in the first cache library, the data that matches the first target data is read from the central database.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program is executed by an electronic device to perform the method according to any one of claims 1 to 12.
14. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method described in any one of claims 1 to 12.
15. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 12 through the computer program.