A resource access control method and device, electronic equipment and storage medium

CN122963822APending Publication Date: 2026-10-23TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510508769.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0003]然而,相关技术中基于锁的资源访问控制方式,不仅资源冲突率高,多线程的并行度低,而且加锁代码繁琐,导致资源访问效率低,运维难度大

Benefits of technology

[0041]本申请实施例通过获取对逻辑资源中的目标共享资源进行目标操作的目标资源访问请求,创建该目标资源访问请求对应的目标线程,并确定该目标共享资源在逻辑资源中对应的父级共享资源以及其在物理资源中的关联共享资源,进而基于目标操作的操作类型确定该目标线程的第一资源锁信息,并进一步基于该第一资源锁信息确定目标线程的第二资源锁信息,其中第一资源锁信息指示目标共享资源的锁类型,第二资源锁信息指示上述父级共享资源的意向锁类型和关联共享资源的锁类型,以及基于该第一资源锁信息和第二资源锁信息控制目标线程对目标共享资源的访问,从而利用共享资源之间的依赖关系,进行了更小锁粒度、更简化地资源访问控制,资源冲突率大大降低,多线程并行度大大提高,减少了加锁代码的复杂度,在提升资源访问效率的同时,运维难度也大大降低。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122963822A_ABST
    Figure CN122963822A_ABST
Patent Text Reader

Abstract

The application discloses a resource access control method and device, electronic equipment and a storage medium. The method comprises the following steps: obtaining a target resource access request for requesting a target operation on a target shared resource in a logical resource, and creating a corresponding target thread; determining a parent shared resource corresponding to the target shared resource in the logical resource and an associated shared resource of the target shared resource in a physical resource; determining first resource lock information of the target thread based on an operation type of the target operation, wherein the first resource lock information indicates a lock type of the target shared resource; determining second resource lock information of the target thread based on the first resource lock information, wherein the second resource lock information indicates an intended lock type of the parent shared resource and a lock type of the associated shared resource; and controlling access of the target thread to the target shared resource based on the first resource lock information and the second resource lock information. The application reduces the resource conflict rate, improves the parallelism of multi-thread and the resource access efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a resource access control method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the development of computer technology, the types of shared resources in computer systems are increasing, and the access to shared resources is also increasing. Locks are an important technical means for controlling resource access in computer systems. They are used to manage concurrent access to shared resources in order to resolve conflicts in concurrent access to shared resources.

[0003] However, the lock-based resource access control method in related technologies not only has a high resource conflict rate and low parallelism of multi-threading, but also has cumbersome locking code, resulting in low resource access efficiency and high maintenance difficulty. Summary of the Invention

[0004] To address the problems of the prior art, embodiments of this application provide a resource access control method, apparatus, electronic device, and storage medium. The technical solution is as follows:

[0005] On the one hand, a resource access control method is provided, the method comprising:

[0006] Obtain a target resource access request and create a target thread corresponding to the target resource access request; the target resource access request is used to request a target operation on a target shared resource in the logical resources.

[0007] Determine the parent shared resource corresponding to the target shared resource in the logical resources, and the associated shared resources of the target shared resource in the physical resources;

[0008] Based on the operation type of the target operation, the first resource lock information of the target thread is determined; the first resource lock information indicates the lock type of the target shared resource;

[0009] Based on the first resource lock information, the second resource lock information of the target thread is determined; the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource;

[0010] Based on the first resource lock information and the second resource lock information, the access of the target thread to the target shared resource is controlled.

[0011] On the other hand, a resource access control device is provided, the device comprising:

[0012] The thread creation module is used to obtain a target resource access request and create a target thread corresponding to the target resource access request; the target resource access request is used to request a target operation on a target shared resource in the logical resources.

[0013] The upper-level associated resource determination module is used to determine the parent shared resource corresponding to the target shared resource in the logical resources, and the associated shared resources of the target shared resource in the physical resources;

[0014] The first lock information determination module is used to determine the first resource lock information of the target thread based on the operation type of the target operation; the first resource lock information indicates the lock type of the target shared resource;

[0015] The second lock information determination module is used to determine the second resource lock information of the target thread based on the first resource lock information; the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource;

[0016] The access control module is used to control the target thread's access to the target shared resource based on the first resource lock information and the second resource lock information.

[0017] In one exemplary implementation, the upper-level associated resource determination module includes:

[0018] The calling module is used to call resource tree information, which includes logical resource branches and physical resource branches connected to the root node. The logical resource branches represent the hierarchical relationship between shared resources in the logical resources, and the physical resource branches represent the hierarchical relationship between shared resources in the physical resources.

[0019] The parent resource determination module is used to determine the first node corresponding to the target shared resource in the logical resource branch, and to determine the shared resources corresponding to each intermediate node between the first node and the root node in the logical resource branch as the parent shared resource.

[0020] The associated resource determination module is used to determine the second node corresponding to the target shared resource in the physical resource branch, and to determine the shared resources corresponding to the second node in the physical resource branch, as well as the shared resources corresponding to each intermediate node between the second node and the root node, as the associated shared resources.

[0021] In one exemplary embodiment, the first lock information determination module includes:

[0022] The first determining module is configured to determine, when the target operation is a first operation type, the first resource lock information indicating an exclusive lock for the target thread; the first operation type changes the resource state of the operated resource;

[0023] The second determining module is used to determine, when the target operation is a second operation type, the first resource lock information indicating a shared lock for the target thread; the second operation type does not change the resource state of the operated resource.

[0024] In one exemplary embodiment, the second lock information determination module includes:

[0025] The third determining module is used to determine, when the first resource lock information indicates an exclusive lock, the second resource lock information of the target thread indicates an intentional exclusive lock of the parent shared resource, the exclusive lock of the shared resource corresponding to the second node, and the intentional exclusive lock of the shared resource corresponding to each intermediate node between the second node and the root node.

[0026] The fourth determining module is used to determine, when the first resource lock information indicates a shared lock, the intended shared lock of the parent shared resource indicated by the second resource lock information of the target thread, the shared lock of the shared resource corresponding to the second node, and the intended shared lock of the shared resource corresponding to each intermediate node between the second node and the root node.

[0027] In one exemplary implementation, the access control module includes:

[0028] The other lock information determination module is used to determine the lock information applied by other threads to the parent shared resource and the associated shared resource;

[0029] The first conflict detection module is used to perform resource lock conflict detection on the second resource lock information based on the lock information applied by the other threads to the parent shared resource and the associated shared resource, and obtain the first resource lock conflict detection result;

[0030] The first access control submodule is used to control the target thread's access to the target shared resource based on the first resource lock conflict detection result and the first resource lock information.

[0031] In one exemplary implementation, the first access control submodule includes:

[0032] The fifth determining module is used to determine the shared resource accessed by the other threads when the first resource lock conflict detection result indicates that there is no conflict.

[0033] An access module is used to perform the target operation on the target shared resource using the target thread when the shared resource accessed by the other thread is different from the target shared resource.

[0034] The second conflict detection module is used to perform resource lock conflict detection on the first resource lock information based on the lock information applied by the other threads to the target shared resource when the shared resource accessed by the other threads is the same as the target shared resource, and obtain the second resource lock conflict detection result.

[0035] The second access control submodule is used to control the target thread's access to the target shared resource based on the second resource lock conflict detection result.

[0036] In one exemplary embodiment, the first access control submodule further includes:

[0037] The waiting module is used to put the target thread into a waiting execution state when the first resource lock conflict detection result indicates that there is a conflict, until the first resource lock conflict detection result indicates that there is no conflict.

[0038] On the other hand, an electronic device is provided, including a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the resource access control method of any of the above aspects.

[0039] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or the at least one program being loaded and executed by a processor to implement the resource access control method as described above.

[0040] On the other hand, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the resource access control method of any of the above aspects.

[0041] This application embodiment obtains a target resource access request for a target operation on a target shared resource in logical resources, creates a target thread corresponding to the target resource access request, and determines the parent shared resource of the target shared resource in logical resources and its associated shared resources in physical resources. Then, based on the operation type of the target operation, it determines the first resource lock information of the target thread, and further determines the second resource lock information of the target thread based on the first resource lock information. The first resource lock information indicates the lock type of the target shared resource, and the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource. Based on the first and second resource lock information, it controls the target thread's access to the target shared resource. This utilizes the dependencies between shared resources to achieve finer-grained and simpler resource access control, significantly reducing resource conflict rates, greatly improving multi-threaded parallelism, and reducing the complexity of locking code. While improving resource access efficiency, it also significantly reduces operational and maintenance difficulties. Attached Figure Description

[0042] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0043] Figure 1 This is a schematic diagram of an implementation environment provided in an embodiment of this application;

[0044] Figure 2 This is a flowchart illustrating a resource access control method provided in an embodiment of this application;

[0045] Figure 3 This is an example of resource tree information provided in an embodiment of this application;

[0046] Figure 4 This is a flowchart illustrating another resource access control method provided in an embodiment of this application;

[0047] Figure 5 This is a structural block diagram of a resource access control device provided in an embodiment of this application;

[0048] Figure 6 This is a hardware structure block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0050] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0051] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0052] It is understood that in the specific embodiments of this application, data such as user information are involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0053] Please see Figure 1 The diagram shown is an implementation environment provided in this application embodiment. The implementation environment includes a terminal 110, a resource access control server 120, and a database 130. The terminal 110 and the resource access control server 120 can communicate via wired or wireless network connection, and the resource access control server 120 and the database 130 can communicate via wired or wireless network connection.

[0054] A database, simply put, can be viewed as an electronic filing cabinet—a place to store electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, with minimal redundancy, and independent of application programs.

[0055] In this embodiment, database 130 may include various types of shared resources, which can be divided into logical resources and physical resources. For example, logical resources may include clusters, zones, and tables, while physical resources may include storage processes (servers). Understandably, logical and physical resources can be further subdivided based on actual needs. For instance, a storage process (server) may be divided into multiple shards, each shard corresponding to a table in a logical resource. Exemplarily, database 130 may be a distributed database, such as providing distributed NoSQL data storage services. The data types stored in database 130 can be determined based on the associated specific business. For example, if the associated specific business is a virtual scene business, then the database may store data related to that virtual scene business.

[0056] Terminal 110 includes, but is not limited to, mobile phones, computers, smart voice interaction devices, smart home appliances, vehicle terminals, and aircraft. Terminal 110 can initiate a target resource access request to resource access control server 120. This target resource access request is used to request a target operation on a target shared resource in the logical resources. After obtaining the target resource access request, resource access control server 120 can create a target thread corresponding to the target resource access request, and then control the target thread's access to the target shared resource in database 130 based on the resource access control method of this application embodiment. The details will be described in detail in the following content of this application. By utilizing the subdivided and hierarchical dependency relationship between shared resources, while locking local resources, their parent resources can automatically hold an intention lock type with a lower probability of conflict. This achieves smaller lock granularity and simpler resource access control, greatly reducing the resource conflict rate, greatly improving the parallelism of multi-threading, reducing the complexity of locking code, improving resource access efficiency, and greatly reducing the difficulty of operation and maintenance.

[0057] It is understood that terminal 110 can refer to one of multiple terminals, and this embodiment only uses terminal 110 as an example. Those skilled in the art will know that the number of terminals can be more or less. For example, there may be only a few terminals, or there may be dozens or hundreds of terminals, or even more. This application embodiment does not limit the number of terminals or the type of devices.

[0058] It should be noted that the server involved in the embodiments of this application can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0059] Please see Figure 2 The diagram shown is a flowchart illustrating a resource access control method provided in an embodiment of this application. This method can be applied to... Figure 1 The resource access control server in the system. It should be noted that this specification provides the operational steps of the methods described in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many steps and does not represent the only execution order. In actual system or product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown... Figure 2 As shown, the method may include:

[0060] S201, Obtain the target resource access request and create the target thread corresponding to the target resource access request.

[0061] Among them, the target resource access request is used to request a target operation on a target shared resource in the logical resources.

[0062] Specifically, a target resource access request can be initiated by a terminal based on a client running on it for accessing database tables. The target resource access request can carry the identification information and operation information of the target shared resource to be accessed. The identification information can uniquely identify a shared resource, for example, the identification information of the target shared resource is table A. The operation information is used to indicate the target operation for the target shared resource. The target operation can be any one of adding, deleting, modifying, searching, etc.

[0063] Understandably, a target resource access request is one of multiple resource access requests received by the resource access control server. These multiple resource access requests can be for the same shared resource in the logical resources, or they can be for different shared resources in the logical resources.

[0064] For each resource access request, the resource access control server can create a corresponding thread, and then process the resource access request through the corresponding thread.

[0065] S203, determine the parent shared resource corresponding to the target shared resource in the logical resources, and the associated shared resource of the target shared resource in the physical resources.

[0066] In this embodiment, the dependency relationships between different types of shared resources are utilized. For both logical and physical resources, parent-child relationship information and association information between shared resources can be stored. Then, for a target shared resource, its corresponding parent shared resource in the logical resource can be determined based on the parent-child relationship information in the logical resource, and its corresponding associated shared resource in the physical resource can be determined based on the association information between the logical resource and the physical resource.

[0067] S205, based on the operation type of the target operation, determine the first resource lock information of the target thread.

[0068] The first resource lock information indicates the lock type of the target shared resource. Specifically, the lock type of the target shared resource indicated by the first resource lock information can be a lock based on a shared exclusivity mechanism, that is, it can be a shared lock or an exclusive lock.

[0069] A shared exclusive lock is a synchronization mechanism for concurrency control in computer programs, also known as a "shared-mutex lock" or a multi-reader-single-writer lock. It solves the read-write problem, allowing concurrent reentrancy for read operations and mutual exclusion for write operations. This means multiple threads can read data simultaneously, but writing data requires acquiring an exclusive lock. When a writer is writing data, other writers or readers must wait until the writer completes the write operation. A common use of read-write locks is to control thread access to a specific data structure in memory. This data structure cannot be updated atomically and is invalid until the update is complete.

[0070] S207, based on the first resource lock information, determine the second resource lock information of the target thread; the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource.

[0071] Specifically, after determining the first resource lock information of the target thread, the second resource lock information of the target resource can be automatically determined based on the first resource lock information. The second resource lock information indicates the intention lock type of the parent shared resource in the logical resource and the lock type of the associated shared resource in the physical resource.

[0072] The intention lock type can include intention shared locks and intention exclusive locks. The lock type of associated shared resources in physical resources can be determined based on the parent-child hierarchy within those shared resources. Specifically, associated shared resources can include directly associated shared resources and indirectly associated shared resources. Directly associated shared resources are physical resources directly associated with the target shared resource, while indirectly associated shared resources are the parent shared resources of the directly associated shared resource within the physical resources. For example, physical resources can be a storage process (Server) and the shards of the corresponding tables within the storage process. If the target shared resource is table A, then the physical resource directly associated with table A is shard A of table A, i.e., the directly associated shared resource is shard A, and the indirectly associated shared resource is the storage process (Server). In this embodiment, the lock type of directly associated shared resources in physical resources is consistent with the lock type of the target shared resource in logical resources, and is also a lock based on a shared-exclusive mechanism, which can be a shared lock or an exclusive lock. The lock type of indirectly associated shared resources in physical resources is an intention lock type.

[0073] In some exemplary embodiments, the resource access control server can maintain corresponding resource tree information for the shared resources of the database. The resource tree information includes logical resource branches and physical resource branches connected to the root node. The logical resource branches represent the hierarchical relationship between the shared resources in the logical resources, and the physical resource branches represent the hierarchical relationship between the shared resources in the physical resources.

[0074] like Figure 3 The illustration shows an example of resource tree information provided in this application embodiment. The root node connects both logical resource branches and physical resource branches. The logical resource branches include multiple nodes connected sequentially, each representing a level of shared resource within the logical resources. Specifically, these include cluster nodes, zone nodes, and table nodes. Table nodes serve as leaf nodes, and the intermediate nodes between the root node and table nodes (i.e., cluster nodes and zone nodes) can act as parent nodes of table nodes. The physical resource branches also include multiple nodes connected sequentially, each representing a level of shared resource within the physical resources. Specifically, these include storage process nodes and shard nodes. Shard nodes serve as leaf nodes, and the intermediate nodes between the root node and shard nodes (i.e., storage process nodes) can act as parent nodes of shard nodes. It should be noted that each shard in a shard node corresponds one-to-one with each table in a table node; that is, each table in the logical resources corresponds to a specific shard in the physical resources.

[0075] Furthermore, step S203, when determining the parent shared resource corresponding to the target shared resource in the logical resource and the associated shared resource of the target shared resource in the physical resource, may include:

[0076] The resource tree information is invoked, which includes logical resource branches and physical resource branches connected to the root node. The logical resource branches represent the hierarchical relationship between shared resources in the logical resources, and the physical resource branches represent the hierarchical relationship between shared resources in the physical resources.

[0077] Determine the first node corresponding to the target shared resource in the logical resource branch, and determine the shared resources corresponding to each intermediate node between the first node and the root node in the logical resource branch as the parent shared resource;

[0078] The second node corresponding to the target shared resource in the physical resource branch is determined, and the shared resources corresponding to the second node in the physical resource branch, as well as the shared resources corresponding to each intermediate node between the second node and the root node, are determined as the associated shared resources.

[0079] Specifically, with Figure 3 Taking the resource tree information shown as an example, assuming the target shared resource is table A, which corresponds to shard SA, then the first node is... Figure 3 The table node in the table, the second node is Figure 3 In a shard node, the parent shared resources are the cluster resources corresponding to the cluster node and the partition resources corresponding to the zone node, and the associated shared resources are the shard SA in the shard node and the storage process resources corresponding to the storage process node.

[0080] The above implementation uses resource tree information to make the hierarchical relationship of each shared resource clearer and more accurate. At the same time, the division of shared resources is more detailed, which helps to improve the efficiency of resource access control and reduce the probability of resource conflicts.

[0081] In some exemplary embodiments, step S205 above, when determining the first resource lock information of the first thread based on the operation type of the target operation, may include:

[0082] When the target operation is a first operation type, the first resource lock information of the target thread is determined to be an exclusive lock, and the first operation type changes the resource state of the operated resource;

[0083] When the target operation is of the second operation type, the first resource lock information of the target thread is determined to be a shared lock, and the second operation type does not change the resource state of the operated resource.

[0084] Specifically, the first operation type can be a write operation, such as modification, deletion, or addition. An exclusive lock allows exclusive access to an object, preventing any other thread from accessing the shared resource for which an exclusive lock is applied. The second operation type can be a read operation, such as a query. A shared lock prevents other threads from modifying the object being accessed. This type of lock allows multiple threads to concurrently read the same shared resource, but does not allow any thread to modify it.

[0085] In some exemplary embodiments, step S207, when determining the second resource lock information of the target thread based on the first resource lock information, may include:

[0086] When the first resource lock information indicates an exclusive lock, the second resource lock information of the target thread indicates an intentional exclusive lock of the parent shared resource, an exclusive lock of the shared resource corresponding to the second node, and an intentional exclusive lock of the shared resource corresponding to each intermediate node between the second node and the root node.

[0087] When the first resource lock information indicates a shared lock, the second resource lock information of the target thread indicates the intended shared lock of the parent shared resource, the shared lock of the shared resource corresponding to the second node, and the intended shared lock of the shared resources corresponding to each intermediate node between the second node and the root node.

[0088] by Figure 3 Taking the example shown, assuming the target shared resource is table A, if the target operation is a modification operation, then table A acquires an exclusive lock (which can be abbreviated as X), the partition and cluster both acquire intention exclusive locks (which can be abbreviated as IX), shard SA acquires an exclusive lock (which can be abbreviated as X), and the storage process acquires intention exclusive lock IX. If the target operation is a query operation, then table A acquires a shared lock (which can be abbreviated as S), the partition and cluster both acquire intention shared locks (which can be abbreviated as IS), shard SA acquires a shared lock S, and the storage process acquires intention shared lock IS.

[0089] In the above implementation, when the target thread acquires an exclusive lock on the target shared resource, it acquires an intention exclusive lock on the parent shared resource; when the target thread acquires a shared lock on the target shared resource, it acquires an intention shared lock on the parent shared resource. This not only achieves a smaller lock granularity and enables local resource locking, but also ensures that the parent automatically holds an intention lock type with a lower probability of conflict. This helps reduce the overall probability of shared resource conflicts, simplifies resource management, and improves resource access efficiency.

[0090] S209, based on the first resource lock information and the second resource lock information, control the target thread's access to the target shared resource.

[0091] Specifically, resource lock conflict detection can be performed based on the first and second resource lock information of the target thread, and the access of the target thread to the target shared resources can be controlled according to the result of the resource lock conflict detection.

[0092] In this embodiment of the application, for lock information applied on the same shared resource, conflict determination can be performed using the compatibility rules in Table 1 below.

[0093] Table 1

[0094] Is it compatible? Shared Lock S Exclusive lock X Intentional Shared Lock IS Intentional Exclusive Lock IX Shared Lock S yes no yes no Exclusive lock X no no no no Intention Shared Lock IS yes no yes yes Intentional Exclusive Lock IX no no yes yes

[0095] In some exemplary implementations, such as Figure 4 As shown, step S209 above may include the following when implemented:

[0096] S401, determine the lock information applied by other threads to the parent shared resource and the associated shared resource.

[0097] Specifically, the lock information applied by other threads to the parent shared and the associated shared resources is determined in the same way as the resource lock information of the target thread in the aforementioned embodiment of this application, and can be obtained based on the aforementioned steps S201 to S207.

[0098] S403, based on the lock information applied by the other threads to the parent shared resource and the associated shared resource, perform resource lock conflict detection on the second resource lock information to obtain the first resource lock conflict detection result.

[0099] The first resource lock conflict detection result indicates whether a conflict exists.

[0100] Specifically, continuing with the previous example, assuming the target thread performs a modification operation on table A, the resource lock information obtained by the target thread is shown in Table 2 below:

[0101] Table 2

[0102]

[0103]

[0104] Assuming that other threads are modifying table B, based on the aforementioned steps S201 to S207, the resource lock information acquired by these other threads is shown in Table 3 below:

[0105] Table 3

[0106] Shared resource ID Lock type / S / SB (the fragment corresponding to table B) X (Exclusive Lock) / S (stored process) IX (Intention Exclusivity Lock) / C / Z / B (Table B) X (Exclusive Lock) / C / Z (partition) IX (Intention Exclusivity Lock) / C (cluster) IX (Intention Exclusivity Lock)

[0107] Therefore, based on the lock information applied by other threads to the parent shared resource and the associated shared resource, the process of detecting resource lock conflicts on the second resource lock information of the target thread can be shown in Table 4 below:

[0108] Table 4

[0109] Shared resource ID Lock type Conflict detection / S (stored process) IX,IX no / S / SB (the fragment corresponding to table B) X no / S / SA (the fragment corresponding to table A) X no / C (cluster) IX,IX no / C / Z (partition) IX,IX no

[0110] Based on Table 4 above, the first resource lock conflict detection result is no conflict.

[0111] S405, based on the first resource lock conflict detection result and the first resource lock information, control the target thread's access to the target shared resource.

[0112] Specifically, when other threads and the target thread operate on shared resources at the same level in the logical resources, the lock information of both threads for the same parent shared resource is of the intention lock type. As shown in Table 1 above, the intention lock type is compatible with each other. Therefore, when multiple threads operate on different shared resources at the same level in the logical resources, adding any lock will not cause resource conflicts, thus greatly reducing the probability of resource conflicts.

[0113] For example, see [link to example]. Figure 4 When implementing step S405 above, if the first resource lock conflict detection result indicates no conflict, steps S407 to S413 can be executed; if the first resource lock conflict detection result indicates a conflict, step S415 can be executed, specifically as follows:

[0114] S407, if the first resource lock conflict detection result indicates no conflict, determine the shared resource accessed by the other threads.

[0115] It is understandable that the shared resources accessed by other threads may be the same as or different from the target shared resource. If they are different, step S409 can be executed; otherwise, steps S411 to S413 can be executed.

[0116] S409, if the shared resource accessed by the other threads is different from the target shared resource, then the target thread is used to perform the target operation on the target shared resource.

[0117] Specifically, if the shared resource accessed by other threads is different from the target shared resource, for example, if other threads access table B and the target thread accesses table A, then there will be no conflict between the other threads and the target thread regarding table resources. In this way, the resource access control server can use the target thread to perform the target operation on table A, such as modification or addition. That is to say, at this time, other threads and the target thread can perform operations in parallel.

[0118] S411, if the shared resource accessed by the other thread is the same as the target shared resource, then based on the lock information applied by the other thread to the target shared resource, resource lock conflict detection is performed on the first resource lock information to obtain a second resource lock conflict detection result.

[0119] Specifically, if the shared resource accessed by other threads is the same as the target shared resource, such as table A, then resource lock conflict detection needs to be performed on the lock information applied to table A by other threads and the lock information applied to table A by the target thread (i.e., the first resource lock information). For example, if other threads modify table A, they apply an exclusive lock X to table A. If the target thread also modifies table A, it also applies an exclusive lock X to table A. Then, by combining the compatibility rules of Table 1 mentioned above, the second resource lock conflict detection result can be obtained. Since exclusive lock X is incompatible with exclusive lock X, the second resource lock conflict detection result indicates that a conflict exists.

[0120] S413, based on the second resource lock conflict detection result, control the target thread's access to the target shared resource.

[0121] Specifically, if the second resource lock conflict detection result indicates that a conflict exists, the following step S415 can be executed; otherwise, if the second resource lock conflict detection result indicates that there is no conflict, the target thread is used to perform the target operation on the target shared resource.

[0122] S415, the target thread is put into a waiting execution state until there is no conflict.

[0123] In the above implementation, by subdividing and hierarchically layering large shared resources and simultaneously locking them locally, no resource conflict will occur when applying any lock to different shared resources. For locks applied to the same shared resource, the probability of overall resource conflict can be greatly reduced because the parent automatically holds an intention lock type with a lower probability of conflict. This greatly improves parallelism, enhances the efficiency of resource access, and reduces the complexity of locking code. While improving efficiency, it also reduces code complexity, lowers the difficulty of operation and maintenance, and effectively enhances the operational capabilities of the database.

[0124] Corresponding to the resource access control methods provided in the above embodiments, this application also provides a resource access control device. Since the resource access control device provided in this application corresponds to the resource access control methods provided in the above embodiments, the implementation methods of the aforementioned resource access control methods are also applicable to the resource access control device provided in this embodiment, and will not be described in detail in this embodiment.

[0125] Please see Figure 5 The diagram shown is a structural schematic of a resource access control device provided in an embodiment of this application. This device has the function of implementing the resource access control method in the above-described method embodiments. This function can be implemented in hardware or by hardware executing corresponding software. Figure 5 As shown, the resource access control device 500 may include:

[0126] The thread creation module 510 is used to obtain the target resource access request and create the target thread corresponding to the target resource access request; the target resource access request is used to request target operation on the target shared resource in the logical resource.

[0127] The upper-level associated resource determination module 520 is used to determine the parent shared resource corresponding to the target shared resource in the logical resource, as well as the associated shared resource of the target shared resource in the physical resource;

[0128] The first lock information determination module 530 is used to determine the first resource lock information of the target thread based on the operation type of the target operation; the first resource lock information indicates the lock type of the target shared resource;

[0129] The second lock information determination module 540 is used to determine the second resource lock information of the target thread based on the first resource lock information; the second resource lock information indicates the intended lock type of the parent shared resource and the lock type of the associated shared resource.

[0130] The access control module 550 is used to control the target thread's access to the target shared resource based on the first resource lock information and the second resource lock information.

[0131] In one exemplary implementation, the superior associated resource determination module 520 includes:

[0132] The calling module is used to call resource tree information, which includes logical resource branches and physical resource branches connected to the root node. The logical resource branches represent the hierarchical relationship between shared resources in the logical resources, and the physical resource branches represent the hierarchical relationship between shared resources in the physical resources.

[0133] The parent resource determination module is used to determine the first node corresponding to the target shared resource in the logical resource branch, and to determine the shared resources corresponding to each intermediate node between the first node and the root node in the logical resource branch as the parent shared resource.

[0134] The associated resource determination module is used to determine the second node corresponding to the target shared resource in the physical resource branch, and to determine the shared resource corresponding to the second node in the physical resource branch, as well as the shared resources corresponding to each intermediate node between the second node and the root node, as the associated shared resource.

[0135] In one exemplary embodiment, the first lock information determination module includes:

[0136] The first determining module is used to determine, when the target operation is a first operation type, the first resource lock information indicating an exclusive lock for the target thread; the first operation type changes the resource state of the operated resource;

[0137] The second determining module is used to determine the first resource lock information indicating a shared lock for the target thread when the target operation is a second operation type; the second operation type does not change the resource state of the operated resource.

[0138] In one exemplary embodiment, the second lock information determination module includes:

[0139] The third determining module is used to determine, when the first resource lock information indicates an exclusive lock, the target thread's second resource lock information indicates an intentional exclusive lock for the parent shared resource, the exclusive lock for the shared resource corresponding to the second node, and the intentional exclusive locks for the shared resources corresponding to each intermediate node between the second node and the root node.

[0140] The fourth determining module is used to determine, when the first resource lock information indicates a shared lock, the intended shared lock of the parent shared resource indicated by the second resource lock information of the target thread, the shared lock of the shared resource corresponding to the second node, and the intended shared lock of the shared resource corresponding to each intermediate node between the second node and the root node.

[0141] In one exemplary embodiment, the access control module 550 includes:

[0142] The other lock information determination module is used to determine the lock information applied by other threads to the parent shared resource and the associated shared resource;

[0143] The first conflict detection module is used to perform resource lock conflict detection on the second resource lock information based on the lock information applied by the other thread to the parent shared resource and the associated shared resource, and obtain the first resource lock conflict detection result;

[0144] The first access control submodule is used to control the target thread's access to the target shared resource based on the first resource lock conflict detection result and the first resource lock information.

[0145] In one exemplary implementation, the first access control submodule includes:

[0146] The fifth determining module is used to determine the shared resource accessed by the other thread when the first resource lock conflict detection result indicates that there is no conflict.

[0147] The access module is used to perform the target operation on the target shared resource using the target thread when the shared resource accessed by other threads is different from the target shared resource.

[0148] The second conflict detection module is used to perform resource lock conflict detection on the first resource lock information based on the lock information applied to the target shared resource by the other thread when the shared resource accessed by the other thread is the same as the target shared resource, and obtain the second resource lock conflict detection result.

[0149] The second access control submodule is used to control the target thread's access to the target shared resource based on the second resource lock conflict detection result.

[0150] In one exemplary implementation, the first access control submodule further includes:

[0151] The waiting module is used to put the target thread into a waiting execution state when the first resource lock conflict detection result indicates that there is a conflict, until the first resource lock conflict detection result indicates that there is no conflict.

[0152] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.

[0153] This application provides an electronic device including a processor and a memory. The memory stores at least one instruction or at least one program segment, which is loaded and executed by the processor to implement any of the resource access control methods provided in the above method embodiments.

[0154] Memory can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for the functions, etc.; the data storage area can store data created based on the use of the device, etc. Furthermore, memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory can also include a memory controller to provide the processor with access to the memory.

[0155] The methods and embodiments provided in this application can be executed in a computer terminal, server, or similar computing device; that is, the aforementioned electronic device may include a computer terminal, server, or similar computing device. Taking running on a server as an example... Figure 6 This is a hardware structure block diagram of an electronic device running a resource access control method provided in an embodiment of this application, such as... Figure 6 As shown, the server 600 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 610 (CPUs 610 may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), a memory 630 for storing data, and one or more storage media 620 (e.g., one or more mass storage devices) for storing application programs 623 or data 622. The memory 630 and storage media 620 may be temporary or persistent storage. The program stored in the storage media 620 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 610 may be configured to communicate with the storage media 620 and execute the series of instruction operations stored in the storage media 620 on the server 600. Server 600 may also include one or more power supplies 660, one or more wired or wireless network interfaces 650, one or more input / output interfaces 640, and / or one or more operating systems 621, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0156] The input / output interface 640 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 600. In one example, the input / output interface 640 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 640 may be a radio frequency (RF) module for wireless communication with the Internet.

[0157] Those skilled in the art will understand that Figure 6 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 600 may also include... Figure 6 The more or fewer components shown, or having the same Figure 6 The different configurations shown.

[0158] Embodiments of this application also provide a computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a resource access control method. The at least one instruction or the at least one program is loaded and executed by the processor to implement any of the resource access control methods provided in the above-described method embodiments.

[0159] Embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform any of the resource access control methods provided in the above-described method embodiments.

[0160] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0161] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0162] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0163] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0164] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A resource access control method, characterized in that, The method includes: Obtain a target resource access request and create a target thread corresponding to the target resource access request; the target resource access request is used to request a target operation on a target shared resource in the logical resources. Determine the parent shared resource corresponding to the target shared resource in the logical resources, and the associated shared resources of the target shared resource in the physical resources; Based on the operation type of the target operation, the first resource lock information of the target thread is determined; the first resource lock information indicates the lock type of the target shared resource; Based on the first resource lock information, the second resource lock information of the target thread is determined; the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource; Based on the first resource lock information and the second resource lock information, the access of the target thread to the target shared resource is controlled.

2. The method according to claim 1, characterized in that, Determining the parent shared resource corresponding to the target shared resource in the logical resource, and the associated shared resource of the target shared resource in the physical resource includes: The resource tree information is invoked, which includes logical resource branches and physical resource branches connected to the root node. The logical resource branches represent the hierarchical relationship between shared resources in the logical resources, and the physical resource branches represent the hierarchical relationship between shared resources in the physical resources. Determine the first node corresponding to the target shared resource in the logical resource branch, and determine the shared resources corresponding to each intermediate node between the first node and the root node in the logical resource branch as the parent shared resource; The second node corresponding to the target shared resource in the physical resource branch is determined, and the shared resources corresponding to the second node in the physical resource branch, as well as the shared resources corresponding to each intermediate node between the second node and the root node, are determined as the associated shared resources.

3. The method according to claim 2, characterized in that, The determination of the first resource lock information of the target thread based on the operation type of the target operation includes: If the target operation is of the first operation type, the first resource lock information of the target thread is determined to indicate an exclusive lock; the first operation type changes the resource state of the operated resource. When the target operation is of the second operation type, the first resource lock information of the target thread is determined to be a shared lock; the second operation type does not change the resource state of the operated resource.

4. The method according to claim 3, characterized in that, The step of determining the second resource lock information of the target thread based on the first resource lock information includes: When the first resource lock information indicates an exclusive lock, the second resource lock information of the target thread indicates an intentional exclusive lock of the parent shared resource, an exclusive lock of the shared resource corresponding to the second node, and an intentional exclusive lock of the shared resource corresponding to each intermediate node between the second node and the root node. When the first resource lock information indicates a shared lock, the second resource lock information of the target thread indicates the intended shared lock of the parent shared resource, the shared lock of the shared resource corresponding to the second node, and the intended shared lock of the shared resources corresponding to each intermediate node between the second node and the root node.

5. The method according to claim 1, characterized in that, The step of controlling the target thread's access to the target shared resource based on the first resource lock information and the second resource lock information includes: Determine the lock information applied by other threads to the parent shared resource and the associated shared resource; Based on the lock information applied by the other threads to the parent shared resource and the associated shared resource, resource lock conflict detection is performed on the second resource lock information to obtain the first resource lock conflict detection result; Based on the first resource lock conflict detection result and the first resource lock information, the access of the target thread to the target shared resource is controlled.

6. The method according to claim 5, characterized in that, The step of controlling the target thread's access to the target shared resource based on the first resource lock conflict detection result and the first resource lock information includes: If the first resource lock conflict detection result indicates that there is no conflict, determine the shared resource accessed by the other threads; If the shared resource accessed by the other threads is different from the target shared resource, then the target thread is used to perform the target operation on the target shared resource; If the shared resource accessed by the other threads is the same as the target shared resource, then based on the lock information applied by the other threads to the target shared resource, resource lock conflict detection is performed on the first resource lock information to obtain the second resource lock conflict detection result; Based on the second resource lock conflict detection result, the access of the target thread to the target shared resource is controlled.

7. The method according to claim 6, characterized in that, The method further includes: If the first resource lock conflict detection result indicates that a conflict exists, the target thread will enter a waiting execution state until the first resource lock conflict detection result indicates that there is no conflict.

8. A resource access control device, characterized in that, The device includes: The thread creation module is used to obtain a target resource access request and create a target thread corresponding to the target resource access request; the target resource access request is used to request a target operation on a target shared resource in the logical resources. The upper-level associated resource determination module is used to determine the parent shared resource corresponding to the target shared resource in the logical resources, and the associated shared resources of the target shared resource in the physical resources; The first lock information determination module is used to determine the first resource lock information of the target thread based on the operation type of the target operation; the first resource lock information indicates the lock type of the target shared resource; The second lock information determination module is used to determine the second resource lock information of the target thread based on the first resource lock information; the second resource lock information indicates the intention lock type of the parent shared resource and the lock type of the associated shared resource; The access control module is used to control the target thread's access to the target shared resource based on the first resource lock information and the second resource lock information.

9. An electronic device, characterized in that, The system includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the resource access control method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the resource access control method as described in any one of claims 1 to 7.

11. A computer program, characterized in that, When the computer program is executed by the processor, it implements the resource access control method according to any one of claims 1 to 7.