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

Bug 273411

Summary: Provide the method CDOLock#getOtherLockers() method
Product: [Modeling] EMF Reporter: Stephane fournier <stephane.fournier>
Component: cdo.coreAssignee: Project Inbox <emf.cdo-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: caspar_d, Michal.Tkacz, saulius.tvarijonas, smcduff, stepper
Version: 4.2Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Stephane fournier CLA 2009-04-23 07:43:23 EDT
It should be useful to change a bit CDOLock.isObjectLockedByOthers() method to return a list (or an array) of who owns the lock (when the object is already locked) rather than a simple boolean. If the list is empty, the object is not locked.

Here is a simple use case : a collaborative model editor with a pessimistic lock strategy.
As soon as an object is modified by an user, this one is locked (write lock). N.B: The lock is released when the transaction is committed or rolled back.

When attempting to modify a locked object (let's say user A owns already a write lock) by user B, this one would appreciate a warning message (for instance) reporting that the object is locked by user A.

In studying CDO code, I think we can return a list (or an array) of ids.
The returned ids can be based on view id or user id (if any).
IUserAware interface is implemented by Connector, Channel and Session.

At the moment, I've an issue with the connector on server side. After its creation time on server side, it does not have the value set on the connector on client side (see http://www.eclipse.org/newsportal/article.php?id=41190&group=eclipse.tools.emf#41190).

Stephane.
Comment 1 Stephane fournier CLA 2009-04-24 10:46:53 EDT
Hi,
Since Eike solved my issue, I've implemented the suggestion I made to know who is locking an object (to report a message to the end-user).

To avoid to modify CDOLock.isObjectLockedByOthers method signature, I introduced a new method named getLockers() (a more appropriate name can be found, please let me know guys).

getLockers() method returns all other ones that lock the related object.
The return element is a collection of Id : either the Session.getUserId (if any i.e credential is used) or SessionId.

On server side, I shared the implementation in RWLockManager.java for isObjectLockedByOthers & getLockers services to avoid code duplication.
Indeed, returning an empty collection means no one is locking the object.

Let me know what you think about that.

Shall we introduce this new method or modify isObjectLockedByOthers as discussed in the bug description ?

Stéphane.
Comment 2 Simon Mc Duff CLA 2009-04-24 10:56:21 EDT
(In reply to comment #1)
> Hi,
> Since Eike solved my issue, I've implemented the suggestion I made to know who
> is locking an object (to report a message to the end-user).
> 
> To avoid to modify CDOLock.isObjectLockedByOthers method signature, I
> introduced a new method named getLockers() (a more appropriate name can be
> found, please let me know guys).
> 
> getLockers() method returns all other ones that lock the related object.
> The return element is a collection of Id : either the Session.getUserId (if any
> i.e credential is used) or SessionId.
> 

The locking is made per CDOView. getLockers should returns the viewid nothing else. From there we could ask more info if we want right ? Make sense ?


> On server side, I shared the implementation in RWLockManager.java for
> isObjectLockedByOthers & getLockers services to avoid code duplication.
> Indeed, returning an empty collection means no one is locking the object.
> 
> Let me know what you think about that.
> 
> Shall we introduce this new method or modify isObjectLockedByOthers as
> discussed in the bug description ?

getLockers will returns locks from others... or all locks (include the one who is asking ?)

> 
> Stéphane.
> 

Comment 3 Stephane fournier CLA 2009-04-24 15:11:06 EDT

(In reply to comment #2)
> (In reply to comment #1)
> > Hi,
> > Since Eike solved my issue, I've implemented the suggestion I made to know who
> > is locking an object (to report a message to the end-user).
> > 
> > To avoid to modify CDOLock.isObjectLockedByOthers method signature, I
> > introduced a new method named getLockers() (a more appropriate name can be
> > found, please let me know guys).
> > 
> > getLockers() method returns all other ones that lock the related object.
> > The return element is a collection of Id : either the Session.getUserId (if any
> > i.e credential is used) or SessionId.
> > 
> 
> The locking is made per CDOView. getLockers should returns the viewid nothing
> else. From there we could ask more info if we want right ? Make sense ?
> 
I think to clarify the situation, a simple scenario is useful.

Scenario :
- 2 Eclipse applications running CDO clients (client A & B) on different computers.
- a CDO Server application on another computer.
- Let's assume, both clients use credentials to connect to the cdo server.

1) Client A gets a write lock on Object 'Dummy'.

2) Client B wants to know who has locked Object 'Dummy' ? Because he wants to modify it and at the moment he can't.
So, from client B (on client side), would it be possible with 'client A' view Id (get from getLockers() method) to retrieve more info ? By more info, I mean, userId (the one defined by client A credential). To do that, we need to get the client A IView instance, to call getSession.getUserId() for instance....

In fact the question is : from a view can we access another view info running on a different application instance ? If we can't, we have to retrieve view info on server side because the server has accesses to all views.
 
I'm not a cdo expert, it may be a silly question.


> 
> > On server side, I shared the implementation in RWLockManager.java for
> > isObjectLockedByOthers & getLockers services to avoid code duplication.
> > Indeed, returning an empty collection means no one is locking the object.
> > 
> > Let me know what you think about that.
> > 
> > Shall we introduce this new method or modify isObjectLockedByOthers as
> > discussed in the bug description ?
> 
> getLockers will returns locks from others... or all locks (include the one who
> is asking ?)
> 

I think, we can have both, we just need an additional flag in the getLockers method to include or not the requester.

> > 
> > Stéphane.
> > 
> 

Comment 4 Eike Stepper CLA 2009-04-24 15:39:31 EDT
Guys,

I like the idea of being able to know who owns a lock and maybe send a message to this person.

I think one of the central challenges is this question: How to identify a view in a different client?

The viewID alone is not unique over all views of a repository. It is a counter starting from 1 for each session.

The combination with the sessionID would be unique over the whole repository. But only for the current runtime instance. In other words, the sessionID starts from 1 with each activation of a repository.

For several reasons I would like to have a new sort of viewID that is unique for each view that was created in the whole lifetime of a repository. This will be needed for transactions anyway if we want to explicitly persist transactions / commit operations (for audit reasons, bug 256649). And for the persistent locks feature request (bug 263024) this might become necessary as well.

Maybe it makes sense to create a new implementation of CDOView for this purpose, one that has no current state but can serve as an instance for information purposes. Maybe it makes sense to add a narrower super interface to CDOView for this purpose.

For the persistent ID of these views, do you think that a long integer is large enough?

Should we also make the IDs of the associated sessions persistent?
Comment 5 Stephane fournier CLA 2009-04-28 03:06:33 EDT
(In reply to comment #4)
> Guys,
> 
> I like the idea of being able to know who owns a lock and maybe send a message
> to this person.

Me too :)
> 
> I think one of the central challenges is this question: How to identify a view
> in a different client?
> 
> The viewID alone is not unique over all views of a repository. It is a counter
> starting from 1 for each session.
> 
> The combination with the sessionID would be unique over the whole repository.
> But only for the current runtime instance. In other words, the sessionID starts
> from 1 with each activation of a repository.
> 
> For several reasons I would like to have a new sort of viewID that is unique
> for each view that was created in the whole lifetime of a repository. This will
> be needed for transactions anyway if we want to explicitly persist transactions
> / commit operations (for audit reasons, bug 256649). And for the persistent
> locks feature request (bug 263024) this might become necessary as well.
> 
> Maybe it makes sense to create a new implementation of CDOView for this
> purpose, one that has no current state but can serve as an instance for
> information purposes. Maybe it makes sense to add a narrower super interface to
> CDOView for this purpose.
> 
> For the persistent ID of these views, do you think that a long integer is large
> enough?
> 
It should be ! Does it make sense to recycle ID when the view has been closed ?

> Should we also make the IDs of the associated sessions persistent?
> 
To be honest, I have no idea regarding this point. You are the expert ;)

Regarding the schedule, do you think we can get something working in Galileo release train ?

Comment 6 Eike Stepper CLA 2009-04-28 03:13:44 EDT
(In reply to comment #5)
> Regarding the schedule, do you think we can get something working in Galileo
> release train ?

This mainly depends on your ability to contribute in time :P
Since no other project in Galileo depends on CDO, we don't care too much for official feature freeze...
Comment 7 Stephane fournier CLA 2009-04-28 05:55:38 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > Regarding the schedule, do you think we can get something working in Galileo
> > release train ?
> 
> This mainly depends on your ability to contribute in time :P

I was expecting such an answer from you :)
Sure, I can contribute some parts, but I don't have enough CDO knowledges to implement all your suggestions by my own. May we work together ? 

> Since no other project in Galileo depends on CDO, we don't care too much for
> official feature freeze...
> 



Comment 8 Eike Stepper CLA 2009-04-28 11:54:25 EDT
Sure!

If you bare with me for my limited time...
Comment 9 Eike Stepper CLA 2009-04-28 13:08:21 EDT
I'm thinking about this persistent evidence of sessions and views/transactions.
This somehow breaks the former assumption that the repository data is only modified in the scope of transactions.
There are also performance and resource consumption concerns...

Maybe we should make this a more explicit decision at the client side?
Something like a CDOView.getState() / setState()...

And we'd need API to "re-open" persisted views on a session.

That could match nicely with the pending persistent lock feature:
We'd only allow them if CDOView.getState()==State.DURABLE

In any case I think a separate Bugzilla should be filed for this "persistent view" thing.
Comment 10 Eike Stepper CLA 2009-11-01 05:58:58 EST
Rebasing all unresolved enhancement requests to 3.0
Comment 11 Eike Stepper CLA 2010-06-29 04:50:11 EDT
Rebasing all outstanding enhancements requests to version 4.0
Comment 12 Eike Stepper CLA 2011-06-23 03:57:12 EDT
Moving all open enhancement requests to 4.1
Comment 13 Eike Stepper CLA 2011-07-16 11:04:56 EDT
Renaming because changing the return type of an existing method is a breaking change. Adding a new method seems more adequate. In addition there might be a performance penalty involved.
Comment 14 Eike Stepper CLA 2012-08-14 22:55:26 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 15 Eike Stepper CLA 2012-12-31 02:11:47 EST
This (and more) has been implemented in bug 353691:

org.eclipse.emf.cdo.CDOObject.cdoLockState()

org.eclipse.emf.cdo.common.lock.CDOLockState.getLockedObject()
org.eclipse.emf.cdo.common.lock.CDOLockState.isLocked(LockType, CDOLockOwner, boolean)
org.eclipse.emf.cdo.common.lock.CDOLockState.getReadLockOwners()
org.eclipse.emf.cdo.common.lock.CDOLockState.getWriteLockOwner()
org.eclipse.emf.cdo.common.lock.CDOLockState.getWriteOptionOwner()

*** This bug has been marked as a duplicate of bug 353691 ***
Comment 16 Eike Stepper CLA 2013-06-27 04:00:44 EDT
Closing