Project

General

Profile

Bug #12107

Incremental conversion fails when a temp-table is removed from a program, or a program defining one is renamed or deleted, and later runs report success with stale Java

Added by Octavian Adrian Gavril 20 days ago. Updated 7 days ago.

Status:
Rejected
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:
Incremental Conversion

Related issues

Related to Conversion Tools - Feature #7169: drive conversion order using user-specified dependencies Review

History

#1 Updated by Octavian Adrian Gavril 20 days ago

Incremental conversion fails when a temp-table is removed from a program, and when a program which defines a temp-table is renamed or deleted. The error then repeats in later incremental conversions, and a rerun without any source change reports success while the Java no longer matches the 4GL code. Only ant clean.convert and a new conversion of everything repair the project.

All cases were reproduced on trunk 16826. The testcase has three programs. a.p and b.p define the same temp-table, and c.p has none.

a.p:

DEFINE TEMP-TABLE tta NO-UNDO
   FIELD f1 AS INTEGER
   FIELD f2 AS CHARACTER
   INDEX ix1 IS PRIMARY f1.

CREATE tta.
tta.f1 = 1.
FOR EACH tta:
   MESSAGE "a.p" tta.f1 tta.f2.
END.

b.p:

DEFINE TEMP-TABLE tta NO-UNDO
   FIELD f1 AS INTEGER
   FIELD f2 AS CHARACTER
   INDEX ix1 IS PRIMARY f1.

CREATE tta.
tta.f1 = 1.
FOR EACH tta:
   MESSAGE "b.p" tta.f1 tta.f2.
END.

c.p:

MESSAGE "c.p".

Each case starts from these three programs. An incremental conversion converts all programs, unless a step says otherwise.

Removing the temp-table from a program fails, and so does every later conversion:
  1. Run a full conversion.
  2. Replace the code of a.p with MESSAGE "a.p". and run an incremental conversion. It aborts with Error loading AST file/resource: ./cvt/a.p.schema.
  3. Add a comment to b.p and run an incremental conversion. It aborts with the same error.
  4. Add a comment to c.p and run an incremental conversion. It aborts with the same error, although c.p has no temp-table.
  5. Run an incremental conversion without changing any file. It reports INCREMENTAL CONVERSION: no changed files found and succeeds, but A.java still uses tta, and B.java and C.java miss the comments of steps 3 and 4.
Renaming a program which defines a temp-table fails:
  1. Run a full conversion.
  2. Rename a.p to a2.p and run an incremental conversion. It aborts with a NullPointerException.
  3. Run an incremental conversion without changing any file. It succeeds, but A2.java is never generated.
  4. Add a comment to b.p and run an incremental conversion. It aborts with the same NullPointerException.
Deleting a program which defines a temp-table fails when the next conversion names a single file:
  1. Run a full conversion.
  2. Delete a.p, add a comment to b.p, and run an incremental conversion of b.p only. It aborts with the same NullPointerException.
  3. Run an incremental conversion without changing any file. It succeeds, but B.java misses the comment of step 2.
  4. Add another comment to b.p and run an incremental conversion. It aborts with the same NullPointerException.
Deleting the program and converting all programs succeeds only for that run:
  1. Run a full conversion.
  2. Delete a.p and run an incremental conversion. It succeeds.
  3. Add a comment to b.p and run an incremental conversion. It aborts with the same NullPointerException.

All these errors are raised by the rule preTmpTabNames = createMapAstKeyToString("pre_tmpTabNames") in rules/fixups/stable_naming.xml. The error of the removal case is:

Caused by: com.goldencode.ast.AstException: Error loading AST file/resource: ./cvt/a.p.schema
    at com.goldencode.ast.XmlFilePlugin.loadTree(XmlFilePlugin.java:335)
    at com.goldencode.ast.AstManager.loadTree(AstManager.java:373)
    at com.goldencode.p2j.uast.AstKey.getAst(AstKey.java:697)
    at com.goldencode.p2j.uast.AstKey.equals(AstKey.java:240)
    at java.base/java.util.HashMap.putVal(HashMap.java:633)
    at java.base/java.util.HashMap.put(HashMap.java:610)
    at com.goldencode.p2j.convert.db.H2Map.lambda$new$0(H2Map.java:236)
    at com.goldencode.p2j.convert.db.DBHelper.executeQuery(DBHelper.java:597)
    at com.goldencode.p2j.convert.db.H2Map.<init>(H2Map.java:245)
    at com.goldencode.p2j.convert.db.ConversionData.createMap(ConversionData.java:1648)
    at com.goldencode.p2j.pattern.CommonAstSupport$Library.createMapAstKeyToString(CommonAstSupport.java:6505)
Caused by: java.lang.IllegalArgumentException: Missing/bogus input file/resource ./cvt/a.p.schema
    at com.goldencode.ast.XmlFilePlugin.loadTree(XmlFilePlugin.java:309)

The error of the rename and delete cases is:

Caused by: java.lang.NullPointerException: Cannot invoke "com.goldencode.artifacts.Artifact.getRelativePath()" because "artifact" is null
    at com.goldencode.ast.XmlFilePlugin.loadTree(XmlFilePlugin.java:286)
    at com.goldencode.ast.AstManager.loadTree(AstManager.java:373)
    at com.goldencode.p2j.uast.AstKey.getAst(AstKey.java:697)
    at com.goldencode.p2j.uast.AstKey.equals(AstKey.java:240)
    at java.base/java.util.HashMap.putVal(HashMap.java:633)
    at java.base/java.util.HashMap.put(HashMap.java:610)
    at com.goldencode.p2j.convert.db.H2Map.lambda$new$0(H2Map.java:236)
    at com.goldencode.p2j.convert.db.DBHelper.executeQuery(DBHelper.java:597)
    at com.goldencode.p2j.convert.db.H2Map.<init>(H2Map.java:245)
    at com.goldencode.p2j.convert.db.ConversionData.createMap(ConversionData.java:1648)
    at com.goldencode.p2j.pattern.CommonAstSupport$Library.createMapAstKeyToString(CommonAstSupport.java:6505)

When b.p defines a different temp-table than a.p, the rename and the single-file delete still fail, at other places of the same rule set. Removing the temp-table from a.p then succeeds, but the DMO of that temp-table stays in src/.

#2 Updated by Octavian Adrian Gavril 20 days ago

  • Status changed from New to WIP
  • Assignee set to Octavian Adrian Gavril

I'm looking into this one.

#3 Updated by Octavian Adrian Gavril 20 days ago

I ran the testcases of this task on 7169a (#7169) at revision 16835, which is based on trunk 16826. Each step is an incremental conversion, whose output I compared with a full conversion of the same sources by the same build.

The first issue which 7169a fixes is deleting or renaming a temp-table program, both when the incremental conversion is given the whole file set and when it names only another file. ConversionData.cleanupArtifacts() now calls clean(sourceArtifact, true), which purges the pre_tmpTabNames entries of the deleted program.

The second issue which 7169a fixes is the silent staleness. A failed incremental conversion no longer leaves the hashes its files saved at parse time. ConversionData.invalidateFailed() (added in 16813 of 7169a) drops the conversion data and the signature of every file the failed job selected, so the next incremental conversion converts them again instead of reporting no changed files.

These cases still fail with 7169a and remain to be fixed in this task:
  1. Removing a temp-table from a program or a class, when another program defines the same temp-table. The conversion fails, and so does every later incremental conversion.
  2. Removing one of the two temp-tables of a program, when another program defines the same temp-table. This case was not in the initial note.
  3. Removing a temp-table from a program, and later adding the same temp-table to another program. The conversion which adds it fails.
  4. Deleting a temp-table program with trunk 16826, then converting another temp-table program with 7169a. The conversion data left by trunk makes the incremental conversion fail.

I will move the focus of this task to these cases only, and let 7169a bring the fixes for the other issues.

#4 Updated by Octavian Adrian Gavril 19 days ago

  • % Done changed from 0 to 100
  • Status changed from WIP to Review
  • reviewer Constantin Asofiei, Dănuț Filimon added

The fix is in 12107a/16827 and changes H2Map and AstKey.

The cause of the failures is that a kept pre_tmpTabNames entry identifies its temp-table only by the ID of a node in the .schema file of the program. When the program loses a temp-table, its .schema file is written again with new node IDs, or it is deleted. The entry then points to another node or to none, and comparing a temp-table with it fails when the map is loaded. Since the entry is never removed, the error repeats in every later incremental conversion.

The fix is that H2Map now skips such an entry when it loads the map. For a program which the incremental conversion converts again, the new AstKey.isCurrent() loads the node and checks that it still has the same structure. For the other programs, the entry is skipped only when the .schema file is no longer registered or no longer exists. A skipped entry is dropped when the map is saved, so the temp-table gets the same name as in a full conversion. An entry whose node did not change is kept, so the program keeps its temp-table names.

AstKey also gets a fixed serialVersionUID, equal to the value Java computes for it on trunk 16826. The keys are stored serialized in the conversion database, and without it the new public method would change that value and make the existing conversion data unreadable.

The extra cost is small. For a program converted in the same run, the check loads its .schema file, which this run has just written. For the other programs, it only checks that the .schema file is registered and exists, so a run does not load the .schema files of the whole project.

I tested the fix with the testcases of this task, comparing each incremental conversion with a full conversion of the same sources:
  • The four cases of the previous note pass, with 1 and with 4 conversion threads. They fail on trunk 16826 and on 7169a.
  • The rename and delete cases of the initial note pass too.
  • Without the check of the converted programs, removing one of the two temp-tables fails again. Without the check of the other programs, the case with the conversion data left by trunk 16826 fails again.
  • A conversion which follows a failed one still misses the files of the failed one, as on trunk 16826. This is the case which 7169a fixes.
  • 7169a at revision 16835 with this change passes all testcases of this task.
  • With the testcases of #12029 (31 cases, 111 steps), no step which passes on trunk 16826 gets worse, and 23 steps get better.

Danut, Constantin, please review the changes.

#5 Updated by Dănuț Filimon 18 days ago

Review of 12107a/16827:
  • src/com/goldencode/p2j/convert/db/H2Map.java: should not reference uast.AstKey (please remove the import, which was unused before), you can move the additional Consumer code in a separate method from DBHelper.
  • src/com/goldencode/p2j/uast/AstKey.java: Add a warning log when there is an exception.

#6 Updated by Octavian Adrian Gavril 18 days ago

src/com/goldencode/p2j/convert/db/H2Map.java: should not reference uast.AstKey (please remove the import, which was unused before), you can move the additional Consumer code in a separate method from DBHelper.

Done in 12107a/16828. The check is now the new DBHelper.isStale(), and H2Map no longer imports com.goldencode.p2j.uast.AstKey and com.goldencode.artifacts.*.

src/com/goldencode/p2j/uast/AstKey.java: Add a warning log when there is an exception.

I did not add it, because the exception is thrown in a normal case. A program has a .schema file only while it defines a temp-table. When its only temp-table is removed, the incremental conversion converts the program again and its .schema file no longer exists, but the kept pre_tmpTabNames entry of the program still names a node of that file. isCurrent() then calls getAst(), which loads the tree through AstManager.loadTree(). The tree artifact is still registered but its file is gone, so XmlFilePlugin.loadTree() throws IllegalArgumentException("Missing/bogus input file/resource ./cvt/a.p.schema") and wraps it in AstException("Error loading AST file/resource: ./cvt/a.p.schema").

This is the same exception which made trunk 16826 fail in this case (the first stack trace of the initial note), where AstKey.equals() called getAst(). Catching it in isCurrent() is how the entry gets dropped, so a warning would show in every successful incremental conversion after a temp-table is removed from a program which has no other one.

The other exception of XmlFilePlugin.loadTree(), the NullPointerException for a tree which is no longer registered, does not reach isCurrent(). A renamed or deleted program is not converted again, so DBHelper.isStale() only checks that its tree is still registered and that its file exists, without loading the tree.

#7 Updated by Octavian Adrian Gavril 18 days ago

I ran the testcases of this task again on 7169a at revision 16836, which Danut committed on November 3. Since 16836, AstKey stores what equals() compares and no longer loads the AST, so loading pre_tmpTabNames no longer fails when a .schema file is deleted or written again.

The cases of #12107-3 which still failed with 7169a/16835 now pass with 7169a/16836 alone, without 12107a, with the same results as 12107a. These are removing a temp-table from a program or a class which another program also defines, removing one of the two temp-tables of a program, and removing a temp-table and later adding it to another program. The rename and delete cases of the initial note pass as well.

The case with the conversion data left by trunk 16826 still fails with 7169a/16836, with JdbcSQLDataException: Deserialization failed. 16836 cannot read a conversion database written before it, so this case needs a full conversion on 7169a, with or without 12107a.

The case which 7169a/16836 still gets wrong, and which 12107a fixes, is a change of a temp-table definition. It uses the testcase of #12029-1.

ttappsrv.i:

DEFINE {1} SHARED TEMP-TABLE tt-appsrv
   FIELD partition AS CHARACTER
   FIELD host      AS CHARACTER
   INDEX pi-part IS PRIMARY UNIQUE partition.

ttaview.p:

{ttappsrv.i}

FOR EACH tt-appsrv NO-LOCK:
END.

ttdef1.p:

{ttappsrv.i "NEW GLOBAL"}

CREATE tt-appsrv.
ASSIGN tt-appsrv.partition = "one".

ttdef2.p:

{ttappsrv.i "NEW GLOBAL"}

CREATE tt-appsrv.
ASSIGN tt-appsrv.partition = "two".
The steps are these:
  1. Run a full conversion.
  2. Add FIELD port AS INTEGER to ttappsrv.i after the field host, and run an incremental conversion. It succeeds and the Java compiles, but the temp-table gets the new DMO interfaces TtAppsrv_2 and TtAppsrv_2_1, and TtAppsrv_1 stays in src/ without the field port. A full conversion of the same sources names the temp-table TtAppsrv_1 and TtAppsrv_1_1, with the field port.

Trunk 16826 gives the same result. With 12107a, the incremental conversion gives the same Java as a full conversion, except the SQL table name of the temp-table (tt6 instead of tt4), which comes from a counter.

The reason is that the kept pre_tmpTabNames entry of the old definition stays in the map. 16836 compares it by its stored content, so it no longer matches the changed temp-table, which then gets a new name. 12107a drops such an entry when its program is converted again and its node has changed (AstKey.isCurrent()).

So 12107a is still needed for a changed temp-table definition after 7169a. Its AstKey part cannot be merged into 7169a as it is, because isCurrent() uses getAst(), which 16836 removed, and DBHelper.isReconverted() now takes the conversion job as well. This is what makes the merge conflict in all three files.

As 7169a will reach trunk only later, I think 12107a would be merged first. When 7169a is rebased on that trunk, the check of a changed definition has to be adapted to the new AstKey, and I can prepare a patch for 7169a which does that.

#8 Updated by Octavian Adrian Gavril 7 days ago

As agreed with Greg, the fixes for this issue are in 7169a (#7169) instead of 12107a, and branch 12107a will not be merged.

These cases are fixed by fixes which 7169a already had:
  • Renaming or deleting a program which defines a temp-table.
  • The stale Java which a run reports as successful after a failed incremental conversion.
  • Removing a temp-table from a program, since 16836.
This case is fixed by a new fix which I moved from 12107a to 7169a in revision 16838, adapted to the new AstKey of 7169a (#7169-84):
  • Changing a temp-table definition (#12107-7).

This task can be closed.

#9 Updated by Greg Shah 7 days ago

  • Status changed from Review to Rejected

Please dead-archive 12107a.

#10 Updated by Octavian Adrian Gavril 7 days ago

Branch 12107a was archived as dead.

#11 Updated by Octavian Adrian Gavril 4 days ago

  • Related to Feature #7169: drive conversion order using user-specified dependencies added

Also available in: Atom PDF