Skip to content

Commit dbcc29d

Browse files
Eureka (#413)
* Upgrade to Hazelcast 4 * Screenshots * Update text to match screenshot counts
1 parent c909b60 commit dbcc29d

File tree

29 files changed

+95
-64
lines changed

29 files changed

+95
-64
lines changed

hazelcast-integration/springboot-eureka-partition-groups/README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ Here we do it from the Hazelcast server. If the maps "__eurekast_safe__"
616616
and "__eurekast_unsafe__" are empty, we put some data in them.
617617

618618
The maps "__eurekast_safe__" and "__eurekast_unsafe__" are
619-
[IMap](http://docs.hazelcast.org/docs/3.8/javadoc/com/hazelcast/core/IMap.html),
619+
[IMap](http://docs.hazelcast.org/docs/4.0/javadoc/com/hazelcast/map/IMap.html),
620620
meaning they are split into sections and those sections spread across
621621
the available servers. The default is for 271 such sections, named _partitions_,
622622
so we create 271 entries to try to put one data record entry into each.
@@ -861,14 +861,12 @@ What you should see is that the "__eurekast_safe__" map has survived
861861
this event unscathed. There are still 271 entries.
862862

863863
What you should see is that the "__eurekast_unsafe__" map has lost
864-
some data. In the screenshot only 201 entries remain, so 70 have
864+
some data. In the screenshot only 196 entries remain, so 75 have
865865
gone.
866866

867-
You should expect to lost about a quarter of the unsafe (no backup)
868-
data. Four servers, one is killed.
869-
870-
The exact number lost will depend on how the map partitions have been
871-
allocated to the servers. This is not random, but difficult to predict.
867+
This seems intuititve to have lost about a quarter of the unsafe (no backup)
868+
data. Four servers, one is killed. However, it is not a correct belief
869+
as we will discover later on.
872870

873871
### 14. Kill another specific Hazelcast Server
874872

@@ -895,8 +893,8 @@ The "__eurekast_safe__" map is still fine, all 271 entries are there.
895893
We have lost both the `odd` zone servers but the other copy of the data was
896894
in the `even` zone servers, so no data has been lost.
897895

898-
With two servers gone, the "__eurekast_unsafe__" map will be about half the
899-
original size. Here it shows 149, you should have a roughly similar number.
896+
With two servers gone, the "__eurekast_unsafe__" map will be smaller still.
897+
Here it shows 74, you will probably have a different number.
900898

901899
### 16. Kill yet another Hazelcast Server
902900

@@ -934,9 +932,20 @@ zone available it's better than nothing. Here it has saved us.
934932

935933
Surprised 2 ?
936934

937-
The "__eurekast_unsafe__" has dropped from 149 to 145 by the most recent loss of a server.
938-
We've lost 75% of the hosts but not 75% of the data, and that's because it's the partitions
939-
that are spread across the hosts.
935+
The "__eurekast_unsafe__" dropped from 271 to 196 when a server crashed, then down to 74
936+
when another crashed, then down to 1 !!
937+
938+
What is going on ?
939+
940+
What is going on is partitioning. Data is organised into groups based on their keys,
941+
and the groups are spread across the servers. With small data volumes the groups may
942+
be different sizes. So if you lose a server which is hosting larger than average
943+
groups, you lost more data.
944+
945+
It's not really a problem. If you have much larger data volumes, millions or billions,
946+
the deviation in the group sizes becomes almost unnoticable.
947+
948+
And if you're worried about losing data, turn on data safety.
940949

941950
## Hazelcasts Mancenter
942951

hazelcast-integration/springboot-eureka-partition-groups/my-eureka-common/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
<dependencies>
2424
<dependency>
2525
<groupId>org.springframework.cloud</groupId>
26-
<artifactId>spring-cloud-starter-eureka</artifactId>
26+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
27+
<exclusions>
28+
<exclusion>
29+
<groupId>org.springframework.cloud</groupId>
30+
<artifactId>spring-cloud-netflix-ribbon</artifactId>
31+
</exclusion>
32+
</exclusions>
2733
</dependency>
2834
</dependencies>
2935
</project>

hazelcast-integration/springboot-eureka-partition-groups/my-eureka-common/src/main/java/com/hazelcast/samples/eureka/partition/groups/MyEurekaDiscoveryService.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.hazelcast.samples.eureka.partition.groups;
22

3-
import com.hazelcast.nio.Address;
3+
import com.hazelcast.cluster.Address;
44
import com.hazelcast.spi.discovery.DiscoveryNode;
55
import com.hazelcast.spi.discovery.SimpleDiscoveryNode;
66
import com.hazelcast.spi.discovery.integration.DiscoveryService;
@@ -11,11 +11,14 @@
1111
import org.springframework.cloud.client.discovery.DiscoveryClient;
1212
import org.springframework.stereotype.Component;
1313

14+
import java.io.IOException;
15+
import java.net.ServerSocket;
1416
import java.util.ArrayList;
1517
import java.util.HashMap;
1618
import java.util.List;
1719
import java.util.Map;
1820

21+
import static com.hazelcast.internal.util.EmptyStatement.ignore;
1922
import static com.hazelcast.spi.partitiongroup.PartitionGroupMetaData.PARTITION_GROUP_ZONE;
2023

2124
/**
@@ -41,6 +44,7 @@ public class MyEurekaDiscoveryService implements DiscoveryService {
4144

4245
private static final String YML_SEPARATOR = ".";
4346

47+
4448
@Value("${eureka.client.registerWithEureka:true}")
4549
public boolean registerWithEureka;
4650

@@ -62,8 +66,8 @@ public class MyEurekaDiscoveryService implements DiscoveryService {
6266
* @return A map with one entry, the partition group for this host.
6367
*/
6468
@Override
65-
public Map<String, Object> discoverLocalMetadata() {
66-
HashMap<String, Object> result = new HashMap<>();
69+
public Map<String, String> discoverLocalMetadata() {
70+
HashMap<String, String> result = new HashMap<>();
6771

6872
/* The metadata is only for partition groups, so we don't need this if we are
6973
* a Hazelcast client. Hazelcast servers register with Eureka, clients only read.
@@ -76,7 +80,7 @@ public Map<String, Object> discoverLocalMetadata() {
7680
log.info("discoverLocalMetadata(): Hazelcast lookup to Eureka : start");
7781

7882
// Find the web port this process is using.
79-
String port = String.valueOf(discoveryClient.getLocalServiceInstance().getPort());
83+
String port = this.findPort(System.getProperty("my.web.port"));
8084
// Since this is a one machine example, we know which machine we are on.
8185
String hostPort = "localhost" + YML_SEPARATOR + port;
8286

@@ -174,4 +178,36 @@ public void start() {
174178
@Override
175179
public void destroy() {
176180
}
181+
182+
/**
183+
* We need to know the web port this process will use, but this module
184+
* is triggered before Spring decides. Using the base port (as a String)
185+
* determine which port is free, assuming Spring picks it as next in
186+
* sequence.
187+
*
188+
* @param Starting port
189+
* @return Next free port, starting port if free or greater
190+
*/
191+
private String findPort(String startingPort) {
192+
try {
193+
int startPort = Integer.parseInt(startingPort);
194+
int freePort = 0;
195+
196+
for (int port = startPort; port < startPort + 100; port++) {
197+
try {
198+
new ServerSocket(port).close();
199+
freePort = port;
200+
break;
201+
} catch (IOException portInUse) {
202+
ignore(portInUse);
203+
}
204+
}
205+
206+
return String.valueOf(freePort);
207+
208+
} catch (NumberFormatException nfe) {
209+
log.error("Not a number, starting port '{}'", startingPort);
210+
}
211+
return "";
212+
}
177213
}

hazelcast-integration/springboot-eureka-partition-groups/my-eureka-server/.springBeans

Lines changed: 0 additions & 16 deletions
This file was deleted.

hazelcast-integration/springboot-eureka-partition-groups/my-eureka-server/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
<dependency>
4141
<groupId>org.springframework.cloud</groupId>
4242
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
43+
<exclusions>
44+
<exclusion>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
47+
</exclusion>
48+
</exclusions>
4349
</dependency>
4450
</dependencies>
4551

hazelcast-integration/springboot-eureka-partition-groups/my-hazelcast-client/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@
2525
<groupId>${project.groupId}</groupId>
2626
<artifactId>my-eureka-common</artifactId>
2727
<version>${project.version}</version>
28-
<exclusions>
29-
<exclusion>
30-
<groupId>com.hazelcast</groupId>
31-
<artifactId>hazelcast</artifactId>
32-
</exclusion>
33-
<exclusion>
34-
<groupId>com.hazelcast</groupId>
35-
<artifactId>hazelcast-all</artifactId>
36-
</exclusion>
37-
<exclusion>
38-
<groupId>com.hazelcast</groupId>
39-
<artifactId>hazelcast-client</artifactId>
40-
</exclusion>
41-
</exclusions>
4228
</dependency>
4329

4430
<dependency>

hazelcast-integration/springboot-eureka-partition-groups/my-hazelcast-client/src/main/java/com/hazelcast/samples/eureka/partition/groups/MyConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class MyConfiguration {
4444
public ClientConfig clientConfig(DiscoveryServiceProvider discoveryServiceProvider) {
4545
ClientConfig clientConfig = new ClientConfig();
4646

47+
// Naming
48+
clientConfig.setClusterName(Constants.CLUSTER_NAME);
49+
4750
// Discovery
4851
clientConfig.setProperty("hazelcast.discovery.enabled", Boolean.TRUE.toString());
4952
clientConfig.getNetworkConfig().getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);

hazelcast-integration/springboot-eureka-partition-groups/my-hazelcast-server/pom.xml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<description>Hazelcast Server</description>
1616

1717
<properties>
18+
<hazelcast.version>4.0</hazelcast.version>
19+
1820
<!-- needed for checkstyle/findbugs -->
1921
<main.basedir>${project.parent.parent.parent.basedir}</main.basedir>
2022
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -25,20 +27,6 @@
2527
<groupId>${project.groupId}</groupId>
2628
<artifactId>my-eureka-common</artifactId>
2729
<version>${project.version}</version>
28-
<exclusions>
29-
<exclusion>
30-
<groupId>com.hazelcast</groupId>
31-
<artifactId>hazelcast</artifactId>
32-
</exclusion>
33-
<exclusion>
34-
<groupId>com.hazelcast</groupId>
35-
<artifactId>hazelcast-all</artifactId>
36-
</exclusion>
37-
<exclusion>
38-
<groupId>com.hazelcast</groupId>
39-
<artifactId>hazelcast-client</artifactId>
40-
</exclusion>
41-
</exclusions>
4230
</dependency>
4331

4432
<dependency>
@@ -51,6 +39,10 @@
5139
<groupId>org.springframework.boot</groupId>
5240
<artifactId>spring-boot-starter-actuator</artifactId>
5341
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-web</artifactId>
45+
</dependency>
5446
</dependencies>
5547

5648
<build>

hazelcast-integration/springboot-eureka-partition-groups/pom.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
<description>Project POM</description>
1717

1818
<properties>
19+
<hazelcast.version>4.0</hazelcast.version>
20+
1921
<!-- needed for checkstyle/findbugs -->
2022
<main.basedir>${project.parent.parent.basedir}</main.basedir>
2123
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2224

2325
<java.version>1.8</java.version>
24-
<spring-boot.version>1.5.2.RELEASE</spring-boot.version>
25-
<spring-cloud.version>Camden.SR5</spring-cloud.version>
26+
<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
27+
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
2628
</properties>
2729

2830
<modules>
@@ -36,9 +38,16 @@
3638
</modules>
3739

3840
<dependencies>
41+
<!-- https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9-and-above -->
42+
<dependency>
43+
<groupId>org.glassfish.jaxb</groupId>
44+
<artifactId>jaxb-runtime</artifactId>
45+
</dependency>
46+
3947
<dependency>
4048
<groupId>com.hazelcast</groupId>
41-
<artifactId>hazelcast</artifactId>
49+
<artifactId>hazelcast-all</artifactId>
50+
<version>${hazelcast.version}</version>
4251
</dependency>
4352

4453
<dependency>
916 KB
Loading

0 commit comments

Comments
 (0)