[heketi-devel] To pass a *bolt.DB or a *bolt.Tx
Luis Pabon
lpabon at chrysalix.org
Fri Mar 10 06:02:12 UTC 2017
I think the key is to keep the transactions small. If you notice, a lot of
the volume allocations pass *db to the functions so they can use the db
when needed. Also, none of the calls in a Tx context call out to glusterfs
because it would be time consuming and single threaded. Instead state is
saved on the db, the tx is finished, and the work can the be started on
gluster. If there is an error or the db needs to be update, it will do it
after the completion of the work, which could have (and most likely was)
done in parallel.
I think for the PR proposed, the SetState() call could take *db instead of
*tx. If it is the simple ones (enable/disable) then the change can be
done, and the function returns.
If it is "remove", then state of the device in the db can be changed, then
db can be released and work can be started on that device. Then SetState()
can return to the asynchttp routine with a result. The key thing here is
that all bricks used to replace the bricks on the removed device where
replaced in parallel.
- Luis
On Thu, Mar 9, 2017 at 5:03 PM, Raghavendra Talur <rtalur at redhat.com> wrote:
> On Fri, Mar 10, 2017 at 3:21 AM, Michael Adam <obnox at samba.org> wrote:
> > Hi Talur,
> >
> > Thanks for this write-up!
> >
> > It sounds all very consistent.
> >
> > But I will want to thoroughly look at the code.
> > The Mutex thing sounds a bit like complete
> > serialization (for write processes).
>
> Yes, for small functions, this would completely serialize the
> goroutines and essentially we lose all the benefits. I could not come
> up with any better solution though.
>
>
> >
> > Cheers - Michael
> >
> > On 2017-03-10 at 02:03 +0530, Raghavendra Talur wrote:
> >> Here is what Bolt documentation says about transactions:
> >>
> >> ```
> >> Transactions
> >>
> >> Bolt allows only one read-write transaction at a time but allows as
> >> many read-only transactions as you want at a time. Each transaction
> >> has a consistent view of the data as it existed when the transaction
> >> started.
> >>
> >> Individual transactions and all objects created from them (e.g.
> >> buckets, keys) are not thread safe. To work with data in multiple
> >> goroutines you must start a transaction for each one or use locking to
> >> ensure only one goroutine accesses a transaction at a time. Creating
> >> transaction from the DB is thread safe.
> >> ```
> >>
> >> Now, in heketi, there some operations at app.* level that might have
> >> to view/update many buckets(node,brick,volumes,device). The methods of
> >> these objects take either a *bolt.Tx or a *bolt.DB.
> >>
> >> In my understanding, there are some app.* operations where it is a
> >> must that all the methods that are called within it, should get the
> >> same view of db; in that case, it makes sense that app.* function
> >> starts a tx and hands it down to the lower methods thereby ensuring a
> >> consistent view.
> >>
> >> Some methods however, like Create and Destroy methods of brick have
> >> been written to take a *bolt.DB as a argument. This seems to be done
> >> to enable use of goroutines. Now, we have functions in the higher
> >> layer calling these very methods which would want the operation to be
> >> done in the transaction created above.
> >>
> >> In PR #710 I have made two changes to tackle the above problem:
> >> 1. Changed these methods to take *bolt.Tx as arg instead of *bolt.DB
> >> 2. Introduce a sync.Mutex as another member of StatusGroup, any
> >> goroutines that want to operate on the db using a shared tx must call
> >> the new Lock() method of StatusGroup and call Unlock() after the db
> >> operation is done.
> >>
> >> In summary, as bolt documentation suggests, to work with data in
> >> multiple go routines:
> >> we used to: start a transaction for each one
> >> now we do: mutex locking to ensure only one goroutine accesses a
> >> transaction at a time
> >>
> >> If there are better ideas, they are most welcome.
> >>
> >> Thanks,
> >> Raghavendra Talur
> >> _______________________________________________
> >> heketi-devel mailing list
> >> heketi-devel at gluster.org
> >> http://lists.gluster.org/mailman/listinfo/heketi-devel
> _______________________________________________
> heketi-devel mailing list
> heketi-devel at gluster.org
> http://lists.gluster.org/mailman/listinfo/heketi-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gluster.org/pipermail/heketi-devel/attachments/20170310/f1394814/attachment-0001.html>
More information about the heketi-devel
mailing list