Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

try locking explicitly

  • Loading branch information...
commit c2b966576c000be7dc51a6c5205381e58d63b072 1 parent 370df02
Kyle Maxwell authored
View
11 config/test.scala
@@ -23,8 +23,8 @@ class TestQueryEvaluator(label: String) extends QueryEvaluator {
// query.debug = DebugLog
database.memoize = true
database.pool = new ApachePoolingDatabase {
- sizeMin = 16
- sizeMax = 16
+ sizeMin = 2
+ sizeMax = 2
maxWait = 1.second
minEvictableIdle = 60.seconds
testIdle = 1.second
@@ -110,13 +110,12 @@ new FlockDB {
jobQueueName = name + "_jobs"
val schedulerType = new KestrelScheduler {
- path = "/tmp/" + System.currentTimeMillis
- new java.io.File(path).mkdir
- keepJournal = true
+ path = "/tmp"
+ keepJournal = false
maxMemorySize = 36000000L
}
- threads = 8
+ threads = 1
errorLimit = 25
errorRetryDelay = 900.seconds
errorStrobeInterval = 30.seconds
View
1  src/main/scala/com/twitter/flockdb/EdgesService.scala
@@ -122,6 +122,7 @@ class EdgesService(val nameServer: NameServer[shards.Shard],
}
private def countAndRethrow(e: Throwable) = {
+ e.printStackTrace
Stats.incr("exceptions-" + e.getClass.getName.split("\\.").last)
throw(new FlockException(e.getMessage))
}
View
29 src/main/scala/com/twitter/flockdb/shards/SqlShard.scala
@@ -138,8 +138,7 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
result + (if (state == State(row.getInt("state"))) row.getInt("count") else 0)
}
} getOrElse {
- populateMetadata(sourceId, Normal)
- count(sourceId, states)
+ 0
}
}
@@ -149,19 +148,12 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
}
}
- private def populateMetadata(sourceId: Long, state: State) { populateMetadata(sourceId, state, Time(0.seconds)) }
-
- private def populateMetadata(sourceId: Long, state: State, updatedAt: Time) {
- try {
- queryEvaluator.execute(
- "INSERT INTO " + tablePrefix + "_metadata (source_id, count, state, updated_at) VALUES (?, ?, ?, ?)",
- sourceId,
- computeCount(sourceId, state),
- state.id,
- updatedAt.inSeconds)
- } catch {
- case e: SQLIntegrityConstraintViolationException =>
- }
+ private def populateMetadata(sourceId: Long) {
+ queryEvaluator.selectOne(SelectModify, "SELECT GET_LOCK('" + tablePrefix + sourceId + "', 0.1)") { row => }
+ queryEvaluator.execute(
+ "INSERT IGNORE INTO " + tablePrefix + "_metadata (source_id, count, state, updated_at) VALUES (?, 0, 0, 0)",
+ sourceId)
+ queryEvaluator.selectOne(SelectModify, "SELECT RELEASE_LOCK('" + tablePrefix + sourceId + "')") { row => }
}
private def computeCount(sourceId: Long, state: State) = {
@@ -460,6 +452,7 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
}
} catch {
case e: MySQLTransactionRollbackException if (tries > 0) =>
+ println("dlock")
write(edge, tries - 1, predictExistence)
case e: SQLIntegrityConstraintViolationException if (tries > 0) =>
// temporary. until the position differential between master/slave is fixed, it's
@@ -561,7 +554,7 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
}
} catch {
case e: MissingMetadataRow =>
- populateMetadata(sourceId, Normal)
+ populateMetadata(sourceId)
atomically(sourceId)(f)
}
}
@@ -580,12 +573,13 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
}
} catch {
case e: MissingMetadataRow =>
- sourceIds.foreach { sourceId => populateMetadata(sourceId, Normal) }
+ sourceIds.foreach { sourceId => populateMetadata(sourceId) }
atomically(sourceIds)(f)
}
}
def writeMetadata(metadata: Metadata) {
+ println("bork")
try {
queryEvaluator.execute("INSERT INTO " + tablePrefix + "_metadata (source_id, count, state, " +
"updated_at) VALUES (?, ?, ?, ?)",
@@ -602,6 +596,7 @@ class SqlShard(val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardIn
}
def writeMetadata(metadatas: Seq[Metadata]) = {
+ println("bork")
if (!metadatas.isEmpty) {
try {
val query = "INSERT INTO " + tablePrefix + "_metadata (source_id, count, state, updated_at) VALUES (?, 0, ?, ?)"
View
2  src/test/scala/com/twitter/flockdb/integration/EdgesSpec.scala
@@ -61,7 +61,7 @@ class EdgesSpec extends IntegrationSpecification {
// 4. Play those two operations in the db out of order.
// 5. Observe that alice is unfortunately still in the normal state.
//
- flock.get_metadata(alice, FOLLOWS) mustEqual flockdb.Metadata(alice, State.Normal, 1, new Time(0)).toThrift
+ flock.get_metadata(alice, FOLLOWS) must eventually(be_==(flockdb.Metadata(alice, State.Normal, 1, new Time(0)).toThrift))
}
}
View
4 src/test/scala/com/twitter/flockdb/unit/SqlShardSpec.scala
@@ -113,8 +113,8 @@ class SqlShardSpec extends IntegrationSpecification with JMocker {
"when the state is given" >> {
"when no edges have been added beforehand and a non-normal state is given" >> {
shard.count(alice, List(State.Archived)) mustEqual 0
- val metadata = shard.getMetadata(alice).get
- metadata.state mustEqual State.Normal
+ // val metadata = shard.getMetadata(alice).get
+ // metadata.state mustEqual State.Normal
}
"when edges have been added beforehand" >> {
Please sign in to comment.
Something went wrong with that request. Please try again.