AF 2.6 Delete Snapshot Scenario

Discussion created by rdavin Employee on Nov 5, 2013
Latest reply on Nov 8, 2013 by ekuwana

I currently have an AFSDK 2.5 application to perform data maintenance for some of our controllers.  The app implements its own data fanning.  I want to investigate giving it better or simpler features offered in AF 2.6, especially regarding buffering.


While our end-users think of a controller as a hardware device in the field, I think of it as a collection of PI tags associated by their controller type and serial number.  E.g. All tags with name beginning with “3DTCW/12345:*”.  For this example, there are 150 individual tags.  Most are Float32.  Some are true strings.  Some are digital tags.  Some are Integers.  Some have data as frequently as 5-minutes, others have data once a year (a configuration tag for example).  We not use sub-second time stamps.


Our environment has many PI Servers.  Some are stand-alone.  Some are in an HA collective.  Consider an example where I want to delete a range of data for a controller, that is to say delete data in the same time range for all 150 associated tags.    This is not same as a recent thread “Using AF SDK for deleting values in HA”.  Rather I might have an HA with buffering.  I might have an HA without buffering.  Or I might have stand-alone PI Server.   I need one app that handles all of these possibilities.


The current 2.5 app that accommodate all this safely does the following:

  1. Loop through all member servers and call my Delete method.  (For context of this app, I consider a stand-alone PI Server to be a one-member system. )
  2. My Delete method performs this PER member server:
  3. Set a class-level Boolean named IsBuffered = false;
  4. Fetch all related tags.  
  5. PER tag, do the following:
  6. Fetch the tag’s snapshot.
  7. Set a bSnapshot flag if the snapshot falls within the time range.
  8. If bSnapshot is false, retrieve data for the entire range.
  9. If bSnapshot is true, retrieve data for the start of the time range with the adjusted end time being 1-second before the snapshot.
  10. Delete the retrieved data, i.e. tag.UpdateValues(arcvalues, AFUpdateOption.Remove).
  11. If bSnapshot is false, continue to next tag.
  12. If IsBuffered is true, log a message, and continue to next tag.
  13. Else bSnapshot is true and IsBuffered is false, so attempt to remove the snapshot.  This is wrapped in try block.  If it fails, set IsBuffered to true in the catch block.
  14. When all tags are processed, continue to next member server.

Yes, I know I could do a bulk call for the snapshot.  I originally had that.  But when running across remotely across a continent for many member servers, it was taking upwards of 10-minutes so that the bulk fetched snapshot could have been stale.  Fetching the snapshot per tag rather than in bulk call is not the problem.


The whole problem are all the checks and juggling of whether to have special handling around deleting the snapshot, and fetching everything in the time range except the snapshot.  I am thinking of what’s the best way to do this in 2.6?  With the default AFData.BufferOption set to BufferIfPossible, do I even have to do anything?   Do I have to loop over each member?  What if I am running against a PI Collective that has buffering turned off?  I imagine that I would still have to fan over the members.


Just from what little I have read today - and please someone from OSIsoft correct me - what I’m thinking is something along the lines:

  1. When the user clicks the delete button, I detect if the requested PI Server has buffering enabled around the same time I check to see if it’s a collective.  Something like PIServer.GetHealthStatus()?  Buffering is not running if its Health is among {NotRunning, Disabled, NotConfigured}.  Right?
  2. If a collective has healthy buffering, should I not fan out across its members and instead just process it once?
  3. If a collective has buffering turned off, I probably must still fan out across its members.
  4. In either case, for the per tag delete, I can stop jumping through hoops to have special handling if the snapshot falls within my time range.

Any guidance is appreciated.