Skip to content

Commit

Permalink
Fix several issues in recent alarms changes
Browse files Browse the repository at this point in the history
The patch fixes several issues introduced in ff5e042:

- dcache-common imports hikaricp, which means that several components that
  don't make use of databases now pull in database related code (like the srm client).

- Missing @OverRide annotations in AlarmEnabledDataSource

- Redundant shutdown method in AlarmEnabledDataSource (use close)

- Infinite loop in uncaught exception handler (on IOException that isn't an
  out of file descriptor error, the code would loop forever)

- Complex code before kill on fatal JVM error (which in case of OOM may lead to
  another OOM rather than a shutdown)

To fix the HikariCP dependency I had to update to HikariCP 2.0.1.

Target: trunk
Require-notes: no
Require-book: no
Acked-by: Albert Rossi <arossi@fnal.gov>
Patch: https://rb.dcache.org/r/7188/
  • Loading branch information
gbehrmann committed Aug 8, 2014
1 parent e547954 commit 4b10fe5
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion modules/acl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<artifactId>HikariCP-java6</artifactId>
</dependency>
<dependency>
<groupId>org.dcache</groupId>
Expand Down
31 changes: 15 additions & 16 deletions modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dmg.cells.nucleus ;

import com.google.common.base.Throwables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.net.InetAddress;
Expand Down Expand Up @@ -320,27 +321,25 @@ public void uncaughtException(Thread t, Throwable e)
*/
if (e instanceof VirtualMachineError) {
_oomSafetyBuffer = null;
kill();
_log.error(AlarmMarkerFactory.getMarker(Severity.CRITICAL,
"FATAL_JVM_ERROR",
getCellDomainName(),
getCellName()),
"Fatal JVM error", e);
_log.error("Shutting down...");
kill();
"Restarting due to fatal JVM error", e);
return;
}

if (e instanceof IOException) {
Throwable cause = e;
while(cause != null) {
if (cause.toString().contains("Too many open files")) {
_log.error(AlarmMarkerFactory.getMarker(Severity.CRITICAL,
"OUT_OF_FILE_DESCRIPTORS",
getCellDomainName(),
getCellName()),
"Uncaught exception in thread " + t.getName(),
e);
return;
}
Throwable root = Throwables.getRootCause(e);
if (root instanceof FileNotFoundException) {
if (root.getMessage().contains("Too many open files")) {
_log.error(AlarmMarkerFactory.getMarker(Severity.CRITICAL,
"OUT_OF_FILE_DESCRIPTORS",
getCellDomainName(),
getCellName()),
"Uncaught exception in thread " + t.getName(),
e);
return;
}
}

Expand Down
5 changes: 0 additions & 5 deletions modules/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,5 @@
<groupId>org.bouncycastle</groupId>
<artifactId>${bouncycastle.bcprov}</artifactId>
</dependency>

<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*/
package org.dcache.db;

import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
Expand All @@ -76,6 +75,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import org.dcache.alarms.Severity;
import org.dcache.util.NetworkUtils;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* A decorator which allows exception thrown by the connection
* factory to be marked as alarms.
Expand All @@ -93,34 +94,46 @@ public class AlarmEnabledDataSource implements DataSource, Closeable {
private final String url;

/**
* @param serviceName alarms will be identified by a combination of
* @param connectorName alarms will be identified by a combination of
* this name, the connection url and the canonical name of
* this client host.
*/
public AlarmEnabledDataSource(String url,
String connectorName,
DataSource delegate) {
this.connectorName = connectorName;
this.url = url;
this.delegate = delegate;
this.connectorName = checkNotNull(connectorName);
this.url = checkNotNull(url);
this.delegate = checkNotNull(delegate);
}

@Override
public PrintWriter getLogWriter() throws SQLException {
return delegate.getLogWriter();
}

@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(delegate)) {
return (T) delegate;
}
return delegate.unwrap(iface);
}

@Override
public void setLogWriter(PrintWriter out) throws SQLException {
delegate.setLogWriter(out);
}

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface.isInstance(delegate)) {
return true;
}
return delegate.isWrapperFor(iface);
}

@Override
public Connection getConnection() throws SQLException {
try {
return delegate.getConnection();
Expand All @@ -135,10 +148,12 @@ public Connection getConnection() throws SQLException {
}
}

@Override
public void setLoginTimeout(int seconds) throws SQLException {
delegate.setLoginTimeout(seconds);
}

@Override
public Connection getConnection(String username, String password)
throws SQLException {

Expand All @@ -155,33 +170,20 @@ public Connection getConnection(String username, String password)
}
}

@Override
public int getLoginTimeout() throws SQLException {
return delegate.getLoginTimeout();
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return delegate.getParentLogger();
}

public DataSource getDelegate() {
return delegate;
}

@Override
public void close() throws IOException {
if (delegate instanceof HikariDataSource) {
((HikariDataSource) delegate).shutdown();
} else if (delegate instanceof Closeable) {
if (delegate instanceof Closeable) {
((Closeable) delegate).close();
}
}

public void shutdown() {
try {
close();
} catch (IOException t) {
LOGGER.warn("{}: shutdown encountered a problem: {}",
connectorName,
t.getMessage() );
}
}
}
2 changes: 1 addition & 1 deletion modules/dcache-chimera/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<artifactId>HikariCP-java6</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -299,7 +300,11 @@ public void cleanUp()
_broadcastRegistration.unregister();
}
if (_dataSource != null) {
_dataSource.shutdown();
try {
_dataSource.close();
} catch (IOException e) {
_log.debug("Failed to shutdown database connection pool: {}", e.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

<bean id="file-system" class="org.dcache.chimera.JdbcFs" depends-on="liquibase">
<constructor-arg>
<bean class="org.dcache.db.AlarmEnabledDataSource" destroy-method="shutdown">
<bean class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<constructor-arg value="${pnfsmanager.db.url}"/>
<constructor-arg value="JdbcFs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</constructor-arg>
</bean>

<bean id="dataSource" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="shutdown">
<bean id="dataSource" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<constructor-arg value="${nfs.db.url}"/>
<constructor-arg value="DCacheAwareJdbcFs"/>
Expand Down
2 changes: 1 addition & 1 deletion modules/dcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<artifactId>HikariCP-java6</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -181,7 +182,11 @@ public void cleanUp()
{
super.cleanUp();
if (ds != null) {
ds.shutdown();
try {
ds.close();
} catch (IOException e) {
log.debug("Failed to shutdown database connection pool: {}", e.getMessage());
}
}
executor.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</constructor-arg>
</bean>

<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="shutdown">
<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<constructor-arg value="${spacemanager.db.url}"/>
<constructor-arg value="SpaceManager"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
</constructor-arg>
</bean>

<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="shutdown">
<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<constructor-arg value="${srm.db.url}"/>
<constructor-arg value="Srm"/>
Expand Down
2 changes: 1 addition & 1 deletion modules/srm-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<artifactId>HikariCP-java6</artifactId>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>1.3.9</version>
<artifactId>HikariCP-java6</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down

0 comments on commit 4b10fe5

Please sign in to comment.