AnsweredAssumed Answered

Can not remove values : [-11073] Target event for removal not found in record

Question asked by elia-acc on Apr 6, 2017
Latest reply on Jul 27, 2017 by Dan Fishman

Dears,

I'm busy analyzing the throughput I can achieve when backfilling values in PI Tags.
The tags are retrieved from the attribute of elements in an AF tree.
I loaded 1000 random values to 50 tags.
Once the backfilling is finished, I'm logging the time spent , then I remove all the values from the tags.

This works perfectly with 1000 values per tag and I am reaching an average of 110 000 values / sec.
I then re-executed the same test, but with 100000 values. The throughput reached was similar (138 000 values /sec)
Unfortunately, the cleaning failed for this second attempt.
The PIPoint.UpdateValues() return an AFErrors<AFValue>, for some points with 1 error in it :
[-11073] Target event for removal not found in record

I tried manually remove the value  (using  the archive editor of PI SMT), no error was , but the value reappears after save.

Below, you'll see the code used to remove the values.

Can you please tell me :
1. - Is there an easiest way to remove all the values from a PI Point Tag?
2.- What is the reason for this exception ?

 

[TestMethod]

        public void RemoveValues()

        {          

            AFElement[] elementsToLoad = _testElements;

           

            Parallel.ForEach(elementsToLoad, afElement =>

            {

                // Define chunks to avoid OutOfMemoryException while retrieving values to remove

                List<AFTimeRange> timeRanges = new List<AFTimeRange>();

                DateTime startTime = new DateTime(2017, 03, 01, 00, 00, 00, DateTimeKind.Utc);

                DateTime endTime = DateTime.MinValue;

                DateTime maxEndTime = DateTime.UtcNow;

                while (endTime < maxEndTime)

                {

                    endTime = new[] {startTime.AddDays(10), maxEndTime}.Min();

                    timeRanges.Add(new AFTimeRange(startTime.ToString("O"), endTime.ToString("O")));

                    startTime = endTime.AddTicks(1);

                }

 

                // Get reference to the PIPoint containing the values

                var piPoint = afElement.Attributes.Cast<AFAttribute>().First(att => att.Name == "MW").DataReference.PIPoint;

               

                foreach (var range in timeRanges)

                {                   

                    // Retrieve the values for the current chunk

                    AFValues values = piPoint.RecordedValues(range, AFBoundaryType.Inside, string.Empty, true, 0);

                   

                    if (values.Any()) // Invoking Update values with an empty collection throws an exception

                    {

                        var updateResult = piPoint.UpdateValues(values, AFUpdateOption.Remove);

                        if (updateResult?.HasErrors ?? false) //

                        {

                            Debug.WriteLine($"First error while removing values : {updateResult.Errors.First().Value}");

                        }

                    }

                }

            });

        }

Outcomes