Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 578871 - add ISchedulableOperation #30

Merged
merged 3 commits into from
Apr 20, 2022
Merged

Bug 578871 - add ISchedulableOperation #30

merged 3 commits into from
Apr 20, 2022

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Apr 19, 2022

to prevent UI freeze during UNDO

to prevent UI freeze during UNDO
@iloveeclipse
Copy link
Member

Shouldn't that be put into org.eclipse.core.commands bundle to other "Operations" in org.eclipse.core.commands.operations? Job's runtime API does not need this operation.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

Shouldn't that be put into org.eclipse.core.commands bundle to other "Operations" in org.eclipse.core.commands.operations?

yea, but operations has no dependency to runtime. so it's not possible without adding additional dependencies.

Copy link
Member

@iloveeclipse iloveeclipse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking on eclipse-platform/eclipse.platform.ui#18, I think this code really belongs to org.eclipse.core.commands.operations

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

Looking on eclipse-platform/eclipse.platform.ui#18, I think this code really belongs to org.eclipse.core.commands.operations

It makes no sense that you on the one hand request to not add dependencies and on ask to do so in the next review.

@iloveeclipse
Copy link
Member

@jukzi : what makes sense and what not is exact the question that needs to be discussed in a review. So if a reviewer asks something, probably that makes sense for him, at least.

You proposing to add new API and I simply questioning if the API should be added somewhere else. This is usual during reviews, that people discuss things.

I see that org.eclipse.core.commands doesn't require runtime bundle, so my first proposal to put new API there will not work.
I see that org.eclipse.ui.workbench has org.eclipse.ui.operations so that could be a better place.

WDYT?

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

org.eclipse.ui.workbench

workbench does not work either because UndoableOperation2ChangeAdapter does not require a workbench

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

@iloveeclipse There is a subtle difference between a question and a request. Please reconsider your review or suggest a working alternative. Currently your vote blocks merging without adding any value.

@iloveeclipse
Copy link
Member

Currently your vote blocks merging without adding any value.

@jukzi : such comments are not OK, please consider to change the way you discuss things in public reviews.

Now to the actual change: API is there for years, so addition of API should be made carefully, and so I think it could wait few more hours. May be someone else has a proposal or could provide other feedback.

@mickaelistria
Copy link
Contributor

May be someone else has a proposal

I've made a proposal in eclipse-platform/eclipse.platform.ui#8 , which I believe would resolve this issue and many more of that kind. However I won't be able to work on it for some time. If someone wants to give it a try, that would be welcome.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

It's totally fine to wait for others to review. I just want you to understand that it is offending to read that there are "changes requested" when they are not.

@iloveeclipse
Copy link
Member

I just want you to understand that it is offending to read that there are "changes requested" when they are not.

This is github way to tell you there was a -1 comment in terms of gerrit.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 19, 2022

This is github way to tell you there was a -1 comment in terms of gerrit.

It's as well offending on github as on gerrit to not reconsidering a negative review after it was solved.

@mickaelistria
Copy link
Contributor

@jukzi please try to avoid turning every comment into a passive-aggressive form of blaming people who are just doing their best as well, and consider just kindly asking. A comment such as "I think I covered all requested changes but the review is still -1, what do you think is missing?" is much more pleasant and ultimately more efficient.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 20, 2022

I think I covered all requested changes but the review is still -1, what do you think is missing?

@jukzi
Copy link
Contributor Author

jukzi commented Apr 20, 2022

I think I covered all requested changes but the review is still -1, what do you think is missing?

@iloveeclipse
Copy link
Member

Hint for the future: don't use "merge", use "rebase" for your commits. This way the reviewer has a chance to review the change in one commit squashed locally and not the merge commit somewhere in the middle and few other commits flying around.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 20, 2022

Hint for the future: don't use "merge", use "rebase" for your commits.

i don't find a rebase button in github. i only see "refresh and merge" in the branch.

package org.eclipse.core.runtime.jobs;

/**
* An interface to mark an Operation that needs an {@link ISchedulingRule}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: please use "operation", not "Operation" because it is a word, not an API name.

public interface ISchedulableOperation {
/**
* @return an {@link ISchedulingRule} that the operation will acquire in the
* current thread - if any. To make sure the operation can proceed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new javadoc is way better compared to the old one.
Still I struggle with this: To make sure the operation can proceed without waiting for a blocking thread ... caller should call beginRule()

The problem is - this is the opposite what the API says, because beginRule() API says If the rule conflicts with another rule currently running in another thread, this method blocks.

What you actually mean is: to make sure operation can interrupt autobuild if used in context of ... but that is too much of a unrelated context for this API.

Here is my attempt to fix that (you can copy to clipboard and use Team->Apply patch in Eclipse):

diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ISchedulableOperation.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ISchedulableOperation.java
index 432ce62..db672d5 100644
--- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ISchedulableOperation.java
+++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ISchedulableOperation.java
@@ -15,7 +15,8 @@
 
+import org.eclipse.core.runtime.IProgressMonitor;
+
 /**
- * An interface to mark an Operation that needs an {@link ISchedulingRule}.
+ * An interface to mark an operation that needs an {@link ISchedulingRule}.
  *
  * @since 3.13
- *
  */
@@ -23,12 +24,14 @@
 	/**
+	 * Gives the caller a hint if this operation may require a rule to proceed. The
+	 * caller should call
+	 * {@link IJobManager#beginRule(ISchedulingRule, IProgressMonitor)} before the
+	 * operation and {@link IJobManager#endRule(ISchedulingRule)} after if the rule
+	 * is specified.
+	 *
 	 * @return an {@link ISchedulingRule} that the operation will acquire in the
-	 *         current thread - if any. To make sure the operation can proceed
-	 *         without waiting for a blocking thread a caller should call
-	 *         {@link IJobManager#beginRule(ISchedulingRule, org.eclipse.core.runtime.IProgressMonitor)}
-	 *         before the operation and {@link IJobManager#endRule(ISchedulingRule)}
-	 *         after. Returns {@code null} if no rule needed - in that case the
-	 *         caller should not call neither <code>beginRule</code> nor
-	 *         <code>endRule</code>. As this method returns only a hint the
+	 *         current thread - if any. Returns {@code null} if no rule needed - in
+	 *         that case the caller should not call neither <code>beginRule</code>
+	 *         nor <code>endRule</code>. As this method returns only a hint the
 	 *         operation can not assume that the caller already acquired the rule.
-	 *         The Operation still has to acquire it - which will lead to a nested
+	 *         The operation still has to acquire it - which will lead to a nested
 	 *         rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new javadoc is way better compared to the old one. Still I struggle with this: To make sure the operation can proceed without waiting for a blocking thread ... caller should call beginRule()

The problem is - this is the opposite what the API says, because beginRule() API says If the rule conflicts with another rule currently running in another thread, this method blocks.

i dont't see the problem. the trick here is that when beginRule() has been called in the same thread before the operation, then the beginRule in the operation is just nested and guaranteed to be wait free.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont't see the problem

But I see it.

the trick here is that when beginRule() has been called in the same thread before the operation, then the beginRule in the operation is just nested and guaranteed to be wait free.

This is not correct.

"wait free" can only happen if there is no conflicting rule set in some other running job: If the rule conflicts with another rule currently running in another thread, this method blocks. This is same as for lock.aquire(). Sure, if current thread already acquired the lock, it is wait free.

Here we don't know in which thread what rule is used, so we can't assume that we are running the code with the rule already started and no one else is running with that rule.

I would recommend to use the proposed javadoc or provide another version if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still don't get the point, let's figure out if we are talking about the same:

I state that:

// Caller:
beginRule(myRule,null); // 1. may block until conflicting rule ends
{ // called Operation:
  beginRule(myRule,null); // 2. guaranteed wait free, because same thread
  endRule(myRule);
}
endRule(myRule);

and that is what this API is for - to give the Operation the wait free beginRule (at 2.).
And the usage will then even put additional goodies, like interrupt autobuild and cancel dialog (at 1.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and that is what this API is for

Jörg, you seem to believe that the code here is only for your specific case - it is not, because it is public API. We don't know how API will be used once we release that and we can't assume it will be used only a case of nested call, at least here it is very generic one.

It is not called IOperationForNestedRuleBeginOnly.

If you want something only for case 2 in your example, this is not right API and actually doesn't belong to this bundle at all because it is tailored for a very specific use case. This is the reason I originally won't place this code here at all.

So if we provide generic API in jobs bundle that claims to use beginRule() to avoid waits it is just wrong message. beginRule() is used to acquire a lock, and that is a potentially blocking operation. Therefore it is confusing to provide javadoc that says the opposite.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i still can not imaging how to abuse the API but it's not important. i updated the javadoc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i still can not imaging how to abuse the API

Just assume you are 3rd party guy and have no clue about the current issue. You read the docs on job API, sees this class javadoc and say: cool, all what I need to avoid waiting is to call beginRule() at some time. You will do that and that will cause waiting and even deadlock your code! This is not cool, you are upset and Eclipse API is stupid.

@iloveeclipse
Copy link
Member

i don't find a rebase button in github. i only see "refresh and merge" in the branch.

I meant Eclipse. In Eclipse, if your PR branch and head of the origin are diverged, commit all your changes on PR branch, switch to "master", pull from origin to "master" branch and rebase your PR branch on master.

@jukzi
Copy link
Contributor Author

jukzi commented Apr 20, 2022

In Eclipse, if your PR branch and head

yea, but before i could rebase to the upstream repo i need to refresh the upstream into my fork which results in merge :-(
or is there any way to have two remotes?

@merks
Copy link
Contributor

merks commented Apr 20, 2022

In Eclipse, if your PR branch and head

@jukzi

yea, but before i could rebase to the upstream repo i need to refresh the upstream into my fork which results in merge :-( or is there any way to have two remotes?

I've been wondering the same thing! It wold be nice to have a remote that connects to the unforked repo so that when you have master checked out and do a pull, it comes from the main repo. I don't want to have to keep my fork in sync with the main repo because I have to do that manually so I only want my fork when I'm working on contributing something, which is on and off. There must be a simpler way using two remotes so that I'm not switching URIs...

@iloveeclipse
Copy link
Member

iloveeclipse commented Apr 20, 2022

Guys, you can have as many remotes as you want. I still have gerrit for example for jdt, because lot of patches are only there.
So what you want typically is "origin" remote pointing to the official repo, and your own "my_clone" remote pointing to your clone repo. Here how it looks like for me:

image

The way I'm working is:

  • checkout "master" branch and pull from origin repo to master
  • create branch on top of master "issue_42" (set "rebase" policy in the new branch dialog in Eclipse)
  • hack & commit on that "issue_42" branch
  • push "issue_42" branch to "iloveeclipse" repo & create PR from that
  • hack & amend commit on that branch if I need any changes
  • checkout "master" and pull from origin to get latest commits
  • checkout "issue_42", in history view right click "master" and say "Rebase head on"
  • force push "issue_42" branch to "iloveeclipse" repo (PR will be updated automatically)

@merks
Copy link
Contributor

merks commented Apr 20, 2022

Yes, I know that, but I don't know how to use them effectively. I hate to admit that out loud because I should really just figure it out. Sorry...

It's also probably important to set rebase in the right place (re: the comment about a merge happening):

image

@jukzi
Copy link
Contributor Author

jukzi commented Apr 20, 2022

The way I'm working is:

that flow seems to make sense.
It should be described in the https://github.com/eclipse-platform/.github/blob/main/CONTRIBUTING.md
It is much more complicated then gerrit though :-(
One thing still unclear to me: should set "configure fetch" or "configure push" when i create new remote? i could not see a difference.

@iloveeclipse iloveeclipse merged commit 3aaa152 into eclipse-platform:master Apr 20, 2022
@iloveeclipse
Copy link
Member

One thing still unclear to me: should set "configure fetch" or "configure push" when i create new remote?
i could not see a difference.

This is flexible, depending on what you want to have as result and which rights you have. If you plan only fetch from origin, you can leave "configure push" which might use different url for same repo. In most cases you are fine configuring fetch only, the push config will be derived from that automatically.

@merks
Copy link
Contributor

merks commented Apr 22, 2022

@iloveeclipse

I tried this approach out today contributing to PDE and it works way better than what's currently documented in the guidelines. The part I hate most is the manual syncing of my fork, but that's not relevant with this approach. One just goes back to master when done. This type of documentation, focused on using EGit in the IDE, is exactly what we need. It's also great you explain about how to do a rebase as well! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants