EgorBaranovEnjoysTyping commented on PR #12584:
URL: https://github.com/apache/ignite/pull/12584#issuecomment-7353530736
# Blockers
## K1. `false` → `FAILED` is wrong
**Location:** `MaintenanceProcessor:412-415`,
`CheckCorruptedCacheStoresCleanAction:40-51`, `MaintenanceLoggingTest:955-956`
The meaning of `false` is inferred from the action name.
`CheckCorruptedCacheStoresCleanAction` returns `FALSE` while corrupted files
**are still on disk** — a normal intermediate "check has not passed yet" state.
It will be logged as `ACTIVE->FAILED`.
Related: the same `false` in the async branch (`:405-406`) becomes
`CANCELLED` — one result, two states. `toLowerCase()` lacks `Locale.ROOT`
(harmless for current names, silently breaks on any name containing `I`). Test
`:955-956` **enshrines** the wrong behaviour via
`failedStopAction=ACTIVE->SKIPPED`.
**Fix:** derive `FAILED` only from a thrown exception, or introduce `enum
MaintenanceActionResult` in a separate ticket.
> **EN:** `false` can't be mapped to `FAILED`:
`CheckCorruptedCacheStoresCleanAction` returns `false` while corrupted files
are *still present* — an intermediate state, not a failure. It will be logged
as `ACTIVE->FAILED`, while the same `false` from an async action (`:405-406`)
becomes `CANCELLED`. Please derive `FAILED` only from a thrown exception, or
return an enum instead of `Boolean`. Also `toLowerCase()` needs `Locale.ROOT`.
## K2. Async action failure is never logged
**Location:** `MaintenanceProcessor:402-408`
On `error != null`, `whenComplete` sets `FAILED` and says nothing — no
`log.error`, no event. Only the next tick would print it. But defragmentation
calls `failureProc.process(CRITICAL_ERROR)` on `Throwable`
(`ExecuteDefragmentationAction:96-100`), so the node halts **before** that
tick. The most important state is never visible.
**Fix:** log the transition right there, inside `whenComplete`.
> **EN:** The `error != null` branch only flips the state to `FAILED` and
logs nothing; the only consumer is the next metrics tick. But
`ExecuteDefragmentationAction` calls `failureProc.process(CRITICAL_ERROR)` on
`Throwable`, so the node halts before that tick — an async failure is never
visible. Please log the transition right there.
## K3. The feature is unavailable with `metricsLogFrequency=0`
**Location:** `IgniteKernal:1300-1311`, `IgniteLogInfoProviderImpl:742-750`
Both the task list and the banner are printed only from
`ackNodeBasicMetrics`, which is scheduled when `metricsLogFreq > 0`. With `0`
(the recommended production setting) nothing about maintenance mode reaches the
log. Yet this is exactly the state a node does not leave on its own — the
administrator has to learn about it from the log.
**Fix:** log unconditionally on entering the mode and on task
registration/unregistration; keep the tick as a reminder only.
> **EN:** The block lives inside `ackNodeBasicMetrics`, scheduled only when
`metricsLogFrequency > 0` (`IgniteKernal:1300-1311`). With the recommended `0`
the task list is never logged at all — in the one state a node doesn't leave on
its own. Please log unconditionally on entering the mode / on task registration.
## K4. `maintenanceMode` is never reset, `tasksStates` is never pruned
**Location:** `MaintenanceProcessor:197`, `:294-295`, `:202-211`
`maintenanceMode` is assigned once (`:197`) with no inverse.
`unregisterMaintenanceTask` (`:294-295`) only sets `isRegistered = false`,
leaving the entry. Result: after all tasks are repaired the node prints forever:
```
!!! ATTENTION! NODE IS IN MAINTENANCE MODE !!!
^-- UNREGISTERED name=...
```
The `catch` (`:202-211`) calls `tasksStates.clear()` but never resets
`maintenanceMode`, so an exception inside the `forEach` yields
`isMaintenanceMode() == true` over an empty list.
**Fix:** remove the entry on unregistration, reset the flag when
`activeTasks` empties, reset both fields in the `catch`.
> **EN:** `maintenanceMode` is assigned once (`:197`) and never reset, and
`tasksStates` entries are never removed (`:294-295` only flips `isRegistered`).
After all tasks are repaired the node logs `!!! ATTENTION! ...` every tick
forever. The `catch` at `:202-211` clears the map but leaves `maintenanceMode
== true`. Please reset the flag and drop the entry on unregister.
## K5. Unguarded cast on the metrics hot path
**Location:** `IgniteLogInfoProviderImpl:680`
```java
MaintenanceProcessor mntcProc =
(MaintenanceProcessor)ctx.maintenanceRegistry();
```
Runs on every tick, for every log-info plugin, regardless of the mode.
`MaintenanceRegistry` is a public interface, so a custom implementation throws
`ClassCastException` inside `timeout().schedule` (`IgniteKernal:1301-1308`),
where only `IgniteClientDisconnectedException` is caught. The metrics task then
dies for all plugins.
**Fix:** add an `instanceof` guard, or expose the methods on
`MaintenanceRegistry`.
> **EN:** `(MaintenanceProcessor)ctx.maintenanceRegistry()` runs on every
metrics tick for every plugin, even outside maintenance mode.
`MaintenanceRegistry` is public, so a custom implementation throws
`ClassCastException` inside the scheduled task (only
`IgniteClientDisconnectedException` is caught) and kills metric logging for all
plugins. Please add an `instanceof` check or expose the methods on the
interface.
## K6. `ExecuteDefragmentationAction.execute()` may never complete its future
**Location:** `ExecuteDefragmentationAction:73-107`
- `Thread.start()` sits **outside** the `try`. If `start()` throws, the
exception propagates synchronously, `fut` is never completed, `ACTIVE` is
already set, and the caller waits forever.
- The `catch` is too narrow: `IgniteCheckedException | IgniteException`. An
`OutOfMemoryError` or `AssertionError` from `beforeDefragmentation()` produces
the same hang.
- `fut.complete(!defrgMgr.isCanceled())` conflates "cancel requested" with
"cancel happened": `cancel()` returns `false` both when it wins and when it is
too late (`CachePartitionDefragmentationManager:671-685`).
**Fix:** `try/catch (Throwable)` around the whole body with
`completeExceptionally`; an explicit tri-state instead of `!isCanceled()`.
> **EN:** Thread creation and `start()` sit outside the `try`, and the
`catch` covers only `IgniteCheckedException | IgniteException`. Any other
throwable leaves the future never completed while `trackedAction` already
marked `ACTIVE`. Also `fut.complete(!defrgMgr.isCanceled())` conflates "cancel
requested" with "cancel happened".
## K7. `await()` without a timeout on the checkpoint thread
**Location:** `MaintenanceDefragmentationLoggingTest:194-199`, `:93-95`
`markerReached.await()` without a timeout runs on the thread completing the
checkpoint. In `afterTest` the field is nulled **before** the nodes are stopped:
```java
markerReached = null; // :93
stopAllGrids(); // :95
```
Any failed assertion between starting defragmentation and `countDown()`
(`:115`, `:135`, `:151`) yields either an NPE inside `create()` (latch not yet
captured) or a `stopAllGrids()` hang until the 5-minute timeout.
**Fix:** `await(timeout, SECONDS)`; `stopAllGrids()` before nulling the
field; `countDown()` in a `finally`.
> **EN:** `markerReached.await()` without a timeout runs on the checkpoint
thread, and `afterTest` nulls the field *before* `stopAllGrids()`. Any failed
assertion before `countDown()` gives either an NPE in `create()` or a hang
until the 5-minute timeout. Please use `await(timeout, SECONDS)` and null the
field after stopping the grids.
## K8. `testTask` has no assertions and mismatched semaphore accounting
**Location:** `MaintenanceLoggingTest:464-516`
Three consecutive `execute()` calls and not a single `assert` after them.
The entire "verification" is three `Thread.sleep(3000)`. All four assertions
precede the first `execute()`. Plus `catch (Exception ignored)` around
`prepareAndExecuteMaintenance()`.
Semaphore: `AsyncAction.execute()` (`:779-790`) performs two `acquire()`
calls. In `testTask` there are 10 `acquire()` against 7 `release()`. Three
threads stay parked in `acquire()` forever and never reach `unregisterTask()`.
The threads are daemons, so the JVM does not hang — the test simply does not
verify its intent.
This is the same point nizhikov raised in round 1, and it has regressed: one
`execute()` call before, three now.
**Fix:** drop `sleep`, assert via `LogListener.check(...)`, pair every
`release()` in a `finally`, assert on each `execute()` result.
> **EN:** `testTask` performs three `execute()` calls and three
`Thread.sleep(3000)` with no assertions — the only four asserts are before the
first `execute()`. Also `release()` is called 7 times against 10 `acquire()`,
so three worker threads stay parked forever. Same point as in the first review
round, now with three calls instead of one.
---
# Substantive Issues
**S1. `tasksStates()` — `stream()` instead of `Comparable`.**
`MaintenanceProcessor:370-373`. Encapsulate the comparison in
`MaintenanceTaskState implements Comparable` and sort with `Collections.sort`;
the Stream API is discouraged in Ignite. Note `values()` is an unordered
`Collection` view over `ConcurrentHashMap`, not a `List` — copy first with `new
ArrayList<>(tasksStates.values())`.
**S2. `toString` assembled by hand although `S.toString` exists.**
`MaintenanceTaskState:89-127`. The `" ^-- "` indent is hardcoded in one
class, a second indent in `IgniteLogInfoProviderImpl:747`; the format is
smeared across two files. `S.toString(S.OB, ...)` (`GridToStringBuilder:1691`)
provides it out of the box. Also `" MaintenanceTask "` has a trailing space,
`"MaintenanceTasks"` does not.
**S3. `ActionLifecycle.state(State)` — a mutator named like a noun.**
`MaintenanceTaskState:154`. Reads as an accessor, performs an append. Prefer
`addState` / `record`. There is also a window between `addActionLifecycle` and
`state(ACTIVE)` (`MaintenanceProcessor:395-397`): a tick landing in that gap
prints `action=` with no states.
**S4. Double lookup and a latent NPE.** `MaintenanceProcessor:294-295`,
`:377-380`. `containsKey` + `get` instead of a single `get` with a null check.
The second site is NPE-prone by construction and is protected only by the
absence of removals — which is precisely K4.
**S5. Startup banner.** `IgniteKernal:1029-1047`. `stream().max().get()`
with no "not found" branch; the empty string inside `List.of` renders as `>>> `
with a dangling space; the wording diverges from
`IgniteLogInfoProviderImpl:746`; the task count is missing although
`activeTasks.size()` is already known.
**S6. `parameters()` goes into the log verbatim.**
`MaintenanceTaskState:97`. An arbitrary caller-supplied string: `]`, commas and
line breaks break the format, and the length is unbounded. This ties into
testing: `LogListener.matches` is a **substring** match
(`LogListener.java:110`), so the tests cannot detect format degradation.
**S7. `compareTo` without `equals`/`hashCode`.** Introducing `Comparable`
leaves `compareTo == 0` while `equals == false`. Harmless for log ordering, but
convention places `equals`/`hashCode` before `toString`.
**S8. `IndexCorruptionRebuildTest` — an unrelated change.** `:103`, `:120`,
`:122`, `:204`, `:233`. The whole class received `metricsLogFrequency(1000)`
and a `ListeningTestLogger` for the sake of a single assertion.
`clearListeners()` is never called (the three new tests do call it).
`check(10000)` polls for 10 s against a 1-second tick; calling
`ackNodeBasicMetrics` directly (it is package-private) would be cheaper.
---
# Performance and Memory
**No throughput regression.** The block runs only when `isMaintenanceMode()`
(`IgniteLogInfoProviderImpl:742`), there are 1–3 tasks, and
`DFLT_METRICS_LOG_FREQ = 60000` (`IgniteConfiguration:205`). Outside the mode
the only cost is one cast at `:680`. `CopyOnWriteArrayList` is appropriate
here: `state()` is written from `whenComplete` and read from the metrics
thread, with 2–4 writes per action.
**P2 — the leak is real, and it is driven externally.** `ActionLifecycle`
retains only `actionName`; the `MaintenanceAction` itself is not retained, so
plugin classloaders are not pinned — this is done correctly. But
`actionsForMaintenanceTask()` builds a **new** wrapper on every call (`:358`),
and `trackedAction` permanently appends a lifecycle to `executedActions`
(`:395`). And that is the documented operator loop:
`control.sh --persistence check` → `PersistenceTask:250-259` → the action
returns `FALSE` while files remain → "Maintenance task is not fixed."
(`PersistenceAbstractCommand:81`) → the operator retries.
The byte cost is tiny (~150 B), but every lifecycle is re-rendered into the
log on every tick: 8 640 retries (one per 10 s over a day) → a ~225 KB line
every minute → **~320 MB of log per day**. Additionally, `tasksStates` is not
pruned on unregistration — bounded for the three built-in names, unbounded for
user-supplied ones (K4 from the memory side).
**Fix:** cap the history at the last lifecycle per action name, or cache
`trackedAction` at workflow registration instead of recreating it. The latter
also answers "which of the two `action0=ACTIVE->COMPLETED` is newer".
> **EN:** `executedActions` (`MaintenanceTaskState:53`) is appended in
`trackedAction` (`MaintenanceProcessor:395`) and never trimmed, and
`actionsForMaintenanceTask()` builds a *new* wrapper on every call
(`:355-361`). The documented retry loop — `control.sh --persistence check`
returning `false` until files are gone (`PersistenceAbstractCommand:81`) —
permanently appends one lifecycle per attempt. Memory is modest (~150 B), but
each entry is re-rendered every tick (`IgniteLogInfoProviderImpl:749`): 8 640
retries → a ~225 KB log line per minute, i.e. ~320 MB/day. Please cap the
history per action name or cache the tracked wrappers per workflow.
---
# Minor Issues
- **N1.** 16 added lines exceed 120 chars: `MaintenanceProcessor:57` (124),
`MaintenanceDefragmentationLoggingTest:233,238,243,248`,
`MaintenanceLoggingTest:234,254,530,531,874,956,1009,1027` (121–128).
Checkstyle tolerates 140, so CI stays silent.
- **N2.** `MaintenanceTaskState:114` — the only `var` in the new code (5
exist across all of `modules/core`).
- **N3.** `MaintenanceLoggingTest:792` — `if
(Thread.currentThread().isAlive())` inside `catch (InterruptedException)`; a
thread executing the `catch` is always alive, so the condition is always `true`.
- **N4.** `MaintenanceProcessor:203-204` — constant string concatenation in
`log.warning`.
- **N5.** `ExecuteDefragmentationAction:99` — `// TODO Check other options.`
without a ticket number.
- **N6.** Empty `/** */` at `MaintenanceProcessor:67,70,73,76` is **not** a
result of this PR, and the new `tasksStates` field is documented substantively.
The remark does not apply.
---
# Inline Comments (9, all unresolved)
| # | Anchor | Verdict |
|---|---|---|
| T1 | `MaintenanceProcessor:56` | Confirmed, but "one line" is impossible —
shorten the text |
| T2 | `MaintenanceProcessor:58-59` | Confirmed, but the declared type is
not the issue |
| T3 | `MaintenanceProcessor:369-370` | Confirmed except the third point —
reword it |
| T4 | `MaintenanceProcessor:414-417` | Confirmed, and there is something
worse nearby |
| T5 | `MaintenanceTaskState:88` | The strongest of the nine |
| T6 | `IgniteLogInfoProviderImpl:749` | A duplicate of T5 with a correct
anchor |
| T7 | `IgniteKernal:1028-1030` | Confirmed |
| T8 | `MaintenanceDefragmentationLoggingTest:101` | There is an answer, but
a real bug sits next to it |
| T9 | `MaintenanceLoggingTest:779-782` | Confirmed, the protocol is
asymmetric |
**T1.** Line 57 is **124** chars; collapsed onto one line it becomes
**128**. So the request is not "make it one line" but "shorten it": `/** {@link
MaintenanceTaskState}s logged by ackNodeBasicMetrics in maintenance mode. */`.
The current text is also ungrammatical ("are logged in acknowledge Node Basic
Metrics").
**T2.** `ConcurrentHashMap` formally signals thread safety, but no atomic
operations are used at all: only `put`, `clear`, `containsKey`, `get`,
`values()`. The `containsKey` + `get` pair is not atomic (S4), and correctness
relies on "keys are never removed" — which the K4 fix breaks. "Declare it as
`ConcurrentMap`" does not solve this; either use `computeIfPresent` or state
the invariant explicitly.
**T3.** The intent was: comparison into the class, sorting via
`Collections.sort`, and `Comparator.comparing` together with `stream()`
removed. The third point refers to the comparator, not to `tasksStates()` (the
accessor is needed — `IgniteLogInfoProviderImpl:743` calls it). Please reword:
as written it reads as "remove the accessor", and the author may resolve it
without changing anything.
**T4.** `null` falls into the `else` and silently becomes `COMPLETED`. This
is real for `MaintenanceAction<T>` with an unconstrained `T`. But the same
block contains something worse: name-based inference (K1). Please broaden the
remark to K1, otherwise only the `null` case gets fixed.
**T5.** `MaintenanceTaskState:89-127` assembles `prefix [name=value, ...]`
by hand: a `StringBuilder`, a hardcoded `" ^-- "`, manual `->` and `", "`.
`S.toString(S.OB, ...)` (`GridToStringBuilder:1691`) does all of it and removes
the indent duplication as well.
**T6.** Specifics missing from the comment: the indent is defined in two
classes; `"MaintenanceTasks"` lacks a trailing space while `"MaintenanceTask "`
has one; there is no count — `MaintenanceTasks (3)` reads better; `forEach`
uses a lambda where convention prefers a plain `for`.
**T7.** Four lines where the first is the signal and the rest are
explanations, plus an empty string inside `List.of`. `>>> ATTENTION!
MAINTENANCE MODE IS ENABLED!` plus one or two lines is enough.
**T8.** `super.afterTest()` is last because `beforeTest()` begins with
`super.beforeTest()` — the pair is symmetric (LIFO).
`GridAbstractTest.afterTest()` (`:354-361`) restores `changedLevels`, and
neither test calls `setLevel()`, so it is a no-op today. But "it is a no-op, so
the order does not matter" is a fragile argument; the answer "it mirrors
`beforeTest`" deserves a comment. Statistics for `modules/core`: `afterTest`
first in 331 cases, last in 183, middle in 16; `beforeTest` first in 311.
**More importantly:** `markerReached = null` (`:93`) precedes `stopAllGrids()`
(`:95`) — that is K7 and must be fixed.
**T9.** `AsyncAction.execute()` (`:779-790`): the first `acquire()` blocks
the return until the test decides, the second keeps the thread alive until the
end of the test. The protocol works but is undocumented, so it reads as a
mistake. At minimum, a comment per `acquire()`; `testTask` has 10 `acquire()`
against 7 `release()` (K8).
---
--
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]