public class PicodataClusterAwareDataSource extends PicodataConnectionPoolDataSource implements DataSource, Serializable, AutoCloseable
Picodata implementation of ConnectionPoolDataSource that should be used with
external connection pool implementations. This implementation is intended to be used with
a cluster-aware load balancer. DefaultLoadBalancerImpl is used if no other load
balancer implementation is specified.
Example usage:
PicodataClusterAwareDataSource ds = new PicodataClusterAwareDataSource(); ds.setLoadBalancer(new MyCustomLoadBalancer()); ds.setTopologyUpdateDelay(5000); ds.setTopologyUpdateMaxReconnectionAttempts(3);
This class can be used e.g. in Spring or HikariCP configuration. Example Spring configuration (the property prefixes can be different):
spring.datasource.type=io.picodata.jdbc.datasource.PicodataClusterAwareDataSource spring.datasource.url=jdbc:picodata://localhost:5432/ spring.datasource.username=myuser spring.datasource.password=mypassword
An optional nodes selection strategy can be implemented and used for filtering
and reordering the nodes before making a connection. The custom strategy class must implement
LoadBalancerNodesSelectionStrategy and be available for the class loader.
Then the strategy can be specified for use as follows:
spring.datasource.nodes-selection-strategy=com.example.MyCustomNodesSelectionStreategyImpl
You can specify the lists of allowed and forbidden tiers for the connection nodes. This will allow creating connection only to read-only nodes or skip arbiter nodes, depending on your cluster topology. Let's imagine that your cluster has a dedicated tier for read-only nodes and all arbiter nodes are assigned to an "arbiter" tier. For selecting only suitable nodes for connection, specify the following properties:
spring.datasource.nodes-allowed-tiers=read-only spring.datasource.nodes-forbidden-tiers=arbiter
| Constructor and Description |
|---|
PicodataClusterAwareDataSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
getDataSourceProperty(PicodataDataSourceProperty property) |
String |
getDescription()
Gets a description of this DataSource.
|
LoadBalancer |
getLoadBalancer()
Get the load balancer instance.
|
protected LoadBalancerConfig |
getLoadBalancerConfig()
Get actual load balancer configuration, containing settings for nodes selection
mechanism
|
String |
getNodesAllowedTiers()
Get the comma-separated list of allowed tier names for the connection nodes.
|
String |
getNodesForbiddenTiers()
Get the comma-separated list of forbidden tier names for the connection nodes.
|
String |
getNodesSelectionStrategy()
Set the nodes selection strategy to use.
|
String |
getProperty(String name) |
int |
getTopologyUpdateDelay()
Get the topology update delay
|
int |
getTopologyUpdateMaxReconnectionAttempts()
Get the maximum number of reconnection attempts while receiving topology updates.
|
protected String |
internalGetURL(String user,
String password) |
boolean |
isWrapperFor(Class<?> iface) |
void |
setDataSourceProperty(PicodataDataSourceProperty property,
String value) |
void |
setLoadBalancer(LoadBalancer loadBalancer)
Set the load balancer implementation to use.
|
void |
setNodesAllowedTiers(String nodesAllowedTiers)
Set the comma-separated list of allowed tier names for the connection nodes.
|
void |
setNodesForbiddenTiers(String nodesForbiddenTiers)
Set the comma-separated list of forbidden tier names for the connection nodes.
|
void |
setNodesSelectionStrategy(String nodesSelectionStrategy)
Set the nodes selection strategy to use.
|
void |
setProperty(String name,
String value) |
void |
setTopologyUpdateDelay(int topologyUpdateDelay)
Set the topology update delay in milliseconds.
|
void |
setTopologyUpdateMaxReconnectionAttempts(int topologyUpdateMaxReconnectionAttempts)
Set the maximum number of reconnection attempts while receiving topology updates.
|
<T> T |
unwrap(Class<T> iface) |
getPooledConnection, getPooledConnectiongetApplicationName, getCancelSignalTimeout, getConnection, getConnection, getConnectTimeout, getDatabaseMetadataCacheFields, getDatabaseMetadataCacheFieldsMiB, getDefaultRowFetchSize, getHideUnprivilegedObjects, getHosts, getLocalSocketAddress, getLoginTimeout, getLogServerErrorDetail, getLogWriter, getMaxResultBuffer, getParentLogger, getPassword, getPorts, getPreparedStatementCacheQueries, getPreparedStatementCacheSizeMiB, getPrepareThreshold, getProperty, getReadOnly, getReadOnlyMode, getReceiveBufferSize, getReWriteBatchedInserts, getSendBufferSize, getSocketFactory, getSocketTimeout, getSslCert, getSslFactory, getSslHostnameVerifier, getSslKey, getSslMode, getSslPassword, getSslPasswordCallback, getSslRootCert, getTcpKeepAlive, getTcpNoDelay, getUnknownLength, getURL, getUser, readBaseObject, setApplicationName, setCancelSignalTimeout, setConnectTimeout, setDatabaseMetadataCacheFields, setDatabaseMetadataCacheFieldsMiB, setDefaultRowFetchSize, setHideUnprivilegedObjects, setHosts, setLocalSocketAddress, setLoginTimeout, setLogServerErrorDetail, setLogWriter, setMaxResultBuffer, setPassword, setPorts, setPreparedStatementCacheQueries, setPreparedStatementCacheSizeMiB, setPrepareThreshold, setProperty, setReadOnly, setReadOnlyMode, setReceiveBufferSize, setReWriteBatchedInserts, setSendBufferSize, setSocketFactory, setSocketTimeout, setSslCert, setSslFactory, setSslHostnameVerifier, setSslKey, setSslMode, setSslPassword, setSslPasswordCallback, setSslRootCert, setTcpKeepAlive, setTcpNoDelay, setUnknownLength, setURL, setUser, writeBaseObjectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConnection, getConnectiongetLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriterpublic String getDescription()
getDescription in class PicodataConnectionPoolDataSourcepublic int getTopologyUpdateDelay()
public void setTopologyUpdateDelay(int topologyUpdateDelay)
topologyUpdateDelay - delay in millisecondspublic int getTopologyUpdateMaxReconnectionAttempts()
public void setTopologyUpdateMaxReconnectionAttempts(int topologyUpdateMaxReconnectionAttempts)
topologyUpdateMaxReconnectionAttempts - maximum number of reconnection attemptspublic String getNodesSelectionStrategy()
public void setNodesSelectionStrategy(String nodesSelectionStrategy)
nodesSelectionStrategy - class name of the nodes selection strategy, can be emptypublic String getNodesAllowedTiers()
public void setNodesAllowedTiers(String nodesAllowedTiers)
nodesAllowedTiers - list of allowed tier namespublic String getNodesForbiddenTiers()
public void setNodesForbiddenTiers(String nodesForbiddenTiers)
nodesForbiddenTiers - list of forbidden tier namespublic void setLoadBalancer(LoadBalancer loadBalancer)
loadBalancer - load balancer instancepublic LoadBalancer getLoadBalancer()
protected LoadBalancerConfig getLoadBalancerConfig()
protected String internalGetURL(String user, String password) throws SQLException
internalGetURL in class PicodataBaseDataSourceSQLExceptionpublic String getProperty(String name) throws SQLException
getProperty in class PicodataBaseDataSourceSQLExceptionpublic void setProperty(String name, String value) throws SQLException
setProperty in class PicodataBaseDataSourceSQLExceptionpublic String getDataSourceProperty(PicodataDataSourceProperty property)
public void setDataSourceProperty(PicodataDataSourceProperty property, String value)
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2025 Picodata. All rights reserved.