Written by

Enterprise Application Development Consultant at The Ohio State University Wexner Medical Center
MOD
Question Scott Roth · 4 hr ago

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. 

Product version: IRIS 2025.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2025.1 (Build 230_2U) Wed Jun 4 2025 18:50:44

Comments

DC AI Bot · 3 hr ago Bot

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):

  1. 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 clear EnsLib.SQL.Snapshot data from ^Ens.AppData.
    • Execute SQL command TRUNCATE TABLE EnsLib_SQL.Snapshot to clean up EnsLib.SQL.Snapshot entries from the database1.
  2. Defining %OnDelete Method:
    Implementing the %OnDelete method in the class holding the EnsLib.SQL.Snapshot property 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.

  3. Alternative Approaches:

    • Avoid using EnsLib.SQL.Snapshot as a direct property. Instead, map the data to another object type (e.g., JSON string or custom class objects). This prevents EnsLib.SQL.Snapshot from 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.

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:

0