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

Commit

Permalink
set log level of optimism to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Maxwell committed Jan 19, 2011
1 parent bd14674 commit 8e8d633
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
6 changes: 3 additions & 3 deletions config/test.scala
Expand Up @@ -23,8 +23,8 @@ class TestQueryEvaluator(label: String) extends QueryEvaluator {
// query.debug = DebugLog
database.memoize = true
database.pool = new ApachePoolingDatabase {
sizeMin = 10
sizeMax = 10
sizeMin = 8
sizeMax = 8
maxWait = 1.second
minEvictableIdle = 60.seconds
testIdle = 1.second
Expand Down Expand Up @@ -115,7 +115,7 @@ new FlockDB {
maxMemorySize = 36000000L
}

threads = 4
threads = 2
errorLimit = 25
errorRetryDelay = 900.seconds
errorStrobeInterval = 30.seconds
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Expand Up @@ -3,6 +3,6 @@
project.organization=com.twitter
project.name=flockdb
sbt.version=0.7.4
project.version=1.5.1-mc-SNAPSHOT
project.version=1.5.1-optimism-SNAPSHOT
build.scala.versions=2.7.7
project.initialize=false
33 changes: 23 additions & 10 deletions src/main/scala/com/twitter/flockdb/shards/Optimism.scala
Expand Up @@ -2,6 +2,7 @@ package com.twitter.flockdb.shards

import com.twitter.gizzard.shards.ShardException
import com.twitter.util.Time
import net.lag.logging.Logger

class OptimisticLockException(message: String) extends ShardException(message)

Expand Down Expand Up @@ -54,21 +55,33 @@ class OptimisticLockException(message: String) extends ShardException(message)
trait Optimism extends Shard {
protected case class MetadataWithEx(metadata: Metadata, ex: Option[Throwable])

def optimistically(sourceId: Long)(f: State => Unit) = {
private val log = Logger.get(getClass.getName)

var before = getWinner(sourceId)
def optimistically(sourceId: Long)(f: State => Unit) = {
try {
log.debug("starting optimistic lock of " + shardInfo.id + " for " + sourceId)
var before = getWinner(sourceId)

f(before.metadata.state)
f(before.metadata.state)

// We didn't do this immediately, because we still want to propagate writes with best effort.
// We should reenqueue if the optimistic lock only covers a subset of the intended targets.
before.ex.foreach(throw _)
// We didn't do this immediately, because we still want to propagate writes with best effort.
// We should reenqueue if the optimistic lock only covers a subset of the intended targets.
before.ex.foreach(throw _)

var after = getWinner(sourceId)
after.ex.foreach(throw _)
var after = getWinner(sourceId)
after.ex.foreach(throw _)

if(before.metadata.state != after.metadata.state) {
throw new OptimisticLockException("Lost optimistic lock for " + sourceId + ": was " + before.metadata.state +", now " + after.metadata.state)
if(before.metadata.state != after.metadata.state) {
val message = shardInfo.id + " lost optimistic lock for " + sourceId + ": was " + before.metadata.state +", now " + after.metadata.state
log.debug(message)
throw new OptimisticLockException(message)
}
log.debug("successful optimistic lock of " + shardInfo.id + " for " + sourceId)
} catch {
case e: Throwable => {
log.debug("exception in optimistic lock of " + shardInfo.id + " for " + sourceId + ": " + e.getMessage)
throw(e)
}
}
}

Expand Down
Expand Up @@ -74,7 +74,7 @@ class OptimisticLockRegressionSpec extends IntegrationSpecification() {
var found = false
while (errors.size > 0) {
val job = errors.get.get.job
if (job.toString.indexOf("Lost optimistic lock") > 0) {
if (job.toString.indexOf("lost optimistic lock") > 0) {
found = true
}
job()
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/com/twitter/flockdb/unit/JobSpec.scala
Expand Up @@ -43,7 +43,7 @@ class IdentityShard[ConcreteShard <: Shard](shard: ConcreteShard)
extends ReadWriteShard[ConcreteShard] {
val children = Seq(shard)
val weight = 1
def shardInfo = throw new UnsupportedOperationException()
def shardInfo = new ShardInfo("a", "b", "c")

def readAllOperation[A](method: (ConcreteShard => A)) = FanoutResults(method, shard)
def readOperation[A](method: (ConcreteShard => A)) = method(shard)
Expand Down

0 comments on commit 8e8d633

Please sign in to comment.