Skip to content

Instantly share code, notes, and snippets.

View ericacm's full-sized avatar

Some Dude ericacm

View GitHub Profile
@ericacm
ericacm / ClusterService.scala
Last active December 11, 2015 09:38
Cluster Service
trait ClusterService {
def initialize()
def enabled: Boolean
def clusterStatus: ClusterStatus
def nodeId: String
}
case class ClusterStatus(
current: String,
isLeader: Boolean,
@ericacm
ericacm / gist:4315253
Created December 17, 2012 01:56
Test after building from source. I also removed the RetryLoop. This is what happens after I kill the ZK leader. The original leader localhost:14181 loses leadership and no member gets hasLeadership though the participant.isLeader is true for localhost:14189.
This is localhost:14181 - the original leader
20:45:43.175 [RMI TCP Connection(2)-127.0.0.1-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - nodeId=localhost:14181 hasLeadership=true, Cluster participants: localhost:14181, localhost:14189, leader=localhost:14181
20:46:00.017 [ThreadPoolTaskScheduler-1] ERROR com.netflix.curator.ConnectionState - Connection timed out for connection string (localhost:14181,localhost:14185,localhost:14189) and timeout (15000) / elapsed (16724)
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss
at com.netflix.curator.ConnectionState.getZooKeeper(ConnectionState.java:94) ~[curator-client-1.2.3.jar:na]
at com.netflix.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:105) [curator-client-1.2.3.jar:na]
at com.netflix.curator.framework.imps.CuratorFrameworkImpl.getZooKeeper(CuratorFrameworkImpl.java:410) [curator-framework-1.2.3.jar:na]
at com.netflix.curator.framework.imps.GetChildrenBuilderImpl$3.call(Ge
@ericacm
ericacm / gist:4247058
Created December 9, 2012 21:18
ZK leader killed, app leadership moves to different cluster member
Original leader (localhost:14181):
16:11:18.002 [ForkJoinPool-1-worker-9] DEBUG c.n.s.n.DeliveryService$DeliverySerializer - received SerializedDelivery: none
16:11:18.002 [ForkJoinPool-1-worker-9] DEBUG c.n.s.n.DeliveryServiceImpl - delivering noDigest events
16:11:18.128 [main-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - watchedEvent: eventType=NodeChildrenChanged state=SyncConnected
16:11:18.139 [main-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - nodeId=localhost:14181 isLeader=true, Cluster participants: localhost:14181, localhost:14185, leader=localhost:14181
16:11:18.250 [main-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - watchedEvent: eventType=None state=Disconnected
16:11:24.498 [main-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - nodeId=localhost:14181 isLeader=true, Cluster participants: localhost:14181, localhost:14185, leader=localhost:14181
16:11:24.500 [main-EventThread] INFO c.nyx.services.ZookeeperServiceImpl - watchedEvent: eventType=None state=
@ericacm
ericacm / scheduledDistribute.scala
Last active October 13, 2015 19:47
Sample scheduled job
@Value("${deliveryService.distributeSchedule:0,30 * * * * *}")
var distributeSchedule: String = _
schedulerService.addJob(
SchedulerJob("distributeEvents", () => scheduledDistribute(), distributeSchedule))
def scheduledDistribute() =
if (clusterService.clusterStatus.isLeader)
distribute()
@ericacm
ericacm / gist:3943149
Last active October 12, 2015 00:28
ClusterService / ClusterConfig
trait ClusterService {
def initialize()
def enabled: Boolean
def clusterStatus: ClusterStatus
}
case class ClusterStatus(
current: String,
isLeader: Boolean, leader: String,
participants: Iterable[String])
@ericacm
ericacm / gist:3943058
Created October 24, 2012 00:56
refreshWorkers
def refreshWorkers() {
val cs = clusterService.clusterStatus
for (participant <- cs.participants) {
val path = if (cs.current == participant)
akkaConfig.localActorPath(workerPath)
else
remotePathForParticipant(
akkaConfig, participant, workerPath)
@ericacm
ericacm / zkClientStartup.scala
Last active October 11, 2015 23:28
start Zookeeper client
def initialize() {
// Embedded server startup here (see part 2)
// ...
curatorFramework =
CuratorFrameworkFactory.newClient(
connectString, sessionTimeoutSec*1000,
connectionTimeoutSec*1000, new RetryOneTime(1))
curatorFramework.start()
@ericacm
ericacm / ZkServerStartup.scala
Last active October 11, 2015 23:28
start Zookeeper server
// hosts is in the form host:port,host:port
@Value("${zookeeperService.hosts:localhost}")
@ManagedGetter @BeanProperty
var hosts: String = _
val hostsArr = hosts.split(",")
val serversKeyArr = new Array[String](hostsArr.length)
val serversValArr = new Array[String](hostsArr.length)
for ((server, idx) <- hostsArr.zipWithIndex) {
val (host, port) = if (server.contains(":")) {
@ericacm
ericacm / gist:3935996
Created October 23, 2012 00:55
selectLeader
if (clientEnabled) {
startThread("leaderSelection") {
while (electingLeader) {
selectLeader()
electLoop.acquire()
if (electingLeader) log.info("Lost connection to Zookeeper - reselecting leader")
}
}
log.info("Waiting for leader to be selected")
leaderSelected.acquire()
@ericacm
ericacm / gist:3935937
Created October 23, 2012 00:45
leaderSelector app startup
startThread("leaderSelection") {
while (electingLeader) {
selectLeader()
electLoop.acquire()
if (electingLeader) log.info("Lost connection to Zookeeper - reselecting leader")
}
}
log.info("Waiting for leader to be selected")
leaderSelected.acquire()