Saturday, November 21, 2009

Tokyo Cabient and rufus/tokyo table locking

This may be obvious but I just write it anyway.

It is from http://rufus.rubyforge.org/rufus-tokyo/Rufus/Tokyo/Table.html and what I tried out based on the information there.

1. When you instantiate Rufus::Tokyo::Table, it gets the default mode of :write and :create, which locks the table.

-> So instantiating another fails with "Rufus::Tokyo::TokyoError: (err 16) lock error".

2. If the mode is :read and 'f' (non blocking lock), multiple instances can be created and each can read.

-> But when one is with the mode :write and 'f' (non blocking lock), instantiating another with the mode :read and 'f' fails with "Rufus::Tokyo::TokyoError: (err 16) lock error".

3. When one is instantiated with the mode :write and 'f' (non blocking lock), instantiating another with the mode :read and 'e' (non locking) succeeds.

-> And you can read from either instances.

-> When you write a value with that first instance with the mode :write and 'f', you can read the value from that first instance. But in order to read the value from the other second instance with the mode :read and 'e', you have to first close it and instantiate a new one with the mode :read and 'e'. Otherwise, that second instance doesn't read the newly added value.

4. When multiple instances are instantiated in the same thread (e.g same Rails console), thread occurs with "Rufus::Tokyo::TokyoError: (err 1) threading error".

5. If table file is never created, the mode :create must be specified.

No comments: