[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Possible transaction issue with LMDB
- To: Леонид Юрьев <leo@yuriev.ru>
- Subject: Re: Possible transaction issue with LMDB
- From: William Brown <william@blackhats.net.au>
- Date: Fri, 17 Aug 2018 10:33:35 +1000
- Cc: openldap-technical@openldap.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= blackhats.net.au; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=qjEluV RIbVoKzv2ODbDCbNDHuOoZeUSE8fqxy+sw2F8=; b=kJul+nK39t16BHZ9Af1WnY Ft3YqdZY+E/gQjVcANbo9CubT6eMJNsZduRkWgQZVKcs6ePdwkbzn4JgQNTWw/Zb ItBcIugaKTqGJ17bbfm9W0PZk8sAK+ayTb5+g85MiE6qU4BRkHOSzbSMPXrYf+pY ordhlWZa0+exhjz9Gmyzjcl1F2eKZnmc42KV6xAuEeM8mHcEvR1/WoNZyZwiknMb Usm8EYUJjKOONJHI2B+A0NRnlnf1i+WojkwfwQR+JaF48tYGx6wdDG/edlADcZaL Hdy1pDBfgVR1a443fq7G66MHnKR0uWNQBQqcUpceYkymaAoATA7IR5DWLDQEZTDA ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=qjEluV RIbVoKzv2ODbDCbNDHuOoZeUSE8fqxy+sw2F8=; b=P0bQO/VOsxCj3AuBDN6XEk EXpTchg1evsvKEaZWZhDsSI3R6m146wvjgFwNz/hpFpUu+s2tuXQfFcztAKeZTJS mdi+r5vlt3ikDPYIi3pgIP9J0KaAYcpV8aIfUxHilov4Z5I1Yzj/q1cfqOTN6aFk Mo8MTwkJXVab7OU6SnquRD1P2/j2h3W2J0Z/ULolAQPwsnEHjSLtDez9lTs58SkG LhMTcX5NADPSZKgViogSCk80CjrqN3vgEVw+IgyYnV21PWPjLg3RrObmwe8Rkox4 KhrZeBKJgzbic7wM1KfLVgX9UnuDEnaOzmNTJhXCQmUgA0jYRKT90hVwdz/pgiFA ==
- In-reply-to: <CAO2+NUAxG_Ub1ww4t6pQy5DZG384G8odx8c8h-ZER47tCibwQQ@mail.gmail.com>
- References: <bc95677266fbeaba248f46fceffd4117ee3a88db.camel@blackhats.net.au> <CAO2+NUAxG_Ub1ww4t6pQy5DZG384G8odx8c8h-ZER47tCibwQQ@mail.gmail.com>
On Fri, 2018-08-17 at 01:34 +0300, Леонид Юрьев wrote:
> Hi,
>
> Shortly, no issue.
>
> LMDB provides MVCC via COW, therefore any read transaction see the
> constant snapshot of DB, which is correspond to last committed write
> transaction at the time when reading was started.
>
> Any further write transactions will create the new snapshots, which
> will be visible for further reading, but not for read transactions
> that was started before.
>
Hi,
I'm quite aware that it is COW - this issue is specific to COW trees.
Transactions must be removed in order, they can not be removed out of
order. It is about how pages are reclaimed for the freelist.
If you have tree state A, you have nodes say 1 through 4. We'll say 1
is the root, and 2 - 4 are the leaves.
We take the transaction at A.
Now we conduct a write with TXN X. We'll copy nodes 1 (r) and 4 to 5
(r) and 6 now and make our update. We now commit. At this point this is
the "last generation" where 1 and 4 exist.
We begin the transaction at B
Now we condact a write with TXN Y. We'll copy nodes 2, 3 and 5 (r). 5
Being the root from X, 2,3 still in use at A. We now commit.
We begin a read transaction C.
At this point we now close transaction B.
B now clears it's resources - Because B is the last location where 2,3
were "alive", they are at this point freed. however, they are *still
required* by TXN A for a valid and complete tree.
At this point, TXN A now consists of nodes 1, 4, and nodes 2,3 are on
the freelist where they are possibly able to be reused.
You begin a new write, and commit many values. This will over-write the
content of nodes 2,3 (as they are in the free list), causing the reader
of TXN A to now percieve invalid data.
I have previously seen this with my in-memory only tree, but I was able
to recreate this with LMDB. I'm not able to release the POC at this
time. The issue arises because transactions *must* be cleared in order
from oldest to newest, as a fundamental part of COW is the shared
resources, and understanding when node lifetimes expire.
I hope that this explains the issue more thoroughly.
> Regards,
> Leonid.
>
>
> 2018-08-16 13:03 GMT+03:00 William Brown <william@blackhats.net.au>:
> > Hi there,
> >
> > While doing some integration testing of LMDB I noticed that there
> > may
> > be an issue with out of order transaction handling.
> >
> > The scenario is:
> >
> > Open Read TXN A
> > Open Write TXN X, and change values of the DB
> > Commit X
> > Open Read TXN B
> > Open Write TXN Y, and change values of the DB
> > Commit Y
> > Open Read TXN C
> >
> > Abort/Close TXN B.
> >
> > At this point, because of the page touch between A -> B and B -> C,
> > B
> > now believes that the pages of A are the "last time" they are
> > available
> > as they were all subsequently copied for TXN C. The pages of A are
> > then
> > added to the freelists when B closes. When TXN A is read from the
> > data
> > may have been altered due to future writes as LMDB attempts to use
> > previously allocated pages first.
> >
> > This situation is more likely to arise on large batch writes, but
> > could
> > manifest with smaller series of writes. This would be a silent
> > issue,
> > as the over-written pages may be valid, and could cause data to
> > "silently vanish" inside of the read transaction A leading to
> > unpredictable results.
> >
> > I hope that this report helps you to diagnose and resolve the
> > issue.
> >
--
Sincerely,
William