VRS
A file format for sensor data.
Loading...
Searching...
No Matches
RecordManager.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <list>
20#include <memory>
21#include <mutex>
22
23#include "ForwardDefinitions.h"
24#include "Record.h"
25
26namespace vrs {
27
28using std::list;
29
30class DataLayout;
31
39 friend class Record;
40
41 public:
43 RecordManager(const RecordManager&) = delete;
44 void operator=(const RecordManager&) = delete;
46
55 Record*
56 createRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource& data);
57
69 double timestamp,
70 Record::Type type,
71 uint32_t formatVersion,
72 const DataSource& data,
73 std::unique_ptr<DirectWriteRecordData>&& directWriteData);
74
79 uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers = true);
80
82 void purgeCache();
83
88 void collectOldRecords(double maxAge, list<Record*>& outCollectedRecords);
89
93 return compression_;
94 }
95
100 compression_ = compression;
101 }
102
106 void setMaxCacheSize(size_t max) {
107 maxCacheSize_ = max;
108 }
109
113 size_t getCurrentCacheSize() const {
114 return cache_.size();
115 }
116
117 private:
118 static size_t getAcceptableOverCapacity(size_t capacity);
119 void recycle(Record* record);
120
121 std::mutex mutex_;
122 list<Record*> activeRecords_; // Records ready to be written
123 list<Record*> cache_; // Written/recycled records available for reuse
124
125 CompressionPreset compression_;
126 size_t maxCacheSize_;
127 uint64_t creationOrder_;
128};
129
130} // namespace vrs
A class referencing data to be captured in a record at creation.
Definition DataSource.h:151
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:79
Type
Definition Record.h:88
VRS internal class to manage the records of a specific Recordable after their creation.
Definition RecordManager.h:38
CompressionPreset getCompression() const
Definition RecordManager.h:92
void setCompression(CompressionPreset compression)
Definition RecordManager.h:99
uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers=true)
Definition RecordManager.cpp:127
void collectOldRecords(double maxAge, list< Record * > &outCollectedRecords)
Definition RecordManager.cpp:181
Record * createUncompressedRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource &data, std::unique_ptr< DirectWriteRecordData > &&directWriteData)
Definition RecordManager.cpp:116
Record * createRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource &data)
Definition RecordManager.cpp:55
size_t getCurrentCacheSize() const
Definition RecordManager.h:113
void setMaxCacheSize(size_t max)
Definition RecordManager.h:106
void purgeCache()
Release as much memory as possible, by deleting all the records in the cache.
Definition RecordManager.cpp:173
Definition AsyncDiskFileChunk.hpp:49
CompressionPreset
VRS Compression setting.
Definition Compressor.h:38