Skip to main content

%Library.GlobalEdit

persistent class %Library.GlobalEdit extends %Library.Persistent, %SYSTEM.Help

SQL Table Name: %Library.GlobalEdit

Property Inventory

Method Inventory

Parameters

parameter DEFAULTCONCURRENCY = 0;
Inherited description: DEFAULTCONCURRENCY is the default value for the concurrency formal argument defined for %Open, %OpenId, %Delete and %DeleteId methods. It is not the default value of the %Concurrency property of persistent classes. If the value of the actual concurrency argument passed to any of the above methods is -1 then the formal argument value will be set to the value of the DEFAULTCONCURRENCY parameter value defined for the class.

Properties

property Collation as %Library.Collate;
Collation of the global.
Property methods: CollationCollationListClose(), CollationCollationListExecute(), CollationCollationListFetch(), CollationDisplayToLogical(), CollationGet(), CollationGetLocalName(), CollationGetLocalNumber(), CollationGetSystemDefaultName(), CollationGetSystemDefaultNumber(), CollationIsValid(), CollationIsValidName(), CollationIsValidNumber(), CollationLogicalToDisplay(), CollationMakeArray(), CollationNormalize(), CollationSet(), CollationSetLocalName(), CollationSetLocalNumber()
property DatabaseBlockSize as %Integer (VALUELIST = ",2048,4096,8192,16384,32768,65536") [ InitialExpression = $$$8k , ReadOnly ];
Block size of the database the global is in.
Property methods: DatabaseBlockSizeDisplayToLogical(), DatabaseBlockSizeGet(), DatabaseBlockSizeIsValid(), DatabaseBlockSizeLogicalToDisplay(), DatabaseBlockSizeNormalize()
property Directory as %SysPath [ ReadOnly ];
Directory global is located in.
Property methods: DirectoryDisplayToLogical(), DirectoryGet(), DirectoryIsValid(), DirectoryLogicalToDisplay(), DirectoryLogicalToOdbc(), DirectoryNormalize()
property Exists as Security.Datatype.BooleanYN [ ReadOnly ];
Global directory entry exists.
Property methods: ExistsDisplayToLogical(), ExistsGet(), ExistsIsValid(), ExistsLogicalToDisplay(), ExistsLogicalToOdbc(), ExistsNormalize(), ExistsOdbcToLogical()
property FirstDataBlock as %Integer [ Calculated ];
First data block of the global.
Note referencing this property causes a $D(global) and I/O to occur.
Property methods: FirstDataBlockDisplayToLogical(), FirstDataBlockIsValid(), FirstDataBlockLogicalToDisplay(), FirstDataBlockNormalize()
property GrowthBlock as %Integer;
Growth block for the global.
Property methods: GrowthBlockDisplayToLogical(), GrowthBlockGet(), GrowthBlockIsValid(), GrowthBlockLogicalToDisplay(), GrowthBlockNormalize()
property IsEmpty as Security.Datatype.BooleanYN [ ReadOnly ];
Global contains no data.
Property methods: IsEmptyDisplayToLogical(), IsEmptyGet(), IsEmptyIsValid(), IsEmptyLogicalToDisplay(), IsEmptyLogicalToOdbc(), IsEmptyNormalize(), IsEmptyOdbcToLogical()
property IsKeep as Security.Datatype.BooleanYN;
Keep global directory attributes when deleted.
Property methods: IsKeepDisplayToLogical(), IsKeepGet(), IsKeepIsValid(), IsKeepLogicalToDisplay(), IsKeepLogicalToOdbc(), IsKeepNormalize(), IsKeepOdbcToLogical()
property Name as %String;
Name of the global.
Property methods: NameDisplayToLogical(), NameGet(), NameIsValid(), NameLogicalToDisplay(), NameLogicalToOdbc(), NameNormalize()
property Permission as Security.Datatype.Permission [ ReadOnly ];
Current permission on the global. This is the "RW" value that the process who has this instance open has access to it.
Property methods: PermissionDisplayToLogical(), PermissionExternalToInternal(), PermissionGet(), PermissionInternalToExternal(), PermissionIsValid(), PermissionLogicalToDisplay(), PermissionLogicalToOdbc(), PermissionNormalize()
property PointerBlock as %Integer;
Top pointer block of the global.
Property methods: PointerBlockDisplayToLogical(), PointerBlockGet(), PointerBlockIsValid(), PointerBlockLogicalToDisplay(), PointerBlockNormalize()
property ResourceName as %String [ ReadOnly ];
Resource name of the global.
Property methods: ResourceNameDisplayToLogical(), ResourceNameGet(), ResourceNameIsValid(), ResourceNameLogicalToDisplay(), ResourceNameLogicalToOdbc(), ResourceNameNormalize()
property System as %String [ ReadOnly ];
System name where global resides.
Property methods: SystemDisplayToLogical(), SystemGet(), SystemIsValid(), SystemLogicalToDisplay(), SystemLogicalToOdbc(), SystemNormalize()

Methods

classmethod CheckGlobalIntegrity(Directory As %String = "", Name As %String, StopAfterAnyError As %Boolean) as %Status
This checks the integrity of a single global. The return value contains information about the global
method CheckIntegrity(Silent As %Boolean) as %Status
This checks the integrity of a global. The return value contains information about the global
classmethod CollationPrompt(Prompt, Obj)
method CollationSet(Arg As %String) as %Status
method Compact(PercentFull As %Integer = 90, ByRef MbProcessed As %Float, ByRef MbCompressed As %Float, MbToCompress As %Integer = 0, ByRef LastGlobalReference As %String = "") as %Status
Compact a global.
PercentFull - How full each data page should be, 50-100
MbProcessed - How many MB of the global was processed
MbCompressed - How many MB was it compressed to
MbToCompress - How many MB of the global to compress in this call (0=ALL)
LastGlobalReference - Last reference, "" = completed

Typical useage is as follows, which compacts the data pages to 80%full, and returns the amount of data processed, and the size it was compacted to:

s x=##Class(%GlobalEdit).Open("X",dbdirectory)
s t=x.Compact(80,.CurrSize,.NewSize)

Note that this function can be called repeatedly for the same global so that it can be done in chunks by using the last two parameters. The following example does 10MB chunks of the global at a time and accumulates and displays a status:

s x=##Class(%GlobalEdit).Open("X",dbdirectory)
s TotalCurrSize=0,TotalNewSize=0
do {
s t=x.Compact(80,.CurrSize,.NewSize,10,.LastReference)
s TotalCurrSize=TotalCurrSize+CurrSize
s TotalNewSize=TotalNewSize+NewSize
w !,"Global "_x.Name_" processed="_TotalCurrSize_", compacted to="_TotalNewSize
} while LastReference'=""
classmethod CompactGlobal(Name As %String, Directory As %String = {$zu(12, "")}, PercentFull As %Integer = 90, ByRef MbProcessed As %Integer, ByRef MbCompressed As %Integer, MbToCompress As %Integer = 0, ByRef LastGlobalReference As %String = "") as %Status
Compact a global.
See the method Compact for details on parameters.
classmethod CompareRange(SrcDirectory As %String, DstDirectory As %String, StartingNode As %String, EndingNode As %String, MaxDifferences As %Integer = 0, MaxToCompare As %String = "0,0", Flags As %Integer = 7, ByRef Differences As %String) as %Status
Compare the same global in two different databases.
Parameters: 
SrcDirectory - Directory where the source nodes are located.
DstDirectory - Directory where the destination nodes are located.
StartingNode - Node where the compare is started.
EndingNode - Node where the compare finishes. "" - (Default) Compare all nodes until end of global.
MaxDifferences - Maximum number of differences to return. 0 - (Default) Return all differences.
MaxToCompare - 2 Piece comma delimited string as follows:

  If Flags Bit 3 - Off:"MaxMBToProcess,AverageNodeSize"
    If MaxMBToProcess is 0, then the method will process the entire range.
    If MaxMBToProcess is > 0, then the method will return after that number of MB has been processed.
    If AverageNodeSize is 0, then the MB processed is calculated by adding the length of each node and its data value.
    If AverageNodeSize is > 0, then the MB processed is calculated by multiplying the number of nodes processed by
    the AverageNodeSize. This is more accurate.

  If Flags Bit 3 - On: "MaxNodesToProcess,AverageNodeSize"
    If MaxNodesToProcess is 0, then the method will process the entire range.
    If MaxNodesToProcess is > 0, then the method will return after that number of nodes has been processed.
    If AverageNodeSize is 0, then the MB processed is calculated by adding the length of each node and its data value.
    If AverageNodeSize is is > 0, then the MB processed is calculated by multiplying the number of nodes processed by
    the AverageNodeSize. This is more accurate.
  
Flags - Bit string of compare options.
  Bit 0 - Return Data values
  Bit 1 - Format Node names using %Library.Utility:FormatReference()
  Bit 2 - Format Data values using %Library.Utility:FormatString()
  Bit 3 - 0 - MaxMBToProcess is passed in MaxToCompare variable
          1 - MaxNodesToProcess is passed in MaxToCompare variable

Return Values:
Status - Return Status of the method. 
  1) If MaxMBToProcess is > 0, and we have reached the max, the error $$$ERROR($$$MaxMBToCompare) is returned.
  2) If MaxNodesToProcess is > 0, and we have reached the max, the error $$$ERROR($$$MaxNodesToCompare) is returned.
  3) If MaxDifferences > 0 and we have reached the max, the error $$$ERROR($$$MaxDifferencesReached) is returned.
  4) If we have exceeded process storage space ($s) with a large amount of differences, the error $$$ERROR($$$MaxStorageReached) is returned.
  In these four cases any differences found are returned in the Differences() array. The caller may then call this method again using the returned LastNodeProcessed as
  the StartingNode to compare the next set of nodes.
  5) $$$ERROR($$$DifferencesFound) - The compare completed successfuly, and some differences were found. Results are in the Differences() array.
  6) $$$OK - The compare has completed successfully. No differences were found.

Differences - Number of differences
Differences(0) - $lb(LastNodeProcessed,BlocksChecked,NodesChecked,MBChecked,BlockSize)
  LastNodeProcessed - Last node processed in the compare. May be used as the StartingNode if the method is called again. Returns "" if at end of range.
  BlocksChecked - Number of Blocks in the SrcDirectory processed. More accurate if AverageNodeSize is passed.
  NodesChecked - Number of Nodes in the SrcDirectory processed.
  MBChecked - Number of MB in the SrcDirectory processed. More accurate if AverageNodeSize is passed.
  BlockSize - Blocksize of the SrcDirectory
  
Differences(1..x,1) - Global name. Always returned, may be formatted if specified in the Flags parameter.
Differences(1..x,2) - Reason for difference
  1 - Value is Different
  2 - Node is in source but not destination
  3 - Node is in destination but not source
Differences(1..x,3) - Source data value or "" if source does not exist. Only returned if specified in the Flags parameter. May be formatted if specified in the Flags parameter
Differences(1..x,4) - Destination data value or "" if source does not exist. Only returned if specified in the Flags parameter. May be formatted if specified in the Flags parameter]]>

Notes:
AverageNodeSize should be passed for most accurate values for BlocksChecked and MBChecked values in the Differences(0) return value.
AverageNodeSize is returned by the method %Library.GetGlobalSizeBySubscript(). See this method for how this value is calculated.
classmethod Create(Namespace As %String = "", Name As %String, Collation As %String, GrowthBlock As %Integer, PointerBlock As %Integer, Keep As %Boolean, JournalState As %Integer, ByRef Exists As %Boolean) as %Status
Create a global with specified characteristics. Parameter Namespace can be a namespace or a directory. If it is a namespace global mapping rules will apply.
classmethod DeleteDirectoryEntry(Directory, Global) as %Status
Delete a directory entry for a global if the global does not exist.
This should be called with Switch 10 set if the global is possibly being accessed by users.

Parameters:
Directory - Directory where the global lives.
Global - Name of the global to delete the directory entry for.
Note: You must have write access to the database to delete the directory entry.
method FirstDataBlockGet() as %Integer
classmethod GetGlobalCountBySubscript(Directory As %String, StartingNode As %String, EndingNode As %String = "", ByRef Size As %String = 0)
Return the number of global nodes in the range, and journal sizing information.
This method will return the number of global nodes in the range, and the sizes of data within that range. It will also return information about the amount of journal space which would be used if the range were merged into a different database, or moved via a DataMove operation.

Parameters:
Directory - Directory where global is located.
StartNode - Starting node of global. Note that you can specify ^GLOBAL(BEGIN) to mean the start of the global. This would include ^GLOBAL itself. You can also specify ^GLOBAL("XXX"_$c(1)_"*next)" to mean start counting after global ^GLOBAL("XXX").
EndNode - End Node of global. The returned sizes do not include the EndNode. Note that you can specify ^GLOBAL(END) to mean through the end of the global. An EndNode value of null, or equal to the value of StartNode will return the size of StartNode and all children of StartNode.
Return Values:
The method will return a %Status value of success, or an error.
The array Size returns data and estimated journal sizes in both blocks and MB for the specified global range.
If the global does not exist the sizes will all be set to 0. If any error occurs, sizes will not be set.

Size=Number of data nodes
Size("DataSize","Bytes")=Size of global data in bytes
Size("DataSize","MB")=Size of global data in MB
Size("KeySize","Bytes")=Size of global keys in bytes
Size("KeySize","MB")=Size of global keys in MB
Size("TotalNodeSize","Bytes")=Total size of all global data in bytes (Datasize + KeySize)
Size("TotalNodeSize","MB")=Total size of all global data in MB (Datasize + KeySize)
Size("JournalOverHead","Bytes")=Estimate of size of journal overhead in bytes
Size("JournalOverHead","MB")=Estimate of size of journal overhead in MB
Size("TotalJournalSize","Bytes")=Estimate of total journal size in bytes
Size("TotalJournalSize","MB")=Estimate of total journal size in MB

Examples:

Find the counts of global ^DATA
s Status=##Class(%GlobalEdit).GetGlobalCountBySubscript("c:\iris\mgr\user\","DATA","",.Size)

Find the counts of global ^DATA("Jones")
s x=##Class(%GlobalEdit).GetGlobalCountBySubscript("c:\iris\mgr\user\","DATA(""Jones"")","",.Size)

Find the count of nodes between nodes ^DATA("Jones") up to but not including ^DATA("Smith","zzzzz")
s x=##Class(%GlobalEdit).GetGlobalCountBySubscript("c:\iris\mgr\user\","DATA(""Jones"")","DATA(""Smith"",""zzzzz"")",.Size)

Find the count of all the nodes after after node ^X(500)
s x=##Class(%GlobalEdit).GetGlobalCountBySubscript("c:\db1\","^X(500"_$c(1)_"*next)","^X(END)",.Size)

Find the count of all the nodes from the beginning of the global up to but not including ^X(500)
s x=##Class(%GlobalEdit).GetGlobalCountBySubscript("c:\db1\","^X(BEGIN)","^X(500)",.Size)

classmethod GetGlobalSize(Directory As %String, GlobalName As %String, ByRef Allocated As %Integer, ByRef Used As %Integer, fast As %Integer = 0) as %Status
Get size of this global
'Allocated' - total size, in MB, of blocks allocated for the global.
'Used' - total used data, in MB, for the global.
'fast' - 2 : returns stochastic estimates for both 'Allocated' and 'Used' (fastest option for large globals)
1 : only returns exact 'Allocated' value (avoids reads of data blocks)
0 : returns exact values for both 'Allocated' and 'Used'.
classmethod GetGlobalSizeBySubscript(Directory As %String, StartingNode As %String, EndingNode As %String = "", ByRef Size As %String = 0, Fast As %Boolean = 0)
Return the size of a global or range of nodes in a global.
This method will return the size of a global based on the number of database blocks the global resides in.

Parameters:
Directory - Directory where global is located.
StartNode - Starting node of global. Note that you can specify ^GLOBAL(BEGIN) to mean the start of the global. This would include ^GLOBAL itself. You can also specify ^GLOBAL("XXX"_$c(1)_"*next)" to mean start counting after global ^GLOBAL("XXX").
EndNode - End Node of global. The returned sizes do not include the EndNode. Note that you can specify ^GLOBAL(END) to mean through the end of the global. An EndNode value of null, or equal to the value of StartNode will return the size of StartNode and all children of StartNode.
Size - Maximum number of MB to count. If the size of the global exceeds this value, calculation stops, and an error is returned. If undefined or set to 0, then the entire range is counted. Be careful to reset this for multiple calls to the method.
Fast - If set and the global is large, this method will attempt a stochastic sample instead of taking an exact measurement. Recommended only for huge quantities of data. Excludes AverageNodeSize and AverageNodesPerPage measurements (sets them to 0).
Return Values:
The method will return a %Status value of success, or an error.
The array Size returns the amount of data in both blocks and MB, for each level of the global, as well as the size of big string data, and a total. If the global does not exist the sizes will all be set to 0. If any error occurs, sizes will not be set.
Size=Total size in MB of the global range
Size("Blocks","1")=# Blocks in level 1
Size("Blocks","2")=# Blocks in level 2
Size("Blocks","3")=# Blocks in level 3
Size("Blocks","BigStrings")=# Big String Blocks
Size("Blocks","Total")=Total # Blocks in global range
Size("MB","1")=# MB in level 1
Size("MB","2")=# MB in level 2
Size("MB","3")=# MB in level 3
Size("MB","BigStrings")=# Big String MB
Size("MB","Total")=Total # MB in global range
Size("AverageNodesPerPage")=Average nodes per page (Estimate)
AverageNodesPerPage is calculated as follows:
As each Bottom Pointer block is examined, 10 % of the data nodes pointed to by this pointer block are randomly selected and examined. The number of nodes is accumulated in each selected page and summed together, and the total size of data blocks examined is summed together. When we reach 20GB of data blocks examined, the loop continues, but we only select 2% of the data pages. After we process the last pointer block, The AverageNodesPerPage is calculated by dividing the size of the summed data pages by the number of summed nodes. Size("AverageNodeSize")=Average node size (Estimate)
AverageNodeSize is calculated by first estimating the total number of nodes in the global
TotalNodes = Size("AverageNodesPerPage") * (Size("Blocks","Total")-Size("Blocks","BigStrings"))
We then use the following:
AverageNodeSize=$fn(Size*(1024*1024)/TotalNodes,"",1)
Examples:

Find the size of global ^DATA
s Status=##Class(%GlobalEdit).GetGlobalSizeBySubscript("c:\132u1\mgr\user\","DATA","",.Size)

Find the size of data ^DATA("Jones")
s x=##Class(%GlobalEdit).GetGlobalSizeBySubscript("c:\132u1\mgr\user\","DATA(""Jones"")","",.Size)

Find the size of data between nodes ^DATA("Jones") up to but not including ^DATA("Smith","zzzzz")
s x=##Class(%GlobalEdit).GetGlobalSizeBySubscript("c:\132u1\mgr\user\","DATA(""Jones"")","DATA(""Smith"",""zzzzz"")",.Size)

Find the size of all the data after after node ^X(500)
s x=##Class(%GlobalEdit).GetGlobalSizeBySubscript("c:\db1\","^X(500"_$c(1)_"*next)","^X(END)",.Size)

Find the size of all the data from the beginning of the global up to but not including ^X(500)
s x=##Class(%GlobalEdit).GetGlobalSizeBySubscript("c:\db1\","^X(BEGIN)","^X(500)",.Size)

classmethod GrowthBlockPrompt(Prompt, Obj)
method GrowthBlockSet(Arg As %String) as %Status
classmethod IsKeepPrompt(Prompt, Obj)
method IsKeepSet(Arg As %Boolean) as %Status
classmethod KillRange(Directory As %String, StartingNode As %String, EndingNode As %String) as %Status
Kill a subscripted range of a single global in a single database.
This method will kill a range of globals node of a single global in a single database. The starting and ending global name must be the same. When a range is specified, the global is killed from the starting node up to but not including the ending node. The exception to this is if the starting and ending node is the same then that global is killed. The start and end nodes must not contain namespace specifications. Process private globals are not supported. Note that this method ignores all namespace specifications.
Parameters:
Directory - Location of global to kill.
StartingNode - First node of global range to kill. Note that you can specify ^GLOBAL(BEGIN) to mean the start of the global. This includes the global ^GLOBAL itself You can also specify ^GLOBAL("XXX"_$c(1)_"*next)" to mean start deleting after global ^GLOBAL("XXX").
EndingNode - Ending node of global range to kill, up to, but not including this node. Note that you can specify ^GLOBAL(END) to mean through the end of the global.

Return Values:
The method will return a %Status value of success, or an error.

Examples:
Kill nodes between ^X(1,5) and ^X(1,50), not including ^X(1,50)
s Status=##Class(%GlobalEdit).KillRange("c:\db1\","^X(1,5),"^X(1,50)")

Kill node ^X(500) and all subnodes
s Status=##Class(%GlobalEdit).KillRange("c:\db1\","^X(500),"^X(500)")

Kill everything after node ^X(500)
s Status=##Class(%GlobalEdit).KillRange("c:\db1\","^X(500"_$c(1)_"*next)","^X(END)")

Kill everything from the beginning of the node up to but not including ^X(500)
s Status=##Class(%GlobalEdit).KillRange("c:\db1\","^X(BEGIN)","^X(500)")

method NameSet(Arg As %String) as %Status
Set the Global name.
If prefaced by a "^" strip it off
classmethod Open(Name As %String, Directory As %String = {$zu(12, "")}, System As %String = "", concurrency As %Integer = -1, ByRef sc As %Status = $$$OK) as %ObjectHandle
Open an instance of a global.
classmethod PointerBlockPrompt(Prompt, Obj)
method PointerBlockSet(Arg As %String) as %Status

Indexes

index (IDKEY on ) [IdKey, Type = key];
Index methods: IDKEYCheck(), IDKEYDelete(), IDKEYExists(), IDKEYOpen(), IDKEYSQLCheckUnique(), IDKEYSQLExists(), IDKEYSQLFindPKeyByConstraint(), IDKEYSQLFindRowIDByConstraint()

Inherited Members

Inherited Methods

FeedbackOpens in a new tab