Skip to content
This repository
Browse code

set log level of optimism to debug

  • Loading branch information...
commit 8e8d63348764eb333336d512423d03fcb4b86670 1 parent bd14674
authored
6  config/test.scala
@@ -23,8 +23,8 @@ class TestQueryEvaluator(label: String) extends QueryEvaluator {
23 23
 //  query.debug = DebugLog
24 24
   database.memoize = true
25 25
   database.pool = new ApachePoolingDatabase {
26  
-    sizeMin = 10
27  
-    sizeMax = 10
  26
+    sizeMin = 8
  27
+    sizeMax = 8
28 28
     maxWait = 1.second
29 29
     minEvictableIdle = 60.seconds
30 30
     testIdle = 1.second
@@ -115,7 +115,7 @@ new FlockDB {
115 115
       maxMemorySize = 36000000L
116 116
     }
117 117
 
118  
-    threads = 4
  118
+    threads = 2
119 119
     errorLimit = 25
120 120
     errorRetryDelay = 900.seconds
121 121
     errorStrobeInterval = 30.seconds
2  project/build.properties
@@ -3,6 +3,6 @@
3 3
 project.organization=com.twitter
4 4
 project.name=flockdb
5 5
 sbt.version=0.7.4
6  
-project.version=1.5.1-mc-SNAPSHOT
  6
+project.version=1.5.1-optimism-SNAPSHOT
7 7
 build.scala.versions=2.7.7
8 8
 project.initialize=false
33  src/main/scala/com/twitter/flockdb/shards/Optimism.scala
@@ -2,6 +2,7 @@ package com.twitter.flockdb.shards
2 2
 
3 3
 import com.twitter.gizzard.shards.ShardException
4 4
 import com.twitter.util.Time
  5
+import net.lag.logging.Logger
5 6
 
6 7
 class OptimisticLockException(message: String) extends ShardException(message)
7 8
 
@@ -54,21 +55,33 @@ class OptimisticLockException(message: String) extends ShardException(message)
54 55
 trait Optimism extends Shard {
55 56
   protected case class MetadataWithEx(metadata: Metadata, ex: Option[Throwable])
56 57
 
57  
-  def optimistically(sourceId: Long)(f: State => Unit) = {
  58
+  private val log = Logger.get(getClass.getName)
58 59
 
59  
-    var before = getWinner(sourceId)
  60
+  def optimistically(sourceId: Long)(f: State => Unit) = {
  61
+    try {
  62
+      log.debug("starting optimistic lock of " + shardInfo.id + " for " + sourceId)
  63
+      var before = getWinner(sourceId)
60 64
 
61  
-    f(before.metadata.state)
  65
+      f(before.metadata.state)
62 66
 
63  
-    // We didn't do this immediately, because we still want to propagate writes with best effort.
64  
-    // We should reenqueue if the optimistic lock only covers a subset of the intended targets.
65  
-    before.ex.foreach(throw _)
  67
+      // We didn't do this immediately, because we still want to propagate writes with best effort.
  68
+      // We should reenqueue if the optimistic lock only covers a subset of the intended targets.
  69
+      before.ex.foreach(throw _)
66 70
 
67  
-    var after = getWinner(sourceId)
68  
-    after.ex.foreach(throw _)
  71
+      var after = getWinner(sourceId)
  72
+      after.ex.foreach(throw _)
69 73
 
70  
-    if(before.metadata.state != after.metadata.state) {
71  
-      throw new OptimisticLockException("Lost optimistic lock for " + sourceId + ": was " + before.metadata.state +", now " + after.metadata.state)
  74
+      if(before.metadata.state != after.metadata.state) {
  75
+        val message = shardInfo.id + " lost optimistic lock for " + sourceId + ": was " + before.metadata.state +", now " + after.metadata.state
  76
+        log.debug(message)
  77
+        throw new OptimisticLockException(message)
  78
+      }
  79
+      log.debug("successful optimistic lock of " + shardInfo.id + " for " + sourceId)
  80
+    } catch {
  81
+      case e: Throwable => {
  82
+        log.debug("exception in optimistic lock of " + shardInfo.id + " for " + sourceId + ": " + e.getMessage)
  83
+        throw(e)
  84
+      }
72 85
     }
73 86
   }
74 87
 
2  src/test/scala/com/twitter/flockdb/integration/OptimisticLockRegressionSpec.scala
@@ -74,7 +74,7 @@ class OptimisticLockRegressionSpec extends IntegrationSpecification() {
74 74
       var found = false
75 75
       while (errors.size > 0) {
76 76
         val job = errors.get.get.job
77  
-        if (job.toString.indexOf("Lost optimistic lock") > 0) {
  77
+        if (job.toString.indexOf("lost optimistic lock") > 0) {
78 78
           found = true
79 79
         }
80 80
         job()
2  src/test/scala/com/twitter/flockdb/unit/JobSpec.scala
@@ -43,7 +43,7 @@ class IdentityShard[ConcreteShard <: Shard](shard: ConcreteShard)
43 43
   extends ReadWriteShard[ConcreteShard] {
44 44
   val children = Seq(shard)
45 45
   val weight = 1
46  
-  def shardInfo = throw new UnsupportedOperationException()
  46
+  def shardInfo =  new ShardInfo("a", "b", "c")
47 47
 
48 48
   def readAllOperation[A](method: (ConcreteShard => A)) = FanoutResults(method, shard)
49 49
   def readOperation[A](method: (ConcreteShard => A)) = method(shard)

0 notes on commit 8e8d633

Please sign in to comment.
Something went wrong with that request. Please try again.