Article
· Apr 10 3m read

Version Checking on objects. “ERROR:5800”

If you have system tables implementing the "VERSIONPROPERTY" functionality, you may encounter error 5800. This article explains how this error occurs and provides solutions to resolve the issue.

When version checking is implemented, the property specified by VERSIONPROPERTY is automatically incremented each time an instance of the class is updated (either by objects or SQL).

For example:

ClassMethod RunVersionChange() As %Status
{
    Set sample = ##class(dado.TblSample).%OpenId("42")
    Write !,"VERSIONPROPERTY value: "_ sample.VersionCheck

    Do sample.StatusSetObjectId("AL")
    DO sample.%Save()
    WRITE !,!,"SAVED",!

    Write !,"VERSIONPROPERTY value: "_ sample.VersionCheck
}

After executing the %Save() command, the VersionCheck property of the object was incremented by 1.

This feature is useful for performing evaluations and audits of database records.

In CACHÉ/IRIS, the same object extending a %Persistent class can have its OREF sharing within the same process.

For example:

ClassMethod RunVersionChangeSameProcess() As %Status
{
    Set firstInstance = ##class(dado.TblSample).%OpenId("42")
    Set secondInstance = ##class(dado.TblSample).%OpenId("42")

    Write !,"VERSIONPROPERTY first instance value: "_ firstInstance.VersionCheck
    Write !,"VERSIONPROPERTY second instance value: "_ secondInstance.VersionCheck

    Do firstInstance.StatusSetObjectId("QR")
    Do firstInstance.%Save()
    WRITE !,!,"EXECUTED SAVE on first instance ",!

    Write !,"VERSIONPROPERTY first instance value: "_ firstInstance.VersionCheck
    Write !,"VERSIONPROPERTY second instance value: "_ secondInstance.VersionCheck
}

This implies that, as long as they are in the same process, the VersionCheck defined in VERSIONPROPERTY of the dado.TblSample table will always be up-to-date across its instances.

However, when making a change in different processes, the same behavior is not true, as demonstrated in the example:

ClassMethod RunVersionChangeTwoProcess() As %Status
{
    Set sample = ##class(dado.TblSample).%OpenId("42")

    Try {
        Do sample.StatusSetObjectId("AL")
        $$$THROWONERROR(sc,sample.%Save())

        Write !,"VERSIONPROPERTY BEFORE EXECUTING JOB: "_ sample.VersionCheck

        JOB ##class(s01.Error5800).RunVersionChange()
        hang 2

        Do sample.StatusSetObjectId("EP")
        Write !,"VERSIONPROPERTY AFTER EXECUTING JOB: "_ sample.VersionCheck

        Write !,"TRY RUN SAVE: "
        $$$THROWONERROR(sc,sample.%Save())

    }
    Catch ex {
        WRITE !,!,"In the CATCH block"
        WRITE !,"Error code=",ex.Code

        Do sample.%Reload()
        Write !,!,"VERSIONPROPERTY AFTER Reload: "_ sample.VersionCheck
    }
}

In this example, the JOB line JOB ##class(s01.Error5800).RunVersionChange() is performed after an instance of tblSample, however process 2 made a change to the same record already instantiated in JOB 1, ending it before tblSample.%Save() in the first process, causing VersionCheck desynchronization between processes.

This leads to ERROR 5800:

Upon consulting the record in the database, we find that the VersionCheck is at an older version compared to process 1:

To avoid the problem, after asynchronous calls that can change the same database record, it is recommended to use %Reload before making the necessary changes, as in the example:


ClassMethod RunVersionChangeTwoProcessWithReload() As %Status { Set sample = ##class(dado.TblSample).%OpenId("42") Try { Do sample.StatusSetObjectId("AL") $$$THROWONERROR(sc,sample.%Save()) Write !,"VERSIONPROPERTY BEFORE EXECUTING JOB: "_ sample.VersionCheck JOB ##class(s01.Error5800).RunVersionChange() hang 2 Do sample.%Reload() Do sample.StatusSetObjectId("EP") Write !,"VERSIONPROPERTY AFTER EXECUTING JOB: "_ sample.VersionCheck Write !,"TRY RUN SAVE: " $$$THROWONERROR(sc,sample.%Save()) } Catch ex { WRITE !,!,"In the CATCH block" WRITE !,"Error code=",ex.Code Do sample.%Reload() Write !,!,"VERSIONPROPERTY AFTER Reload: "_ sample.VersionCheck } }

Discussion (0)1
Log in or sign up to continue