|
7 | 7 | (:import (com.hazelcast.core Hazelcast) |
8 | 8 | (com.hazelcast.config Config |
9 | 9 | LockConfig |
| 10 | + ServiceConfig |
10 | 11 | MapConfig |
11 | | - QuorumConfig))) |
| 12 | + QuorumConfig) |
| 13 | + (com.hazelcast.raft RaftConfig |
| 14 | + RaftMember))) |
12 | 15 |
|
13 | 16 | (def opt-spec |
14 | 17 | [["-m" "--members MEMBER-LIST" "Comma-separated list of peers to connect to" |
15 | 18 | :parse-fn (fn [m] |
16 | 19 | (str/split m #"\s*,\s*"))]]) |
17 | 20 |
|
| 21 | +(defn prepareRaftServiceConfig |
| 22 | + "Prepare Hazelcast RaftConfig and ServiceConfig" |
| 23 | + [members] |
| 24 | + (let [raftConfig (RaftConfig.) |
| 25 | + serviceConfig (ServiceConfig.) |
| 26 | + |
| 27 | + ; add raft members |
| 28 | + _ (doseq [member members] |
| 29 | + (info "Adding " member " to raft group") |
| 30 | + (.addMember raftConfig (RaftMember. (str member ":5701") member))) |
| 31 | + |
| 32 | + _ (.setLeaderElectionTimeoutInMillis raftConfig 1000) |
| 33 | + _ (.setLeaderHeartbeatPeriodInMillis raftConfig 1000) |
| 34 | + |
| 35 | + ; prepare service config |
| 36 | + _ (.setEnabled serviceConfig true) |
| 37 | + _ (.setName serviceConfig com.hazelcast.raft.impl.service.RaftService/SERVICE_NAME) |
| 38 | + _ (.setClassName serviceConfig (.getName com.hazelcast.raft.impl.service.RaftService)) |
| 39 | + _ (.setConfigObject serviceConfig raftConfig) |
| 40 | + ] |
| 41 | + serviceConfig)) |
| 42 | + |
| 43 | +(defn prepareAtomicLongServiceConfig |
| 44 | + "Prepare Raft AtomicLong service config" |
| 45 | + [] |
| 46 | + (let [serviceConfig (ServiceConfig.) |
| 47 | + _ (.setEnabled serviceConfig true) |
| 48 | + _ (.setName serviceConfig com.hazelcast.raft.service.atomiclong.RaftAtomicLongService/SERVICE_NAME) |
| 49 | + _ (.setClassName serviceConfig (.getName com.hazelcast.raft.service.atomiclong.RaftAtomicLongService)) |
| 50 | + ] |
| 51 | + serviceConfig)) |
| 52 | + |
18 | 53 | (defn -main |
19 | 54 | "Go go go" |
20 | 55 | [& args] |
|
23 | 58 | summary |
24 | 59 | errors]} (cli/parse-opts args opt-spec) |
25 | 60 | config (Config.) |
| 61 | + members (:members options) |
26 | 62 |
|
27 | 63 | ; Timeouts |
28 | | - _ (.setProperty config "hazelcast.client.heartbeat.interval" "1000") |
29 | | - _ (.setProperty config "hazelcast.client.heartbeat.timeout" "5000") |
30 | | - _ (.setProperty config "hazelcast.client.invocation.timeout.seconds" "5") |
| 64 | + _ (.setProperty config "hazelcast.client.max.no.heartbeat.seconds" "5") |
31 | 65 | _ (.setProperty config "hazelcast.heartbeat.interval.seconds" "1") |
32 | | - _ (.setProperty config "hazelcast.master.confirmation.interval.seconds" "1") |
33 | 66 | _ (.setProperty config "hazelcast.max.no.heartbeat.seconds" "5") |
34 | | - _ (.setProperty config "hazelcast.max.no.master.confirmation.seconds" "10") |
35 | 67 | _ (.setProperty config "hazelcast.operation.call.timeout.millis" "5000") |
| 68 | + _ (.setProperty config "hazelcast.wait.seconds.before.join" "0") |
| 69 | + _ (.setProperty config "hazelcast.merge.first.run.delay.seconds" "1") |
| 70 | + _ (.setProperty config "hazelcast.merge.next.run.delay.seconds" "1") |
36 | 71 |
|
37 | 72 | ; Network config |
38 | 73 | _ (.. config getNetworkConfig getJoin getMulticastConfig |
39 | 74 | (setEnabled false)) |
40 | 75 | tcp-ip (.. config getNetworkConfig getJoin getTcpIpConfig) |
41 | | - _ (doseq [member (:members options)] |
| 76 | + _ (doseq [member members] |
42 | 77 | (.addMember tcp-ip member)) |
43 | 78 | _ (.setEnabled tcp-ip true) |
44 | 79 |
|
| 80 | + ; prepare raft services |
| 81 | + servicesConfig (.getServicesConfig config) |
| 82 | + _ (.addServiceConfig servicesConfig (prepareRaftServiceConfig members)) |
| 83 | + _ (.addServiceConfig servicesConfig (prepareAtomicLongServiceConfig)) |
| 84 | + |
45 | 85 | ; Quorum for split-brain protection |
46 | 86 | quorum (doto (QuorumConfig.) |
47 | 87 | (.setName "majority") |
|
0 commit comments