Skip to content

Commit

Permalink
Add timeouts to Redis OSeg.
Browse files Browse the repository at this point in the history
Add timeouts on Redis OSeg entries using Redis's EXPIRE command. Track
active object timeouts and refresh them after 1/2 TTL. The
implementation is a bit more complicated than it should be because
older versions of Redis's server a) don't have MULTI command support
for transactions and b) have a buggy EXPIRE command that doesn't
update the TTL if there already is one. The first issue isn't really
addressable, so you can just turn off transaction support with a flag,
but then the completion handlers are more complicated since the
responses look different in transaction and non-transaction modes. The
second issue is addressed by resetting the value as well, which resets
the expiry. Fixes #435.
  • Loading branch information
ewencp committed Aug 8, 2012
1 parent 7857742 commit 2f7af14
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 25 deletions.
6 changes: 5 additions & 1 deletion libspace/plugins/redis/PluginInterface.cpp
Expand Up @@ -44,6 +44,8 @@ static void InitPluginOptions() {
new OptionValue("host","127.0.0.1",Sirikata::OptionValueType<String>(),"Redis host to connect to."),
new OptionValue("port","6379",Sirikata::OptionValueType<uint32>(),"Redis port to connect to."),
new OptionValue("prefix","",Sirikata::OptionValueType<String>(),"Prefix for redis keys, allowing you to provide 'namespaces' so multiple spaces can share the same redis database."),
new OptionValue("ttl","60s",Sirikata::OptionValueType<Duration>(),"Duration for keys to remain valid in Redis before they are automatically removed in case of dead nodes. This is a tradeoff between having to refresh entries and how long it takes before an object identifier can be reclaimed after a server crashes."),
new OptionValue("transactions","true",Sirikata::OptionValueType<bool>(),"If false, disables transactions. This isn't really safe as you can fail between commands and get keys stuck, but it allows running against older versions of Redis. Since this isn't safe, transactions are turned on by default."),
NULL
);
}
Expand All @@ -55,8 +57,10 @@ static ObjectSegmentation* createRedisOSeg(SpaceContext* ctx, Network::IOStrand*
String redis_host = optionsSet->referenceOption("host")->as<String>();
uint32 redis_port = optionsSet->referenceOption("port")->as<uint32>();
String redis_prefix = optionsSet->referenceOption("prefix")->as<String>();
Duration redis_ttl = optionsSet->referenceOption("ttl")->as<Duration>();
bool redis_has_transactions = optionsSet->referenceOption("transactions")->as<bool>();

return new RedisObjectSegmentation(ctx, oseg_strand, cseg, cache, redis_host, redis_port, redis_prefix);
return new RedisObjectSegmentation(ctx, oseg_strand, cseg, cache, redis_host, redis_port, redis_prefix, redis_ttl, redis_has_transactions);
}

} // namespace Sirikata
Expand Down

0 comments on commit 2f7af14

Please sign in to comment.