Class IOfflineStorage

Inheritance Relationships

Derived Type

Class Documentation

class Microsoft::Applications::Events::IOfflineStorage

Subclassed by Microsoft::Applications::Events::IOfflineStorageModule

Public Functions

IOfflineStorage() noexcept = default
virtual ~IOfflineStorage() noexcept = default
virtual void Initialize(IOfflineStorageObserver &observer) = 0

Initialize the offline storage

Prepare any external libraries, open files etc. Called from the internal worker thread as the initialization can take longer time. Any other methods can be called only after initializing. If the offline storage cannot be initialized, calling other methods later must be still possible, they should return some default/error values. The argument observer specifies an instance of IOfflineStorageObserver which will be used to notify the owner about side actions performed by the storage implementation (failures, dropping trimmed events etc.). The callback methods of observer can be invoked during execution of any of the other methods of this interface, so the observer object must stay alive until after the storage has been fully shut down.

Parameters

observer – Notification observer instance

virtual void Shutdown() = 0

Shut down the offline storage

Flush any outstanding operations, close the underlying files etc. No other methods can be called after shutdown. Called from the internal worker thread.

virtual void Flush() = 0

Save pending records to persistent storage

virtual bool StoreRecord(StorageRecord const &record) = 0

Store one telemetry event record

The offline storage might need to trim the oldest events before inserting the new one in order to maintain its configured size limit. Called from the internal worker thread.

Parameters

record – Record data to store

Returns

Whether the record was successfully stored

virtual size_t StoreRecords(StorageRecordVector &records) = 0

Store several telemetry event records

The offline storage might need to trim the oldest events before inserting the new one in order to maintain its configured size limit. Called from the internal worker thread.

Parameters

record – Record data to store

Returns

Number of records stored

virtual bool GetAndReserveRecords(std::function<bool(StorageRecord&&)> const &consumer, unsigned leaseTimeMs, EventLatency minLatency = EventLatency_Unspecified, unsigned maxCount = 0) = 0

Retrieve the best records to upload based on specified parameters

Retrieves stored records one by one, filtered and ordered based on the specified parameters. The priority is considered first: only events of the highest priority found, higher or equal to minPriority , are returned during one call to this method. The timestamp is considered next: events are returned in a decreasing timestamp order, i.e. from the oldest to newest. The specified maxCount is checked the last. The retrieval can be aborted after any record if the consumer returns false. Records which were accepted by the consumer are reserved for the specified amount of time leaseTimeMs and will not be returned again by this method until explicitly released or deleted or until their reservation period expires. Called from the internal worker thread.

Parameters
  • consumer – Callback functor processing the individual retrieved records

  • leaseTimeMs – Amount of time all acccepted records should be reserved for, in milliseconds

  • minPriority – Minimum priority of events to be retrieved

  • maxCount – Maximum number of events to retrieve

Returns

true if everything went well (even with no events really accepted by the consumer), false if an error occurred and the retrieval ended prematurely, records could not be reserved etc.

virtual bool IsLastReadFromMemory() = 0

return where the last read was memory or disk

virtual unsigned LastReadRecordCount() = 0

return last read count

virtual void DeleteAllRecords() = 0

Delete all records from storage

virtual void DeleteRecords(const std::map<std::string, std::string> &whereFilter) = 0

Bulk delete records using “where” clause.

Specify condition using key-value pairs in the map.

virtual void DeleteRecords(std::vector<StorageRecordId> const &ids, HttpHeaders headers, bool &fromMemory) = 0

Delete records with specified IDs

IDs of records that are no longer found in the storage are silently ignored. Called from the internal worker thread.

Parameters

ids – Identifiers of records to delete

virtual void ReleaseRecords(std::vector<StorageRecordId> const &ids, bool incrementRetryCount, HttpHeaders headers, bool &fromMemory) = 0

Release event records with specified IDs

IDs of events that are no longer found in the storage are silently ignored. If incrementRetryCount is set and the retry counter of some records reaches the maximum retry count, those events may be dropped as part of the releasing procedure. Persistent storage implementations of this interface drop these records. MemoryStorage does not. Called from the internal worker thread.

Parameters
  • ids – Identifiers of records to release

  • incrementRetryCount – Determines whether the retry counter should be incremented for the records

virtual bool DeleteSetting(std::string const &name) = 0

Delete value of an auxiliary persistent configuration value

If a setting with the specified name does not exist, success is returned.

Parameters

name – Name of the setting to retrieve

Returns

Status of operation

virtual bool StoreSetting(std::string const &name, std::string const &value) = 0

Set value of an auxiliary persistent configuration value

Set value to an empty string to delete any existing value. Called from the internal worker thread.

Parameters
  • name – Name of the setting to update

  • value – New setting value

Returns

virtual std::string GetSetting(std::string const &name) = 0

Get value of an auxiliary persistent configuration value

If a setting with the specified name does not exist, an empty string is returned. Called from the internal worker thread.

Parameters

name – Name of the setting to retrieve

Returns

Value of the requested setting or an empty string

virtual size_t GetSize() = 0

Get size of the DB

Get current Db size returned. Called from the internal worker thread.

Returns

Value of the requested DB size

virtual size_t GetRecordCount(EventLatency latency = EventLatency_Unspecified) const = 0

Get number of records of specific latency.

If latency is unspecified, then get the total number of records in storage.

Gets the total number of records. Primarily used on shutdown to evaluate if upload still has to be done for the remaining records.

Returns

Number of records

virtual std::vector<StorageRecord> GetRecords(bool shutdown, EventLatency minLatency = EventLatency_Unspecified, unsigned maxCount = 0) = 0

Get Vector of records from DB

If a setting with the specified name does not exist, an empty string is returned. Called from the internal worker thread.

Parameters
  • shutdown – if this is called at shutdown ot not

  • minPriority – lowest priority selected

  • maxCount – max count to be selected

Returns

Value of the requested setting or an empty string

virtual bool ResizeDb() = 0
inline virtual void ReleaseAllRecords()