Application data caching method, data access method and electronic device
By creating real-time changeable memory service connection information in the configuration file, dynamically adjusting the mapping relationship between the database table and the memory server, the problem of low efficiency of data splitting and memory expansion in the existing technology is solved, and no service stop is achieved Efficient splitting and scaling.
Patent Information
- Application Number
- CN202210580977.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2042-05-25
AI Technical Summary
The prior art requires the service to be stopped before the data is split and memory expansion is required, resulting in low efficiency.
By creating memory service connection information that can be changed in real time and takes effect in real time in the configuration file, indicating the mapping relationship between the database table and the memory server, dynamically adjusting data cache and access, avoiding solidified code relationships.
It realizes data splitting and memory expansion without stopping services, improves efficiency, and improves system maintenance work efficiency and business availability.
Smart Images

Figure CN114817335B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a data caching method, a data access method and an electronic device for an application. Background Art
[0002] With the development of electronic devices' intelligence and the increase of functions they can achieve, the operating systems of electronic devices are becoming more and more complex, and the number of applications carried by electronic devices is increasing. Electronic devices frequently apply for and release memory during operation, that is, frequently cache data and access data. When accessing data, if the cached data does not exist in the memory, the data in the hard disk (memory cache server) is accessed.
[0003] The common technique for accessing a memory cache server is to create a connection relationship between the data to be accessed and the memory cache server. This relationship is implemented through code, so when the program is running, this relationship is fixed.
[0004] However, in the current common solution, for scenarios where data needs to be split and memory needs to be expanded, the split and expansion can only be achieved by changing the code. Therefore, the split and expansion process requires stopping the service, resulting in low efficiency of split and expansion. Summary of the invention
[0005] The present application provides a data caching method, a data access method and an electronic device for an application program, which are used to solve the scenario where data needs to be split and memory needs to be expanded. In the current common solution, the splitting and expansion can only be achieved by changing the code. Therefore, the splitting and expansion process requires stopping the service to proceed, resulting in the problem of low efficiency of the splitting and expansion.
[0006] In a first aspect, this embodiment provides a data caching method for an application program, comprising:
[0007] Creating a database table of an application and memory service connection information of a memory server in a configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0008] The memory service connection information in the configuration file is called to cache the database table to the memory server having a mapping relationship with the database table.
[0009] In a second aspect, this embodiment provides a data access method for an application, comprising: obtaining a user data access request, wherein the user data access request carries an identifier of a database table;
[0010] Retrieving the memory service connection information corresponding to the identifier of the database table from the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information indicates a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0011] The memory server having a mapping relationship with the database table is accessed according to the memory service connection information.
[0012] In a third aspect, this embodiment provides an electronic device, including:
[0013] A memory service creation unit, configured to create memory service connection information between a database table of an application and a memory server in a configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0014] A data cache unit is used to call the memory service connection information in the configuration file to cache the database table to the memory server having a mapping relationship with the database table.
[0015] In a third aspect, this embodiment provides an electronic device, including:
[0016] A request acquisition unit, used to acquire a user data access request, wherein the user data access request carries an identifier of a database table;
[0017] A connection retrieving unit, used to retrieve the memory service connection information corresponding to the identifier of the database table from a configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0018] A data access unit is used to access the memory server having a mapping relationship with the database table according to the memory service connection information.
[0019] The embodiments of the present application provide a data caching method, a data access method, and an electronic device for an application. Memory service connection information is created in a configuration file, and the memory service connection information is used to indicate a mapping relationship between a database table and a memory server, and the database table has a mapping relationship with at least one memory server. The memory service connection information in the configuration file is called to cache the database table to a memory server that has a mapping relationship with the database table. When accessing application data, the memory service connection information is called to access the memory server that has a mapping relationship with the database table. The technical solution of the present application uses a configuration file to create memory service connection information. Since the configuration file is a file that can be changed and takes effect in real time, there is no need to stop the service when splitting data and expanding memory, thereby improving the efficiency of splitting data and expanding memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0021] Figure 1 A schematic diagram of an implementation environment according to an exemplary embodiment is shown in FIG.
[0022] Figure 2 A block diagram of a device 200 according to an exemplary embodiment is exemplarily shown in FIG.
[0023] Figure 3 A data access flow chart according to an exemplary embodiment is exemplarily shown in FIG.
[0024] Figure 4 A flowchart of a method for caching data for an application program according to an exemplary embodiment is exemplarily shown in FIG.
[0025] Figure 5 The configuration file structure diagram provided by the embodiment of the present application is exemplarily shown in FIG.
[0026] Figure 6 The flowchart of the configuration file loading process provided by the embodiment of the present application is exemplarily shown in FIG.
[0027] Figure 7 The data splitting process flow chart provided by the embodiment of the present application is exemplarily shown in FIG.
[0028] Figure 8 The schematic diagram of the principle of obtaining memory service connection information provided in the embodiment of the present application is exemplarily shown in FIG.
[0029] Fig. 9 A flowchart of a data access method for an application provided by an embodiment of the present application is exemplarily shown in FIG.
[0030] Fig.10 A flowchart of a process of simultaneously performing data caching and data access provided by an embodiment of the present application is exemplarily shown in FIG.
[0031] Fig.11 A schematic diagram of the structure of an electronic device for data caching provided in an embodiment of the present application is exemplarily shown in FIG.
[0032] Fig.12 A structural diagram of an electronic device for data access provided in an embodiment of the present application is exemplarily shown in FIG.
[0033] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0034] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0035] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.
[0036] The terms "including" and "having" and any variations thereof are intended to cover but not exclude inclusion, for example, a product or device comprising a series of components is not necessarily limited to those components explicitly listed, but may include other components not explicitly listed or inherent to such products or devices. The term "module" or "component" as used in this application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with the element.
[0037] Figure 1 1 is a schematic diagram of an implementation environment according to the present invention. The implementation environment includes: a smart device 110 and a server 120.
[0038] The association method between the smart device 110 and the server 120 includes the network association method and / or protocol of the hardware, and the data association method between the two. After the smart device 110 receives the data provided by the server 120, the data can be cached.
[0039] Figure 2 is a block diagram of a device 200 according to an exemplary embodiment. For example, the device 200 may be Figure 1 The smart device 110 in the implementation environment shown. The smart device 110 may be, for example, various smart home devices, such as a smart TV, a smart TV set-top box, a smart air conditioner, and a smart camera, etc. The smart device may also be a mobile terminal, such as a smart phone, a tablet computer, etc.
[0040] Reference Figure 2 , the device 200 may include one or more of the following components: a processing component 202 , a memory 204 , a power component 206 , a multimedia component 208 , an audio component 210 , a sensor component 214 , and a communication component 216 .
[0041] The processing component 202 generally controls the overall operation of the device 200, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 202 may include one or more processors 218 to execute instructions to perform all or part of the steps of the method described below. In addition, the processing component 202 may include one or more modules to facilitate the interaction between the processing component 202 and other components. For example, the processing component 202 may include a multimedia module to facilitate the interaction between the multimedia component 208 and the processing component 202.
[0042] The memory 204 is configured to store various types of data to support operations on the device 200. Examples of such data include instructions for any application or method operating on the device 200. The memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable red-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The memory 204 also stores one or more modules, which are configured to be executed by the one or more processors 218 to complete the following: Figure 3 , Figure 6 , Fig. 9 All or part of the steps in any of the methods shown.
[0043] The power supply component 206 provides power to the various components of the device 200. The power supply component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 200.
[0044] The multimedia component 208 includes a screen that provides an output interface between the device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel. If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. The screen may also include an organic light emitting display (OLED).
[0045] The audio component 210 is configured to output and / or input audio signals. For example, the audio component 210 includes a microphone (MIC), which is configured to receive external audio signals when the device 200 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode. The received audio signal can be further stored in the memory 204 or sent via the communication component 216. In some embodiments, the audio component 210 also includes a speaker for outputting audio signals.
[0046] The sensor assembly 214 includes one or more sensors for providing various aspects of status evaluation for the device 200. For example, the sensor assembly 214 can detect the open / closed state of the device 200, the relative positioning of the components, and the sensor assembly 214 can also detect the position change of the device 200 or a component of the device 200 and the temperature change of the device 200. In some embodiments, the sensor assembly 214 can also include a magnetic sensor, a pressure sensor or a temperature sensor.
[0047] The communication component 216 is configured to facilitate wired or wireless communication between the device 200 and other devices. The device 200 can access a wireless network based on a communication standard, such as WiFi (WIreless-Fidelity). In an exemplary embodiment, the communication component 216 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 216 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth technology and other technologies.
[0048] In an exemplary embodiment, the device 200 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors, digital signal processing devices, programmable logic devices, field programmable gate arrays, controllers, microcontrollers, microprocessors or other electronic components to perform the following method.
[0049] Memory cache technology is a general solution to improve application performance. The present invention is limited to the scenario where the memory cache data is also stored in the hard disk database (memory server). Figure 3In the data access flow chart shown, in this scenario, the user requests to first access the cache data in the memory. If the cache data does not exist in the memory, the database data in the hard disk is accessed. In some embodiments, when the memory cache needs to be stored on different servers, multiple sets of fixed memory service connections and database connections need to be created. When accessing the memory cache, a fixed correspondence between the accessed database table and the memory server usage code needs to be established.
[0050] For example, a memory service connection is limited to accessing fixed database tables, and the access relationship is solidified in the code during the code development phase. If you need to split the database table (for example, a memory server stores data from 10 database tables, and the server has a maximum available memory of 64G. When the total amount of cached data is greater than 64G, if you want to store more data in the memory server, you need to split part of the 10 tables to another memory server), you need to change the code and add a new set of memory service connection configurations, that is, add code to specify access to some data tables to the new memory server. This means that if you want to split data and expand memory, you need to stop the service before you can proceed, and the efficiency of splitting data and expanding memory is low.
[0051] In order to solve the problems of the above embodiments, the present application provides a data caching method for an application program. Figure 4 The flowchart of a data caching method for an application program according to an exemplary embodiment is shown. The applicable scope and execution subject of the data caching method are, for example, Figure 1 The smart device 110 of the implementation environment is shown. Figure 3 As shown, the data caching method may include the following steps.
[0052] In step S101, the database table of the application and the memory service connection information of the memory server are created in the configuration file. The configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate the mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers.
[0053] The parsing results loaded into the memory by the application development framework are the specific contents of each configuration item contained in the configuration file. Specifically, the configuration items in the configuration file can be environment variables related to the application development framework or environment variables related to the application. In addition, in order to facilitate the application to access the parsing results in the memory, a reading interface for the application to read the parsing results loaded in the memory is also provided in the application development framework.
[0054] In this specific embodiment, the Hero framework is taken as an example for explanation. For ease of understanding, the Hero framework in the present invention is briefly introduced: the Hero framework is a high-performance development framework proposed by the inventor, and the code therein can be compiled using the Go language. Since the Go language is specially optimized for the programming of multi-processor system applications, programs compiled using the Go language have many advantages such as faster execution speed, greater security, and support for parallel processes.
[0055] In some embodiments, a configuration file template library can be pre-set, and the configuration file template library contains multiple configuration items and format specifications of each configuration item; at least one configuration item is selected from the configuration file template library, and the corresponding project content is set for it according to the format specification of the selected configuration item. Specifically, the configuration file template library can be provided by other tool chains (such as application compilation software, etc.) in the present invention. For example, when a developer creates an application through a specific application compilation software, the application compilation software automatically generates a configuration file template for the application according to the pre-stored configuration file template library. Among them, the application compilation software can be various types of software such as Go language compilation software and VC compilation software. The configuration file template automatically generated by the application compilation software contains multiple configuration items, and the developer only needs to select several configuration items from them and set the corresponding project content for them according to the format specification of the selected configuration items.
[0056] The configuration items included in the configuration file can be either environment variables related to the Hero framework or environment variables related to the game application. For example, the environment variables related to the Hero framework include: service loading path, Go language path (also called GoPass), etc. The environment variables related to the game application include: information about the dynamic link library or database that the game application needs to call during operation, etc., where the database information includes the database port, database username and password, etc. In addition, developers can also flexibly configure a variety of other configuration items.
[0057] Each configuration item in the configuration file can be stored in the form of Key-Value, the project name of the configuration item is represented by Key, and the specific project content of the configuration item is represented by Value. The Key-Value storage method can save storage space and improve query efficiency. In this embodiment, the configuration file is written in YAML language. In other embodiments of the present invention, the configuration file can also be written in other languages such as XML and JS.
[0058] like Figure 5As shown in the configuration file diagram, in the configuration file of the embodiment of the present invention, the mapped key is the database table, and the value is the memory service connection information. After the database table and the memory service connection information establish a mapping relationship, the data is cached to the corresponding memory server using the memory service connection information with the mapping relationship.
[0059] For example, the redis configuration file (configuration format) is as follows:
[0060] Default(host: 0.0.0.000; port: 123; password: 123);
[0061] redis001(host: 0.0.0.010; port: 123; password: 123; tables: [table_1, table_2]);
[0062] redis002 (host: 0.0.0.012; port: 123; password: 123; tables: [table_3, table_4]).
[0063] Among them, default indicates the default memory server. host indicates the host ip (Internet Protocol Address), port indicates the port, and passport indicates the verification password. redis001 indicates the memory server numbered 1. redis002 indicates the memory server numbered 2. tables indicates the database tables that establish a mapping relationship with the memory server.
[0064] The application sets the mapping relationship between the database table and the memory service connection information according to the tables configuration under each connection configuration. The settings are shown in Table 1:
[0065] table_1 redis001 table_2 redis001 table_3 redis002 table_4 redis002
[0066] Table 1 Example of the mapping relationship between database tables and memory servers
[0067] The above configuration indicates that table_1 and table-2 are mapped to redis001, and table_3 and table_4 are mapped to redis002.
[0068] When you need to create a separate memory cache service for table_5, you only need to add the following configuration after creating the memory cache service. After adding the configuration, restart the application and it will take effect automatically.
[0069] redis003(host:0.0.0.013port:123password:123;tables:[table_5]).
[0070] The changed mapping relationship is shown in Table 2:
[0071] table_1 redis001 table_2 redis001 table_3 redis002 table_4 redis002 table_5 redis003
[0072] Table 2 Example of the mapping relationship between database tables and memory servers
[0073] When you need to modify table_1 to the same memory cache service as table_5, you only need to delete table_1 under redis001 and add table_5 configuration to redis003. The final configuration format is as follows:
[0074] default(host: 0.0.0.000; port: 123; password: 123);
[0075] redis001(host: 0.0.0.010; port: 123; password: 123; tables: [table_2]);
[0076] redis002(host: 0.0.0.012; port: 123; password: 123; tables: [table_3, table_4]);
[0077] redis003 (host: 0.0.0.012; port: 123; password: 123; tables: [table_1, table_5]).
[0078] The changed mapping relationship is shown in Table 3:
[0079] table_1 redis003 table_2 redis001 table_3 redis002 table_4 redis002 table_5 redis003
[0080] The present invention decouples the access to the data table from the connection to the memory server by adding the association configuration between the database table and the memory service connection information, and changes the fixed relationship into a flexible configuration.
[0081] In some implementations, the specific process of loading the configuration file is as follows: Figure 6 The flowchart shown includes the following steps:
[0082] S201: Receive a configuration file loading instruction. In an embodiment of the present invention, loading a configuration file can be divided into dynamically loading an export directory, dynamically updating a function switch, and configuration parameters, etc. Among them, the export directory is a file directory that provides access services to the outside world. Function switches include dynamic switches for access audit features, dynamic switches for memory optimization features, etc. Parameters refer to various configuration items contained in a configuration file. In an embodiment of the present invention, the specific process of dynamically loading an export directory is introduced, and the operation process of dynamically updating a function switch and configuration parameters is similar to the process of dynamically loading an export directory, which will not be repeated here.
[0083] The loading instruction is used to indicate what operation is performed on the configuration file. According to different operation requirements, the loading instruction can be divided into different types, such as updating the configuration file, adding the configuration file, and other operations. In the specific implementation, the user can realize dynamic loading by manually editing the configuration information on the relevant interface; or by using the command line. When using the command line or interface to load dynamically, it encapsulates the function of modifying the configuration file, so it can be operated directly.
[0084] S202: Load corresponding configuration information according to the directory ID carried in the loading instruction.
[0085] The directory ID is the identification information of the export directory. According to the directory ID, the corresponding export directory can be searched to obtain the corresponding configuration information.
[0086] S203: Verify the export directory corresponding to the configuration information according to the type of the loading instruction. In the embodiment of the present invention, the verification of the export directory mainly determines whether the directory ID carried in the loading instruction exists in the server memory.
[0087] S204: When the export directory passes the verification, the configuration file of the export directory is modified according to the configuration information. Different types of dynamic loading instructions have different corresponding verification conclusions. When the dynamic loading instruction belongs to updating the configuration file, to realize the dynamic update of the configuration file, first the directory ID should exist in the memory, that is, when the directory ID exists in the server memory, it means that the export directory has passed the verification, so that the corresponding configuration file can be found according to the directory ID, and the configuration information can be updated to the configuration file, thereby completing the effective update of the configuration file.
[0088] When the loading instruction belongs to adding a configuration file, in order to realize the dynamic addition of the configuration file, first of all, the directory ID should not exist in the memory. That is, when the directory ID does not exist in the server memory, it means that the export directory has passed the verification, then the directory ID and the configuration information are added in the server memory to complete the effective addition of the configuration file.
[0089] In the above embodiment of loading configuration files, the modified configuration files are made effective in time by dynamically loading configuration files. The services are not interrupted during the dynamic loading process, which is of great help to system operation and maintenance, improves the work efficiency of system maintenance, and reduces the scope of business impact.
[0090] Taking the dynamic loading of the export directory as an example, in addition to the addition and update of the configuration file described above, in order to further improve the function of the configuration file, in the embodiment of the present invention, a function of deleting the export directory can also be set. Specifically, the server can receive an export directory deletion instruction; according to the directory ID carried in the deletion instruction, search from the server memory whether there is an export directory corresponding to the directory ID; when the export directory corresponding to the directory ID exists in the server memory, the export directory and its corresponding configuration information are deleted from the server memory.
[0091] In some embodiments, the method for obtaining the configuration file may include: obtaining the configuration file from the distributed configuration center after the application is started, and caching the configuration file in the local file system, and the cached configuration file is identified by the node server address corresponding to the application. When the distributed configuration center service is unavailable, the application searches for the corresponding configuration file in the local cache through the node server address after restarting. When the client determines that the target application is in local mode, it directly reads the effective configuration file from the local cache corresponding to the target application.
[0092] In step S102, the memory service connection information in the configuration file is called to cache the database table to the memory server having a mapping relationship with the database table.
[0093] The created memory service connection information can be saved in the cache module, and the cache module is also used to save the memory server information table (including the memory server IP address, memory server port, memory server available space and other information). The memory server can report the memory server information to the cache module in real time. When the cache module receives a data cache request from an application, the request carries the information of the database table. First, the memory service connection information in the configuration file is called, and the memory server with a mapping relationship with the database table is searched according to the memory service connection information and the information of the database table carried by the request. After finding the information table of the memory server with the mapping relationship, the data table is cached to the memory server using the information table of the memory server.
[0094] An embodiment of the present application provides a data caching method for an application. Memory service connection information is created in a configuration file, and the memory service connection information is used to indicate a mapping relationship between a database table and a memory server, and the database table has a mapping relationship with at least one memory server. The memory service connection information in the configuration file is called to cache the database table to a memory server that has a mapping relationship with the database table. When accessing application data, the memory service connection information is called to access the memory server that has a mapping relationship with the database table. The technical solution of the present application uses a configuration file to create memory service connection information. Since the configuration file is a file that can be changed and takes effect in real time, there is no need to stop the service when splitting data and expanding memory, thereby improving the efficiency of splitting data and expanding memory.
[0095] In some embodiments, a database table may be pre-set to establish a mapping relationship with at least two memory servers. Figure 7 The data splitting process diagram shown in the figure may include the following steps:
[0096] In step S301, the total amount of data in the database table is obtained.
[0097] In step S302, when the total data size of the database table is larger than the available memory size of the first memory server, the database table is split into a first sub-table and a second sub-table.
[0098] When splitting a database table, first delete the original database table to be split, and then submit the generated multiple split database tables. Corresponding to the database, the original data is first modified to an invalid state, and then multiple valid data are added. The stream computing framework monitors the binary log binlog of the business database (both the master and the slave) in real time, assembles the binlog information in a predetermined format, encapsulates it into a business model, formats it into data with a structure such as json, and then writes it back to the message queue (for example: kafka, etc.). As far as the database table library is concerned, the operation types on the database table are generally added, modified, and deleted. Therefore, the messages formed by the corresponding operation log binlog also include the three types of addition, modification, and deletion. A message corresponds to a row of records that have changed in the database table library. If a database table library operation (sql) statement modifies multiple rows of records in the database table library, then the database table library operation statement is also written to the message queue as multiple messages. The stream computing framework consumes the messages in the message queue in real time to obtain the database table split information and perform actual business logic processing. The database table split information can be to delete the database table information to be split or to generate the database table information after splitting.
[0099] The database table splitting information mainly includes a database table identifier and a database table value. According to the needs of different businesses, the database table splitting information may also include other contents, such as: database table splitting time, business system database table library identifier, etc. According to an embodiment of the present invention, the database table splitting information may mainly include two types: deleting the database table information to be split and generating the split database table information. If the database table splitting information is to delete the database table information to be split, the database table splitting information includes the database table to be split and the database table identifier to be split; if the database table splitting information is to generate the split database table information, the database table splitting information includes the split database table, the split database table identifier and the database table identifier to be split. It can be known that no matter whether the database table splitting information is to delete the database table information to be split or to generate the split database table information, it contains the database table identifier to be split. Therefore, the database table library table is split into the first sub-table and the second sub-table in time, and the first sub-table and the second sub-table both have the identifier of the original database table library table. When the database table is accessed later, the situation that the split database table library table cannot be accessed will not occur.
[0100] In step S303, the first subtable is cached to the first memory server, wherein the total data size of the first subtable is less than or equal to the available memory size of the first memory server. In order to ensure that the total data size of the first subtable is less than the available memory size of the first memory server, before splitting the database table, the available memory size of the first memory server (the priority of the first memory server is higher than that of other memory servers, so the data is cached to the first memory server first) is obtained. When the database is split, the total data size of the first subtable can be set to be less than or equal to the available memory size of the first memory server. Therefore, when caching data, the first subtable can be first cached to the first memory server.
[0101] If the total amount of data in the database table that needs to be cached is smaller than the available memory size of the first memory server, the database table will be directly cached in the first memory server without splitting the database table.
[0102] In step S304, if there is a second memory server and the total data size of the second sub-table is less than or equal to the available memory size of the second memory server, the second sub-table is cached to the second memory server, and in the configuration file, the database table has a mapping relationship with both the first memory server and the second memory server.
[0103] In some embodiments, if the second memory server does not exist, the second sub-table is cached to a spare memory server, wherein the spare memory server has no mapping with the database table.
[0104] In some embodiments, a business scenario identifier may be set for the first database table and the second database table, that is, different database tables correspond to different business scenarios. If the business scenario identifiers of the first database table and the second database table are the same, the first database table and the second database table are cached to the same memory server. If the business scenario identifiers of the first database table and the second database table are different, the first database table and the second database table are cached to different memory servers. In this way, when accessing the database subsequently, for the same business scenario, only one memory server may be accessed without accessing other memory servers, thereby improving the efficiency of data access.
[0105] In some embodiments, multiple sets of the memory service connection information are created in the configuration file. For example, a memory service connection information pool may be created. The memory service connection information in the configuration file is randomly called, and the database table is cached to the memory server that has a mapping relationship with the database table. In this way, when the program caches data, the flexibility of data caching is further improved by dynamically obtaining the memory service connection information from the memory service connection information pool.
[0106] In some embodiments, a time loop queue consisting of time queue items can be established, wherein the time loop queue has a cursor, and the time queue item pointed to by the cursor is the current time. At specified intervals, the cursor moves to the next time queue item. Each time queue item corresponds to a memory server. When caching data, according to the time allocation, one grid is moved at regular intervals to avoid caching all data in one memory server.
[0107] For example, if Figure 8 The schematic diagram of the memory service connection information acquisition principle is shown. Figure 8 The memory service connection information shown is all created with the current database table. Assume that the current cursor points to memory service connection information 1, which indicates the current time. If the database table needs to be cached, use memory server connection 1 to cache the database table to memory server 1. The cursor can move one grid every 12 hours. When the cursor points to memory service connection information 1, which indicates the current time, if the database table needs to be cached, use memory server connection 2 to cache the database table to memory server 2, and so on. This can avoid caching all data in one memory server and make reasonable use of the memory servers in the memory server pool.
[0108] It should be noted that if the available memory size of the memory server connected to the memory service connection information pointed to by the cursor is smaller than the total data size of the database table, the memory service connection information is skipped and the cursor points to the next memory service connection information. Figure 8 In the example, the current cursor points to the memory service connection information 1, indicating that at the current time, if the database table needs to be cached, the memory server connection 1 is used to cache the database table to the memory server 1. However, if the total size of the database table data is larger than the available memory size of the memory server 1, the cursor is directly made to point to the memory service connection information 2, indicating that the database table is cached to the memory server 2.
[0109] Based on the data caching method of the above embodiment, the present application provides a data access method for an application program, such as Fig. 9 The method comprises the following steps:
[0110] In step S401, a user data access request is obtained, wherein the user data access request carries an identifier of a database table.
[0111] In step S402, the memory service connection information corresponding to the identifier of the database table is retrieved from the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information indicates a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0112] In step S403, the memory server having a mapping relationship with the database table is accessed according to the memory service connection information.
[0113] Specifically, when it is detected that the application list page is opened, it is detected whether the electronic device has local data of the application. Generally speaking, applications need to verify the user. For applications that require login verification, after the user opens the application and successfully logs in, the application needs to show the user the default list page, or the user can choose a list page to open. When the electronic device detects that a list page of the application is opened, the page needs to be loaded. At this time, the electronic device needs to obtain the page data and first detects whether the local data of the application exists in the local storage space.
[0114] A local cache space is divided out from the terminal memory space to store the local data of the application. Specifically, a local cache space of a certain size is divided out from the terminal memory space to store the local data cached locally by the application on the terminal. It is understandable that in the local cache space, local data of more than one application is stored. The storage location of each application and its corresponding local data can be recorded through a mapping table. When it is necessary to obtain or detect the local data corresponding to a certain application, the storage location of the corresponding local data can be obtained from the mapping table to find the local data.
[0115] If there is no local data of the application, the application data of the application is obtained from the memory server through the application program interface. Specifically, when the local data of the application does not exist locally on the terminal, the application may be used for the first time or the user has cleared the cache. Therefore, the data displayed this time needs to be obtained from the memory server. At this time, the terminal makes a data request to the memory server through the application program interface (Application Programming Interface, API, referred to as application program interface) and receives the application data of the application returned by the memory server. The application data can also be saved in the local cache space as the local data of the application.
[0116] Obtaining the application data of the application from the memory server means accessing the database table in the memory server. After receiving the user data access request, the memory service connection information corresponding to the identifier of the database table is retrieved from the configuration file. Then, the memory service connection information is used to access the memory server with the mapping relationship and read the required database table. Since the configuration file is a file that can be changed and takes effect in real time, the application can dynamically obtain a memory service connection information for data access before actually accessing the memory server. The hot loading of the memory service connection information is realized, that is, during the operation of the application, a set of memory service connection information configuration is dynamically added and loaded into the application. The hot splitting of the memory server can be realized without suspending or restarting the service (that is, splitting a set of memory servers into two sets to achieve lossless business expansion), alleviating the decline in application availability caused by the migration or expansion of the memory cache service.
[0117] In some embodiments, before retrieving the memory server connection corresponding to the identifier of the database table from the configuration file, the method further includes: obtaining the version number of the configuration file. If the version number of the configuration file is the latest version, the memory service connection information corresponding to the identifier of the database table is retrieved from the configuration file. If the version number of the configuration file is not the latest version, the memory service connection information corresponding to the identifier of the database table is not retrieved from the configuration file. That is, if there are multiple configuration files in the system (the configuration files are changed in real time, and multiple versions of the configuration files may coexist), only the latest configuration file is used for data access. In this way, the configuration file used is always the latest version of the configuration file, reducing the occurrence of data access failures.
[0118] The present invention provides a configuration-based dynamic memory cache connection creation and access method, in which an application dynamically creates multiple sets of memory cache service connections based on the configuration, and automatically selects the correct memory service connection information according to the business scenario when accessing. In the first step, multiple sets of memory service connection information are first configured in the application, and any multiple sets of configurations can be added as needed. In the second step, the database table corresponding to each memory service connection information is configured. In the third step, the application starts hot loading. In the fourth step, according to the first step, the application creates multiple sets of memory service connection information pools. In the fifth step, according to the second step, the application stores the mapping relationship between the database table and the memory service connection information. In the sixth step, the application is started. At this time, the application is in a service-providing state. In the seventh step, a user data access request is received. In the eighth step, a specific business scenario is determined according to the user access request. In the ninth step, the memory service connection information is obtained according to the business scenario and the mapping relationship in the fifth step. If there is memory service connection information with a mapping relationship, jump to the tenth step and use the specified memory service connection information to access the data cached by the memory server.
[0119] In some embodiments, data caching and data access can be performed simultaneously. Fig.10 The schematic diagram of data caching and data accessing performed simultaneously is shown. In the process of caching a database table to a memory server, a data access request is received, and the data access request includes an identifier for accessing the database table. According to the identifier of the database table, it is determined whether the data to be accessed has been cached to the corresponding memory server. If the data to be accessed has been cached to the corresponding memory server, the data is accessed simultaneously during the data caching process. If the data to be accessed has not been cached to the corresponding memory server, the data is not accessed simultaneously during the data caching process.
[0120] Fig.11 The structure diagram of an embodiment of an electronic device for data caching of the present invention includes:
[0121] A memory service creation unit 11 is used to create memory service connection information between a database table of an application and a memory server in a configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information indicates a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0122] The data cache unit 12 is used to call the memory service connection information in the configuration file and cache the database table to the memory server having a mapping relationship with the database table.
[0123] Fig.12 The structure diagram of an embodiment of an electronic device for data access of the present invention includes:
[0124] A request acquisition unit 21, configured to acquire a user data access request, wherein the user data access request carries an identifier of a database table;
[0125] A connection retrieving unit 22, configured to retrieve the memory service connection information corresponding to the identifier of the database table from a configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information indicates a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers;
[0126] The data access unit 23 is used to access the memory server having a mapping relationship with the database table according to the memory service connection information.
[0127] Those skilled in the art will appreciate that the various aspects of the present application can be illustrated and described by a number of patentable categories or situations, including any new and useful process, machine, product or combination of substances, or any new and useful improvements thereto. Accordingly, the various aspects of the present application can be performed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The above hardware or software may all be referred to as "data blocks", "controllers", "engines", "units", "components" or "systems". In addition, the various aspects of the present application may be represented by a computer product located in one or more computer-readable media, which includes computer-readable program code.
[0128] In addition, unless explicitly stated in the claims, the order of the processing elements and sequences described in this application, the use of alphanumeric characters, or the use of other names are not intended to limit the order of the processes and methods of this application. Although the above disclosure discusses some invention embodiments that are currently considered useful through various examples, it should be understood that such details are only for illustrative purposes, and the attached claims are not limited to the disclosed embodiments. On the contrary, the claims are intended to cover all modifications and equivalent combinations that are consistent with the essence and scope of the embodiments of this application. For example, although the system components described above can be implemented by hardware devices, they can also be implemented only by software solutions, such as installing the described system on an existing server or mobile device.
[0129] Similarly, it should be noted that in order to simplify the description of the disclosure of this application and thus help understand one or more embodiments of the invention, in the above description of the embodiments of this application, multiple features are sometimes combined into one embodiment, figure or description thereof. However, this disclosure method does not mean that the features required by the object of this application are more than the features mentioned in the claims. In fact, the features of the embodiments are less than all the features of the single embodiment disclosed above.
Claims
1. A data caching method for an application, characterized in that: The method comprises: After the application is started, a configuration file is obtained from a distributed configuration center, and the configuration file is cached, wherein the configuration file is identified by a node server address corresponding to the application; When the distributed configuration center service is unavailable, after the application is restarted, the configuration file is queried in the local cache through the node server address; Creating memory service connection information between a database table of the application and a memory server in the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers; receiving a loading instruction of the configuration file, wherein the loading instruction carries a directory ID; Load configuration information according to the directory ID; According to the type of the loading instruction, verify the export directory corresponding to the configuration information; When the export directory passes the verification, modifying the configuration file of the export directory according to the configuration information; The memory service connection information in the modified configuration file is called to cache the database table to the memory server having a mapping relationship with the database table.
2. The data caching method for an application according to claim 1, characterized in that: The method further comprises: Obtaining the total amount of data in the database table; When the total amount of data in the database table is greater than the available memory of the first memory server, splitting the database table into a first sub-table and a second sub-table; caching the first sub-table to the first memory server, wherein the amount of data in the first sub-table is less than or equal to the available memory of the first memory server; When there is a second memory server and the amount of data in the second sub-table is less than or equal to the available memory of the second memory server, the second sub-table is cached to the second memory server. In the configuration file, the database table has a mapping relationship with both the first memory server and the second memory server, and the priority of the first memory server is higher than that of the second memory server.
3. The data caching method for an application according to claim 2, characterized in that: The method further comprises: When the total amount of data in the database table is less than or equal to the available memory of the first memory server, the database table is cached to the first memory server.
4. The data caching method for an application according to claim 2, characterized in that: When the second memory server does not exist, the second sub-table is cached to a spare memory server, wherein the spare memory server has no mapping relationship with the database table.
5. The data caching method for an application according to claim 1, characterized in that: The database table has a business scenario identifier, and the method further includes: When the business scenario identifiers of the first database table and the second database table are the same, caching the first database table and the second database table to the same memory server; When the business scenario identifiers of the first database table and the second database table are different, the first database table and the second database table are cached in different memory servers.
6. The data caching method for an application according to claim 1, characterized in that: The method further comprises: Creating multiple sets of the memory service connection information in the configuration file; The memory service connection information in the configuration file is randomly called, and the database table is cached to the memory server having a mapping relationship with the database table.
7. A data access method for an application, characterized in that: The method comprises: After the application is started, a configuration file is obtained from a distributed configuration center, and the configuration file is cached, wherein the configuration file is identified by a node server address corresponding to the application; When the distributed configuration center service is unavailable, after the application is restarted, the configuration file is queried in the local cache through the node server address; Obtaining a user data access request, wherein the user data access request carries an identifier of a database table; Retrieving the memory service connection information corresponding to the identifier of the database table from the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers; receiving a loading instruction of the configuration file, wherein the loading instruction carries a directory ID; Load configuration information according to the directory ID; According to the type of the loading instruction, verify the export directory corresponding to the configuration information; When the export directory passes the verification, modifying the configuration file of the export directory according to the configuration information; The memory service connection information in the modified configuration file is called to access the memory server having a mapping relationship with the database table.
8. The data access method of the application according to claim 7, characterized in that: Before retrieving the memory server connection corresponding to the identifier of the database table from the configuration file, the method further includes: Obtain the version number of the configuration file; When the version number of the configuration file is the latest version number, the memory service connection information corresponding to the identifier of the database table is retrieved from the configuration file.
9. An electronic device, characterized in that: The electronic device comprises: A memory service creation unit, configured to obtain a configuration file from a distributed configuration center after the application is started, and cache the configuration file, wherein the configuration file is identified by a node server address corresponding to the application; when the distributed configuration center service is unavailable, after the application is restarted, query the configuration file in a local cache by the node server address; Creating memory service connection information between a database table of the application and a memory server in the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers; receiving a loading instruction of the configuration file, wherein the loading instruction carries a directory ID; Load configuration information according to the directory ID; According to the type of the loading instruction, verify the export directory corresponding to the configuration information; When the export directory passes the verification, modifying the configuration file of the export directory according to the configuration information; The data cache unit is used to call the memory service connection information in the modified configuration file, and cache the database table to the memory server having a mapping relationship with the database table.
10. An electronic device, characterized in that: The electronic device comprises: A request acquisition unit is used to acquire a configuration file from a distributed configuration center after the application is started, and cache the configuration file, wherein the configuration file is identified by the node server address corresponding to the application; when the distributed configuration center service is unavailable, after the application is restarted, query the configuration file in the local cache by the node server address; acquire a user data access request, wherein the user data access request carries an identifier of a database table; A connection calling unit, used to call the memory service connection information corresponding to the identifier of the database table from the configuration file, wherein the configuration file is a file that can be modified and takes effect in real time, and the memory service connection information is used to indicate a mapping relationship between the database table and the memory server, and the database table has a mapping relationship with at least one of the memory servers; receiving a loading instruction of the configuration file, wherein the loading instruction carries a directory ID; Load configuration information according to the directory ID; According to the type of the loading instruction, verify the export directory corresponding to the configuration information; When the export directory passes the verification, the configuration file of the export directory is modified according to the configuration information; the data access unit is used to call the modified memory service connection information to access the memory server having a mapping relationship with the database table.
Citation Information
Patent Citations
Database deployment method, user equipment, storage medium and device
CN109977099A
