Permalink
Browse files

using thew new parsing technology

  • Loading branch information...
1 parent a3a82ac commit 5f7ec3fe80172b2a819853d3c7b1d962223089cb Nick Kallen committed Apr 9, 2010
View
Binary file not shown.
@@ -73,10 +73,14 @@ object Rowz {
}
val prioritizingScheduler = new PrioritizingJobScheduler(schedulerMap)
- val copyJobParser = new BoundJobParser((nameServer, prioritizingScheduler(Priority.Medium.id)))
- val rowzJobParser = new BoundJobParser(forwardingManager)
- polymorphicJobParser += ("Copy|Migrate".r, copyJobParser)
- polymorphicJobParser += ("Create|Destroy".r, rowzJobParser)
+ val copyJobParser = new BoundJobParser(jobs.CopyParser, (nameServer, prioritizingScheduler(Priority.Medium.id)))
+ val migrateJobParser = new BoundJobParser(new gizzard.jobs.MigrateParser(jobs.CopyParser), (nameServer, prioritizingScheduler(Priority.Medium.id)))
+ val createJobParser = new BoundJobParser(jobs.CreateParser, forwardingManager)
+ val destroyJobParser = new BoundJobParser(jobs.DestroyParser, forwardingManager)
+ polymorphicJobParser += ("Copy".r, copyJobParser)
+ polymorphicJobParser += ("Migrate".r, migrateJobParser)
+ polymorphicJobParser += ("Create".r, createJobParser)
+ polymorphicJobParser += ("Destroy".r, destroyJobParser)
val rowzService = new RowzService(forwardingManager, prioritizingScheduler, new IdGenerator(config("host.id").toInt))
@@ -2,32 +2,34 @@ package com.twitter.rowz.jobs
import com.twitter.gizzard
import Shard.Cursor
+import com.twitter.gizzard.nameserver.NameServer
+import com.twitter.gizzard.scheduler.JobScheduler
import com.twitter.xrayspecs.TimeConversions._
-object Copy {
+object CopyFactory extends gizzard.jobs.CopyFactory[Shard] {
val COUNT = 500
-}
-object CopyFactory extends gizzard.jobs.CopyFactory[Shard] {
- def apply(sourceShardId: Int, destinationShardId: Int) = new Copy(sourceShardId, destinationShardId, Shard.CursorStart)
+ def apply(sourceShardId: Int, destinationShardId: Int) = new Copy(sourceShardId, destinationShardId, Shard.CursorStart, COUNT)
}
-class Copy(sourceShardId: Int, destinationShardId: Int, cursor: Cursor, count: Int) extends gizzard.jobs.Copy[Shard](sourceShardId, destinationShardId, count) {
- def this(sourceShardId: Int, destinationShardId: Int, cursor: Cursor) = this(sourceShardId, destinationShardId, cursor, Copy.COUNT)
- def this(attributes: Map[String, AnyVal]) = {
- this(
- attributes("source_shard_id").toInt,
- attributes("destination_shard_id").toInt,
- attributes("cursor").toInt,
- attributes("count").toInt)
+object CopyParser extends gizzard.jobs.CopyParser[Shard] {
+ def apply(attributes: Map[String, Any]) = {
+ val casted = attributes.asInstanceOf[Map[String, AnyVal]]
+ new Copy(
+ casted("source_shard_id").toInt,
+ casted("destination_shard_id").toInt,
+ casted("cursor").toLong,
+ casted("count").toInt)
}
+}
+class Copy(sourceShardId: Int, destinationShardId: Int, cursor: Cursor, count: Int) extends gizzard.jobs.Copy[Shard](sourceShardId, destinationShardId, count) {
def serialize = Map("cursor" -> cursor)
def copyPage(sourceShard: Shard, destinationShard: Shard, count: Int) = {
val (items, nextCursor) = sourceShard.selectAll(cursor, count)
destinationShard.write(items)
- nextCursor.map(new Copy(sourceShardId, destinationShardId, _))
+ nextCursor.map(new Copy(sourceShardId, destinationShardId, _, count))
}
}
@@ -5,14 +5,16 @@ import com.twitter.xrayspecs.Time
import com.twitter.xrayspecs.TimeConversions._
-case class Create(id: Long, name: String, at: Time) extends UnboundJob[ForwardingManager] {
- def this(attributes: Map[String, AnyVal]) = {
- this(
- attributes("id").toLong,
- attributes("name").toString,
- Time(attributes("at").toInt.seconds))
+object CreateParser extends gizzard.jobs.UnboundJobParser[ForwardingManager] {
+ def apply(attributes: Map[String, Any]) = {
+ new Create(
+ attributes("id").asInstanceOf[Long],
+ attributes("name").asInstanceOf[String],
+ Time(attributes("at").asInstanceOf[Int].seconds))
}
+}
+case class Create(id: Long, name: String, at: Time) extends UnboundJob[ForwardingManager] {
def toMap = {
Map("id" -> id, "name" -> name, "at" -> at.inSeconds)
}
@@ -5,18 +5,20 @@ import com.twitter.xrayspecs.TimeConversions._
import com.twitter.gizzard.jobs.UnboundJob
-case class Destroy(row: Row, at: Time) extends UnboundJob[ForwardingManager] {
- def this(attributes: Map[String, AnyVal]) = {
- this(
+object DestroyParser extends gizzard.jobs.UnboundJobParser[ForwardingManager] {
+ def apply(attributes: Map[String, Any]) = {
+ new Destroy(
new Row(
- attributes("id").toLong,
- attributes("name").toString,
- Time(attributes("createdAt").toInt.seconds),
- Time(attributes("updatedAt").toInt.seconds),
- State(attributes("state").toInt)),
- Time(attributes("at").toInt.seconds))
+ attributes("id").asInstanceOf[Long],
+ attributes("name").asInstanceOf[String],
+ Time(attributes("createdAt").asInstanceOf[Int].seconds),
+ Time(attributes("updatedAt").asInstanceOf[Int].seconds),
+ State(attributes("state").asInstanceOf[Int])),
+ Time(attributes("at").asInstanceOf[Int].seconds))
}
+}
+case class Destroy(row: Row, at: Time) extends UnboundJob[ForwardingManager] {
def toMap = {
Map(
"id" -> row.id,
@@ -20,6 +20,8 @@ object RowzSpec extends Specification with Eventually {
val queryEvaluator = queryEvaluatorFactory("localhost", null, config("rowz.db.username"), config("rowz.db.password"))
doBefore {
+ queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.nameserver.name"))
+ queryEvaluator.execute("CREATE DATABASE " + config("rowz.nameserver.name"))
state.nameServer.rebuildSchema()
queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.db.name"))
@@ -27,6 +27,8 @@ object ShardManagerSpec extends Specification with Eventually {
var shardIdB = 0
doBefore {
+ queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.nameserver.name"))
+ queryEvaluator.execute("CREATE DATABASE " + config("rowz.nameserver.name"))
state.nameServer.rebuildSchema()
queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.db.name"))

0 comments on commit 5f7ec3f

Please sign in to comment.