You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Jukka Zitting <ju...@gmail.com> on 2012/06/18 19:00:33 UTC
Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Hi,
Nice work pushing this ahead! Some design comments below.
On Mon, Jun 18, 2012 at 9:48 AM, <md...@apache.org> wrote:
> + /**
> + * Wait for changes to occur at {@code path} in the underlying repository.
> + * If {@code previous} is not {@code null} returns the {@link ChangeSet}
> + * instance following the one given in {@code previous}.
> + *
> + * @param path path to the subtree to watch for changes
> + * @param previous previous {@code ChangeSet} or {@code null}.
> + * @param timeout the maximum time to wait in milliseconds
> + * @return the next {@code ChangeSet} or {@code null} if a timeout occurred.
> + */
> + @CheckForNull
> + ChangeSet waitForChanges(String path, ChangeSet previous, long timeout);
I'd rather not introduce a blocking method and a new ChangeSet concept
for this. Instead, could we implement observation by polling the
latest state of the tree (or the journal) and using a tree diff to
deliver JCR-level events?
Ideally I'd make the ObservationManager in oak-jcr simply hook into
Session.refresh() and use a per-session background thread to
periodically trigger a new refresh(). Apart from the diff support we
shouldn't need any extra functionality from Oak API.
Stuff like user data and other event details may need more information
that's available in the default diff. We should look at whether we
really do need all that info, and if we do, what's the best way of
making it available through the Oak API. The cleaner and simpler we
can keep the Oak API the better.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 20.6.12 16:04, Julian Reschke wrote:
> On 2012-06-20 17:01, Michael Dürig wrote:
>> ...
>> ...
>> Spec. wise this is fine. Implementation wise I'm not convinced. Who
>> cares about the descriptors anyway ;-) Not even the TCK does... However
>> let's leave it at this for the time being. I think this feature is
>> rarely used if at all and we should concentrate on the important stuff
>> first.
>> ...
>
> I don't think it's fine spec-wise. I also recall using it in the
> remoting layer to get the "non-local" filtering mode working.
Don't quote me out of context ;-) I referred to
"If needed, we could propose to JSR 333 to relax the specified
observation contract or at to introduce more fine-grained descriptors
that allow an implementation like ours to declare at least some
observation functionality as supported."
wrt. this I meant it to be fine spec. wise.
Michael
>
> Best regards, Julian
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Julian Reschke <ju...@gmx.de>.
On 2012-06-20 17:01, Michael Dürig wrote:
> ...
> ...
> Spec. wise this is fine. Implementation wise I'm not convinced. Who
> cares about the descriptors anyway ;-) Not even the TCK does... However
> let's leave it at this for the time being. I think this feature is
> rarely used if at all and we should concentrate on the important stuff
> first.
> ...
I don't think it's fine spec-wise. I also recall using it in the
remoting layer to get the "non-local" filtering mode working.
Best regards, Julian
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 20.6.12 15:44, Jukka Zitting wrote:
> Hi,
>
> On Wed, Jun 20, 2012 at 3:40 PM, Michael Dürig<md...@apache.org> wrote:
>> Leaving userdata out works for me. Not sure what the "spec police" will say
>> though ;-)
>
> To pass the TCK without user data we'll need to set the observation
> supported descriptor to false. I'm OK with that as long as we still
> implement most of the JCR observation interfaces and document the less
> strict observation contract that we are supporting.
>
> If needed, we could propose to JSR 333 to relax the specified
> observation contract or at to introduce more fine-grained descriptors
> that allow an implementation like ours to declare at least some
> observation functionality as supported.
Spec. wise this is fine. Implementation wise I'm not convinced. Who
cares about the descriptors anyway ;-) Not even the TCK does... However
let's leave it at this for the time being. I think this feature is
rarely used if at all and we should concentrate on the important stuff
first.
>
>> I'd however like to keep a container for the events (i.e. trees before and
>> after). Currently this is called ChangeSet but I'm fine with a different
>> name.
>
> Would it be better to pass these things as arguments to a callback
> method instead of as a container object returned by a blocking method
> call? I find the blocking method a bit troublesome as it requires a
> separate thread for each listener.
The client controls blocking through the parameter it passes. So this
shouldn't be a big issue.
>
> As another design alternative, the Validator mechanism we have in
> .core.spi.state suggests a very similar Observer pattern (essentially
> just a Validator without the option of throwing
> CommitFailedExceptions) that could be used by a plugin to directly
> generate JCR-level observation events without having to go through the
> Tree abstraction in the Oak API. That would allow us to directly
> leverage the existing diffing tools and other machinery for
> NodeStates.
Sounds like an interesting idea. I'll try to come up with something
along these lines.
Michael
>
> BR,
>
> Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 20.6.12 16:03, Julian Reschke wrote:
> On 2012-06-20 16:44, Jukka Zitting wrote:
>> Hi,
>>
>> On Wed, Jun 20, 2012 at 3:40 PM, Michael Dürig <md...@apache.org>
>> wrote:
>>> Leaving userdata out works for me. Not sure what the "spec police"
>>> will say
>>> though ;-)
>>
>> To pass the TCK without user data we'll need to set the observation
>> supported descriptor to false. I'm OK with that as long as we still
>> implement most of the JCR observation interfaces and document the less
>> strict observation contract that we are supporting.
>>
>> If needed, we could propose to JSR 333 to relax the specified
>> observation contract or at to introduce more fine-grained descriptors
>> that allow an implementation like ours to declare at least some
>> observation functionality as supported.
>
> "The optimal number of optional features in an API/protocol is zero".
>
> Would it be possible to summarize what makes it hard to support userdata?
In a clustered environment where merges occur on cluster sync. How would
you transport the user data between cluster nodes? See Jukka's example
at the end of http://markmail.org/message/e4b4dzox2ta42qrw
Michael
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Julian Reschke <ju...@gmx.de>.
On 2012-06-20 16:44, Jukka Zitting wrote:
> Hi,
>
> On Wed, Jun 20, 2012 at 3:40 PM, Michael Dürig <md...@apache.org> wrote:
>> Leaving userdata out works for me. Not sure what the "spec police" will say
>> though ;-)
>
> To pass the TCK without user data we'll need to set the observation
> supported descriptor to false. I'm OK with that as long as we still
> implement most of the JCR observation interfaces and document the less
> strict observation contract that we are supporting.
>
> If needed, we could propose to JSR 333 to relax the specified
> observation contract or at to introduce more fine-grained descriptors
> that allow an implementation like ours to declare at least some
> observation functionality as supported.
"The optimal number of optional features in an API/protocol is zero".
Would it be possible to summarize what makes it hard to support userdata?
> ...
Best regards, Julian
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Mon, Jun 25, 2012 at 2:41 PM, Julian Reschke <ju...@gmx.de> wrote:
> Right now it seems the descriptor is set to true, right? (I see test failing
> that didn't before).
No, current Oak trunk reports "option.observation.supported" as false.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Julian Reschke <ju...@gmx.de>.
On 2012-06-20 16:44, Jukka Zitting wrote:
> Hi,
>
> On Wed, Jun 20, 2012 at 3:40 PM, Michael Dürig <md...@apache.org> wrote:
>> Leaving userdata out works for me. Not sure what the "spec police" will say
>> though ;-)
>
> To pass the TCK without user data we'll need to set the observation
> supported descriptor to false. I'm OK with that as long as we still
> implement most of the JCR observation interfaces and document the less
> strict observation contract that we are supporting.
Right now it seems the descriptor is set to true, right? (I see test
failing that didn't before).
I'd also like to point out again that the ability to add user data *is*
used in HTTP remoting (for the purpose of filtering events by session;
as far as I recall this is the case for journaled observation, would
have to check for "classic" observation).
Best regards, Julian
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Wed, Jun 20, 2012 at 3:40 PM, Michael Dürig <md...@apache.org> wrote:
> Leaving userdata out works for me. Not sure what the "spec police" will say
> though ;-)
To pass the TCK without user data we'll need to set the observation
supported descriptor to false. I'm OK with that as long as we still
implement most of the JCR observation interfaces and document the less
strict observation contract that we are supporting.
If needed, we could propose to JSR 333 to relax the specified
observation contract or at to introduce more fine-grained descriptors
that allow an implementation like ours to declare at least some
observation functionality as supported.
> I'd however like to keep a container for the events (i.e. trees before and
> after). Currently this is called ChangeSet but I'm fine with a different
> name.
Would it be better to pass these things as arguments to a callback
method instead of as a container object returned by a blocking method
call? I find the blocking method a bit troublesome as it requires a
separate thread for each listener.
As another design alternative, the Validator mechanism we have in
.core.spi.state suggests a very similar Observer pattern (essentially
just a Validator without the option of throwing
CommitFailedExceptions) that could be used by a plugin to directly
generate JCR-level observation events without having to go through the
Tree abstraction in the Oak API. That would allow us to directly
leverage the existing diffing tools and other machinery for
NodeStates.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 20.6.12 13:16, Jukka Zitting wrote:
> Hi,
>
> On Wed, Jun 20, 2012 at 1:26 PM, Michael Dürig<md...@apache.org> wrote:
>> Yes but... with and without such a lease mechanism my approach is more
>> general and doesn't hurt anything: if older revisions are available my
>> approach generates a more fine grained set of events. If older revisions are
>> not available any more it just gracefully degenerated to your approach. If
>> in the extreme only two revisions (last observed and latest) are available
>> it is the same as your approach.
>
> OK, I'm fine with that. This means basically that we don't make
> guarantees about things like user data, etc. Should we just drop them
> entirely instead of having a vague "they might be there but don't rely
> on it" contract?
Leaving userdata out works for me. Not sure what the "spec police" will
say though ;-)
I'd however like to keep a container for the events (i.e. trees before
and after). Currently this is called ChangeSet but I'm fine with a
different name. This is a place where related meta data lives:
timestamp, originating cluster node id, whether this change originated
from a sync or not, session id which generated this change, ... I can't
say which of these and in what form but I'm pretty sure we are going to
need a way to convey additional information to the client.
Michael
>
> BR,
>
> Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Wed, Jun 20, 2012 at 2:34 PM, Marcel Reutegger <mr...@adobe.com> wrote:
> how about going one step further and define some conditions
> where *no* observation of changes is possible?
>
> that would allow for lots of concurrent writes without worrying
> how to diff them or get them into a sequence.
The diffing part isn't a problem, as we already have that functionality.
The sequence part is trickier, but it shouldn't be an issue either if
we use the solution described in Michael's latest post.
BR,
Jukka Zitting
RE: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Marcel Reutegger <mr...@adobe.com>.
how about going one step further and define some conditions
where *no* observation of changes is possible?
that would allow for lots of concurrent writes without worrying
how to diff them or get them into a sequence.
in the JCR world that could be a mixin type, but IIUC oak doesn't
know what a mixin is. maybe path based?
regards
marcel
> On Wed, Jun 20, 2012 at 1:26 PM, Michael Dürig <md...@apache.org>
> wrote:
> > Yes but... with and without such a lease mechanism my approach is more
> > general and doesn't hurt anything: if older revisions are available my
> > approach generates a more fine grained set of events. If older revisions are
> > not available any more it just gracefully degenerated to your approach. If
> > in the extreme only two revisions (last observed and latest) are available
> > it is the same as your approach.
>
> OK, I'm fine with that. This means basically that we don't make
> guarantees about things like user data, etc. Should we just drop them
> entirely instead of having a vague "they might be there but don't rely
> on it" contract?
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Wed, Jun 20, 2012 at 1:26 PM, Michael Dürig <md...@apache.org> wrote:
> Yes but... with and without such a lease mechanism my approach is more
> general and doesn't hurt anything: if older revisions are available my
> approach generates a more fine grained set of events. If older revisions are
> not available any more it just gracefully degenerated to your approach. If
> in the extreme only two revisions (last observed and latest) are available
> it is the same as your approach.
OK, I'm fine with that. This means basically that we don't make
guarantees about things like user data, etc. Should we just drop them
entirely instead of having a vague "they might be there but don't rely
on it" contract?
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 20.6.12 11:35, Jukka Zitting wrote:
> Hi,
>
> On Tue, Jun 19, 2012 at 11:45 PM, Michael Dürig<md...@apache.org> wrote:
>> But this is no different with polling not backed by the Microkernel journal:
>> when a client takes a long time to digest changes this might cause the next
>> poll to be deferred so much that the relevant revisions are not available
>> any more.
>
> That's still a problem, but a somewhat different one (see the earlier
> discussion about revision lifetimes and leases). The changeset
> approach requires that *all* revisions since the last observed one are
> still available, whereas the polling approach just requires *two*
> revisions to be available: the last observed one and the very latest
> one.
Yes but... with and without such a lease mechanism my approach is more
general and doesn't hurt anything: if older revisions are available my
approach generates a more fine grained set of events. If older revisions
are not available any more it just gracefully degenerated to your
approach. If in the extreme only two revisions (last observed and
latest) are available it is the same as your approach.
>
> In a write-heavy deployment we could easily see hundreds of revisions
> per second. A system that wants to preserve the entire journal for
> even just an hour could face the need to keep track of something like
> a million revisions, potentially much more. I don't think that's a
> feasible approach at least as a general solution.
>
> There may well be deployments where we *do* want to keep detailed
> audit logs of everything anyone has done, but I'd rather handle that
> as an optional extension than a core part of the API.
>
>> There is a linear order of the events on each cluster node. The order is
>> just not the same for all of them. As I said, a cluster sync is just viewed
>> as changes applied by any other session. So its all in the journal.
>
> If you do view the cluster sync as a change applied by another
> session, then how do you handle user data and other event details from
> the potentially many changes that got applied by perhaps multiple
> different sessions on the other cluster node?
Just compare the states from before the sync and after the sync to
calculate the events. I wouldn't forward any user data from remote
sessions since I'd like to view cluster sync as changes applied by a
"sync" session which look just like any other session to the user.
In other words: the observable results should be the same like if a user
"sync" created a session and manually merged the differences of the
cluster nodes.
>
> For example, consider the following scenario with cluster nodes A and B:
>
> A: set property P from X to Y at time 1 with user data K
> B: set property P from X to Y at time 2 with user data L
> B: set property P from Y to Z at time 3 with user data M
> B: set property Q with user data N
>
> When A syncs with B, the resulting property P would presumably be set
> to Z (the only sane way of merging such changes), but which events and
> what user data will an observer on A see? Will user data L ever be
> seen by an observer on A? Will M? If yes, what is the sequence of
> property P changes seen by an observer on A: X -> Y -> Z or X -> Y, X
> -> Y -> Z?
The (imaginary) sync session for A would set P from Y to Z and set
property Q. A would observe X -> Y (its own change) and Y -> Z, setting
of Q (change by the sync session).
Michael
>
> BR,
>
> Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Tue, Jun 19, 2012 at 11:45 PM, Michael Dürig <md...@apache.org> wrote:
> But this is no different with polling not backed by the Microkernel journal:
> when a client takes a long time to digest changes this might cause the next
> poll to be deferred so much that the relevant revisions are not available
> any more.
That's still a problem, but a somewhat different one (see the earlier
discussion about revision lifetimes and leases). The changeset
approach requires that *all* revisions since the last observed one are
still available, whereas the polling approach just requires *two*
revisions to be available: the last observed one and the very latest
one.
In a write-heavy deployment we could easily see hundreds of revisions
per second. A system that wants to preserve the entire journal for
even just an hour could face the need to keep track of something like
a million revisions, potentially much more. I don't think that's a
feasible approach at least as a general solution.
There may well be deployments where we *do* want to keep detailed
audit logs of everything anyone has done, but I'd rather handle that
as an optional extension than a core part of the API.
> There is a linear order of the events on each cluster node. The order is
> just not the same for all of them. As I said, a cluster sync is just viewed
> as changes applied by any other session. So its all in the journal.
If you do view the cluster sync as a change applied by another
session, then how do you handle user data and other event details from
the potentially many changes that got applied by perhaps multiple
different sessions on the other cluster node?
For example, consider the following scenario with cluster nodes A and B:
A: set property P from X to Y at time 1 with user data K
B: set property P from X to Y at time 2 with user data L
B: set property P from Y to Z at time 3 with user data M
B: set property Q with user data N
When A syncs with B, the resulting property P would presumably be set
to Z (the only sane way of merging such changes), but which events and
what user data will an observer on A see? Will user data L ever be
seen by an observer on A? Will M? If yes, what is the sequence of
property P changes seen by an observer on A: X -> Y -> Z or X -> Y, X
-> Y -> Z?
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 19.6.12 18:10, Jukka Zitting wrote:
> Hi,
>
> On Tue, Jun 19, 2012 at 6:45 AM, Michael Dürig<md...@apache.org> wrote:
>> There is nothing which implies "creating" a ChangeSet instance for each
>> commit. The change sets are just implicitly there and can be retrieved with
>> instances of ChangeSet created on the fly by calling waitForChanges(). So no
>> queues. Consumers which use the blocking feature would just process a
>> backlog which they'd consume at their own pace. The backlog is *not*
>> represented by a queue but by a position (the previous parameter). Just like
>> polling only that the call would block if there is no next change set yet.
>
> You need to keep the sequence of events somewhere. Backing it with the
> MicroKernel journal is fine, but note that this implies that the
> journal might need to be unbounded or that observation listeners that
> can't keep up with the rate of incoming changes will start missing
> events. Neither seems like a very good alternative.
But this is no different with polling not backed by the Microkernel
journal: when a client takes a long time to digest changes this might
cause the next poll to be deferred so much that the relevant revisions
are not available any more.
>
>> My reasoning for this is - as I said earlier - that it allows us to
>> implement JCR journals (which has the concept of change sets through the
>> persist event) and also allows us to thread through userData and related
>> information.
>
> If we do want to support those features then I agree that something
> like what you propose is indeed needed. I'm questioning whether we
> really do need that information and if we're willing to pay the
> potentially heavy scalability and performance price that comes with
> tracking all that information.
>
>> In the clustered case I'd handle changed from a cluster sync like changes
>> from any other session. So to the end user changes occurring due to cluster
>> synchronisation do not look any different than changes made by another
>> session on the same instance.
>
> How would you order those changes? The keywords are "following" and
> "previous" in the javadoc snippet I quoted earlier. You can't simply
> treat them as changes that came "after" all local changes before the
> cluster sync, unless you're ready to abandon the useful feature of
> getTreeAfterChange() of one ChangeSet being the same tree as
> getTreeBeforeChange() of the "following" ChangeSet.
There is a linear order of the events on each cluster node. The order is
just not the same for all of them. As I said, a cluster sync is just
viewed as changes applied by any other session. So its all in the journal.
Michael
>
> BR,
>
> Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Tue, Jun 19, 2012 at 6:45 AM, Michael Dürig <md...@apache.org> wrote:
> There is nothing which implies "creating" a ChangeSet instance for each
> commit. The change sets are just implicitly there and can be retrieved with
> instances of ChangeSet created on the fly by calling waitForChanges(). So no
> queues. Consumers which use the blocking feature would just process a
> backlog which they'd consume at their own pace. The backlog is *not*
> represented by a queue but by a position (the previous parameter). Just like
> polling only that the call would block if there is no next change set yet.
You need to keep the sequence of events somewhere. Backing it with the
MicroKernel journal is fine, but note that this implies that the
journal might need to be unbounded or that observation listeners that
can't keep up with the rate of incoming changes will start missing
events. Neither seems like a very good alternative.
> My reasoning for this is - as I said earlier - that it allows us to
> implement JCR journals (which has the concept of change sets through the
> persist event) and also allows us to thread through userData and related
> information.
If we do want to support those features then I agree that something
like what you propose is indeed needed. I'm questioning whether we
really do need that information and if we're willing to pay the
potentially heavy scalability and performance price that comes with
tracking all that information.
> In the clustered case I'd handle changed from a cluster sync like changes
> from any other session. So to the end user changes occurring due to cluster
> synchronisation do not look any different than changes made by another
> session on the same instance.
How would you order those changes? The keywords are "following" and
"previous" in the javadoc snippet I quoted earlier. You can't simply
treat them as changes that came "after" all local changes before the
cluster sync, unless you're ready to abandon the useful feature of
getTreeAfterChange() of one ChangeSet being the same tree as
getTreeBeforeChange() of the "following" ChangeSet.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 18.6.12 23:16, Jukka Zitting wrote:
>> - ChangeSet is just a container carrying the trees as they where after and
>> before the change. So this is very close to the diffing approach you
>> describe only a bit more explicit. Also ChangeSet is the place where
>> additional information like change set meta data could live. I'm close to
>> certain that we will need something along these lines (i.e. userData,
>> timestamps, user who initiated that change, session id of the originating
>> session).
>
> The reason why I worry about the ChangeSet concept is that it implies
> that each commit() produces a separate ChangeSet that then gets
> delivered to each observation listener for processing. This is
> troublesome for two key reasons:
>
> 1) Performance: Consider a large cluster that supports lots of
> concurrent writes hitting all cluster nodes. We should be able to
> support at least hundreds or thousands of commits per second on such
> systems, and ideally the only limit here would be the amount of
> available hardware. With the ChangeSet concept each of those commits
> would result in a separate waitForChanges() return value, which would
> cause event queues to start growing indefinitely if any one of the
> listeners can't keep up with the stream of incoming changes. The
> poll+diff approach avoids that problem since a listener only sees the
> combined set of changes across the polling interval.
There is nothing which implies "creating" a ChangeSet instance for each
commit. The change sets are just implicitly there and can be retrieved
with instances of ChangeSet created on the fly by calling
waitForChanges(). So no queues. Consumers which use the blocking feature
would just process a backlog which they'd consume at their own pace. The
backlog is *not* represented by a queue but by a position (the previous
parameter). Just like polling only that the call would block if there is
no next change set yet.
> 2) Linearity: Our overall design explicitly allows concurrent commits
> that are only later merged together. This makes the concept of a
> "previous" or "following" ChangeSet somewhat troublesome. You could
> avoid that trouble by interpreting all concurrent commits from another
> cluster node as a singe merge ChangeSet, but then you already lose
> per-commit metadata. Again the poll+diff approach avoids this problem
> since it doesn't care how and from where changes entered the latest
> visible state of the tree.
I see. In your scenario you would return all changes (i.e. the diff of
the trees) between the last poll and this poll. In my scenario polling
would just follow the entries in the Microkernel journal and return the
changes (again as diff of the trees) of the revisions therein.
My reasoning for this is - as I said earlier - that it allows us to
implement JCR journals (which has the concept of change sets through the
persist event) and also allows us to thread through userData and related
information.
In the clustered case I'd handle changed from a cluster sync like
changes from any other session. So to the end user changes occurring due
to cluster synchronisation do not look any different than changes made
by another session on the same instance.
Different cluster nodes would see a different linear order of events and
even different events. The end result however would be the same for all
of them.
Michael
>
>> - The approach aligns neatly with the JCR features: implement observation
>> using blocking calls and implement journalling by using non blocking calls.
>
> There's no concept of blocking calls for observation in JCR.
>
> BR,
>
> Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Tue, Jun 19, 2012 at 4:56 AM, Thomas Mueller <mu...@adobe.com> wrote:
> So it seems a MongoDB MicroKernel could support such a feature. Whether or
> not this feature is needed (Jackrabbit 2.x doesn't have it) and whether
> this needs to be in the MicroKernel API is a different question.
Yep. I think it may be difficult for some potential MK backends to
provide the waitForCommit() functionality without polling. Thus it
might be useful for a MicroKernel implementation to rather provide an
(optional?) API for clients to listen to changes with a relaxed
contract that simply offers a "best effort" mechanism for notifying
the client of incoming changes.
A higher level component like JCR-level observation can hook to such
functionality when it's available, but could fall back to polling as
the default implementation and for use cases where immediate
observation is not desirable.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Thomas Mueller <mu...@adobe.com>.
Hi,
Thinking about this again, we would need MicroKernel.waitForCommit() only
to detect changes written by *another* process (another cluster node). A
process should be able to know what it changed itself, without polling,
and having to ask the MicroKernel instance :-)
I was wondering if MongoDB supports feature to avoid polling. What I found
is "Tailable Cursors":
http://www.mongodb.org/display/DOCS/Tailable+Cursors
http://www.shtylman.com/archives/217
So it seems a MongoDB MicroKernel could support such a feature. Whether or
not this feature is needed (Jackrabbit 2.x doesn't have it) and whether
this needs to be in the MicroKernel API is a different question.
Regards,
Thomas
On 6/19/12 9:27 AM, "Thomas Mueller" <mu...@adobe.com> wrote:
>Hi,
>
>>>- We can implement the polling approach (using a 0 timeout) but also
>>>have
>>> the option to do blocking. Since this can be directly delegated to the
>>> Microkernel (waitForCommit) the added complexity for this is minimal.
>>
>>The complexity is still there, it's just one level below. Personally
>>I'd rather drop the waitForCommit() method unless we really do have a
>>hard use case for that functionality.
>
>
>I believe waitForCommit() actually simplify things. It's not a hard use
>case, but from an architectural point of view the advantages of
>waitForCommit() are:
>
>
>- no need for polling, and configuring polling frequency
>- no need for callbacks
>- events are delivered as early as possible
>
>With polling, beside the obvious disadvantage that events are delivered
>(possibly a lot) later, polling also needs more CPU cycles, specially when
>there are multiple consumers. Also, because of the delayed event delivery,
>cache efficiency is reduced, further deceasing performance.
>
>Regards,
>Thomas
>
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Thomas Mueller <mu...@adobe.com>.
Hi,
>>- We can implement the polling approach (using a 0 timeout) but also have
>> the option to do blocking. Since this can be directly delegated to the
>> Microkernel (waitForCommit) the added complexity for this is minimal.
>
>The complexity is still there, it's just one level below. Personally
>I'd rather drop the waitForCommit() method unless we really do have a
>hard use case for that functionality.
I believe waitForCommit() actually simplify things. It's not a hard use
case, but from an architectural point of view the advantages of
waitForCommit() are:
- no need for polling, and configuring polling frequency
- no need for callbacks
- events are delivered as early as possible
With polling, beside the obvious disadvantage that events are delivered
(possibly a lot) later, polling also needs more CPU cycles, specially when
there are multiple consumers. Also, because of the delayed event delivery,
cache efficiency is reduced, further deceasing performance.
Regards,
Thomas
Re: Observation design (Was: svn commit: r1351414 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Mon, Jun 18, 2012 at 9:02 PM, Michael Dürig <md...@apache.org> wrote:
> - We can implement the polling approach (using a 0 timeout) but also have
> the option to do blocking. Since this can be directly delegated to the
> Microkernel (waitForCommit) the added complexity for this is minimal.
The complexity is still there, it's just one level below. Personally
I'd rather drop the waitForCommit() method unless we really do have a
hard use case for that functionality. The JCR spec doesn't mandate it.
> - With the polling approach we offload more complexity to the consumer of
> the API since one has to decide on a reasonable poll interval which might be
> a difficult trade off between latency and server load.
In my experience the client is usually in the best position to judge
how timely it needs the observation events to be. The majority of
observation use cases I know don't need immediate, sub-second
triggering of events. Poll intervals of once a second, once a minute
or once an hour are typically perfectly fine. In fact using blocking
calls for observation is even a bit troublesome as it can easily lead
to tricky race conditions when many listeners get triggered at exactly
the same time.
> - ChangeSet is just a container carrying the trees as they where after and
> before the change. So this is very close to the diffing approach you
> describe only a bit more explicit. Also ChangeSet is the place where
> additional information like change set meta data could live. I'm close to
> certain that we will need something along these lines (i.e. userData,
> timestamps, user who initiated that change, session id of the originating
> session).
The reason why I worry about the ChangeSet concept is that it implies
that each commit() produces a separate ChangeSet that then gets
delivered to each observation listener for processing. This is
troublesome for two key reasons:
1) Performance: Consider a large cluster that supports lots of
concurrent writes hitting all cluster nodes. We should be able to
support at least hundreds or thousands of commits per second on such
systems, and ideally the only limit here would be the amount of
available hardware. With the ChangeSet concept each of those commits
would result in a separate waitForChanges() return value, which would
cause event queues to start growing indefinitely if any one of the
listeners can't keep up with the stream of incoming changes. The
poll+diff approach avoids that problem since a listener only sees the
combined set of changes across the polling interval.
2) Linearity: Our overall design explicitly allows concurrent commits
that are only later merged together. This makes the concept of a
"previous" or "following" ChangeSet somewhat troublesome. You could
avoid that trouble by interpreting all concurrent commits from another
cluster node as a singe merge ChangeSet, but then you already lose
per-commit metadata. Again the poll+diff approach avoids this problem
since it doesn't care how and from where changes entered the latest
visible state of the tree.
> - The approach aligns neatly with the JCR features: implement observation
> using blocking calls and implement journalling by using non blocking calls.
There's no concept of blocking calls for observation in JCR.
BR,
Jukka Zitting
Re: Observation design (Was: svn commit: r1351414 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
api/ChangeSet.java api/ContentSession.java core/ContentSessionImpl.java)
Posted by Michael Dürig <md...@apache.org>.
On 18.6.12 18:00, Jukka Zitting wrote:
> Hi,
>
> Nice work pushing this ahead! Some design comments below.
>
> On Mon, Jun 18, 2012 at 9:48 AM,<md...@apache.org> wrote:
>> + /**
>> + * Wait for changes to occur at {@code path} in the underlying repository.
>> + * If {@code previous} is not {@code null} returns the {@link ChangeSet}
>> + * instance following the one given in {@code previous}.
>> + *
>> + * @param path path to the subtree to watch for changes
>> + * @param previous previous {@code ChangeSet} or {@code null}.
>> + * @param timeout the maximum time to wait in milliseconds
>> + * @return the next {@code ChangeSet} or {@code null} if a timeout occurred.
>> + */
>> + @CheckForNull
>> + ChangeSet waitForChanges(String path, ChangeSet previous, long timeout);
>
> I'd rather not introduce a blocking method and a new ChangeSet concept
> for this. Instead, could we implement observation by polling the
> latest state of the tree (or the journal) and using a tree diff to
> deliver JCR-level events?
>
> Ideally I'd make the ObservationManager in oak-jcr simply hook into
> Session.refresh() and use a per-session background thread to
> periodically trigger a new refresh(). Apart from the diff support we
> shouldn't need any extra functionality from Oak API.
>
> Stuff like user data and other event details may need more information
> that's available in the default diff. We should look at whether we
> really do need all that info, and if we do, what's the best way of
> making it available through the Oak API. The cleaner and simpler we
> can keep the Oak API the better.
Yes we could do that. However I think the approach I outlined has a
number of advantages which outweigh the additional complexity (which is
minimal btw):
- Observation is made explicit feature wise.
- We can implement the polling approach (using a 0 timeout) but also
have the option to do blocking. Since this can be directly delegated to
the Microkernel (waitForCommit) the added complexity for this is minimal.
- With the polling approach we offload more complexity to the consumer
of the API since one has to decide on a reasonable poll interval which
might be a difficult trade off between latency and server load.
- ChangeSet is just a container carrying the trees as they where after
and before the change. So this is very close to the diffing approach you
describe only a bit more explicit. Also ChangeSet is the place where
additional information like change set meta data could live. I'm close
to certain that we will need something along these lines (i.e. userData,
timestamps, user who initiated that change, session id of the
originating session).
- The approach aligns neatly with the JCR features: implement
observation using blocking calls and implement journalling by using non
blocking calls. Also it aligns neatly with the features of the
Microkernel: waitForCommit and getRevisionHistory.
Michael
>
> BR,
>
> Jukka Zitting