You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/07 06:08:21 UTC

[GitHub] [apisix] spacewander commented on a diff in pull request #7869: fix: reload once when log rotate

spacewander commented on code in PR #7869:
URL: https://github.com/apache/apisix/pull/7869#discussion_r964417079


##########
apisix/plugins/log-rotate.lua:
##########
@@ -218,25 +221,42 @@ local function file_size(file)
 end
 
 
-local function rotate_file(files, now_time, max_kept)
+local function rotate_file(files, now_time, max_kept, wait_time)
+    if isempty(files) then
+        return
+    end
+
+    local new_files = new_tab(2, 0)
+    -- rename the log files
     for _, file in ipairs(files) do
         local now_date = os_date("%Y-%m-%d_%H-%M-%S", now_time)
         local new_file = rename_file(default_logs[file], now_date)
         if not new_file then
             return
         end
 
-        local pid = process.get_master_pid()
-        core.log.warn("send USR1 signal to master process [", pid, "] for reopening log file")
-        local ok, err = signal.kill(pid, signal.signum("USR1"))
-        if not ok then
-            core.log.error("failed to send USR1 signal for reopening log file: ", err)
-        end
+        tab_insert(new_files, new_file)
+    end
+
+    -- send signal to reopen log files
+    local pid = process.get_master_pid()
+    core.log.warn("send USR1 signal to master process [", pid, "] for reopening log file")
+    local ok, err = signal.kill(pid, signal.signum("USR1"))
+    if not ok then
+        core.log.error("failed to send USR1 signal for reopening log file: ", err)
+    end
+
+    if enable_compression then
+        -- Waiting for nginx reopen files
+        -- to avoid losing logs during compression
+        ngx_sleep(wait_time)

Review Comment:
   Will the sleep block the timer and cause the next rotation time incorrect?



##########
apisix/plugins/log-rotate.lua:
##########
@@ -37,7 +37,9 @@ local str_format = string.format
 local str_reverse = string.reverse
 local tab_insert = table.insert
 local tab_sort = table.sort
-
+local new_tab = require "table.new"
+local ngx_sleep = require("apisix.core.utils").sleep
+local isempty = require "table.isempty"

Review Comment:
   Better to introduce it via `core.table `



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org