Skip to content

Commit

Permalink
fix(session): support auto recreate session when upgrade (#2959)
Browse files Browse the repository at this point in the history
* fix failed to auto recreate session when upgrade

* The impact of code changes is limited to multiCloud

* response to reivew

* response to review

* response to review
  • Loading branch information
PeachThinking authored and guowl3 committed Aug 2, 2024
1 parent e9bed7d commit c13ee11
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ public ConnectionSession create(@NotNull CreateSessionReq req) {
DefaultConnectSessionIdGenerator idGenerator = new DefaultConnectSessionIdGenerator();
idGenerator.setDatabaseId(req.getDbId());
idGenerator.setFixRealId(StringUtils.isBlank(req.getRealId()) ? null : req.getRealId());
idGenerator.setHost(stateHostGenerator.getHost());
if (Objects.nonNull(req.getFrom()) && isOBCloudEnvironment()) {
idGenerator.setHost(req.getFrom());
} else {
idGenerator.setHost(stateHostGenerator.getHost());
}
sessionFactory.setIdGenerator(idGenerator);
long timeoutMillis = TimeUnit.MILLISECONDS.convert(sessionProperties.getTimeoutMins(), TimeUnit.MINUTES);
timeoutMillis = timeoutMillis + this.connectionSessionManager.getScanIntervalMillis();
Expand Down Expand Up @@ -330,8 +334,8 @@ public ConnectionSession nullSafeGet(@NotNull String sessionId, boolean autoCrea
ConnectionSession session = connectionSessionManager.getSession(sessionId);
if (session == null) {
CreateSessionReq req = new DefaultConnectSessionIdGenerator().getKeyFromId(sessionId);
boolean autoRecreate = cloudMetadataClient.supportsCloudMetadata();
if (!autoCreate || (!StringUtils.equals(req.getFrom(), stateHostGenerator.getHost()) && !autoRecreate)) {
if (!autoCreate
|| (!StringUtils.equals(req.getFrom(), stateHostGenerator.getHost()) && !isOBCloudEnvironment())) {
throw new NotFoundException(ResourceType.ODC_SESSION, "ID", sessionId);
}
Lock lock = this.sessionId2Lock.computeIfAbsent(sessionId, s -> new ReentrantLock());
Expand Down Expand Up @@ -466,4 +470,9 @@ private void preCheckSessionLimit() {
}
}

private boolean isOBCloudEnvironment() {
return cloudMetadataClient.supportsCloudMetadata()
&& Boolean.FALSE.equals(cloudMetadataClient.supportsCloudParentUid());
}

}

0 comments on commit c13ee11

Please sign in to comment.