/** * Activates several cluster services. Used by backups on failover. * * @throws Exception */ public synchronized void activate() throws Exception { if (state != State.STARTED && state != State.DEPLOYED) return; if (backup) { backup = false; deployConfiguredBridges(); for (BroadcastGroup broadcastGroup : broadcastGroups.values()) { try { broadcastGroup.start(); } catch (Exception e) { HornetQServerLogger.LOGGER.unableToStartBroadcastGroup(e, broadcastGroup.getName()); } } for (ClusterConnection clusterConnection : clusterConnections.values()) { try { clusterConnection.activate(); } catch (Exception e) { HornetQServerLogger.LOGGER.unableToStartClusterConnection(e, clusterConnection.getName()); } } for (Bridge bridge : bridges.values()) { try { bridge.start(); } catch (Exception e) { HornetQServerLogger.LOGGER.unableToStartBridge(e, bridge.getName()); } } } }
static RegionLocations getRegionLocations( boolean useCache, int replicaId, ClusterConnection cConnection, TableName tableName, byte[] row) throws RetriesExhaustedException, DoNotRetryIOException, InterruptedIOException { RegionLocations rl; try { if (!useCache) { rl = cConnection.relocateRegion(tableName, row, replicaId); } else { rl = cConnection.locateRegion(tableName, row, useCache, true, replicaId); } } catch (DoNotRetryIOException e) { throw e; } catch (RetriesExhaustedException e) { throw e; } catch (InterruptedIOException e) { throw e; } catch (IOException e) { throw new RetriesExhaustedException("Can't get the location", e); } if (rl == null) { throw new RetriesExhaustedException("Can't get the locations"); } return rl; }
/** * The put request will be buffered by its corresponding buffer queue. And the put request will be * retried before dropping the request. Return false if the queue is already full. * * @return true if the request can be accepted by its corresponding buffer queue. */ public boolean put(final TableName tableName, final Put put, int maxAttempts) { if (maxAttempts <= 0) { return false; } try { HTable.validatePut(put, maxKeyValueSize); // Allow mocking to get at the connection, but don't expose the connection to users. ClusterConnection conn = (ClusterConnection) getConnection(); // AsyncProcess in the FlushWorker should take care of refreshing the location cache // as necessary. We shouldn't have to do that here. HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), false); if (loc != null) { // Add the put pair into its corresponding queue. LinkedBlockingQueue<PutStatus> queue = getQueue(loc); // Generate a MultiPutStatus object and offer it into the queue PutStatus s = new PutStatus(loc.getRegionInfo(), put, maxAttempts); return queue.offer(s); } } catch (IOException e) { LOG.debug("Cannot process the put " + put, e); } return false; }
public String describe() { StringWriter str = new StringWriter(); PrintWriter out = new PrintWriter(str); out.println("Information on " + this); out.println("*******************************************************"); for (ClusterConnection conn : cloneClusterConnections()) { out.println(conn.describe()); } out.println("*******************************************************"); return str.toString(); }
/** * Return the default ClusterConnection to be used case it's not defined by the acceptor * * @return default connection */ public ClusterConnection getDefaultConnection(TransportConfiguration acceptorConfig) { if (acceptorConfig == null) { // if the parameter is null, we just return whatever is defined on defaultClusterConnection return defaultClusterConnection; } else if (defaultClusterConnection != null && defaultClusterConnection.getConnector().isEquivalent(acceptorConfig)) { return defaultClusterConnection; } else { for (ClusterConnection conn : cloneClusterConnections()) { if (conn.getConnector().isEquivalent(acceptorConfig)) { return conn; } } return null; } }
// for testing public void clear() { for (Bridge bridge : bridges.values()) { try { bridge.stop(); } catch (Exception e) { HornetQServerLogger.LOGGER.warn(e.getMessage(), e); } } bridges.clear(); for (ClusterConnection clusterConnection : clusterConnections.values()) { try { clusterConnection.stop(); } catch (Exception e) { e.printStackTrace(); } } clearClusterConnections(); }
/** @see java.sql.Statement#executeQuery(java.lang.String) */ public ResultSet getAnotherResultSet() throws SQLException { logger.debug("Redo st.executeQuery and get ResultSet.\n" + sql); // resultSet内で障害を検知したので、再度コネクションを張り直す。 con.notifyError(this); // エラーを通知。ここでstは新しいものになっているはず。 ResultSet rs = st.executeQuery(sql); return rs; }
@Override public <R> void processBatchCallback( List<? extends Row> list, byte[] tableName, ExecutorService pool, Object[] results, Callback<R> callback) throws IOException, InterruptedException { wrappedConnection.processBatchCallback(list, tableName, pool, results, callback); }
public synchronized void start() throws Exception { if (state == State.STARTED) { return; } for (BroadcastGroup group : broadcastGroups.values()) { if (!backup) { group.start(); } } for (ClusterConnection conn : clusterConnections.values()) { conn.start(); if (backup && configuration.isSharedStore()) { conn.informTopology(); conn.announceBackup(); } } deployConfiguredBridges(); state = State.STARTED; }
public void stop() throws Exception { synchronized (this) { if (state == State.STOPPED || state == State.STOPPING) { return; } state = State.STOPPING; for (BroadcastGroup group : broadcastGroups.values()) { group.stop(); managementService.unregisterBroadcastGroup(group.getName()); } broadcastGroups.clear(); for (ClusterConnection clusterConnection : clusterConnections.values()) { clusterConnection.stop(); managementService.unregisterCluster(clusterConnection.getName().toString()); } for (Bridge bridge : bridges.values()) { bridge.stop(); managementService.unregisterBridge(bridge.getName().toString()); } bridges.clear(); } for (ServerLocatorInternal clusterLocator : clusterLocators) { try { clusterLocator.close(); } catch (Exception e) { HornetQServerLogger.LOGGER.errorClosingServerLocator(e, clusterLocator); } } clusterLocators.clear(); state = State.STOPPED; clearClusterConnections(); }
public RpcRetryingCallerWithReadReplicas( RpcControllerFactory rpcControllerFactory, TableName tableName, ClusterConnection cConnection, final Get get, ExecutorService pool, int retries, int callTimeout, int timeBeforeReplicas) { this.rpcControllerFactory = rpcControllerFactory; this.tableName = tableName; this.cConnection = cConnection; this.conf = cConnection.getConfiguration(); this.get = get; this.pool = pool; this.retries = retries; this.callTimeout = callTimeout; this.timeBeforeReplicas = timeBeforeReplicas; this.rpcRetryingCallerFactory = new RpcRetryingCallerFactory(conf); }
/** * The put request will be buffered by its corresponding buffer queue. And the put request will be * retried before dropping the request. Return false if the queue is already full. * * @return true if the request can be accepted by its corresponding buffer queue. */ public boolean put(final TableName tableName, final Put put, int retry) { if (retry <= 0) { return false; } try { HTable.validatePut(put, maxKeyValueSize); HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), false); if (loc != null) { // Add the put pair into its corresponding queue. LinkedBlockingQueue<PutStatus> queue = getQueue(loc); // Generate a MultiPutStatus object and offer it into the queue PutStatus s = new PutStatus(loc.getRegionInfo(), put, retry); return queue.offer(s); } } catch (IOException e) { LOG.debug("Cannot process the put " + put, e); } return false; }
/** * クラスタリング対応のメソッド実行処理。 * * @param methodName * @param args * @return * @throws SQLException */ private Object clusterCall( String methodName, Object[] args, Class<?>[] parameterTypes, boolean saveMethod) throws SQLException { Object result = null; CalledMethod calledMethod = new CalledMethod(methodName, args, parameterTypes); logger.debug(calledMethod.toString()); try { result = calledMethod.invoke(st); } catch (Exception e) { logger.warn(MSG_WARN_SWITCH_DB, e); // try { st.close(); } catch (SQLException se) {} con.notifyError(this); // エラーを通知。ここでstは新しいものになっているはず。 try { // 再度実行。ここでもさらにエラーがでるならSQLExceptionにラップする。 result = calledMethod.invoke(st); } catch (InvocationTargetException e2) { // 例外がSQLExceptionならそのままthrow Throwable t = e2.getTargetException(); if (t instanceof SQLException) { throw (SQLException) t; } // それ以外ならwrapしてthrow SQLException sqle = new SQLException(); sqle.initCause(e2.getTargetException()); throw sqle; } catch (Exception e2) { SQLException sqle = new SQLException(); sqle.initCause(e2); throw sqle; } } if (saveMethod) { methodList.add(calledMethod); } return result; }
@Override public MasterKeepAliveConnection getKeepAliveMasterService() throws MasterNotRunningException { return wrappedConnection.getKeepAliveMasterService(); }
@Override public void clearCaches(ServerName sn) { wrappedConnection.clearCaches(sn); }
@Override public boolean isDeadServer(ServerName serverName) { return wrappedConnection.isDeadServer(serverName); }
public void announceBackup() { for (ClusterConnection conn : cloneClusterConnections()) { conn.announceBackup(); } }
@Override public AsyncProcess getAsyncProcess() { return wrappedConnection.getAsyncProcess(); }
@Override public NonceGenerator getNonceGenerator() { return wrappedConnection.getNonceGenerator(); }
@Override public boolean isManaged() { return wrappedConnection.isManaged(); }
@Override public void abort(String why, Throwable e) { wrappedConnection.abort(why, e); }
@Override public HTableInterface getTable(TableName tableName) throws IOException { return wrappedConnection.getTable(tableName); }
@Override public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException { return wrappedConnection.getTable(tableName, pool); }
@Override public Configuration getConfiguration() { return wrappedConnection.getConfiguration(); }
@Override public void close() throws IOException { wrappedConnection.close(); }
@Override public ServerStatisticTracker getStatisticsTracker() { return wrappedConnection.getStatisticsTracker(); }
/** @see java.sql.Statement#close() */ public void close() throws SQLException { clusterCall("close", null, null, true); st.close(); con.remove(this); }
@Override public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf) { return wrappedConnection.getNewRpcRetryingCallerFactory(conf); }
@Override public boolean isAborted() { return wrappedConnection.isAborted(); }
@Override public ClientBackoffPolicy getBackoffPolicy() { return wrappedConnection.getBackoffPolicy(); }