From e1012a44b4fec8509f8814f573e1fa520f9bf55e Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 09:46:05 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/polarismesh/polaris/sync/registry/tasks/PullTask.java | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java index 7b2e37a..6a10bff 100644 --- a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java +++ b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java @@ -86,7 +86,7 @@ public void run() { } } } catch (Throwable e) { - LOG.error("[Core] pull task(source {}) encounter exception", source.getName(), e); + LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e); } } diff --git a/pom.xml b/pom.xml index b938119..9a80d33 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ - 0.2.0-alpha.1 + 0.2.0-alpha.2 ${maven.build.timestamp} 2021.0.3 From 44ad4bcce8dcd45d2e291bea5509aa2023e8ac90 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 10:13:48 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/polarismesh/polaris/sync/registry/tasks/PullTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java index 6a10bff..a29be33 100644 --- a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java +++ b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java @@ -86,7 +86,7 @@ public void run() { } } } catch (Throwable e) { - LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e); + LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e.getStackTrace()); } } From d3fa75d472982c44833cb118d2c8a32c80c62b90 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 10:54:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/polarismesh/polaris/sync/registry/tasks/PullTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java index a29be33..c8f5b09 100644 --- a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java +++ b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java @@ -86,7 +86,8 @@ public void run() { } } } catch (Throwable e) { - LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e.getStackTrace()); + e.printStackTrace(); + LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e); } } From 295de5bb90e63102941d28c32e23ae6123bb6809 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 11:05:48 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DpickAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../polarismesh/polaris/sync/common/rest/RestOperator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java index 634fe65..3b659fc 100644 --- a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java +++ b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java @@ -47,8 +47,11 @@ public static String pickAddress(List addresses) { return addresses.get(0); } Random random = new Random(); - int i = random.nextInt(); - return addresses.get(i % addresses.size()); + int i = random.nextInt(addresses.size()); + if (i >= addresses.size()) { + i = 0; + } + return addresses.get(i); } public RestResponse curlRemoteEndpoint(String url, HttpMethod method, From 76eb2f6ce76dee733597465a3d04274e019279d3 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 11:40:34 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DpickAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/polarismesh/polaris/sync/common/rest/RestOperator.java | 4 ++-- .../cn/polarismesh/polaris/sync/registry/tasks/PullTask.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java index 3b659fc..76678cc 100644 --- a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java +++ b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java @@ -20,6 +20,7 @@ import java.time.Duration; import java.util.List; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; @@ -46,8 +47,7 @@ public static String pickAddress(List addresses) { if (addresses.size() == 1) { return addresses.get(0); } - Random random = new Random(); - int i = random.nextInt(addresses.size()); + int i = ThreadLocalRandom.current().nextInt(addresses.size()); if (i >= addresses.size()) { i = 0; } diff --git a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java index c8f5b09..52db945 100644 --- a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java +++ b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java @@ -26,6 +26,7 @@ import cn.polarismesh.polaris.sync.registry.utils.ConfigUtils; import com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse; import com.tencent.polaris.client.pb.ServiceProto.Instance; +import java.io.ByteArrayInputStream; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -86,6 +87,7 @@ public void run() { } } } catch (Throwable e) { + ByteArrayInputStream in = new ByteArrayInputStream() e.printStackTrace(); LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e); } From fb155d10df837b176f50043b85ead13140e5bb0a Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Wed, 24 Aug 2022 11:48:43 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DpickAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../polaris/sync/common/rest/RestOperator.java | 3 --- .../polaris/sync/registry/tasks/PullTask.java | 9 ++++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java index 76678cc..0903b80 100644 --- a/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java +++ b/polaris-sync-commons/src/main/java/cn/polarismesh/polaris/sync/common/rest/RestOperator.java @@ -48,9 +48,6 @@ public static String pickAddress(List addresses) { return addresses.get(0); } int i = ThreadLocalRandom.current().nextInt(addresses.size()); - if (i >= addresses.size()) { - i = 0; - } return addresses.get(i); } diff --git a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java index 52db945..77884e5 100644 --- a/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java +++ b/polaris-sync-registry-core/src/main/java/cn/polarismesh/polaris/sync/registry/tasks/PullTask.java @@ -27,6 +27,8 @@ import com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse; import com.tencent.polaris.client.pb.ServiceProto.Instance; import java.io.ByteArrayInputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -87,9 +89,10 @@ public void run() { } } } catch (Throwable e) { - ByteArrayInputStream in = new ByteArrayInputStream() - e.printStackTrace(); - LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), e); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), sw); } }