Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 521660

Summary: Soundness of DeltaProcessor's basic design
Product: [Eclipse Project] JDT Reporter: Vladimir Piskarev <pisv>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.8   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/104065
Whiteboard: stalebug

Description Vladimir Piskarev CLA 2017-08-31 06:11:28 EDT
Hi,

Just to give you some background information, I'm the main developer of Eclipse Handly project, which aims to provide core building blocks and common infrastructure for handle-based language-specific models just like the Java model. (In fact, we're even using a backwards-compatible experimental fork of JDT Core based on Handly, as a proof of concept and a test workbench.) I'm currently working on a facility for model operations and event batching (something like JavaModelOperation). At first, I just wanted to copy the basic design used in JDT, but now have second thoughts about it.

As far as I understand it, the DeltaProcess is a per-thread object which, in effect, segregates model changes (represented as element deltas) by thread, thereby allowing model change events to be sent in the same thread where the change occurred. However, such design is counter to the notification strategy used by the Eclipse Platform resource model. Since the Java model sits on top of the resource model, this raises the question of soundness of the chosen design.

Let me try to explain it, starting from citing bug 306214 comment 4 by John Arthorne:

"In the end there are two possible event strategies here:

 1) Events are sent in the same thread where the change occurred. However, since changes can be interleaved across threads, the listener may receive change events out of order.

 2) Events are sent from any thread, but events are always sent in the order in which the change occurred.

Both strategies have pros and cons, but in the end we chose event order consistency over event thread consistency."

So, while the resource model chose the second strategy, the DeltaProcessor uses the first one. As far as I see, this means that the DeltaProcessor is prone to the following issues:

* Since changes can be interleaved across threads, the listener may receive change events out of order (which is not necessarily bad per itself, being just a design decision, but perhaps should have been communicated to clients more aggressively).

* There is a fundamental disagreement with the event strategy used by the underlying resource model. "You can never reliably predict what thread a given resource change notification will occur in" (to cite John Arthorne again). However, since the DeltaProcessor tries to merge the registered Java model deltas with the element delta translated from the resource delta, it implicitly expects to receive the resource change notification in the same thread that registered the Java model deltas (i.e. the thread in which the Java model operation occurred in). Clearly, this assumption is not correct and, in particular, may lead to lost of fine-grained deltas, which can be demonstrated with a test case (soon to be posted to Gerrit).

I understand that the DeltaProcessor is an old and complicated part of the JDT Core code base that presumably have served well enough, so probably this is a minor issue from the practical point of view and there may be no incentive to change the current design, especially since this might break existing clients. However, I would appreciate any comments. Perhaps some of the old-time committers could shed some light on why the DeltaProcessor had been designed in this particular way. I may well be missing something. Thank you!
Comment 1 Eclipse Genie CLA 2017-08-31 06:23:09 EDT
New Gerrit change created: https://git.eclipse.org/r/104065
Comment 2 Vladimir Piskarev CLA 2017-08-31 06:33:56 EDT
Added a test case demonstrating that fine-grained deltas may get lost in multi-threaded environment, given the current DeltaProcessor design.
Comment 3 Vladimir Piskarev CLA 2017-09-01 06:17:08 EDT
Added another test demonstrating that not only POST_CHANGE fine-grained deltas but also POST_RECONCILE deltas may get lost when executing in multi-threaded environment.
Comment 4 Eclipse Genie CLA 2020-03-11 19:22:22 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.