Cleaning up EnsLib.SQL.Snapshot in BPL's
We are trying to track down significant growth within our Namespaces, one big culprit is Ens.AppData (EnsLib.SQL.Snapshot).
Within many of our BPL's we use EnsLib.SQL.Snapshot to return Results from External SQL Stored Procedures or Query's. The same EnsLib.SQL.Snapshot context variable is used for many of these calls within a BPL.
Is there something we should be doing at the end of the BPL to ensure that EnsLib.SQL.Snapshot gets cleaned up and purged from Ens.AppData?
Looking over some of the documentation it states that maybe a %OnDelete() class method needs defined but not sure where I need to define it from within a BPL.
Comments
To address the significant growth in your namespace caused by Ens.AppData related to the usage of EnsLib.SQL.Snapshot in Business Process Language (BPL):
-
Issue with cleaning EnsLib.SQL.Snapshot:
The snapshot data is not automatically cleaned during purge operations if it is used as a property within response messages. This results in the global ^Ens.AppData growing indefinitely. You can clean this manually in two steps:- Stop the production.
- Run
do ##class(Ens.Adapter).ClearStaticAppData("EnsLib.SQL.Snapshot")in the terminal of the relevant namespace to clearEnsLib.SQL.Snapshotdata from ^Ens.AppData. - Execute SQL command
TRUNCATE TABLE EnsLib_SQL.Snapshotto clean upEnsLib.SQL.Snapshotentries from the database1.
-
Defining %OnDelete Method:
Implementing the%OnDeletemethod in the class holding theEnsLib.SQL.Snapshotproperty ensures proper cleanup of snapshot data during message deletion. Here is an example:Class ResponseMessage Extends Ens.Response { Property SnapshotProp As EnsLib.SQL.Snapshot; ClassMethod %OnDelete(oid As %ObjectIdentity) As %Status [ Private, ServerOnly = 1 ] { set tSC = $$$OK set id = $$$oidPrimary(oid) set obj = ..%OpenId(id) if (obj.SnapshotProp '= "") { set tSC = ##class(EnsLib.SQL.Snapshot).%DeleteId(obj.SnapshotProp.%Id()) } return tSC } }This ensures that associated snapshot data is deleted alongside its parent message1.
-
Alternative Approaches:
- Avoid using
EnsLib.SQL.Snapshotas a direct property. Instead, map the data to another object type (e.g., JSON string or custom class objects). This preventsEnsLib.SQL.Snapshotfrom being stuck in the global ^Ens.AppData1. - Periodically review and manage orphaned data or snapshots using implemented cleanup tasks in your production environment, ensuring your database remains manageable2.
- Avoid using
By implementing these methods, you can reduce the growth in your namespace and ensure that the cleanup of EnsLib.SQL.Snapshot aligns with your application’s lifecycle. 12
Sources: