Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
create routing tree structure at object creation time, as opposed to
Browse files Browse the repository at this point in the history
query time

also fix exception handling from later versions of querlous.
  • Loading branch information
eaceaser committed Aug 31, 2011
1 parent fd865ed commit 4415315
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Expand Up @@ -3,6 +3,6 @@
project.organization=com.twitter
project.name=gizzard
sbt.version=0.7.4
project.version=3.0.0-beta7
project.version=3.0.0-beta7-SNAPSHOT
build.scala.versions=2.8.1
project.initialize=false
2 changes: 1 addition & 1 deletion project/build/GizzardProject.scala
Expand Up @@ -9,7 +9,7 @@ with SubversionPublisher {
override def filterScalaJars = false
val scalaTools = "org.scala-lang" % "scala-compiler" % "2.8.1"

val querulous = "com.twitter" % "querulous" % "2.3.8"
val querulous = "com.twitter" % "querulous-core" % "2.3.9-SNAPSHOT"

//val kestrel = "net.lag" % "kestrel" % "1.2.7"
// remove when moved to libkestrel
Expand Down
Expand Up @@ -3,7 +3,7 @@ package com.twitter.gizzard.proxy
import java.sql.SQLException
import scala.reflect.Manifest
import com.mysql.jdbc.exceptions.MySQLTransientException
import com.twitter.querulous.database.SqlDatabaseTimeoutException
import com.twitter.querulous.database.{PoolTimeoutException, PoolEmptyException, SqlDatabaseTimeoutException}
import com.twitter.querulous.query.SqlQueryTimeoutException
import com.twitter.querulous.evaluator.{QueryEvaluator, QueryEvaluatorProxy}
import com.twitter.gizzard.shards._
Expand All @@ -15,6 +15,10 @@ class SqlExceptionWrappingProxy(shardId: ShardId) extends ExceptionHandlingProxy
throw new ShardTimeoutException(e.timeout, shardId, e)
case e: SqlDatabaseTimeoutException =>
throw new ShardDatabaseTimeoutException(e.timeout, shardId, e)
case e: PoolTimeoutException =>
throw new NormalShardException(e.toString, shardId, e)
case e: PoolEmptyException =>
throw new NormalShardException(e.toString, shardId, e)
case e: MySQLTransientException =>
throw new NormalShardException(e.toString, shardId, null)
case e: SQLException =>
Expand All @@ -36,6 +40,10 @@ class SqlExceptionWrappingProxyFactory[T <: AnyRef : Manifest](id: ShardId) exte
throw new ShardTimeoutException(e.timeout, id, e)
case e: SqlDatabaseTimeoutException =>
throw new ShardDatabaseTimeoutException(e.timeout, id, e)
case e: PoolTimeoutException =>
throw new NormalShardException(e.toString, id, e)
case e: PoolEmptyException =>
throw new NormalShardException(e.toString, id, e)
case e: MySQLTransientException =>
throw new NormalShardException(e.toString, id, null)
case e: SQLException =>
Expand All @@ -58,6 +66,10 @@ class ShardExceptionWrappingQueryEvaluator(shardId: ShardId, evaluator: QueryEva
throw new ShardTimeoutException(e.timeout, shardId, e)
case e: SqlDatabaseTimeoutException =>
throw new ShardDatabaseTimeoutException(e.timeout, shardId, e)
case e: PoolTimeoutException =>
throw new NormalShardException(e.toString, shardId, e)
case e: PoolEmptyException =>
throw new NormalShardException(e.toString, shardId, e)
case e: MySQLTransientException =>
throw new NormalShardException(e.toString, shardId, null)
case e: SQLException =>
Expand Down
Expand Up @@ -52,8 +52,8 @@ class LeafRoutingNode[T](private[shards] val factory: ShardFactory[T], val shard
val children = Nil

// only one of these will usually be called.
lazy val readOnlyShard = factory.instantiateReadOnly(shardInfo, weight)
lazy val readWriteShard = factory.instantiate(shardInfo, weight)
val readOnlyShard = factory.instantiateReadOnly(shardInfo, weight)
val readWriteShard = factory.instantiate(shardInfo, weight)

override def shardInfos = Seq(shardInfo)

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/twitter/gizzard/shards/RoutingNode.scala
Expand Up @@ -37,6 +37,7 @@ abstract class RoutingNode[T] {
protected[shards] def collectedShards(readOnly: Boolean): Seq[Leaf[T]]

protected val log = Logger.get
protected val exceptionLog = Logger.get("exception")

def shardInfos: Seq[ShardInfo] = children flatMap { _.shardInfos }

Expand Down Expand Up @@ -107,7 +108,7 @@ abstract class RoutingNode[T] {
protected def logException(e: Throwable, shard: T, id: ShardId) {
val normalized = normalizeException(e, id)

log.warning(e, "Error on %s: %s", id, e)
exceptionLog.warning(e, "Error on %s: %s", id, e)
}

protected def normalizeException(ex: Throwable, shardId: ShardId): Throwable = ex match {
Expand Down
23 changes: 19 additions & 4 deletions src/test/scala/com/twitter/gizzard/nameserver/NameServerSpec.scala
Expand Up @@ -32,15 +32,26 @@ object NameServerSpec extends ConfiguredSpecification with JMocker with ClassMoc

val shard = mock[AnyRef]
var shardFactory = mock[ShardFactory[AnyRef]]
val nodes = shardInfos map { new LeafRoutingNode(shardFactory, _, 1) }
val replNode = ReplicatingShard(replicatingInfo, 1, Seq(nodes(3)))
var nodes: Seq[LeafRoutingNode[AnyRef]] = null
var replNode: ReplicatingShard[AnyRef] = null

doBefore {
expect {
one(nameServerShard).reload()
one(nameServerShard).currentState() willReturn Seq(nameServerState)
2.of(shardFactory).instantiateReadOnly(shardInfos(0), 1) willReturn shard
2.of(shardFactory).instantiate(shardInfos(0), 1) willReturn shard
2.of(shardFactory).instantiateReadOnly(shardInfos(1), 1) willReturn shard
2.of(shardFactory).instantiate(shardInfos(1), 1) willReturn shard
2.of(shardFactory).instantiateReadOnly(shardInfos(2), 1) willReturn shard
2.of(shardFactory).instantiate(shardInfos(2), 1) willReturn shard
2.of(shardFactory).instantiateReadOnly(shardInfos(3), 1) willReturn shard
2.of(shardFactory).instantiate(shardInfos(3), 1) willReturn shard
}

nodes = shardInfos map { new LeafRoutingNode(shardFactory, _, 1) }
replNode = ReplicatingShard(replicatingInfo, 1, Seq(nodes(3)))

nameServer = new NameServer(LeafRoutingNode(nameServerShard), identity)
forwarder = nameServer.configureMultiForwarder[AnyRef](
_.shardFactories(SQL_SHARD -> shardFactory)
Expand Down Expand Up @@ -87,8 +98,10 @@ object NameServerSpec extends ConfiguredSpecification with JMocker with ClassMoc
one(nameServerShard).listDownwardLinks(replicatingInfo.id) willReturn linksList
one(nameServerShard).getShard(shardInfos(3).id) willReturn shardInfos(3)
one(nameServerShard).listDownwardLinks(shardInfos(3).id) willReturn List[LinkInfo]()
never(shardFactory).instantiate(shardInfos(2), 1) willReturn shard
never(shardFactory).instantiate(shardInfos(3), 1) willReturn shard
one(shardFactory).instantiateReadOnly(shardInfos(2), 1) willReturn shard
one(shardFactory).instantiate(shardInfos(2), 1) willReturn shard
one(shardFactory).instantiateReadOnly(shardInfos(3), 1) willReturn shard
one(shardFactory).instantiate(shardInfos(3), 1) willReturn shard
}

forwarder.findShardById(shardInfos(2).id) mustEqual Some(nodes(2))
Expand All @@ -99,6 +112,8 @@ object NameServerSpec extends ConfiguredSpecification with JMocker with ClassMoc
val floatingShard = ShardInfo(ShardId("localhost", "floating"), SQL_SHARD, "a", "b", Busy.Normal)

expect {
2.of(shardFactory).instantiateReadOnly(floatingShard, 1)
2.of(shardFactory).instantiate(floatingShard, 1)
one(nameServerShard).getShard(floatingShard.id) willReturn floatingShard
one(nameServerShard).listDownwardLinks(floatingShard.id) willReturn List[LinkInfo]()
}
Expand Down

0 comments on commit 4415315

Please sign in to comment.