Skip to content

Commit

Permalink
Merge pull request foursquare#66 from heralight/patch-1
Browse files Browse the repository at this point in the history
Update docs/Indexing.md
  • Loading branch information
jliszka committed Sep 4, 2012
2 parents 137138b + f4b2508 commit 0035f0c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions docs/Indexing.md
Expand Up @@ -98,17 +98,17 @@ You can call either or both of these from the `validateQuery` and/or `validateMo
when your application boots, set up the hooks like so:

object MyQueryValidator extends QueryHelpers.DefaultQueryValidator {
override def validateQuery[M <: MongoRecord[M]](query: Implicits.GenericBaseQuery[M, _]) {
override def validateQuery[M](query: Query[M, _, _]) {
if (Props.mode != Props.RunModes.Production) {
MongoIndexChecker.validateIndexExpectations(query) &&
MongoIndexChecker.validateQueryMatchesSomeIndex(query)
}

override def validateModify[M <: MongoRecord[M]](modify: BaseModifyQuery[M]) {
override def validateModify[M](modify: ModifyQuery[M, _]) {
validateQuery(modify.query)
}

override def validateFindAndModify[M <: MongoRecord[M], R](modify: BaseFindAndModifyQuery[M, R]) {
override def validateFindAndModify[M, R](modify: FindAndModifyQuery[M, R]) {
validateQuery(modify.query)
}
}
Expand All @@ -118,14 +118,20 @@ when your application boots, set up the hooks like so:
When the index checker has something to warn about, it will call the `QueryHelpers.QueryLogger.logIndexMismatch` callback.
At foursquare we have implemented it like this:

override def logIndexMismatch(msg: => String) {
val stack = Utils.currentStackTrace()
val prefix = stack.indexOf("validateQuery(MongoSetup.scala") // a hack
override def logIndexMismatch(query: Query[_, _, _], msg: => String) {
val stack = currentStackTrace()
val prefix = stack.indexOf("validateQuery(YOURCLASSFILENAME.scala") // a hack
val trimmedStack = stack.drop(prefix).take(800)
LOG.warn(msg + " from " + trimmedStack)
if (services.exists(_.throttleService.throwOnQueryIndexMiss.isShown)) {
throw new Exception(msg)
}
}

def currentStackTrace() = {
val e = new Exception()
e.fillInStackTrace()
getStackTrace(e)
}


0 comments on commit 0035f0c

Please sign in to comment.