2012-04-03 2 views
5

, 나는 예외가 아래로 표시했습니다. 클라이언트에게 재시도 부담이 가해졌습니다.문제 :</p> <p>me.prettyprint.hector.api.exceptions.HectorException : 모든 호스트 풀 내 카산드라 데이터베이스에 액세스하는 모든 헥터 API 함수를 사용할 때마다 문서화되지 않은 예외

내 서버에는 백그라운드에서 실행중인 Cassandra 데이터베이스가 있습니다.

예외에 대해 읽었는데 실제로 문서화되지 않았습니다. 예외는 연결 문제로 인한 것 같습니다.

어떻게 수정합니까?

답변

3

Hector 클라이언트가 Cassandra에 연결할 수없는 경우 오류가 발생합니다. 이 문제를 시도하는 데는 여러 가지 이유가있을 수 있습니다.

  • 코드 (ip/host/port)의 연결 속성이 올바르게 구성되었는지 확인하십시오.
  • cassandra-cli로 원격으로 연결할 수 있는지 확인하십시오. 네트워크 문제 일 수 있습니다.
  • 여기에 연결 코드를 게시 해보세요. 문제가있을 수 있습니다.
0

네트워크 연결 문제로 인해이 오류가 임의로 발생하지만 일반적으로 여러 번 다시 시도하면이 오류가 해결됩니다.

/** 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; 
} 

그리고 그것을 사용하는 방법에 대한 예 : : 여기 헥터 API 함수를 재 시도하는 데 사용하는 코드입니다

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으로 다운 그레이드하면 문제가 해결되었습니다. 그게 이상하다하지만 몇 가지 추가 SBT 종속성 지금 2.0.2.0을 사용

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