Repository navigation
Multiple hosts and target server type feature - #3607
Conversation
roji
left a comment
There was a problem hiding this comment.
Looks awesome for our 1st iteration - this will be a very nice feature. See some comments below, and also vonzshik#12 (this is just a first round, I have more 🤣).
We'll need a lot of test coverage around this...
|
|
||
| static readonly string[] CriticalFailureCodes = | ||
| { | ||
| PostgresErrorCodes.ConnectionException, |
There was a problem hiding this comment.
Does this mean that if I kill a connection (i.e. it's holding a transaction for too long) using pg_terminate_backend() that it would result in the driver thinking that it needs to failover to the next server?
There was a problem hiding this comment.
Yep, it does. The problem is, postgres throws the same exception if the database is stopped.
There was a problem hiding this comment.
Or should we just consider this as something unlikely? @roji
There was a problem hiding this comment.
Hmm... I'd be conservative here - if a code could be generated in a situation which doesn't imply the cluster is offline, I wouldn't treat it as a critical failure code. Like @mintsoft says, there may be some legitimate uses for pg_terminate_backend which shouldn't cause the cluster to be treated as offline.
Note that there's a difference depending on where the error is caught... Any error caught when opening a connection can probably mean that the cluster is offline (though don't forget the difference between database and cluster). On the other hand, with errors caught in other situations (i.e. NpgsqlConnector.ReadMessage) we should be a bit more careful. So maybe we can treat ConnectionException as "critical failure" when it happens on opening, but not when it's in NpgsqlConnector.ReadMessage...
Thoughts?
There was a problem hiding this comment.
Whenever there is an exception while opening a connection, I do not see any reason to not treat the host as 'offline'.
Also, here is the list of errors which pgjdbc treats as 'fatal'.
roji
left a comment
There was a problem hiding this comment.
A few more comments... I'll try to work on the tests today/tomorrow.
|
|
||
| static readonly string[] CriticalFailureCodes = | ||
| { | ||
| PostgresErrorCodes.ConnectionException, |
There was a problem hiding this comment.
Hmm... I'd be conservative here - if a code could be generated in a situation which doesn't imply the cluster is offline, I wouldn't treat it as a critical failure code. Like @mintsoft says, there may be some legitimate uses for pg_terminate_backend which shouldn't cause the cluster to be treated as offline.
Note that there's a difference depending on where the error is caught... Any error caught when opening a connection can probably mean that the cluster is offline (though don't forget the difference between database and cluster). On the other hand, with errors caught in other situations (i.e. NpgsqlConnector.ReadMessage) we should be a bit more careful. So maybe we can treat ConnectionException as "critical failure" when it happens on opening, but not when it's in NpgsqlConnector.ReadMessage...
Thoughts?
| get => _hostRecheckSeconds; | ||
| set | ||
| { | ||
| _hostRecheckSeconds = value; |
There was a problem hiding this comment.
What happens if I set this to 0?
There was a problem hiding this comment.
With 0, it's only going to change if the host is going offline, or a new connector is open.
There was a problem hiding this comment.
Note that this should be meaningless (do nothing) on PostgreSQL 14, where state changes are supposed to be communicated to the client.
There was a problem hiding this comment.
Note offline decision to change 0 to mean "check every single time", since an infinite timeout means that an offline host never comes back.
| get => _hostRecheckSeconds; | ||
| set | ||
| { | ||
| _hostRecheckSeconds = value; |
There was a problem hiding this comment.
Note offline decision to change 0 to mean "check every single time", since an infinite timeout means that an offline host never comes back.
…with a single host
4be9d61 to
67d8673
Compare
Closes #732
Closes #3612
Supersedes #3434
Was done under impression of #3434 as an attempt to make sense on how it's supposed to work.
The only missing feature is updating the server's state with KeepAlive.No longer required per discussion with @roji offline.@mintsoft would be glad to hear your opinion.