imDwAaY opened a new pull request, #7863:
URL: https://github.com/apache/shenyu/pull/7863
Fixes #7697.
### Problem
`GET /instance` loads the persisted `instance_info` rows, then overrides
each row with the node-local `InstanceCheckService` heartbeat cache. The lookup
result is dereferenced without a null check.
`InstanceCheckService.setup()` (which calls `fetchInstanceData()` and fills
the cache) only runs on the elected master, and `/instance/**` is not in the
cluster `forward-list`. A follower therefore serves the list with an empty
local cache and every row throws a `NullPointerException`, failing the whole
page with a 500.
The same window exists on the master for rows persisted by another Admin
writer or inserted after the local snapshot.
### Change
- When the local heartbeat entry is absent, keep the persisted
`instanceState` and `dateUpdated` instead of failing. No fresh `ONLINE` state
is fabricated.
- `last_heart_beat_time` is not persisted in this branch, so the DB-mapped
`lastHeartBeatTime` is `0`. When it is non-positive, fall back to
`dateUpdated.getTime()`; a positive persisted value is kept as-is. Once #7859
persists the column, the fallback stops triggering.
- Nodes that do have a local heartbeat entry keep the existing override
behavior, unchanged.
### Tests
- `InstanceControllerTest#testQueryPluginsWithMissingHealthBeatInfo` sends
one page with two rows to cover both fallback cases: a missing entry with
`lastHeartBeatTime=0` (falls back to `dateUpdated`) and a persisted positive
`lastHeartBeatTime` (kept as-is). It also asserts the response is `200`.
- The existing `testQueryPlugins` now asserts that local heartbeat values
really override the persisted ones.
### Validation
```bash
./mvnw -pl shenyu-admin -am -Dtest=InstanceControllerTest
-DfailIfNoTests=false \
-Djacoco.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true test
```
- `BUILD SUCCESS`, `Tests run: 5, Failures: 0, Errors: 0, Skipped: 0`
- `./mvnw -o -pl shenyu-admin checkstyle:check` passes.
### Scope / follow-ups
- No schema, mapper, service or API changes.
- The two-node cluster E2E scenario from the issue is not included; the
follower case is exactly "persisted rows + empty local cache" and is covered at
the controller level.
- After #7859 persists the instance last heartbeat time, the `dateUpdated`
fallback no longer triggers.
--
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]