Cross-database user data operation method, medium, product and equipment
By implementing the user data operation method across databases, including locking and unlocking operations, as well as the management of memory and failure information tables, the data accuracy and isolation problems under cross-database operations and concurrent operations in the prior art are solved, and the performance and reliability of the database are improved.
Patent Information
- Application Number
- CN202510052089.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-04-18
AI Technical Summary
Existing database technologies are difficult to implement user data operations across databases, especially in concurrent operations, and it is difficult to ensure the accuracy and isolation of data.
By obtaining operation instructions in the target session, finding the database and table identifiers of the target user table, querying and setting the lock information table, performing locking and unlocking operations, ensuring data blocking processing, and managing data in the memory cache and invalidation information table to ensure data accuracy.
It realizes user data operations across databases, ensures the accuracy and isolation of data in concurrency, and improves the performance and reliability of the database.
Smart Images

Figure CN119848060A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a method, medium, product and device for operating user data across databases. Background Art
[0002] In modern data instances, based on data security and user business needs, most provide a certain degree of data isolation. Mainstream databases provide isolation in both physical and logical dimensions. Physical isolation means that the database data is placed in different physical paths; logical isolation means that the data placed in the same physical path is logically placed in different logical units according to logical rules and certain permissions.
[0003] In current database technology, a session (a link to a database) can generally access logically isolated objects, but cannot access physically isolated objects across databases. In addition, since most databases are multi-threaded concurrent execution, it is necessary to ensure the correctness of concurrent access to user table data in other databases. Summary of the invention
[0004] In view of the above problems, the present invention proposes a method, medium, product and device for operating user data across databases that overcome the above problems or at least partially solve the above problems.
[0005] An object of the present invention is to implement user data operations across databases.
[0006] A further object of the present invention is to ensure the accuracy of user table data during concurrent operations.
[0007] In particular, the present invention provides a method for operating user data across databases, comprising:
[0008] Obtain the operation instructions in the target session. The operation instructions are used to operate the user data in the target user table across databases.
[0009] According to the operation instruction, find out the target database identifier corresponding to the target user database where the target user table is located and the target user table identifier corresponding to the target user table;
[0010] According to the target database identifier and the target user table identifier, query in the preset lock information table whether there is lock information corresponding to the target user table, and the preset lock information table is used to record the lock information added when the user table is operated;
[0011] If not, lock the target user table and record the lock information corresponding to the lock in the preset lock information table;
[0012] Obtain the target user table and operate the target user table according to the operation instruction;
[0013] When the operation instruction is executed, the lock is released and the lock information corresponding to the lock in the preset lock information table is deleted.
[0014] Optionally, the step of obtaining a target user table and operating the target user table according to the operation instruction includes:
[0015] Determine whether the target user table is cached in the memory of the target session;
[0016] In the case where the target user table has been cached in the memory of the target session, query whether there is expiration information corresponding to the target user table in the preset expiration information table according to the target database identifier and the target user table identifier. The preset expiration information table is used to record the expiration information corresponding to the target user table.
[0017] If yes, the cached target user table in the target session's memory is deleted, and the data of the target user table is cached in the target session's memory again;
[0018] The target user table in the memory of the target session is operated according to the operation instruction, and the operation result is synchronized to the target user table in the disk.
[0019] Optionally, after the step of operating the target user table in the memory of the target session according to the operation instruction, the step further includes:
[0020] Determine whether the target user table has been changed;
[0021] When the target user table is modified, an invalidation information is added to the target user table;
[0022] The newly added failure information is recorded in the preset failure information table.
[0023] Optionally, after the step of determining whether the target user table is cached in the memory of the target session, the following steps are further included:
[0024] If the target user table is not cached in the memory of the target session, the data of the target user table is read from the disk and cached in the memory of the target session.
[0025] Optionally, after the step of re-caching the data of the target user table into the memory of the target session, the following steps are further included:
[0026] Record the session identifier corresponding to the target session into the expiration information corresponding to the target user table;
[0027] When the session ID recorded in the invalidation information includes the session IDs of all sessions in the current database instance, the invalidation information is deleted.
[0028] Optionally, the preset lock information table and the preset expiration information table are stored in a shared memory of the database instance;
[0029] The preset lock information table is a hash table, the key is the target database identifier and the target user table identifier, and the value is the lock information corresponding to the target user table;
[0030] The preset invalidation information table is a two-level hash table, the key of the first-level hash table is the target database identifier, the value of the first-level hash table is the pointer to the second-level hash table, the key of the second-level hash table is the target user table identifier, and the value of the second-level hash table is the invalidation information corresponding to the target user table.
[0031] Optionally, after the step of querying whether there is lock information corresponding to the target user table in the preset lock information table according to the target database identifier and the target user table identifier, the method further includes:
[0032] If the preset lock information table contains lock information corresponding to the target user table, determine whether the operation instruction supports waiting;
[0033] If the operation instruction supports waiting, after the lock information corresponding to the target user table in the preset lock information table is deleted, the step of locking the target user table and recording the lock information corresponding to the lock in the preset lock information table is executed;
[0034] If the operation instruction does not support waiting, the execution process of the operation instruction is terminated and the result is returned.
[0035] According to another aspect of the present invention, a computer program product is provided, which includes a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned cross-database user data operation methods are implemented.
[0036] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the steps of any one of the above-mentioned cross-database user data operation methods when executing the machine executable program.
[0037] The cross-database user data operation method of the present invention first obtains the operation instruction in the target session, and the operation instruction is used to operate the user data in the target user table across the database; then, according to the operation instruction, the target database identifier corresponding to the target user database where the target user table is located and the target user table identifier corresponding to the target user table are found; then, according to the target database identifier and the target user table identifier, it is queried in the preset lock information table whether there is lock information corresponding to the target user table, wherein the preset lock information table is used to record the lock information added when the user table is operated; if not, the target user table is locked, and the lock information corresponding to the lock is recorded in the preset lock information table; then the target user table is obtained, and the target user table is operated according to the operation instruction; when the operation instruction is executed, the lock is released, and the lock information corresponding to the lock in the preset lock information table is deleted. Through this method, the concurrent cross-database operation target user table can be correctly blocked, thereby ensuring the accuracy of the target user table data under concurrent conditions.
[0038] Furthermore, in the cross-database user data operation method of the present invention, in the process of operating the target user table according to the operation instruction, if the target user table is already cached in the memory of the target session, it will query whether there is the invalidation information corresponding to the target user table in the preset invalidation information table according to the target database identifier and the target user table identifier, wherein the preset invalidation information table is used to record the invalidation information corresponding to the target user table; if so, the cache corresponding to the target user table in the memory of the target session is deleted, and the data of the target user table is cached again in the memory of the target session; then the target user table in the memory of the target session is operated according to the operation instruction, and the operation result is synchronized to the target user table in the disk. Through this method, the target user table data cached in the memory of the target session can be guaranteed to be accurate, and when processing the invalidation information, a passive method of processing invalidation messages is adopted, that is, only when obtaining the information of the user table, the invalidation message corresponding to the target user table will be searched in the preset invalidation information table, which can reduce the frequency of processing invalidation messages and improve database performance.
[0039] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0041] Figure 1is a schematic diagram of a database instance architecture according to an embodiment of the present invention;
[0042] Figure 2 is a flowchart of a method for operating user data across databases according to an embodiment of the present invention;
[0043] Figure 3 is a schematic diagram of a data operation flow according to an embodiment of the present invention;
[0044] Figure 4 is a schematic diagram of a computer program product according to an embodiment of the present invention;
[0045] Figure 5 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and
[0046] Figure 6 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0047] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0048] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein can be considered as a sequenced list of executable instructions for implementing logical functions, which can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0049] In the current database field, some data instances, based on data security and user business needs, mostly provide certain data isolation. Mainstream databases generally provide isolation in both physical and logical dimensions. The so-called physical isolation means that the data in the database is placed in different physical paths; the so-called logical isolation is to follow the logical rules and cooperate with certain permissions to make the data placed in the same physical path logically in different logical units. At present, the physical isolation of mainstream data is achieved through db (database), and the mainstream logical isolation is achieved through schema (mode). Among them, db refers to different databases under the same database instance, which is used to achieve physical isolation of database instances. Schema is different modes under the same db in the same database instance, which is used to achieve logical isolation under db.
[0050] In current database technology, a session can generally access logically isolated objects, but cannot access physically isolated objects across databases. However, some users need to access data in user tables across both physical units (db) and logical units (schemas). To meet such user needs and maintain physical isolation of data, you first need to be able to obtain which user tables are in other dbs; secondly, you need to know the physical storage location of user tables in other dbs, so that you can access user tables in other dbs.
[0051] Based on the above problems, this embodiment proposes a database architecture such as Figure 1 As shown, Figure 1 Schematic diagram of a database instance architecture according to an embodiment of the present invention. Figure 1 It can be seen that the present invention establishes a system database 300 and several user databases, such as user database 410, user database 420, etc., in an established database instance 100. In this embodiment, the system database 300 is generally used to store key system tables and auxiliary system tables. The key system tables are generally used to store key meta-information of all data tables. All data tables include all system tables in the system database and all user tables in the user database, and the auxiliary system tables are used to store auxiliary meta-information other than the key meta-information corresponding to all data tables, that is, the system database 300 is used to store the meta-information of all tables in all databases (including the system database itself and the user database), while the user database is only responsible for storing user data tables, and the user data tables are responsible for storing user data.
[0052] Optionally, a key system table 310 and an auxiliary system table are stored in the system database 300, wherein the key system table 310 generally includes three system tables, namely, a table system table 311, a column system table 312, and a type system table 313. The table system table 311 is generally used to store table characteristic information of all data tables, such as the table ID, table name, mode of the table, db where the table is located, disk table space where the table is located, whether it is a system table, and other information of all tables (including system tables and user tables); the column system table 312 is generally used to store column configuration information of all data tables, such as the name, type, length, and other information of each field of all tables (including system tables and user tables); the type system table 313 is generally used to store data type definition information of all data tables, wherein the data type definition information refers to the implementation details of various data types in the database, such as the basic information, storage format, value range, and other information of various data types (such as INT, VARCHAR, DATE, etc.). Those skilled in the art can set the specific data types stored in the key system table 310 according to actual conditions. An optional example of the table system table is shown in Table 1:
[0053] Table 1
[0054] table table_id table_name table_schema table_db table_space is_system_table ……
[0055] Among them, table_id represents the data table id, table_name represents the data table name, table_schema represents the data table mode, table_db represents the database where the data table is located, table_space represents the table space where the data table is located, and is_system_table represents whether the data table is a system table.
[0056] An optional example of the column system table is shown in Table 2:
[0057] Table 2
[0058] Column table column_table_id column_name column_type_id column_size ……
[0059] Among them, column_table_id indicates that the data table id of the column corresponds to the table_id in the table system table, column_name indicates the field name of the column, column_type_id indicates the data type of the column, and column_type_id indicates the length of the column.
[0060] An optional example of the type system table is shown in Table 3:
[0061] Table 3
[0062]
[0063]
[0064] Among them, type_id represents the id of the data type, which corresponds to column_type_id in the column system table, type_name represents the name of the data type, type_in_function represents the specific setting of the input method, and type_out_function represents the specific setting of the output method. The above key system table is only an optional example, and those skilled in the art can determine the specific content of the above key system table according to actual conditions.
[0065] In addition, the auxiliary system tables include auxiliary system table 321, auxiliary system table 322, and auxiliary system table 323, etc. Such auxiliary system tables are generally used to store auxiliary meta-information other than key meta-information corresponding to all data tables, such as the association between each data table and index, the usage of various functions, and the conversion method of different data types, etc. Those skilled in the art can determine the number of auxiliary system tables and the type of auxiliary meta-information actually stored in each auxiliary system table according to actual conditions.
[0066] When the outside world needs to access database instance 100, it generally chooses to create a new session to connect to database instance 100. At this time, if it wants to access user data in other physically isolated databases across databases (that is, access user databases), it can obtain the specific path of the target user data table to be accessed by querying the key system tables and auxiliary system tables of the system database, and then access the corresponding target user data table according to the specific path, and finally query the corresponding user data for the next step.
[0067] In some optional embodiments, in order to improve the query speed, you can also choose to establish a system cache 200. When a new session is established, the data in the key system table 310 is read into the system cache 200. If you need to query the key system table 310, you can directly query it in the system cache 200, thereby reducing the amount of data that needs to be read; if data from other auxiliary system tables is also needed, you can also first query the path information corresponding to the target auxiliary system table through the key system table 310 in the system cache 200, and then locate the target auxiliary system table according to the path information for query, and cache the data of the target auxiliary system table in the system cache 200. If you still need the data of the target auxiliary system table, you can query it in the system cache 200, thereby further reducing the amount of data that needs to be read.
[0068] This database architecture can maintain physical isolation of user data on the one hand, and on the other hand, can obtain data from user tables in other databases without sacrificing performance. However, most current databases operate concurrently, so it involves how to ensure data correctness while implementing concurrent operations under the above database architecture.
[0069] To solve the above concurrency problem, the present invention proposes an optional method as follows Figure 2 As shown, Figure 2 FIG. 1 is a flow chart of a method for operating user data across databases according to an embodiment of the present invention. Figure 2 As shown, the cross-database user data operation method at least includes the following steps S201 to S206.
[0070] Step S201, obtain the operation instruction in the target session. The operation instruction is used to operate the user data in the target user table across the database, and the user database is used to record the user data. In this step, the operation instruction can generally be obtained by the user actively inputting through the session, or automatically generated by the database program due to business needs during operation. Those skilled in the art can decide the method of obtaining the operation instruction according to actual conditions.
[0071] Step S202, according to the operation instruction, find the target database identifier corresponding to the target user database where the target user table is located and the target user table identifier corresponding to the target user table. The target database identifier and the target user table identifier can generally be their corresponding id values, such as the table_id recorded in the table table shown in Table 1 can be used as the target user table identifier, and table_db can be used as the target database identifier.
[0072] Step S203, querying the preset lock information table to see whether there is lock information corresponding to the target user table. When multiple users or multiple transactions concurrently access a database table, if there is no lock mechanism, multiple transactions may modify the data of the same row or the same table at the same time, resulting in data inconsistency. After locking a data table, it can be ensured that only the currently locked session is allowed to operate the data table, and other sessions cannot access the data table during this process. This can prevent concurrent modification conflicts, thereby ensuring the correctness of the data.
[0073] In some optional embodiments, the preset lock information table is generally stored in the shared memory of the database instance (i.e., system memory). The preset lock information table can generally be a hash table, in which the key is the target database identifier and the target user table identifier, and the value is the lock information corresponding to the target user table. In this way, the preset lock information table can clearly record the locking status of all databases (including system databases and user databases) during use.
[0074] Step S204: If the result of the determination in step S203 is no, the target user table is locked, and lock information corresponding to the lock is recorded in a preset lock information table.
[0075] Step S205: obtaining a target user table, and performing an operation on the target user table according to the operation instruction.
[0076] Step S206, when the operation instruction is executed, the lock is released and the lock information corresponding to the lock in the preset lock information table is deleted.
[0077] Through this method, the target user table of concurrent cross-database operations can be correctly blocked, thereby ensuring the accuracy of the target user table data in concurrent situations.
[0078] In some optional embodiments, after the step of querying whether there is lock information corresponding to the target user table in the preset lock information table according to the target database identifier and the target user table identifier, it can generally also include: if there is lock information corresponding to the target user table in the preset lock information table, determine whether the operation instruction supports waiting; if the operation instruction supports waiting, after waiting for the lock information corresponding to the target user table in the preset lock information table to be deleted, execute the step of locking the target user table and recording the lock information corresponding to the lock in the preset lock information table; if the operation instruction does not support waiting, end the execution process of the operation instruction and return the result. In the database, different operation instructions will have different behaviors when encountering other tables being locked, which generally depends on factors such as the type of instruction and the lock mechanism setting of the database. For example, instructions with strong timeliness usually obtain exclusive locks during execution to ensure data consistency and integrity. At this time, if the target user table is locked, the operation will generally be terminated directly, and an error will be directly reported or the termination reason will be returned. For query-type operation instructions, a shared lock is generally selected by default. At this time, if the target user table is locked, it will generally choose to wait for the lock to be released before locking the target user table and performing the corresponding operation. Whether different instructions support waiting can generally be preset, for example, parameters such as waiting time and locking type are set in a configuration file. Those skilled in the art can set the corresponding parameters according to actual conditions.
[0079] In order to speed up the reading speed of the target user table accessed by the operation instruction, the method of the present invention chooses to cache the data of the target user table into the memory of the target session itself after the first reading of the target user table. Such operation can improve the reading speed of subsequent access to the same target data table, but correspondingly, there will be a deviation between the data in the cache and the actual data of the target user table. To solve this problem, the present invention further proposes the following Figure 3 The operation method shown is Figure 3 is a schematic diagram of a data operation flow according to an embodiment of the present invention; Figure 3 As shown, the cross-database user data operation method at least includes the following steps S301 to S307.
[0080] Step S301, determining whether a target user table has been cached in the memory of the target session.
[0081] Step S302: if the judgment in step S301 is no, the data of the target user table is read from the disk, and the data of the target user table is cached in the memory of the target session.
[0082] Step S303: If the result of step S301 is yes, query whether there is any expiration information corresponding to the target user table in the preset expiration information table, wherein the preset expiration information table is generally used to record the expiration information corresponding to the target user table.
[0083] In some optional embodiments, in order to speed up the query speed, the preset invalidation information table is generally stored in the shared memory of the database instance; in addition, the preset invalidation information table can generally be designed as a two-level hash table, the key of the first-level hash table is the target database identifier, the value of the first-level hash table is the pointer of the second-level hash table, the key of the second-level hash table is the target user table identifier, and the value of the second-level hash table is the invalidation information corresponding to the target user table. This can further improve the efficiency of invalidation message search.
[0084] Step S304: If the result of step S303 is yes, the cache corresponding to the target user table in the target session's memory is deleted, and the data of the target user table is cached again in the target session's memory. If the preset expiration information table contains expiration information corresponding to the target user table, it means that the data of the target user table cached in the target session is inconsistent with the actual target user table data. Therefore, in order to ensure data synchronization, the latest target user table data needs to be re-read into the target session's memory.
[0085] In some optional embodiments, since the expiration information is always stored in a preset expiration information table, in order to reduce the consumption of database resources, it is necessary to promptly clean up invalid expiration information, that is, expiration information that has been accessed by all sessions in the current database instance. Therefore, after the step of re-caching the data of the target user table into the memory of the target session, it can generally also include: recording the session identifier corresponding to the target session into the expiration information corresponding to the target user table; and deleting the expiration information when the session identifier recorded in the expiration information contains the session identifiers of all sessions in the current database instance.
[0086] Step S305: If the result of step S303 is negative or any of step S302 and step S304 is completed, the target user table in the memory of the target session is operated according to the operation instruction, and the operation result is synchronized to the target user table in the disk. If the result of step S303 is negative or any of step S302 and step S304 is completed, it means that the target user table data cached in the memory of the target session is the same as the target user table data in the disk, and the corresponding operation can be quickly performed in the memory, and the operation result is synchronized to the target user table in the disk.
[0087] Step S306, judging whether the target user table has been changed. In some optional embodiments, since the operation instruction includes different types of instructions, for example, DML (Data Manipulation Language) and DDL (Data Definition Language) are two types of languages used for different operations in the database, both of which belong to the operation instruction, but DML statements generally include operations such as inserting (INSERT), updating (UPDATE), deleting (DELETE) and querying (SELECT) data. DDL is a language used to define and manage database objects, such as creating (CREATE), modifying (ALTER), and deleting (DROP) databases, tables, views, indexes and other objects. Among them, the query operation will not change the data in the target user table. If the target user table has not been changed, the corresponding result can be directly returned, but other operations will cause the internal data of the target user table or the structure of the table itself to change, and at this time, the target user table data cached in the target session memory has become invalid.
[0088] Step S307: If the result of the determination in step S306 is yes, a new expiration information is added to the target user table, and the new expiration information is recorded in the preset expiration information table.
[0089] Through this method, the target user table data cached in the memory of the target session can be guaranteed to be accurate, and when processing the invalidation information, a passive method of processing the invalidation message is adopted, that is, only when obtaining the information of the user table, the invalidation message corresponding to the target user table is searched in the preset invalidation information table. This can reduce the frequency of processing invalidation messages and improve database performance.
[0090] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.
[0091] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0092] This embodiment also provides a computer program product 10 , a computer readable storage medium 20 , and a computer device 30 . Figure 4 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Figure 5 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention, Figure 6 is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned cross-database user data operation methods when executed by a processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11, which implements the steps of any of the above-mentioned cross-database user data operation methods when executed by the processor 32. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.
[0093] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.
[0094] For the purposes of the description of the present embodiment, the computer program product 10 is a related product that includes the computer program 11. For the purposes of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which may be any device that can contain, store, communicate, propagate or transmit the program 11 for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0095] The computer device 30 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 30 may be a cloud computing node. The computer device 30 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 may be implemented in a distributed cloud computing environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.
[0096] The computer device 30 may include a processor 32 adapted to execute stored instructions, and a memory 31 providing temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 31 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.
[0097] The computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.
[0098] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A cross-database user data operation method, comprising: Obtaining an operation instruction in a target session, where the operation instruction is used to operate user data in a target user table across databases; According to the operation instruction, a target database identifier corresponding to the target user database where the target user table is located and a target user table identifier corresponding to the target user table are searched and obtained; querying whether there is lock information corresponding to the target user table in a preset lock information table according to the target database identifier and the target user table identifier, wherein the preset lock information table is used to record lock information added when the user table is operated; If not, lock the target user table, and record the lock information corresponding to the lock into the preset lock information table; Acquire the target user table, and operate the target user table according to the operation instruction; When the operation instruction is executed, the lock is released, and the lock information corresponding to the lock in the preset lock information table is deleted.
2. The cross-database user data operation method according to claim 1, wherein: The step of obtaining the target user table and operating the target user table according to the operation instruction includes: Determine whether the target user table is cached in the memory of the target session; In the case where the target user table has been cached in the memory of the target session, querying whether there is expiration information corresponding to the target user table in a preset expiration information table according to the target database identifier and the target user table identifier, the preset expiration information table being used to record the expiration information corresponding to the target user table; If yes, deleting the target user table cached in the memory of the target session, and re-caching the data of the target user table into the memory of the target session; The target user table in the memory of the target session is operated according to the operation instruction, and the operation result is synchronized to the target user table in the disk.
3. The cross-database user data operation method according to claim 2, wherein: After the step of operating the target user table in the memory of the target session according to the operation instruction, the step further includes: Determine whether the target user table is modified; When the target user table is modified, adding invalidation information to the target user table; The newly added expiration information is recorded in the preset expiration information table.
4. The cross-database user data operation method according to claim 2, wherein: After the step of determining whether the target user table is cached in the memory of the target session, the method further includes: When the target user table is not cached in the memory of the target session, data of the target user table is read from the disk, and the data of the target user table is cached in the memory of the target session.
5. The cross-database user data operation method according to claim 2, wherein: After the step of re-caching the data of the target user table into the memory of the target session, the method further includes: Recording the session identifier corresponding to the target session into the expiration information corresponding to the target user table; In the case where the session identifier recorded in the invalidation information includes the session identifiers of all sessions in the current database instance, the invalidation information is deleted.
6. The cross-database user data operation method according to claim 5, wherein: The preset lock information table and the preset expiration information table are stored in the shared memory of the database instance; The preset lock information table is a hash table, the key is the target database identifier and the target user table identifier, and the value is the lock information corresponding to the target user table; The preset invalidation information table is a two-level hash table, the key of the first-level hash table is the target database identifier, the value of the first-level hash table is the pointer to the second-level hash table, the key of the second-level hash table is the target user table identifier, and the value of the second-level hash table is the invalidation information corresponding to the target user table.
7. The cross-database user data operation method according to claim 1, wherein: After the step of querying whether there is lock information corresponding to the target user table in the preset lock information table according to the target database identifier and the target user table identifier, the following step further includes: If the preset lock information table contains lock information corresponding to the target user table, determining whether the operation instruction supports waiting; In the case where the operation instruction supports waiting, after waiting for the lock information corresponding to the target user table in the preset lock information table to be deleted, the step of locking the target user table and recording the lock information corresponding to the lock into the preset lock information table is performed; If the operation instruction does not support waiting, the execution process of the operation instruction is terminated and the result is returned.
8. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the cross-database user data operation method according to any one of claims 1 to 7 are implemented.
9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the cross-database user data operation method according to any one of claims 1 to 7.
10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the cross-database user data operation method according to any one of claims 1 to 7 when executing the machine executable program.