etcd-io / jetcd

etcd java client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cant fetch key value using jetcd version 0.8.2

nazmul-prince opened this issue · comments

Versions

  • etcd: 3.3.25
  • jetcd: 0.8,2
  • java: 17

Describe the bug
I've just installed etcd on my local machine which is ubuntu 22.04. then I have set a key using the following command
etcdctl set mykey "Hello etcd"

Then I have created a simple maven project where i've just added jetcd-core dependency:

    <dependency>
      <groupId>io.etcd</groupId>
      <artifactId>jetcd-core</artifactId>
      <version>0.8.2</version>
    </dependency>

then I have added the following code:

    private static void readKeysFromEtcd() {
        System.out.println("starting reading");
        String etcdEndpoint = "http://localhost:2379";
        ByteSequence key = ByteSequence.from("/mykey".getBytes());

        try (Client client = Client.builder().endpoints(etcdEndpoint).build()) {
            KV kvClient = client.getKVClient();

            // Retrieve the value using CompletableFuture
            CompletableFuture<GetResponse> getFuture = kvClient.get(key);
            GetResponse response = getFuture.exceptionally(e -> {
                System.out.println("shit exception");
                e.printStackTrace();
                return null;
            }).get();

            System.out.println("" + response.getKvs());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

But its giving response.getKvs() = [].

To Reproduce
Just installed the etcd on local machine and then try jetcd with latest version.

Expected behavior
It should just return the value of the corresponding key.

I think the /mykey should be mykey

commented

Have you used the command etcdctl get /mykey to check that the key actually exists?

seems like you are using mykey and not /mykey

If the etcd4j library you are mentioning is https://github.com/jurmous/etcd4j, then it uses the old etcd APIs based on REST, whereas jetcd uses gRPC so if etcd4j works, then there is probably something wrong with your etcd setup.

We have a number of tests you can have a look for some examples https://github.com/etcd-io/jetcd/blob/main/jetcd-core/src/test/java/io/etcd/jetcd/impl/KVTest.java. In case you are still facing an issue, a reproducer in a form of a unit test would be very useful

Have you used the command etcdctl get /mykey to check that the key actually exists?

seems like you are using mykey and not /mykey

tried with both etcdctl get /mykey and etcdctl get mykey both worked.

If the etcd4j library you are mentioning is https://github.com/jurmous/etcd4j, then it uses the old etcd APIs based on REST, whereas jetcd uses gRPC so if etcd4j works, then there is probably something wrong with your etcd setup.

We have a number of tests you can have a look for some examples https://github.com/etcd-io/jetcd/blob/main/jetcd-core/src/test/java/io/etcd/jetcd/impl/KVTest.java. In case you are still facing an issue, a reproducer in a form of a unit test would be very useful

Yeap I'm using the etcd4j library you have mentioned. And which is of course using old etcd rest apis wereas jetcd uses grpc and thats the reason still I wanted to use it in my company's project for better performance. Do you have any suggestion or idea or any link to share for proper etcd setup.
I've installed the etcd in ubuntu using the apt install command, no external settings have been set:
apt install etcd

@lburgazzoli you're right, the problem was in my local etcd settings. installing etcd server with sudo apt install etcd in ubuntu causing this issue, When I installed etcd using the binary then all works. Thanks for giving me the hints.
Another issue, is there any compatibility issue between jetcd and protobuf-java. Because is some of my project which is in spring boot of version 3.0.1 is giving the following error:

io.grpc.StatusRuntimeException: INTERNAL: Failed to frame message
	at io.grpc.Status.asRuntimeException(Status.java:525) ~[grpc-api-1.64.0.jar:1.64.0]
	at io.grpc.internal.MessageFramer.writePayload(MessageFramer.java:157) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.AbstractStream.writeMessage(AbstractStream.java:66) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.ForwardingClientStream.writeMessage(ForwardingClientStream.java:37) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.DelayedStream$6.run(DelayedStream.java:283) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.DelayedStream.drainPendingCalls(DelayedStream.java:182) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.DelayedStream.access$100(DelayedStream.java:44) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.DelayedStream$4.run(DelayedStream.java:148) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.vertx.grpc.VertxChannelBuilder.lambda$null$0(VertxChannelBuilder.java:308) ~[vertx-grpc-4.5.8.jar:4.5.8]
	at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:279) ~[vertx-core-4.5.8.jar:4.5.8]
	at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:261) ~[vertx-core-4.5.8.jar:4.5.8]
	at io.vertx.grpc.VertxChannelBuilder.lambda$build$1(VertxChannelBuilder.java:308) ~[vertx-grpc-4.5.8.jar:4.5.8]
	at io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:315) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.ManagedChannelImpl.updateSubchannelPicker(ManagedChannelImpl.java:849) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.ManagedChannelImpl.access$5100(ManagedChannelImpl.java:124) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.ManagedChannelImpl$LbHelperImpl$1UpdateBalancingState.run(ManagedChannelImpl.java:1435) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:94) ~[grpc-api-1.64.0.jar:1.64.0]
	at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:126) ~[grpc-api-1.64.0.jar:1.64.0]
	at io.grpc.internal.InternalSubchannel$TransportListener.transportReady(InternalSubchannel.java:559) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.netty.ClientTransportLifecycleManager.notifyReady(ClientTransportLifecycleManager.java:52) ~[grpc-netty-1.64.0.jar:1.64.0]
	at io.grpc.netty.NettyClientHandler$FrameListener.onSettingsRead(NettyClientHandler.java:921) ~[grpc-netty-1.64.0.jar:1.64.0]
	at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:515) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$PrefaceFrameListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:735) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onSettingsRead(Http2InboundFrameLogger.java:93) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readSettingsFrame(DefaultHttp2FrameReader.java:532) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:262) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:159) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder.decodeFrame(DefaultHttp2ConnectionDecoder.java:173) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:393) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:250) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:453) ~[netty-codec-http2-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[netty-codec-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[netty-codec-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
	at java.base/java.lang.Thread.run(Thread.java:840) ~[na:na]
Caused by: java.lang.UnsupportedOperationException: This is supposed to be overridden by subclasses.
	at com.google.protobuf.GeneratedMessageV3.getUnknownFields(GeneratedMessageV3.java:302) ~[protobuf-java-3.19.4.jar:na]
	at io.etcd.jetcd.api.RangeRequest.getSerializedSize(RangeRequest.java:669) ~[jetcd-grpc-0.8.2.jar:na]
	at io.grpc.protobuf.lite.ProtoInputStream.available(ProtoInputStream.java:108) ~[grpc-protobuf-lite-1.64.0.jar:1.64.0]
	at io.grpc.internal.MessageFramer.getKnownLength(MessageFramer.java:204) ~[grpc-core-1.64.0.jar:1.64.0]
	at io.grpc.internal.MessageFramer.writePayload(MessageFramer.java:139) ~[grpc-core-1.64.0.jar:1.64.0]
	... 49 common frames omitted

While adding the following dependency resolving it:

		<dependency>
			<groupId>com.google.protobuf</groupId>
			<artifactId>protobuf-java</artifactId>
			<version>4.27.0</version>
		</dependency>

As adding the dependency or excluding teh dependecy of protobuf-java to those dependencies which are using this also resolved this closing thies issue. Thanks all.