[PATCHES] Convert gencache to dbwrap to enable mutexes

Michael Adam obnox at samba.org
Wed Jun 25 05:18:27 MDT 2014

On 2014-06-25 at 08:45 +0200, Stefan (metze) Metzmacher wrote:
> Am 24.06.2014 22:22, schrieb Christof Schmitt:
> > On Tue, Jun 24, 2014 at 12:43:54PM -0700, Christof Schmitt wrote:
> >> On Sat, Jun 21, 2014 at 10:20:44AM +0200, Stefan (metze) Metzmacher wrote:
> >>> Hi Christof,
> >>>
> >>>>> While having a look at it I may found a problem with mutexes and ctdb.
> >>>>>
> >>>>>         /* only pass through specific flags */
> >>>>>         tdb_flags &= TDB_SEQNUM|TDB_VOLATILE;
> >>>>>
> >>>>> in db_open_ctdb() seems to completely useless (or wrong).
> >>>>> ctdbd_db_attach() is called before and gets the raw value of tdb_flags.
> >>>>> It has only has effect for
> >>>>>
> >>>>>         db_ctdb->wtdb = tdb_wrap_open(db_ctdb, db_path, hash_size,
> >>>>>                                       lpcfg_tdb_flags(lp_ctx, tdb_flags),
> >>>>>                                       O_RDWR, 0);
> >>>>>
> >>>>> So I think we can just remove tdb_flags &= TDB_SEQNUM|TDB_VOLATILE; above
> >>>>> and let lpcfg_tdb_flags() remove TDB_MUTEX_LOCKING when adding TDB_NOMMAP.
> >>>>
> >>>> The two patches at the end of the changeset implement those changes.
> >>>
> >>> Thanks! I'll try an autobuild on a machine with mutex support next week.
> >>
> >> I just discovered another issue. gencache opens databases with CLEAR_IF_FIRST.
> >> That is not allowed with mutexes and it also triggers a warning in dbwrap when
> >> transactions are being used.
> >>
> >> The easiest option would be using dbwrap only for gencache_notrans.tdb and
> >> removing CLEAR_IF_FIRST for that database. For gencache.tdb, i am not sure how
> >> to handle the case when tdb_check fails without CLEAR_IF_FIRST.
> > 
> > Sorry for the confusion. CLEAR_IF_FIRST has to be set for mutexes. The
> > main issue is that transactions are not allowed in dbwrap if
> > CLEAR_IF_FIRST is set. My idea here is to adapt dwrap to only warn if
> > the database has been opened through db_open which allows the clustered
> > usage. Databases opened directly with dbwrap_local_open should still
> > allow transactions and CLEAR_IF_FIRST.
> Transactions are not allowed with mutexes if I remember correctly.

Generally, we try to implement the pattern that a
database with CLEAR_IF_FIRST does not use transactions.
For the gencache case, a transaction is used on gencache_notrans
(despite the name...:-) only in the stabilize operation that
stabilizes the contents throught to the persistent gencache.tdb.
It currently works like this:


where stabilize_fn does this on a record:

1. store it to or delete it from cache
   (depending on the timeout)
2. delete it from the cache_notrans

I'll think we should avoid the transaction here on
gencache_notrans, too, and I will provide a patch that
does it like this:


with stabilize_fn_mod doing only:
1. store it to or delete it from cache
   (depending on the timeout)

This should have the same effect without
using transactions on gencache_notrans.

This would allow to use mutexes correctly
on gencache_notrans. In order to convert
it to dbwrap, we need to add a means of
using allrecord lock via dbrwap (it does
currently not offer it).

Cheers - Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20140625/769993ed/attachment.pgp>

More information about the samba-technical mailing list