Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CDO Revisions not Persisting in HSQLDB
CDO Revisions not Persisting in HSQLDB [message #1258901] Thu, 27 February 2014 21:58 Go to next message
Gabe Colburn is currently offline Gabe ColburnFriend
Messages: 28
Registered: December 2012
Junior Member
I am having issues persisting the revision history of objects in CDO after the server is shutdown.

I presently have two applications:

1) A headless RCP app that starts a CDO server programatically and uses an HSQLDB database.
2) An RCP E4 app (the client) that the customer uses.

In the client, I added a view that shows the historical changes to objects/features of interest. The code to get the historical information looks like this:

int currentVersion = obj.cdoRevision().getVersion();
InternalCDORevision revision;
InternalCDORevision prevRevision;
for( int i = currentVersion; i > 1; i-- ) {
revision = (InternalCDORevision)CDOUtil.getRevisionByVersion(rx, i);
prevRevision = (InternalCDORevision)CDOUtil.getRevisionByVersion(rx, i-1);
revision.setUnchunked();
prevRevision.setUnchunked();

CDORevisionDelta revisionDelta = revision.compare(prevRevision);
List<CDOFeatureDelta> featureDeltas = revisionDelta.getFeatureDeltas();
for (CDOFeatureDelta featureDelta : featureDeltas )
{
if( featureDelta.getFeature().equals([insert feature 1] )
// Get the historical information to show to the user on feature 1
else if( featureDelta.getFeature().equals([insert feature 2] )
// Get the historical information to show to the user on feature 2
}
}

Not sure if this is the best way, but it allows me to show the chronological changes to only features of interest to the user and has been working well. The problem I've found is as long as the CDO server is running I can get the historical information. Once I shutdown the CDO server (for maintenance or if the machine went down) and bring it up again, all the previous revisions except for the latest are no longer available. For example, if the latest revision number was 10 on the object, the CDO server gives the error: "Can only retrieve current version 10 for OID2590 - version requested was BranchVersion[Branch[id=0, name=MAIN], v9]"

When I create the respository I set:
Map<String,String> props = new HashMap<String,String>();
props.put(Props.SUPPORTING_AUDITS, "true");
IRepository repo = CDOServerUtil.createRepository( getRepositoryName(), store, props);

I am using CDO 4.2.1v20130913-0613
HSQLDB feature 2.2.8.201310261216
Net4j DB Framework HSQLDB Adapter 4.2.0v20130601-1611
Net4j Signaling Platform SDK 4.2.1.v20130806-0658

Any thoughts as to what I'm missing to get the revisions persisted?

Thanks,
-Gabe
Re: CDO Revisions not Persisting in HSQLDB [message #1259202 is a reply to message #1258901] Fri, 28 February 2014 05:52 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Am 27.02.2014 22:58, schrieb Gabe Colburn:
> I am having issues persisting the revision history of objects in CDO after the server is shutdown.
You probably mean "after the server is restarted" ;-)

>
> I presently have two applications:
>
> 1) A headless RCP app that starts a CDO server programatically and uses an HSQLDB database.
> 2) An RCP E4 app (the client) that the customer uses.
>
> In the client, I added a view that shows the historical changes to objects/features of interest. The code to get the
> historical information looks like this:
>
> int currentVersion = obj.cdoRevision().getVersion();
> InternalCDORevision revision;
> InternalCDORevision prevRevision;
> for( int i = currentVersion; i > 1; i-- ) {
> revision = (InternalCDORevision)CDOUtil.getRevisionByVersion(rx, i);
> prevRevision = (InternalCDORevision)CDOUtil.getRevisionByVersion(rx, i-1);
This could be faster if you remember the current revision to use it as the previous revision in the next iteration. Call
getRevisionByVersion() only once per iteration.

> revision.setUnchunked();
> prevRevision.setUnchunked();
Never use internal interfaces unless you know exactly what you're doing. Note that we may break the contract of these
interfaces even in minor releases.

In particular setUnchunked() is problematic because it brutally changes a flag in the revision that is otherwise
carefully managed. If you're using partial collection loading (chunking) this likely leaads to errors. If you're not
using it, setUnchunked() is a NOOP. In both cases you shouldn't use it.

>
> CDORevisionDelta revisionDelta = revision.compare(prevRevision);
> List<CDOFeatureDelta> featureDeltas = revisionDelta.getFeatureDeltas();
> for (CDOFeatureDelta featureDelta : featureDeltas )
> {
> if( featureDelta.getFeature().equals([insert feature 1] )
> // Get the historical information to show to the user on feature 1
> else if( featureDelta.getFeature().equals([insert feature 2] )
> // Get the historical information to show to the user on feature 2
> }
> }
>
> Not sure if this is the best way, but it allows me to show the chronological changes to only features of interest to
> the user and has been working well. The problem I've found is as long as the CDO server is running I can get the
> historical information. Once I shutdown the CDO server (for maintenance or if the machine went down) and bring it up
> again, all the previous revisions except for the latest are no longer available. For example, if the latest revision
> number was 10 on the object, the CDO server gives the error: "Can only retrieve current version 10 for OID2590 -
> version requested was BranchVersion[Branch[id=0, name=MAIN], v9]"
>
> When I create the respository I set:
> Map<String,String> props = new HashMap<String,String>();
> props.put(Props.SUPPORTING_AUDITS, "true");
> IRepository repo = CDOServerUtil.createRepository( getRepositoryName(), store, props);
I suspect the problem is how you create your store, more exactly its IMappingStrategy. It's likely that you create it
without auti support. Can you paste that code?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


>
> I am using CDO 4.2.1v20130913-0613
> HSQLDB feature 2.2.8.201310261216
> Net4j DB Framework HSQLDB Adapter 4.2.0v20130601-1611
> Net4j Signaling Platform SDK 4.2.1.v20130806-0658
>
> Any thoughts as to what I'm missing to get the revisions persisted?
>
> Thanks,
> -Gabe
>


Re: CDO Revisions not Persisting in HSQLDB [message #1259402 is a reply to message #1259202] Fri, 28 February 2014 10:35 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 28-02-14 06:52, Eike Stepper wrote:
> "Can only retrieve current version 10 for OID2590 - version requested
> was BranchVersion[Branch[id=0, name=MAIN], v9]"

This interesting, we observed similar errors in the past.

http://www.eclipse.org/forums/index.php/t/452927/
Re: CDO Revisions not Persisting in HSQLDB [message #1259410 is a reply to message #1259402] Fri, 28 February 2014 10:45 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Am 28.02.2014 11:35, schrieb Christophe Bouhier:
> On 28-02-14 06:52, Eike Stepper wrote:
>> "Can only retrieve current version 10 for OID2590 - version requested
>> was BranchVersion[Branch[id=0, name=MAIN], v9]"
>
> This interesting, we observed similar errors in the past.
>
> http://www.eclipse.org/forums/index.php/t/452927/
Searching for "Can only retrieve current version" in the code base brings up DBStoreAccessor.readRevisionByVersion(),
which clearly implies that the mapping strategy is not adequate:

if (mappingStrategy.hasAuditSupport())
{
...
}
else
{
...

throw new IllegalStateException("Can only retrieve current version " + revision.getVersion() + " for " + id
//$NON-NLS-1$ //$NON-NLS-2$
+ " - version requested was " + branchVersion); //$NON-NLS-1$
}

The problem only manifests itself after a server restart because the in-memory revision cache (both at client and server
side) only considers the repository-level property, which you've set correctly.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: CDO Revisions not Persisting in HSQLDB [message #1259664 is a reply to message #1259202] Fri, 28 February 2014 17:04 Go to previous messageGo to next message
Gabe Colburn is currently offline Gabe ColburnFriend
Messages: 28
Registered: December 2012
Junior Member
Hi Eike,

Thanks for your great response. I had added the setUnchuncked code a while back to solve some errors I was getting. I didn't realize it was internal. When I comment out those two lines I get the following error when I call:

revisionDelta = revision.compare(prevRevision);

Stacktrace:
org.eclipse.emf.cdo.common.util.PartialCollectionLoadingNotSupportedException: List contains proxy elements
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.checkNoProxies(CDORevisionDeltaImpl.java:416)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.analyzeLists(CDORevisionDeltaImpl.java:366)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.compare(CDORevisionDeltaImpl.java:426)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.<init>(CDORevisionDeltaImpl.java:116)
at org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision.compare(BaseCDORevision.java:442)

Here is how I am creating the store/mapping strategy:

public IStore createStore(String database, String databaseName, String url, Properties properties, String user, String password) {
		Map<String,String> props = new HashMap<String,String>();
		props.put(IMappingStrategy.PROP_QUALIFIED_NAMES, "true");
		props.put(IMappingStrategy.PROP_FORCE_NAMES_WITH_ID, "true");
		props.put(IMappingStrategy.PROP_MAX_TABLE_NAME_LENGTH,"64");

		HSQLDBDataSource myDataSource = new HSQLDBDataSource();
		
		myDataSource.setDatabase(database);
		myDataSource.setDatabaseName(databaseName);
		myDataSource.setUrl(url);
		myDataSource.setProperties(properties);
		myDataSource.setUser(user);
		myDataSource.setPassword(password);

		IMappingStrategy mappingStrategy = CDODBUtil.createMappingStrategy( "horizontal" );
		mappingStrategy.setProperties(props);
		
		IDBStore store = CDODBUtil.createStore( mappingStrategy,
				DBUtil.getDBAdapter("hsqldb"),
				DBUtil.createConnectionProvider( myDataSource ));
		mappingStrategy.setStore( store );

		return store;
	}


On this page: https://wiki.eclipse.org/CDO/Server_Configuration_Reference#Element_mappingStrategy
it seems that I need to set the supportingAudits property to true, but I don't see it in IMappingStrategy. What's the correct way to turn on auditing in the mapping strategy?

Also, thanks for your point on a more efficient loop.

Thanks!

-Gabe
Re: CDO Revisions not Persisting in HSQLDB [message #1265841 is a reply to message #1259664] Thu, 06 March 2014 16:24 Go to previous messageGo to next message
Gabe Colburn is currently offline Gabe ColburnFriend
Messages: 28
Registered: December 2012
Junior Member
Figured out how to get the revisions to be persisted.

I changed creation of the mapping strategy from:

CDODBUtil.createMappingStrategy( "horizontal" )
to
CDODBUtil.createHorizontalMappingStrategy(true);

However I still get the following stacktrace:

org.eclipse.emf.cdo.common.util.PartialCollectionLoadingNotSupportedException: List contains proxy elements
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.checkNoProxies(CDORevisionDeltaImpl.java:416)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.analyzeLists(CDORevisionDeltaImpl.java:366)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.compare(CDORevisionDeltaImpl.java:426)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.<init>(CDORevisionDeltaImpl.java:116)
at org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision.compare(BaseCDORevision.java:442)

whenever I execute the line:

revisionDelta = revision.compare(prevRevision);


without the statements:

revision.setUnchunked();
prevRevision.setUnchunked();


When I set them to unchunked the error goes away.

-Gabe
Re: CDO Revisions not Persisting in HSQLDB [message #1265848 is a reply to message #1265841] Thu, 06 March 2014 16:33 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Am 06.03.2014 17:24, schrieb Gabe Colburn:
> Figured out how to get the revisions to be persisted.
>
> I changed creation of the mapping strategy from:
>
> CDODBUtil.createMappingStrategy( "horizontal" )
> to
> CDODBUtil.createHorizontalMappingStrategy(true);
>
> However I still get the following stacktrace:
>
> org.eclipse.emf.cdo.common.util.PartialCollectionLoadingNotSupportedException: List contains proxy elements
You can't use the compare() method with partial collection loading (PCL) enabled. If PCL is enabled your CDORevisions
can contain list element proxies which can't be compared because they don't know their real values. The (internal)
setUnchunked() method just sets an internal revision flag to optimize the recognition of partially loaded revisions, but
it doesn't resolve the contained element proxies. You can try InternalCDOSession.resolveAllElementProxies(CDORevision),
or just disable PCL.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> at
> org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.checkNoProxies(CDORevisionDeltaImpl.java:416)
> at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl$2.analyzeLists(CDORevisionDeltaImpl.java:366)
> at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.compare(CDORevisionDeltaImpl.java:426)
> at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.<init>(CDORevisionDeltaImpl.java:116)
> at org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision.compare(BaseCDORevision.java:442)
>
> whenever I execute the line:
>
> revisionDelta = revision.compare(prevRevision);
>
> without the statements:
>
> revision.setUnchunked();
> prevRevision.setUnchunked();
>
> When I set them to unchunked the error goes away.
>
> -Gabe


Previous Topic:Building a UI on EMF - UPDATED
Next Topic:[XCORE] how to create an EList in an operation
Goto Forum:
  


Current Time: Thu Sep 26 05:06:26 GMT 2024

Powered by FUDForum. Page generated in 0.04129 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top