Definition
JDBC_PING uses a database to discover initial members. It was initially designed as an alternative to S3_PING, as some cloud deployed applications need access to a shared database anyway, so they could reuse credentials to access the database rather than deal with an additional service and relative authentication tokens. It uses a single table, so if that's not annoying you could share an existing Datasource with your application.
Connection configuration
Either provide all needed connection properties, or specify a JNDI name to lookup a Datasource in the environment.
Via connection properties:
Name | Description | Example |
---|---|---|
connection_url | JDBC connection URL to use | jdbc:mysql://localhost/jgroups |
connection_username | username for the JDBC connection | myapp_username |
connection_password | password for the JDBC connection | myapp_password |
connection_driver | Fully qualified classname of the JDBC Driver to use | com.mysql.jdbc.Driver |
Via JNDI lookup:
Name | Description | Example |
---|---|---|
datasource_jndi_name | JNDI name of the Datasource to lookup | java:JGroups-testing-ds |
It's considered an illegal configuration to configure both JNDI related properties and plain connection related properties. It will attempt to create the needed table automatically.
Customize table definition and used SQL statements
The following properties permit you to customize all SQL related aspects, from changing the table create statement being used, disable automatic table creation, and the CRUD operations.
Name | Description |
---|---|
initialize_sql | SQL fragment used to create the table. Set it to blank to prevent table creation |
insert_single_sql | SQL statement used to insert a new record |
delete_single_sql | SQL statement used to delete a record |
select_all_pingdata_sql | SQL query to retrieve addresses |
Update statements don't need to be atomic, and so they use a delete followed by an insert.
The default statements are:
CREATE TABLE JGROUPSPING ( own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, ping_data varbinary(5000) DEFAULT NULL, PRIMARY KEY (own_addr, cluster_name) )
INSERT INTO JGROUPSPING (own_addr, cluster_name, ping_data) values (?, ?, ?)
DELETE FROM JGROUPSPING WHERE own_addr=? AND cluster_name=?
SELECT ping_data FROM JGROUPSPING WHERE cluster_name=?
Where own_addr and cluster_name are treated as String, while ping_data is a byte array. Keep consistency in the parameter order and choose compatible types appropriate to your database of choice.
Other configuration properties
Name | Description | Default |
---|---|---|
interval | Interval (in milliseconds) at which the own Address is (re)written. 0 disables it. | 60000 |
The own Address is initially written at startup and deleted at shutdown, but it might be useful to have it rewrite it periodically by using the interval property.
Tested configurations
While the default SQL fragments use standard SQL in hope that they will be fine for you without needing reconfiguration, often specific databases require, or perform better, using different statements to take advantage of proprietary dialects.
MySQL recommended options
initialize_sql | CREATE TABLE IF NOT EXISTS JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, ping_data varbinary(5000) DEFAULT NULL, PRIMARY KEY (own_addr, cluster_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
Oracle tested options
Configuration xml of JDBC_PING
<JDBC_PING datasource_jndi_name="java:/comp/env/sqlPool"
initialize_sql="CREATE TABLE JGROUPSPING (
own_addr varchar(200) NOT NULL,
bind_addr varchar(200) NOT NULL,
created timestamp NOT NULL,
cluster_name varchar(200) NOT NULL,
ping_data blob,
constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name)
)"
insert_single_sql="INSERT INTO JGROUPSPING (own_addr, bind_addr, created, cluster_name, ping_data) values (?,
'${jgroups.tcp.address:127.0.0.1}',sysdate, ?, ?)"
delete_single_sql="DELETE FROM JGROUPSPING WHERE own_addr=? AND cluster_name=?"
select_all_pingdata_sql="SELECT ping_data FROM JGROUPSPING WHERE cluster_name=?"
/>
Additional attributes:
- BIND_ADDR is ip address to easily recognize which machine runs the node, jgroups.tcp.address must be defined java property
- CREATED helps find which node joined later - detect possible partitioning in monitoring tools outside of running cluster ...
Comments