Hi Alfonso,

I'm afraid for expire functionality, you would be looking at some caching solution, in Java for example you could use Guava or EHCache if running in the same JVM, if you need a distributed cache then memcached would be the right thing to use, now, if you need search AND expire documents, you could use ElasticSearch or Solr (If solr then version 4.0.0.BETA+)

Regards,

Guido.

On 28/09/12 11:19, Nico Meyer wrote:
Hi Alfonso,

there simply is no connection between bitcasks key expiration feature and the rest of Riak, including the search. To say it bluntly, Riak has no 'real' key expiration that would work like one would naively expect. That is, like someone magically coming along and issuing a full fleged delete for each expired key. In reality, bitcask just 'forgets' keys after they are expired, which to the rest of the system looks like someone just tinkered directly with the disk.

Cheers,
Nico

Am 28.09.2012 11:22, schrieb Alfonso De Gregorio:
Hi All,

I would like to store ephemeral objects in Riak, while retaining the
ability to search among them before they expire. So far, I had no
luck.

When I query the cache with the ephemeral objects, Riak Search returns
the expired entries among the matches. AFAICT, it correctly indexes
the entries at pre-commit time but don't update the index at key
expiration time.

I've tried rebuilding the index but, sadly, it didn't helped and, even
if it would, the rebuild frequency would make the workaround too slow
for any short lived data.

Am I missing something? Probable. Any clues?

Here is what I have done, so you can try to reproduce this behaviour
-- running Riak 1.2.0 on Ubuntu 12.04.1 LTS:

1. Configured Riak to use multi_backend to have both expiring and
normal persistent data

             {storage_backend, riak_kv_multi_backend},
             {multi_backend_default, <<"default">>},
             {multi_backend, [
                 {<<"default">>, riak_kv_bitcask_backend, []},
{<<"cache">>, riak_kv_bitcask_backend, [{expiry_secs, 60}]}
                     ]},

2. Enabled search functionality, setting riak_search to 'true'

3. Set up index for the cache bucket

$ search-cmd install cache


4. Cached some JSON encoded data

$ curl -v -X PUT -H "Content-Type: application/json" --data-binary
@./data http://localhost:8098/riak/cache/key1
$ curl -v -X PUT -H "Content-Type: application/json" --data-binary
@./data http://localhost:8098/riak/cache/key2

5. Waited the expiration of the first key

6. Searched

$ sudo search-cmd search cache "name:\"Alyssa\""

Attempting to restart script through sudo -H -u riak

  :: Searching for 'name:"Alyssa"' / '' in cache...

------------------------------

index/id: cache/key1
p -> [0]
score -> 0.35355339059327373

------------------------------

index/id: cache/key2
p -> [0]
score -> 0.35355339059327373

------------------------------

  :: Found 2 results.


7.  Retrieved the keys

$ curl http://localhost:8098/riak/cache/key1
not found

$ curl http://localhost:8098/riak/cache/key2
{
  "name":"Alyssa P. Hacker",
  "bio":"I'm an engineer, making awesome things.",
  "favorites":{
               "book":"The Moon is a Harsh Mistress",
               "album":"Magical Mystery Tour"
              }
}


8. Tried the Solr-like interface -- it reports the presence of two
matching keys and return (of course) only the one not expired yet

$ curl "http://localhost:8098/solr/cache/select?start=0&rows=10000&q=name:\"Alyssa\"";
...
   <result name="response" numFound="2" start="0" maxScore="0.353553">
     <doc>
       <str name="id">key2
       </str>
       <str name="bio">I'm an engineer, making awesome things.
       </str>
       <str name="favorites_album">Magical Mystery Tour
       </str>
       <str name="favorites_book">The Moon is a Harsh Mistress
       </str>
       <str name="name">Alyssa P. Hacker
       </str>
     </doc>
   </result>


9. Rebuild the index

$ riak attach
{ok, Ring} = riak_core_ring_manager:get_my_ring().
Partitions = [P || {P, '[email protected]'} <- riak_core_ring:all_owners(Ring)].
[riak_kv_vnode:repair(P) || P <- Partitions].
10. Searched again, getting the same results as above



Thank you.

Cheers,





_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to