3 Replies Latest reply on Sep 9, 2015 9:51 PM by bshang

    Add child Event Frame generates an error

    acote

      Hello PISquare geeks,

       

      I built an AFSDK app that generates thousand of Event Frames per day and that have reprocessing capability. Once in a while, the following error is trapped:

       

      Cannot add EventFrame 'EFName' with UniqueID '2d06ea22-e945-4bdb-0000-00000022c0e3' because there is another EventFrame with an identical UniqueID

       

      Here is one with the stack trace:

      2015/09/09 08:46:25|An error occured while executing command ChangeEventDescription. Details: System.InvalidOperationException: Cannot add EventFrame 'Slab ID 1' with UniqueID '2d06ea22-e945-4bdb-0000-00000022b6d5' because there is another EventFrame with an identical UniqueID.

         at OSIsoft.AF.PISystem.CheckServerError(dcServerError err, Boolean firstAttempt)

         at OSIsoft.AF.Support.AFSerialProxy.Call(String rpcName, ProxyDelegate codeBlock)

         at OSIsoft.AF.Support.AFSerialProxy.CheckInEventFrame(dcEventFrame[] changes, dcObjectIdentity[] deletedIdentities, Boolean& updatedUOM, Int64[]& securityIds)

         at OSIsoft.AF.EventFrame.AFEventFrame.RemoteCheckInEventFrame(AFDatabase database, dcEventFrame[] changes, dcObjectIdentity[] deletedIdentities)

         at OSIsoft.AF.AFDatabase.SaveEventFrames(Boolean doCheckIn, Boolean disableObjectListCheckIn, Int32 maxChangedItems, List`1 appliedList, List`1 changeList, List`1 deleteList)

         at OSIsoft.AF.AFDatabase.ProcessDatabaseApplyCheckInChanges(ProcessMode mode, AFCheckedOutMode checkedOutMode, IEnumerable`1 objList, List`1 appliedList, HashSet`1 elementsWithAutoCreatedAnalyses, Boolean& dbPagedRefreshRequired)

         at OSIsoft.AF.AFDatabase.ProcessDatabaseChanges(ProcessMode mode, AFCheckedOutMode checkedOutMode, IEnumerable`1 objList, List`1 appliedList, HashSet`1 elementsWithAutoCreatedAnalyses)

         at OSIsoft.AF.Support.AFProcessChangesList.ProcessList(ProcessMode mode)

         at OSIsoft.AF.Support.AFTransactable.CheckIn(Boolean disableObjectListCheckIn)

       

      Here is the snippet

       

      What am I doing wrong and how can I ensure that a new EF will have a truly unique ID?

       

      Thanks for your Help

       

      Alex @ ATS Process Automation Solutions

        • Re: Add child Event Frame generates an error
          bshang

          Could you try the recommendation by Justin in this thread (using database.CheckIn)? Multi-threading AF SDK calls to add AFElements resulting in error: Can not add Element because there is another Element …

           

          If the problem persists, what is the version of AF SDK? Is the application multi-threaded? What is the logic/code that determines whether a child EF is created?

            • Re: Add child Event Frame generates an error
              acote

              Hello Barry and thanks for your reply.

               

              I'm using AFSDK 2.7 and validating with both 2.6 and 2.7... The app is multi-threading.

               

              As shown in the snippet, the CheckIn() is an AFEventFrame method which do not have parameters like ObjectsCheckedOutThisThread within the Database CheckIn. The child EF is created in the parent within a single thread but after seeing the thread you mentioned, I find relevant to investigate if another thread modify (ex: change description + CheckIn) that same EF uSecs after it is created.

                • Re: Add child Event Frame generates an error
                  bshang

                  Thanks for the information. In general, writes to the same AF collection are not thread-safe, so the user code should handle concurrency, via locks for example. If you think multiple threads might be adding EFs to the same collection, you can try using a lock around the EventFrames.Add and CheckIn methods. If you will be checking in multiple elements, we recommend doing this in bulk, via AFDatabase.CheckIn() for example, rather than individual checkin calls. Using the database-level checkin method, you can also specify the AFCheckedOutMode to specify if you want to check in elements for the session, thread, or user.

                  1 of 1 people found this helpful