WO2014194678A1 - 一种数据库系统的锁操作方法及设备 - Google Patents

一种数据库系统的锁操作方法及设备 Download PDF

Info

Publication number
WO2014194678A1
WO2014194678A1 PCT/CN2014/071030 CN2014071030W WO2014194678A1 WO 2014194678 A1 WO2014194678 A1 WO 2014194678A1 CN 2014071030 W CN2014071030 W CN 2014071030W WO 2014194678 A1 WO2014194678 A1 WO 2014194678A1
Authority
WO
WIPO (PCT)
Prior art keywords
lock
value
target
state
processing node
Prior art date
Application number
PCT/CN2014/071030
Other languages
English (en)
French (fr)
Inventor
聂愿愿
刘辉军
王传廷
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP14730727.6A priority Critical patent/EP2876566A4/en
Priority to IN1340KON2014 priority patent/IN2014KN01340A/en
Priority to RU2014133161/08A priority patent/RU2585973C2/ru
Priority to US14/323,546 priority patent/US9449041B2/en
Publication of WO2014194678A1 publication Critical patent/WO2014194678A1/zh

Links

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/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • 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/23Updating
    • G06F16/2365Ensuring data consistency and integrity

Definitions

  • the present invention relates to the field of databases, and in particular, to a lock operation method and device for a database system. Background technique
  • the shared cluster database is mainly used for On-Line Transaction Processing (OLTP) applications, which need to support a large number of concurrent users to periodically add and modify data, so the entire database system needs to manage a large number of various types of locks, common There are page locks, regular locks, and tuple locks. Since the database system needs to be used for locks to ensure the consistency of various states of the database, as with the 10 operations, locking and unlocking are usually one of the longest operations in the database system, and the lock subsystem in the database. The design will greatly affect the performance of the entire database system.
  • OTP On-Line Transaction Processing
  • the lock state of each lock includes two lock states, a shared lock and an exclusive lock.
  • the locking or unlocking operation of the lock may include an operation of adding a shared lock or an operation of putting a shared lock, and an operation of adding a lock or an operation of releasing the lock.
  • the locking or unlocking operation of the lock is mainly implemented as follows:
  • the processing node requests a message from the central coordination node (Cordinator Node, CN), the request message includes information of the target lock, and the request information may be a lock request message or a lock request message, if it is a lock request message , the request message includes a request message requesting a shared lock or a request message requesting an exclusive lock;
  • the CN After receiving the request message, the CN searches for the target lock according to the information of the target lock. If it is a lock request message, and the target lock can be locked, the target lock is locked, and the PN is returned. If the lock request message is successful, and the target lock is not currently available for locking, a request message for requesting the PN to join the waiting queue of the target lock is sent to the PN. If it is a lock request message, the target lock is unlocked. If the target lock has another PN in the waiting queue, a PN transmission notification message is selected from the other PNs to implement the target lock transfer.
  • the lock or lock operation of the PN on any lock must be performed by interacting with the CN to complete the locking or unlocking operation of the lock.
  • the number of PN locks or locks on the lock is very large, so the CN needs to process a large number of lock messages, which makes the CN easily reach the performance bottleneck, resulting in low performance of the database system.
  • the embodiment of the invention provides a lock operation method and device for a database system, which can improve the performance of the database system.
  • a first aspect of the present invention provides a lock operation method for a database system, the method comprising: a first processing node acquiring a lock operand of a target lock, wherein the lock operand is used to record that the target lock is currently in the database system a state on each of the processing nodes, and the state of the target lock currently on each processing node in the database system is represented using one or more of the data bits of the lock operand;
  • the first processing node performs a locking operation on the target data object using the target lock, and uses a value of the data bit in the lock operand for indicating a state of the target lock on the first processing node Updating to a value indicating that the target lock is in a locked state on the first processing node;
  • the first processing node confirms whether the locking operation is successful according to the lock operand.
  • the locking operand is used to represent the target lock Updating a value of a data bit of a state on the first processing node to a value indicating that the target lock is in a locked state on the first processing node includes:
  • the first processing node confirms whether the locking operation is successful according to the lock operation number, and includes: when the original value satisfies a condition that the locking operation is successful, the first processing node confirms the The lock operation succeeds; otherwise, it is determined that the lock operation failed.
  • the locking, by the first processing node, the target data object by using the target lock includes: Processing a node to perform a shared lock operation on the target data object by using the target lock;
  • the value of the lock state including:
  • the first processing node confirms that the locking operation is successful, otherwise, determining that the locking operation fails includes: Determining, by the first processing node, whether the state of the target lock recorded by the original value in each processing node in the database system is allowed to add a shared lock state; if yes, confirming the adding shared lock operation Succeeded; if not, it is confirmed that the operation of adding the shared lock fails;
  • the permission to share the lock state is any one of an unlocked state and a shared lock state.
  • the locking, by the first processing node, the target data object by using the target lock includes: Processing a node to perform an exclusive lock operation on the target data object by using the target lock;
  • the value of the lock state including:
  • the first processing node confirms that the locking operation is successful, otherwise, determining that the locking operation fails includes:
  • the permission to share the lock state is any one of an unlocked state and a shared lock state.
  • the method further includes:
  • a second aspect of the present invention provides a lock operation method for a database system, including:
  • the first processing node acquires a lock operand of the target lock, the lock operand is used to record a state of the target lock currently on each processing node in the database system, and the target lock is currently in the database system
  • the state on each processing node is represented using one or more of the data bits
  • the first processing node performs a lock operation on the target data object using the target lock; the first processing node uses the lock operand to indicate a state in which the target lock is on the first processing node
  • the value of the data bit is updated to a value indicating that the target lock is in an unlocked state on the first processing node, such that the processing node in the database system learns the target lock based on the lock operand On the first processing node is an unlocked state.
  • the first processing node updates a value of a data bit of the lock operand indicating a state of the target lock on the first processing node to be used for indicating Place
  • the value of the target lock on the first processing node is an unlocked state, including:
  • the first processing node acquires an original value of the lock operand at a time when the target lock is used to perform a lock operation on the target data object, and uses the original value to indicate that the target lock is in the Adding a value of the data bit of the state on the first processing node to a preset third value to obtain an updated value of the lock operand, where the updated value indicates that the target lock is in the first process
  • the value of the data bit of the state on the node is a value indicating that the target lock is unlocked on the first processing node.
  • the first processing node is configured to indicate, in the updated value, a state in which the target is locked on the first processing node After the value of the data bit is used as a value indicating that the target lock is in an unlocked state on the first processing node, the method further includes:
  • the update value is sent to the processing node in the queue waiting state, so that the target node locks the target lock to perform a lock operation on the target lock.
  • a third aspect of the present invention provides a node device, including: an acquiring unit, an operating unit, and a determining unit, where:
  • the acquiring unit is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state of the target lock currently in each processing node in the database system, where the database system is where the node device is located a database system; and the state of the target lock currently on each processing node in the database system is represented using one or more of the lock operands;
  • the operating unit is configured to perform a locking operation on the target data object on the node device by using the target lock, and use the lock operand to represent the target lock on the first processing node
  • the value of the data bit of the state is updated to a value indicating that the target lock is in a locked state on the first processing node;
  • the determining unit is configured to confirm, according to the lock operand, whether the locking operation is successful.
  • the operating unit specifically includes:
  • a locking unit configured to perform a locking operation on the target data object on the node device by using the target lock
  • an obtaining unit configured to acquire an original value of the lock operand at a time when the locking unit performs a locking operation on the target data object on the node device by using the target lock;
  • a first update unit configured to update a value of a data bit of the original value used to indicate a state of the target lock on the node device, to indicate that the target lock is in the first processing node The value of the locked state
  • the confirming unit is specifically configured to confirm that the locking operation is successful when the original value satisfies the condition that the locking operation is successful, otherwise, determine that the locking operation fails.
  • the first updating unit is specifically configured to add a value of a data bit of the original value for indicating a state of the target lock on the first processing node, and add a preset first value, to obtain An update value of the lock operand; a value of a data bit of the update value indicating a state of the target lock on the first processing node indicates that the target lock is on the first processing node a value of the shared lock state; the confirming unit is specifically configured to determine whether the state of the target lock recorded by the original value in each processing node in the database system is allowed to add a shared lock state; if yes, Confirmation The operation of adding the shared lock is successful; otherwise, it is determined that the locking operation fails;
  • the permission to share the lock state is any one of an unlocked state and a shared lock state.
  • the first updating unit is configured to add a value of a data bit of the original value for indicating a state of the target lock on the first processing node, and a preset second value, to obtain An update value of the lock operand; a value of a data bit of the update value indicating a state of the target lock on the first processing node indicates that the target lock is on the first processing node a value of the exclusive lock state; the confirmation unit is specifically configured to determine whether the state of the target lock recorded by the original value in each processing node in the database system is allowed to add a shared lock state; , confirming that the operation of adding the exclusive lock is successful, otherwise, determining that the operation of adding the exclusive lock fails; or
  • the confirming unit is specifically configured to determine whether the state of the target lock recorded by the original value on the node device is a shared lock state, and whether states on other processing nodes are all unlocked states, if , confirming that the operation of the exclusive lock operation is successful, otherwise, determining that the operation of the exclusive lock operation fails; the other processing nodes are all processing nodes except the node device in the database system;
  • the node device further includes:
  • a fourth aspect of the present invention provides a node device, including: an acquiring unit, an operating unit, and an updating unit, where:
  • the acquiring unit is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state of the target lock currently in each processing node in the database system, where the database system is where the node device is located a database system; and the state of the target lock currently on each processing node in the database system is represented using one or more of the operands;
  • the operation unit is configured to perform a lock operation on the target data object by using the target lock; the update unit is configured to use the lock operand to indicate a state in which the target lock is on the node device The value of the data bit is updated to a value indicating that the target lock is in an unlocked state on the node device, so that the processing node in the database system knows that the target lock is in accordance with the lock operand The node device is unlocked.
  • the updating unit is specifically configured to acquire an original value of the lock operand at a time when the target data object is locked by using the target lock, and the original value of the lock operand And a value of a data bit used to indicate a state of the target lock on the node device, plus a preset third value, to obtain an updated value of the lock operand, where the updated value indicates
  • the value of the data bit of the state of the target lock on the node device is a value indicating that the target lock is in an unlocked state on the node device.
  • the node device further includes:
  • a determining unit configured to use the lock unit in the update unit to indicate that the target lock is in After the value of the data bit of the state on the node device is updated to a value indicating that the target lock is in an unlocked state on the node device, determining that the target lock represented by the original value is in the Whether the state on each processing node in the database system has a queue waiting state, and if so, sending the update value to the processing node whose target lock is in a queue waiting state, so that the target lock is a processing node pair in a queue waiting state The target lock performs a lock operation.
  • the first processing node acquires a lock operand of the target lock, where the lock operand is used to record a state of the target lock currently on each processing node in the database system, and the target lock is currently in the
  • the state on each processing node in the database system is represented using one or more of the lock operands; the first processing node uses the target lock to lock the target data object; when the lock When the operand satisfies the condition that the locking operation is successful, the first processing node confirms that the locking operation is successful, and uses the data in the lock operand to indicate the state of the target lock on the first processing node.
  • the value of the bit is updated to a value indicating that the target lock is in a locked state on the first processing node.
  • the processing node implements the lock operation through the lock operand, and the entire lock operation process is independently performed by the processing node, so that the central coordination node does not need to process the lock message, thereby improving the performance of the database system.
  • FIG. 1 is a schematic flowchart of a lock operation method of a database system according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a lock operation method of another database system according to an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a lock operation method of another database system according to an embodiment of the present invention
  • FIG. 5 is a schematic structural diagram of a node device according to an embodiment of the present invention
  • FIG. 6 is a schematic diagram of another node device according to an embodiment of the present invention
  • FIG. 7 is a schematic structural diagram of another node device according to an embodiment of the present invention
  • FIG. 8 is a schematic structural diagram of another node device according to an embodiment of the present invention
  • FIG. 10 is a schematic structural diagram of another node device according to an embodiment of the present invention
  • FIG. 11 is a schematic structural diagram of another node device according to an embodiment of the present invention
  • FIG. 1 is a schematic flowchart of a lock operation method of a database system according to an embodiment of the present invention.
  • the database system where the lock is located includes N PNs, and N is an integer greater than 0, as shown in FIG. include:
  • the first PN acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system.
  • the state on each PN is represented by one or more data bits in the lock operand.
  • the first PN may be any PN in the database system, and the target lock is any lock in the system.
  • the lock operands of all locks in the database system can be saved in the central coordination node CN of the database system, so the first PN can query the lock operand of the target lock from the CN, Thereby, the state information of the target lock currently on each processing node in the database system is obtained.
  • the state that the target lock is on the PN may include at least one of the following:
  • the status value in the above lock operand indicates the state in which the PN uses the target lock.
  • the first PN performs a locking operation on the target data object by using the target lock.
  • the first PN confirms that the locking operation is successful, and uses the lock operand to indicate that the target lock is in the first
  • the value of the data bit of the state on the PN is updated to a value indicating that the target lock is in a locked state on the first PN.
  • the device implementing the present invention may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the first PN acquires a lock operand of the target lock, where the lock operand is used to record a state of the target lock currently on each PN in the database system, and the target lock is currently in the
  • the state on each PN in the database system is represented using one or more of the lock operands; the first PN uses the target lock to lock the target data object; when the lock operand satisfies When the lock operation succeeds, the first PN confirms that the lock operation is successful, and updates the value of the data bit in the lock operand for indicating the state of the target lock on the first PN to be used. And indicating that the target lock is in a locked state on the first PN.
  • FIG. 2 is a schematic flowchart of a lock operation method of another database system according to an embodiment of the present invention. As shown in FIG. 2, the method includes:
  • the first PN acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system.
  • the state on each PN is represented using one or more of the data bits of the lock operand.
  • the lock operand may be a set of M-bit binary numbers, where M is the number of bits of the operating system of the PN, such as a 32-bit operating system, then the M is 32, and the operating system is 128. M is 128.
  • the lock operand may include data of two 2-digit binary numbers.
  • the data of one 2-bit binary number indicates the state of the target lock on one ,, that is, the state of the target lock currently on each ⁇ in the database system uses one 2-bit binary of the lock operand The data representation of the number.
  • each node in the foregoing system may be configured with a node identifier, and the embodiment of the present invention may establish a mapping relationship between the location of the binary number of the lock operand and the node identifier, such as the node identifier of the above ⁇ ⁇ is 0123. .. ⁇ , the above mapping relationship can be 0-1 bit of data in the lock operand, which can indicate the state of the target lock on the node whose node ID is 0.
  • the data of 2-3 bits in the lock operand can be represented.
  • the target lock is in the state of the node whose ID is 1, and the data of 3-4 bits in the lock operand can indicate the state of the target lock on the node whose node is identified as 2, and the lock operand is 5-6 bits.
  • the data can represent the state of the target lock on the node identified as node 3, ..., the data of the N -1- ⁇ bit in the lock operand can be the state indicating that the target lock is on the node whose node is identified as ⁇ . For example, if the node ID of the first node is 0, the 0-1 binary number in the operand indicates the state of the target lock on the first frame.
  • the above node identifier and the above mapping relationship are only an example of the present invention. Examples of the invention include, but are not limited to, the node identifications and mapping relationships listed above.
  • the state of the target lock on the ⁇ can include at least one of the following:
  • mapping relationship between the value of the binary number and the state of the lock may also be established, and the mapping relationship may be as follows: Lock operand (2 bits) lock status
  • the above table only shows a 2-bit binary number, indicating the state of the target lock on a PN.
  • the 2-bit binary number in the table is 0-1 bits, that is, the 2-digit binary number in the table indicates that the target lock is in the node identifier.
  • the state on the PN of 0, when the 2-bit binary number in the table is 01, then the state of the target lock on the PN whose node identifier is 0 is the shared lock.
  • the 2-bit binary number in the table is 10 then The state of the target lock on the PN whose node ID is 0 is an exclusive lock.
  • a mapping relationship between the value of the binary number not listed above and the state of the lock is included.
  • the first PN performs a locking operation on the target data object by using the target lock.
  • the locking operation may include:
  • the first PN confirms that the locking operation is successful, and uses the lock operand to indicate that the target lock is in the first
  • the value of the data bit of the state on the PN is updated to a value indicating that the target lock is in a locked state on the first PN.
  • the value used to indicate the locked state is 01 or 10, so that when step 202 adds a shared lock, step 203 can use the lock operand to indicate that the target is locked.
  • the value of the data bit of the state on the first PN is updated to 01; when step 202 adds the lock, step 203 may use the lock operand to indicate that the target is locked in the first PN
  • the value of the data bit on the status is updated to 10.
  • the method may further include: 204.
  • the first PN determines that the locking operation fails. And updating, in the operand, a value of a data bit indicating a state of the target lock on the first PN to indicate that the target lock is in a queue waiting state on the first PN value. In this way, when the locking operation fails, the state of the target lock on the first PN is updated to the queue waiting state.
  • step 203 may include:
  • the first PN acquires an original value of the lock operand at a time when the target lock is locked using the target lock, and uses the original value to represent the target lock in the first
  • the value of the data bit of the state on a PN is added to a preset first value to obtain an updated value of the lock operand;
  • the first PN confirms that the locking operation is successful, and uses the updated value to indicate the state of the target lock on the first PN.
  • the value of the data bit is used as a value for indicating that the target lock is in a locked state on the first PN.
  • the first value can be 01 or 10.
  • step 202 is to perform a shared lock operation
  • the foregoing value refers to the value of the lock operation at the time when the first PN locks the target lock in step 202.
  • the database system may have multiple PNs to perform the target lock.
  • the lock operation of these PNs on the target lock may be very similar, that is, between steps 201 and 202 of the example of the present invention, other PNs lock the target, which changes the operands.
  • the data bit used to indicate the state of the target lock on the other PN, that is, the value of the lock operand is updated, that is, the value of the lock operand obtained in step 201 is not necessarily the latest value when the target lock is locked. .
  • step 203 can obtain the original value, that is, the value of the lock operand at the time of the locking operation in step 202.
  • step 203 can be performed by an FAA operation in an atomic operation (Fetch And Add, the content of the operation is an atomic operation of adding an original value of the operand and returning the original value), and the atomic operation is in a database system. Or the operation that has been performed all the time, that is, the operation is executed from the start to the shutdown, so that the original value of the lock operand can be obtained by the above FAA operation.
  • step 203 can obtain the original value of the lock operand by the operation, and at the same time, in the FAA operation.
  • the first value is added, for example, the above 4 ' ⁇ , that is, step 203 only needs to execute a 4' ⁇ , and the updated value is obtained, where i is the current node identifier, and V is the original value of the lock operand.
  • step 202 may include:
  • the first PN performs the operation of adding a shared lock to the target data object by using the target lock; when the original value satisfies the condition that the locking operation is successful in step 203, the first PN confirms the locking operation. Success, can include:
  • the permission to share the lock state is any one of an unlocked state and a shared lock state. That is, the conditions for the above locking operation to be successful may include:
  • the state of the target lock represented by the original value in each PN of the database system is the above-mentioned permission to add a shared lock state, that is, an unlocked or shared lock, that is, the target lock represented by the original value is
  • the state on each PN in the database system is either unlocked or shared, and the state of the target lock represented by the above original value in each PN in the database system does not include exclusive lock or queue waiting. That is, the above original value does not indicate that the state of the target lock on any PN is an exclusive lock or a queue wait. In this way, the first PN can successfully add a shared lock to the target lock.
  • step 202 may include:
  • the first PN performs an operation of performing an exclusive lock on the target data object by using the target lock; when the original value satisfies the condition that the locking operation is successful in step 203, the first PN confirms the adding
  • the lock operation is successful and can include:
  • the first PN confirms that the locking operation is successful, and may include:
  • the first PN Determining, by the first PN, whether the state of the target lock recorded on the first PN is a shared lock state, and if yes, determining that the target lock recorded by the original value is in another PN Whether the state of the upper state is an unlocked state, if yes, confirming that the operation of adding the exclusive lock is successful; the other PN is all PNs except the first PN in the database system;
  • the permission to share the lock state is any one of an unlocked state and a shared lock state. That is, the conditions for the above locking operation to be successful may include:
  • the state indicated by the original value is an unlocked or shared lock on each PN in the database system; or the target lock represented by the original value is in the first PN
  • the state on the node is a shared lock, the state of the target lock on other PNs is unlocked; the other PNs are all PNs in the database system except the first PN node.
  • the original value does not include an exclusive lock or a queue wait, or the shared lock is not included except that the state of the first PN use target lock is a shared lock. In this way, the first PN can successfully lock the target lock.
  • the current PN can read, modify, delete, etc. the data pair corresponding to the target lock.
  • step 204 may include:
  • the first PN determines that the locking operation fails, and uses the original value to indicate that the target lock is in the first PN
  • the value of the data bit of the upper state is updated to a value indicating that the target lock is in a queued wait state on the first PN.
  • step 204 may be the same as step 203 above, and step 204 may also be the lock operation by the FAA operation.
  • the value of the data bit used to indicate the state of the target lock on the first PN is used to indicate that the target lock is a queued wait state on the first PN. That is, step 204 can include:
  • the first PN determines that the locking operation fails, and uses the FAA operation to indicate that the target lock is in the first PN
  • the value of the data bit of the upper state is used to indicate that the target lock is a value of the queue waiting state on the first PN, wherein the value added in the FFA operation is a value opposite to the first value, ie When the first value is 01, the value added in the FFA operation is -01, and when the first value is 10, the value added in the FFA operation is -10. This ensures that the value of the lock operand used is up-to-date when the update performed in step 204 is performed.
  • step 202 may include:
  • the first PN uses the target lock to perform an exclusive lock operation on the target data object; that is, the basis of the shared lock Add an exclusive lock.
  • step 203 can include:
  • the first PN acquires a value of a data bit of a state on a PN when the target data object is subjected to an exclusive lock operation using the target lock, and adds a preset second value to obtain the lock operand. Update value
  • the first PN confirms that the value of the added data bit is updated to indicate that the target lock is exclusive on the first PN The value of the lock state.
  • the mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, the 0-1 bit in the lock operand can represent the state of the PN using the target lock with the node identifier being 0)
  • the second value may be 10
  • the updated value is used to indicate that the target lock is in the
  • the value of the data bit of the state on the first PN is updated to a value indicating that the target lock is in an exclusive lock state on the first PN, and may be used to represent the target lock in the updated value
  • the value of the data bit of the state on the first PN is added -01.
  • the mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can indicate that the node identifier is 0.
  • the foregoing step 202 may include: The first PN performs a shared lock operation on the target lock,
  • Step 203 can include:
  • the first PN performs an FAA operation on the lock operand, wherein the value added in the FAA operation is 4 '' (ie, the first value is also understood to be a value indicating a shared lock, such as 01), first The PN acquires an original value of the lock operand at a time when the target lock is locked using the target lock, and obtains a value after the FAA operation (ie, the updated value), the value is the lock
  • the above-mentioned original value of the operation is added with the value of 4 ' ⁇ , and the added value indicates that the state of the target lock on the first frame is a shared lock, that is, the original value is used to indicate that the target lock is in the first
  • the value 00 of the data bit of the state on the ⁇ is incremented by 01, the value obtained is 01.
  • step 203 adds the shared lock successfully, and uses the updated value.
  • a value of a data bit indicating a state in which the target lock is on the first side is a value indicating that the target lock is in a locked state on the first side.
  • step 204 is performed, where: step 204 may include: The lock operand performs the FAA operation, wherein the value added in the FAA operation is 2 x 4' ⁇ , the value of the lock operand at the time of executing step 204 is obtained, and a value after performing the FAA operation is obtained, which is the lock
  • the value of the operation step 204 is added with the value of 2 x 4' ⁇ , and adding the value indicates that the state of the target lock on the first frame is queued, that is, after the data 01 of the first position is added by 10, The value is 11.
  • the step 202 may include:
  • the first ⁇ uses the target lock to perform an exclusive lock operation on the target data object;
  • Step 203 can include:
  • the first lock operand performs the FAA operation, wherein the value added in the FAA operation is 2 x 4' ⁇ (ie, the first value described above can be understood as a value for indicating an exclusive lock, such as 10), Lock operation
  • the original value of the number, and the value obtained after performing the FAA operation (that is, the above updated value)
  • the value is the above-mentioned original value of the above lock operation plus the value of 2 x 4' ⁇
  • the value indicates that the target lock is in the first
  • the state on a PN is an exclusive lock, that is, after the data bit 01 of the lock operand indicating the state of the target lock on the first PN is incremented by 10, the value obtained is 10.
  • step 203 confirms that the exclusive lock is successful, and uses the updated value to indicate the target.
  • the value of the data bit of the state locked on the first PN is updated to a value indicating that the target lock is in an exclusive lock state on the first PN.
  • Step 204 is performed, where: Step 204 may include:
  • the first PN performs an FAA operation on the lock operand, wherein the value added in the FAA operation is 4' ⁇ , and the value of the lock operand at the time of executing step 204 is obtained, and a value after performing the FAA operation is obtained.
  • the value of the time at the step 204 of the above-mentioned lock operation is added to the value of 4' ⁇ , and the added value indicates that the state of the target lock on the first PN is queued, that is, the lock operand is used to represent the target.
  • the value 01 of the data bit of the state locked on the first PN is incremented by 10
  • the value obtained is 11.
  • step 202 may include:
  • the first PN uses the target lock to perform an exclusive lock operation on the target data object.
  • Step 203 can include:
  • the first PN performs an FAA operation on the lock operand, wherein the value added in the FAA operation is 2 x 4' ⁇ (ie, the second value is also understood to be a value for indicating an exclusive lock, such as 10).
  • the value is The above-mentioned original value of the above lock operation is added with the value of 2 x 4' ⁇ , so that adding the value means that the target lock is in the first
  • the state on the PN is queued, i.e., the value 01 of the data bit in the lock operand indicating the state of the target lock on the first PN plus 10, the value obtained is 11.
  • Step 203 updating a value of a data bit of the update value indicating a state of the target lock on the first PN to indicate that the target lock is exclusive on the first PN
  • the value of the lock state ie
  • the first PN performs a FAA operation on the above lock operand, wherein the value added in the FAA operation is -4' ⁇ (ie, minus 01, ).
  • the value of the data bit in the lock operand for indicating the state of the target lock on the first PN is updated from the value for indicating the queue waiting state (ie, 11) to indicate the exclusive lock state.
  • step 202 adds an exclusive lock failure. Since the step 203 adds a value for indicating the exclusive lock, the value of the data bit in the lock operand indicating the state of the target lock on the first PN is used to indicate that the queue is waiting. The value of the state (i.e., 11), so step 204 may not be included in this embodiment.
  • the lock state can be shared and locked as an exclusive lock.
  • step 201 may include:
  • the first PN when the first PN needs to add, read, modify, or delete the data object corresponding to the target lock, the first PN may send a request to the CN to request to operate the target lock.
  • the NC looks up the hash table to mention the lock operand of the target lock.
  • the CN creates the lock operand of the target lock and returns it to the node device.
  • step 201 may include:
  • the first PN receives a lock operand of the target lock sent by the second PN in the database system.
  • the second PN refers to any PN in the database system other than the first PN.
  • step 201 may include:
  • the first PN reads the lock operand of the target lock stored locally by the current PN.
  • FIG. 3 is a schematic flow chart of another method for locking a database system according to an embodiment of the present invention. As shown in FIG. 3, the method includes:
  • the first PN acquires a lock operand of a target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system.
  • the state on each PN is represented by one or more data bits in the operand; optionally, the first PN may be any PN in the database system, and the target lock is any lock in the above system, for example Group lock, page lock, etc.
  • the state that the target lock is on the PN may include at least one of the following:
  • Unlocked, shared locks, exclusive locks, and queued waits The status value in the above lock operand indicates the state in which the PN uses the target lock.
  • the first PN performs a lock operation on the target data object by using the target lock.
  • the first PN updates a value of a data bit in the lock operand indicating a state in which the target lock is on the first PN to indicate that the target lock is on the first PN.
  • the value of the lock state is such that the PN in the database system learns that the target lock is in the lock state on the first PN according to the lock operand.
  • the above locked state may be understood as an unlocked state.
  • the device implementing the present invention may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the first PN acquires a lock operand of the target lock, where the lock operand is used to record a state of the target lock currently on each PN in the database system, and the target lock is currently in the
  • the state on each PN in the database system is represented using one or more of the lock operands;
  • the first PN uses the target lock to perform a lock operation on the target data object;
  • the first PN operates the lock a value of a data bit in the number indicating a state of the target lock on the first PN is updated to a value indicating that the target lock is in a lock state on the first PN, such that
  • the PN in the database system learns that the target lock is in a lock state on the first PN according to the lock operand.
  • FIG. 4 is a schematic flowchart of a lock operation method of another database system according to an embodiment of the present invention. As shown in FIG. 4, the method includes:
  • the first PN acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system.
  • the state on each PN is represented using one or more of the data bits; as an alternative embodiment, the lock operand may be a set of M-bit binary numbers, and the M is a PN operating system. The number of bits, such as a 32-bit operating system, then M is 32. If the operating system is 128 then M is 128.
  • the lock operand may include data of two 2-digit binary numbers.
  • the data of one 2-bit binary number indicates the state of the target lock on one ,, that is, the state of the target lock currently on each ⁇ in the database system uses one 2-bit binary of the lock operand The data representation of the number.
  • each node in the foregoing system may be configured with a node identifier, and the embodiment of the present invention may establish a mapping relationship between the location of the binary number of the lock operand and the node identifier, such as the node identifier of the above ⁇ ⁇ is 0123. .. ⁇ , the above mapping relationship can be 0-1 bit of data in the lock operand, which can indicate the state of the target lock on the node whose node ID is 0.
  • the data of 2-3 bits in the lock operand can be represented.
  • the target lock is in the state of the node whose ID is 1, and the data of 3-4 bits in the lock operand can indicate the state of the target lock on the node whose node is identified as 2, and the lock operand is 5-6 bits.
  • the target lock is in the state of the PN whose node is identified as 3, ...
  • the data of the N -1-N bits in the lock operand can be the state indicating that the target lock is on the PN whose node identifier is N. For example, if the node identifier of the first PN is 0, the 0-1 bit binary number in the operand indicates the state of the target lock on the first PN.
  • the above node identifier and the above mapping relationship are only an example of the present invention. Examples of the invention include, but are not limited to, the node identifications and mapping relationships listed above.
  • the state of the target lock on the PN may include at least one of the following:
  • mapping relationship between the value of the binary number and the state of the lock may also be established, and the mapping relationship may be as follows:
  • the above table only shows a 2-bit binary number, indicating the state of the target lock on a PN.
  • the 2-bit binary number in the table is 0-1 bits, that is, the 2-digit binary number in the table indicates that the target lock is in the node identifier.
  • the state on the PN of 0, when the 2-bit binary number in the table is 01, then the state of the target lock on the PN whose node identifier is 0 is the shared lock.
  • the 2-bit binary number in the table is 10 then The state of the target lock on the PN whose node ID is 0 is an exclusive lock.
  • a mapping relationship between the value of the binary number not listed above and the state of the lock is included.
  • the first PN performs a lock operation on the target data object by using the target lock.
  • the foregoing unlocking operation may include:
  • the first PN acquires an original value of the lock operand at a time when the target lock is used to perform a lock operation on the target data object, and uses the original value to indicate that the target lock is in the Adding a value of the data bit of the state on the first PN to a preset third value to obtain an updated value of the lock operand, and indicating that the target lock is on the first PN
  • the value of the data bit of the state is a value for indicating that the target lock is in an unlocked state on the first PN.
  • the third value may be -01 or -10, so that when the step When the shared lock is placed in 402, the third value is -01; when step 402 is released, the third value is -10, to obtain an updated value indicating that the target lock is on the first PN.
  • the value of the status data bit is 00.
  • step 402 when the mapping between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above, and the mapping relationship between the value of the binary number and the state of the lock satisfies the mapping shown in the above table.
  • step 402 when the node identifier of the first PN is 0, that is, step 402 is W minus 0001, and the node identifier of the first PN is 1, that is, step 402 is W minus 0100. It should be noted that, in this implementation manner, only the calculation is performed according to the mapping relationship listed above. When the mapping relationship is changed, the algorithm of step 403 may also perform corresponding changes.
  • step 402 the lock operation is performed, and step 403 may add -2 x 4' ⁇ by the value of the lock operand, that is, only need to execute a 2 x 4' ⁇ , where -2 x 4' ⁇ is a binary number, i is the node identifier of the first PN, and W is the value of the above lock operand.
  • -2 x 4' ⁇ is a binary number
  • i is the node identifier of the first PN
  • W is the value of the above lock operand.
  • the node identifier of the first PN is 0, that is, step 402 is W minus 0010
  • the node identifier of the first PN is 1, that is, step 402 is W minus 1000.
  • the algorithm of step 403 may also change accordingly.
  • step 403 can be performed by an FAA operation in an atomic operation, because the content of the FAA operation is to add a value to the original value of the operand, and return an atomic operation of the original value, so that step 403 can be obtained through the operation.
  • the original value of the lock operand is added, and the third value is added to the FAA operation, for example, the above -4' ⁇ , that is, step 403 only needs to execute a ⁇ - 4 ' ⁇ , and the updated value can be obtained, where i
  • the node ID of the current PN, and V is the original value of the above lock operand.
  • the method may further include:
  • the first PN determines whether there is a queue waiting state in the state of the target lock represented by the original value in each PN in the database system. If yes, the first PN waits in a queue for the target lock.
  • the PN of the state transmits the update value such that the target lock is a PN that is in a queued wait state to lock the target lock.
  • the target lock is a queued PN, that is, the state of the target lock is queued on the PN, so that the step 404 sends the updated value to the PN whose target lock is queued, so that No need to go through the CN, saving CN overhead.
  • mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can represent the PN usage target with the node identifier 0).
  • mapping relationship between the state of the lock and the mapping between the value of the binary and the state of the lock the foregoing step 402 may include:
  • the first PN performs a shared lock operation on the target lock
  • Step 403 can include:
  • the first PN performs a FAA operation on the above lock operand, wherein the value added in the FAA operation is -4' ⁇
  • the above third value can also be understood as a value for indicating the shared lock, such as -01
  • the original value of the lock operand is obtained, and a value after performing the FAA operation is obtained (ie, the above update) Value)
  • the value is the above-mentioned original value of the above lock operation plus the value of -4' ⁇
  • the added value indicates that the state of the target lock on the first PN is unlocked, that is, the lock operand is used.
  • the value obtained is 00.
  • mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can represent the PN usage target with the node identifier 0).
  • mapping relationship between the state of the lock and the mapping between the value of the binary and the state of the lock the foregoing step 402 may include:
  • the first PN performs an operation of releasing the lock on the target lock
  • Step 403 can include:
  • the first PN performs an FAA operation on the lock operand, wherein the value added in the FAA operation is -2 x 4' ⁇ (ie, the third value is understood to be a value used to indicate that the lock is released, such as - 10), obtaining the original value of the lock operand, and obtaining a value after performing the FAA operation (ie, the updated value), the value being the above-mentioned original value of the lock operation plus -2 x 4' ⁇ a value, the added value indicating that the state of the target lock on the first PN is unlocked, that is, the value of the data bit of the lock operand indicating the state of the target lock on the first PN is 10 After subtracting 10, the value is 00.
  • step 401 may include:
  • the first PN receives the lock operation of the target lock sent by the central coordination node in the database system Count
  • step 301 may include:
  • the first PN receives a lock operand of the target lock sent by the second PN in the database system; the second PN refers to any PN other than the first PN in the database system. For example, the number of lock operations sent in step 302.
  • step 401 may include:
  • the first PN reads the lock operand of the target lock stored locally by the first PN.
  • FIG. 5 is a schematic structural diagram of a node device according to an embodiment of the present invention.
  • the node device is a PN in the database system.
  • the method includes: an obtaining unit 51, an operating unit 52, and a first updating unit 53, among them:
  • the obtaining unit 51 is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system
  • the state on each of the PNs is represented using one or more of the data bits of the lock operand.
  • the foregoing node device may be any PN in the database system, and the target lock is any lock in the foregoing system;
  • the state that the target lock is on the PN may include at least one of the following:
  • Unlocked, shared locks, exclusive locks, and queued waits The status value in the above lock operand indicates the state in which the PN uses the target lock.
  • the operating unit 52 is configured to perform a locking operation on the target data object by using the target lock.
  • a first updating unit 53 configured to confirm that the locking operation is successful when the lock operand satisfies a condition that the locking operation is successful, and use the lock operand to indicate that the target lock is in the node
  • the value of the data bit of the state on the device is updated to a value indicating that the target lock is locked on the node device
  • the foregoing node device may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the node device acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database.
  • a state on each PN in the system is represented using one or more of the lock operands; the node device uses the target lock to lock the target data object; when the lock operand satisfies a lock operation Upon successful condition, the node device confirms that the locking operation is successful, and updates the value of the data bit in the lock operand indicating the state of the target lock on the node device to be used to indicate the
  • the target lock is a value of the locked state on the node device.
  • FIG. 6 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN in a database system.
  • the method includes: an obtaining unit 61, an operating unit 62, and a first updating unit. 63 , where:
  • the obtaining unit 61 is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system
  • the state on each of the PNs is represented using one or more of the data bits of the lock operand.
  • the lock operand may be a set of M-bit binary numbers, where M is the number of bits of the operating system of the PN, such as a 32-bit operating system, then the M is 32, and the operating system is 128. M is 128.
  • the lock operand may include data of two 2-digit binary numbers.
  • the data of a 2-bit binary number indicates the state of the target lock on one ,, that is, the target lock is currently
  • the state on each PN in the database system is represented using data for one 2-bit binary number of the lock operands.
  • each PN in the foregoing system may be configured with a node identifier
  • the embodiment of the present invention may establish a mapping relationship between a location of a binary number of the lock operand and a node identifier, for example, the node identifier of the N PNs is 0123. ..N
  • the above mapping relationship can be 0-1 bits of data in the lock operand to indicate the state of the target lock on the PN whose node ID is 0, and the data of 2-3 bits in the lock operand can be represented.
  • the target lock is in the state of the PN whose node is identified as 1, and the data of 3-4 bits in the lock operand can indicate the state of the target lock on the PN whose node is identified as 2, and the lock operand is 5-6 bits.
  • the data can represent the state of the target lock on the PN identified as node 3, ..., the data of the N -1-N bits in the lock operand can be the state indicating that the target lock is on the PN whose node identifier is N. For example, if the node identifier of the first PN is 0, the 0-1 binary digit in the operand indicates the state of the target lock on the first PN.
  • the above node identifier and the above mapping relationship are only an example of the present invention. Examples of the invention include, but are not limited to, the node identifications and mapping relationships listed above.
  • the state of the target lock on the PN may include at least one of the following:
  • mapping relationship between the value of the binary number and the state of the lock may also be established, and the mapping relationship may be as follows:
  • the above table only shows a 2-bit binary number, indicating the state of the target lock on a PN.
  • the 2-bit binary number in the table is 0-1 bits, that is, the 2-digit binary number in the table indicates that the target lock is in the node identifier.
  • the state on the PN of 0, when the 2-bit binary number in the table is 01, then the state of the target lock on the PN whose node identifier is 0 is the shared lock.
  • the 2-bit binary number in the table is 10 then The state of the target lock on the PN whose node ID is 0 is an exclusive lock.
  • a mapping relationship between the value of the binary number not listed above and the state of the lock is included.
  • the operating unit 62 is configured to perform a locking operation on the target data object by using the target lock.
  • the locking operation may include:
  • a first updating unit 63 configured to: when the lock operand satisfies a condition that the locking operation succeeds, confirm that the locking operation is successful, and use the lock operand to indicate that the target lock is in the node
  • the value of the data bit of the state on the device is updated to a value indicating that the target lock is locked on the node device.
  • the node device may further include:
  • a second updating unit 64 configured to determine that the locking operation fails when the lock operand does not satisfy a condition that the locking operation succeeds, and use the operand to indicate that the target is locked in the node
  • the value of the data bit of the state on the device is updated to a value indicating that the target lock is in a queued wait state on the node device.
  • the first update unit 63 may further include:
  • a first calculating unit (not shown in the drawing), configured to acquire an original value of the lock operand at a time when the target data object is locked using the target lock, and the original value And a value of a data bit used to indicate a state of the target lock on the node device, plus a preset first value, to obtain an updated value of the lock operand;
  • a first confirming unit (not shown in the drawing), configured to confirm that the locking operation is successful when the original value satisfies a condition that the locking operation is successful, and use the updated value to indicate the
  • the value of the data bit of the state of the target lock on the node device acts as a value for indicating that the target lock is locked on the node device.
  • the first value can be 01 or 10.
  • the operation unit 62 performs a shared lock operation
  • the first update unit 63 may add 4 '' by the value of the lock operand, that is, only need to execute a ⁇ +4′ ⁇ to obtain the updated value.
  • i is the node ID of the first
  • W is the original value of the above lock operand.
  • the node identifier of the first PN is 0,
  • the node identifier of the first PN is 1, and W is added to 0100.
  • the algorithm of the first updating unit 63 may also make a corresponding change. Line plus shared lock operation;
  • the first confirming unit (not shown in the drawing) can also be used to determine whether the state of the target lock recorded by the original value in each database of the database system is allowed to be shared lock state; , confirming that the operation of adding the shared lock is successful;
  • the permission to share the lock state is any one of an unlocked state and a shared lock state. That is, the conditions for the above locking operation to be successful may include:
  • the state of the target lock represented by the original value in each PN of the database system is the above-mentioned permission to add a shared lock state, that is, an unlocked or shared lock, that is, the target lock represented by the original value is
  • the state on each PN in the database system is either unlocked or shared, and the state of the target lock represented by the above original value in each PN in the database system does not include exclusive lock or queue waiting. That is, the above original value does not indicate that the state of the target lock on any PN is an exclusive lock or a queue wait. In this way, the first PN can successfully add a shared lock to the target lock.
  • Exclusive lock operation
  • the first confirming unit (not shown in the drawing) can also be used to determine whether the state of the target lock recorded by the original value in each database of the database system is allowed to be shared lock state; , confirming that the operation of adding the lock is successful; or
  • the first confirmation unit (not shown in the drawing) is further configured to determine whether the state of the target lock recorded by the original value on the node device is a shared lock state, and if yes, determine the original Whether the state of the target lock recorded on the other PN has an unlocked state, and if so, confirming that the add-and-lock operation is successful; the other PN is the node device in the database system All PNs except
  • the permission to share the lock state is any one of an unlocked state and a shared lock state. That is, the conditions for the above locking operation to be successful may include:
  • the state of the target lock represented by the original value on each PN in the database system is The lock is not locked or shared; or the state of the target lock represented by the original value on the first PN node is a shared lock, and the state of the target lock on another PN is unlocked;
  • the other PNs are all PNs in the database system except the first PN node.
  • the original value does not include an exclusive lock or a queue wait, or the shared lock is not included except that the state of the first PN use target lock is a shared lock. In this way, the first PN can successfully lock the target lock.
  • the current PN can read, modify, delete, etc. the data pair corresponding to the target lock.
  • the second updating unit 64 is further configured to: when the original value does not satisfy the condition that the locking operation succeeds, determine that the locking operation fails, and use the original value to indicate the The value of the data bit of the state of the target lock on the node device is updated to a value indicating that the target lock is in a queued wait state on the node device.
  • another PN may perform a lock operation on the target lock
  • the second update unit 64 may be the same as the first update unit 63, and the second update unit 64 may also The value of the data bit used in the lock operand to indicate the state of the target lock on the node device by the FAA operation described above is used to indicate that the target lock is a queued wait state on the node device. That is, the second update unit 64 may be further configured to determine that the locking operation fails when the original value does not satisfy the condition that the locking operation is successful, and use the lock operation number to represent the target lock by using a FAA operation.
  • the value of the data bit of the state on the node device is used to indicate that the target lock is a queued wait state on the node device, wherein the value added in the FFA operation is opposite to the first value
  • the value that is, when the first value is 01, the value added in the FFA operation is -01, and when the first value is 10, the value added in the FFA operation is -10. This ensures that the value of the lock operand used is up-to-date when the update performed by the second update unit 64 is performed.
  • the operation unit 62 is further configured to: when the state of the target lock on the node device is a shared lock state, use the target lock to add the target data object.
  • the operation of the lock that is, the lock on the basis of the shared lock.
  • the first update unit 63 may further include:
  • a second calculating unit (not shown in the drawing), configured to acquire an original value of the lock operand at a time when the target data object is subjected to an exclusive lock operation using the target lock, and the original value a value of a data bit having a value indicating a state of the target lock on the node device plus a preset a second value, obtaining an updated value of the lock operand;
  • a second confirming unit (not shown in the drawing), configured to confirm that the adding and unlocking operation succeeds when the original value satisfies the condition that the exclusive locking operation is successful, and use the updated value
  • the value of the data bit representing the state of the target lock on the node device is updated to a value indicating that the target lock is in an exclusive lock state on the node device.
  • the mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, the 0-1 bit in the lock operand can represent the state of the PN using the target lock with the node identifier being 0)
  • the second value may be 10
  • the updated value is used to indicate that the target lock is in the
  • the value of the data bit of the state on the node device is updated to a value indicating that the target lock is in an exclusive lock state on the node device, and may be used to represent the target lock in the updated value.
  • the value of the data bit of the state on the node device is added -01.
  • mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can indicate that the node identifier is 0.
  • the operation unit 62 may also be used by the first PN to perform the target lock. Add a shared lock operation,
  • the first update unit 63 is further configured to perform an FAA operation on the lock operand, wherein a value added in the FAA operation is 4 ′′ (ie, the first value is also used to represent a value of the shared lock, For example, 01), the node device acquires an original value of the lock operand at a time when the target lock is locked by the target lock, and obtains a value after performing the FAA operation (ie, the updated value), The value is the above-mentioned original value of the above lock operation plus the value of 4 '', and the added value indicates that the target lock is at the first
  • the state on the PN is a shared lock, that is, the value of the data bit of the original value used to indicate the state of the target lock on the node device is 00 plus 01, and the value is 01.
  • the first update unit 63 adds the shared lock successfully, and the update is performed.
  • a value of a data bit in the value indicating a state of the target lock on the node device as a value indicating that the target lock is in a locked state on the node device.
  • the second update unit 64 performs an FAA operation on the lock operand, wherein the value added in the FAA operation is 2 x 4' ⁇ , and the lock operation is performed at the time of executing the second update unit 64.
  • the value of the number, and the value obtained after performing the FAA operation which is the value of the second update unit 64 at the time of execution of the above lock operation plus the value of 2 x 4' ⁇ , and adding the value indicates that the target lock is at the first
  • the state on the PN is queued, that is, after the data 01 of the first location is incremented by 10, the value obtained is 11.
  • mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can indicate that the node identifier is 0.
  • the PN uses the mapping relationship of the state of the target lock, and when the mapping relationship between the value of the binary number and the state of the lock satisfies the mapping relationship shown in the above table, the operating unit 62 may also be configured to: when the target lock is in the node device When the upper state is an unlocked state, the node device uses the target lock to perform an exclusive lock operation on the target data object;
  • the first update unit 63 is further configured to perform an FAA operation on the lock operand, wherein the value added in the FAA operation is 2 x 4' ⁇ (ie, the first value is understood to be used to represent an exclusive lock. a value, such as 10), obtains the original value of the lock operand, and obtains a value after the FAA operation (ie, the updated value), the value is the above original value of the lock operation plus 2 x 4' a value indicating that the state of the target lock on the first PN is an exclusive lock, that is, the data bit 01 of the lock operand indicating the state of the target lock on the node device plus 10 After that, the value obtained is 10.
  • the first update unit 63 confirms that the lock is successful, and uses the updated value to indicate the location.
  • the value of the data bit of the state of the target lock on the node device is updated to a value indicating that the target lock is in an exclusive lock state on the node device.
  • the second update unit 64 is executed, wherein: the second update unit 64 can also be used to perform the above lock operation.
  • the number performs the FAA operation, wherein the value added in the FAA operation is 4' ⁇ , and the value of the lock operand at the time when the second update unit 64 confirms the lock failure time is obtained, and a value obtained by performing the FAA operation is obtained.
  • the second update unit 64 that is the above lock operation confirms the value of the lock failure time and the value of 4' ⁇ , and adds the value to indicate that the state of the target lock on the first PN is queued, that is, the lock operation.
  • the value 01 of the data bit indicating the state of the target lock on the node device is incremented by 10
  • the value obtained is 11.
  • mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, 0-1 bits in the lock operand can indicate that the node identifier is 0.
  • the PN uses the mapping relationship of the state of the target lock, and when the mapping relationship between the value of the binary number and the state of the lock satisfies the mapping relationship shown in the above table, the operating unit 62 may also be configured to: when the target lock is in the node device When the state of the upper state is the shared lock state, the target data object is used to perform an exclusive lock operation using the target lock.
  • the first update unit 63 is further configured to perform an FAA operation on the lock operand, wherein a value added in the FAA operation is 2 x 4' ⁇ (ie, the second value is also used to represent an exclusive lock)
  • the value, such as 10 obtains the original value of the lock operand, and obtains a value after the FAA operation (ie, the updated value), which is the above-mentioned original value of the above lock operation plus 2 x 4
  • the value of ' ⁇ such that the value is added to indicate that the state of the target lock on the first PN is queued, that is, the data bit of the lock operand indicating the state of the target lock on the node device.
  • the value of 01 plus 10 gives a value of 11.
  • the state of the target lock represented by the original value in each PN of the database system is the permission to add a shared lock state; or the target lock represented by the original value is in the The state on the first PN node is a shared lock, and the state of the target lock on the other PN is unlocked, then it is confirmed that the lock is successful.
  • the value of the data bit in the lock operand indicating the state of the target lock on the node device is a value indicating the queue waiting state ( That is, the first update unit 63 updates the value of the data bit of the update value indicating the state of the target lock on the node device to indicate that the target lock is on the node device.
  • the value of the exclusive lock state ie
  • the FAA operation is performed on the above lock operand, wherein the value added in the FAA operation is -4' ⁇ (ie, minus 01, ).
  • the value of the data bit in the lock operand used to indicate the state of the target lock on the node device is updated from a value (ie, 11) for indicating a queued wait state to a state for indicating an exclusive lock state. Value (ie 10).
  • the state of the target lock represented by the original value on each PN in the database system includes a queue waiting or an exclusive lock, or the target lock represented by the value of the current moment is at the node If the state on the device is a shared lock, and the state of the target lock on another PN or another plurality of PNs is a shared lock, then the operating unit 62 fails to add the lock. Since the first update unit 63 adds a value for indicating the exclusive lock, the value of the data bit in the lock operand indicating the state of the target lock on the node device is used to indicate The value of the queued state (i.e., 11) is such that the second update unit 64 may not be included in this embodiment.
  • the lock state can be shared and locked as an exclusive lock.
  • the obtaining unit 61 may be further configured to receive a lock operand of the target lock sent by a central coordination node in the database system;
  • the node device may send a request message requesting operation to the target lock to the CN, After receiving the message, the NC searches for the lock operation of the target lock in the hash table.
  • the CN creates the lock operand of the target lock and returns it to the node device. .
  • the obtaining unit 61 is further configured to receive a lock operand of the target lock sent by the second PN in the database system.
  • the second PN refers to any PN in the database system other than the node device.
  • the obtaining unit 61 is further configured to read a lock operand of the target lock stored locally by the node device.
  • FIG. 7 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN in the database system.
  • the method includes: an obtaining unit 71, an operating unit 72, and an updating unit 73, where:
  • the acquiring unit 71 is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the
  • the state on each PN in the database system is represented using one or more of the data bits;
  • An operation unit 72 configured to perform a lock operation on the target data object by using the target lock
  • an update unit 73 configured to use, in the lock operand, data indicating a state in which the target lock is on the node device The value of the bit is updated to a value indicating that the target lock is in a lock state on the node device, such that the PN in the database system learns that the target lock is in the node device according to the lock operand The top is locked.
  • the device implementing the present invention may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the node device acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database.
  • a state on each PN in the system is represented using one or more of the lock operands;
  • the node device uses the target lock to perform a lock operation on the target data object;
  • the node device uses the lock operand Updating a value of a data bit indicating a state of the target lock on the node device to a value indicating that the target lock is in a lock state on the node device to enable a PN in the database system Obtaining, according to the lock operand, that the target lock is in a lock state on the node device.
  • FIG. 8 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN in the database system.
  • the method includes: an obtaining unit 81, an operating unit 82, and an updating unit 83, where:
  • the obtaining unit 81 is configured to acquire a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database system
  • the state on each PN is represented by one or more data bits in the operand
  • the lock operand may be a set of M-bit binary numbers, where M is the number of bits of the operating system of the PN, such as a 32-bit operating system, then the M is 32, and the operating system is 128. M is 128.
  • the lock operand may include data of two 2-digit binary numbers. The data of one 2-bit binary number indicates the state of the target lock on one ,, that is, the state of the target lock currently on each ⁇ in the database system uses one 2-bit binary of the lock operand The data representation of the number.
  • the operation unit 82 is configured to perform a lock operation on the target data object by using the target lock.
  • the unlocking operation may include:
  • the updating unit 83 is configured to acquire an original value of the lock operand at a time when the target data object is locked by using the target lock, and use the original value to represent the target lock.
  • the value of the data bit of the state on the node device is added with a preset third value to obtain an updated value of the lock operand, and the updated value indicates that the target lock is on the node device.
  • the value of the data bit of the state is a value for indicating that the target lock is in an unlocked state on the node device.
  • the third value may be -01 or -10, such that when the operating unit 82 puts the shared lock, the third value is -01; when the operating unit 82 puts it out In the case of a lock, the third value is -10 to obtain a value of 00 in the updated value indicating the state of the target lock on the node device.
  • the node device may further include:
  • the determining unit 84 is configured to determine whether the state of the target lock represented by the original value is in a queue waiting state in each state in the database system, and if yes, the node device is in a queue waiting state to the target lock The update value is sent to cause the target lock to be in a queued wait state to lock the target lock.
  • the target lock mentioned above is queued waiting, that is, the state of the target lock is queued in the state of the target lock, so that the determining unit 84 sends the updated value to the target lock for waiting in the queue, so that There is no need to go through the CN, saving CN overhead.
  • the operation unit 82 may be further configured to perform the common lock on the target lock. Lock-up operation;
  • the updating unit 83 can also be configured to perform an FAA operation on the lock operand, wherein the value added in the FAA operation is -4'. (ie, the third value is also used to represent the value of the shared lock. If -01), the original value of the lock operand is obtained, and a value after performing the FAA operation (ie, the above updated value) is obtained, and the value is the above-mentioned original value of the lock operation plus -4' ⁇
  • the value of the added value indicates that the state of the target lock on the first PN is unlocked, that is, the value of the data bit in the lock operand indicating the state of the target lock on the node device. After subtracting 01, the value is 00.
  • the operation unit 82 may be further configured to perform the operation of releasing the lock on the target lock. ;
  • the updating unit 83 can also be configured to perform an FAA operation on the lock operand, wherein the value added in the FAA operation is -2 x 4' ⁇ (ie, the third value is understood to be used to indicate that the lock is released. a value, such as -10), obtains the original value of the lock operand, and obtains a value after the FAA operation (ie, the updated value), the value is the above-mentioned original value of the above lock operation plus -2 x a value of 4' ⁇ , the added value indicates that the state of the target lock on the first PN is unlocked, that is, the data bit in the lock operand indicating the state of the target lock on the node device After the value 10 is decremented by 10, the value obtained is 00.
  • the obtaining unit 81 may be further configured to receive a lock operand of the target lock sent by a central coordination node in the database system;
  • the obtaining unit 81 is further configured to receive a lock operand of the target lock sent by the second PN in the database system, where the second PN refers to the database system Any PN other than the node device.
  • the obtaining unit 81 is further configured to read a lock operand of the target lock stored locally by the node device.
  • FIG. 9 is a schematic structural diagram of another node device according to an embodiment of the present disclosure, where the node device is A PN in the database system, as shown in FIG. 9, includes: a memory 91 and a processor 92, wherein: the memory 91 is configured to store a set of program codes, and the processor 92 is configured to adjust the program code stored in the memory 91 for execution as follows operating:
  • the lock operand is used to record a state of the target lock currently on each PN in the database system, and the target lock is currently on each PN in the database system
  • the state is represented using one or more of the data bits of the lock operand
  • the target data object is locked using the target lock.
  • Determining that the locking operation is successful when the lock operand satisfies a condition that the locking operation is successful, and using the data bit of the lock operand for indicating the state of the target lock on the node device The value is updated to a value indicating that the target lock is in a locked state on the node device.
  • the device implementing the present invention may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the node device acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database.
  • a state on each PN in the system is represented using one or more of the lock operands; the node device uses the target lock to lock the target data object; when the lock operand satisfies a lock operation Upon successful condition, the node device confirms that the locking operation is successful, and updates the value of the data bit in the lock operand indicating the state of the target lock on the node device to be used to indicate the
  • the target lock is a value of the locked state on the node device.
  • FIG. 10 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN in the database system.
  • the device includes: a memory 101 and a processor 102, where:
  • the memory 101 is used to store a set of program codes, and the processor 102 is configured to adjust the program code stored in the memory 101 for performing the following operations:
  • the lock operand is for recording a state of the target lock currently on each PN in the database system, and the target lock is currently in each PN in the database system
  • the upper state is represented using one or more of the data bits of the lock operand
  • Determining that the locking operation fails when the lock operand does not satisfy the condition that the locking operation is successful, and using the data bit of the operand for indicating the state of the target lock on the node device The value is updated to a value indicating that the target lock is in a queued wait state on the node device.
  • the processor 102 when the lock operand satisfies the condition that the lock operation succeeds, the processor 102 confirms that the lock operation is successful, and uses the lock operand to indicate the
  • the operation of updating the value of the data bit of the state of the target lock on the node device to a value indicating that the target lock is in the locked state on the node device may include:
  • the operation performed by the processor 102 to lock the target data object by using the target lock may include:
  • the operation performed by the processor 102 to confirm that the locking operation is successful when the original value satisfies the condition that the locking operation is successful may include:
  • the permission to share the lock state is any one of an unlocked state and a shared lock state.
  • the target data lock is locked by the processor 102 using the target lock.
  • the operation can include:
  • the operation performed by the processor 102 to confirm that the locking operation is successful when the original value satisfies the condition that the locking operation is successful may include:
  • the permission to share the lock state is any one of an unlocked state and a shared lock state.
  • the current PN can read, modify, delete, etc. the data pair corresponding to the target lock.
  • the processor 102 determines that the lock operation fails, and uses the operand to indicate that the target lock is in the
  • the operation of updating the value of the data bit of the state on the node device to a value indicating that the target lock is in the queue waiting state on the node device may include:
  • Determining that the locking operation fails when the original value does not satisfy the condition that the locking operation is successful, and using the data value of the original value for indicating the state of the target lock on the node device The value is updated to a value indicating that the target lock is in a queued wait state on the node device.
  • the operation performed by the processor 102 to lock the target data object by using the target lock may include:
  • the target data object is used to perform an exclusive lock operation on the target data object; that is, an exclusive lock is added on the shared lock.
  • the processor 102 confirms that the lock operation is successful, and uses the lock operand to indicate that the target lock is in the
  • the operation of updating the value of the data bit of the state on the node device to a value indicating that the target lock is in a locked state on the node device may include:
  • the mapping relationship between the location of the binary number of the lock operand and the node identifier satisfies the mapping relationship listed above (ie, the 0-1 bit in the lock operand can represent the state of the PN using the target lock with the node identifier being 0)
  • the second value may be 10
  • the updated value is used to indicate that the target lock is in the
  • the value of the data bit of the state on the node device is updated to a value indicating that the target lock is in an exclusive lock state on the node device, and may be used to represent the target lock in the updated value.
  • the value of the data bit of the state on the node device is added -01.
  • the processor 102 may update, by using the FAA operation described in the foregoing embodiment, a value of a data bit in the lock operand indicating a state of the target lock on the node device, where Repeat the instructions.
  • the node device may further include:
  • a receiver 103 configured to receive a lock operand of the target lock sent by a central coordination node in the database system
  • the operation of acquiring the lock operand of the target lock performed by the processor 102 may include: receiving, by the control receiver 103, a lock operand of the target lock sent by the central coordination node in the database system.
  • the node device may send a request message requesting operation to the target lock to the CN, After receiving the message, the NC searches for the lock operation of the target lock in the hash table.
  • the CN creates the lock operand of the target lock and returns it to the node device. .
  • the node device may further include:
  • the receiver 103 can also be configured to receive a lock operand of the target lock sent by the second PN in the database system.
  • the second PN refers to any of the database systems except the current PN PN;
  • the operation of acquiring the lock operand of the target lock performed by the processor 102 may include: controlling the receiver 103 to receive the lock operand of the target lock sent by the other PNs in the database system.
  • the operation performed by the processor 102 to acquire the lock operand of the target lock may include:
  • FIG. 11 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN of a database system, as shown in FIG. 11, a memory 111 and a processor 112, where
  • the memory 111 is used to store a set of program codes, and the processor 112 is configured to adjust the program code stored in the memory 111 for performing the following operations:
  • the lock operand is used to record a state of the target lock currently on each PN in the database system, and the target lock is currently on each PN in the database system
  • the state is represented using one or more of the data bits
  • the foregoing node device may be a node device in any database system, for example, a computer, a node device in a network, such as a base station, a controller device, or the like.
  • the node device acquires a lock operand of the target lock, where the lock operand is used to record a state that the target lock is currently on each PN in the database system, and the target lock is currently in the database.
  • a state on each PN in the system is represented using one or more of the lock operands;
  • the node device uses the target lock to perform a lock operation on the target data object;
  • the node device uses the lock operand Data bits representing the state of the target lock on the node device The value is updated to a value indicating that the target lock is in a lock state on the node device, so that the PN in the database system learns that the target lock is on the node device according to the lock operand Locked state.
  • FIG. 12 is a schematic structural diagram of another node device according to an embodiment of the present invention.
  • the node device is a PN of the database system.
  • the memory 121, the processor 122, and the transmitter 123 are used to store one.
  • the program code is used by the processor 122 to adjust the program code stored in the memory 121 for performing the following operations:
  • the lock operand is used to record a state of the target lock currently on each PN in the database system, and the target lock is currently on each PN in the database system
  • the state is represented using one or more of the data bits
  • the processor 122 can obtain the foregoing original value by using the FAA operation described in the foregoing embodiment, and the foregoing updated value, and the repeated description is not repeated here.
  • the node device may further include:
  • a receiver 124 configured to receive a lock operand of the target lock sent by a central coordination node in the database system
  • the operation of acquiring the lock operand of the target lock performed by the processor 122 may include: receiving, by the control receiver 124, the sending by the central coordination node in the database system The lock operand of the target lock.
  • the node device may send a request message requesting operation to the target lock to the CN, After receiving the message, the NC searches for the lock operation of the target lock in the hash table.
  • the CN creates the lock operand of the target lock and returns it to the node device. .
  • the node device may further include:
  • the receiver 124 is also operative to receive a lock operand of the target lock sent by the second PN in the database system.
  • the second PN refers to any PN in the database system except the current PN;
  • the operation of acquiring the lock operand of the target lock performed by the processor 122 may include: controlling the receiver 124 to receive the lock operand of the target lock sent by the other PNs in the database system.
  • the operation performed by the processor 124 to acquire the lock operand of the target lock may include:
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

Landscapes

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

Abstract

本发明实施例公开了一种数据库系统的锁操作方法,包括:第一处理节点获取目标锁的锁操作数;第一处理节点使用所述目标锁对目标数据对象进行加锁操作;当所述锁操作数满足加锁操作成功的条件时,第一处理节点确认所述加锁操作成功,并将所述锁操作数中用于表示所述目标锁在所述第一处理节点上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态的值。相应地本发明实施例还公开了一种节点设备。本发明实施例可以提高数据库系统的性能。

Description

一种数据库系统的锁操作方法及设备
技术领域
本发明涉及数据库领域, 尤其涉及一种数据库系统的锁操作方法及设备。 背景技术
共享集群数据库系来主要用于联机事务处理 ( On-Line Transaction Processing, OLTP )应用,该应用需要支持大量并发用户定期添加和修改数据, 因此整个数据库系统需要管理大量的各种类型的锁, 常见的有页锁、常规锁和 元组锁等。 由于数据库系统需要用于锁来保证数据库的各种状态的一致性, 因 此与 10操作一样, 加锁和放锁通常也是数据库系统里耗费时间最长的操作之 一, 进而数据库中的锁子系统的设计会很大程度影响整个数据库系统的性能。
对于锁子系统, 除了需要管理各种各样的锁之外,还要实现对这些锁的加 锁或放锁操作, 而每个锁的锁定状态包含共享锁和排它锁这两种锁定状态,锁 的加锁或放锁操作就可以包括加共享锁的操作或放共享锁的操作,以及加排它 锁的操作或放排它锁的操作。
目前实现锁的加锁或放锁操作, 主要通过如下方式实现:
处理节点 (Processing Node, PN ) 向中心协调节点 ( Coordinator Node , CN )请求消息, 该请求消息包含目标锁的信息, 该请求信息可以是加锁请求 消息或放锁请求消息, 若是加锁请求消息, 则该请求消息包含请求加共享锁的 请求消息或请求加排它锁的请求消息;
CN接收到该请求消息后, 根据上述目标锁的信息搜索该目标锁, 如果是 加锁请求消息, 且该目标锁可以加锁, 则对目标锁进行加锁, 并向上述 PN返 回加锁成功的消息; 如果是加锁请求消息, 且该目标锁当前不可以用于加锁, 则向上述 PN发送用于请求上述 PN加入该目标锁的等待队列的请求消息。 如 果是放锁请求消息, 则对目标锁进行放锁,若该目标锁的等待队列有其它 PN, 则从这其它 PN中选择一个 PN发送通知消息实现目标锁转移。
上述技术中, PN对任一锁的加锁或放锁操作都必需通过与 CN进行消息 交互才可以完成锁的加锁或放锁的操作。 而在实现应用中, PN对锁的加锁或 放锁的操作的数量是很庞大的, 这样 CN就需要处理大量的锁消息, 导致 CN 很容易达到性能瓶颈, 从而造成数据库系统的性能很低。 发明内容
本发明实施例提供了一种数据库系统的锁操作方法及设备,可以提高数据 库系统的性能。
本发明第一方面提供一种数据库系统的锁操作方法, 所述方法包括: 第一处理节点获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁 当前在所述数据库系统中各个处理节点上的状态,且所述目标锁当前在所述数 据库系统中每个处理节点上的状态使用所述锁操作数中的一个或者多个数据 位表示;
所述第一处理节点使用所述目标锁对目标数据对象进行加锁操作, 并将 所述锁操作数中用于表示所述目标锁在所述第一处理节点上的状态的数据位 的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态的值;
所述第一处理节点根据所述锁操作数确认所述加锁操作是否成功。
在第一种可能的实现方式中,所述将所述锁操作数中用于表示所述目标锁 在所述第一处理节点上的状态的数据位的值更新为用于表示所述目标锁在所 述第一处理节点上为加锁状态的值, 包括:
获取使用所述目标锁对所述目标数据对象进行加锁操作的时刻所述锁操 作数的原有值;
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态的值; 所述第一处理节点根据所述锁操作数确认所述加锁操作是否成功, 包括: 当所述原有值满足加锁操作成功的条件时 ,所述第一处理节点确认所述加 锁操作成功; 否则, 确定所述加锁操作失败。
结合第一方面的第一种可能的实现方式,在第二种可能的实现方式中, 所 述第一处理节点使用所述目标锁对所述目标数据对象进行加锁操作包括: 所述第一处理节点使用所述目标锁对所述目标数据对象进行加共享锁的 操作;
所述将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态 的值, 包括:
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值加上预先设定的第一值,得到所述锁操作数的更新值; 所述更新值中 用于表示所述目标锁在所述第一处理节点上的状态的数据位的值为表示所述 目标锁在所述第一处理节点上为共享锁状态的值;
所述当所述原有值满足加锁操作成功的条件时,所述第一处理节点确认所 述加锁操作成功, 否则, 确定所述加锁操作失败包括: 所述第一处理节点判断所述原有值所记录的所述目标锁在所述数据库系 统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所述加 共享锁操作成功; 若否, 则确认所述加共享锁操作失败;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 结合第一方面的第一种可能的实现方式,在第三种可能的实现方式中, 所 述第一处理节点使用所述目标锁对所述目标数据对象进行加锁操作包括: 所述第一处理节点使用所述目标锁对所述目标数据对象进行加排它锁的 操作;
所述将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态 的值, 包括:
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值加上预先设定的第二值,得到所述锁操作数的更新值; 所述更新值中 用于表示所述目标锁在所述第一处理节点上的状态的数据位的值为表示所述 目标锁在所述第一处理节点上为排他锁状态的值;
当所述原有值满足加锁操作成功的条件时 ,所述第一处理节点确认所述加 锁操作成功, 否则, 确定所述加锁操作失败包括:
所述第一处理节点判断所述原有值所记录的所述目标锁在所述数据库系 统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所述加 排它锁操作成功, 否则, 确定所述加排它锁操作失败; 或者
所述第一处理节点判断所述原有值所记录的所述目标锁在所述第一处理 节点上的状态是否为共享锁状态,且在其它处理节点上的状态是否均为未锁定 状态, 若是, 则确认所述加排它锁操作成功, 否则, 确定所述加排它锁操作失 败;所述其它处理节点为所述数据库系统中除所述第一处理节点之外的所有处 理节点;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 结合第一方面的第一种可能的实现方式或第一方面的第二种可能的实现 方式中, 在第四种可能的实现方式中, 所述方法还包括:
当所述第一处理节点确定所述加锁操作失败时,将所述更新值中用于表示 所述目标锁在所述第一处理节点上的状态的数据位的值更新为用于表示所述 目标锁在所述第一处理节点上为排队等待状态的值。 本发明第二方面提供一种数据库系统的锁操作方法, 包括:
第一处理节点获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁 当前在所述数据库系统中各个处理节点上的状态,且所述目标锁当前在所述数 据库系统中每个处理节点上的状态使用所述操作数中的一个或者多个数据位 表示;
所述第一处理节点使用所述目标锁对目标数据对象进行放锁操作; 所述第一处理节点将所述锁操作数中用于表示所述目标锁在所述第一处 理节点上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节 点上为未锁定状态的值,以使所述数据库系统中的处理节点根据所述锁操作数 获知所述目标锁在所述第一处理节点上为未锁定状态。
在第一种可能的实现方式中,所述第一处理节点将所述锁操作数中用于表 示所述目标锁在所述第一处理节点上的状态的数据位的值更新为用于表示所 述目标锁在所述第一处理节点上为未锁定状态的值, 包括:
所述第一处理节点获取使用所述目标锁对所述目标数据对象进行放锁操 作的时刻所述锁操作数的原有值,以及将所述原有值中用于表示所述目标锁在 所述第一处理节点上的状态的数据位的值加上预先设定的第三值,得到所述锁 操作数的更新值,所述更新值中表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为未锁定状态的值。
结合第二方面的第一种可能实现方式, 在第二种能可能的实现方式中, 所 述第一处理节点将所述更新值中表示所述目标锁在所述第一处理节点上的状 态的数据位的值作为用于表示所述目标锁在所述第一处理节点上为未锁定状 态的值之后, 所述方法还包括:
所述第一处理节点判断所述原有值所表示的所述目标锁在所述数据库系 统中各个处理节点上的状态是否存在排队等待状态, 若是, 所述第一处理节点 向所述目标锁为排队等待状态的处理节点发送所述更新值,以使所述目标锁为 排队等待状态的处理节点对所述目标锁进行锁操作。
本发明第三方面提供一种节点设备, 包括: 获取单元、 操作单元和确定单 元, 其中:
所述获取单元, 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在数据库系统中各个处理节点上的状态,所述数据库系统为所述节 点设备所在的数据库系统;且所述目标锁当前在所述数据库系统中每个处理节 点上的状态使用所述锁操作数中的一个或者多个数据位表示;
所述操作单元,用于使用所述目标锁对所述节点设备上的目标数据对象进 行加锁操作,并将所述锁操作数中用于表示所述目标锁在所述第一处理节点上 的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加 锁状态的值;
所述确定单元, 用于根据所述锁操作数确认所述加锁操作是否成功。 在第一种可能的实现方式中, 所述操作单元具体包括:
加锁单元,用于使用所述目标锁对所述节点设备上的目标数据对象进行加 锁操作;
获取单元,用于获取所述加锁单元使用所述目标锁对所述节点设备上的目 标数据对象进行加锁操作的时刻所述锁操作数的原有值;
第一更新单元,用于将所述原有值中用于表示所述目标锁在所述节点设备 上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为 加锁状态的值;
所述确认单元, 具体用于当所述原有值满足加锁操作成功的条件时,确认 所述加锁操作成功, 否则, 确定所述加锁操作失败。
结合第三方面的第一种可能的实现方式,在第二种可能的实现方式中, 所 作;
所述第一更新单元,具体用于将所述原有值中用于表示所述目标锁在所述 第一处理节点上的状态的数据位的值加上预先设定的第一值,得到所述锁操作 数的更新值;所述更新值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为共享锁状态的值; 所述确认单元具体用于判断所述原有值所记录的所述目标锁在所述数据 库系统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所 述加共享锁操作成功; 否则, 确定所述加锁操作失败;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 结合第三方面的第一种可能的实现方式,在第三种可能的实现方式中, 所 作;
所述第一更新单元,具体用于将所述原有值中用于表示所述目标锁在所述 第一处理节点上的状态的数据位的值加上预先设定的第二值,得到所述锁操作 数的更新值;所述更新值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为排他锁状态的值; 所述确认单元,具体用于判断所述原有值所记录的所述目标锁在所述数据 库系统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所 述加排它锁操作成功, 否则, 确定所述加排它锁操作失败; 或者
所述确认单元具体用于判断所述原有值所记录的所述目标锁在所述节点 设备上的状态是否为共享锁状态,且在其它处理节点上的状态是否均为未锁定 状态, 若是, 则确认所述加排它锁操作成功, 否则, 确定所述加排它锁操作失 败;所述其它处理节点为所述数据库系统中除所述节点设备之外的所有处理节 点;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 结合第三方面的第二种可能的实现方式或第三方面的第三可能的实现方 式, 在第四种可能的实现方式中, 所述节点设备还包括:
第二更新单元, 用于当所述确认单元确定所述加锁操作失败时, 将所述更 新值中用于表示所述目标锁在所述第一处理节点上的状态的数据位的值更新 为用于表示所述目标锁在所述第一处理节点上为排队等待状态的值。 本发明第四方面提供一种节点设备, 包括: 获取单元、 操作单元和更新单 元, 其中:
所述获取单元, 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在数据库系统中各个处理节点上的状态,所述数据库系统为所述节 点设备所在的数据库系统;且所述目标锁当前在所述数据库系统中每个处理节 点上的状态使用所述操作数中的一个或者多个数据位表示;
所述操作单元, 用于使用所述目标锁对目标数据对象进行放锁操作; 所述更新单元,用于将所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为未 锁定状态的值,以使所述数据库系统中的处理节点根据所述锁操作数获知所述 目标锁在所述节点设备上为未锁定状态。
在第一种可能的实现方式中,所述更新单元具体用于获取使用所述目标锁 对所述目标数据对象进行放锁操作的时刻所述锁操作数的原有值,以及将所述 原有值中用于表示所述目标锁在所述节点设备上的状态的数据位的值加上预 先设定的第三值,得到所述锁操作数的更新值, 所述更新值中表示所述目标锁 在所述节点设备上的状态的数据位的值为表示所述目标锁在所述节点设备上 为未锁定状态的值。
结合第四方面的第一种可能的实现方式,在第二种可能的实现方式中, 所 述节点设备还包括:
判断单元,用于在所述更新单元将所述锁操作数中用于表示所述目标锁在 所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所述节点 设备上为未锁定状态的值之后,判断所述原有值所表示的所述目标锁在所述数 据库系统中各个处理节点上的状态是否存在排队等待状态, 若是, 向所述目标 锁为排队等待状态的处理节点发送所述更新值,以使所述目标锁为排队等待状 态的处理节点对所述目标锁进行锁操作。
上述技术方案中, 第一处理节点获取目标锁的锁操作数, 所述锁操作数用 于记录所述目标锁当前在所述数据库系统中各个处理节点上的状态,且所述目 标锁当前在所述数据库系统中每个处理节点上的状态使用所述锁操作数中的 一个或者多个数据位表示;第一处理节点使用所述目标锁对目标数据对象进行 加锁操作; 当所述锁操作数满足加锁操作成功的条件时, 第一处理节点确认所 述加锁操作成功,并将所述锁操作数中用于表示所述目标锁在所述第一处理节 点上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上 为加锁状态的值。 这样处理节点通过锁操作数来实现锁操作, 整个锁操作过程 由处理节点独立完成,从而中心协调节点无需处理锁消息, 这样就可以提高数 据库系统的性能。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施 例或现有技术描述中所需要使用的附图作筒单地介绍,显而易见地, 下面描述 中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲, 在不付 出创造性劳动的前提下, 还可以根据这些附图获得其他的附图。
图 1 是本发明实施例的提供的一种数据库系统的锁操作方法的流程示意 图;
图 2 是本发明实施例的提供的另一种数据库系统的锁操作方法的流程示 意图; 图 3 是本发明实施例的提供的另一种数据库系统的锁操作方法的流程示 意图; 图 4 是本发明实施例的提供的另一种数据库系统的锁操作方法的流程示 意图; 图 5是本发明实施例提供的一种节点设备的结构示意图; 图 6是本发明实施例提供的另一种节点设备的结构示意图; 图 7是本发明实施例提供的另一种节点设备的结构示意图; 图 8是本发明实施例提供的另一种节点设备的结构示意图; 图 9是本发明实施例提供的另一种节点设备的结构示意图; 图 10是本发明实施例提供的另一种节点设备的结构示意图; 图 11是本发明实施例提供的另一种节点设备的结构示意图; 图 12是本发明实施例提供的另一种节点设备的结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。基于本发明中的实施例, 本领域普通技术人员在没有作出创造 性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。
图 1 是本发明实施例的提供的一种数据库系统的锁操作方法的流程示意 图,所述锁所在的数据库系统包含 N个 PN, N为大于 0的整数,如图 1所示, 包括:
101、 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记录所述目标 锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述数据 库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数据位表示; 可选的, 上述第一 PN可以为数据库系统中任一 PN, 上述目标锁为上述 系统中任一锁, 例如组锁, 页锁等; 数据库系统中所有的锁的锁操作数可以保 存在该数据库系统的中心协调节点 CN中, 因此第一 PN可以从该 CN中查询 得到该目标锁的锁操作数,从而得到该目标锁当前在该数据库系统中各个处理 节点上的状态信息。
可选的, 本发明实施例中, 所述目标锁在 PN上的状态可以包括如下至少 一项:
未锁定( No lock hold ),共享锁( Share lock held ),排它锁( Exclusive lock held )和排队等待(Lock pending )。 上述锁操作数中的状态值表示 PN使用目 标锁的状态。
102、 第一 PN使用所述目标锁对目标数据对象进行加锁操作。
103、 当所述锁操作数满足加锁操作成功的条件时, 所述第一 PN确认所 述加锁操作成功, 并将所述锁操作数中用于表示所述目标锁在所述第一 PN上 的状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为加锁状态 的值。
作为一种可选的实施方式, 实现本发明的设备, 即 PN可以是任一数据库 系统中的节点设备, 例如, 计算机、 网络中节点设备, 如基站、控制器设备等。
上述技术方案中, 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 第一 PN使用所述目标锁对目标数据对象进行加锁操作; 当所述锁 操作数满足加锁操作成功的条件时, 第一 PN确认所述加锁操作成功, 并将所 述锁操作数中用于表示所述目标锁在所述第一 PN上的状态的数据位的值更新 为用于表示所述目标锁在所述第一 PN上为加锁状态的值。 这样整个锁操作过 程由第一 PN独立完成, 从而 CN无需处理锁消息, 这样就可以提高数据库系 图 2 是本发明实施例提供的另一种数据库系统的锁操作方法的流程示意 图, 如图 2所示, 包括:
201、 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记录所述目标 锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述数据 库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数据位表示。
作为一种可选的实施方式, 上述锁操作数可以是一组 M位二进制数, M 为 PN的操作系统的位数, 如 32位的操作系统那么 M就为 32 , 如操作系统为 128那么 M就为 128。
可选的, 该实施方式中, 若上述数据库系统中 PN的个数为 N, 且 N和 M 满足 N = M / 2时, 那么上述锁操作数就可以包含 Ν个 2位二进制数的数据, 1 个 2位二进制数的数据表示目标锁在 1个 ΡΝ上的状态, 即所述目标锁当前在 所述数据库系统中每个 ΡΝ上的状态使用所述锁操作数中的 1个 2位二进制数 的数据表示。
可选的, 上述系统中每个 ΡΝ可以设置有节点标识, 那么本发明实施例就 可以建立锁操作数的二进制数的位置与节点标识的映射关系, 如上述 Ν个 ΡΝ 的节点标识为 0123...Ν, 上述映射关系就可以是锁操作数中 0-1位的数据就可 以表示目标锁在为节点标识为 0的 ΡΝ上的状态, 锁操作数中 2-3位的数据就 可以表示目标锁在为节点标识为 1的 ΡΝ上的状态, 锁操作数中 3-4位的数据 就可以表示目标锁在为节点标识为 2的 ΡΝ上的状态, 锁操作数中 5-6位的数 据就可以表示目标锁在为节点标识为 3的 ΡΝ上的状态,…,锁操作数中 N -1-Ν 位的数据就可以为表示目标锁在节点标识为 Ν的 ΡΝ上的状态。 例如, 第一 ΡΝ的节点标识为 0那么, 操作数中 0-1位二进制数表示目标锁在第一 ΡΝ上 的状态。 当然上述节点标识和上述映射关系仅是本发明实例中一个例子。本发 明实例包括但不限上述列出的节点标识和映射关系。
可选的, 目标锁在 ΡΝ上的状态可以包括如下至少一项:
未锁定、 共享锁、 排它锁和排队等待。 本发明实施例中还可以建立二进制 数的值与锁的状态的映射关系, 该映射关系可以如下所示: 锁操作数( 2位 ) 锁状态
00 未锁定
01 共享锁
10 排它锁
11 排队等待
其中, 上表只显示 2位二进制数, 表示目标锁在一个 PN上的状态, 例如 表中的 2位二进制数为 0-1位, 即表中的 2位二进制数表示目标锁在为节点标 识为 0的 PN上的状态, 当表中的 2位二进制数为 01时, 那么目标锁在节点 标识为 0的 PN上的状态为共享锁, 当表中的 2位二进制数为 10时, 那么目 标锁在节点标识为 0的 PN上的状态为排它锁。 当然在本发明实施例中包括不 始于上述列出的二进制数的值与锁的状态的映射关系。
202、 第一 PN使用所述目标锁对目标数据对象进行加锁操作。
作为一种可选的实施方式, 上述加锁操作可以包括:
加共享锁的操作或加排它锁的操作。
203、 当所述锁操作数满足加锁操作成功的条件时, 所述第一 PN确认所 述加锁操作成功, 并将所述锁操作数中用于表示所述目标锁在所述第一 PN上 的状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为加锁状态 的值。
例如: 如上述映射关系所示, 用于表示加锁状态的值为 01或者 10, 这样 当步骤 202加共享锁时,步骤 203就可以将所述锁操作数中用于表示所述目标 锁在所述第一 PN上的状态的数据位的值更新为 01 ; 当步骤 202加排它锁时, 步骤 203就可以将所述锁操作数中用于表示所述目标锁在所述第一 PN上的状 态的数据位的值更新为 10。
作为一种可选的实施方式, 步骤 203之后, 所述方法还可以包括: 204、 当所述锁操作数不满足加锁操作成功的条件时, 所述第一 PN确定 所述加锁操作失败, 并将所述操作数中用于表示所述目标锁在所述第一 PN上 的状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为排队等待 状态的值。 这样可以实现当加锁操作失败时, 将目标锁在第一 PN上的状态更新为排 队等待状态。
作为一种可选的实施方式, 步骤 203可以包括:
第一 PN获取使用所述目标锁对所述目标数据对象进行加锁操作的时刻所 述锁操作数的原有值, 以及将所述原有值中用于表示所述目标锁在所述第一 PN上的状态的数据位的值加上预先设定的第一值, 得到所述锁操作数的更新 值;
当所述原有值满足加锁操作成功的条件时, 第一 PN确认所述加锁操作成 功, 并将所述更新值中用于表示所述目标锁在所述第一 PN上的状态的数据位 的值作为用于表示所述目标锁在所述第一 PN上为加锁状态的值。
可选的,当锁操作数的二进制数的位置与节点标识的映射关系满足上述列 出的映射关系,且二进制数的值与锁的状态的映射关系满足上表所示的映射关 系时, 上述第一值可以是 01或者 10。
可选的, 步骤 202是进行加共享锁操作, 那么步骤 203可以通过上述锁操 作数的值加上 4'' , 即只需要执行一个 ΡΓ + 4'·就可以得到上述更新值, 其中, 4''为 二进制数 (例如 4。 = 0001, 41 = 0100, 42 = 010000, ), i为第一 PN的节点标识, W为上 述锁操作数的的原有值。 例如第一 PN的节点标识为 0时, 即将 W加上 0001 , 第一 PN的节点标识为 1时, 即将 W加上 0100。 需要说明的是, 该实施方式 中, 仅根据上述列出的映射关系而计算的, 当上述映射关系改变时, 步骤 203 的算法也可以作出相应的变化。
可选的, 上述原有值指步骤 202中第一 PN对目标锁进行加锁操作的时刻 上述锁操作数的值; 在实际应用中, 数据库系统中可能是会多个 PN对上述目 标锁进行锁操作, 同时, 这些 PN对目标锁的锁操作的时间可能很相近, 即在 本发明实例例执行步骤 201和步骤 202之间,就有其它 PN对目标进行锁操作, 这样就会改变操作数中用于表示目标锁在其它 PN上的状态的数据位, 即会更 新上述锁操作数的值,即步骤 201获取的锁操作数的值在对目标锁进行加锁操 作时不一定是最新值。所以为了保证能得知步骤 202的加锁操作是否成功, 步 骤 203就可以获取上述原有值,即执行步骤 202中的加锁操作时刻上述锁操作 数的值。 可选的, 步骤 203可以通过原子操作中 FAA操作 ( Fetch And Add , 该操 作的内容是将操作数的原有值加一个值, 并返回原有值的原子操作), 原子操 作是数据库系统中或 ΡΝ中一直执行的操作,即从开机到关机该操作一直执行, 这样通过上述 FAA操作就可以获取上述锁操作数的原有值。 由于 FAA操作的 内容是将操作数的原有值加一个值, 并返回原有值的原子操作, 这样步骤 203 就可以通过该操作获取到上述锁操作数的原有值, 同时, FAA操作中加了上 述第一值, 例如上述 4'· , 即步骤 203 只需要执行一个 4'· , 就可以得到上述 更新值, 其中 i当前 ΡΝ的节点标识, V为上述锁操作数的原有值。
可选的, 步骤 202可以包括:
第一 PN使用所述目标锁对所述目标数据对象进行加共享锁的操作; 步骤 203中当所述原有值满足加锁操作成功的条件时, 所述第一 PN确认 所述加锁操作成功, 可以包括:
所述第一 PN判断所述原有值所记录的所述目标锁在所述数据库系统中各 个 PN上的状态是否均为允许加共享锁状态; 若是, 则确认所述加共享锁操作 成功;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 即上述加锁操作成功的条件可以包括:
所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态为 上述允许加共享锁状态, 即未锁定或者共享锁, 即在上述原有值所表示的目标 锁在所述数据库系统中各个 PN上的状态要么为未锁定, 要么为共享锁, 上述 原有值所表示的目标锁在所述数据库系统中各个 PN上的状态不包括排它锁或 排队等待。 即上述原有值没有表示目标锁在任一 PN上的状态为排它锁或排队 等待。 这样第一 PN就可以对目标锁加共享锁成功。
可选的, 步骤 202可以包括:
第一 PN使用所述目标锁对所述目标数据对象进行加排它锁的操作; 步骤 203中的当所述原有值满足加锁操作成功的条件时, 所述第一 PN确 认所述加锁操作成功, 可以包括:
第一 PN 判断所述原有值所记录的所述目标锁在所述数据库系统中各个 PN上的状态是否均为允许加共享锁状态; 若是, 则确认所述加排它锁操作成 功; 或者
步骤 203中的当所述原有值满足加锁操作成功的条件时, 所述第一 PN确 认所述加锁操作成功, 可以包括:
第一 PN判断所述原有值所记录的所述目标锁在所述第一 PN上的状态是 否为共享锁状态, 若是, 则判断所述原有值所记录的所述目标锁在其它 PN上 的状态是否均为未锁定状态, 若是, 则确认所述加排它锁操作成功; 所述其它 PN为所述数据库系统中除所述第一 PN之外的所有 PN;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 即上述加锁操作成功的条件可以包括:
所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态为 未锁定或者共享锁; 或者, 所述原有值所表示的所述目标锁在所述第一 PN节 点上的状态为共享锁,所述目标锁在其它 PN上的状态为未锁定;所述其它 PN 为所述数据库系统中除所述第一 PN节点之外的所有 PN。 所述原有值中不包 括排它锁或排队等待, 或者除第一 PN使用目标锁的状态为共享锁之外不包括 共享锁。 这样第一 PN就可以对目标锁加排它锁成功。
可选的, 确认加锁操作成功, 当前 PN就可以对目标锁对应的数据对进行 读取、 修改、 删除等操作。
可选的, 步骤 204可以包括:
当所述原有值不满足加锁操作成功的条件时, 所述第一 PN确定所述加锁 操作失败, 并将所述原有值中用于表示所述目标锁在所述第一 PN上的状态的 数据位的值更新为用于表示所述目标锁在所述第一 PN 上为排队等待状态的 值。
可选的, 为了避免当前 PN对目标进行锁操作的过程中, 有其它 PN对目 标锁进行锁操作, 步骤 204可以同上述步骤 203—样, 步骤 204也可以是通过 上述 FAA操作将锁操作数中用于表示所述目标锁在所述第一 PN上的状态的 数据位的值用于表示所述目标锁在所述第一 PN上为排队等待状态的值。 即步 骤 204可以包括:
当所述原有值不满足加锁操作成功的条件时, 所述第一 PN确定所述加锁 操作失败,并通过 FAA操作将锁操作数中用于表示所述目标锁在所述第一 PN 上的状态的数据位的值用于表示所述目标锁在所述第一 PN上为排队等待状态 的值, 其中, FFA操作中所加的值为与所述第一值相反的值, 即上述第一值为 01时, FFA操作中所加的值就为 -01 , 上述第一值为 10时, FFA操作中所加的 值就为 -10。 这样就保证了步骤 204执行的更新时, 所使用的锁操作数的值是 最新的。
作为一种可选的实施方式, 步骤 202可以包括:
当所述目标锁在所述第一 PN上的状态为共享锁状态时, 所述第一 PN使 用所述目标锁对所述目标数据对象进行加排它锁的操作;即上共享锁的基础上 加排它锁。
可选的, 步骤 203可以包括:
第一 PN获取使用所述目标锁对所述目标数据对象进行加排它锁操作的时 一 PN上的状态的数据位的值加上预先设定的第二值,得到所述锁操作数的更 新值;
当所述原有值满足加排它锁操作成功的条件时, 第一 PN确认所述加排它 的数据位的值更新为用于表示所述目标锁在所述第一 PN 上为排它锁状态的 值。
可选的,当锁操作数的二进制数的位置与节点标识的映射关系满足上述列 出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标 锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足上表所示 的映射关系时, 上述第二值可以是 10 , 上述将所述更新值中用于表示所述目 标锁在所述第一 PN上的状态的数据位的值更新为用于表示所述目标锁在所述 第一 PN上为排它锁状态的值, 可以是将更新值中用于表示所述目标锁在所述 第一 PN上的状态的数据位的值加上 -01。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 上述步骤 202可以包括: 第一 PN对所述目标锁进行加共享锁的操作,
步骤 203可以包括:
第一 PN对上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 4'' (即上述第一值, 也可以理解为用于表示共享锁的值, 如 01 ), 第一 PN获取 使用所述目标锁对所述目标数据对象进行加锁操作的时刻所述锁操作数的原 有值, 以及得到一个进行 FAA操作后的值(即上述更新值), 该值是上述锁操 作的上述原有值加上 4'·的值, 相加后的值表示目标锁在第一 ΡΝ上的状态为共 享锁, 即原有值中用于表示所述目标锁在所述第一 ΡΝ上的状态的数据位的值 00加上 01后, 得到值就为 01。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 ΡΝ上的状态 为上述允许加共享锁状态时, 那么步骤 203就加共享锁成功, 并将所述更新值 中用于表示所述目标锁在所述第一 ΡΝ上的状态的数据位的值作为用于表示所 述目标锁在所述第一 ΡΝ上为加锁状态的值。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 ΡΝ上的状态 包含排队等待或者排它锁时,那么就执行步骤 204,其中: 步骤 204可以包括: 第一 ΡΝ对上述锁操作数进行 FAA操作, 其中, FAA操作中所加的值为 2 x 4'· , 得到执行步骤 204时刻上述锁操作数的值, 以及得到一个进行 FAA操 作后的值, 该是上述锁操作的执行步骤 204时刻的值加上 2 x 4'·的值, 相加得到 值就表示目标锁在第一 ΡΝ上的状态为排队等待, 即第一位置的数据 01加上 10后, 得到值就为 11。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 ΡΝ使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 步骤 202可以包括:
当所述目标锁在所述第一 ΡΝ上的状态为未锁定状态时, 所述第一 ΡΝ使 用所述目标锁对所述目标数据对象进行加排它锁的操作;
步骤 203可以包括:
第一 ΡΝ上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 2 x 4'· (即上述第一值, 可以理解为用于表示排它锁的值, 如 10 ), 得到所述锁操作 数的原有值, 以及得到一个进行 FAA操作后的值(即上述更新值), 该值是上 述锁操作的上述原有值加上 2 x 4'·的值, 该值表示目标锁在第一 PN上的状态为 排它锁, 即所述锁操作数中用于表示所述目标锁在所述第一 PN上的状态的数 据位 01加上 10后, 得到值就为 10。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 为上述允许加共享锁状态时; 或者, 所述原有值所表示的所述目标锁在所述第 一 PN上的状态为共享锁, 所述目标锁在其它 PN上的状态为未锁定状态时, 那么步骤 203就确认加排它锁成功,并将所述更新值中用于表示所述目标锁在 所述第一 PN 上的状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为排它锁状态的值。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 包含排队等待或者排它锁时, 或者所述原有值所表示的所述目标锁在第一 PN 上的状态为共享锁, 且在另一 PN或者另多个 PN上的状态也为共享锁时, 那 么就执行步骤 204, 其中: 步骤 204可以包括:
第一 PN对上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 4'· , 得到执行步骤 204时刻上述锁操作数的值, 以及得到一个进行 FAA操作后的 值, 该是上述锁操作的执行步骤 204时刻的值加上 4'·的值, 相加得到值就表示 目标锁在第一 PN上的状态为排队等待, 即所述锁操作数中用于表示所述目标 锁在所述第一 PN上的状态的数据位的值 01加上 10后, 得到值就为 11。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 步骤 202可以包括:
当所述目标锁在所述第一 PN上的状态为共享锁状态时, 所述第一 PN使 用所述目标锁对所述目标数据对象进行加排它锁的操作
步骤 203可以包括:
第一 PN对上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 2 x 4'· (即上述第二值, 也可以理解为用于表示排它锁的值, 如 10 ), 得到所述锁操 作数的原有值, 以及得到一个进行 FAA操作后的值(即上述更新值), 该值是 上述锁操作的上述原有值加上 2 x 4'·的值,这样相加得到值就表示目标锁在第一
PN上的状态为排队等待, 即所述锁操作数中用于表示所述目标锁在所述第一 PN上的状态的数据位的值 01加上 10后, 得到值就为 11。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 为上述允许加共享锁状态时; 或者, 所述原有值所表示的所述目标锁在所述第 一 PN节点上的状态为共享锁, 所述目标锁在其它 PN上的状态为未锁定, 那 么就确认加排它锁成功。 由于步骤 203加上上述第二值后, 所述锁操作数中用 于表示所述目标锁在所述第一 PN上的状态的数据位的值为用于表示排队等待 状态的值(即 11 ), 步骤 203将所述更新值中用于表示所述目标锁在所述第一 PN上的状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为排 它锁状态的值, 即
第一 PN对上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 -4'· (即减去 01 , )。即将所述锁操作数中用于表示所述目标锁在所述第一 PN上的 状态的数据位的值从用于表示排队等待状态的值(即 11 ) 更新为用于表示排 它锁状态的值(即 10 )。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 包含排队等待或者排它锁,或者所述当前时刻的值所表示的所述目标锁在所述 第一 PN上的状态为共享锁, 且所述目标锁在另一个 PN或者另多个 PN上的 状态为共享锁, 那么步骤 202就加排它锁失败。 由于步骤 203加上用于表示加 排它锁的值后, 所述锁操作数中用于表示所述目标锁在所述第一 PN上的状态 的数据位的值值为用于表示排队等待状态的值(即 11 ), 这样在本实施例中就 可以不包括步骤 204。
该实施例中, 可以共享锁状态加锁为排它锁。
作为一种可选的实施方式, 步骤 201可以包括:
第一 PN接收所述数据库系统中的中心协调节点发送的所述目标锁的锁操 作数;
可选的, 该实施方式中, 当第一 PN需要对目标锁对应的数据对象进行添 加、 读取、 修改或删除等操作时, 第一 PN就可以向 CN发送请求对目标锁进 行操作的请求消息, NC接收到该消息后就查找哈希表提到目标锁的锁操作数, 当哈希表中不存在目标锁的锁操作信息时, CN就创建目标锁的锁操作数, 并 返回给节点设备。
作为一种可选的实施方式, 步骤 201可以包括:
第一 PN接收所述数据库系统中的第二 PN发送的所述目标锁的锁操作数。 所述第二 PN指所述数据库系统中除所述第一 PN之外的任一 PN。
作为一种可选的实施方式, 步骤 201可以包括:
第一 PN读取当前 PN本地存储的所述目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对加锁操作进行详细说明, 可以 实现提高数据库系统的可用性。 图 3 是本发明实施例提供的另一种数据库系统的锁操作方法的流程示意 图, 如图 3所示, 包括:
301、 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记录所述目标 锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述数据 库系统中每个 PN上的状态使用所述操作数中的一个或者多个数据位表示; 可选的, 上述第一 PN可以为数据库系统中任一 PN, 上述目标锁为上述 系统中任一锁, 例如组锁, 页锁等;
可选的, 本发明实施例中, 所述目标锁在 PN上的状态可以包括如下至少 一项:
未锁定、 共享锁、 排它锁和排队等待。 上述锁操作数中的状态值表示 PN 使用目标锁的状态。
302、 第一 PN使用所述目标锁对目标数据对象进行放锁操作;
303、第一 PN将所述锁操作数中用于表示所述目标锁在所述第一 PN上的 状态的数据位的值更新为用于表示所述目标锁在所述第一 PN上为放锁状态的 值, 以使所述数据库系统中的 PN根据所述锁操作数获知所述目标锁在所述第 一 PN上为放锁状态。
可选的, 上述放锁状态可以是理解为未锁定状态。
作为一种可选的实施方式, 实现本发明的设备, 即 PN可以是任一数据库 系统中的节点设备, 例如, 计算机、 网络中节点设备, 如基站、控制器设备等。 上述技术方案中, 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 第一 PN使用所述目标锁对目标数据对象进行放锁操作; 第一 PN 将所述锁操作数中用于表示所述目标锁在所述第一 PN上的状态的数据位的值 更新为用于表示所述目标锁在所述第一 PN上为放锁状态的值, 以使所述数据 库系统中的 PN根据所述锁操作数获知所述目标锁在所述第一 PN上为放锁状 态。 这样整个锁操作过程由第一 PN独立完成, 从而 CN无需处理锁消息, 这 样就可以提高数据库系统的性能。 图 4 是本发明实施例提供的另一种数据库系统的锁操作方法的流程示意 图, 如图 4所示, 包括:
401、 第一 PN获取目标锁的锁操作数, 所述锁操作数用于记录所述目标 锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述数据 库系统中每个 PN上的状态使用所述操作数中的一个或者多个数据位表示; 作为一种可选的实施方式, 上述锁操作数可以是一组 M位二进制数, M 为 PN的操作系统的位数, 如 32位的操作系统那么 M就为 32 , 如操作系统为 128那么 M就为 128。
可选的, 该实施方式中, 若上述数据库系统中 PN的个数为 N, 且 N和 M 满足 N = M / 2时, 那么上述锁操作数就可以包含 Ν个 2位二进制数的数据, 1 个 2位二进制数的数据表示目标锁在 1个 ΡΝ上的状态, 即所述目标锁当前在 所述数据库系统中每个 ΡΝ上的状态使用所述锁操作数中的 1个 2位二进制数 的数据表示。
可选的, 上述系统中每个 ΡΝ可以设置有节点标识, 那么本发明实施例就 可以建立锁操作数的二进制数的位置与节点标识的映射关系, 如上述 Ν个 ΡΝ 的节点标识为 0123...Ν, 上述映射关系就可以是锁操作数中 0-1位的数据就可 以表示目标锁在为节点标识为 0的 ΡΝ上的状态, 锁操作数中 2-3位的数据就 可以表示目标锁在为节点标识为 1的 ΡΝ上的状态, 锁操作数中 3-4位的数据 就可以表示目标锁在为节点标识为 2的 ΡΝ上的状态, 锁操作数中 5-6位的数 据就可以表示目标锁在为节点标识为 3的 PN上的状态,…,锁操作数中 N -1-N 位的数据就可以为表示目标锁在节点标识为 N的 PN上的状态。 例如, 第一 PN的节点标识为 0那么, 操作数中 0-1位二进制数表示目标锁在第一 PN上 的状态。 当然上述节点标识和上述映射关系仅是本发明实例中一个例子。本发 明实例包括但不限上述列出的节点标识和映射关系。
可选的, 目标锁在 PN上的状态可以包括如下至少一项:
未锁定、 共享锁、 排它锁和排队等待。 本发明实施例中还可以建立二进制 数的值与锁的状态的映射关系, 该映射关系可以如下所示:
Figure imgf000026_0001
其中, 上表只显示 2位二进制数, 表示目标锁在一个 PN上的状态, 例如 表中的 2位二进制数为 0-1位, 即表中的 2位二进制数表示目标锁在为节点标 识为 0的 PN上的状态, 当表中的 2位二进制数为 01时, 那么目标锁在节点 标识为 0的 PN上的状态为共享锁, 当表中的 2位二进制数为 10时, 那么目 标锁在节点标识为 0的 PN上的状态为排它锁。 当然在本发明实施例中包括不 始于上述列出的二进制数的值与锁的状态的映射关系。
402、 第一 PN使用所述目标锁对目标数据对象进行放锁操作;
作为一种可选的实施方式, 上述放锁操作可以包括:
放共享锁的操作或放排它锁的操作。
403、 第一 PN获取使用所述目标锁对所述目标数据对象进行放锁操作的 时刻所述锁操作数的原有值,以及将所述原有值中用于表示所述目标锁在所述 第一 PN上的状态的数据位的值加上预先设定的第三值,得到所述锁操作数的 更新值, 并所述更新值中表示所述目标锁在所述第一 PN上的状态的数据位的 值作为用于表示所述目标锁在所述第一 PN上为未锁定状态的值。
例如: 如上述映射关系所示, 上述第三值可以为 -01或者 -10, 这样当步骤 402放共享锁时, 上述第三值就为 -01 ; 当步骤 402放排它锁时, 上述第三值就 为 -10,以得到更新值中表示所述目标锁在所述第一 PN上的状态的数据位的值 为 00。
可选的, 可选的, 当锁操作数的二进制数的位置与节点标识的映射关系满 足上述列出的映射关系,且二进制数的值与锁的状态的映射关系满足上表所示 的映射关系时, 步骤 402是进行放共享锁操作, 那么步骤 403可以通过上述锁 操作数的值加上 -4'· , 即只需要执行一个 ^ - 4'· , 其中, 4i '为二进制数(例如 40 = 0001,^ = 0100, 42 = 010000, ), i为第一 PN的节点标识, W为上述锁操作数的值。 例如第一 PN的节点标识为 0时, 即步骤 402就是 W减去 0001 , 第一 PN的 节点标识为 1时, 即步骤 402就是 W减去 0100。 需要说明的是, 该实施方式 中, 仅上根据上述列出的映射关系而计算的, 当上述映射关系改变时, 步骤 403的算法也可以作出相应的变化。
可选的, 步骤 402是进行放排它锁操作, 那么步骤 403可以通过上述锁操 作数的值加上 -2 x 4'· , 即只需要执行一个 2 x 4'· , 其中, -2 x 4'·为二进制数, i 为第一 PN的节点标识, W为上述锁操作数的值。 例如第一 PN的节点标识为 0时, 即步骤 402就是 W减去 0010, 第一 PN的节点标识为 1时, 即步骤 402 就是 W减去 1000。 需要说明的是, 该实施方式中, 仅上根据上述列出的映射 关系而计算的, 当上述映射关系改变时, 步骤 403的算法也可以作出相应的变 化。
可选的, 步骤 403可以通过原子操作中 FAA操作, 由于 FAA操作的内容 是将操作数的原有值加一个值, 并返回原有值的原子操作, 这样步骤 403就可 以通过该操作获取到上述锁操作数的原有值, 同时, FAA操作中加了上述第 三值, 例如上述 -4'· , 即步骤 403只需要执行一个 ^ - 4'· , 就可以得到上述更新 值, 其中 i当前 PN的节点标识, V为上述锁操作数的原有值。
作为一种可选的实施方式, 在步骤 403之后, 所述方法还可以包括:
404、 第一 PN判断所述原有值所表示的所述目标锁在所述数据库系统中 各个 PN上的状态是否存在排队等待状态, 若是, 所述第一 PN向所述目标锁 为排队等待状态的 PN发送所述更新值,以使所述目标锁为排队等待状态的 PN 对所述目标锁进行锁操作。 可选的,上述所述目标锁为排队等待的 PN,就是指目标锁的状态在该 PN 上的状态为排队等待, 这样步骤 404 再将更新值发送至目标锁为排队等待的 PN, 这样就无需经过 CN, 从而节省 CN的开销。
在另一实施例中,当锁操作数的二进制数的位置与节点标识的映射关系满 足上述列出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN 使用目标锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足 上表所示的映射关系时, 上述步骤 402可以包括:
第一 PN对所述目标锁进行放共享锁的操作;
步骤 403可以包括:
第一 PN对上述锁操作数进行 FAA操作,其中, FAA操作中所加的值为 -4'·
(即上述第三值, 也可以理解为用于表示放共享锁的值, 如 -01 ), 得到所述锁 操作数的原有值, 以及得到一个进行 FAA操作后的值(即, 上述更新值), 该 值是上述锁操作的上述原有值加上 -4'·的值,相加后的值表示目标锁在第一 PN 上的状态为未锁定, 即将所述锁操作数中用于表示所述目标锁在所述第一 PN 上的状态的数据位的值 01减去 01后, 得到值就为 00。
在另一实施例中,当锁操作数的二进制数的位置与节点标识的映射关系满 足上述列出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN 使用目标锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足 上表所示的映射关系时, 上述步骤 402可以包括:
第一 PN对所述目标锁进行放排它锁的操作;
步骤 403可以包括:
第一 PN对上述锁操作数进行 FAA操作, 其中, FAA操作中所加的值为 -2 x 4'· (即上述第三值, 可以理解为用于表示放排它锁的值, 如 -10 ), 得到所 述锁操作数的原有值, 以及得到一个进行 FAA操作后的值(即上述更新值), 该值是上述锁操作的上述原有值加上 -2 x 4'·的值, 相加后的值表示目标锁在第 一 PN上的状态为未锁定, 即将所述锁操作数中用于表示所述目标锁在所述第 一 PN上的状态的数据位的值 10减去 10后, 得到值就为 00。
作为一种可选的实施方式, 步骤 401可以包括:
第一 PN接收所述数据库系统中的中心协调节点发送的所述目标锁的锁操 作数;
作为一种可选的实施方式, 步骤 301可以包括:
第一 PN接收所述数据库系统中的第二 PN发送的所述目标锁的锁操作数; 所述第二 PN指所述数据库系统中除所述第一 PN之外的任一 PN。 例如步骤 302发送的锁操作数。
作为一种可选的实施方式, 步骤 401可以包括:
第一 PN读取第一 PN本地存储的所述目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对放锁操作进行详细说明, 可以 实现提高数据库系统的可用性。 下面为本发明装置实施例,本发明装置实施例用于执行本发明方法实施例 一至四实现的方法, 为了便于说明, 仅示出了与本发明实施例相关的部分, 具 体技术细节未揭示的, 请参照本发明实施例一、 实施例二、 实施例三和实施例 四。 图 5是本发明实施例提供的一种节点设备的结构示意图,该节点设备为为 数据库系统中的一个 PN, 图 5所示, 包括: 获取单元 51、 操作单元 52和第 一更新单元 53 , 其中:
获取单元 51 , 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述 数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数据位表 示。
可选的, 上述节点设备可以为数据库系统中任一 PN, 上述目标锁为上述 系统中任一锁;
可选的, 本发明实施例中, 所述目标锁在 PN上的状态可以包括如下至少 一项:
未锁定、 共享锁、 排它锁和排队等待。 上述锁操作数中的状态值表示 PN 使用目标锁的状态。
操作单元 52 , 用于使用所述目标锁对目标数据对象进行加锁操作。 第一更新单元 53 , 用于当所述锁操作数满足加锁操作成功的条件时, 确 认所述加锁操作成功,并将所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为加 锁状态的值
作为一种可选的实施方式,上述节点设备可以是任一数据库系统中的节点 设备, 例如, 计算机、 网络中节点设备, 如基站、 控制器设备等。
上述技术方案中, 节点设备获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 节点设备使用所述目标锁对目标数据对象进行加锁操作; 当所述锁 操作数满足加锁操作成功的条件时, 节点设备确认所述加锁操作成功, 并将所 述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的值更 新为用于表示所述目标锁在所述节点设备上为加锁状态的值。这样整个锁操作 过程由第一 PN独立完成, 从而 CN无需处理锁消息, 这样就可以提高数据库 系统的性能。 图 6是本发明实施例提供的另一种节点设备的结构示意图,所述节点设备 为数据库系统中的一个 PN, 如图 6所示, 包括: 获取单元 61、 操作单元 62 和第一更新单元 63 , 其中:
获取单元 61 , 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述 数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数据位表 示。
作为一种可选的实施方式, 上述锁操作数可以是一组 M位二进制数, M 为 PN的操作系统的位数, 如 32位的操作系统那么 M就为 32 , 如操作系统为 128那么 M就为 128。
可选的, 该实施方式中, 若上述数据库系统中 PN的个数为 N, 且 N和 M 满足 N = M / 2时, 那么上述锁操作数就可以包含 Ν个 2位二进制数的数据, 1 个 2位二进制数的数据表示目标锁在 1个 ΡΝ上的状态, 即所述目标锁当前在 所述数据库系统中每个 PN上的状态使用所述锁操作数中的 1个 2位二进制数 的数据表示。
可选的, 上述系统中每个 PN可以设置有节点标识, 那么本发明实施例就 可以建立锁操作数的二进制数的位置与节点标识的映射关系, 如上述 N个 PN 的节点标识为 0123...N, 上述映射关系就可以是锁操作数中 0-1位的数据就可 以表示目标锁在为节点标识为 0的 PN上的状态, 锁操作数中 2-3位的数据就 可以表示目标锁在为节点标识为 1的 PN上的状态, 锁操作数中 3-4位的数据 就可以表示目标锁在为节点标识为 2的 PN上的状态, 锁操作数中 5-6位的数 据就可以表示目标锁在为节点标识为 3的 PN上的状态,…,锁操作数中 N -1-N 位的数据就可以为表示目标锁在节点标识为 N的 PN上的状态。 例如, 第一 PN的节点标识为 0那么, 操作数中 0-1位二进制数表示目标锁在第一 PN上 的状态。 当然上述节点标识和上述映射关系仅是本发明实例中一个例子。本发 明实例包括但不限上述列出的节点标识和映射关系。
可选的, 目标锁在 PN上的状态可以包括如下至少一项:
未锁定、 共享锁、 排它锁和排队等待。 本发明实施例中还可以建立二进制 数的值与锁的状态的映射关系, 该映射关系可以如下所示:
Figure imgf000031_0001
其中, 上表只显示 2位二进制数, 表示目标锁在一个 PN上的状态, 例如 表中的 2位二进制数为 0-1位, 即表中的 2位二进制数表示目标锁在为节点标 识为 0的 PN上的状态, 当表中的 2位二进制数为 01时, 那么目标锁在节点 标识为 0的 PN上的状态为共享锁, 当表中的 2位二进制数为 10时, 那么目 标锁在节点标识为 0的 PN上的状态为排它锁。 当然在本发明实施例中包括不 始于上述列出的二进制数的值与锁的状态的映射关系。
操作单元 62 , 用于使用所述目标锁对目标数据对象进行加锁操作。 作为一种可选的实施方式, 上述加锁操作可以包括:
加共享锁的操作或加排它锁的操作。
第一更新单元 63 , 用于当所述锁操作数满足加锁操作成功的条件时, 确 认所述加锁操作成功,并将所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为加 锁状态的值。
作为一种可选的实施方式, 所述节点设备还可以包括:
第二更新单元 64, 用于当所述锁操作数不满足加锁操作成功的条件时, 确定所述加锁操作失败,并将所述操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为排 队等待状态的值。
这样可以实现当加锁操作失败时, 将目标锁在第一 PN上的状态更新为排 队等待状态。
作为一种可选的实施方式, 第一更新单元 63还可以包括:
第一计算单元(附图中未画出), 用于获取使用所述目标锁对所述目标数 据对象进行加锁操作的时刻所述锁操作数的原有值,以及将所述原有值中用于 表示所述目标锁在所述节点设备上的状态的数据位的值加上预先设定的第一 值, 得到所述锁操作数的更新值;
第一确认单元(附图中未画出), 用于当所述原有值满足加锁操作成功的 条件时,确认所述加锁操作成功, 并将所述更新值中用于表示所述目标锁在所 述节点设备上的状态的数据位的值作为用于表示所述目标锁在所述节点设备 上为加锁状态的值。
可选的,当锁操作数的二进制数的位置与节点标识的映射关系满足上述列 出的映射关系,且二进制数的值与锁的状态的映射关系满足上表所示的映射关 系时, 上述第一值可以是 01或者 10。
可选的,操作单元 62是进行加共享锁操作, 那么第一更新单元 63可以通 过上述锁操作数的值加上 4'' , 即只需要执行一个 ΡΓ+ 4'·就可以得到上述更新值, 其中, 4''为二进制数(例如 4。 = 0001, 41 = 0100, 42 = 010000, ), i为第一 ΡΝ的节点标 识, W为上述锁操作数的的原有值。例如第一 PN的节点标识为 0时, 即将 W 加上 0001 , 第一 PN的节点标识为 1时, 即将 W加上 0100。 需要说明的是, 该实施方式中,仅才艮据上述列出的映射关系而计算的,当上述映射关系改变时, 第一更新单元 63的算法也可以作出相应的变化。 行加共享锁的操作;
第一确认单元(附图中未画出)还可以用于判断所述原有值所记录的所述 目标锁在所述数据库系统中各个 PN上的状态是否均为允许加共享锁状态; 若 是, 则确认所述加共享锁操作成功;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 即上述加锁操作成功的条件可以包括:
所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态为 上述允许加共享锁状态, 即未锁定或者共享锁, 即在上述原有值所表示的目标 锁在所述数据库系统中各个 PN上的状态要么为未锁定, 要么为共享锁, 上述 原有值所表示的目标锁在所述数据库系统中各个 PN上的状态不包括排它锁或 排队等待。 即上述原有值没有表示目标锁在任一 PN上的状态为排它锁或排队 等待。 这样第一 PN就可以对目标锁加共享锁成功。 排它锁的操作;
第一确认单元(附图中未画出)还可以用于判断所述原有值所记录的所述 目标锁在所述数据库系统中各个 PN上的状态是否均为允许加共享锁状态; 若 是, 则确认所述加排它锁操作成功; 或者
第一确认单元(附图中未画出)还可以用于判断所述原有值所记录的所述 目标锁在所述节点设备上的状态是否为共享锁状态, 若是, 则判断所述原有值 所记录的所述目标锁在其它 PN上的状态是否均为未锁定状态, 若是, 则确认 所述加排它锁操作成功; 所述其它 PN为所述数据库系统中除所述节点设备之 外的所有 PN;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 即上述加锁操作成功的条件可以包括:
所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态为 未锁定或者共享锁; 或者, 所述原有值所表示的所述目标锁在所述第一 PN节 点上的状态为共享锁,所述目标锁在其它 PN上的状态为未锁定;所述其它 PN 为所述数据库系统中除所述第一 PN节点之外的所有 PN。 所述原有值中不包 括排它锁或排队等待, 或者除第一 PN使用目标锁的状态为共享锁之外不包括 共享锁。 这样第一 PN就可以对目标锁加排它锁成功。
可选的, 确认加锁操作成功, 当前 PN就可以对目标锁对应的数据对进行 读取、 修改、 删除等操作。
可选的, 第二更新单元 64还可以用于当所述原有值不满足加锁操作成功 的条件时, 确定所述加锁操作失败, 并将所述原有值中用于表示所述目标锁在 所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所述节点 设备上为排队等待状态的值。
可选的, 为了避免当前 PN对目标进行锁操作的过程中, 有其它 PN对目 标锁进行锁操作, 第二更新单元 64可以同上述第一更新单元 63—样, 第二更 新单元 64也可以是通过上述 FAA操作将锁操作数中用于表示所述目标锁在所 述节点设备上的状态的数据位的值用于表示所述目标锁在所述节点设备上为 排队等待状态的值。 即第二更新单元 64还可以用于当所述原有值不满足加锁 操作成功的条件时, 确定所述加锁操作失败, 并通过 FAA操作将锁操作数中 用于表示所述目标锁在所述节点设备上的状态的数据位的值用于表示所述目 标锁在所述节点设备上为排队等待状态的值, 其中, FFA操作中所加的值为与 所述第一值相反的值, 即上述第一值为 01时, FFA操作中所加的值就为 -01 , 上述第一值为 10时, FFA操作中所加的值就为 -10。 这样就保证了第二更新单 元 64执行的更新时, 所使用的锁操作数的值是最新的。
作为一种可选的实施方式, 操作单元 62还可以用于当所述目标锁在所述 节点设备上的状态为共享锁状态时,使用所述目标锁对所述目标数据对象进行 加排它锁的操作; 即上共享锁的基础上加排它锁。
可选的, 第一更新单元 63还可以包括:
第二计算单元(附图中未画出), 用于获取使用所述目标锁对所述目标数 据对象进行加排它锁操作的时刻所述锁操作数的原有值,以及将所述原有值中 用于表示所述目标锁在所述节点设备上的状态的数据位的值加上预先设定的 第二值, 得到所述锁操作数的更新值;
第二确认单元(附图中未画出), 用于当所述原有值满足加排它锁操作成 功的条件时,确认所述加排它锁操作成功, 并将所述更新值中用于表示所述目 标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所 述节点设备上为排它锁状态的值。
可选的,当锁操作数的二进制数的位置与节点标识的映射关系满足上述列 出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标 锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足上表所示 的映射关系时, 上述第二值可以是 10 , 上述将所述更新值中用于表示所述目 标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所 述节点设备上为排它锁状态的值,可以是将更新值中用于表示所述目标锁在所 述节点设备上的状态的数据位的值加上 -01。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 上述操作单元 62还可以用于第一 PN对所述 目标锁进行加共享锁的操作,
第一更新单元 63还可以用于对上述锁操作数进行 FAA操作, 其中, FAA 操作中所加的值为 4'' (即上述第一值, 也可以理解为用于表示共享锁的值, 如 01 ), 节点设备获取使用所述目标锁对所述目标数据对象进行加锁操作的时刻 所述锁操作数的原有值,以及得到一个进行 FAA操作后的值(即上述更新值), 该值是上述锁操作的上述原有值加上 4''的值, 相加后的值表示目标锁在第一
PN上的状态为共享锁, 即原有值中用于表示所述目标锁在所述节点设备上的 状态的数据位的值 00加上 01后, 得到值就为 01。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 为上述允许加共享锁状态时, 那么第一更新单元 63就加共享锁成功, 并将所 述更新值中用于表示所述目标锁在所述节点设备上的状态的数据位的值作为 用于表示所述目标锁在所述节点设备上为加锁状态的值。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 包含排队等待或者排它锁时,第二更新单元 64对上述锁操作数进行 FAA操作, 其中, FAA操作中所加的值为 2 x 4'· , 得到执行第二更新单元 64时刻上述锁操 作数的值, 以及得到一个进行 FAA操作后的值, 该是上述锁操作的执行第二 更新单元 64时刻的值加上 2 x 4'·的值, 相加得到值就表示目标锁在第一 PN上 的状态为排队等待, 即第一位置的数据 01加上 10后, 得到值就为 11。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 操作单元 62还可以用于当所述目标锁在所述 节点设备上的状态为未锁定状态时,所述节点设备使用所述目标锁对所述目标 数据对象进行加排它锁的操作;
第一更新单元 63还可以用于对上述锁操作数进行 FAA操作, 其中, FAA 操作中所加的值为 2 x 4'· (即上述第一值, 可以理解为用于表示排它锁的值, 如 10 ), 得到所述锁操作数的原有值, 以及得到一个进行 FAA操作后的值(即上 述更新值), 该值是上述锁操作的上述原有值加上 2 x 4'·的值, 该值表示目标锁 在第一 PN上的状态为排它锁, 即所述锁操作数中用于表示所述目标锁在所述 节点设备上的状态的数据位 01加上 10后, 得到值就为 10。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 为上述允许加共享锁状态时; 或者, 所述原有值所表示的所述目标锁在所述节 点设备上的状态为共享锁, 所述目标锁在其它 PN上的状态为未锁定状态时, 那么第一更新单元 63就确认加排它锁成功, 并将所述更新值中用于表示所述 目标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在 所述节点设备上为排它锁状态的值。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 包含排队等待或者排它锁时, 或者所述原有值所表示的所述目标锁在第一 PN 上的状态为共享锁, 且在另一 PN或者另多个 PN上的状态也为共享锁时, 那 么就执行第二更新单元 64, 其中: 第二更新单元 64还可以用于对上述锁操作 数进行 FAA操作, 其中, FAA操作中所加的值为 4'· , 得到第二更新单元 64确 认加锁失败时刻上述锁操作数的值, 以及得到一个进行 FAA操作后的值, 该 是上述锁操作的第二更新单元 64确认加锁失败时刻时刻的值加上 4'·的值, 相 加得到值就表示目标锁在第一 PN上的状态为排队等待, 即所述锁操作数中用 于表示所述目标锁在所述节点设备上的状态的数据位的值 01加上 10后,得到 值就为 11。
在另一个可选的实施例中,当锁操作数的二进制数的位置与节点标识的映 射关系满足上述列出的映射关系(即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标锁的状态的映射关系),且二进制数的值与锁的状态的映射关 系满足上表所示的映射关系时, 操作单元 62还可以用于当所述目标锁在所述 节点设备上的状态为共享锁状态时,使用所述目标锁对所述目标数据对象进行 加排它锁的操作
第一更新单元 63还可以用于对上述锁操作数进行 FAA操作, 其中, FAA 操作中所加的值为 2 x 4'· (即上述第二值, 也可以理解为用于表示排它锁的值, 如 10 ),得到所述锁操作数的原有值, 以及得到一个进行 FAA操作后的值(即 上述更新值), 该值是上述锁操作的上述原有值加上 2 x 4'·的值, 这样相加得到 值就表示目标锁在第一 PN上的状态为排队等待, 即所述锁操作数中用于表示 所述目标锁在所述节点设备上的状态的数据位的值 01加上 10后,得到值就为 11。
当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 为上述允许加共享锁状态时; 或者, 所述原有值所表示的所述目标锁在所述第 一 PN节点上的状态为共享锁, 所述目标锁在其它 PN上的状态为未锁定, 那 么就确认加排它锁成功。 由于第一更新单元 63加上上述第二值后, 所述锁操 作数中用于表示所述目标锁在所述节点设备上的状态的数据位的值为用于表 示排队等待状态的值(即 11 ), 第一更新单元 63将所述更新值中用于表示所 述目标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁 在所述节点设备上为排它锁状态的值, 即
对上述锁操作数进行 FAA操作, 其中, FAA操作中所加的值为 -4'· (即减 去 01 , )。 即将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态 的数据位的值从用于表示排队等待状态的值(即 11 ) 更新为用于表示排它锁 状态的值(即 10 )。 当所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状态 包含排队等待或者排它锁,或者所述当前时刻的值所表示的所述目标锁在所述 节点设备上的状态为共享锁, 且所述目标锁在另一个 PN或者另多个 PN上的 状态为共享锁, 那么操作单元 62就加排它锁失败。 由于第一更新单元 63加上 用于表示加排它锁的值后,所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值值为用于表示排队等待状态的值(即 11 ), 这样在本 实施例中就可以不包括第二更新单元 64。
该实施例中, 可以共享锁状态加锁为排它锁。
作为一种可选的实施方式, 获取单元 61还可以用于接收所述数据库系统 中的中心协调节点发送的所述目标锁的锁操作数;
可选的, 该实施方式中, 当节点设备需要对目标锁对应的数据对象进行添 加、 读取、 修改或删除等操作时, 节点设备就可以向 CN发送请求对目标锁进 行操作的请求消息, NC接收到该消息后就查找哈希表提到目标锁的锁操作数, 当哈希表中不存在目标锁的锁操作信息时, CN就创建目标锁的锁操作数, 并 返回给节点设备。
作为一种可选的实施方式, 获取单元 61还可以用于接收所述数据库系统 中的第二 PN发送的所述目标锁的锁操作数。 例如上述方法实施例中步骤 305 中的转移消息。 所述第二 PN指所述数据库系统中除所述节点设备之外的任一 PN。
作为一种可选的实施方式, 获取单元 61还可以用于读取所述节点设备本 地存储的所述目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对加锁操作进行详细说明, 可以 实现提高数据库系统的可用性。 图 7是本发明实施例提供的另一种节点设备的结构示意图,该节点设备为 数据库系统中一个 PN, 如图 7所示, 包括: 获取单元 71、 操作单元 72和更 新单元 73 , 其中:
获取单元 71 , 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述 数据库系统中每个 PN 上的状态使用所述操作数中的一个或者多个数据位表 示;
操作单元 72 , 用于使用所述目标锁对目标数据对象进行放锁操作; 更新单元 73 , 用于将所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为放 锁状态的值, 以使所述数据库系统中的 PN根据所述锁操作数获知所述目标锁 在所述节点设备上为放锁状态。
作为一种可选的实施方式, 实现本发明的设备, 即 PN可以是任一数据库 系统中的节点设备, 例如, 计算机、 网络中节点设备, 如基站、控制器设备等。
上述技术方案中, 节点设备获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 节点设备使用所述目标锁对目标数据对象进行放锁操作; 节点设备 将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的 值更新为用于表示所述目标锁在所述节点设备上为放锁状态的值,以使所述数 据库系统中的 PN根据所述锁操作数获知所述目标锁在所述节点设备上为放锁 状态。 这样整个锁操作过程由第一 PN独立完成, 从而 CN无需处理锁消息, 这样就可以提高数据库系统的性能。 图 8是本发明实施例提供的另一种节点设备的结构示意图,该节点设备为 数据库系统中一个 PN, 如图 8所示, 包括: 获取单元 81、 操作单元 82和更 新单元 83 , 其中:
获取单元 81 , 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前在所述 数据库系统中每个 PN 上的状态使用所述操作数中的一个或者多个数据位表 示;
作为一种可选的实施方式, 上述锁操作数可以是一组 M位二进制数, M 为 PN的操作系统的位数, 如 32位的操作系统那么 M就为 32 , 如操作系统为 128那么 M就为 128。 可选的, 该实施方式中, 若上述数据库系统中 PN的个数为 N, 且 N和 M 满足 N = M / 2时, 那么上述锁操作数就可以包含 Ν个 2位二进制数的数据, 1 个 2位二进制数的数据表示目标锁在 1个 ΡΝ上的状态, 即所述目标锁当前在 所述数据库系统中每个 ΡΝ上的状态使用所述锁操作数中的 1个 2位二进制数 的数据表示。
操作单元 82, 用于点使用所述目标锁对目标数据对象进行放锁操作; 作为一种可选的实施方式, 上述放锁操作可以包括:
放共享锁的操作或放排它锁的操作。
更新单元 83 , 用于获取使用所述目标锁对所述目标数据对象进行放锁操 作的时刻所述锁操作数的原有值,以及将所述原有值中用于表示所述目标锁在 所述节点设备上的状态的数据位的值加上预先设定的第三值,得到所述锁操作 数的更新值,并所述更新值中表示所述目标锁在所述节点设备上的状态的数据 位的值作为用于表示所述目标锁在所述节点设备上为未锁定状态的值。
例如: 如上面实施例描述映射关系所示, 上述第三值可以为 -01或者 -10, 这样当操作单元 82放共享锁时, 上述第三值就为 -01 ; 当操作单元 82放排它 锁时, 上述第三值就为 -10, 以得到更新值中表示所述目标锁在所述节点设备 上的状态的数据位的值为 00。
作为一种可选的实施方式, 所述节点设备还可以包括:
判断单元 84, 判断所述原有值所表示的所述目标锁在所述数据库系统中 各个 ΡΝ上的状态是否存在排队等待状态, 若是, 所述节点设备向所述目标锁 为排队等待状态的 ΡΝ发送所述更新值,以使所述目标锁为排队等待状态的 ΡΝ 对所述目标锁进行锁操作。
可选的,上述所述目标锁为排队等待的 ΡΝ,就是指目标锁的状态在该 ΡΝ 上的状态为排队等待, 这样判断单元 84再将更新值发送至目标锁为排队等待 的 ΡΝ, 这样就无需经过 CN, 从而节省 CN的开销。
在另一实施例中,当锁操作数的二进制数的位置与节点标识的映射关系满 足上述列出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN 使用目标锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足 上表所示的映射关系时, 上述操作单元 82还可以用于对所述目标锁进行放共 享锁的操作;
更新单元 83还可以用于对上述锁操作数进行 FAA操作,其中, FAA操作 中所加的值为 -4'· (即上述第三值, 也可以理解为用于表示放共享锁的值, 如 -01 ), 得到所述锁操作数的原有值, 以及得到一个进行 FAA操作后的值(即, 上述更新值), 该值是上述锁操作的上述原有值加上 -4'·的值, 相加后的值表示 目标锁在第一 PN上的状态为未锁定, 即将所述锁操作数中用于表示所述目标 锁在所述节点设备上的状态的数据位的值 01减去 01后, 得到值就为 00。
在另一实施例中,当锁操作数的二进制数的位置与节点标识的映射关系满 足上述列出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN 使用目标锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足 上表所示的映射关系时, 上述操作单元 82还可以用于对所述目标锁进行放排 它锁的操作;
更新单元 83还可以用于对上述锁操作数进行 FAA操作,其中, FAA操作 中所加的值为 -2 x 4'· (即上述第三值, 可以理解为用于表示放排它锁的值, 如 -10 ), 得到所述锁操作数的原有值, 以及得到一个进行 FAA操作后的值(即 上述更新值), 该值是上述锁操作的上述原有值加上 -2 x 4'·的值, 相加后的值表 示目标锁在第一 PN上的状态为未锁定, 即将所述锁操作数中用于表示所述目 标锁在所述节点设备上的状态的数据位的值 10减去 10后, 得到值就为 00。
作为一种可选的实施方式, 获取单元 81还可以用于接收所述数据库系统 中的中心协调节点发送的所述目标锁的锁操作数;
作为一种可选的实施方式, 获取单元 81还可以用于接收所述数据库系统 中的第二 PN发送的所述目标锁的锁操作数; 所述第二 PN指所述数据库系统 中除所述节点设备之外的任一 PN。
作为一种可选的实施方式, 获取单元 81还可以用于读取所述节点设备本 地存储的所述目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对放锁操作进行详细说明, 可以 实现提高数据库系统的可用性。 图 9是本发明实施例提供的另一种节点设备的结构示意图,该节点设备为 数据库系统中一个 PN, 如图 9所示, 包括: 存储器 91和处理器 92 , 其中: 存储器 91用于存储一组程序代码, 处理器 92用于调整存储器 91所存储 的程序代码用于执行如下操作:
获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁当前在所述数 据库系统中各个 PN上的状态,且所述目标锁当前在所述数据库系统中每个 PN 上的状态使用所述锁操作数中的一个或者多个数据位表示;
使用所述目标锁对目标数据对象进行加锁操作。
当所述锁操作数满足加锁操作成功的条件时,确认所述加锁操作成功, 并 将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的 值更新为用于表示所述目标锁在所述节点设备上为加锁状态的值。
作为一种可选的实施方式, 实现本发明的设备, 即 PN可以是任一数据库 系统中的节点设备, 例如, 计算机、 网络中节点设备, 如基站、控制器设备等。
上述技术方案中, 节点设备获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 节点设备使用所述目标锁对目标数据对象进行加锁操作; 当所述锁 操作数满足加锁操作成功的条件时, 节点设备确认所述加锁操作成功, 并将所 述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的值更 新为用于表示所述目标锁在所述节点设备上为加锁状态的值。这样整个锁操作 过程由第一 PN独立完成, 从而 CN无需处理锁消息, 这样就可以提高数据库 系统的性能。 图 10是本发明实施例提供的另一种节点设备的结构示意图, 该节点设备 为数据库系统中一个 PN, 如图 10所示, 包括: 存储器 101和处理器 102, 其 中:
存储器 101用于存储一组程序代码,处理器 102用于调整存储器 101所存 储的程序代码用于执行如下操作:
获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁当前在所述数 据库系统中各个 PN上的状态,且所述目标锁当前在所述数据库系统中每个 PN 上的状态使用所述锁操作数中的一个或者多个数据位表示;
使用所述目标锁对目标数据对象进行加锁操作;
当所述锁操作数满足加锁操作成功的条件时,确认所述加锁操作成功, 并 将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的 值更新为用于表示所述目标锁在所述节点设备上为加锁状态的值;
当所述锁操作数不满足加锁操作成功的条件时, 确定所述加锁操作失败, 并将所述操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的 值更新为用于表示所述目标锁在所述节点设备上为排队等待状态的值。
这样可以实现当加锁操作失败时, 将目标锁在第一 PN上的状态更新为排 队等待状态。
作为一种可选的实施方式,处理器 102执行的当所述锁操作数满足加锁操 作成功的条件时, 确认所述加锁操作成功, 并将所述锁操作数中用于表示所述 目标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在 所述节点设备上为加锁状态的值的操作, 可以包括:
获取使用所述目标锁对所述目标数据对象进行加锁操作的时刻所述锁操 作数的原有值,以及将所述原有值中用于表示所述目标锁在所述节点设备上的 状态的数据位的值加上预先设定的第一值, 得到所述锁操作数的更新值; 当所述原有值满足加锁操作成功的条件时,确认所述加锁操作成功, 并将 所述更新值中用于表示所述目标锁在所述节点设备上的状态的数据位的值作 为用于表示所述目标锁在所述节点设备上为加锁状态的值。
可选的,处理器 102执行的使用所述目标锁对所述目标数据对象进行加锁 的操作, 可以包括:
使用所述目标锁对所述目标数据对象进行加共享锁的操作;
处理器 102执行的当所述原有值满足加锁操作成功的条件时,所述节点设 备确认所述加锁操作成功的操作, 可以包括:
判断所述原有值所记录的所述目标锁在所述数据库系统中各个 PN上的状 态是否均为允许加共享锁状态; 若是, 则确认所述加共享锁操作成功;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 可选的,处理器 102执行的使用所述目标锁对所述目标数据对象进行加锁 的操作, 可以包括:
使用所述目标锁对所述目标数据对象进行加排它锁的操作;;
处理器 102执行的当所述原有值满足加锁操作成功的条件时,所述节点设 备确认所述加锁操作成功的操作, 可以包括:
判断所述原有值所记录的所述目标锁在所述数据库系统中各个 PN上的状 态是否均为允许加共享锁状态; 若是, 则确认所述加排它锁操作成功; 或者 判断所述原有值所记录的所述目标锁在所述节点设备上的状态是否为共 享锁状态, 若是, 则判断所述原有值所记录的所述目标锁在其它 PN上的状态 是否均为未锁定状态, 若是, 则确认所述加排它锁操作成功; 所述其它 PN为 所述数据库系统中除所述节点设备之外的所有 PN;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。 可选的, 确认加锁操作成功, 当前 PN就可以对目标锁对应的数据对进行 读取、 修改、 删除等操作。
可选的, 处理器 102执行的当所述锁操作数不满足加锁操作成功的条件 时,确定所述加锁操作失败, 并将所述操作数中用于表示所述目标锁在所述节 点设备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上 为排队等待状态的值的操作, 可以包括:
当所述原有值不满足加锁操作成功的条件时,确定所述加锁操作失败, 并 将所述原有值中用于表示所述目标锁在所述节点设备上的状态的数据位的值 更新为用于表示所述目标锁在所述节点设备上为排队等待状态的值。
作为一种可选的实施方式,处理器 102执行的使用所述目标锁对所述目标 数据对象进行加锁的操作, 可以包括:
当所述目标锁在所述节点设备上的状态为共享锁状态时,使用所述目标锁 对所述目标数据对象进行加排它锁的操作; 即上共享锁的基础上加排它锁。
可选的, 处理器 102执行的当所述锁操作数满足加锁操作成功的条件时, 确认所述加锁操作成功,并将所述锁操作数中用于表示所述目标锁在所述节点 设备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为 加锁状态的值的操作, 可以包括:
获取使用所述目标锁对所述目标数据对象进行加排它锁操作的时刻所述 上的状态的数据位的值加上预先设定的第二值, 得到所述锁操作数的更新值; 当所述原有值满足加排它锁操作成功的条件时,确认所述加排它锁操作成 的值更新为用于表示所述目标锁在所述节点设备上为排它锁状态的值。
可选的,当锁操作数的二进制数的位置与节点标识的映射关系满足上述列 出的映射关系 (即锁操作数中 0-1位就可以表示节点标识为 0的 PN使用目标 锁的状态的映射关系), 且二进制数的值与锁的状态的映射关系满足上表所示 的映射关系时, 上述第二值可以是 10 , 上述将所述更新值中用于表示所述目 标锁在所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所 述节点设备上为排它锁状态的值,可以是将更新值中用于表示所述目标锁在所 述节点设备上的状态的数据位的值加上 -01。
可选的, 处理器 102可以通过上面实施例描述的 FAA操作将所述锁操作 数中用于表示所述目标锁在所述节点设备上的状态的数据位的值进行更新,此 处为作重复说明。
作为一种可选的实施方式, 所述节点设备还可以包括:
接收器 103 , 用于接收所述数据库系统中的中心协调节点发送的所述目标 锁的锁操作数;
其中, 处理器 102执行的获取目标锁的锁操作数的操作可以包括: 通过控制接收器 103 接收所述数据库系统中的中心协调节点发送的所述 目标锁的锁操作数。
可选的, 该实施方式中, 当节点设备需要对目标锁对应的数据对象进行添 加、 读取、 修改或删除等操作时, 节点设备就可以向 CN发送请求对目标锁进 行操作的请求消息, NC接收到该消息后就查找哈希表提到目标锁的锁操作数, 当哈希表中不存在目标锁的锁操作信息时, CN就创建目标锁的锁操作数, 并 返回给节点设备。
作为一种可选的实施方式, 所述节点设备还可以包括:
接收器 103还可以用于接收所述数据库系统中的第二 PN发送的所述目标 锁的锁操作数。 所述第二 PN指所述数据库系统中除所述当前 PN之外的任一 PN;
其中, 处理器 102执行的获取目标锁的锁操作数的操作可以包括: 控制接收器 103接收所述数据库系统中的其它 PN发送的所述目标锁的锁 操作数。
作为一种可选的实施方式,处理器 102执行的获取目标锁的锁操作数的操 作可以包括:
读取本地存储的目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对加锁操作进行详细说明, 可以 实现提高数据库系统的可用性。 图 11是本发明实施例提供的另一种节点设备的结构示意图, 该节点设备 为数据库系统一个 PN, 如图 11所示, 存储器 111和处理器 112 , 其中,
存储器 111用于存储一组程序代码, 处理器 112用于调整存储器 111所存 储的程序代码用于执行如下操作:
获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁当前在所述数 据库系统中各个 PN上的状态,且所述目标锁当前在所述数据库系统中每个 PN 上的状态使用所述操作数中的一个或者多个数据位表示;
使用所述目标锁对目标数据对象进行放锁操作;
将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据 位的值更新为用于表示所述目标锁在所述节点设备上为放锁状态的值,以使所 述数据库系统中的 PN根据所述锁操作数获知所述目标锁在所述节点设备上为 放锁状态。
作为一种可选的实施方式,上述节点设备可以是任一数据库系统中的节点 设备, 例如, 计算机、 网络中节点设备, 如基站、 控制器设备等。
上述技术方案中, 节点设备获取目标锁的锁操作数, 所述锁操作数用于记 录所述目标锁当前在所述数据库系统中各个 PN上的状态, 且所述目标锁当前 在所述数据库系统中每个 PN上的状态使用所述锁操作数中的一个或者多个数 据位表示; 节点设备使用所述目标锁对目标数据对象进行放锁操作; 节点设备 将所述锁操作数中用于表示所述目标锁在所述节点设备上的状态的数据位的 值更新为用于表示所述目标锁在所述节点设备上为放锁状态的值,以使所述数 据库系统中的 PN根据所述锁操作数获知所述目标锁在所述节点设备上为放锁 状态。 这样整个锁操作过程由第一 PN独立完成, 从而 CN无需处理锁消息, 这样就可以提高数据库系统的性能。 图 12是本发明实施例提供的另一种节点设备的结构示意图, 该节点设备 为数据库系统一个 PN, 如图 12所示, 存储器 121、 处理器 122和发射器 123 , 存储器 121用于存储一组程序代码,处理器 122用于调整存储器 121所存 储的程序代码用于执行如下操作:
获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁当前在所述数 据库系统中各个 PN上的状态,且所述目标锁当前在所述数据库系统中每个 PN 上的状态使用所述操作数中的一个或者多个数据位表示;
使用所述目标锁对目标数据对象进行放锁操作;
获取使用所述目标锁对所述目标数据对象进行放锁操作的时刻所述锁操 作数的原有值,以及将所述原有值中用于表示所述目标锁在所述节点设备上的 状态的数据位的值加上预先设定的第三值,得到所述锁操作数的更新值, 并所 述更新值中表示所述目标锁在所述节点设备上的状态的数据位的值作为用于 表示所述目标锁在所述节点设备上为未锁定状态的值;
判断所述原有值所表示的所述目标锁在所述数据库系统中各个 PN上的状 态是否存在排队等待状态, 若是, 通过发射器 123向所述目标锁为排队等待状 态的 PN发送所述更新值, 以使所述目标锁为排队等待状态的 PN对所述目标 锁进行锁操作。
可选的, 处理器 122可以通过上面实施例描述的 FAA操作得到上述原有 值, 和上述更新值, 此处不说重复说明。
作为一种可选的实施方式, 所述节点设备还可以包括:
接收器 124, 用于接收所述数据库系统中的中心协调节点发送的所述目标 锁的锁操作数;
其中, 处理器 122执行的获取目标锁的锁操作数的操作可以包括: 通过控制接收器 124接收所述数据库系统中的中心协调节点发送的所述 目标锁的锁操作数。
可选的, 该实施方式中, 当节点设备需要对目标锁对应的数据对象进行添 加、 读取、 修改或删除等操作时, 节点设备就可以向 CN发送请求对目标锁进 行操作的请求消息, NC接收到该消息后就查找哈希表提到目标锁的锁操作数, 当哈希表中不存在目标锁的锁操作信息时, CN就创建目标锁的锁操作数, 并 返回给节点设备。
作为一种可选的实施方式, 所述节点设备还可以包括:
接收器 124还可以用于接收所述数据库系统中的第二 PN发送的所述目标 锁的锁操作数。 所述第二 PN指所述数据库系统中除所述当前 PN之外的任一 PN;
其中, 处理器 122执行的获取目标锁的锁操作数的操作可以包括: 控制接收器 124接收所述数据库系统中的其它 PN发送的所述目标锁的锁 操作数。
作为一种可选的实施方式,处理器 124执行的获取目标锁的锁操作数的操 作可以包括:
读取本地存储的目标锁的锁操作数。
上述技术方案中, 在上面实施例的基础, 对放锁操作进行详细说明, 可以 实现提高数据库系统的可用性。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程, 是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算 机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。 其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory, ROM )或随机存取存储器 ( Random Access Memory, 筒称 RAM )等。
以上所揭露的仅为本发明较佳实施例而已,当然不能以此来限定本发明之 权利范围,因此依本发明权利要求所作的等同变化,仍属本发明所涵盖的范围。

Claims

权 利 要 求
1、 一种数据库系统的锁操作方法, 其特征在于, 包括:
第一处理节点获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁 当前在所述数据库系统中各个处理节点上的状态,且所述目标锁当前在所述数 据库系统中每个处理节点上的状态使用所述锁操作数中的一个或者多个数据 位表示;
所述第一处理节点使用所述目标锁对目标数据对象进行加锁操作, 并将 所述锁操作数中用于表示所述目标锁在所述第一处理节点上的状态的数据位 的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态的值; 所述第一处理节点根据所述锁操作数确认所述加锁操作是否成功。
2、 如权利要求 1所述的方法, 其特征在于, 所述将所述锁操作数中用于 表示所述目标锁在所述第一处理节点上的状态的数据位的值更新为用于表示 所述目标锁在所述第一处理节点上为加锁状态的值, 包括:
获取使用所述目标锁对所述目标数据对象进行加锁操作的时刻所述锁操 作数的原有值;
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态的值; 所述第一处理节点根据所述锁操作数确认所述加锁操作是否成功, 包括: 当所述原有值满足加锁操作成功的条件时 ,所述第一处理节点确认所述加 锁操作成功; 否则, 确定所述加锁操作失败。
3、 如权利要求 2所述的方法, 其特征在于, 所述第一处理节点使用所述 目标锁对所述目标数据对象进行加锁操作包括:
所述第一处理节点使用所述目标锁对所述目标数据对象进行加共享锁的 操作;
所述将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态 的值, 包括:
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值加上预先设定的第一值,得到所述锁操作数的更新值; 所述更新值中 用于表示所述目标锁在所述第一处理节点上的状态的数据位的值为表示所述 目标锁在所述第一处理节点上为共享锁状态的值;
所述当所述原有值满足加锁操作成功的条件时,所述第一处理节点确认所 述加锁操作成功, 否则, 确定所述加锁操作失败包括:
所述第一处理节点判断所述原有值所记录的所述目标锁在所述数据库系 统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所述加 共享锁操作成功; 若否, 则确认所述加共享锁操作失败;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。
4、 如权利要求 2所述的方法, 其特征在于, 所述第一处理节点使用所述 目标锁对所述目标数据对象进行加锁操作包括:
所述第一处理节点使用所述目标锁对所述目标数据对象进行加排它锁的 操作;
所述将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加锁状态 的值, 包括:
将所述原有值中用于表示所述目标锁在所述第一处理节点上的状态的数 据位的值加上预先设定的第二值,得到所述锁操作数的更新值; 所述更新值中 用于表示所述目标锁在所述第一处理节点上的状态的数据位的值为表示所述 目标锁在所述第一处理节点上为排他锁状态的值;
当所述原有值满足加锁操作成功的条件时 ,所述第一处理节点确认所述加 锁操作成功, 否则, 确定所述加锁操作失败包括:
所述第一处理节点判断所述原有值所记录的所述目标锁在所述数据库系 统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所述加 排它锁操作成功, 否则, 确定所述加排它锁操作失败; 或者
所述第一处理节点判断所述原有值所记录的所述目标锁在所述第一处理 节点上的状态是否为共享锁状态,且在其它处理节点上的状态是否均为未锁定 状态, 若是, 则确认所述加排它锁操作成功, 否则, 确定所述加排它锁操作失 败;所述其它处理节点为所述数据库系统中除所述第一处理节点之外的所有处 理节点;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。
5、 如权利要求 3或 4所述的方法, 其特征在于, 所述方法还包括: 当所述第一处理节点确定所述加锁操作失败时,将所述更新值中用于表示 所述目标锁在所述第一处理节点上的状态的数据位的值更新为用于表示所述 目标锁在所述第一处理节点上为排队等待状态的值。
6、 一种数据库系统的锁操作方法, 其特征在于, 包括:
第一处理节点获取目标锁的锁操作数,所述锁操作数用于记录所述目标锁 当前在所述数据库系统中各个处理节点上的状态,且所述目标锁当前在所述数 据库系统中每个处理节点上的状态使用所述操作数中的一个或者多个数据位 表示;
所述第一处理节点使用所述目标锁对目标数据对象进行放锁操作; 所述第一处理节点将所述锁操作数中用于表示所述目标锁在所述第一处 理节点上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节 点上为未锁定状态的值,以使所述数据库系统中的处理节点根据所述锁操作数 获知所述目标锁在所述第一处理节点上为未锁定状态。
7、 如权利要求 6所述的方法, 其特征在于, 所述第一处理节点将所述锁 操作数中用于表示所述目标锁在所述第一处理节点上的状态的数据位的值更 新为用于表示所述目标锁在所述第一处理节点上为未锁定状态的值, 包括: 所述第一处理节点获取使用所述目标锁对所述目标数据对象进行放锁操 作的时刻所述锁操作数的原有值,以及将所述原有值中用于表示所述目标锁在 所述第一处理节点上的状态的数据位的值加上预先设定的第三值,得到所述锁 操作数的更新值,所述更新值中表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为未锁定状态的值。
8、 如权利要求 7所述的方法, 其特征在于, 所述第一处理节点将所述更 新值中表示所述目标锁在所述第一处理节点上的状态的数据位的值作为用于 表示所述目标锁在所述第一处理节点上为未锁定状态的值之后,所述方法还包 括:
所述第一处理节点判断所述原有值所表示的所述目标锁在所述数据库系 统中各个处理节点上的状态是否存在排队等待状态, 若是, 所述第一处理节点 向所述目标锁为排队等待状态的处理节点发送所述更新值,以使所述目标锁为 排队等待状态的处理节点对所述目标锁进行锁操作。
9、 一种节点设备, 其特征在于, 包括: 获取单元、 操作单元和确定单元, 其中:
所述获取单元, 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在数据库系统中各个处理节点上的状态,所述数据库系统为所述节 点设备所在的数据库系统;且所述目标锁当前在所述数据库系统中每个处理节 点上的状态使用所述锁操作数中的一个或者多个数据位表示;
所述操作单元,用于使用所述目标锁对所述节点设备上的目标数据对象进 行加锁操作,并将所述锁操作数中用于表示所述目标锁在所述第一处理节点上 的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为加 锁状态的值;
所述确定单元, 用于根据所述锁操作数确认所述加锁操作是否成功。
10、如权利要求 9所述的节点设备,其特征在于,所述操作单元具体包括: 加锁单元,用于使用所述目标锁对所述节点设备上的目标数据对象进行加 锁操作;
获取单元,用于获取所述加锁单元使用所述目标锁对所述节点设备上的目 标数据对象进行加锁操作的时刻所述锁操作数的原有值;
第一更新单元,用于将所述原有值中用于表示所述目标锁在所述节点设备 上的状态的数据位的值更新为用于表示所述目标锁在所述第一处理节点上为 加锁状态的值;
所述确认单元, 具体用于当所述原有值满足加锁操作成功的条件时,确认 所述加锁操作成功, 否则, 确定所述加锁操作失败。
11、 如权利要求 10所述的节点设备, 其特征在于, 所述加锁单元具体用 于使用所述目标锁对所述目标数据对象进行加共享锁的操作;
所述第一更新单元,具体用于将所述原有值中用于表示所述目标锁在所述 第一处理节点上的状态的数据位的值加上预先设定的第一值,得到所述锁操作 数的更新值;所述更新值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为共享锁状态的值; 所述确认单元具体用于判断所述原有值所记录的所述目标锁在所述数据 库系统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所 述加共享锁操作成功; 否则, 确定所述加锁操作失败;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。
12、 如权利要求 10所述的节点设备, 其特征在于, 所述加锁单元具体用 于使用所述目标锁对所述目标数据对象进行加排它锁的操作;
所述第一更新单元,具体用于将所述原有值中用于表示所述目标锁在所述 第一处理节点上的状态的数据位的值加上预先设定的第二值,得到所述锁操作 数的更新值;所述更新值中用于表示所述目标锁在所述第一处理节点上的状态 的数据位的值为表示所述目标锁在所述第一处理节点上为排他锁状态的值; 所述确认单元,具体用于判断所述原有值所记录的所述目标锁在所述数据 库系统中各个处理节点上的状态是否均为允许加共享锁状态; 若是, 则确认所 述加排它锁操作成功, 否则, 确定所述加排它锁操作失败; 或者
所述确认单元具体用于判断所述原有值所记录的所述目标锁在所述节点 设备上的状态是否为共享锁状态,且在其它处理节点上的状态是否均为未锁定 状态, 若是, 则确认所述加排它锁操作成功, 否则, 确定所述加排它锁操作失 败;所述其它处理节点为所述数据库系统中除所述节点设备之外的所有处理节 点;
其中, 所述允许加共享锁状态为未锁定状态和共享锁状态中的任一状态。
13、 如权利要求 11或 12所述的节点设备, 其特征在于, 所述节点设备还 包括:
第二更新单元, 用于当所述确认单元确定所述加锁操作失败时, 将所述更 新值中用于表示所述目标锁在所述第一处理节点上的状态的数据位的值更新 为用于表示所述目标锁在所述第一处理节点上为排队等待状态的值。
14、一种节点设备, 其特征在于, 包括: 获取单元、操作单元和更新单元, 其中:
所述获取单元, 用于获取目标锁的锁操作数, 所述锁操作数用于记录所述 目标锁当前在数据库系统中各个处理节点上的状态,所述数据库系统为所述节 点设备所在的数据库系统;且所述目标锁当前在所述数据库系统中每个处理节 点上的状态使用所述操作数中的一个或者多个数据位表示;
所述操作单元, 用于使用所述目标锁对目标数据对象进行放锁操作; 所述更新单元,用于将所述锁操作数中用于表示所述目标锁在所述节点设 备上的状态的数据位的值更新为用于表示所述目标锁在所述节点设备上为未 锁定状态的值,以使所述数据库系统中的处理节点根据所述锁操作数获知所述 目标锁在所述节点设备上为未锁定状态。
15、 如权利要求 14所述节点设备, 其特征在于, 所述更新单元具体用于 获取使用所述目标锁对所述目标数据对象进行放锁操作的时刻所述锁操作数 的数据位的值加上预先设定的第三值,得到所述锁操作数的更新值, 所述更新 值中表示所述目标锁在所述节点设备上的状态的数据位的值为表示所述目标 锁在所述节点设备上为未锁定状态的值。
16、 如权利要求 15所述的节点设备, 其特征在于, 所述节点设备还包括: 判断单元,用于在所述更新单元将所述锁操作数中用于表示所述目标锁在 所述节点设备上的状态的数据位的值更新为用于表示所述目标锁在所述节点 设备上为未锁定状态的值之后,判断所述原有值所表示的所述目标锁在所述数 据库系统中各个处理节点上的状态是否存在排队等待状态, 若是, 向所述目标 锁为排队等待状态的处理节点发送所述更新值,以使所述目标锁为排队等待状 态的处理节点对所述目标锁进行锁操作。
PCT/CN2014/071030 2013-06-06 2014-01-21 一种数据库系统的锁操作方法及设备 WO2014194678A1 (zh)

Priority Applications (4)

Application Number Priority Date Filing Date Title
EP14730727.6A EP2876566A4 (en) 2013-06-06 2014-01-21 SPERROPERATION PROCEDURE OF A DATABASE SYSTEM AND DEVICE
IN1340KON2014 IN2014KN01340A (zh) 2013-06-06 2014-01-21
RU2014133161/08A RU2585973C2 (ru) 2013-06-06 2014-01-21 Способ и устройство управления операцией блокировки системы баз данных
US14/323,546 US9449041B2 (en) 2013-06-06 2014-07-03 Database system lock operation method and device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310222370.5 2013-06-06
CN2013102223705A CN103336789A (zh) 2013-06-06 2013-06-06 一种数据库系统的锁操作方法及设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US14/323,546 Continuation US9449041B2 (en) 2013-06-06 2014-07-03 Database system lock operation method and device

Publications (1)

Publication Number Publication Date
WO2014194678A1 true WO2014194678A1 (zh) 2014-12-11

Family

ID=49244954

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/071030 WO2014194678A1 (zh) 2013-06-06 2014-01-21 一种数据库系统的锁操作方法及设备

Country Status (6)

Country Link
US (1) US9449041B2 (zh)
EP (1) EP2876566A4 (zh)
CN (1) CN103336789A (zh)
IN (1) IN2014KN01340A (zh)
RU (1) RU2585973C2 (zh)
WO (1) WO2014194678A1 (zh)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103336789A (zh) * 2013-06-06 2013-10-02 华为技术有限公司 一种数据库系统的锁操作方法及设备
CN104252545B (zh) * 2014-10-11 2017-05-31 南京国电南自维美德自动化有限公司 一种实时内存数据库的对象类型属性类型锁的实现方法
US10614039B2 (en) * 2017-04-04 2020-04-07 International Business Machines Corporation Testing of lock managers in computing environments
CN110008031B (zh) 2018-01-05 2022-04-15 北京金山云网络技术有限公司 设备操作方法、集群系统、电子设备及可读取存储介质
CN109376165A (zh) * 2018-11-14 2019-02-22 深圳市金证科技股份有限公司 内存数据库锁的实现方法和装置及计算机可读存储介质
CN109933606B (zh) * 2019-03-19 2021-04-27 上海达梦数据库有限公司 一种数据库修改方法、装置、设备及存储介质
CN110162532B (zh) * 2019-05-09 2021-06-04 中国银行股份有限公司 交易数据处理方法和设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050289143A1 (en) * 2004-06-23 2005-12-29 Exanet Ltd. Method for managing lock resources in a distributed storage system
CN102355473A (zh) * 2011-06-28 2012-02-15 用友软件股份有限公司 分布式计算环境下的锁定控制系统和方法
US8271437B2 (en) * 2008-07-28 2012-09-18 International Business Machines Corporation Managing locks across distributed computing nodes
CN103336789A (zh) * 2013-06-06 2013-10-02 华为技术有限公司 一种数据库系统的锁操作方法及设备

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5596754A (en) * 1992-10-29 1997-01-21 Digital Equipment Corporation Method for performing private lock management
KR100314879B1 (ko) 1998-05-15 2002-02-28 이계철 주기억장치데이터베이스관리시스템을위한락관리방법
US6182186B1 (en) * 1998-06-30 2001-01-30 Sun Microsystems, Inc. Method and apparatus that utilizes lock states to lock resources
US6658513B1 (en) * 2000-10-10 2003-12-02 International Business Machines Corporation Managing locks affected by planned or unplanned reconfiguration of locking facilities
US6850938B1 (en) * 2001-02-08 2005-02-01 Cisco Technology, Inc. Method and apparatus providing optimistic locking of shared computer resources
US7624126B2 (en) * 2003-06-25 2009-11-24 Microsoft Corporation Registering for and retrieving database table change information that can be used to invalidate cache entries
US7650360B2 (en) * 2004-04-16 2010-01-19 Microsoft Corporation System and methods for database lock with reference counting
US20060242104A1 (en) * 2005-04-21 2006-10-26 Microsoft Corporation Systems and methods for manipulating data in a data storage system
CN101364230B (zh) * 2008-09-24 2011-04-20 金蝶软件(中国)有限公司 一种并发访问控制方法及装置
CN102129391B (zh) * 2011-03-14 2013-08-28 华中科技大学 一种数据库中自旋锁的实现方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050289143A1 (en) * 2004-06-23 2005-12-29 Exanet Ltd. Method for managing lock resources in a distributed storage system
US8271437B2 (en) * 2008-07-28 2012-09-18 International Business Machines Corporation Managing locks across distributed computing nodes
CN102355473A (zh) * 2011-06-28 2012-02-15 用友软件股份有限公司 分布式计算环境下的锁定控制系统和方法
CN103336789A (zh) * 2013-06-06 2013-10-02 华为技术有限公司 一种数据库系统的锁操作方法及设备

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP2876566A4 *

Also Published As

Publication number Publication date
EP2876566A1 (en) 2015-05-27
RU2014133161A (ru) 2016-03-10
US9449041B2 (en) 2016-09-20
CN103336789A (zh) 2013-10-02
RU2585973C2 (ru) 2016-06-10
IN2014KN01340A (zh) 2015-10-16
US20140372396A1 (en) 2014-12-18
EP2876566A4 (en) 2015-08-26

Similar Documents

Publication Publication Date Title
WO2014194678A1 (zh) 一种数据库系统的锁操作方法及设备
US6539446B1 (en) Resource locking approach
US8285925B1 (en) Management of object mapping information corresponding to a distributed storage system
US7409397B2 (en) Supporting replication among a plurality of file operation servers
US7600063B2 (en) Techniques for improved read-write concurrency
US8051179B2 (en) Distributed session failover
US7392335B2 (en) Anticipatory changes to resources managed by locks
JP4098233B2 (ja) マルチノードシステム内でのデータおよびロック転送中の呼出し時間およびメッセージトラフィックの減少
US8452958B2 (en) Determining certificate revocation status
US20120072763A1 (en) System and method of file locking in a network file system federated namespace
EP3146438B1 (en) Securing a directed acyclic graph
US7571354B2 (en) System and method for request routing
US9875212B1 (en) Managing cached information corresponding to a distributed storage system
US9501513B2 (en) Advanced concurrency management in enterprise service oriented architecture based integrated business processing of distributed application components
US8505030B2 (en) Coordinating resources using a volatile network intermediary
US10713378B2 (en) Techniques for eventually consistent inheritance propagation for nested content item namespaces
US20070005555A1 (en) Method and mechanism for supporting virtual content in performing file operations at a RDBMS
EP3391217B1 (en) Long-running storage manageability operation management
US9560134B1 (en) Storage array side write locking
JP2011232926A (ja) 分散データベースシステム、デッドロック通知方法およびデッドロック通知プログラム
JP2013541086A (ja) 分散型メタデータキャッシュ
US8521771B1 (en) Management of class-associated object mapping information corresponding to a distributed storage system
CN114329636B (zh) 一种司法数据的访问控制方法、系统、设备及存储介质
JP6728773B2 (ja) 情報処理システム、情報処理装置、排他制御装置、情報処理方法、排他制御方法、及び、プログラム
WO2015097991A1 (ja) トランザクション分散処理装置、方法、システム、および、記憶媒体

Legal Events

Date Code Title Description
REEP Request for entry into the european phase

Ref document number: 2014730727

Country of ref document: EP

WWE Wipo information: entry into national phase

Ref document number: 2014730727

Country of ref document: EP

ENP Entry into the national phase

Ref document number: 2014133161

Country of ref document: RU

Kind code of ref document: A

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14730727

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE