Exemplo n.º 1
0
  /**
   * 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;
  }
Exemplo n.º 3
0
  /**
   * 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;
  }
Exemplo n.º 4
0
  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();
  }
Exemplo n.º 5
0
 /**
  * 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;
   }
 }
Exemplo n.º 6
0
 // 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();
 }
Exemplo n.º 7
0
  /** @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;
  }
Exemplo n.º 8
0
 @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);
 }
Exemplo n.º 9
0
  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;
  }
Exemplo n.º 10
0
  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);
 }
Exemplo n.º 12
0
  /**
   * 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;
  }
Exemplo n.º 13
0
  /**
   * クラスタリング対応のメソッド実行処理。
   *
   * @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;
  }
Exemplo n.º 14
0
 @Override
 public MasterKeepAliveConnection getKeepAliveMasterService() throws MasterNotRunningException {
   return wrappedConnection.getKeepAliveMasterService();
 }
Exemplo n.º 15
0
 @Override
 public void clearCaches(ServerName sn) {
   wrappedConnection.clearCaches(sn);
 }
Exemplo n.º 16
0
 @Override
 public boolean isDeadServer(ServerName serverName) {
   return wrappedConnection.isDeadServer(serverName);
 }
Exemplo n.º 17
0
 public void announceBackup() {
   for (ClusterConnection conn : cloneClusterConnections()) {
     conn.announceBackup();
   }
 }
Exemplo n.º 18
0
 @Override
 public AsyncProcess getAsyncProcess() {
   return wrappedConnection.getAsyncProcess();
 }
Exemplo n.º 19
0
 @Override
 public NonceGenerator getNonceGenerator() {
   return wrappedConnection.getNonceGenerator();
 }
Exemplo n.º 20
0
 @Override
 public boolean isManaged() {
   return wrappedConnection.isManaged();
 }
Exemplo n.º 21
0
 @Override
 public void abort(String why, Throwable e) {
   wrappedConnection.abort(why, e);
 }
Exemplo n.º 22
0
 @Override
 public HTableInterface getTable(TableName tableName) throws IOException {
   return wrappedConnection.getTable(tableName);
 }
Exemplo n.º 23
0
 @Override
 public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
   return wrappedConnection.getTable(tableName, pool);
 }
Exemplo n.º 24
0
 @Override
 public Configuration getConfiguration() {
   return wrappedConnection.getConfiguration();
 }
Exemplo n.º 25
0
 @Override
 public void close() throws IOException {
   wrappedConnection.close();
 }
Exemplo n.º 26
0
 @Override
 public ServerStatisticTracker getStatisticsTracker() {
   return wrappedConnection.getStatisticsTracker();
 }
Exemplo n.º 27
0
 /** @see java.sql.Statement#close() */
 public void close() throws SQLException {
   clusterCall("close", null, null, true);
   st.close();
   con.remove(this);
 }
Exemplo n.º 28
0
 @Override
 public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf) {
   return wrappedConnection.getNewRpcRetryingCallerFactory(conf);
 }
Exemplo n.º 29
0
 @Override
 public boolean isAborted() {
   return wrappedConnection.isAborted();
 }
Exemplo n.º 30
0
 @Override
 public ClientBackoffPolicy getBackoffPolicy() {
   return wrappedConnection.getBackoffPolicy();
 }