On Sat, Jan 31, 2009 at 5:25 AM, Emmanuel Lecharny <elecharny@apache.org> wrote:
Alex Karasulu wrote:
Hi all,

Emmanuel and I were having an interesting conversation about the kinds of
transaction properties needed by ApacheDS to comply with various
specification requirements. For example all LDAP operations must be atomic
and must preserve consistency. Furthermore, one can easily debate the need
for isolation where any operation does not see or get impacted by the
partial changes of another concurrent operation.

We started discussing these ACID properties and ways in which they could be
implemented. Isolation is very interesting now thanks to directory
versioning and the change log. We can easily implement isolation now. When a
relatively lengthy operation like a search is being conducted, it should not
see modifications within scope that occur after the search began. The search
operation in the example can be replaced with any other operation minus all
unbind, some extended, and all abandon requests.
 
Atomicity and Isolation are both complex to guarantee in a LDAP server.

If we think about Atomicity, for instance, even if we can guarantee it somehow for somesimple operation like Modify, Add or Delete, for the ModDN operation is not that simple. We have to guarantee that all the potential renames are done - or reverted - as a whole.

Yep. I was thinking about this exact example and how the modifyDn operation could potentially change a lot of descendants.
 
As this operation can impact a big part of the server, and could take several seconds (minutes, hours, dependening on the number of entries), this is obviously not trivial. However, moddn operation aren't the most frequent one. Regarding the most simpler operation (add, delete and modify), I think we should implement some kind of "transaction" in the backend : the modified entry has to be tagged as 'under modification' until the backend has updated correctly the modification (or rollbacked it).

Well I'd like to avoid using the partition to implement something like this since it is not a generalized solution.  When this capability is pushed into a partition then all implementations will need to implement it their own way. Partitions are already complicated to implement so adding this requirement on top can make it overwhelming.  We want people to be able to make partitions for whatever data they want to present through LDAP to create a rich environment for choosing different partitions.

For example JDBM offers transactions. We could have piggy backed on this feature to provide ACID properties under JDBM. Their are some quirks though with how JDBM does this but it can be leveraged.  I decided a while back while implementing the partition not to do this because I wanted the transaction management to be handled above the partitions.
 
Then we can untag the entry, and it's available back. How the CL can come into play here is to be discussed. IMHO, the CL and this 'transaction' will work hand to hand at some point.

Yes although I don't know how yet I agree that the CL is key here.  Perhaps we need to build a transaction manager on top of the CL that handles and tracks these things as well as manages the transactions. The tracking of a transaction context, it's commit, or rollback is all up to a transaction manager.  The CL is just there for history and logging and is something the transaction manager uses as a tool to do it's job.
 

Regarding isolation, it's a bit more difficult, as a search can already have sent back some results which could be change by another modify operation. This is especially the case for a ModDN operation.

The change log, not only tracks each change, but it allows the directory
server to inject the "revisions" attribute into entries. The revisions
attribute is multi-valued and lists all the revisions of changes which
altered the entry. For the search example, we can conduct the search
operation while locking it down to a revision.
That does not work for deleted entries, obviously ...

Sure it can work for deletes.  You must have wrote this without reading further.  Basically according to the change log, any entries with changes after time S when search began are evaluated to see if they should be included or removed from the result set returned by the search operation.  You don't just let search produce candidates returning all and forgetting about the changes that occurred after the search began.
 

 This is best implemented by
conditionally filtering out or injecting candidates with revisions greater
than the revision at which the search operation started. Let's call the
revision when search started S. So entries in the server which posses
revision numbers greater than S need further evaluation. We have to evaluate
if the filter matches these entries with revisions > S when their state was
at revision S. This may require some reverse patching and re-evaluation of
the filter on the patched entry in state S.  This is not so bad because
there usually are not that many changes taking place at the same time on the
same entry: meaning the number of LDIF's to patch on an entry to evaluate in
it's former state at S will be small. This way we effectively lock down the
search to a specific revision, giving the search operation what appears to
be a snapshot of the DIT. The search results will not be impacted by any
concurrent changes.
 
Well, I don't think this is the best approach. In any case, a Ldap Search is considered as a dirty read. We have no way to lock down the modification on the read entries. So the user has _no_ guarantee that the entry he gets back will be valid. Usually, it doesn't matter, because the ratio of read vs writes on a LDAP server is just so big that we consider we don't have modifications. So we can simply return the latest revision, whatever it is. Anyway, there is another aspect we have to consider : once the user gets his entry, and before he uses it, before potentially send it back as a modification to the server, the very same entry can have been modified in between. As we don't lock entries, we can't protect the users from such a case.

The point is, the search should be conducted as if it were performed on a snapshot of the DIT at the time the search was issued.  Now if you get dirty reads then you can have inconsistent views of the information which is rare yes but possible.

The beauty of this approach is that it allows us to search the DIT at an time not just when the search occurred (time S as stated above).  This actually allows us to for example to implement a "search in the past" control where the user can conduct a search on the server at an earlier time.  This is insanely powerful in terms of being able to have versioned views in the server of information.  Say you have some application's configuration in the DIT and you locked the appilcation down to read at some time/rev associated with a release date for the application.  So the application pulls it's configs from the DS with this control. Then you continue making changes to the configuration data as you change the application in developement. You can setup and run both the production application and the development application but using different revisions when performing the lookups. 

The power this provides for configuration management is awesome to say the least.  Now I am digressing.
 


<digression>
We have to remember here that we are not dealing with bank accounts and balances, or nuclear plants. Most of the case, we are using a LDAP server to handle identities. They rarely change, or when they do, it's because the person owning this identity is changing his own identity - thus limitating the odds that he is using it at the same time -. Usually, if we think about authorizations, which are subject to way more changes that identities, we can't consider it as a continuous flow of modification.

Yes yes I think you know that I would know this :-). However we're just thinking about these features.  We have to know how much of a bitch it is by going into the details then stepping back and looking at the big picture.  Finished reading the digression and I think we've told each other this several times before in the past.

I used to think this way a lot but there are several things that have impacted my views.  For example we need atomicity period which is a bigger deal with moddn.  Also with triggers we need atomicity badly too.  These are protocol requirements and there's no arguing with that. To do all this we're going to need a transaction manager that can begin, commit or rollback sets of changes to the DIT.
 


In other words, creations or deletion of entries might be frequent, modification should be quite rare.

In today's day and age directories are being used in a myriad of ways - especially after the identity buzz. I don't think we can be as comfortable generalizing the scenario to expect as much as we used to.
 


I have gathered some stats from some of my clients, and the ration changes/reads is like 1/5000... I would be interested to get more numbers here !

Last, not least, I consider that if the ratio goes up to something like 1/100, then it's time to consider using a transactional system, namely, a RDBMS.

Yeah stats are good but we need a lot of them from different industries to understand this picture.
 

</digression>

So far, I'm not saying that it's wrong to think about using a MVCC system, but I'm a bit sceptic about the gain in term of isolation (the I in ACID) it will offer in our case.

We're doing it somewhat today just not going all the way. This whole versioning facility is the basis for it.  I don't think I understand why you're skeptical. I hope to explore how this sense is coming to you because maybe you have a seriously important reason behind it and just are not vocalizing it.

Thanks,
Alex