2012-04-03 39 views
5

每當我使用任何赫克託API函數來訪問我的卡桑德拉的數據庫,我得到一個異常:問題赫克託API和卡桑德拉數據庫:記錄異常

me.prettyprint.hector.api.exceptions.HectorException:所有主機池下調。重試負擔推到客戶端。

我的服務器確實有在後臺運行的Cassandra數據庫。

我閱讀了例外情況,它實際上沒有記錄。看起來例外是由於連接問題。

我該如何解決?

回答

3

如果Hector客戶端無法連接到Cassandra,將會出現該錯誤。可能有多種原因需要嘗試:

  • 確保代碼(ip/host/port)中的連接屬性配置正確。
  • 請確保您可以使用cassandra-cli遠程連接到它 - 這可能是一個網絡問題。
  • 嘗試在此發佈您的連接代碼 - 可能在那裏存在問題。
0

由於網絡連接問題,我得到這個錯誤,但重試幾次通常會修復它。下面是我用來試赫克託API函數的代碼:

/** An interface where inside the execute() method I call Hector */ 
public interface Retriable<T> { 
    T execute(); 
} 

/** 
* Executes operation and retries N times in case of an exception 
* @param retriable 
* @param maxRetries 
* @param <T> 
* @return 
*/ 
public static <T> T executeWithRetry(Retriable<T> retriable, int maxRetries) { 
    T result; 
    int retries = 0; 
    long sleepSec = 1; 
    // retry in case of an exception: 
    while (true) { 
     try { 
      result = retriable.execute(); 
      break; 
     } catch (Exception e) { 
      if (retries == maxRetries) { 
       LOG.error("Exception occurred. Reached max retries.", e); 
       throw e; 
      } 
      retries++; 
      LOG.error(String.format("Exception occurred. Retrying in %d seconds - #%d", sleepSec, retries), e); 
      try { 
       Thread.sleep(sleepSec * 1000); 
       // increase sleepSec exponentially: 
       sleepSec *= 2; 
      } catch (InterruptedException e1) { 
       e1.printStackTrace(); 
      } 
     } 
    } 
    return result; 
} 

,並就如何使用它的一個例子:

ColumnFamilyResult<String, String> columns = executeWithRetry(new Retriable<ColumnFamilyResult<String, String>>() { 
     @Override 
     public ColumnFamilyResult<String, String> execute() { 
      return template.queryColumns(row.getKey()); 
     } 
    }); 
0

我與卡桑德拉單位得到同樣的錯誤2.0.2.1降級版本到2.0.2.0解決了這個問題。這很奇怪,但我用2.0.2.0現在有一些額外的SBT依賴

  "com.datastax.cassandra" % "cassandra-driver-core" % "2.0.1", 
     "org.cassandraunit" % "cassandra-unit" % "2.0.2.0" withSources() withJavadoc()