Skip to content

fix(admin): persist the instance last heartbeat time - #7859

Merged
Aias00 merged 1 commit into
apache:masterfrom
nanhe17:fix/7723-instance-heartbeat-persistence
Oct 20, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
nanhe17:fix/7723-instance-heartbeat-persistence

Conversation

@nanhe17

@nanhe17 nanhe17 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7723

Problem

InstanceInfoServiceImpl assigns lastHeartBeatTime on the update path and InstanceCheckService.handleBeatInfo stamps it on every accepted heartbeat, but the value never reached the database:

  • instance-info-sqlmap.xml omits last_heart_beat_time from BaseResultMap, Base_Column_List, insert and updateById.
  • The initialization schemas (H2, MySQL, PostgreSQL, Oracle) and the 2.7.1→2.7.2 upgrade scripts lack the column.
  • The create path (InstanceInfoDO.buildInstanceInfoDO) never copies the VO value.

Every read path — including the restart/master-handover restore in InstanceCheckService.fetchInstanceData — therefore sees 0, and the checker ages restored instances from epoch zero.

Solution

  • Persist last_heart_beat_time (bigint NOT NULL DEFAULT 0) through the mapper XML (result map, column list, insert, update).
  • Copy the reported heartbeat in buildInstanceInfoDO via a new builder method.
  • Add the column to the H2/MySQL/PG/Oracle init schemas and to the five 2.7.1→2.7.2 upgrade scripts (mysql/ob/og/oracle/pg). Historical rows backfill to 0 ("no durable observation yet") and are refreshed on the next heartbeat report; upgrade behavior documented in db/upgrade/upgrade-guide.md.

Compatibility

  • New column is NOT NULL DEFAULT 0; no existing statement changes semantics. resultType selects map through the globally enabled mapUnderscoreToCamelCase; the resultMap covers the remaining queries.
  • No public API or configuration change.

Tests

  • InstanceInfoMapperTest: insertRoundTripsLastHeartBeatTime / updateRoundTripsLastHeartBeatTime round-trip a fixed nonzero timestamp on H2 through insert and update, covering both resultType auto-mapping (selectById, selectOneByQuery) and the resultMap path (findAllByNamespaceId).
  • InstanceInfoServiceImplTest: testCreatePersistsReportedHeartBeatTime / testUpdatePersistsReportedHeartBeatTime verify the service passes the reported heartbeat to the mapper on both paths.

Local verification (Windows, JDK 21): ./mvnw -pl shenyu-admin -am test — InstanceInfoMapperTest 11/11, InstanceInfoServiceImplTest 4/4, InstanceInfoMapperOracleSqlTest 1/1, InstanceInfoServiceTest 8/8, checkstyle passing. The full ./mvnw clean install -Dmaven.javadoc.skip=true reactor build succeeds; the unrelated shenyu-plugin-tracing module (no dependency on the touched modules) has one pre-existing failure (TraceContinuityTest) that reproduces identically on pristine master in this environment, so it was excluded from the local run.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

The instance mapper's column list, result map, insert and update
omitted last_heart_beat_time, so the last reported heartbeat never
reached the database: reads and restart restores saw 0, and the
create path never copied the VO value either.

Add the column (bigint NOT NULL DEFAULT 0) to the H2/MySQL/PG/Oracle
init schemas and the five 2.7.1->2.7.2 upgrade scripts, persist it
through the mapper XML, copy it in buildInstanceInfoDO, and add
mapper round-trip regression tests plus service-path tests.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, complete change for #7723. The last_heart_beat_time column is added across all dialects (mysql / oracle / pg / h2) plus the 2.7.1→2.7.2 upgrade scripts and the upgrade guide; the InstanceInfoDO builder and instance-info-sqlmap.xml are wired through; and the mapper / service round-trip tests confirm persistence. The 0 default (no durable observation yet; real value stored on the next heartbeat) is documented correctly in the upgrade guide.

One note (non-blocking): no CI check runs are reported on this head commit — it looks like the workflow was not triggered. Please kick off a run (e.g. re-run the checks or a blank push) so the gates are recorded before merge.

Approving the change itself.

@Aias00

Aias00 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

pls add my wechat: aias00

@Aias00
Aias00 merged commit ee52a6f into apache:master Oct 20, 2026
55 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Instance last heartbeat time is never persisted or restored

2 participants