api7 / lua-resty-etcd

Nonblocking Lua etcd driver library for OpenResty

Home Page:https://api7.ai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用resty.etcd查询value value值消失

yuqiquan opened this issue · comments

调用readdir方法,打印返回的res.body 发现有的key存在value 有的则没有
但是通过etcdctl 命令他是存在value的 这是为什么

image
image

但是有的key又有value
image

commented

调用readdir方法,打印返回的res.body 发现有的key存在value 有的则没有
但是通过etcdctl 命令他是存在value的 这是为什么

The screenshot you took is not the same key

https://user-images.githubusercontent.com/44921350/196856718-b4b6475e-1024-47ec-b92f-f4a7c2288243.png

这个是我调用readdir函数查询 key为/wo 的返回信息 是没有value的

但是 通过etcdctl get /wo命令查询他是有value的

commented

这个是我调用readdir函数查询 key为/wo 的返回信息 是没有value的

但是 通过etcdctl get /wo命令查询他是有value的

The logs you see are printed by your commonutil.lua, will it be a problem?

Here is the data structure I got from readdir:

{
  body = {
    count = "2",
    header = {
      cluster_id = "14841639068965178418",
      member_id = "10276657743932975437",
      raft_term = "10",
      revision = "27188"
    },
    kvs = { {
        create_revision = "27183",
        key = "/dir",
        mod_revision = "27187",
        value = "abc",
        version = "3"
      }, {
        create_revision = "27184",
        key = "/dir/a",
        mod_revision = "27188",
        value = "abca",
        version = "3"
      } }
  },
  body_reader = <function 1>,
  has_body = true,
  headers = {
    ["Access-Control-Allow-Headers"] = "accept, content-type, authorization",
    ["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PUT, DELETE",
    ["Access-Control-Allow-Origin"] = "*",
    ["Content-Length"] = "341",
    ["Content-Type"] = "application/json",
    Date = "Fri, 21 Oct 2022 03:09:19 GMT",
    ["Grpc-Metadata-Content-Type"] = "application/grpc",
    <metatable> = {
      __index = <function 2>,
      __newindex = <function 3>,
      normalised = {
        ["access-control-allow-headers"] = "Access-Control-Allow-Headers",
        ["access-control-allow-methods"] = "Access-Control-Allow-Methods",
        ["access-control-allow-origin"] = "Access-Control-Allow-Origin",
        ["content-length"] = "Content-Length",
        ["content-type"] = "Content-Type",
        date = "Date",
        ["grpc-metadata-content-type"] = "Grpc-Metadata-Content-Type"
      }
    }
  },
  read_body = <function 4>,
  read_trailers = <function 5>,
  reason = "OK",
  status = 200
}

apache/apisix#8138
我是在apisix环境中调用的这个 我把我遇到的问题复现了一遍

commented

Here's an example:

etcdctl put /foo '"init_dir"'
etcdctl put /foo/bar  '"abcd"'

then use

local data, err = etcd:readdir("/foo")

the kvs of data will be:

    kvs = { {
        create_revision = "27232",
        key = "/foo",
        mod_revision = "27235",
        value = "init_dir",
        version = "2"
      }, {
        create_revision = "27233",
        key = "/foo/bar",
        mod_revision = "27234",
        value = "abcd",
        version = "2"
      } }
  }

why?

Because you use etcdctl to set the kv and use lua-resty-etcd to get the kv. lua-resty-etcd will do the decoding of the value, ref:

kv.key = decode_base64(kv.key)
kv.value = decode_base64(kv.value or "")
kv.value = self.serializer.deserialize(kv.value)

It is recommended to use lua-resty-etcd to read and write etcd. If you must use etcdctl, please make sure it complies with lua-resty-etcd.