Lease based leader election system
First Claim
1. A system, comprising:
- a database service, implemented by one or more computing devices and configured to store a replica of a database table on respective master hosts on computing devices in the system, each master host residing in a different availability zone, wherein a master host configured to act as a primary master host can service write requests that are directed to the database table;
a data storage service, implemented by one or more computing devices;
wherein one of the master hosts is configured to assume the role of primary master host for the database table, wherein to assume the role of primary master host, the one of the master hosts is configured to;
update a lease record maintained by the data storage service to reflect that the one of the master hosts holds a lease for the database table, wherein the lease represents an authorization to act as the primary master host for the database table for a pre-determined lease period; and
enter a writable mode that enables writing to the replica of the database table stored on the one of the master hosts;
wherein the other one of the master hosts is configured to;
access the lease record to determine whether the lease is held; and
in response to determining that the lease is held by the one of the master hosts, maintain the replica of the database table stored on the other one of the master hosts in a read-only mode;
wherein the one of the master hosts is further configured to;
access, subsequent to assuming the role of primary master host and prior to expiration of the pre-determined lease period, the lease record to determine whether the lease is still held by the one of the master hosts;
maintain the replica of the database table stored on the one of the master hosts in the writable mode and renew the lease, in response to determining that the lease is still held by the one of the master hosts, wherein to renew the lease, the one of the master hosts updates the lease record to reflect that the one of the master hosts still holds the lease and that it has been renewed; and
enter a read-only mode and refrain from renewing the lease, in response to determining that the lease is held by the other one of the master hosts.
1 Assignment
0 Petitions
Accused Products
Abstract
A database service may store data on behalf of clients in multiple replicas on respective computing nodes in different availability zones. The service may employ a lease based protocol to select a master replica for a replica group that does not depend on an external service, but is managed by client processes executing on the database hosts themselves. To assume the role of a primary (writable) master for a database table, a master host may acquire a lease by updating a lease record for the table that is maintained in a consistent data store. If the master host fails to renew the lease within a pre-determined lease period, it may revert to read-only mode, and a secondary master host, having determining (based on the lease record) that the primary master no longer holds the lease, may assume the role of primary master by acquiring the lease and making itself writable.
60 Citations
21 Claims
-
1. A system, comprising:
-
a database service, implemented by one or more computing devices and configured to store a replica of a database table on respective master hosts on computing devices in the system, each master host residing in a different availability zone, wherein a master host configured to act as a primary master host can service write requests that are directed to the database table; a data storage service, implemented by one or more computing devices; wherein one of the master hosts is configured to assume the role of primary master host for the database table, wherein to assume the role of primary master host, the one of the master hosts is configured to; update a lease record maintained by the data storage service to reflect that the one of the master hosts holds a lease for the database table, wherein the lease represents an authorization to act as the primary master host for the database table for a pre-determined lease period; and enter a writable mode that enables writing to the replica of the database table stored on the one of the master hosts; wherein the other one of the master hosts is configured to; access the lease record to determine whether the lease is held; and in response to determining that the lease is held by the one of the master hosts, maintain the replica of the database table stored on the other one of the master hosts in a read-only mode; wherein the one of the master hosts is further configured to; access, subsequent to assuming the role of primary master host and prior to expiration of the pre-determined lease period, the lease record to determine whether the lease is still held by the one of the master hosts; maintain the replica of the database table stored on the one of the master hosts in the writable mode and renew the lease, in response to determining that the lease is still held by the one of the master hosts, wherein to renew the lease, the one of the master hosts updates the lease record to reflect that the one of the master hosts still holds the lease and that it has been renewed; and enter a read-only mode and refrain from renewing the lease, in response to determining that the lease is held by the other one of the master hosts. - View Dependent Claims (2, 3, 4, 5)
-
-
6. A method, comprising:
performing by one or more computers; acquiring, by a given one of a group of two or more computing nodes that operate collectively over multiple availability zones, a lease that represents an authorization to assume a particular role within the group of computing nodes for a pre-determined lease period, wherein at most one of the computing nodes in the group can be authorized to perform the particular role at a time, and wherein acquiring the lease comprises updating a lease record maintained in a consistent data store to reflect the acquisition of the lease; renewing, one or more times by the given computing node subsequent to said assuming the particular role, the lease, wherein renewing the lease comprises updating the lease record to reflect the continued ownership of the lease by the given computing node; accessing, by another one of the group of computing nodes, the lease record maintained in the consistent data store; determining, by the other computing node, dependent at least in part on the lease record, whether the given computing node has renewed the lease during a most recent lease period; acquiring, by the other computing node, in response to determining that the given computing node has not renewed the lease during the most recent lease period, the lease, wherein acquiring the lease comprises updating the lease record to reflect the acquisition of the lease by the other computing node; and assuming, by the other computing node, the particular role within the group of computing nodes for the next lease period. - View Dependent Claims (7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
-
17. A non-transitory, computer-readable storage medium storing program instructions that when executed on one or more computers cause the one or more computers to implement a database service,
wherein the database service comprises two master hosts, each residing in a different availability zone; -
wherein each of the master hosts executes a respective instance of a client process for performing lease based leader election, and wherein the respective instances of the client process collectively control assumption, by no more than one of the master hosts at a time, of the role of primary master host for a given database table, replicas of which are stored on each of the master hosts; wherein to control assumption of the role of primary master host, the respective instance of the client process executing on each of the master hosts is configured to perform one or more of; accessing lease information for the given database table that is maintained by a consistent data storage service; determining, dependent on the lease information, whether a lease that represents an authorization to assume the role of primary master host for the given database table for a pre-determined lease period is held by one of the master hosts; determining, dependent on the lease information or on replication status information for one or more of the master hosts that is maintained by the consistent data storage service, whether a master host that holds the lease has renewed the lease within a most recent lease period; acquiring the lease in response to determining that no other master host holds the lease or that a master host that holds the lease has not renewed the lease within a most recent lease period, wherein acquiring the lease comprises updating the lease information for the given database table that is maintained by the consistent data storage service to reflect the acquisition of the lease by the master host;
orrenewing the lease prior to the expiration of the lease period in response to determining that the master host holds the lease, wherein renewing the lease comprises updating the lease information for the given database table that is maintained by the consistent data storage service to reflect the continued ownership of the lease by the master host. - View Dependent Claims (18, 19, 20, 21)
-
Specification