private void handleGetConnectionException(final CachedDataSource source, Throwable exc) { try { if(!source.canTakeOffLine()) { LOGGER.error("Could not switch due to blocking"); return; } boolean removed = dsQueue.remove(source); if(!broken.contains(source)) { if(broken.add(source)) { LOGGER.warn("DB Recovery: DataSource <" + source.getDbConnectionName() + "> put in the recovery mode. Reason : " + exc.getMessage()); } else { LOGGER.warn("Error putting DataSource <" +source.getDbConnectionName()+ "> in recovery mode."); } } else { LOGGER.info("DB Recovery: DataSource <" + source.getDbConnectionName() + "> already in recovery queue"); } if(removed) { if(!dsQueue.isEmpty()) { LOGGER.warn("DB DataSource <" + dsQueue.first().getDbConnectionName() + "> became active"); } } } catch (Exception e) { LOGGER.error("", e); } }
public CachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException { ds = configure(jdbcElem); if ("org.apache.derby.jdbc.EmbeddedDriver".equals(jdbcElem.getDriverName())) { isDerby = true; } monitor = new SQLExecutionMonitor(this); }
public CachedRowSet getData(String statement, List<Object> arguments) throws SQLException { TestObject testObject = monitor.registerRequest(); try (Connection connection = this.getConnection()) { if (connection == null) { throw new SQLException("Connection invalid"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection); } return executePreparedStatement(connection, statement, arguments, true); } finally { monitor.deregisterRequest(testObject); } }
public boolean writeData(String statement, List<Object> arguments) throws SQLException { TestObject testObject = monitor.registerRequest(); try (Connection connection = this.getConnection()) { if (connection == null) { throw new SQLException("Connection invalid"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection); } return executeUpdatePreparedStatement(connection, statement, arguments, true); } finally { monitor.deregisterRequest(testObject); } }
continue; semaphore.add(cachedDS[i]); cachedDS[i].setInterval(monitoringInterval); cachedDS[i].setInitialDelay(monitoringInitialDelay); cachedDS[i].setExpectedCompletionTime(expectedCompletionTime); cachedDS[i].setUnprocessedFailoverThreshold(unprocessedFailoverThreshold); cachedDS[i].addObserver(DBResourceManager.this);
long time = System.currentTimeMillis(); try { if(!active.isFabric()) { if(this.dsQueue.size() > 1 && active.isSlave()) { CachedDataSource master = findMaster(); if(master != null) { return active.getData(statement, arguments); if(message == null) message = exc.getClass().getName(); LOGGER.error("Generated alarm: "+active.getDbConnectionName()+" - "+message); if(exc instanceof SQLException) throw (SQLException)exc; if(LOGGER.isDebugEnabled()){ time = System.currentTimeMillis() - time; LOGGER.debug(">> getData : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
if(!active.isFabric()) { if(this.dsQueue.size() > 1 && active.isSlave()) { CachedDataSource master = findMaster(); if(master != null) { return active.getConnection(username, password); } catch(Throwable exc){ if(recoveryMode){
try (Connection conn = this.getConnection(); Statement stmt = conn.createStatement()) { Boolean readOnly; String hostname; LOGGER.debug(DATA_SOURCE_CONNECT_SUCCESS,getDbConnectionName(),hostname,readOnly); LOGGER.error(DATA_SOURCE_CONNECT_FAILURE, this.getDbConnectionName(),exc.getMessage()); } else { LOGGER.info(DATA_SOURCE_CONNECT_FAILURE, this.getDbConnectionName(),exc.getMessage());
protected boolean isSlave() throws PoolExhaustedException { // If using Apache derby, just return false if (isDerby) { return false; } CachedRowSet rs; boolean isSlave; String hostname = "UNDETERMINED"; try { boolean localSlave = true; rs = this.getData("SELECT @@global.read_only, @@global.hostname", new ArrayList<>()); while (rs.next()) { localSlave = rs.getBoolean(1); hostname = rs.getString(2); } isSlave = localSlave; } catch (PoolExhaustedException peexc) { throw peexc; } catch (Exception e) { LOGGER.error("", e); isSlave = true; } if (isSlave) { LOGGER.debug("SQL SLAVE : {} on server {}, pool {}", connectionName, hostname, getAvailableConnections()); } else { LOGGER.debug("SQL MASTER : {} on server {}, pool {}", connectionName, hostname, getAvailableConnections()); } return isSlave; }
if (resetConnectionPool(brokenSource)) { broken.remove(brokenSource); brokenSource.blockImmediateOffLine(); dsQueue.add(brokenSource); LOGGER.info("DataSource <" + brokenSource.getDbConnectionName() + "> recovered.");
public void cleanUp() { for(Iterator<CachedDataSource> it=dsQueue.iterator();it.hasNext();){ CachedDataSource cds = it.next(); it.remove(); cds.cleanUp(); } try { this.terminating = true; if(broken != null) { try { broken.add( new TerminatingCachedDataSource(new TerminatingConfiguration())); } catch(Exception exc){ LOGGER.error("Waiting for Worker to stop", exc); } } worker.join(terminationTimeOut); LOGGER.info("DBResourceManager.RecoveryMgr <"+worker.toString() +"> termination was successful: " + worker.getState()); } catch(Exception exc){ LOGGER.error("Waiting for Worker thread to terminate ", exc); } }
public boolean writeData(String statement, List<String> arguments) throws Throwable { ArrayList<Object> newList = new ArrayList<>(); if (arguments != null && !arguments.isEmpty()) { newList.addAll(arguments); } resetInactivityTimer(); return dataSource.executeUpdatePreparedStatement(connection, statement, newList, false); }
public CachedRowSet getData(String statement, List<String> arguments) throws Throwable { ArrayList<Object> newList = new ArrayList<>(); if (arguments != null && !arguments.isEmpty()) { newList.addAll(arguments); } resetInactivityTimer(); return dataSource.executePreparedStatement(connection, statement, newList, false); }
if(!active.isFabric()) { if(this.dsQueue.size() > 1 && active.isSlave()) { CachedDataSource master = findMaster(); if(master != null) { return active.getData(statement, arguments); } catch(SQLDataException | SQLSyntaxErrorException | SQLIntegrityConstraintViolationException exc){ throw exc; LOGGER.error("Generated alarm: "+active.getDbConnectionName(), exc); handleGetConnectionException(active, exc); } finally { if(LOGGER.isDebugEnabled()){ time = System.currentTimeMillis() - time; LOGGER.debug("getData processing time : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
active = dsQueue.first(); if(!active.isFabric()) { if(this.dsQueue.size() > 1 && active.isSlave()) { CachedDataSource master = findMaster(); if(master != null) { return new DBLibConnection(active.getConnection(), active); } catch(javax.sql.rowset.spi.SyncFactoryException exc){ LOGGER.debug("Free memory (bytes): " + Runtime.getRuntime().freeMemory());
@Override public void cleanUp() { DataSource dataSource = (DataSource) ds; dataSource.getPool().purge(); dataSource.close(true); super.cleanUp(); }