Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public interface JdbcRegistryClientHeartbeatMapper extends BaseMapper<JdbcRegist

@Select("select * from t_ds_jdbc_registry_client_heartbeat")
List<JdbcRegistryClientHeartbeat> selectAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public boolean updateById(JdbcRegistryClientHeartbeatDTO jdbcRegistryClientHeart
return jdbcRegistryClientHeartbeatMapper.updateById(jdbcRegistryClientHeartbeat) == 1;
}

public void upsert(JdbcRegistryClientHeartbeatDTO clientHeartbeatDTO) {
JdbcRegistryClientHeartbeat clientHeartbeat =
JdbcRegistryClientHeartbeatDTO.toJdbcRegistryClientHeartbeat(clientHeartbeatDTO);
int row = jdbcRegistryClientHeartbeatMapper.updateById(clientHeartbeat);
if (row == 0) {
jdbcRegistryClientHeartbeatMapper.insert(clientHeartbeat);
}
}

public void insert(JdbcRegistryClientHeartbeatDTO jdbcRegistryClient) {
checkNotNull(jdbcRegistryClient.getId());
JdbcRegistryClientHeartbeat jdbcRegistryClientHeartbeat =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void refreshClientsHeartbeat() {
}
JdbcRegistryClientHeartbeatDTO clone = jdbcRegistryClientHeartbeatDTO.clone();
clone.setLastHeartbeatTime(now);
jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO);
jdbcRegistryClientRepository.upsert(jdbcRegistryClientHeartbeatDTO);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's better don't use upsert here, if the client heartbeat has been removed, then we should shutdown, since the server might have been failovered by other server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the client is not down. The connection to the database is unreachable within more than a session timeout time. When the database is available, the client will send the heartbeat with the same client ID.
You mean in this case, the client should generate an new client ID and insert a new client record?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the session times out and the heartbeat is removed, the server/client should stop rather than reinsert a heartbeat, because at this point other servers may have already detected that the heartbeat is down and initiated fault-tolerance procedures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A more recommended approach would be to throw an exception when

jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO);

fails, and make refreshClientsHeartbeat return directly when jdbcRegistryServerState == JdbcRegistryServerState.DISCONNECTED.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So this client should be restarted manually to register it again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The client shouldn't restarted, it should shutdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm confused. How to register this client again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When a session times out, indicating that the client has disconnected, a disconnection event must be triggered, and the service will automatically terminate without requiring re-registration.

jdbcRegistryClientHeartbeatDTO.setLastHeartbeatTime(clone.getLastHeartbeatTime());
}
if (jdbcRegistryServerState == JdbcRegistryServerState.SUSPENDED) {
Expand Down
Loading