This is an automated email from the ASF dual-hosted git repository.
rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 993b04d9bd IGNITE-23273 Use a ConversionService per Ignite node (#4451)
993b04d9bd is described below
commit 993b04d9bd7eccbe6b8f909d4770dccff9331c75
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Wed Sep 25 20:24:51 2024 +0400
IGNITE-23273 Use a ConversionService per Ignite node (#4451)
By default, Micronaut uses a shared ConversionService, so, if we start a
few Ignite nodes in the same JVM (like we do in our tests) and then we stop a
node, the shared ConversionService gets reset and loses converters still needed
for remaining nodes. This commit switches to using one ConversionService
instance per Ignite node to avoid this interference.
---
.../apache/ignite/internal/rest/RestComponent.java | 32 +++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git
a/modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java
b/modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java
index ba045b2c63..6a5f20f161 100644
---
a/modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java
+++
b/modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java
@@ -21,6 +21,9 @@ import static io.micronaut.context.env.Environment.BARE_METAL;
import static
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.DefaultApplicationContext;
+import io.micronaut.core.convert.ConversionService;
+import io.micronaut.core.convert.DefaultConversionService;
import io.micronaut.http.server.exceptions.ServerStartupException;
import io.micronaut.http.ssl.ClientAuthentication;
import io.micronaut.runtime.Micronaut;
@@ -196,7 +199,7 @@ public class RestComponent implements IgniteComponent {
}
private Micronaut buildMicronautContext(int portCandidate, int
sslPortCandidate) {
- Micronaut micronaut = Micronaut.build("");
+ Micronaut micronaut = new IgniteMicronaut().args("");
setFactories(micronaut);
return micronaut
@@ -322,4 +325,31 @@ public class RestComponent implements IgniteComponent {
return LOCALHOST;
}
}
+
+ /**
+ * This overrides the way {@link ConversionService} is obtained.
Currently, one instance of {@link ConversionService} is shared
+ * between all Micronaut instances by default, which causes troubles when
stopping some nodes in tests (REST API on other nodes
+ * becomes affected). This is deprecated in Micronaut itself, but for now
we have to use this workaround.
+ *
+ * <p>This should be removed as soon as {@link ConversionService#SHARED}
is removed from Micronaut.
+ */
+ @SuppressWarnings({"rawtypes", "NullableProblems"})
+ private static class IgniteMicronaut extends Micronaut {
+ private final ConversionService conversionService = new
DefaultConversionService();
+
+ @Override
+ protected ApplicationContext newApplicationContext() {
+ return new DefaultApplicationContext(this) {
+ @Override
+ protected ConversionService createConversionService() {
+ return conversionService;
+ }
+ };
+ }
+
+ @Override
+ public ConversionService<?> getConversionService() {
+ return conversionService;
+ }
+ }
}