CN110888858A - Database operation method and device, storage medium and electronic device - Google Patents

Database operation method and device, storage medium and electronic device Download PDF

Info

Publication number
CN110888858A
CN110888858A CN201911040315.8A CN201911040315A CN110888858A CN 110888858 A CN110888858 A CN 110888858A CN 201911040315 A CN201911040315 A CN 201911040315A CN 110888858 A CN110888858 A CN 110888858A
Authority
CN
China
Prior art keywords
account
lock
lock resource
target
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911040315.8A
Other languages
Chinese (zh)
Other versions
CN110888858B (en
Inventor
高子叶
刘羽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201911040315.8A priority Critical patent/CN110888858B/en
Publication of CN110888858A publication Critical patent/CN110888858A/en
Application granted granted Critical
Publication of CN110888858B publication Critical patent/CN110888858B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses an operation method and device of a database, a storage medium and an electronic device. Wherein, the method comprises the following steps: the method comprises the steps of obtaining a first request of a first account, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client; under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources; and executing target operation on the target data under the condition of preempting the second lock resource for the first account. The method and the device solve the technical problem of inconsistent data of the database in the related technology.

Description

Database operation method and device, storage medium and electronic device
Technical Field
The application relates to the field of internet, in particular to an operation method and device of a database, a storage medium and an electronic device.
Background
With the rapid development of information-based construction, an information system becomes a key for an enterprise to maintain business operation, and the enterprise urgently needs to improve the availability of the information system, ensure the continuity of business and reduce the loss caused by disasters or faults to the maximum extent. On the other hand, diversified service types lead to the increasing complication of data access requirements, the database server is also overloaded due to the rapid rise of the data volume, and the enterprises also urgently need to improve the operation efficiency of the information system.
In a large-scale event (such as annual celebration of a company and shopping festival), for example, the data read-write quantity is extremely large: the user can initiate the invitation of changing cards when interacting, invite the friend help to replace the cards, in order to reach the purpose that the card sum is the fixed number (for example for 9), this user friend can hold the card condition according to oneself, replace the card, help accomplishes the activity task, just so the condition that a plurality of users updated the same card simultaneously can appear, cause the inconsistent problem of data update, and the card that is used for replacing is when going to replace other people's card, oneself also has the possibility of being replaced, need guarantee the uniformity of a plurality of data updates this moment.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the application provides an operation method and device of a database, a storage medium and an electronic device, and aims to at least solve the technical problem of inconsistent data of the database in the related art.
According to an aspect of an embodiment of the present application, there is provided an operation method of a database, including: the method comprises the steps of obtaining a first request of a first account, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client; under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources; and executing target operation on the target data under the condition of preempting the second lock resource for the first account.
According to another aspect of the embodiments of the present application, there is also provided an operating device for a database, including: the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a first request of a first account, the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client; the preemption unit is used for preempting a second lock resource for the first account under the condition that the first lock resource is determined to be allocated to the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources; and the operation unit is used for executing target operation on the target data under the condition of preempting the second lock resource for the first account.
According to another aspect of the embodiments of the present application, there is also provided a storage medium including a stored program which, when executed, performs the above-described method.
According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the above method through the computer program.
In the embodiment of the application, a first request for acquiring a first account is adopted, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client; under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources; the method comprises the steps of executing target operation on target data in a mode of preempting second lock resources for a first account, limiting the concurrency amount of data operation on each server through the number of the first lock resources, acquiring the operation authority of the target data through the second lock resources and an operand of the same target data in a mode of preempting the lock resources, avoiding inconsistency of data updating when a large number of requests simultaneously request to operate the same target data, and solving the technical problem of inconsistency of data of databases in related technologies.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a schematic diagram of a hardware environment for a method of operation of a database according to an embodiment of the present application;
FIG. 2 is a flow chart of an alternative method of operation of a database according to an embodiment of the present application;
FIG. 3 is a schematic diagram of an alternative server and database system according to an embodiment of the present application;
FIG. 4 is a flow chart of an alternative method of operation of a database according to an embodiment of the present application;
FIG. 5 is a schematic diagram of an alternative database operating apparatus according to an embodiment of the present application;
and
fig. 6 is a block diagram of a terminal according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
First, partial nouns or terms appearing in the description of the embodiments of the present application are applicable to the following explanations:
redis (named as Remote Dictionary Server) is an open source log-type and Key-Value database written in ANSIC language, supporting network, based on memory and enduring, and provides API of multiple languages.
Cookies, and sometimes their complex forms, refer to data (usually encrypted) that certain websites store on the user's local terminal for purposes of identifying and tracking the user's identity.
According to an aspect of embodiments of the present application, there is provided a method embodiment of a method of operating a database.
Alternatively, in the present embodiment, the operation method of the database may be applied to a hardware environment formed by the terminal 101 and the server 103 as shown in fig. 1. As shown in fig. 1, a server 103 is connected to a terminal 101 through a network, which may be used to provide services (such as game services, multimedia services, etc.) for the terminal or a client installed on the terminal, and a database 105 may be provided on the server or separately from the server for providing data storage services for the server 103, and the network includes but is not limited to: the terminal 101 is not limited to a PC, a mobile phone, a tablet computer, and the like. The database operation method according to the embodiment of the present application may be executed by the server 103, or may be executed by both the server 103 and the terminal 101.
Fig. 2 is a flow chart of an alternative method of operating a database according to an embodiment of the present application, which may include the following steps, as shown in fig. 2:
step S202, a first request of a first account is obtained, where the first request is used to request a server to perform a target operation on target data in a database, the first account is used for being used on a client, and the database is used to provide a service for the client.
The client is a client installed on the terminal, and can be a multimedia content client, a game client, a live broadcast client, a communication client and the like, and the description is given by taking a video client as an example in the following; the first account, i.e. the account used in the client, may be a mobile phone number, an instant messaging account, a temporary account, etc.; the database is used for providing data required by service for a client, and comprises the target data; the target operation comprises the operations of updating, deleting, replacing and the like of the target data.
Step S204, under the condition that the first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of the data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources.
The number of the servers may be multiple, and for each server, the number of the first lock resources on the server defines a concurrency amount of data operations concurrently executed by the server, for example, there are N first lock resources, and the concurrency amount is N (the value of N is an integer greater than or equal to 1, such as 5); for the first account, the next operation can be carried out only if the first lock resource is obtained, namely, the second lock resource is preempted, and the target operation is carried out after the second lock resource is preempted; the data operation is an operation (including the above target operation) on the data, such as modifying, deleting, adding, supplementing and the like.
The lock resource is equivalent to a virtual lock simulating a "physical lock", and the locked object is "data", where the virtual lock may be managed by software, such as a software instance, and a specific instance is a program code that runs in JAVA in a new form and has logic functions of "generating a lock, distributing a lock, recovering a lock", and the like.
And step S206, executing target operation on the target data under the condition of occupying the second lock resource for the first account.
Through the steps, the concurrency of data operation on each server is limited through the number of the first lock resources, the operation authority of the target data is obtained through the operand of the second lock resources to the same target data in a mode of preempting the lock resources, the phenomenon that data updating is inconsistent when a large number of requests simultaneously request to operate the same target data is avoided, and the technical problem of data inconsistency of databases in related technologies can be solved. The technical solution of the present application is further detailed below with reference to the steps shown in fig. 2.
In the technical solution provided in step S202, a first request of a first account is obtained, where the first request is used to request a server to execute a target operation on target data in a database.
The database is a distributed database, including but not limited to a Key-value NoSQL type database (e.g., Redis rich, etc.), a column family NoSQL type database (also called a wind column store, e.g., hbasecraandra, etc.), and a document NoSQL (e.g., mongodb, etc.). The database is referred to as Redis for illustration.
In the technical solution provided in step S204, under the condition that it is determined that the first lock resource is allocated to the first account, the second lock resource is preempted for the first account.
For a single server, before determining a target instance in the multiple instances, sequentially increasing lock identification IDs (e.g., 1 to N) may be generated, the multiple instances are generated according to a preset threshold (i.e., N), and a concurrency amount of data operations concurrently executed by the server is defined by the preset threshold; a plurality of instances and a lock identification corresponding to each of the plurality of instances are stored in a hash container (e.g., a convurrenthashmap).
The ConcurrentHashMap container is provided with a plurality of locks (namely lock resources), each lock is used for locking a part of data (namely data corresponding to the lock resources) in the container, so when the data of different data sections in the container is accessed in multiple threads, lock competition does not exist among the threads, and the concurrent access efficiency can be effectively improved.
In the above embodiment, the first account may obtain the first lock resource according to the following steps S2042 to S2044:
step S2042, determining a target instance of the multiple instances, where the target instance is an instance allocated for the first account, and the multiple instances are instances generated on the server for allocating the first lock resource.
Optionally, when determining a target instance in the multiple instances, in a case that an instance already allocated to the first account exists in the multiple instances (in other words, the request was initiated before the first account, the request is a repeatedly initiated request, and an instance has already been allocated to the request before the first account), the instance already allocated to the first account is taken as the target instance; and under the condition that the plurality of instances do not have the instance allocated to the first account, allocating a target instance to the first account from the plurality of instances, wherein the lock identifier corresponding to the target instance is matched with the account identifier of the first account, for example, the account identifier hashcode of the first account is subjected to modular extraction to obtain a lock identifier ID, and then the instance of the lock identifier lock ID is taken as the target instance.
Step S2044, a first lock resource to which the target instance belongs is allocated to the first account.
Optionally, when allocating a first lock resource to which the target instance belongs to the first account, sending a first preemption request to the target instance, where the first preemption request is used to request the target instance to allocate the first lock resource to the first account; and under the condition that the received first response message of the target instance indicates that the preemption is successful, allocating the first lock resource indicated by the first response message to the first account, and under the condition that the first response message indicates that the preemption is failed, returning a prompt of operation failure to the first account.
Preempting the second lock resource for the first account, in a manner similar to the aforementioned preempting of the first lock resource, includes: sending a second preemption request to the database, wherein the second preemption request is used for requesting the database to allocate a second lock resource corresponding to the target data to the first account; and under the condition that the received second response message of the database indicates that the preemption is successful, allocating the second lock resource indicated by the second response message to the first account, and under the condition that the second response message indicates that the preemption is failed, returning a prompt of operation failure to the first account.
Optionally, the second lock resource is adapted to the type of the database, for example, when the database is Redis, the second lock resource may be a lock resource implemented by setnx; when the database is Hbase, the second lock resource may be a lock resource implemented by a ReadWriteLock class in jdk, and similarly, the rest types of databases are similar to the above, and the description will be continued with an example in which the database is Redis and the second lock resource is setnx. The second lock resource is of a different type than the first lock resource, the second lock resource being for use by the distributed database, e.g., setnx, and the first lock resource being for use by the server, e.g., renentrntlock.
In the technical solution provided in step S206, when the second lock resource is seized for the first account, a target operation is performed on the target data, such as updating, exchanging, deleting, and the like of the card.
Optionally, after the target operation is performed on the target data, the association between the first lock resource, the second lock resource, and the first account is released, and the first lock resource and the second lock resource, which are released from the association with the first account, are allowed to be preempted by any other account, and of course, the first account may also reinitiate new preemption.
The technical scheme of the application can be used for data updating in a high-concurrency scene, and the problem of how to ensure data updating consistency by updating multiple data in one operation in the high-concurrency scene through the combination of a first type lock (ReentrntLock) of the server and a Redis distributed lock (such as setnx) is solved.
As an alternative embodiment, the following description will take an example of applying the technical solution of the present application to guarantee the consistency of card data:
if only a distributed lock is adopted, such as a setnx mode of the Redis, it can be guaranteed that the behavior of multiple requests for preempting the lock is performed smoothly under the condition of small concurrency, but in the process of pressure testing of the server, the situation that the same card is used twice or for multiple times occasionally still occurs, which indicates that under a high concurrency scene, the data for preempting one Redis distributed lock may occur to cause inconsistency due to multiple preemptions in the process of synchronizing multiple machines in the Redis cluster, and therefore a method is needed for solving the problem.
In order to ensure consistency of multiple data updates in a high concurrency scenario, in the system architecture shown in fig. 3, a server cluster (for example, including 2 servers) and a Redis database cluster (for example, taking a master and a slave), are included, based on a Redis distributed lock used in a service, a rentrandlock is added to a single server to limit concurrency conditions inside the single server, and before trying to preempt the Redis distributed lock, the corresponding rentrandlock (i.e., a lock in a container, or a lock resource) needs to be preempted first, so that concurrency conditions on the single server are controlled, and accuracy of data update storage and stability of the service are ensured. The specific implementation steps are shown in fig. 4:
on a single server, after the service is started, a certain number of resetlock instances (i.e., multiple instances) are generated in advance, for example, lock ids which are sequentially increased from 0 are generated, each lock id correspondingly generates one resetlock instance, and the lock id and the resetlock instances are stored in a securrenthashmap, so that the characteristic that the securrenthashmap is suitable for high-concurrency scenes is utilized.
In step S402, the user accesses an interface, for example, a data update interface provided by the server when the user updates the card.
In step S404, a lock generated in advance is searched for in the container ConcurrentHashMap.
If a user needs to obtain a corresponding reitrantlock instance when performing card number updating operation, a login user id (i.e. an account number of the user) is obtained through a user cookie, a lock id is obtained by performing modulo operation according to a hash code of the login user id and the number of the reitrantlocks, and a reitrantlock instance corresponding to the lock id is obtained through a ConcurrentHashMap, for example, the user id is 123, the number of the reitrantlocks is 10, and the modulo result is 3, then a lock with the lock id of 3 is tried to be allocated to the user.
Step S406, after the ReetrantLock instance is obtained, trying to preempt the first lock resource, and solving the problem that the concurrency of a single server is too large.
tryLock () is used to preempt lock resources, and only when the lock resources are preempted successfully, the subsequent operation can be performed.
It should be noted that, if only the distributed lock is used, in a case of high concurrency, a single server may have multiple requests instantaneously, and a distributed lock of Redis is obtained at the same time, which results in dirty data, so a rentrantlock is added to the single server, which controls the concurrency problem on the single server, and controls concurrency by preempting the lock in order to ensure data accuracy and prevent the same data from being updated at the same time; redis distributed locks are continuously used among a plurality of servers, and the problem of concurrent data updating of the services is solved.
Step S408, under the condition that the lock is seized unsuccessfully, directly returning the code corresponding to the operation failure for the service performance.
And step S410, acquiring a first lock resource ReetrantLock under the condition that the lock is successfully preempted.
Step S412, under the condition that the first lock resource ReetrantLock is obtained in a failure mode, directly returning the code with the corresponding operation failure, and releasing the ReetrantLock resource.
And step S414, after the ReetrantLock locks are successfully preempted, the preemption operation of the Redis distributed locks is continued, namely, the second preemption is tried, so as to solve the problem of overlarge concurrency among a plurality of servers in the service.
And trying to preempt a Redis distributed lock corresponding to the card data id to be modified through a setnx mode of Redis, and performing data updating storage operation only when the Redis distributed lock is successfully preempted.
And step S416, under the condition that the Redis distributed lock is unsuccessfully preempted, directly returning the code corresponding to the operation failure, and releasing the distributed lock resource and the ReetrantLock of the Redis.
And step S418, under the condition that the Redis distributed lock is successfully preempted, obtaining the Redis distributed lock corresponding to the card data id to be modified.
Step S420, when the Redis distributed lock corresponding to the card data id to be modified is obtained, if the obtaining is failed due to abnormity, the code with the corresponding operation failure is returned, and the distributed lock resource and the ReetrantLock lock of the Redis are released.
And step S422, after the Redis distributed lock corresponding to the card data id to be modified is obtained, updating the data.
If the operation of exchanging numbers of the cards of two users is involved, the operation is required to be carried out on the two updated users, and the consistency of the updating of the numbers of the two cards is ensured.
In step S424, after the operation, whether the lock succeeds or fails, the locks that have been successfully preempted need to be sequentially released.
In Redis, distributed lock data corresponding to the card id is cleared, and an unLock () method is performed in the reretratlock instance to release the reretratlock.
The above embodiments are described by taking card games as an example, and after the user participates in the game, the user can obtain cards and exchange the cards to achieve conditions for drawing a lottery. The scheme of the application can be used for controlling concurrency control in the mahjong changing process, and it should be noted that other scenes requiring concurrent updating of the same data are also applicable to the technical scheme of the application.
According to the scheme, the data consistency updating in a high-concurrency scene (such as video, reading, social contact, education, finance and other end products and application thereof) is realized by combining the ReentranLock with the Redis distributed lock.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present application.
According to another aspect of the embodiment of the present application, there is also provided an operation apparatus for a database, which is used for implementing the operation method for the database. Fig. 5 is a schematic diagram of an alternative database operating apparatus according to an embodiment of the present application, and as shown in fig. 5, the apparatus may include:
an obtaining unit 501, configured to obtain a first request of a first account, where the first request is used to request a server to perform a target operation on target data in a database, the first account is used for being used on a client, and the database is used to provide a service for the client;
a preemption unit 503, configured to preempt, for a first account, a second lock resource when it is determined that the first lock resource is allocated to the first account, where the first lock resource is used to limit a concurrency amount of data operations concurrently executed by a server to be less than or equal to a preset threshold, and the second lock resource and the first lock resource are different types of lock resources;
and an operation unit 505, configured to perform a target operation on the target data when the second lock resource is preempted for the first account.
It should be noted that the obtaining unit 501 in this embodiment may be configured to execute step S202 in this embodiment, the preemption unit 503 in this embodiment may be configured to execute step S204 in this embodiment, and the operating unit 505 in this embodiment may be configured to execute step S206 in this embodiment.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of the above embodiments. It should be noted that the modules described above as a part of the apparatus may operate in a hardware environment as shown in fig. 1, and may be implemented by software or hardware.
Through the modules, the concurrency of data operation on each server is limited through the number of the first lock resources, the operation authority of the target data is obtained through the operand of the second lock resources to the same target data in a mode of preempting the lock resources, the phenomenon that data updating is inconsistent when a large number of requests simultaneously request to operate the same target data is avoided, and the technical problem of data inconsistency of databases in related technologies can be solved.
Optionally, the preemption unit may include: a determining module, configured to determine a target instance of a plurality of instances, where the target instance is an instance allocated for a first account, and the plurality of instances are instances generated on a server for allocating a first lock resource; and the distribution module is used for distributing the first lock resource to which the target instance belongs to the first account.
Optionally, the determining module may be further configured to: in the case that the instance allocated to the first account exists in the plurality of instances, taking the instance allocated to the first account as a target instance; and in the case that the plurality of instances do not have the instance which is allocated to the first account, allocating a target instance to the first account from the plurality of instances, wherein the lock identification corresponding to the target instance is matched with the account identification of the first account.
Optionally, the allocation module may be further configured to: sending a first preemption request to a target instance, wherein the first preemption request is used for requesting the target instance to allocate a first lock resource for a first account; and in the case that the received first response message of the target instance indicates that the preemption is successful, allocating the first lock resource indicated by the first response message to the first account.
Optionally, the apparatus of the present application may further include a generating unit, configured to generate the multiple instances according to a preset threshold before determining a target instance of the multiple instances, where the preset threshold is used to limit a concurrency amount of data operations concurrently executed by the server; a plurality of instances and a lock identification corresponding to each instance in the plurality of instances are stored.
Optionally, the preemption unit is further operable to: sending a second preemption request to the database, wherein the second preemption request is used for requesting the database to allocate a second lock resource corresponding to the target data to the first account; and in the case that the received second response message of the database indicates that the preemption is successful, allocating the second lock resource indicated by the second response message to the first account.
Optionally, the apparatus of the present application may further include a releasing unit, configured to release the association between the first lock resource, the second lock resource, and the first account after the target operation is performed on the target data, where the first lock resource and the second lock resource that release the association with the first account are allowed to be preempted by the second account.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of the above embodiments. It should be noted that the modules described above as a part of the apparatus may be operated in a hardware environment as shown in fig. 1, and may be implemented by software, or may be implemented by hardware, where the hardware environment includes a network environment.
According to another aspect of the embodiment of the present application, there is also provided a server or a terminal for implementing the operation method of the database.
Fig. 6 is a block diagram of a terminal according to an embodiment of the present application, and as shown in fig. 6, the terminal may include: one or more processors 601 (only one of which is shown in fig. 6), a memory 603, and a transmitting device 605, as shown in fig. 6, the terminal may further include an input-output device 607.
The memory 603 may be used to store software programs and modules, such as program instructions/modules corresponding to the database operation method and apparatus in the embodiment of the present application, and the processor 601 executes various functional applications and data processing by running the software programs and modules stored in the memory 603, that is, implementing the above-mentioned database operation method. The memory 603 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 603 may further include memory located remotely from the processor 601, which may be connected to the terminal through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The above-mentioned transmission device 605 is used for receiving or sending data via a network, and may also be used for data transmission between a processor and a memory. Examples of the network may include a wired network and a wireless network. In one example, the transmission device 605 includes a Network adapter (NIC) that can be connected to a router via a Network cable and other Network devices to communicate with the internet or a local area Network. In one example, the transmission device 605 is a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
Among them, the memory 603 is used to store an application program, in particular.
The processor 601 may call the application stored in the memory 603 through the transmission device 605 to perform the following steps:
the method comprises the steps of obtaining a first request of a first account, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client;
under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources;
and executing target operation on the target data under the condition of preempting the second lock resource for the first account.
The processor 601 is further configured to perform the following steps:
determining a target instance of a plurality of instances, wherein the target instance is an instance allocated for the first account, and the plurality of instances are instances generated on the server for allocating the first lock resource;
a first lock resource to which the target instance belongs is allocated to the first account.
By adopting the embodiment of the application, a first request for acquiring a first account is adopted, the first request is used for requesting a server to execute target operation on target data in a database, the first account is used on a client, and the database is used for providing service for the client; under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources; the method comprises the steps of executing target operation on target data in a mode of preempting second lock resources for a first account, limiting the concurrency amount of data operation on each server through the number of the first lock resources, acquiring the operation authority of the target data through the second lock resources and an operand of the same target data in a mode of preempting the lock resources, avoiding inconsistency of data updating when a large number of requests simultaneously request to operate the same target data, and solving the technical problem of inconsistency of data of databases in related technologies.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment is not described herein again.
It can be understood by those skilled in the art that the structure shown in fig. 6 is only an illustration, and the terminal may be a terminal device such as a smart phone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, and a Mobile Internet Device (MID), a PAD, etc. Fig. 6 is a diagram illustrating a structure of the electronic device. For example, the terminal may also include more or fewer components (e.g., network interfaces, display devices, etc.) than shown in FIG. 6, or have a different configuration than shown in FIG. 6.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by a program instructing hardware associated with the terminal device, where the program may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), magnetic or optical disks, and the like.
Embodiments of the present application also provide a storage medium. Alternatively, in the present embodiment, the storage medium may be used for program codes for executing an operation method of a database.
Optionally, in this embodiment, the storage medium may be located on at least one of a plurality of network devices in a network shown in the above embodiment.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps:
the method comprises the steps of obtaining a first request of a first account, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client;
under the condition that a first lock resource is determined to be allocated to the first account, preempting a second lock resource for the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operation executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources;
and executing target operation on the target data under the condition of preempting the second lock resource for the first account.
Optionally, the storage medium is further arranged to store program code for performing the steps of:
determining a target instance of a plurality of instances, wherein the target instance is an instance allocated for the first account, and the plurality of instances are instances generated on the server for allocating the first lock resource;
a first lock resource to which the target instance belongs is allocated to the first account.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment is not described herein again.
Optionally, in this embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
The integrated unit in the above embodiments, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or a part of or all or part of the technical solution contributing to the prior art may be embodied in the form of a software product stored in a storage medium, and including instructions for causing one or more computer devices (which may be personal computers, servers, network devices, or the like) to execute all or part of the steps of the method described in the embodiments of the present application.
In the above embodiments of the present application, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed client may be implemented in other manners. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The foregoing is only a preferred embodiment of the present application and it should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.

Claims (10)

1. A method of operating a database, comprising:
the method comprises the steps of obtaining a first request of a first account, wherein the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client;
preempting a second lock resource for the first account under the condition that the first lock resource is determined to be allocated to the first account, wherein the first lock resource is used for limiting the concurrency quantity of data operations executed concurrently by the server to be less than or equal to a preset threshold value, and the second lock resource and the first lock resource are different types of lock resources;
and executing the target operation on the target data under the condition that the second lock resource is preempted for the first account.
2. The method of claim 1, further comprising allocating the first lock resource for the first account as follows:
determining a target instance of a plurality of instances, wherein the target instance is an instance allocated for the first account, and the plurality of instances are instances generated on the server for allocating the first lock resource;
and allocating the first lock resource to which the target instance belongs to the first account.
3. The method of claim 2, wherein determining the target instance of the plurality of instances comprises:
in the case that the instance allocated to the first account exists in the plurality of instances, taking the instance allocated to the first account as the target instance;
and under the condition that no instance which is already allocated to the first account exists in the multiple instances, allocating the target instance to the first account from the multiple instances, wherein the lock identification corresponding to the target instance is matched with the account identification of the first account.
4. The method of claim 2, wherein allocating the first lock resource to which the target instance belongs to the first account comprises:
sending a first preemption request to the target instance, wherein the first preemption request is used for requesting the target instance to allocate the first lock resource for the first account;
and in the case that the received first response message of the target instance indicates that the preemption is successful, allocating the first lock resource indicated by the first response message to the first account.
5. The method of claim 2, wherein prior to determining the target instance of the plurality of instances, the method comprises:
generating the multiple instances according to the preset threshold, wherein the preset threshold is used for limiting the concurrency amount of the data operation executed by the server concurrently;
and saving the plurality of instances and the lock identification corresponding to each instance in the plurality of instances.
6. The method of any of claims 1 to 5, wherein preempting a second lock resource for the first account number comprises:
sending a second preemption request to the database, wherein the second preemption request is used for requesting the database to allocate the second lock resource corresponding to the target data to the first account;
and in the case that the received second response message of the database indicates that the preemption is successful, allocating the second lock resource indicated by the second response message to the first account.
7. The method of any of claims 1 to 5, wherein after performing the target operation on the target data, the method further comprises:
and releasing the association among the first lock resource, the second lock resource and the first account, wherein the first lock resource and the second lock resource which are released from the association with the first account are allowed to be preempted by a second account.
8. An apparatus for operating a database, comprising:
the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a first request of a first account, the first request is used for requesting a server to execute target operation on target data in a database, the first account is used for being used on a client, and the database is used for providing service for the client;
a preemption unit, configured to preempt, for a first account, a second lock resource when it is determined that the first account is allocated with the first lock resource, where the first lock resource is used to limit a concurrency amount of data operations concurrently executed by the server to be less than or equal to a preset threshold, and the second lock resource and the first lock resource are different types of lock resources;
and the operation unit is used for executing the target operation on the target data under the condition that the second lock resource is preempted for the first account.
9. A storage medium, characterized in that the storage medium comprises a stored program, wherein the program when executed performs the method of any of the preceding claims 1 to 7.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the method of any of the preceding claims 1 to 7 by means of the computer program.
CN201911040315.8A 2019-10-29 2019-10-29 Database operation method and device, storage medium and electronic device Active CN110888858B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911040315.8A CN110888858B (en) 2019-10-29 2019-10-29 Database operation method and device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911040315.8A CN110888858B (en) 2019-10-29 2019-10-29 Database operation method and device, storage medium and electronic device

Publications (2)

Publication Number Publication Date
CN110888858A true CN110888858A (en) 2020-03-17
CN110888858B CN110888858B (en) 2023-06-30

Family

ID=69746606

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911040315.8A Active CN110888858B (en) 2019-10-29 2019-10-29 Database operation method and device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN110888858B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112817995A (en) * 2021-02-22 2021-05-18 北京奇艺世纪科技有限公司 Data processing method and device, electronic equipment and storage medium
CN113836161A (en) * 2021-09-30 2021-12-24 紫光云技术有限公司 Method for realizing timed task atomicity by using database lock
CN113918530A (en) * 2021-12-14 2022-01-11 北京达佳互联信息技术有限公司 Method and device for realizing distributed lock, electronic equipment and medium
CN113986850A (en) * 2021-10-27 2022-01-28 北京天宇威视科技股份有限公司 Storage method, device, equipment and computer readable storage medium of electronic file
CN115269207A (en) * 2022-09-29 2022-11-01 浙江省公众信息产业有限公司无线运营分公司 Method and system for allocating resources to vCPE network elements
CN115809301A (en) * 2023-02-03 2023-03-17 天翼云科技有限公司 Database processing method and device, electronic equipment and readable storage medium

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4716528A (en) * 1986-02-03 1987-12-29 International Business Machines Corporation Method for managing lock escalation in a multiprocessing, multiprogramming environment
US6178440B1 (en) * 1997-01-25 2001-01-23 International Business Machines Corporation Distributed transaction processing system implementing concurrency control within the object request broker and locking all server objects involved in a transaction at its start
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
DE102009042128A1 (en) * 2009-09-18 2011-03-24 Siemens Aktiengesellschaft Method and system for using temporary exclusive locks for parallel resource access
CN106354795A (en) * 2016-08-26 2017-01-25 南威软件股份有限公司 Distributed data exchanging system
CN106528876A (en) * 2016-12-09 2017-03-22 北京奇虎科技有限公司 Information processing method for distributed system and distributed information processing system
CN107977376A (en) * 2016-10-24 2018-05-01 腾讯科技(深圳)有限公司 Distributed data base system and transaction methods
CN108319496A (en) * 2017-01-18 2018-07-24 阿里巴巴集团控股有限公司 resource access method, service server, distributed system and storage medium
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
CN109901798A (en) * 2019-02-27 2019-06-18 新华三技术有限公司成都分公司 Date storage method and device
CN110032424A (en) * 2019-01-28 2019-07-19 阿里巴巴集团控股有限公司 The implementation method and device of distributed lock
CN110231979A (en) * 2019-05-07 2019-09-13 深圳壹账通智能科技有限公司 Transaction methods, device, equipment and storage medium based on block chain

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4716528A (en) * 1986-02-03 1987-12-29 International Business Machines Corporation Method for managing lock escalation in a multiprocessing, multiprogramming environment
US6178440B1 (en) * 1997-01-25 2001-01-23 International Business Machines Corporation Distributed transaction processing system implementing concurrency control within the object request broker and locking all server objects involved in a transaction at its start
CN101364230A (en) * 2008-09-24 2009-02-11 金蝶软件(中国)有限公司 Concurrent access control method and device
DE102009042128A1 (en) * 2009-09-18 2011-03-24 Siemens Aktiengesellschaft Method and system for using temporary exclusive locks for parallel resource access
CN104205053A (en) * 2009-09-18 2014-12-10 西门子公司 Method and system for using temporary exclusive blocks for parallel accesses to operating means
CN106354795A (en) * 2016-08-26 2017-01-25 南威软件股份有限公司 Distributed data exchanging system
CN107977376A (en) * 2016-10-24 2018-05-01 腾讯科技(深圳)有限公司 Distributed data base system and transaction methods
CN106528876A (en) * 2016-12-09 2017-03-22 北京奇虎科技有限公司 Information processing method for distributed system and distributed information processing system
CN108319496A (en) * 2017-01-18 2018-07-24 阿里巴巴集团控股有限公司 resource access method, service server, distributed system and storage medium
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
CN110032424A (en) * 2019-01-28 2019-07-19 阿里巴巴集团控股有限公司 The implementation method and device of distributed lock
CN109901798A (en) * 2019-02-27 2019-06-18 新华三技术有限公司成都分公司 Date storage method and device
CN110231979A (en) * 2019-05-07 2019-09-13 深圳壹账通智能科技有限公司 Transaction methods, device, equipment and storage medium based on block chain

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112817995A (en) * 2021-02-22 2021-05-18 北京奇艺世纪科技有限公司 Data processing method and device, electronic equipment and storage medium
CN112817995B (en) * 2021-02-22 2023-09-15 北京奇艺世纪科技有限公司 Data processing method and device, electronic equipment and storage medium
CN113836161A (en) * 2021-09-30 2021-12-24 紫光云技术有限公司 Method for realizing timed task atomicity by using database lock
CN113836161B (en) * 2021-09-30 2023-11-03 紫光云技术有限公司 Method for realizing timed task atomicity by utilizing database lock
CN113986850A (en) * 2021-10-27 2022-01-28 北京天宇威视科技股份有限公司 Storage method, device, equipment and computer readable storage medium of electronic file
CN113918530A (en) * 2021-12-14 2022-01-11 北京达佳互联信息技术有限公司 Method and device for realizing distributed lock, electronic equipment and medium
CN113918530B (en) * 2021-12-14 2022-05-13 北京达佳互联信息技术有限公司 Method and device for realizing distributed lock, electronic equipment and medium
CN115269207A (en) * 2022-09-29 2022-11-01 浙江省公众信息产业有限公司无线运营分公司 Method and system for allocating resources to vCPE network elements
CN115269207B (en) * 2022-09-29 2022-12-23 浙江省公众信息产业有限公司无线运营分公司 Method and system for allocating resources to vCPE network element
CN115809301A (en) * 2023-02-03 2023-03-17 天翼云科技有限公司 Database processing method and device, electronic equipment and readable storage medium

Also Published As

Publication number Publication date
CN110888858B (en) 2023-06-30

Similar Documents

Publication Publication Date Title
CN110888858B (en) Database operation method and device, storage medium and electronic device
CN106936899B (en) Configuration method of distributed statistical analysis system and distributed statistical analysis system
CN109379448B (en) File distributed deployment method and device, electronic equipment and storage medium
US10445186B1 (en) Associating a guest application within a virtual machine to create dependencies in backup/restore policy
US20190140902A1 (en) Centralized configuration data in a distributed file system
CN106899648A (en) A kind of data processing method and equipment
US20160261693A1 (en) Cloud-based data backup and operation method and system
CN112910880B (en) Virtual room creating method, system, device, equipment and medium
JP6975153B2 (en) Data storage service processing method and equipment
CN114185558A (en) Native application master selection method and device based on K8s and storage medium
CN114443908A (en) Graph database construction method, system, terminal and storage medium
US20150286496A1 (en) Systems and methods for enlisting single phase commit resources in a two phase commit transaction
CN112988377B (en) Resource allocation method, system and medium for cloud service
CN113254424A (en) Data service migration method, device and equipment
US20220038444A1 (en) Cloud device, application processing method, electronic device and storage medium
CN111159179A (en) Table partitioning method, related device and computer readable storage medium
CN113318452B (en) Resource updating method and device, computer readable medium and electronic equipment
US10013273B1 (en) Virtual machine termination management
CN111327719B (en) Service processing method, device, service server and medium
US11138078B2 (en) Repairing partially completed transactions in fast consensus protocol
CN112860422B (en) Method, apparatus and computer program product for job processing
KR102156656B1 (en) System and method for creating stack of virtual machine
US10972343B2 (en) System and method for device configuration update
EP3659033B1 (en) Connector leasing for long-running software operations
CN109558205B (en) Disk access method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant