[ejabberd] gen_storage API Questions

Badlop badlop at gmail.com
Thu Jan 6 22:36:39 MSK 2011


2011/1/6 W. Andrew Loe III <andrew at andrewloe.com>:
> I'm working on modifying mod_muc_room to log each message to a table
> (muc_message). I have been able to get messages logged but am stuck on
> the different table types (bag vs set). It seems like both of them are
> not what I want,

You defined:
> -record(muc_message, {name_host,
>     jid,
>     nick,
>     message,
>     contents
>   }).

The first element in the tuple is name_host.
This means the primary key will be: the roomname + the MUC host.

When using the "set" table type,
you can only keep 1 single element in the table for each
pair roomname+host.
If you want to keep more, then include in the key a unique identifier,
like the timestamp (not in seconds, better in microseconds to be mostly unique).

When using the "bag" table type,
you can have multiple elements in the table with identical keys.
In your case, that should work.


>  I need to just insert new records without deleting
> one first, do I really want dirty_write here?

In your case I think a transaction isn't needed, and dirty_write is enough.

The attached patch follows the Bag idea, tested to work with mnesia and odbc.
After that patch, you probably want to add a 'timestamp' column in that table.
Notice that your muc_message table is conceptually similar to offline_msg.
Check mod_offline.erl in case of doubts.


> Also, why does gen_storage_odbc always do DELETE + INSERT vs UPDATE?,
> this negates any performance optimizations the SQL engine may be able
> to do on UPDATES.

gen_storage_odbc doesn't have an UPDATE function.
gen_storage_odbc is a particular version of gen_storage.
gen_storage doesn't have an UPDATE function.
gen_storage keeps most API from mnesia.
mnesia doesn't have an UPDATE function.

If a backend could benefit from adding a specific function (like SQL
with UPDATE),
such function can be added to gen_storage.
How many instances of delete+insert are there in ejabberd master code?


---
Badlop
ProcessOne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Get-the-nick-and-stanza-for-text-messages-and-make-t.patch
Type: text/x-patch
Size: 2831 bytes
Desc: not available
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20110106/d1549bcb/attachment.bin>


More information about the ejabberd mailing list