Я использую Hazelcast в качестве поставщика Hibernate 2LC в своем приложении Spring Boot в режиме встроенного / P2P. После запуска приложения я увидел, что для моего кластера Hazelcast созданы два члена. Когда я запускаю второй экземпляр всего моего приложения, создаются еще два члена.
В настоящее время я использую следующую конфигурацию с HazelcastCacheRegionFactory
(не локально).
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=com.hazelcast.hibernate.HazelcastCacheRegionFactory
spring.jpa.properties.hibernate.generate_statistics=true
ВЦентр управления Hazelcast, похоже, один член является двойником другого. Однако при запуске второго экземпляра моего приложения Spring Boot оба участника все еще существуют, и в целом они увеличиваются до четырех.
Я уже пытался установить для счетчика резервных копий значение 0 в моем hazelcast.xml
.
При запуске первого экземпляра моего приложения я получаю следующие журналы:
2019-10-09 12:04:51.055 WARN 21088 --- [ restartedMain] c.h.instance.HazelcastInstanceFactory : Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:
--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
2019-10-09 12:04:51.058 INFO 21088 --- [ restartedMain] c.h.config.AbstractConfigLocator : Loading 'hazelcast.xml' from the classpath.
2019-10-09 12:04:51.238 WARN 21088 --- [ restartedMain] c.h.config.AbstractXmlConfigHelper : Name of the hazelcast schema location is incorrect, using default
2019-10-09 12:04:51.717 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Prefer IPv4 stack is true, prefer IPv6 addresses is false
2019-10-09 12:04:53.004 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Picked [10.29.47.243]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
2019-10-09 12:04:53.016 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5701 [dev] [3.12.2] Hazelcast 3.12.2 (20190802 - e34b163) starting at [10.29.47.243]:5701
2019-10-09 12:04:53.016 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5701 [dev] [3.12.2] Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
2019-10-09 12:04:53.240 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.BackpressureRegulator : [10.29.47.243]:5701 [dev] [3.12.2] Backpressure is disabled
2019-10-09 12:04:55.174 INFO 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5701 [dev] [3.12.2] Creating MulticastJoiner
2019-10-09 12:04:55.313 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.OperationExecutorImpl : [10.29.47.243]:5701 [dev] [3.12.2] Starting 4 partition threads and 3 generic threads (1 dedicated for priority tasks)
2019-10-09 12:04:55.314 INFO 21088 --- [ restartedMain] c.h.internal.diagnostics.Diagnostics : [10.29.47.243]:5701 [dev] [3.12.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-10-09 12:04:55.328 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5701 [dev] [3.12.2] [10.29.47.243]:5701 is STARTING
2019-10-09 12:04:57.466 INFO 21088 --- [ restartedMain] c.h.internal.cluster.ClusterService : [10.29.47.243]:5701 [dev] [3.12.2]
Members {size:1, ver:1} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267 this
]
2019-10-09 12:04:57.486 INFO 21088 --- [ restartedMain] c.h.i.m.ManagementCenterService : [10.29.47.243]:5701 [dev] [3.12.2] Hazelcast will connect to Hazelcast Management Center on address:
http://localhost:8080/hazelcast-mancenter
2019-10-09 12:04:57.495 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5701 [dev] [3.12.2] [10.29.47.243]:5701 is STARTED
2019-10-09 12:04:57.544 INFO 21088 --- [MC.State.Sender] com.hazelcast.client.impl.ClientEngine : [10.29.47.243]:5701 [dev] [3.12.2] Applying a new client selector :ClientSelector{any}
2019-10-09 12:04:57.651 INFO 21088 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-10-09 12:04:58.089 INFO 21088 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-10-09 12:04:58.163 INFO 21088 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-10-09 12:04:58.274 INFO 21088 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-10-09 12:04:58.276 INFO 21088 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-10-09 12:04:58.533 INFO 21088 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-10-09 12:04:58.777 INFO 21088 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2019-10-09 12:04:59.122 INFO 21088 --- [ restartedMain] c.h.h.HazelcastCacheRegionFactory : Starting up HazelcastCacheRegionFactory
2019-10-09 12:04:59.124 INFO 21088 --- [ restartedMain] c.h.config.AbstractConfigLocator : Loading 'hazelcast.xml' from the classpath.
2019-10-09 12:04:59.127 WARN 21088 --- [ restartedMain] c.h.config.AbstractXmlConfigHelper : Name of the hazelcast schema location is incorrect, using default
2019-10-09 12:04:59.165 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Prefer IPv4 stack is true, prefer IPv6 addresses is false
2019-10-09 12:04:59.949 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Picked [10.29.47.243]:5703, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5703], bind any local is true
2019-10-09 12:04:59.950 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5703 [dev] [3.12.2] Hazelcast 3.12.2 (20190802 - e34b163) starting at [10.29.47.243]:5703
2019-10-09 12:04:59.950 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5703 [dev] [3.12.2] Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
2019-10-09 12:04:59.956 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.BackpressureRegulator : [10.29.47.243]:5703 [dev] [3.12.2] Backpressure is disabled
2019-10-09 12:05:01.343 INFO 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5703 [dev] [3.12.2] Creating MulticastJoiner
2019-10-09 12:05:01.348 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.OperationExecutorImpl : [10.29.47.243]:5703 [dev] [3.12.2] Starting 4 partition threads and 3 generic threads (1 dedicated for priority tasks)
2019-10-09 12:05:01.349 INFO 21088 --- [ restartedMain] c.h.internal.diagnostics.Diagnostics : [10.29.47.243]:5703 [dev] [3.12.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-10-09 12:05:01.349 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5703 [dev] [3.12.2] [10.29.47.243]:5703 is STARTING
2019-10-09 12:05:01.473 INFO 21088 --- [ restartedMain] c.h.i.cluster.impl.MulticastJoiner : [10.29.47.243]:5703 [dev] [3.12.2] Trying to join to discovered node: [10.29.47.243]:5701
2019-10-09 12:05:01.478 INFO 21088 --- [cached.thread-2] com.hazelcast.nio.tcp.TcpIpConnector : [10.29.47.243]:5703 [dev] [3.12.2] Connecting to /10.29.47.243:5701, timeout: 10000, bind-any: true
2019-10-09 12:05:01.486 INFO 21088 --- [.IO.thread-in-0] com.hazelcast.nio.tcp.TcpIpConnection : [10.29.47.243]:5701 [dev] [3.12.2] Initialized new cluster connection between /10.29.47.243:5701 and /10.29.47.243:51948
2019-10-09 12:05:01.487 INFO 21088 --- [.IO.thread-in-0] com.hazelcast.nio.tcp.TcpIpConnection : [10.29.47.243]:5703 [dev] [3.12.2] Initialized new cluster connection between /10.29.47.243:51948 and /10.29.47.243:5701
2019-10-09 12:05:07.483 INFO 21088 --- [ration.thread-0] c.h.internal.cluster.ClusterService : [10.29.47.243]:5701 [dev] [3.12.2]
Members {size:2, ver:2} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267 this
Member [10.29.47.243]:5703 - 9862ded6-c26d-4da8-929f-f8616a4bf633
]
2019-10-09 12:05:07.489 INFO 21088 --- [ration.thread-0] c.h.internal.cluster.ClusterService : [10.29.47.243]:5703 [dev] [3.12.2]
Members {size:2, ver:2} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267
Member [10.29.47.243]:5703 - 9862ded6-c26d-4da8-929f-f8616a4bf633 this
]
2019-10-09 12:05:08.481 WARN 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5703 [dev] [3.12.2] Config seed port is 5701 and cluster size is 2. Some of the ports seem occupied!
2019-10-09 12:05:08.482 INFO 21088 --- [ restartedMain] c.h.i.m.ManagementCenterService : [10.29.47.243]:5703 [dev] [3.12.2] Hazelcast will connect to Hazelcast Management Center on address:
http://localhost:8080/hazelcast-mancenter
2019-10-09 12:05:08.487 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5703 [dev] [3.12.2] [10.29.47.243]:5703 is STARTED
Как можно решить проблему наличия двух членов на экземпляр приложения? Есть ли фактическое использование двух членов на экземпляр?
Решение от @ Mesut
Я добавил следующее утверждение в файл application.properties
Spring Boot (конфигурацию можно было бы разместить в другом месте).
spring.jpa.properties.hibernate.cache.hazelcast.instance_name=your-instance-name
Вы также должны создать бин с именем your-instance-name. В Spring Boot этого можно добиться, аннотируя метод, который возвращает экземпляр Hazelcast с @Bean
. Это может быть сделано в вашем основном классе или в классе @Configuration
.
@Bean
public Config hazelcastConfig() {
Config config = new Config();
config.setInstanceName("your-instance-name");
config.setProperty("hazelcast.phone.home.enabled", "false");
return config;
}
@Bean
public HazelcastInstance hazelcastInstance(Config config) {
return Hazelcast.newHazelcastInstance(config);
}
Это приводит к тому, что в каждом экземпляре вашего приложения будет только один член (очень хорошо). Однако подключение к центру управления больше не работает (это не так важно в моей ситуации).