Reputation: 1463
I am new to AWS Aurora.
When reading this paragraph below in this link:
To increase availability, you can use Aurora Replicas as failover targets. That is, if the primary instance fails, an Aurora Replica is promoted to the primary instance
If the failed Primary Instance can recover, which role will it be? I guess it will become a Replica?
I ask this question because I guess the server code that is connecting the Aurora DB Cluster must specify Primary Instance's and Replica's endpoint? Since Replica only serves read-only query, the code must have the endpoints corrected after a Replica is promoted to Primary Instance in order to make write-operation query?
How does my code know which endpoint is now Primary Instance's (i.e. write-operation query can be made)?
Upvotes: 2
Views: 1627
Reputation: 200692
An Aurora cluster not only provides you with direct connection endpoints for each node in the cluster, but it also provides you with a Read-Write endpoint and a Read-Only endpoint. The Read-Write endpoint will always point to the primary node. The Read-Only endpoint will do a DNS round robin of connections across the read replica nodes.
So if a node fails and a different node is promoted to primary, as long as you are using those endpoints instead of the individual node endpoints, you won't have to change anything.
Upvotes: 4
Reputation: 2830
If the failed Primary Instance can recover, which role will it be? I guess it will become a Replica?
There are multiple scenarios for a writer failure, and they are handled differently depending on the scenario. Failover is one of the ways by which Aurora recovers from a failure. When a failover occurs, the old WRITER is restarted as a READER. For other minor failure scenarios, Aurora would auto recover without requiring a failover. The same WRITER is revived instead.
How does my code know which endpoint is now Primary Instance's
Your code should always deal with Cluster Endpoints and not instance endpoints. The cluster RW endpoint will always point to the master and the cluster RO endpoint will do a DNS round robin across the replicas. At any point when a failover occurs, you client connections get dropped and they should try to reconnect using the cluster endpoints.
If you really need to know the details of the current writer and reader, you could do that by querying the replica status table, but I don't think that's what you need here.
Upvotes: 1
Reputation: 15031
You connect to the cluster endpoint through a URL, something like mydbcluster.cluster-123456789012.us-east-1.rds.amazonaws.com:3306
This way, when the failover occurs, you don't have to make any change to your code, behind the scenes in AWS, the url will now point to the read-replica which is now promoted as the primary (write) node.
Upvotes: 1