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

Bug 332125

Summary: Wrong new offline ids after repair db
Product: [Modeling] EMF Reporter: Erwin Betschart <erwin>
Component: cdo.dbAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3    
Version: 4.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed patch
stepper: iplog+
Patch v2 none

Description Erwin Betschart CLA 2010-12-08 08:44:54 EST
Build Identifier: 4.0

When an offlineClone application is kill during the next start repairAfterCrash is called.
repairAfterCrash sets then the next local id always to 0. That is new offline created objects have ids 0, -1, -2 ... (looks like an external id)

Will attach a patch.

Reproducible: Always

Steps to Reproduce:
1. Create an offline clone application
2. Start and kill the application
3. Restart the application
Comment 1 Erwin Betschart CLA 2010-12-08 08:56:50 EST
Created attachment 184784 [details]
Proposed patch

resultSet.getLong(1);
--> delivers 0 in case MIN(NULL) was executed; MIN(NULL) if there were no offline branches in the table.

if (id > Long.MAX_VALUE / 2L && id < min)
--> Taking Long.MAX_VALUE / 2L in order to decide if the found minimum was a local or master id.
Comment 2 Eike Stepper CLA 2010-12-09 13:50:52 EST
Created attachment 184886 [details]
Patch v2

I've tried to get rid of the >MAX_VALUE/2 constraint by detecting only the objects that are newly created in offline branches. This requires a JOIN with the CDO_OBJECTS table, which is always present for horizontal mapping strategies. Can you please test that and tell me if you like it?
Comment 3 Erwin Betschart CLA 2010-12-13 08:50:29 EST
Seems to work tested the following cases: 
 -> Crashed db without offline changes -> max long: ok
 -> Crashed db with offline changes: ok

Your patch needs a small change (missing whitespace): 
+    String suffix = "AS t WHERE t." + ...
to:
+    String suffix = " AS t WHERE t." + ...


Several jdbc exceptions (Column T.CDO_ID not found) were thrown and silently irgnored but this had no impact on the computed local minimum.
Comment 4 Eike Stepper CLA 2010-12-14 01:44:52 EST
(In reply to comment #3)
> Seems to work tested the following cases:
> -> Crashed db without offline changes -> max long: ok
> -> Crashed db with offline changes: ok

Thank you for testing.

> Your patch needs a small change (missing whitespace):
> +    String suffix = "AS t WHERE t." + ...
> to:
> +    String suffix = " AS t WHERE t." + ...

Oh, now I've added a space there.

> Several jdbc exceptions (Column T.CDO_ID not found) were thrown and silently
> irgnored but this had no impact on the computed local minimum.

Yes, these exceptions are to be expected because at repair time we don't already know the real mappings and just iterate over all tables. I double checked that we don't get "false positives" with this approach.

Committed to HEAD.
Comment 5 Eike Stepper CLA 2011-06-23 03:39:44 EDT
Available in R20110608-1407