Triggers

2 views
Skip to first unread message

Joshua Barney

unread,
Jul 25, 2013, 1:59:50 PM7/25/13
to InterSy...@googlegroups.com
I have two triggers set on a file, for predelete and preclear. The trigger is supposed to copy the item being deleted, record the time, date, user, and program that is deleting the item. I have a lot of items that are not being copied into the trigger file or are being copied NULL. I am looking for some advice to troubleshoot this

Michael Cohen

unread,
Jul 25, 2013, 6:54:17 PM7/25/13
to InterSy...@googlegroups.com

please provide more info:

1. what version of Caché are you testing?  any recent changes to the system?

2. do the errors relate to delete via SQL or objects, or just from normal MV DELETE?

3. do the triggers work for some records/files, but not others?  any pattern

4. perhaps send copies of you trigger subroutines (I can give you my email if you don’t want to make them public)

--
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
---
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to InterSystems-...@googlegroups.com.
To post to this group, send email to InterSy...@googlegroups.com.
Visit this group at http://groups.google.com/group/InterSystems-MV.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Josh Barney

unread,
Jul 29, 2013, 9:12:09 AM7/29/13
to InterSy...@googlegroups.com

1. Cache for Windows (x86-64) 2009.1.3 (Build 704_0_10426) Tue Apr 12 2011 03:54:57 GMTDT

2. MV DELETE

3. the trigger is sporadic at best. sometimes it will copy everything correctly, sometimes nothing is written at all, other times the triggered item is created but there is nothing in it. From 5k+ records in a single day appr 1500 missing records, 1000 incorrect records

4.

     SUBROUTINE SUB.DELETE.TRANS.REVIEW(FV, EVENT, PRERC, FLAGS, ID, REC, USERRC)

      COM PACS,PGM,SCREEN(10),LEVEL,CTRL,COMNUM,VALUES

 

      EQU POSTOPEN TO 1

      EQU PREREAD TO 2

      EQU POSTREAD TO 3

      EQU PREDELETE TO 4

      EQU POSTDELETE TO 5

      EQU PRECLEAR TO 6    ;* CLEARFILE

      EQU POSTCLEAR TO 7

      EQU PREWRITE TO 8

      EQU POSTWRITE TO 9

      EQU PREINSERT TO 10

      EQU POSTINSERT TO 11

      EQU PREUPDATE TO 12

      EQU POSTUPDATE TO 13

 

      READ OLDREC FROM FV,ID ELSE OLDREC = ""

 

      IF UNASSIGNED(^TRANS.REVIEW.BACKUP) THEN

         EXECUTE "CREATE-FILE TRANS.REVIEW.BACKUP" CAPTURING MSGS

      END

 

      IF ASSIGNED(PGM) THEN

         EVENTDESC = PGM<LEVEL>

      END ELSE

         EVENTDESC = "UNKNOWN"

      END

      REC = OLDREC

      REC<21> = DATE()

      REC<22> = OCONV(TIME(),"MT")

      REC<23> = @USER

      REC<24> = EVENTDESC

 

      ^TRANS.REVIEW.BACKUP(ID) = REC

 

      RETURN

Edward Clark

unread,
Jul 29, 2013, 9:50:55 AM7/29/13
to InterSy...@googlegroups.com
On thing to consider maybe: A CLEAR-FILE fires the pre/post clear events for the file, but does not fire any events for individual items, so if you are using clear-file, there would be no item data to save.
Also, no delete triggers get fired at all if the item didn't originally exist. Could some of the deletes be on items that don't exist?
 
Is the trigger set strictly only for preclear and predelete? If there are other trigger events occuring, it would complicate things.
Do the triggers get set  at runtime? does the file that the trigger is on get deleted and recreated?
 
Is it possible that 2 processes might be deleting the items at the same time, or one deleting while another is writing? if one or the other doesn't take the right locks, the trigger could have odd results.


From: InterSy...@googlegroups.com [mailto:InterSy...@googlegroups.com] On Behalf Of Josh Barney
Sent: Monday, July 29, 2013 9:15 AM

Josh Barney

unread,
Jul 29, 2013, 9:52:57 AM7/29/13
to InterSy...@googlegroups.com

it is pre-delete only and the only trigger on the file. when we pulled the data backup to compare the triggered info v the backup info that is there the missing/incorrect record info came from

Edward Clark

unread,
Jul 29, 2013, 10:23:01 AM7/29/13
to InterSy...@googlegroups.com
looks like you pressed send too soon :) "record info came from"...?


From: InterSy...@googlegroups.com [mailto:InterSy...@googlegroups.com] On Behalf Of Josh Barney
Sent: Monday, July 29, 2013 9:54 AM

Josh Barney

unread,
Jul 29, 2013, 10:27:34 AM7/29/13
to InterSy...@googlegroups.com

3. the trigger is sporadic at best. sometimes it will copy everything correctly, sometimes nothing is written at all, other times the triggered item is created but there is nothing in it. From 5k+ records in a single day appr 1500 missing records, 1000 incorrect records

 

 

Michael Cohen

unread,
Jul 29, 2013, 10:31:26 AM7/29/13
to InterSy...@googlegroups.com

I am nervous about the CREATE-FILE in the trigger.

 

If 2 users do a DELETE at the same time and the file does not exist, the first will create the file’s VOC entry pointing to the expected global, but the second would see that the global was in use and so assign a different global to store the data.

 

For example, the second CREATE-FILE would do something like this (note attribute 2):

MV:;^junk=123

MV:CREATE-FILE junk

[421] DICT for file 'junk' created. Type = INODE

[418] Default data section for file 'junk' created. Type = INODE

[437] Added default record '@ID' to 'DICT junk'.

[417] CreateFile Completed.

MV:CT VOC junk

     junk

0001 F

0002 ^D.4

0003 ^DICT.junk

0004

0005

0006

0007

0008

0009

0010

MV:

 

Can you use a different approach to assure that TRANS.REVIEW.BACKUP always exists?  Or does it, so this does not matter?

 

Edward Clark

unread,
Jul 29, 2013, 10:38:31 AM7/29/13
to InterSy...@googlegroups.com
That may not be a problem in this situation. The trigger potentially creates the file, but always writes directly to a specific global instead of to the file. So if multiple creates were an issue, the file with the wrong global would *always* be empty instead of partially.
Of course it's dangerous in general. That's why I asked if these files were being created on the fly.


From: InterSy...@googlegroups.com [mailto:InterSy...@googlegroups.com] On Behalf Of Michael Cohen
Sent: Monday, July 29, 2013 10:32 AM

To: InterSy...@googlegroups.com
Subject: RE: [InterSystems-MV] Triggers
--

Michael Cohen

unread,
Jul 29, 2013, 11:11:18 AM7/29/13
to InterSy...@googlegroups.com

true, but if the last CREATE-FILE left the VOC with a bad file pointer (like mine), then normal MV READs would look at the wrong global

 

but, that does not sound like this problem since his reads get mixed results

Reply all
Reply to author
Forward
0 new messages