I have not tested in a collective but I am almost sure your problem is not related to High Availability. Please try the code snippet below to remove the snapshots. It worked for me so it should work for you also.
Dim sdkroot As New PISDK.PISDK() Dim myPIServer As Server = sdkroot.Servers.Item("SERVERNAME") Dim myPIPoint As PIPoint = myPIServer.PIPoints("TestTag") Dim snapshot As PIValue = myPIPoint.Data.Snapshot Console.WriteLine("Current snapshot value: " & snapshot.Value) Console.WriteLine("Current snapshot value: " & snapshot.TimeStamp.LocalDate.ToString()) myPIPoint.Data.RemoveValues(myPIPoint.Data.Snapshot.TimeStamp, "*", PISDK.DataRemovalConstants.drRemoveAll) Console.WriteLine("Snapshot removed!") snapshot = myPIPoint.Data.Snapshot Console.WriteLine("Current snapshot value: " & snapshot.Value) Console.WriteLine("Current snapshot value: " & snapshot.TimeStamp.LocalDate.ToString())
Let me know if you have any question,
This fails because you cannot delete from a collective through the buffer system. I'm not sure how this code is much different than mine except that my code connects to the specific node and not the collective. I am using the RemoveValues function with essentially the same parameters.
I've performed some testing in order to get a better understanding what kind of issue you might be facing. As Marcos did, I've tested with a single PI Server instead of a PI Collective but I doubt the issue you are facing originates from using a PI Collective.
The good news is that both code examples work. What I like with Marcos example that it shows how the snapshot becomes updated with the previous archive event in case the snapshot is deleted but let's go step by step.
The first thing that I did was enabling PI Buffer Subsystem using the ICU. Afterwards I've enabled PI SDK buffering through PISDKUtility.exe. I used PI SMT -> Point Builder on the client to create a new point with point source LAB and PI SMT -> Archive Editor to add some events. Next I tried both code examples to attempt deleting the snapshot event failed. The reason was identified by the following entry in the PI Server's log:
E 19-Jun-13 17:04:00 pisnapss:pisnapmgr
>> Postevent failed: [-11414] Buffered point does not accept new events
Point ID: 53, Connection ID: 58, User: Domain\Gregor, User ID: 11, mode: remove
Event time: 19-Jun-13 17:03:53, value: 356.9
I used pibufss -creg command on the client to see what applications had registered:
Client buffer registration dump. Total count: 2
app name, app PID, domain identity, buffer mode, target collective/server, no fanning target member
DelSnap.vshost.exe, 2856, Domain\Gregor, FanAndBuffer, PIServant,
SMTHost.exe, 532, Domain\Gregor, FanAndBuffer, PIServant,
As mentioned earlier, I had used PI SMT -> Archive Editor to create events and hence the point was locked against updates from a different source. To release the point lock, I used piartool -bfs on the PI Server node to find the registration ID and then piartool -bfs <ID> -reset to release the buffer lock.
Now I was able to delete from the snapshot. When switching between client applications (your and Marcos' code) I had to again release the buffer lock. I was expecting to run into an issue when attempting to delete the latest snapshot because this would mean there wouldn't be any archived event anymore existent for the particular point. I indeed was believing that this might have been the issue you were running into. However, deletion with Marcos code failed before the delete attempt because the DigitaState (Pt Created) isn't properly translated but was successful with your code.
I would be curious why it fails for you. Have you recognized any related messages in the clients / servers PI Message Log?
After testing various other ways I found that if buffering is turned off, and the pibufss is shut down, then I am able to delete the snapshot. I wanted to leave pi buffering enabled so that inserts and updates would buffer and because the buffer doesn't support deletes, I was going to try and handle that manually. Deleting data doesn't happen that often but we do need that capability in our application. The problem with using piartool to release the point lock is that this cannot be done from the application as it is not running on the PI server. Is there another way to release this lock? I am beginning to think the only way to do this is to implement my own buffer that updates both servers and shut the pibuffss service off.
I previously said, that I do not expect big differences if deleting through PI Buffer Subsystem. After reading your last post, I had some doubts and gave it a try. I created a PI Collective, took care the PI Buffer Subsystem configuration becomes changed accordingly. Based on your code snippet I inserted a break between establishing the connection to PI and the delete attempt. I also put a Try-Catch around the whole code to be able to properly capture exceptions. After the application ran to the breakpoint I checked with pibufss -creg on the client that my connection was "fanned and buffered". On the Primary and Secondary PI Server I verified with piartool -bfs that there was actually no point lock. I then continued from the breakpoint. The following error was caught by the Try-Catch block:
Write failed. Unbuffered write would desynchronize archive data. <collectivename>
This confirms that PI Buffer Subsystem will not allow any deletes through a buffered and fanned connection.
If you indeed need the ability to delete events from within your custom application, I suggest creating a parallel connection using the IPICollective Interface for this purpose. Be sure to treat each collective member with the delete operation. You can use pibufss -creg command to verify your (delete) connection is 'NotFanning'.
Even it turns out the point lock is not causing the issue here, you might be interested that tags become locked for the period (seconds) specified with excmax point attribute.
I am beginning to think the only way to do this is to implement my own buffer that updates both servers and shut the pibuffss service off.
Well there is a lot of positive to report about PI Buffer Subsystem too. Event become compressed on the interface node and are send 'marked' as compressed events to PI. This reduces the network traffic and - likely of more value - and ensures all Collective members become updated with equal events. If a buffer queue becomes corrupted, i.e. because of a power outage, PI tools can be used to recover data from the queue files.
Something isn't set up the same as mine then because I do not get the Write failed. "Unbuffered write would desynchronize archive data. <collectivename>" In my code I connect to each node individually throught the Collective.MemberOpen function and try to delete. When I do that I get "Failed to remove one or more requested events.  Success." If I didn't connect to them individually then yet I do get the "Unbuffered write would desynchronize archive data. <collectivename>." I was connecting to each node seperately hoping this would work because I figured this was bypassing the PIBufferss.
I have noticed the PI SMT behaves as my code does. I have buffering turned on on my computer and if I go to the archive editor, I can delete any value as long as it isn't the snapshot. PI SMT will only delete it on the node I am connected to though.
Make sure buffering is enabled
Open PI SQL Commander
Insert a value for a tag (Buffering works and pushes it to both servers)
Insert another value (Buffering works both servers show the value)
Open archive editor and delete value 1 (the non-snapshot value) and save (this works but only deletes on the node you selected)
Try to delete the most recent value and save (This doesn't work)
The purpose of this is I am making a manual entry application of lab data that I would like in PI. These samples are once every 4 hours and I don't want compression turned on. I would LOVE to use the pibufferss to do this but I need to have a way to delete. My code was almost working with pibuferss running except for the snapshot delete didn't work. I don't expect deleting very often but we have very error prone users and need to be able to delete occasionally.
We are going down the route disabling buffering and connecting to the nodes separately to Insert/Update/Delete.
The command line tools that ship with PI may not look pretty fancy and one or the other may not be used to using the command prompt but please be assured that these tools are very useful and sometimes as well a lot more powerful than any Windows Forms based tool.
Have you checked with pibufss -creg if your application is registered as 'FanAndBuffer' or as 'NotFanning'?