diaosj commented on code in PR #14208:
URL: https://github.com/apache/apisix/pull/14208#discussion_r4661532848


##########
apisix/utils/batch-processor.lua:
##########
@@ -141,19 +187,61 @@ end
 
 
 function create_buffer_timer(self)
-    local hdl, err = timer_at(self.inactive_timeout, flush_buffer, self)
+    ensure_recovery_timer()
+    local timer = {deadline = now() + self.inactive_timeout}
+    local hdl, err = timer_at(self.inactive_timeout, flush_buffer, self, timer)
     if not hdl then
         if err == "process exiting" then
-            timer_at(0, flush_buffer, self)
-        else
+            hdl, err = timer_at(0, flush_buffer, self, timer)
+            timer.deadline = now()
+        end
+        if not hdl then
+            self.is_timer_running = false
             core.log.error("failed to create buffer timer: ", err)
             return
         end
     end
+    pending_buffers[self] = timer
     self.is_timer_running = true
 end
 
 
+function recover_timers(premature)
+    if premature then
+        return
+    end
+
+    local cutoff = now() - TIMER_GRACE
+    local dropped = {}
+    for batch, self in pairs(pending_batches) do
+        if batch.timer_deadline <= cutoff then
+            pending_batches[batch] = nil
+            batch.timer_deadline = nil
+            local count = #batch.entries
+            self.processed_entries = self.processed_entries + count

Review Comment:
   Addressed in `b06163c8`: `schedule_recovery` now captures `cutoff = 
timer_now() - TIMER_GRACE` and defers reclamation via `timer_at(0, 
recover_timers, cutoff)` (when overdue entries exist) without recomputing 
`cutoff` in `recover_timers`. Narrowed `TEST 5`'s `ngx.timer.at` interception 
and added `TEST 7` for the 3s worker-pause regression.



##########
apisix/utils/batch-processor.lua:
##########
@@ -59,11 +87,15 @@ local function schedule_func_exec(self, delay, batch)
                                "while exiting: ", err2)
                 return
             end
+            delay = 0
         else
             core.log.error("failed to create process timer: ", err)
             return
         end
     end
+
+    batch.timer_deadline = now() + delay

Review Comment:
   Addressed in `b06163c8`: all four deadline/cutoff assignments now use 
`timer_now()`, backed by `resty.core.time.monotonic_time` on OpenResty >= 
1.21.4.2 and NGINX's exported `ngx_current_msec` via FFI on 1.21.4.1 (verified 
at load time, no silent fallback to wall time). Added `TEST 8` covering the 
1.21.4.1 fallback path and a forward wall-clock jump.



-- 
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: [email protected]

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

Reply via email to