gpt4 book ai didi

etcd - 尝试按前缀删除所有键并重新放置时,txn 请求中给出的重复键

转载 作者:行者123 更新时间:2023-12-04 08:54:16 28 4
gpt4 key购买 nike

正在尝试使用 coreos/jetcd 用于更新 etcd 中的 haproxy 设置来自Java代码。

我想要实现的是:

  • 删除单个主机的所有端点
  • 添加给定主机的更新数据

  • 我想通过前缀删除所有键,并将实际数据作为原子操作放入 etcd。

    这就是我尝试使用 etcd 事务的原因。我的代码是:
    Op.DeleteOp deleteOp = Op.delete(
    fromString(prefix),
    DeleteOption.newBuilder().withPrefix(fromString(prefix)).build()
    );
    Txn tx = kvClient.txn().Else(deleteOp);
    newKvs.forEach((k,v) -> {
    tx.Else(Op.put(fromString(k), fromString(v), DEFAULT));
    });
    try {
    tx.commit().get();
    } catch (InterruptedException | ExecutionException e) {
    log.error("ETCD transaction failed", e);
    throw new RuntimeException(e);
    }

    使用 ETCD v3 API (etcd v3.2.9)。 KVstore 最初是空的,我想添加 3 条记录。 prefix值(value)是:
    /proxy-service/hosts/example.com

    kvs是一张 map :
    "/proxy-service/hosts/example.com/FTP/0" -> "localhost:10021"
    "/proxy-service/hosts/example.com/HTTPS/0" -> "localhost:10443"
    "/proxy-service/hosts/example.com/HTTP/0" -> "localhost:10080"
    commit().get() 上发生异常符合以下根本原因:
    Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: etcdserver: duplicate key given in txn request
    at io.grpc.Status.asRuntimeException(Status.java:526)
    at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:427)
    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
    at com.coreos.jetcd.internal.impl.ClientConnectionManager$AuthTokenInterceptor$1$1.onClose(ClientConnectionManager.java:267)
    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:419)
    at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:60)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:493)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$500(ClientCallImpl.java:422)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:525)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:102)
    ... 3 more

    我做错了什么,我还能如何将多个 etcd 更改作为原子操作完成?

    最佳答案

    看起来删除一个键然后为同一个键添加新值的操作不能在同一个txn中。 .根据The etcd APIv3 documentation :

    Txn processes multiple requests in a single transaction. A txn request increments the revision of the key-value store and generates events with the same revision for every completed request. It is not allowed to modify the same key several times within one txn.

    关于etcd - 尝试按前缀删除所有键并重新放置时,txn 请求中给出的重复键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47078317/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com