Skip to content

Commit

Permalink
return SERVER ERROR when availability blocks an operation
Browse files Browse the repository at this point in the history
RB_ID=93662
  • Loading branch information
Stephan Zuercher committed Oct 26, 2012
1 parent 13cef6b commit bfb8217
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/scala/net/lag/kestrel/MemcacheHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class MemcacheHandler(
handle(request)
} catch {
case e: AvailabilityException =>
Future(new MemcacheResponse("ERROR") then Codec.Disconnect)
// kestrel-client ruby gem will retry (if configured) on SERVER_ERROR, but
// not on ERROR or CLIENT_ERROR
Future(new MemcacheResponse("SERVER_ERROR") then Codec.Disconnect)
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/test/scala/net/lag/kestrel/KestrelHandlerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,33 @@ class KestrelHandlerSpec extends Specification with JMocker with ClassMocker wit
}
}
}

"respect server status" in {
"by blocking get when reads are blocked" in {
withTempFolder {
queues = new QueueCollection(folderName, timer, scheduler, config, Nil, Nil)
val serverStatus = mock[ServerStatus]
val handler = new FakeKestrelHandler(queues, 10, Some(serverStatus))
expect {
one(serverStatus).blockReads willReturn true
}

handler.getItem("q", None, false, false) must throwAn[AvailabilityException]
}
}

"by blocking set when writes are blocked" in {
withTempFolder {
queues = new QueueCollection(folderName, timer, scheduler, config, Nil, Nil)
val serverStatus = mock[ServerStatus]
val handler = new FakeKestrelHandler(queues, 10, Some(serverStatus))
expect {
one(serverStatus).blockWrites willReturn true
}

handler.setItem("q", 0, None, Array[Byte](1,2,3,4)) must throwAn[AvailabilityException]
}
}
}
}
}
12 changes: 12 additions & 0 deletions src/test/scala/net/lag/kestrel/MemcacheHandlerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,18 @@ class MemcacheHandlerSpec extends Specification with JMocker with ClassMocker {
}
}

"availability exception returns SERVER_ERROR" in {
val serverStatus = mock[ServerStatus]
expect {
one(connection).remoteAddress willReturn address
one(serverStatus).blockReads willReturn true
}

val memcacheHandler = new MemcacheHandler(connection, queueCollection, 10, Some(serverStatus))

memcacheHandler(toReq("get q"))() mustEqual MemcacheResponse("SERVER_ERROR", None)
}

"unknown command" in {
expect {
one(connection).remoteAddress willReturn address
Expand Down

0 comments on commit bfb8217

Please sign in to comment.