gy09535 opened a new issue #3389:
URL: https://github.com/apache/apisix/issues/3389


   ### Issue description
   I  add other apisix instance ,  when it init, I can  not get data from etcd.
   But the new config can sync when apisix instance is started,  the etcd is  
cluster, I add some logs :
   ```
   2021/01/21 08:39:24 [warn] 30#30: *182 [lua] config_etcd.lua:191: 
sync_data(): init key: /apisix/upstreams from etcd, res: 
{"user":"apisix","timeout":30,"password":"wosaiapisix","http_host":["http:\/\/172.16.11.152:2379","http:\/\/172.16.11.154:2379","http:\/\/172.16.11.153:2379"],"protocol":"v3","api_prefix":"\/v3","ssl_verify":false,"tls":{"verify":false},"ttl":-1}
 etcd config: 
{"user":"apisix","timeout":30,"password":"wosaiapisix","http_host":["http:\/\/172.16.11.152:2379","http:\/\/172.16.11.154:2379","http:\/\/172.16.11.153:2379"],"protocol":"v3","api_prefix":"\/v3","ssl_verify":false,"tls":{"verify":false},"ttl":-1},
 context: ngx.timer
   2021/01/21 08:39:24 [warn] 30#30: *182 [lua] config_etcd.lua:294: 
sync_data(): load key: /apisix/upstreams data: {}, context: ngx.timer
   ```
   
   But I can  get  data use "etcdctl"
   ```
    env ETCDCTL_API=3 etcdctl --endpoints http://172.16.11.152:2379 
--user=apisix:xxxxxxxx  get --from-key /apisix/upstreams
   
   
{"id":"334312499069321769","create_time":1608795377,"update_time":1609140334,"nodes":[{"host":"xxxxx","port":80,"weight":1}],"timeout":{"connect":6000,"read":6000,"send":6000},"type":"roundrobin","name":"backend-service"}
   /apisix/upstreams/334338203324514857
   
{"id":"334338203324514857","create_time":1608810698,"update_time":1609229283,"nodes":[{"host":"dashboard.sqb.svc.cluster.local","port":80,"weight":1}],"timeout":{"connect":10000,"read":10000,"send":10000},"type":"roundrobin","name":"ft-zeus-dashboard"}
   ```
   log location is 
   
   ```
   local function sync_data(self)
       if not self.key then
           return nil, "missing 'key' arguments"
       end
   
       if self.need_reload then
           local res, err = readdir(self.etcd_cli, self.key)
           if not res then
               return false, err
           end
   
           local dir_res, headers = res.body.node or {}, res.headers
           log.warn("init key: ", self.key, " from etcd, res: ",
                     json.delay_encode(dir_res)," etcd config: 
",json.delay_encode(self.etcd_conf))
           if not dir_res then
               return false, err
           end
   
           if self.values then
               for i, val in ipairs(self.values) do
                   if val and val.clean_handlers then
                       for _, clean_handler in ipairs(val.clean_handlers) do
                           clean_handler(val)
                       end
                       val.clean_handlers = nil
                   end
               end
   
               self.values = nil
               self.values_hash = nil
           end
   
           local changed = false
   
           if self.single_item then
               self.values = new_tab(1, 0)
               self.values_hash = new_tab(0, 1)
   
               local item = dir_res
               local data_valid = item.value ~= nil
   
               if data_valid and self.item_schema then
                   data_valid, err = check_schema(self.item_schema, item.value)
                   if not data_valid then
                       log.error("failed to check item data of [", self.key,
                                 "] err:", err, " ,val: ", 
json.encode(item.value))
                   end
               end
   
               if data_valid then
                   changed = true
                   insert_tab(self.values, item)
                   self.values_hash[self.key] = #self.values
   
                   item.clean_handlers = {}
   
                   if self.filter then
                       self.filter(item)
                   end
               end
   
               self:upgrade_version(item.modifiedIndex)
   
           else
               if not dir_res.nodes then
                   dir_res.nodes = {}
               end
   
               self.values = new_tab(#dir_res.nodes, 0)
               self.values_hash = new_tab(0, #dir_res.nodes)
   
               for _, item in ipairs(dir_res.nodes) do
                   local key = short_key(self, item.key)
                   local data_valid = true
                   if type(item.value) ~= "table" then
                       data_valid = false
                       log.error("invalid item data of [", self.key .. "/" .. 
key,
                                 "], val: ", item.value,
                                 ", it shoud be a object")
                   end
   
                   if data_valid and self.item_schema then
                       data_valid, err = check_schema(self.item_schema, 
item.value)
                       if not data_valid then
                           log.error("failed to check item data of [", self.key,
                                     "] err:", err, " ,val: ", 
json.encode(item.value))
                       end
                   end
   
                   if data_valid then
                       changed = true
                       insert_tab(self.values, item)
                       self.values_hash[key] = #self.values
   
                       item.value.id = key
                       item.clean_handlers = {}
   
                       if self.filter then
                           self.filter(item)
                       end
                   end
   
                   self:upgrade_version(item.modifiedIndex)
               end
           end
   
           if headers then
               self:upgrade_version(headers["X-Etcd-Index"])
           end
   
           if changed then
               self.conf_version = self.conf_version + 1
           end
   
           self.need_reload = false
           log.warn("load key: ", self.key, " data: ", 
json.delay_encode(self.values))
           return true
       end
   ```
   ### Environment
   
   * apisix version (cmd: `apisix version`):2.0
   * OS: (cmd: `uname -a`)
   * OpenResty / Nginx version: (cmd: `nginx -V` or `openresty -V`)
   
   ### Minimal test code / Steps to reproduce the issue
   
   1.
   2.
   3.
   
   ### What's the actual result? (including assertion message & call stack if 
applicable)
   
   ### What's the expected result?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to