yongboy commented on a change in pull request #3848:
URL: https://github.com/apache/apisix/pull/3848#discussion_r596804207



##########
File path: apisix/discovery/consul_kv.lua
##########
@@ -230,6 +241,73 @@ local function update_application(server_name_prefix, data)
 end
 
 
+local function read_dump_srvs()
+    local data, err = util.read_file(dump_params.path)
+    if not data then
+        log.warn("read dump file get error: ", err)
+        return
+    end
+
+    core.log.info("read dump file: ", data)
+    data = util.trim(data)
+    if #data == 0 then
+        core.log.error("dump file is empty")
+        return
+    end
+
+    local entity, err  = core.json.decode(data)
+    if err then
+        core.log.error("decoded dump data got error: ", err, ", file content: 
", data)
+        return
+    end
+
+    if not entity.services or not entity.last_update then
+        core.log.error("decoded dump data miss fields, file content: ", data)
+        return
+    end
+
+    local now_time = ngx.time()
+    core.log.info("dump file last_update: ", entity.last_update, ", 
dump_params.expire: ",
+        dump_params.expire, ", now_time: ", now_time)
+    if dump_params.expire ~= 0  and (entity.last_update + dump_params.expire) 
< now_time then
+       core.log.warn("dump file: ", dump_params.path,
+         " had expired, ignored it")
+        return
+    end
+
+    applications = entity.services
+    core.log.info("load dump file into memory success")
+end
+
+
+local function write_dump_srvs()
+    local entity = {
+        services = applications,
+        last_update = ngx.time(),
+        expire = dump_params.expire, -- later need handle it
+    }
+    local data = core.json.encode(entity)
+    local succ, err =  util.write_file(dump_params.path, data)
+    if not succ then
+        core.log.error("write dump into file got error: ", err)
+    end
+end
+
+
+local function show_dump_file()
+    if not dump_params then
+        return 503, "dump params is nil"
+    end
+
+    local data, err = util.read_file(dump_params.path)
+    if not data then
+        return 500, err

Review comment:
       Yes, it would be better.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to