Skip to content
Permalink
Browse files
remove the user of the word master internally (#1713)
* deprecate the use of the word master
remove the use of the word master internally

* remove more uses of the word master
Document use of the word primary and secondary

* Use PGProperty to set values, avoid hardcoding names
  • Loading branch information
davecramer committed Feb 23, 2020
1 parent 94641ef commit 9a3e0f0ce92cc0a7addb369127b7790c5199cea3
Showing 7 changed files with 98 additions and 73 deletions.
@@ -112,6 +112,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Changed
- `ssl=true` implies `sslmode=verify-full`, that is it requires valid server certificate [cdeeaca4](https://github.com/pgjdbc/pgjdbc/commit/cdeeaca47dc3bc6f727c79a582c9e4123099526e)

targetServerType=master has been deprecated in favour of targetServerType=primary. master
will still be accepted but not documented.
### Added
- Support for `sslmode=allow/prefer/require` [cdeeaca4](https://github.com/pgjdbc/pgjdbc/commit/cdeeaca47dc3bc6f727c79a582c9e4123099526e)

@@ -441,10 +441,12 @@ Connection conn = DriverManager.getConnection(url);
* **targetServerType** = String

Allows opening connections to only servers with required state,
the allowed values are any, master, slave, secondary, preferSlave and preferSecondary.
The master/slave distinction is currently done by observing if the server allows writes.
the allowed values are any, primary, master, slave, secondary, preferSlave and preferSecondary.
The primary/secondary distinction is currently done by observing if the server allows writes.
The value preferSecondary tries to connect to secondary if any are available,
otherwise allows falls back to connecting also to master.
otherwise allows falls back to connecting also to primary.
- *N.B.* the words master and slave are being deprecated. We will silently accept them, but primary
and secondary are encouraged.

* **hostRecheckSeconds** = int

@@ -549,14 +551,20 @@ postgres installation that has identical data on each node.
For example streaming replication postgres or postgres-xc cluster.

For example an application can create two connection pools.
One data source is for writes, another for reads. The write pool limits connections only to master node:
One data source is for writes, another for reads. The write pool limits connections only to a primary node:

`jdbc:postgresql://node1,node2,node3/accounting?targetServerType=master`.
`jdbc:postgresql://node1,node2,node3/accounting?targetServerType=primary`.

And read pool balances connections between slaves nodes, but allows connections also to master if no slaves are available:
And read pool balances connections between secondary nodes, but allows connections also to a primary if no secondaries are available:

`jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true`
`jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSecondary&loadBalanceHosts=true`

<<<<<<< HEAD
If a slave fails, all slaves in the list will be tried first. If the case that there are no available slaves
the master will be tried. If all of the servers are marked as "can't connect" in the cache then an attempt
will be made to connect to all of the hosts in the URL in order.
=======
If a secondary fails, all secondaries in the list will be tried first. If the case that there are no available secondaries
the primary will be tried. If all of the servers are marked as "can't connect" in the cache then an attempt
will be made to connect to all of the hosts in the URL in order.
>>>>>>> 263d23605b9e4900fc161da165829a6b2ae168fc
@@ -583,6 +583,7 @@ public enum PGProperty {
null,
"The password for the client's ssl key (ignored if sslpasswordcallback is set)"),


/**
* The classname instantiating {@code javax.security.auth.callback.CallbackHandler} to use.
*/
@@ -626,7 +627,7 @@ public enum PGProperty {
"any",
"Specifies what kind of server to connect",
false,
new String[] {"any", "master", "slave", "secondary", "preferSlave", "preferSecondary"}),
new String [] {"any", "primary", "master", "slave", "secondary", "preferSlave", "preferSecondary"}),

/**
* Enable or disable TCP keep-alive. The default is {@code false}.
@@ -255,10 +255,10 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin
QueryExecutor queryExecutor = new QueryExecutorImpl(newStream, user, database,
cancelSignalTimeout, info);

// Check Master or Secondary
// Check Primary or Secondary
HostStatus hostStatus = HostStatus.ConnectOK;
if (candidateHost.targetServerType != HostRequirement.any) {
hostStatus = isMaster(queryExecutor) ? HostStatus.Master : HostStatus.Secondary;
hostStatus = isPrimary(queryExecutor) ? HostStatus.Primary : HostStatus.Secondary;
}
GlobalHostStatusTracker.reportHostStatus(hostSpec, hostStatus);
knownStates.put(hostSpec, hostStatus);
@@ -753,7 +753,7 @@ private void runInitialQueries(QueryExecutor queryExecutor, Properties info)

}

private boolean isMaster(QueryExecutor queryExecutor) throws SQLException, IOException {
private boolean isPrimary(QueryExecutor queryExecutor) throws SQLException, IOException {
Tuple results = SetupQueryRunner.run(queryExecutor, "show transaction_read_only", true);
String value = queryExecutor.getEncoding().decode(results.get(0));
return value.equalsIgnoreCase("off");
@@ -14,9 +14,19 @@ public boolean allowConnectingTo(HostStatus status) {
return status != HostStatus.ConnectFail;
}
},
/**
* @deprecated we no longer use the terms master or slave in the driver, or the PostgreSQL
* project.
*/
@Deprecated
master {
public boolean allowConnectingTo(HostStatus status) {
return status == HostStatus.Master || status == HostStatus.ConnectOK;
return primary.allowConnectingTo(status);
}
},
primary {
public boolean allowConnectingTo(HostStatus status) {
return status == HostStatus.Primary || status == HostStatus.ConnectOK;
}
},
secondary {
@@ -35,17 +45,20 @@ public boolean allowConnectingTo(HostStatus status) {
/**
* <p>The postgreSQL project has decided not to use the term slave to refer to alternate servers.
* secondary or standby is preferred. We have arbitrarily chosen secondary.
* As of Jan 2018 in order not to break existint code we are going to accept both slave or
* As of Jan 2018 in order not to break existing code we are going to accept both slave or
* secondary for names of alternate servers.</p>
*
* <p>The current policy is to keep accepting this silently but not document slave, or slave preferSlave</p>
*
* <p>As of Jul 2018 silently deprecate the use of the word master as well</p>
*
* @param targetServerType the value of {@code targetServerType} connection property
* @return HostRequirement
*/

public static HostRequirement getTargetServerType(String targetServerType) {
String allowSlave = targetServerType.replace("lave", "econdary");

String allowSlave = targetServerType.replace("lave", "econdary").replace("master", "primary");
return valueOf(allowSlave);
}

@@ -11,6 +11,6 @@
public enum HostStatus {
ConnectFail,
ConnectOK,
Master,
Primary,
Secondary
}

0 comments on commit 9a3e0f0

Please sign in to comment.