Hello Quanlong Huang, Impala Public Jenkins,

I'd like you to reexamine a change. Please visit

    https://gerrit.cloudera.org/24975

to look at the new patch set (#10).

Change subject: IMPALA-15451: Make hierarchical event executors event-driven
......................................................................

IMPALA-15451: Make hierarchical event executors event-driven

1) When hierarchical event processing is enabled, catalogd consumes
noticeable CPU on an idle cluster. Each DbEventExecutor and
TableEventExecutor thread was scheduled with scheduleAtFixedRate()
every 10 ms, regardless of whether it had any work. With the default
configuration of 5 db executors, each having 5 table executors, 30
threads wake up 100 times per second each, i.e. ~3000 wakeups per
second. Although each pass finds no events and does little work, the
cost of scheduling and context switches adds up.

This patch replaces the fixed-rate polling with event-driven
wakeups. Each executor thread now runs a process loop and blocks in
a new EventExecutorWaiter when it has nothing to do. It is woken up
in the following cases:
- DbEventExecutor is signalled when:
  1. An event is enqueued to one of its DbProcessors.
  2. All the TableProcessors waiting on a DbBarrierEvent have
     reached it.
- TableEventExecutor is signalled when:
  1. An event is enqueued to one of its TableProcessors.
  2. A DbBarrierEvent its TableProcessor waits on is processed.
  3. The pseudo drop table event of a RenameTableBarrierEvent is
     processed, making its pseudo create table event processable.

EventExecutorWaiter records a signal raised while the executor
thread is busy, so the next wait returns immediately and no wakeup
is lost.

TableEventExecutor always waits until it is signalled, since every
event that cannot be processed yet is signalled once it becomes
processable. DbEventExecutor wakes up every 1 second while it has
DbProcessors, to remove the TableProcessors that have been idle for
min_event_processor_idle_ms. Otherwise, it also waits until it is
signalled.

Since events are processed as soon as they are enqueued or become
processable, instead of waiting up to 10 ms for the next tick, this
also removes the scheduling latency from event processing.

2) When an event fails to process, the event processor changes to ERROR
or NEEDS_INVALIDATE status and the executors stop processing, leaving
the failed event and the events after it queued on the executors.
These stale events were not discarded. So upon event processor start,
they were processed first, regardless of the event id the event
processor is started from.

To fix it, the events queued on the executors are now discarded when
the event processor changes to ERROR or NEEDS_INVALIDATE. The greatest
synced event is retained, and the last dispatched event is moved back
to it. Upon start, event processing resumes from the greatest synced
event id, the latest event id or the given event id, and the events
after it are fetched from HMS again.

3) In hierarchical mode, clearing the event executors upon event
processing failure or global INVALIDATE METADATA discards the queued
events and makes their databases and tables appear processed, so HMS
event sync requests could succeed with stale metadata.
EventExecutorService now counts the number of times it is cleared. A
request captures the count before checking its databases and tables.
If the count changes or the event processor cannot process events,
the request waits for the greatest synced event id to reach its latest
event id instead, since clear() retains the greatest synced event and
the catalog reset advances it. The request fails if the event
processor goes to ERROR or NEEDS_INVALIDATE, or times out.

4) This also fixes a race in RenameTableBarrierEvent, where the pseudo
drop and create table event threads could both see both events
processed and skipped, and both increment the events-skipped metric.
Event-driven wakeups made it more likely, causing
test_rename_table_hierarchical_one_db_and_two_table_threads to fail
intermittently. Since the pseudo create table event is always
processed after the pseudo drop table event, only the create now
updates the skipped metric and the delete event log, and injects the
error for testing.

Testing:
- Ran existing tests.
- Added test_event_processor_start_upon_error to verify that the
  failed event is retried upon :event_processor('start'), and is not
  retried upon :event_processor('start', -1) even when a subsequent
  event is enqueued for the same table. Multiple INSERT events are
  fetched in a batch, so that the events queued after the failed
  event are discarded upon failure.
- Added test_hms_event_sync_upon_catalog_reset to verify that a query
  waiting for HMS events to be synced succeeds with the latest metadata
  when a global INVALIDATE METADATA discards the events queued on the
  event executors.
- The non-hierarchical variants of the tests are now set
  --enable_hierarchical_event_processing=false explicitly. The flag
  defaults to true, so they were running in hierarchical mode.
- Verified with top -H that DbEventExecutor and TableEventExecutor
  threads do not consume CPU on an idle catalogd.

Assisted-by: Claude Opus 4.8 (Claude Code)
Change-Id: I97107e99ead7907023a936d0017f33fcdba23185
---
M fe/src/main/java/org/apache/impala/catalog/events/DbBarrierEvent.java
M fe/src/main/java/org/apache/impala/catalog/events/DbEventExecutor.java
M fe/src/main/java/org/apache/impala/catalog/events/EventExecutorService.java
A fe/src/main/java/org/apache/impala/catalog/events/EventExecutorWaiter.java
M fe/src/main/java/org/apache/impala/catalog/events/EventProcessException.java
M 
fe/src/main/java/org/apache/impala/catalog/events/MetastoreEventsProcessor.java
M fe/src/main/java/org/apache/impala/catalog/events/RenameTableBarrierEvent.java
M fe/src/main/java/org/apache/impala/catalog/events/TableEventExecutor.java
M 
fe/src/test/java/org/apache/impala/catalog/events/EventExecutorServiceTest.java
M tests/common/environ.py
M tests/custom_cluster/test_event_processing_error.py
M tests/custom_cluster/test_event_processing_perf.py
M tests/custom_cluster/test_events_custom_configs.py
13 files changed, 628 insertions(+), 181 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/75/24975/10
--
To view, visit https://gerrit.cloudera.org/24975
To unsubscribe, visit https://gerrit.cloudera.org/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I97107e99ead7907023a936d0017f33fcdba23185
Gerrit-Change-Number: 24975
Gerrit-PatchSet: 10
Gerrit-Owner: Anonymous Coward <[email protected]>
Gerrit-Reviewer: Anonymous Coward <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>

Reply via email to