Skip to content

Commit

Permalink
ISPN-810 - Treat Memcached flush_all delay same way as store commands
Browse files Browse the repository at this point in the history
Fixed by making sure flush_all delay is converted to milliseconds after
passing through the UNIX time check.
  • Loading branch information
galderz authored and Vladimir Blagojevic committed Dec 1, 2010
1 parent 555530b commit 2bcc7d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Expand Up @@ -222,7 +222,7 @@ abstract class AbstractProtocolDecoder[K, V <: CacheValue] extends Decoder {
* Otherwise it's just considered number of seconds from
* now and it's returned in milliseconds unit.
*/
private def toMillis(lifespan: Int): Long = {
protected def toMillis(lifespan: Int): Long = {
if (lifespan > SecondsInAMonth) {
val unixTimeExpiry = TimeUnit.SECONDS.toMillis(lifespan) - System.currentTimeMillis
if (unixTimeExpiry < 0) 0 else unixTimeExpiry
Expand Down
Expand Up @@ -286,7 +286,7 @@ class MemcachedDecoder(cache: Cache[String, MemcachedValue], scheduler: Schedule
if (flushDelay == 0)
flushFunction(cache.getAdvancedCache)
else
scheduler.schedule(new DelayedFlushAll(cache, flushFunction), flushDelay, TimeUnit.SECONDS)
scheduler.schedule(new DelayedFlushAll(cache, flushFunction), toMillis(flushDelay), TimeUnit.MILLISECONDS)
if (params == None || !params.get.noReply) OK else null
}
case VersionRequest => new StringBuilder().append("VERSION ").append(Version.version).append(CRLF)
Expand Down
Expand Up @@ -337,7 +337,14 @@ class MemcachedFunctionalTest extends MemcachedSingleNodeTest {
}
}

def testFlushAllDelayed(m: Method) {
def testFlushAllDelayed(m: Method) = flushAllDelayed(m, 2, 2200)

def testFlushAllDelayedUnixTime(m: Method) {
val delay: Int = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis + 2000).asInstanceOf[Int]
flushAllDelayed(m, delay, 2200)
}

private def flushAllDelayed(m: Method, delay: Int, sleep: Long) {
for (i <- 1 to 5) {
val key = k(m, "k" + i + "-");
val value = v(m, "v" + i + "-");
Expand All @@ -346,10 +353,10 @@ class MemcachedFunctionalTest extends MemcachedSingleNodeTest {
assertEquals(client.get(key), value)
}

val f = client.flush(2);
val f = client.flush(delay);
assertTrue(f.get(timeout, TimeUnit.SECONDS).booleanValue)

sleepThread(2200);
sleepThread(sleep);

for (i <- 1 to 5) {
val key = k(m, "k" + i + "-");
Expand Down

0 comments on commit 2bcc7d7

Please sign in to comment.