Commit 469c1c18 authored by bkblack's avatar bkblack Committed by Jason Song
parent 989f37b1
...@@ -132,24 +132,11 @@ public class NotificationControllerV2 implements ReleaseMessageListener { ...@@ -132,24 +132,11 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
Set<String> watchedKeys = Sets.newHashSet(watchedKeysMap.values()); Set<String> watchedKeys = Sets.newHashSet(watchedKeysMap.values());
List<ReleaseMessage> latestReleaseMessages =
releaseMessageService.findLatestReleaseMessagesGroupByMessages(watchedKeys);
/** /**
* Manually close the entity manager. * 1、set deferredResult before the check, for avoid more waiting
* Since for async request, Spring won't do so until the request is finished, * If the check before setting deferredResult,it may receive a notification the next time
* which is unacceptable since we are doing long polling - means the db connection would be hold * when method handleMessage is executed between check and set deferredResult.
* for a very long time
*/ */
entityManagerUtil.closeEntityManager();
List<ApolloConfigNotification> newNotifications =
getApolloConfigNotifications(namespaces, clientSideNotifications, watchedKeysMap,
latestReleaseMessages);
if (!CollectionUtils.isEmpty(newNotifications)) {
deferredResultWrapper.setResult(newNotifications);
} else {
deferredResultWrapper deferredResultWrapper
.onTimeout(() -> logWatchedKeys(watchedKeys, "Apollo.LongPoll.TimeOutKeys")); .onTimeout(() -> logWatchedKeys(watchedKeys, "Apollo.LongPoll.TimeOutKeys"));
...@@ -169,6 +156,27 @@ public class NotificationControllerV2 implements ReleaseMessageListener { ...@@ -169,6 +156,27 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
logWatchedKeys(watchedKeys, "Apollo.LongPoll.RegisteredKeys"); logWatchedKeys(watchedKeys, "Apollo.LongPoll.RegisteredKeys");
logger.debug("Listening {} from appId: {}, cluster: {}, namespace: {}, datacenter: {}", logger.debug("Listening {} from appId: {}, cluster: {}, namespace: {}, datacenter: {}",
watchedKeys, appId, cluster, namespaces, dataCenter); watchedKeys, appId, cluster, namespaces, dataCenter);
/**
* 2、check new release
*/
List<ReleaseMessage> latestReleaseMessages =
releaseMessageService.findLatestReleaseMessagesGroupByMessages(watchedKeys);
/**
* Manually close the entity manager.
* Since for async request, Spring won't do so until the request is finished,
* which is unacceptable since we are doing long polling - means the db connection would be hold
* for a very long time
*/
entityManagerUtil.closeEntityManager();
List<ApolloConfigNotification> newNotifications =
getApolloConfigNotifications(namespaces, clientSideNotifications, watchedKeysMap,
latestReleaseMessages);
if (!CollectionUtils.isEmpty(newNotifications)) {
deferredResultWrapper.setResult(newNotifications);
} }
return deferredResultWrapper.getResult(); return deferredResultWrapper.getResult();
...@@ -308,4 +316,3 @@ public class NotificationControllerV2 implements ReleaseMessageListener { ...@@ -308,4 +316,3 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment