Debashish
Debashish

Reputation: 43

Removing versions from versionStorage for deleted pages AEM (JackRAbbit)

We have a large number of deleted pages in our application. However, the versions still exits in the version storage. Is there any way to delete them.

I tried by traversing through the /jcr:system/jcr:versionStorage and identifying the deleted pages. However, when I try to Delete the version, I get the following error.

javax.jcr.nodetype.ConstraintViolationException: Item is protected.

Also, if I try to Purge the page through code, due to the high volume of deleted pages present in the repository, I get the error based

(org.apache.jackrabbit.oak.plugins.index.property.strategy.ContentMirrorStoreStrategy) - Traversed 10000 nodes (31911 index entries) using index cqParentPath with filter Filter(query=sele ct [jcr:path], [jcr:score], * from [nt:version] as a where isdescendantnode(a,

Please help, as I am literally stuck with this issue.

So basic question is, is there any way to delete the nodes containing the versions for deleted pages in JackRabbit (AEM)

Upvotes: 0

Views: 1051

Answers (1)

Csaboka
Csaboka

Reputation: 11

I realize I'm late in answering this, but it might still help someone who encounters this issue later.

You can remove a version from a version history (except the special version named "jcr:rootVersion"), but you can't do it via the regular API. You need to use the VersionManager API, like this:

Node node = session.getNode("/jcr:system/jcr:versionStorage/path/to/your/version/node");
Version version = (Version) node;
version.getContainingHistory().removeVersion(version.getName());
// Version removal is committed automatically, independently from Session.save() calls

There is no API for removing full version histories, as opposed to individual versions inside those histories. The best workaround I could find is the one you have found yourself: restore one of the versions (preferably jcr:rootVersion since it's the smallest) to some path, delete all versions except jcr:rootVersion, then delete the restored node. Oak has some built-in functionality that cleans up histories of deleted items, but only if the history is empty. You need to restore and then delete a version to trigger it, though, "emptying" a history won't trigger it by itself.

As for the log message you mentioned: it isn't an error, just a warning. It turns into an error if a query needs to traverse more than 100,000 nodes, at which point your query will be aborted with an exception. If you won't reach the 100K node limit and don't worry about overloading your instance, you can ignore the warning. If you do reach the 100K limit, you have several options:

  • Create a new index to support the query you are trying to run. This is only advised if you plan to run the query regularly, it's not worth the overhead for one-off queries.
  • Break the task into smaller chunks (for example, run the query on smaller subtrees and aggregate the results yourself)
  • Implement recursive tree traversal yourself. It may be less efficient than letting the query engine do it, but your own traversal code is not limited to reading a certain amount of nodes.

Upvotes: 0

Related Questions