Skip to content

Instantly share code, notes, and snippets.

View ericacm's full-sized avatar

Some Dude ericacm

View GitHub Profile
@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 / 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 / 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: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 / 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 / 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 / nodeToWorker.scala
Last active December 11, 2015 09:39
Node to worker example
val participants = clusterService.clusterStatus.participants
val workers = participants.map(nodeIdToActorRef(_))
workers.foreach(_ ! nextWork())
class ZookeeperService(hostInfo: HostInfo)
extends ClusterService with EmbeddedZookeeper {
def nodeId: String = hostInfo.hostname + ":" + hostInfo.basePort + 1
@Value("${zookeeperService.client.enabled:false}")
var enabled: Boolean = _
@Value("${zookeeperService.leaderPath:/ls}")
var leaderPath: String = _
@ericacm
ericacm / Build.scala
Created January 27, 2013 00:36
Build.scala for ClusterSingletonManagerSpec testing
import sbt._
import Keys._
import com.typesafe.sbt.SbtMultiJvm
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.{ MultiJvm }
object ExampleBuild extends Build {
lazy val buildSettings = Defaults.defaultSettings ++ multiJvmSettings ++ Seq(
organization := "example",
version := "1.0",
import org.apache.zookeeper.server.quorum.{QuorumPeerMain => ApacheQuorumPeerMain}
import org.apache.zookeeper.server.{ZooKeeperServerMain => ApacheZookeeperServerMain}
trait EmbeddedZookeeper {
this: ClusterService with Logging =>
@Value("${zookeeperService.server.enabled:false}")
var isServerEnabled: Boolean = _
// Location of server data directory