Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #35 from Sanne/JGRP-1440

JGRP-1440 JDBC_PING java.sql.SQLException: ORA-00001: unique constraint ...
  • Loading branch information...
commit 9d1d01739e4d6a46a682d962196b8230302b9328 2 parents 8a23979 + 2889086
@belaban authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 src/org/jgroups/protocols/JDBC_PING.java
View
19 src/org/jgroups/protocols/JDBC_PING.java
@@ -2,7 +2,6 @@
import org.jgroups.Address;
import org.jgroups.annotations.Property;
-import org.jgroups.util.Util;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -122,8 +121,9 @@ protected void attemptSchemaInitialization() {
log.debug("Could not execute initialize_sql statement; not necessarily an error.", e);
}
else {
- //avoid printing out the stacktrace
- log.debug("Could not execute initialize_sql statement; not necessarily an error. Set to debug logging level for details.");
+ //avoid printing out the stacktrace when not debugging
+ log.info("Could not execute initialize_sql statement; not necessarily an error, we always attempt to create the schema. " +
+ "To suppress this message, set initialize_sql to an empty value. Cause:" + e.getMessage());
}
}
} finally {
@@ -227,8 +227,15 @@ protected void remove(String clustername, Address addr) {
}
}
+ //It's possible that multiple threads in the same cluster node invoke this concurrently;
+ //Since delete and insert operations are not atomic
+ //(and there is no SQL standard way to do this without introducing a transaction)
+ //we need the synchronization or risk a duplicate insertion on same primary key.
+ //This synchronization should not be a performance problem as this is just a Discovery protocol.
+ //Many SQL dialects have some "insert or update" expression, but that would need
+ //additional configuration and testing on each database. See JGRP-1440
@Override
- protected void writeToFile(PingData data, String clustername) {
+ protected synchronized void writeToFile(PingData data, String clustername) {
final String ownAddress = addressAsString(data.getAddress());
final Connection connection = getConnection();
if (connection != null) {
@@ -246,7 +253,7 @@ protected void writeToFile(PingData data, String clustername) {
}
}
- protected void insert(Connection connection, PingData data, String clustername, String address) throws SQLException {
+ protected synchronized void insert(Connection connection, PingData data, String clustername, String address) throws SQLException {
final byte[] serializedPingData = serializeWithoutView(data);
PreparedStatement ps = connection.prepareStatement(insert_single_sql);
try {
@@ -261,7 +268,7 @@ protected void insert(Connection connection, PingData data, String clustername,
}
}
- protected void delete(Connection connection, String clustername, String addressToDelete) throws SQLException {
+ protected synchronized void delete(Connection connection, String clustername, String addressToDelete) throws SQLException {
PreparedStatement ps = connection.prepareStatement(delete_single_sql);
try {
ps.setString(1, addressToDelete);
Please sign in to comment.
Something went wrong with that request. Please try again.