Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
collect per graph stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Liang committed Jan 10, 2012
1 parent d9f09a9 commit 8730216
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/scala/com/twitter/flockdb/EdgesService.scala
Expand Up @@ -47,14 +47,18 @@ class EdgesService(

def containsMetadata(sourceId: Long, graphId: Int): Boolean = {
rethrowExceptionsAsThrift {
Stats.transaction.name = "contains-metadata"
val name = "contains-metadata"
Stats.transaction.name = name
Stats.incr(name + "-graph_" + graphId)
forwardingManager.find(sourceId, graphId, Direction.Forward).getMetadata(sourceId).isDefined
}
}

def contains(sourceId: Long, graphId: Int, destinationId: Long): Boolean = {
rethrowExceptionsAsThrift {
Stats.transaction.name = "contains"
val name = "contains"
Stats.transaction.name = name
Stats.incr(name + "-graph_" + graphId)
forwardingManager.find(sourceId, graphId, Direction.Forward).get(sourceId, destinationId).map { edge =>
edge.state == State.Normal || edge.state == State.Negative
}.getOrElse(false)
Expand All @@ -63,7 +67,9 @@ class EdgesService(

def get(sourceId: Long, graphId: Int, destinationId: Long): Edge = {
rethrowExceptionsAsThrift {
Stats.transaction.name = "get"
val name = "get"
Stats.transaction.name = name
Stats.incr(name + "-graph_" + graphId)
forwardingManager.find(sourceId, graphId, Direction.Forward).get(sourceId, destinationId).getOrElse {
throw new FlockException("Record not found: (%d, %d, %d)".format(sourceId, graphId, destinationId))
}
Expand All @@ -72,7 +78,9 @@ class EdgesService(

def getMetadata(sourceId: Long, graphId: Int): Metadata = {
rethrowExceptionsAsThrift {
Stats.transaction.name = "get-metadata"
val name = "get-metadata"
Stats.transaction.name = name
Stats.incr(name + "-graph_" + graphId)
forwardingManager.find(sourceId, graphId, Direction.Forward).getMetadata(sourceId).getOrElse {
throw new FlockException("Record not found: (%d, %d)".format(sourceId, graphId))
}
Expand Down Expand Up @@ -101,6 +109,7 @@ class EdgesService(
rethrowExceptionsAsThrift {
queries.parallel(future).map { query =>
val term = query.term
Stats.incr("select-edge-graph_" + term.graphId)
val shard = forwardingManager.find(term.sourceId, term.graphId, Direction(term.isForward))
val states = if (term.states.isEmpty) List(State.Normal) else term.states

Expand Down
Expand Up @@ -51,9 +51,11 @@ class SelectCompiler(forwardingManager: ForwardingManager, intersectionConfig: c
if (items != 1) throw new InvalidQueryException("Left " + items + " items on the stack instaed of 1")

var stack = new mutable.Stack[QueryTree]
val graphIds = new mutable.HashSet[Int]
for (op <- program) op.operationType match {
case SelectOperationType.SimpleQuery =>
val term = op.term.get
graphIds += term.graphId
val shard = forwardingManager.find(term.sourceId, term.graphId, Direction(term.isForward))
val states = if (term.states.isEmpty) List(State.Normal) else term.states
val query = if (term.destinationIds.isDefined) {
Expand Down Expand Up @@ -84,6 +86,11 @@ class SelectCompiler(forwardingManager: ForwardingManager, intersectionConfig: c
})
}

// collect stats per graph
for (graphId <- graphIds) {
Stats.incr(name + "-graph_" + graphId);
}

Stats.transaction.record("Query Plan: "+rv.toString)
Stats.transaction.name = name
rv
Expand Down

0 comments on commit 8730216

Please sign in to comment.