如何在cassandra3中强制远程读取?

nnsrf1az  于 2021-06-15  发布在  Cassandra
关注(0)|答案(2)|浏览(320)

我们正试图修改cassandra代码,使其仅执行远程读取(从不在本地读取),以达到推测性重试和请求复制延迟减少技术的性能测试目的。
到目前为止,我们已经修改了src/java/org/apache/cassandra/service/abstractreadexecutor.java,以执行如下操作:

public abstract class AbstractReadExecutor {
  protected int getNonLocalEndpointIndex (Iterable<InetAddress> endpoints) {
    int endpoint_index = 0;

    // iterate thru endpoints and pick non-local one
    boolean found = false;
    for (InetAddress e : endpoints) {
     if (! StorageProxy.canDoLocalRequest(e) ) {
        found = true;
        break;
     }
     endpoint_index++;
    }

    if (!found) {
        endpoint_index = 0;
    }
    return endpoint_index;
   }
}

public static class NeverSpeculatingReadExecutor extends AbstractReadExecutor {
   public void executeAsync() {
         int endpoint_index = getNonLocalEndpointIndex(targetReplicas);
         makeDataRequests(targetReplicas.subList(endpoint_index, endpoint_index+1));

         if (targetReplicas.size() > 1)
             makeDigestRequests(targetReplicas.subList(1, targetReplicas.size()));
         }
    }
}

但是,它不起作用,因为targetreplicas几乎总是只有一个端点(本地端点),用于使用较小的工作负载、5个cassandra节点和3的复制因子。

3duebb1j

3duebb1j1#

如果这只是为了测试,可以将1个节点设置为错误的dc,并对该节点不拥有的内容使用本地查询(驱动程序上的白名单负载平衡策略,以确保请求只转到它)。只需要让它只测试node没有副本的东西。
或者你对测试读取修复中的代理突变感兴趣?

w51jfk4q

w51jfk4q2#

我只能通过添加一个函数“getremotereplicas()”来执行远程读取,该函数在创建readexecutor对象之前/时过滤掉本地节点。然后通常只返回1个节点(非本地节点)。

public static AbstractReadExecutor getReadExecutor(...) {
    ...
    List<InetAddress> remoteReplicas = getRemoteReplicas( allReplicas );
    List<InetAddress> targetReplicas = consistencyLevel.filterForQuery(keyspace, remoteReplicas, repairDecision);
    ...
}

private static List<InetAddress> getRemoteReplicas(List<InetAddress> replicas) {
    logger.debug("ALL REPLICAS: " + replicas.toString());
    List<InetAddress> remote_replicas = new ArrayList<>();

    // iterate thru replicas and pick non-local one
    boolean found = false;
    for (InetAddress r : replicas) {
        if (! StorageProxy.canDoLocalRequest(r) ) {
            remote_replicas.add(r);
            found = true;
        }
    }
    if (!found) {
      return replicas;
    }
    logger.debug("REMOTE REPLICAS: " + remote_replicas.toString());
    return remote_replicas;
}

在src/java/org/apache/cassandra/service/abstractreadexecutor.java中

相关问题