Skip to content

Commit

Permalink
Fix notify
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Sep 29, 2024
1 parent 86fa382 commit 69655d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,8 @@ private synchronized void doOnEvent(ServiceInstancesChangedEvent event) {
}

int emptyNum = hasEmptyMetadata(revisionToInstances);
if (emptyNum != 0) { // retry every 10 seconds
if (emptyNum != 0) {
hasEmptyMetadata = true;
if (retryPermission.tryAcquire()) {
if (retryFuture != null && !retryFuture.isDone()) {
// cancel last retryFuture because only one retryFuture will be canceled at destroy().
retryFuture.cancel(true);
}
try {
retryFuture = scheduler.schedule(
new AddressRefreshRetryTask(retryPermission, event.getServiceName()),
10_000L,
TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error(
INTERNAL_ERROR,
"unknown error in registry module",
"",
"Error submitting async retry task.");
}
logger.warn(
INTERNAL_ERROR, "unknown error in registry module", "", "Address refresh try task submitted");
}

// return if all metadata is empty, this notification will not take effect.
if (emptyNum == revisionToInstances.size()) {
Expand All @@ -214,10 +194,12 @@ private synchronized void doOnEvent(ServiceInstancesChangedEvent event) {
"",
"Address refresh failed because of Metadata Server failure, wait for retry or new address refresh event.");

submitRetryTask(event);
return;
}
} else {
hasEmptyMetadata = false;
}
hasEmptyMetadata = false;

Map<String, Map<Integer, Map<Set<String>, Object>>> protocolRevisionsToUrls = new HashMap<>();
Map<String, List<ProtocolServiceKeyWithUrls>> newServiceUrls = new HashMap<>();
Expand All @@ -241,6 +223,34 @@ private synchronized void doOnEvent(ServiceInstancesChangedEvent event) {

this.serviceUrls = newServiceUrls;
this.notifyAddressChanged();

if (hasEmptyMetadata) {
submitRetryTask(event);
}
}

private void submitRetryTask(ServiceInstancesChangedEvent event) {
// retry every 10 seconds
if (retryPermission.tryAcquire()) {
if (retryFuture != null && !retryFuture.isDone()) {
// cancel last retryFuture because only one retryFuture will be canceled at destroy().
retryFuture.cancel(true);
}
try {
retryFuture = scheduler.schedule(
new AddressRefreshRetryTask(retryPermission, event.getServiceName()),
10_000L,
TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error(
INTERNAL_ERROR,
"unknown error in registry module",
"",
"Error submitting async retry task.");
}
logger.warn(
INTERNAL_ERROR, "unknown error in registry module", "", "Address refresh try task submitted");
}
}

public synchronized void addListenerAndNotify(URL url, NotifyListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public static MetadataInfo getRemoteMetadata(
ServiceInstance instance = selectInstance(instances);
String metadataType = ServiceInstanceMetadataUtils.getMetadataStorageType(instance);
MetadataInfo metadataInfo;
boolean interrupted = Thread.currentThread().isInterrupted();
try {
if (logger.isDebugEnabled()) {
logger.debug("Instance " + instance.getAddress() + " is using metadata type " + metadataType);
Expand Down Expand Up @@ -194,14 +193,6 @@ public static MetadataInfo getRemoteMetadata(
+ " from instance " + instance.getAddress(),
e);
metadataInfo = null;
} finally {
logger.info("After getting metadata from instance " + instance.getAddress() + ", interrupted status for "
+ Thread.currentThread().getName() + " is " + Thread.interrupted() + ". "
+ "If it was interrupted, this may caused by Metadata fetch timeout.");
if (interrupted) {
logger.info("Resetting interrupted status for " + Thread.currentThread().getName() + " to true due to "
+ "previous interrupted status.");
}
}

if (metadataInfo == null) {
Expand Down

0 comments on commit 69655d1

Please sign in to comment.