Added safety and completeness for database trash bin emptying
The current trash bin emptying logic is not rigorous or complete enough at the moment. It currently uses TGRemover to remove entries of the trash bin, which can result in crashes like this:
org.simantics.PlatformException: org.simantics.db.exception.ServiceException: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
Caused by: org.simantics.db.exception.ServiceException: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
at org.simantics.db.layer0.util.Layer0Utils.emptyTrashBin(Layer0Utils.java:1297)
at org.simantics.db.layer0.util.Layer0Utils.emptyTrashBin(Layer0Utils.java:1247)
at org.simantics.db.layer0.util.Layer0Utils.emptyTrashBin(Layer0Utils.java:1243)
at fi.semantum.gams.db.SCLFunctions.loadGAMS(SCLFunctions.java:160)
at scl.GAMS.DB.SCLMain$1.Temp.apply(_SCL_FunctionValue)
at org.simantics.scl.runtime.function.FunctionImpl1.applyArray(FunctionImpl1.java:83)
at org.simantics.scl.compiler.internal.interpreted.IApply.execute(IApply.java:29)
at org.simantics.scl.compiler.internal.interpreted.ILambda$Arity2Func.apply(ILambda.java:69)
at org.simantics.scl.runtime.function.UnsaturatedFunction1.apply(UnsaturatedFunction1.java:19)
at org.simantics.modeling.LifeCycleContext.load(LifeCycleContext.java:20)
at org.simantics.modeling.LifeCycleProcesses.configure(LifeCycleProcesses.java:61)
at org.simantics.project.impl.Project.activate(Project.java:124)
....
Caused by: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
at org.simantics.db.layer0.adapter.impl.TGRemover.remove(TGRemover.java:78)
at org.simantics.db.layer0.util.Layer0Utils$4.perform(Layer0Utils.java:1272)
at fi.vtt.simantics.procore.internal.SessionImplSocket$3.run(SessionImplSocket.java:665)
at fi.vtt.simantics.procore.internal.SessionRequestManager$3.run(SessionRequestManager.java:177)
at org.simantics.db.impl.query.QueryThread.run(QueryThread.java:251)
Caused by: org.simantics.db.exception.DatabaseException: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
at org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest.perform(ModelTransferableGraphSourceRequest.java:276)
at org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest.perform(ModelTransferableGraphSourceRequest.java:1)
at org.simantics.db.impl.query.QueryProcessor.tryQuery(QueryProcessor.java:5192)
at org.simantics.db.impl.graph.ReadGraphImpl.syncRequest(ReadGraphImpl.java:1912)
at org.simantics.db.layer0.adapter.impl.TGRemover.remove(TGRemover.java:48)
... 4 more
Caused by: org.simantics.db.exception.RuntimeDatabaseException: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
at org.simantics.db.layer0.util.ModelTransferableGraphSource$1.execute(ModelTransferableGraphSource.java:106)
at gnu.trove.map.hash.TIntIntHashMap.forEachEntry(TIntIntHashMap.java:422)
at org.simantics.db.layer0.util.ModelTransferableGraphSource.<init>(ModelTransferableGraphSource.java:98)
at org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest.getSource(ModelTransferableGraphSourceRequest.java:282)
at org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest.perform(ModelTransferableGraphSourceRequest.java:268)
... 8 more
Caused by: org.simantics.db.exception.ValidationException: Reference to external resource Inverse:$2392121 without unique uri (0 parents).
at org.simantics.db.layer0.util.ModelTransferableGraphSource.getId(ModelTransferableGraphSource.java:191)
at org.simantics.db.layer0.util.ModelTransferableGraphSource$1.execute(ModelTransferableGraphSource.java:103)
... 12 more
which are caused by corruptions in the removed material. The code that does the removal cannot really expect any kind of correctness from the material in the trash bin. Therefore we need to add two kinds fallback logics for TGRemover:
- IsComposedOfRemover
- Removes all statements from all resources starting from the specified resource that are
- reachable through an L0.IsComposedOf chain from the starting resource
- either owned by no root (L0.IsOwnedBy) or owned by the removed root resource
- Removes statements and their inverses to/from resources that are owned by some other index root
- Removes all statements from all resources starting from the specified resource that are
- UnlinkRemover which is ran only if all else fails
Edited by Tuukka Lehtonen