17 #ifndef MEMORYLOGSTORAGE_HPP_
18 #define MEMORYLOGSTORAGE_HPP_
30 class IKaaClientContext;
65 std::size_t maxOccupiedSize,
66 float percentToDelete,
81 void shrinkToSize(std::size_t allowedVolume);
84 buckets_.emplace_back(++currentBucketId_);
87 bool checkBucketOverflow(
const LogRecord& record) {
88 const auto& currentBucket = buckets_.back();
89 return (currentBucket.occupiedSize_ + record.getSize() > maxBucketSize_) ||
90 (currentBucket.logs_.size() + 1 > maxBucketRecordCount_);
93 void internalAddLogRecord(LogRecord&& record);
96 enum class BucketState {
101 struct InternalBucket {
102 InternalBucket(std::int32_t bucketId)
103 : bucketId_(bucketId) {}
106 std::int32_t bucketId_ = 0;
107 std::size_t occupiedSize_ = 0;
108 std::list<LogRecord> logs_;
112 const std::size_t maxBucketSize_;
113 const std::size_t maxBucketRecordCount_;
115 std::int32_t currentBucketId_ = 0;
117 std::size_t occupiedSizeOfUnmarkedRecords_ = 0;
118 std::size_t unmarkedRecordCount_ = 0;
120 std::size_t totalOccupiedSize_ = 0;
121 std::size_t maxOccupiedSize_ = 0;
122 std::size_t shrinkedSize_ = 0;
124 std::list<InternalBucket> buckets_;
125 KAA_MUTEX_DECLARE(memoryLogStorageGuard_);
126 IKaaClientContext &context_;
virtual BucketInfo addLogRecord(LogRecord &&record)
Persists a log record.
MemoryLogStorage(IKaaClientContext &context, std::size_t bucketSize=LogStorageConstants::DEFAULT_MAX_BUCKET_SIZE, std::size_t bucketRecordCount=LogStorageConstants::DEFAULT_MAX_BUCKET_RECORD_COUNT)
Creates the size-unlimited log storage.
virtual ILogStorageStatus & getStatus()
Returns a log storage status.
The helper class which is used to transfer logs from LogStorage to LogCollector.
The default ILogStorage implementation.
virtual std::size_t getRecordsCount()
Returns the number of collected logs.
virtual void removeBucket(std::int32_t bucketId)
Tells a log storage to remove a log bucket.
static const std::size_t DEFAULT_MAX_BUCKET_RECORD_COUNT
static const std::size_t DEFAULT_MAX_BUCKET_SIZE
Describes a unique log bucket.
Interface of a log storage.
virtual std::size_t getConsumedVolume()
Returns amount of bytes collected logs are consumed.
virtual void rollbackBucket(std::int32_t bucketId)
Tells a log storage to consider a log bucket as unused, i.e. a log bucket will be accessible again vi...
virtual LogBucket getNextBucket()
Returns a new log bucket.
The public interface to represent the current log storage state.