Permalink
Browse files

Merge branch 'tracingfix'

Conflicts:
	querulous-core/src/main/scala/com/twitter/querulous/config/AsyncQueryEvaluator.scala
  • Loading branch information...
2 parents defba76 + 93bc8f0 commit fbc0a343537e7552d857bfb7f69b0b34b2ad8906 @freels freels committed Nov 22, 2011
View
1 querulous-core/src/main/scala/com/twitter/querulous/async/AsyncDatabase.scala
@@ -31,4 +31,5 @@ trait AsyncDatabaseFactory {
trait AsyncDatabase {
def withConnection[R](f: Connection => R): Future[R]
+ def shutdown() {}
}
View
2 querulous-core/src/main/scala/com/twitter/querulous/async/AsyncQueryEvaluator.scala
@@ -127,4 +127,6 @@ trait AsyncQueryEvaluator {
}
def transaction[T](f: Transaction => T): Future[T]
+
+ def shutdown()
}
View
7 querulous-core/src/main/scala/com/twitter/querulous/async/StandardAsyncQueryEvaluator.scala
@@ -8,7 +8,7 @@ import com.twitter.querulous.evaluator.{Transaction, ParamsApplier}
class StandardAsyncQueryEvaluatorFactory(
databaseFactory: AsyncDatabaseFactory,
- queryFactory: QueryFactory)
+ queryFactory: => QueryFactory)
extends AsyncQueryEvaluatorFactory {
def apply(
hosts: List[String],
@@ -77,6 +77,11 @@ extends AsyncQueryEvaluator {
database.withConnection { c => f(new Transaction(queryFactory, c)) }
}
+ def shutdown() {
+ queryFactory.shutdown()
+ database.shutdown()
+ }
+
// equality overrides
override def equals(other: Any) = other match {
View
12 querulous-core/src/main/scala/com/twitter/querulous/config/AsyncQueryEvaluator.scala
@@ -24,6 +24,14 @@ class AsyncQueryEvaluator {
private var memoizedFactory: Option[async.AsyncQueryEvaluatorFactory] = None
+ protected def newQueryFactory(stats: querulous.StatsCollector) = {
+ query(stats)
+ }
+
+ protected def newDatabaseFactory(stats: querulous.StatsCollector) = {
+ database(stats)
+ }
+
def apply(stats: querulous.StatsCollector): async.AsyncQueryEvaluatorFactory = {
synchronized {
if (!singletonFactory) memoizedFactory = None
@@ -44,10 +52,10 @@ class AsyncQueryEvaluator {
val db = new async.BlockingDatabaseWrapperFactory(
workP,
checkoutP,
- database(stats)
+ newDatabaseFactory(stats)
)
- Some(new async.StandardAsyncQueryEvaluatorFactory(db, query(stats)))
+ Some(new async.StandardAsyncQueryEvaluatorFactory(db, newQueryFactory(stats)))
}
memoizedFactory.get
View
1 querulous-core/src/main/scala/com/twitter/querulous/query/Query.scala
@@ -4,6 +4,7 @@ import java.sql.{ResultSet, Connection}
trait QueryFactory {
def apply(connection: Connection, queryClass: QueryClass, queryString: String, params: Any*): Query
+ def shutdown() = {}
}
trait Query {
View
16 ...lous-tracing/src/main/scala/com/twitter/querulous/config/TracingAsyncQueryEvaluator.scala
@@ -0,0 +1,16 @@
+package com.twitter.querulous.config
+
+import com.twitter.finagle.tracing
+import com.twitter.querulous
+import querulous.query.TracingQueryFactory
+
+class TracingAsyncQueryEvaluator extends AsyncQueryEvaluator {
+
+ var tracerFactory: tracing.Tracer.Factory = tracing.NullTracer.factory
+ var serviceName: String = ""
+
+ protected override def newQueryFactory(stats: querulous.StatsCollector) = {
+ new TracingQueryFactory(super.newQueryFactory(stats), serviceName, tracerFactory())
+ }
+
+}
View
16 querulous-tracing/src/main/scala/com/twitter/querulous/query/TracingQuery.scala
@@ -1,9 +1,9 @@
package com.twitter.querulous.query
import com.twitter.finagle.tracing.{Tracer, Annotation, Trace}
-import java.nio.ByteBuffer
import java.sql.Connection
import java.net.{UnknownHostException, InetSocketAddress, InetAddress}
+import java.nio.ByteBuffer
/**
* Adds trace annotations to capture data about the query.
@@ -31,11 +31,10 @@ class TracingQuery(query: Query, connection: Connection, queryClass: QueryClass,
// we want to know which query caused these timings
getRootQuery match {
case q: SqlQuery =>
- Trace.record(Annotation.BinaryAnnotation("querulous.query",
- ByteBuffer.wrap(q.query.getBytes())))
- Trace.recordRpcname(serviceName, queryClass.name)
+ Trace.record(Annotation.BinaryAnnotation("querulous.query", ByteBuffer.wrap(q.query.getBytes())))
case _ => ()
}
+ Trace.recordRpcname(serviceName, queryClass.name)
// send request and time it
Trace.record(Annotation.ClientSend())
@@ -46,11 +45,14 @@ class TracingQuery(query: Query, connection: Connection, queryClass: QueryClass,
}
}
-class TracingQueryFactory(queryFactory: QueryFactory, serviceName: String,
- tracerFactory: Tracer.Factory) extends QueryFactory {
+class TracingQueryFactory(queryFactory: QueryFactory,
+ serviceName: String,
+ tracer: Tracer) extends QueryFactory {
def apply(connection: Connection, queryClass: QueryClass, query: String, params: Any*) = {
new TracingQuery(queryFactory(connection, queryClass, query, params: _*),
- connection, queryClass, serviceName, tracerFactory())
+ connection, queryClass, serviceName, tracer)
}
+
+ override def shutdown() = { tracer.release() }
}

0 comments on commit fbc0a34

Please sign in to comment.