Methods, systems, and computer program products for efficiently accessing an ordered sequence in a clustered database environment
Described are improved systems, computer program products, and methods for efficiently accessing an ordered sequence in a clustered database environment. The approach includes receiving multiple requests for ordered sequence numbers from a plurality of entities. These multiple entries respectively pertaining to the multiple requests may be stored in a data structure. An entry may be selected from the multiple entries in the data structure; and one or more ordered sequence numbers may be provided to a requesting entity for the entry with a distributed lock mechanism based at least in part upon sequence number reservation or a local entity priority.
1 . A method, comprising:
enforcing, at a database server in a database environment, uniqueness of ordered sequence numbers for fulfillment of requests for the ordered sequence numbers at least by:
receiving multiple requests for particular ordered sequence numbers of an ordered sequence for a database from a plurality of entities that is remote from the database server, wherein
a local entity priority grants a higher priority to one or more entities having a first parent entity at a first hierarchical level as does a first entity of the plurality of entities, and grants a lower priority to one or more separate entities having a second parent entity that is also located at the first hierarchical level but is different from the first parent entity, and
multiple entries respectively representing the multiple requests are stored in a data structure; and
responsive to receipt of the multiple requests, providing an ordered sequence number to the first entity having the first parent entity; and
after providing the ordered sequence number to the first entity having the first parent entity and located at a second hierarchical level under the first hierarchical level, providing one or more additional ordered sequence numbers to a requesting entity of the one or more entities based at least in part upon the local entity priority, providing the one or more additional ordered sequence numbers comprising:
prioritizing, using at least the local entity priority, a request for at least one ordered sequence number from the requesting entity over a separate request from another requesting entity of the one or more separate entities at least by selecting, from the data structure, an entry representing the requesting entity when the requesting entity has the first parent entity as does the first entity and is provided with the one or more additional ordered sequence numbers including the at least one ordered sequence number, wherein
the another requesting entity has the second parent entity different from the first parent entity, and
the particular ordered sequence numbers include the one or more additional sequence numbers, and
the particular ordered sequence numbers are different from one another in an order of the ordered sequence for the database and are respectively provided to the plurality of entities based at least in part upon the local entity priority.
2 . The method of claim 1 , wherein providing the one or more additional ordered sequence numbers is based at least in part upon the local entity priority comprises:
acquiring, by the first entity, an exclusive lock for acquiring the ordered sequence number;
acquiring, by the first entity, the ordered sequence number from the ordered sequence numbers at least by using the exclusive lock; and
providing priority to the requesting entity relative to the first entity over the another requesting entity to acquire the exclusive lock for acquiring the one or more additional ordered sequence number, wherein
the database environment comprises a hierarchical structure of computing entities having at least the first hierarchical level and the second hierarchical level under the first hierarchical level,
the one or more entities, the first entity, and the one or more separate entities are located at the second hierarchical level in the hierarchical structure of computing entities,
the separate request is received before the request, and
the one or more additional ordered sequence numbers for fulling the multiple requests are different from each other.
3 . The method of claim 2 , further comprising:
identifying the another requesting entity that has a waiting entry in the data structure and corresponds to a same parent as the first entity;
releasing, by the first entity, the exclusive lock; and
acquiring, by the requesting entity, the exclusive lock on the one or more additional ordered sequence numbers that are generated by an ordered sequence number generator for the request, wherein
the first hierarchical level comprises at least a first instance of a database in the hierarchical structure of computing entities, and
the second hierarchical level comprises at least a plurality of sessions of the first instance of the database.
4 . The method of claim 3 , further comprising:
when it is determined that there exists no other local requesting entity with an entry in the data structure, selecting a separate entity that is not located on the local instance based at least in part upon a pending entry for the separate entity in the data structure, the pending entry corresponding to a particular request for at least one ordered sequence number that has not been fulfilled.
5 . The method of claim 1 , further comprising generating multiple additional ordered sequence numbers and providing the multiple additional ordered sequence numbers based at least in part upon sequence number reservation, wherein providing the multiple additional ordered sequence numbers is based at least in part upon the sequence number reservation comprises:
acquiring, by the first entity or a different entity having ownership of a distributed lock mechanism, an exclusive lock for acquiring an additional ordered sequence number of the multiple additional ordered sequence numbers;
acquiring, by the first entity or the different entity, the additional ordered sequence number from the multiple additional ordered sequence numbers at least by using the exclusive lock; and
reserving, by the first entity or the different entity, one or more separate ordered sequence numbers for the multiple additional ordered sequence numbers for one or more remaining entities that are waiting on a queue for the one or more separate ordered sequence numbers.
6 . The method of claim 5 , further comprising:
sending information pertaining to the one or more remaining entities or one or more remaining entries, wherein the one or more remaining entries correspond to one or more requests for respective ordered sequence numbers by the one or more remaining entities, and the one or more requests are stored in the data structure and are waiting for fulfillment.
7 . The method of claim 6 , further comprising:
transforming one or more requests for exclusive locks by the one or more remaining entities into one or more transformed requests that are respectively associated with one or more shared locks; and
while the first entity or the different entity is currently holding the exclusive lock, obtaining, by the one or more remaining entities, the one or more separate ordered sequence numbers by respectively using the one or more shared locks, rather than waiting for the first entity or the different entity to release the exclusive lock.
8 . The method of claim 7 , further comprising:
releasing, by the first entity, the exclusive lock; and
respectively acquiring, by the one or more remaining entities, the one or more shared locks, wherein
the distributed lock mechanism comprises a first distributed lock mechanism instance that is located on the first instance or node and grants locks to first lock requesting entities on the first instance or node, and
the distributed lock mechanism comprises a second distributed lock mechanism instance that is located on the second instance or node and grants locks to second lock requesting entities on the second instance or node.
9 . The method of claim 5 , wherein the sequence number reservation is used in conjunction with the local entity priority in servicing the multiple requests for the ordered sequence numbers.
10 . The method of claim 1 , further comprising:
while the first entity is currently holding an exclusive lock to be provided with the ordered sequence number, obtaining, by one or more remaining entities that also request for the ordered sequence numbers as the first entity, one or more separate ordered sequence numbers of the ordered sequence numbers by respectively using one or more shared locks different from the exclusive lock, rather than waiting for the first entity to release the exclusive lock.
11 . A system comprising:
a processor; and
a memory to hold a set of program code instructions, in which the set of program code instructions comprises program code to perform a set of acts, the set of acts comprising:
enforcing, at a database server in a database environment, uniqueness of ordered sequence numbers for fulfillment of requests for the ordered sequence numbers at least by:
receiving multiple requests for particular ordered sequence numbers of an ordered sequence for a database from a plurality of entities that is remote from the database server, wherein
a local entity priority grants a higher priority to one or more entities having a first parent entity at a first hierarchical level as does a first entity of the plurality of entities, and grants a lower priority to one or more separate entities having a second parent entity that is also located at the first hierarchical level but is different from the first parent entity, and
multiple entries respectively representing the multiple requests are stored in a data structure; and
responsive to receipt of the multiple requests, providing an ordered sequence number to the first entity having the first parent entity; and
after providing the ordered sequence number to the first entity having the first parent entity and located at a second hierarchical level under the first hierarchical level, providing one or more additional ordered sequence numbers to a requesting entity of the one or more entities based at least in part upon the local entity priority, providing the one or more additional ordered sequence numbers comprising:
prioritizing, using at least the local entity priority, a request for at least one ordered sequence number from the requesting entity over a separate request from another requesting entity of the one or more separate entities by selecting, from the data structure, an entry representing the requesting entity when the requesting entity has the first parent entity as does the first entity and is provided with the one or more additional ordered sequence numbers including the at least one ordered sequence number, wherein
the another requesting entity has the second parent entity different from the first parent entity, and
the particular ordered sequence numbers include the one or more additional sequence numbers, and
the particular ordered sequence numbers are different from one another in an order of the ordered sequence for the database and are respectively provided to the plurality of entities based at least in part upon the local entity priority.
12 . The system of claim 11 , wherein providing the one or more additional ordered sequence numbers is based at least in part upon the local entity priority, the set of acts further comprising:
acquiring, by the first entity, an exclusive lock for acquiring the ordered sequence number;
acquiring, by the first entity, the ordered sequence number from the ordered sequence numbers at least by using the exclusive lock; and
providing priority to the requesting entity relative to the first entity over the another requesting entity to acquire the exclusive lock for acquiring the one or more additional ordered sequence number, wherein
the database environment comprises a hierarchical structure of computing entities having at least the first hierarchical level and the second hierarchical level under the first hierarchical level,
the one or more entities, the first entity, and the one or more separate entities are located at the second hierarchical level in the hierarchical structure of computing entities,
the separate request is received before the specific request, and
the one or more additional ordered sequence numbers for fulling the multiple requests are different from each other.
13 . The system of claim 12 , the set of acts further comprising:
identifying the remote entity that has a waiting entry in the data structure and corresponds to a same parent as the entity;
releasing, by the entity, the exclusive lock; and
acquiring, by the local requesting entity, the exclusive lock as the lock on the one or more ordered sequence numbers that are generated by an ordered sequence number generator for request, wherein
the first hierarchical level comprises at least a first instance of a database in the hierarchical structure of computing entities, and
the second hierarchical level comprises at least a plurality of sessions of the first instance of the database.
14 . The system of claim 13 , the set of acts further comprising:
when it is determined that there exists no other local requesting entity with an entry in the data structure, selecting a separate entity that is not located on the local instance based at least in part upon a pending entry for the separate entity in the data structure, the pending entry corresponding to a particular request for at least one ordered sequence number that has not been fulfilled.
15 . The system of claim 11 , wherein the set of acts further comprising generating multiple additional ordered sequence numbers; and providing the multiple additional ordered sequence numbers based at least in part upon the sequence number reservation, the set of acts further comprising:
acquiring, by the first entity or a different entity having ownership of a distributed lock mechanism, an exclusive lock for acquiring an additional ordered sequence number of the multiple additional ordered sequence numbers;
acquiring, by the first entity or the different requesting entity, the additional ordered sequence number from the multiple additional ordered sequence number at least by using the exclusive lock; and
reserving, by the first entity or the different requesting entity, one or more separate ordered sequence numbers for the multiple additional ordered sequence numbers for one or more remaining entities that are waiting on a queue for the one or more separate ordered sequence numbers.
16 . The system of claim 15 , the set of acts further comprising:
sending information pertaining to the one or more remaining entities or one or more remaining entries, wherein the one or more remaining entries correspond to one or more requests for respective ordered sequence numbers by the one or more remaining entities, and the one or more requests are stored in the data structure and are waiting for fulfillment.
17 . The system of claim 16 , the set of acts further comprising:
transforming the one or more requests for exclusive locks by the one or more remaining entities into one or more transformed requests that are respectively associated with one or more shared locks; and
while the first entity or the different entity is currently holding the exclusive lock, obtaining, by the one or more remaining entities, the one or more separate ordered sequence numbers by respectively using the one or more shared locks, rather than waiting for the first entity or the different entity to release the exclusive lock.
18 . The system of claim 17 , the set of acts further comprising:
releasing, by the first entity, the exclusive lock; and
respectively acquiring, by the one or more remaining entities, the one or more shared locks, wherein
the distributed lock mechanism comprises a first distributed lock mechanism instance that is located on the first instance or node and grants locks to first lock requesting entities on the first instance or node, and
the distributed lock mechanism comprises a second distributed lock mechanism instance that is located on the second instance or node and grants locks to second lock requesting entities on the second instance or node.
19 . The system of claim 15 , wherein the sequence number reservation is used in conjunction with the local entity priority in servicing the multiple requests for the ordered sequence numbers.
20 . A computer program product including a non-transitory computer readable medium having stored thereupon instructions which, when executed by a processor, causes the processor to perform a set of acts, the set of acts comprising:
enforcing, at a database server in a database environment, uniqueness of ordered sequence numbers for fulfillment of requests for the ordered sequence numbers at least by:
receiving multiple requests for particular ordered sequence numbers of an ordered sequence for a database from a plurality of entities that is remote from the database server, wherein
a local entity priority grants a higher priority to one or more entities having a first parent entity at a first hierarchical level as does a first entity of the plurality of entities, and grants a lower priority to one or more separate entities having a second parent entity that is also located at the first hierarchical level but is different from the first parent entity, and
multiple entries respectively representing the multiple requests are stored in a data structure; and
responsive to receipt of the multiple requests, providing an ordered sequence number to the first entity having the first parent entity; and
after providing the ordered sequence number to the first entity having the first parent entity and located at a second hierarchical level under the first hierarchical level, providing one or more additional ordered sequence numbers to a requesting entity of the one or more entities based at least in part upon the local entity priority, providing the one or more additional ordered sequence numbers comprising:
prioritizing, using at least the local entity priority, a request for at least one ordered sequence number from the requesting entity over separate request from another requesting entity of the one or more separate entities at least by selecting, from the data structure, an entry representing the requesting entity when the requesting entity has the first parent entity as does the first entity and is provided with the one or more additional ordered sequence number including the at least one ordered sequence number, wherein
the another requesting entity has the second parent entity different from the first parent entity, and
the particular ordered sequence numbers include the one or more additional sequence numbers, and
the particular ordered sequence numbers are different from one another in an order of the ordered sequence for the database and are respectively provided to the plurality of entities based at least in part upon the local entity priority.
21 . The computer program product of claim 20 , wherein providing the one or more additional ordered sequence numbers is based at least in part upon the local entity priority, the set of acts further comprising:
acquiring, by the first entity, an exclusive lock for acquiring the ordered sequence number;
acquiring, by the first entity, the ordered sequence number from the ordered sequence numbers at least by using the exclusive lock; and
providing priority to the requesting entity relative to the entity over the another requesting entity to acquire the exclusive lock for acquiring the one or more additional ordered sequence number, wherein
the database environment comprises a hierarchical structure of computing entities having at least the first hierarchical level and the second hierarchical level under the first hierarchical level,
the one or more entities, the first entity, and the one or more separate entities are located at the second hierarchical level in the hierarchical structure of computing entities,
the separate request is received before the specific request, and
the one or more additional ordered sequence numbers for fulling the multiple requests are different from each other.
22 . The computer program product of claim 21 , the set of acts further comprising:
identifying the another requesting entity that has a waiting entry in the data structure and corresponds to a same parent as the first entity;
releasing, by the first entity, the exclusive lock; and
acquiring, by the requesting entity, the exclusive lock on the one or more additional ordered sequence numbers that are generated by an ordered sequence number generator for the request, wherein
the first hierarchical level comprises at least a first instance of a database in the hierarchical structure of computing entities, and
the second hierarchical level comprises at least a plurality of sessions of the first instance of the database.
23 . The computer program product of claim 22 , the set of acts further comprising:
when it is determined that there exists no other local requesting entity with an entry in the data structure, selecting a separate entity that is not located on the local instance based at least in part upon a pending entry for the separate entity in the data structure, the pending entry corresponding to a particular request for at least one ordered sequence number that has not been fulfilled.
24 . The computer program product of claim 21 , wherein the sequence number reservation is used in conjunction with the local entity priority.
25 . The computer program product of claim 20 , wherein the set of acts further comprising generating multiple additional ordered sequence numbers; and providing the one or more ordered sequence numbers based at least in part upon the sequence number reservation, the set of acts further comprising:
acquiring, by the first entity or a different entity having ownership of a distributed lock mechanism, an exclusive lock for acquiring an additional ordered sequence number;
acquiring, by the first entity or the different entity, the additional ordered sequence number from the multiple additional ordered sequence number at least by using the exclusive lock; and
reserving, by the first entity or the different entity, one or more separate ordered sequence numbers for the multiple additional ordered sequence numbers for one or more remaining entities that are waiting on a queue for one or more separate ordered sequence numbers.
26 . The computer program product of claim 25 , the set of acts further comprising:
sending information pertaining to the one or more remaining entities or one or more remaining entries, wherein the one or more remaining entries correspond to one or more requests for respective ordered sequence numbers by the one or more remaining entities, and the one or more requests are stored in the data structure and are waiting for fulfillment.
27 . The computer program product of claim 26 , the set of acts further comprising:
transforming the one or more requests for exclusive locks by the one or more remaining entities into one or more transformed requests that are respectively associated with one or more shared locks; and
while the first entity or the different entity is currently holding the exclusive lock, obtaining, by the one or more remaining entities, the one or more separate ordered sequence numbers by respectively using the one or more shared locks, rather than waiting for the first entity or the different entity to release the exclusive lock.
28 . The computer program product of claim 27 , the set of acts further comprising:
releasing, by the first entity, the exclusive lock; and
respectively acquiring, by the one or more remaining entities, the one or more shared locks, wherein
the distributed lock mechanism comprises a first distributed lock mechanism instance that is located on the first instance or node and grants locks to first lock requesting entities on the first instance or node, and
the distributed lock mechanism comprises a second distributed lock mechanism instance that is located on the second instance or node and grants locks to second lock requesting entities on the second instance or node.