jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcel Reutegger" <mreut...@gmail.com>
Subject Re: "Unable to lock node. Node has pending changes: /counter"
Date Mon, 19 Jun 2006 12:47:36 GMT
There are two reason why this can happen (as far as I can see):

- the session actually did modify the node /counter before calling
generateNewResourceId(), thus it cannot lock the node

or

- a previous call to generateNewResourceId() failed in the
Locked.run() method, leaving unsaved changes.
The Locked utility does not automatically revert changes in case of an
exception thrown by Locked.run(). That's the responsibility of the
caller, because only he knows what is actually done in Locked.run().

The code you provided only shows the Locked.run() method, but does not
include a test case that shows how and when generateNewResourceId() is
called. Do you have a simple test that reproduces the
InvalidItemStateException? One other question: does this happen always
or only sporadically?

regards
marcel

On 6/19/06, Torgeir Veimo <torgeir@pobox.com> wrote:
> I get this with the following code;
>
> /* setup, run only once */
>
> Node root = session.getRootNode();
> Node counter = null;
> try {
>    counter = (Node) session.getItem("/counter");
> } catch (javax.jcr.RepositoryException re) {
>    log.debug("repository is empty, setting up default nodes");
>    counter = null;
> }
> if (counter == null) {
>    counter = root.addNode("counter");
>    counter.addMixin("mix:lockable");
>    counter.setProperty("value", 0);
>    session.save();
> }
>
> /* sequence fetcher */
> public int generateNewResourceId()
>    throws UnsupportedOperationException {
>
>        try {
>            Node counter = (Node) session.getItem("/counter");
>            long nextValue = ((Long) new Locked() {
>                protected Object run(Node counter) throws
> javax.jcr.RepositoryException {
>                    Property seqProp = counter.getProperty("value");
>                    long value = seqProp.getLong();
>                    seqProp.setValue(++value);
>                    seqProp.save();
>                    return new Long(value);
>                }
>            }.with(counter, false)).longValue();
>            log.debug("sequence value: " + nextValue);
>
>        } catch (Exception e) {
>            log.error("unable to get new resource id; ", e);
>        }
>        return -1;
>    }
>
> All this is with derby DB, jackrabbit 1.01, and the Locked.java code
> from current svn (as of today).
>
> Any clues why I'm getting the following exception?
>
> 13:13:19,476 ERROR JackrabbitRepositoryDAO  - unable to get new resource
> id;
> javax.jcr.InvalidItemStateException: Unable to lock node. Node has
> pending changes: /counter
>        at org.apache.jackrabbit.core.NodeImpl.lock(NodeImpl.java:3910)
>        at org.apache.jackrabbit.util.Locked.tryLock(Locked.java:251)
>        at org.apache.jackrabbit.util.Locked.with(Locked.java:145)
>        at org.apache.jackrabbit.util.Locked.with(Locked.java:103)
>        at
> com.netenviron.repository.dao.jackrabbit.JackrabbitRepositoryDAO.generateNewResourceId(JackrabbitRepositoryDAO.java:293)
>        at
> com.netenviron.repository.RepositoryManager.generateNewResourceId(RepositoryManager.java:164)
>        at com.netenviron.repository.Resource.<init>(Resource.java:58)
>        at
> com.netenviron.repository.dao.jackrabbit.JackrabbitRepositoryDAO.getResource(JackrabbitRepositoryDAO.java:521)
>
>
> --
> Torgeir Veimo <torgeir@pobox.com>
>
>

Mime
View raw message