OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
File_Namespace::FileBuffer Class Reference

Represents/provides access to contiguous data stored in the file system. More...

#include <FileBuffer.h>

+ Inheritance diagram for File_Namespace::FileBuffer:
+ Collaboration diagram for File_Namespace::FileBuffer:

Public Member Functions

 FileBuffer (FileMgr *fm, const size_t pageSize, const ChunkKey &chunkKey, const size_t initialSize=0)
 Constructs a FileBuffer object. More...
 
 FileBuffer (FileMgr *fm, const size_t pageSize, const ChunkKey &chunkKey, const SQLTypeInfo sqlType, const size_t initialSize=0)
 
 FileBuffer (FileMgr *fm, const ChunkKey &chunkKey, const std::vector< HeaderInfo >::const_iterator &headerStartIt, const std::vector< HeaderInfo >::const_iterator &headerEndIt)
 
 ~FileBuffer () override
 Destructor. More...
 
Page addNewMultiPage (const int32_t epoch)
 
void reserve (const size_t numBytes) override
 
size_t freeMetadataPages ()
 
size_t freeChunkPages ()
 
size_t freePages ()
 
void freePagesBeforeEpoch (const int32_t targetEpoch)
 
void read (int8_t *const dst, const size_t numBytes=0, const size_t offset=0, const MemoryLevel dstMemoryLevel=CPU_LEVEL, const int32_t deviceId=-1) override
 
void write (int8_t *src, const size_t numBytes, const size_t offset=0, const MemoryLevel srcMemoryLevel=CPU_LEVEL, const int32_t deviceId=-1) override
 Writes the contents of source (src) into new versions of the affected logical pages. More...
 
void append (int8_t *src, const size_t numBytes, const MemoryLevel srcMemoryLevel=CPU_LEVEL, const int32_t deviceId=-1) override
 
void copyPage (Page &srcPage, Page &destPage, const size_t numBytes, const size_t offset=0)
 
Data_Namespace::MemoryLevel getType () const override
 
int8_t * getMemoryPtr () override
 Not implemented for FileMgr – throws a runtime_error. More...
 
size_t pageCount () const override
 Returns the number of pages in the FileBuffer. More...
 
bool hasDataPages () const
 
size_t pageSize () const override
 Returns the size in bytes of each page in the FileBuffer. More...
 
virtual size_t pageDataSize () const
 Returns the size in bytes of the data portion of each page in the FileBuffer. More...
 
virtual size_t reservedHeaderSize () const
 
virtual std::vector< MultiPagegetMultiPage () const
 Returns vector of MultiPages in the FileBuffer. More...
 
MultiPage getMetadataPage () const
 
size_t reservedSize () const override
 Returns the total number of bytes allocated for the FileBuffer. More...
 
size_t numMetadataPages () const
 Returns the total number of used bytes in the FileBuffer. More...
 
bool isMissingPages () const
 
size_t numChunkPages () const
 
std::string dump () const
 
void freePage (const Page &page)
 
- Public Member Functions inherited from Data_Namespace::AbstractBuffer
 AbstractBuffer (const int device_id)
 
 AbstractBuffer (const int device_id, const SQLTypeInfo sql_type)
 
virtual ~AbstractBuffer ()
 
virtual void read (int8_t *const dst, const size_t num_bytes, const size_t offset=0, const MemoryLevel dst_buffer_type=CPU_LEVEL, const int dst_device_id=-1)=0
 
virtual void write (int8_t *src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1)=0
 
virtual void append (int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1)=0
 
virtual void setMemoryPtr (int8_t *new_ptr)
 
virtual int pin ()
 
virtual int unPin ()
 
virtual int getPinCount ()
 
size_t size () const
 
int getDeviceId () const
 
bool isDirty () const
 
bool isAppended () const
 
bool isUpdated () const
 
bool hasEncoder () const
 
SQLTypeInfo getSqlType () const
 
void setSqlType (const SQLTypeInfo &sql_type)
 
EncodergetEncoder () const
 
void setDirty ()
 
void setUpdated ()
 
void setAppended ()
 
void setSize (const size_t size)
 
void clearDirtyBits ()
 
void initEncoder (const SQLTypeInfo &tmp_sql_type)
 
void syncEncoder (const AbstractBuffer *src_buffer)
 
void copyTo (AbstractBuffer *destination_buffer, const size_t num_bytes=0)
 
void resetToEmpty ()
 

Static Public Member Functions

static size_t getMinPageSize ()
 

Static Public Attributes

static constexpr size_t kHeaderBufferOffset {32}
 

Private Member Functions

void writeHeader (Page &page, const int32_t pageId, const int32_t epoch, const bool writeMetadata=false)
 Write header writes header at top of page in format. More...
 
void writeMetadata (const int32_t epoch)
 
void readMetadata (const Page &page)
 
void setBufferHeaderSize ()
 
void freePage (const Page &page, const bool isRolloff)
 
void freePagesBeforeEpochForMultiPage (MultiPage &multiPage, const int32_t targetEpoch, const int32_t currentEpoch)
 
void initMetadataAndPageDataSize ()
 
int32_t getFileMgrEpoch ()
 

Private Attributes

FileMgrfm_
 
const size_t metadataPageSize_
 
MultiPage metadataPages_
 
std::vector< MultiPagemultiPages_
 
size_t pageSize_
 
size_t pageDataSize_
 
size_t reservedHeaderSize_
 
ChunkKey chunkKey_
 

Friends

class FileMgr
 
class CachingFileMgr
 

Additional Inherited Members

- Protected Attributes inherited from Data_Namespace::AbstractBuffer
std::unique_ptr< Encoderencoder_
 
SQLTypeInfo sql_type_
 
size_t size_
 
int device_id_
 

Detailed Description

Represents/provides access to contiguous data stored in the file system.

The FileBuffer consists of logical pages, which can map to any identically-sized page in any file of the underlying file system. A page's metadata (file and page number) are stored in MultiPage objects, and each MultiPage includes page metadata for multiple versions of the same page.

Note that a "Chunk" is brought into a FileBuffer by the FileMgr.

Note(s): Forbid Copying Idiom 4.1

Definition at line 57 of file FileBuffer.h.

Constructor & Destructor Documentation

File_Namespace::FileBuffer::FileBuffer ( FileMgr fm,
const size_t  pageSize,
const ChunkKey chunkKey,
const size_t  initialSize = 0 
)

Constructs a FileBuffer object.

Definition at line 37 of file FileBuffer.cpp.

References CHECK, CHECK_GT, fm_, pageDataSize_, pageSize_, reservedHeaderSize_, and setBufferHeaderSize().

41  : AbstractBuffer(fm->getDeviceId())
42  , fm_(fm)
46  , chunkKey_(chunkKey) {
47  // Create a new FileBuffer
48  CHECK(fm_);
52  //@todo reintroduce initialSize - need to develop easy way of
53  // differentiating these pre-allocated pages from "written-to" pages
54  /*
55  if (initalSize > 0) {
56  // should expand to initialSize bytes
57  size_t initialNumPages = (initalSize + pageSize_ -1) / pageSize_;
58  int32_t epoch = fm_->epoch();
59  for (size_t pageNum = 0; pageNum < initialNumPages; ++pageNum) {
60  Page page = addNewMultiPage(epoch);
61  writeHeader(page,pageNum,epoch);
62  }
63  }
64  */
65 }
const size_t metadataPageSize_
Definition: FileBuffer.h:198
#define CHECK_GT(x, y)
Definition: Logger.h:305
AbstractBuffer(const int device_id)
size_t pageSize() const override
Returns the size in bytes of each page in the FileBuffer.
Definition: FileBuffer.h:137
#define CHECK(condition)
Definition: Logger.h:291
size_t getMetadataPageSize() const
Definition: FileMgr.h:369

+ Here is the call graph for this function:

File_Namespace::FileBuffer::FileBuffer ( FileMgr fm,
const size_t  pageSize,
const ChunkKey chunkKey,
const SQLTypeInfo  sqlType,
const size_t  initialSize = 0 
)

Definition at line 67 of file FileBuffer.cpp.

References CHECK, fm_, pageDataSize_, pageSize_, reservedHeaderSize_, and setBufferHeaderSize().

72  : AbstractBuffer(fm->getDeviceId(), sqlType)
73  , fm_(fm)
74  , metadataPageSize_(fm->getMetadataPageSize())
77  , chunkKey_(chunkKey) {
78  CHECK(fm_);
81 }
const size_t metadataPageSize_
Definition: FileBuffer.h:198
AbstractBuffer(const int device_id)
size_t pageSize() const override
Returns the size in bytes of each page in the FileBuffer.
Definition: FileBuffer.h:137
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

File_Namespace::FileBuffer::FileBuffer ( FileMgr fm,
const ChunkKey chunkKey,
const std::vector< HeaderInfo >::const_iterator &  headerStartIt,
const std::vector< HeaderInfo >::const_iterator &  headerEndIt 
)

Definition at line 83 of file FileBuffer.cpp.

References CHECK, File_Namespace::FileMgr::failOnReadError(), logger::FATAL, fm_, initMetadataAndPageDataSize(), LOG, metadataPages_, multiPages_, pageSize_, File_Namespace::MultiPage::push(), setBufferHeaderSize(), and show_chunk().

87  : AbstractBuffer(fm->getDeviceId())
88  , fm_(fm)
89  , metadataPageSize_(fm->getMetadataPageSize())
91  , pageSize_(0)
92  , chunkKey_(chunkKey) {
93  // We are being assigned an existing FileBuffer on disk
94 
95  CHECK(fm_);
97  int32_t lastPageId = -1;
98  int32_t curPageId = 0;
99  for (auto vecIt = headerStartIt; vecIt != headerEndIt; ++vecIt) {
100  curPageId = vecIt->pageId;
101 
102  // We only want to read last metadata page
103  if (curPageId == -1) { // stats page
104  metadataPages_.push(vecIt->page, vecIt->versionEpoch);
105  } else {
106  if (curPageId != lastPageId) {
107  // protect from bad data on disk, and give diagnostics
108  if (fm->failOnReadError()) {
109  if (curPageId != lastPageId + 1) {
110  LOG(FATAL) << "Failure reading DB file " << show_chunk(chunkKey)
111  << " Current page " << curPageId << " last page " << lastPageId
112  << " epoch " << vecIt->versionEpoch;
113  }
114  }
115  if (lastPageId == -1) { // If we are on first real page
117  }
118  MultiPage multiPage(pageSize_);
119  multiPages_.push_back(multiPage);
120  lastPageId = curPageId;
121  }
122  multiPages_.back().push(vecIt->page, vecIt->versionEpoch);
123  }
124  }
125  if (curPageId == -1) { // meaning there was only a metadata page
127  }
128 }
#define LOG(tag)
Definition: Logger.h:285
const size_t metadataPageSize_
Definition: FileBuffer.h:198
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
std::string show_chunk(const ChunkKey &key)
Definition: types.h:98
AbstractBuffer(const int device_id)
void push(const Page &page, const int epoch)
Pushes a new page with epoch value.
Definition: Page.h:102
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

File_Namespace::FileBuffer::~FileBuffer ( )
override

Destructor.

Definition at line 130 of file FileBuffer.cpp.

130  {
131  // need to free pages
132  // NOP
133 }

Member Function Documentation

Page File_Namespace::FileBuffer::addNewMultiPage ( const int32_t  epoch)

Definition at line 419 of file FileBuffer.cpp.

References fm_, multiPages_, pageSize_, File_Namespace::MultiPage::push(), and File_Namespace::FileMgr::requestFreePage().

Referenced by append(), reserve(), and write().

419  {
420  Page page = fm_->requestFreePage(pageSize_, false);
421  MultiPage multiPage(pageSize_);
422  multiPage.push(page, epoch);
423  multiPages_.emplace_back(multiPage);
424  return page;
425 }
virtual Page requestFreePage(size_t pagesize, const bool isMetadata)
Definition: FileMgr.cpp:877
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::append ( int8_t *  src,
const size_t  numBytes,
const MemoryLevel  srcMemoryLevel = CPU_LEVEL,
const int32_t  deviceId = -1 
)
override

Definition at line 503 of file FileBuffer.cpp.

References addNewMultiPage(), CHECK, File_Namespace::Page::fileId, fm_, File_Namespace::FileMgr::getFileInfoForFileId(), getFileMgrEpoch(), multiPages_, pageDataSize_, File_Namespace::Page::pageNum, pageSize_, reservedHeaderSize_, Data_Namespace::AbstractBuffer::setAppended(), Data_Namespace::AbstractBuffer::size_, File_Namespace::FileInfo::write(), and writeHeader().

506  {
507  setAppended();
508 
509  size_t startPage = size_ / pageDataSize_;
510  size_t startPageOffset = size_ % pageDataSize_;
511  size_t numPagesToWrite =
512  (numBytes + startPageOffset + pageDataSize_ - 1) / pageDataSize_;
513  size_t bytesLeft = numBytes;
514  int8_t* curPtr = src; // a pointer to the current location in dst being written to
515  size_t initialNumPages = multiPages_.size();
516  size_ = size_ + numBytes;
517  auto epoch = getFileMgrEpoch();
518  for (size_t pageNum = startPage; pageNum < startPage + numPagesToWrite; ++pageNum) {
519  Page page;
520  if (pageNum >= initialNumPages) {
521  page = addNewMultiPage(epoch);
522  writeHeader(page, pageNum, epoch);
523  } else {
524  // we already have a new page at current
525  // epoch for this page - just grab this page
526  page = multiPages_[pageNum].current().page;
527  }
528  CHECK(page.fileId >= 0); // make sure page was initialized
529  FileInfo* fileInfo = fm_->getFileInfoForFileId(page.fileId);
530  size_t bytesWritten;
531  if (pageNum == startPage) {
532  bytesWritten = fileInfo->write(
533  page.pageNum * pageSize_ + startPageOffset + reservedHeaderSize_,
534  min(pageDataSize_ - startPageOffset, bytesLeft),
535  curPtr);
536  } else {
537  bytesWritten = fileInfo->write(page.pageNum * pageSize_ + reservedHeaderSize_,
538  min(pageDataSize_, bytesLeft),
539  curPtr);
540  }
541  curPtr += bytesWritten;
542  bytesLeft -= bytesWritten;
543  }
544  CHECK(bytesLeft == 0);
545 }
size_t write(const size_t offset, const size_t size, const int8_t *buf)
Definition: FileInfo.cpp:64
Page addNewMultiPage(const int32_t epoch)
Definition: FileBuffer.cpp:419
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
void writeHeader(Page &page, const int32_t pageId, const int32_t epoch, const bool writeMetadata=false)
Write header writes header at top of page in format.
Definition: FileBuffer.cpp:427
#define CHECK(condition)
Definition: Logger.h:291
FileInfo * getFileInfoForFileId(const int32_t fileId) const
Definition: FileMgr.h:229

+ Here is the call graph for this function:

void File_Namespace::FileBuffer::copyPage ( Page srcPage,
Page destPage,
const size_t  numBytes,
const size_t  offset = 0 
)

Definition at line 401 of file FileBuffer.cpp.

References CHECK, CHECK_LE, checked_malloc(), File_Namespace::Page::fileId, fm_, File_Namespace::FileMgr::getFileInfoForFileId(), pageDataSize_, File_Namespace::Page::pageNum, pageSize_, File_Namespace::FileInfo::read(), reservedHeaderSize_, and File_Namespace::FileInfo::write().

Referenced by write().

404  {
405  CHECK_LE(offset + numBytes, pageDataSize_);
406  FileInfo* srcFileInfo = fm_->getFileInfoForFileId(srcPage.fileId);
407  FileInfo* destFileInfo = fm_->getFileInfoForFileId(destPage.fileId);
408 
409  int8_t* buffer = reinterpret_cast<int8_t*>(checked_malloc(numBytes));
410  ScopeGuard guard = [&buffer] { free(buffer); };
411  size_t bytesRead = srcFileInfo->read(
412  srcPage.pageNum * pageSize_ + offset + reservedHeaderSize_, numBytes, buffer);
413  CHECK(bytesRead == numBytes);
414  size_t bytesWritten = destFileInfo->write(
415  destPage.pageNum * pageSize_ + offset + reservedHeaderSize_, numBytes, buffer);
416  CHECK(bytesWritten == numBytes);
417 }
void * checked_malloc(const size_t size)
Definition: checked_alloc.h:45
#define CHECK_LE(x, y)
Definition: Logger.h:304
#define CHECK(condition)
Definition: Logger.h:291
FileInfo * getFileInfoForFileId(const int32_t fileId) const
Definition: FileMgr.h:229

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string File_Namespace::FileBuffer::dump ( ) const

Definition at line 642 of file FileBuffer.cpp.

References chunkKey_, Data_Namespace::AbstractBuffer::hasEncoder(), show_chunk(), and Data_Namespace::AbstractBuffer::size_.

642  {
643  std::stringstream ss;
644  ss << "chunk_key = " << show_chunk(chunkKey_) << "\n";
645  ss << "has_encoder = " << (hasEncoder() ? "true\n" : "false\n");
646  ss << "size_ = " << size_ << "\n";
647  return ss.str();
648 }
std::string show_chunk(const ChunkKey &key)
Definition: types.h:98

+ Here is the call graph for this function:

size_t File_Namespace::FileBuffer::freeChunkPages ( )

Definition at line 189 of file FileBuffer.cpp.

References freePage(), and multiPages_.

Referenced by freePages(), and freePagesBeforeEpoch().

189  {
190  size_t num_pages_freed = multiPages_.size();
191  for (auto multiPageIt = multiPages_.begin(); multiPageIt != multiPages_.end();
192  ++multiPageIt) {
193  for (auto pageIt = multiPageIt->pageVersions.begin();
194  pageIt != multiPageIt->pageVersions.end();
195  ++pageIt) {
196  freePage(pageIt->page, false /* isRolloff */);
197  }
198  }
199  multiPages_.clear();
200  return num_pages_freed;
201 }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
void freePage(const Page &page)
Definition: FileBuffer.cpp:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t File_Namespace::FileBuffer::freeMetadataPages ( )

Definition at line 176 of file FileBuffer.cpp.

References freePage(), metadataPages_, File_Namespace::MultiPage::pageVersions, and File_Namespace::MultiPage::pop().

Referenced by freePages().

176  {
177  size_t num_pages_freed = metadataPages_.pageVersions.size();
178  for (auto metaPageIt = metadataPages_.pageVersions.begin();
179  metaPageIt != metadataPages_.pageVersions.end();
180  ++metaPageIt) {
181  freePage(metaPageIt->page, false /* isRolloff */);
182  }
183  while (metadataPages_.pageVersions.size() > 0) {
185  }
186  return num_pages_freed;
187 }
void pop()
Purges the oldest Page.
Definition: Page.h:110
std::deque< EpochedPage > pageVersions
Definition: Page.h:81
void freePage(const Page &page)
Definition: FileBuffer.cpp:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::freePage ( const Page page)

Definition at line 166 of file FileBuffer.cpp.

Referenced by freeChunkPages(), freeMetadataPages(), and freePagesBeforeEpochForMultiPage().

166  {
167  freePage(page, false);
168 }
void freePage(const Page &page)
Definition: FileBuffer.cpp:166

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::freePage ( const Page page,
const bool  isRolloff 
)
private

Definition at line 170 of file FileBuffer.cpp.

References CHECK, File_Namespace::Page::fileId, fm_, File_Namespace::FileInfo::freePage(), File_Namespace::FileMgr::getFileInfoForFileId(), getFileMgrEpoch(), and File_Namespace::Page::pageNum.

170  {
171  FileInfo* fileInfo = fm_->getFileInfoForFileId(page.fileId);
172  CHECK(fileInfo);
173  fileInfo->freePage(page.pageNum, isRolloff, getFileMgrEpoch());
174 }
#define CHECK(condition)
Definition: Logger.h:291
FileInfo * getFileInfoForFileId(const int32_t fileId) const
Definition: FileMgr.h:229

+ Here is the call graph for this function:

size_t File_Namespace::FileBuffer::freePages ( )

Definition at line 203 of file FileBuffer.cpp.

References freeChunkPages(), and freeMetadataPages().

203  {
204  return freeMetadataPages() + freeChunkPages();
205 }

+ Here is the call graph for this function:

void File_Namespace::FileBuffer::freePagesBeforeEpoch ( const int32_t  targetEpoch)

Definition at line 217 of file FileBuffer.cpp.

References CHECK_LE, chunkKey_, fm_, freeChunkPages(), freePagesBeforeEpochForMultiPage(), getFileMgrEpoch(), metadataPages_, multiPages_, pageSize_, File_Namespace::MultiPage::pageVersions, and Data_Namespace::AbstractBuffer::size_.

217  {
218  // This method is only safe to be called within a checkpoint, after the sync and epoch
219  // increment where a failure at any point32_t in the process would lead to a safe
220  // rollback
221  auto currentEpoch = getFileMgrEpoch();
222  CHECK_LE(targetEpoch, currentEpoch);
223  freePagesBeforeEpochForMultiPage(metadataPages_, targetEpoch, currentEpoch);
224  for (auto& multiPage : multiPages_) {
225  freePagesBeforeEpochForMultiPage(multiPage, targetEpoch, currentEpoch);
226  }
227 
228  // Check if all buffer pages can be freed
229  if (size_ == 0) {
230  size_t max_historical_buffer_size{0};
231  for (auto& epoch_page : metadataPages_.pageVersions) {
232  // Create buffer that is used to get the buffer size at the epoch version
233  FileBuffer buffer{fm_, pageSize_, chunkKey_};
234  buffer.readMetadata(epoch_page.page);
235  max_historical_buffer_size = std::max(max_historical_buffer_size, buffer.size());
236  }
237 
238  // Free all chunk pages, if none of the old chunk versions has any data
239  if (max_historical_buffer_size == 0) {
240  freeChunkPages();
241  }
242  }
243 }
void freePagesBeforeEpochForMultiPage(MultiPage &multiPage, const int32_t targetEpoch, const int32_t currentEpoch)
Definition: FileBuffer.cpp:207
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
std::deque< EpochedPage > pageVersions
Definition: Page.h:81
#define CHECK_LE(x, y)
Definition: Logger.h:304
FileBuffer(FileMgr *fm, const size_t pageSize, const ChunkKey &chunkKey, const size_t initialSize=0)
Constructs a FileBuffer object.
Definition: FileBuffer.cpp:37

+ Here is the call graph for this function:

void File_Namespace::FileBuffer::freePagesBeforeEpochForMultiPage ( MultiPage multiPage,
const int32_t  targetEpoch,
const int32_t  currentEpoch 
)
private

Definition at line 207 of file FileBuffer.cpp.

References freePage(), and File_Namespace::MultiPage::freePagesBeforeEpoch().

Referenced by freePagesBeforeEpoch().

209  {
210  std::vector<EpochedPage> epochedPagesToFree =
211  multiPage.freePagesBeforeEpoch(targetEpoch, currentEpoch);
212  for (const auto& epochedPageToFree : epochedPagesToFree) {
213  freePage(epochedPageToFree.page, true /* isRolloff */);
214  }
215 }
void freePage(const Page &page)
Definition: FileBuffer.cpp:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32_t File_Namespace::FileBuffer::getFileMgrEpoch ( )
private

Definition at line 637 of file FileBuffer.cpp.

References chunkKey_, File_Namespace::FileMgr::epoch(), fm_, and get_table_prefix().

Referenced by append(), freePage(), freePagesBeforeEpoch(), reserve(), and write().

637  {
638  auto [db_id, tb_id] = get_table_prefix(chunkKey_);
639  return fm_->epoch(db_id, tb_id);
640 }
virtual int32_t epoch(int32_t db_id, int32_t tb_id) const
Returns current value of epoch - should be one greater than recorded at last checkpoint. Because FileMgr only contains buffers from one table we can just return the FileMgr&#39;s epoch instead of finding a table-specific epoch.
Definition: FileMgr.h:281
std::pair< int, int > get_table_prefix(const ChunkKey &key)
Definition: types.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t* File_Namespace::FileBuffer::getMemoryPtr ( )
inlineoverridevirtual

Not implemented for FileMgr – throws a runtime_error.

Implements Data_Namespace::AbstractBuffer.

Definition at line 124 of file FileBuffer.h.

References logger::FATAL, and LOG.

124  {
125  LOG(FATAL) << "Operation not supported.";
126  return nullptr; // satisfy return-type warning
127  }
#define LOG(tag)
Definition: Logger.h:285
MultiPage File_Namespace::FileBuffer::getMetadataPage ( ) const
inline

Definition at line 148 of file FileBuffer.h.

148 { return metadataPages_; }
size_t File_Namespace::FileBuffer::getMinPageSize ( )
static

Definition at line 161 of file FileBuffer.cpp.

References File_Namespace::anonymous_namespace{FileBuffer.cpp}::calculate_buffer_header_size().

Referenced by Parser::anonymous_namespace{ParserNode.cpp}::get_page_size_def().

161  {
162  constexpr size_t max_chunk_size{5};
163  return calculate_buffer_header_size(max_chunk_size) + 1;
164 }
size_t calculate_buffer_header_size(size_t chunk_size)
Definition: FileBuffer.cpp:146

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual std::vector<MultiPage> File_Namespace::FileBuffer::getMultiPage ( ) const
inlinevirtual

Returns vector of MultiPages in the FileBuffer.

Definition at line 147 of file FileBuffer.h.

Referenced by read().

147 { return multiPages_; }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200

+ Here is the caller graph for this function:

Data_Namespace::MemoryLevel File_Namespace::FileBuffer::getType ( ) const
inlineoverridevirtual

Implements Data_Namespace::AbstractBuffer.

Definition at line 121 of file FileBuffer.h.

References Data_Namespace::DISK_LEVEL.

bool File_Namespace::FileBuffer::hasDataPages ( ) const
inline

Returns whether or not a buffer has data pages. It is possible for a buffer to represent metadata (have a size and encode) but not contain actual data.

Definition at line 134 of file FileBuffer.h.

134 { return pageCount() > 0; }
size_t pageCount() const override
Returns the number of pages in the FileBuffer.
Definition: FileBuffer.h:130
void File_Namespace::FileBuffer::initMetadataAndPageDataSize ( )
private

Definition at line 650 of file FileBuffer.cpp.

References CHECK, File_Namespace::MultiPage::current(), File_Namespace::Page::fileId, metadataPages_, File_Namespace::EpochedPage::page, pageDataSize_, pageSize_, readMetadata(), and reservedHeaderSize_.

Referenced by FileBuffer().

650  {
651  CHECK(metadataPages_.current().page.fileId != -1); // was initialized
654 }
int32_t fileId
Definition: Page.h:47
#define CHECK(condition)
Definition: Logger.h:291
void readMetadata(const Page &page)
Definition: FileBuffer.cpp:446
EpochedPage current() const
Returns a reference to the most recent version of the page.
Definition: Page.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool File_Namespace::FileBuffer::isMissingPages ( ) const

Definition at line 656 of file FileBuffer.cpp.

References multiPages_, pageDataSize_, and Data_Namespace::AbstractBuffer::size().

656  {
657  // Detect the case where a page is missing by comparing the amount of pages read
658  // with the metadata size.
659  return ((size() + pageDataSize_ - 1) / pageDataSize_ != multiPages_.size());
660 }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200

+ Here is the call graph for this function:

size_t File_Namespace::FileBuffer::numChunkPages ( ) const

Definition at line 662 of file FileBuffer.cpp.

References multiPages_.

662  {
663  size_t total_size = 0;
664  for (const auto& multi_page : multiPages_) {
665  total_size += multi_page.pageVersions.size();
666  }
667  return total_size;
668 }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
size_t File_Namespace::FileBuffer::numMetadataPages ( ) const
inline

Returns the total number of used bytes in the FileBuffer.

Definition at line 156 of file FileBuffer.h.

156 { return metadataPages_.pageVersions.size(); };
std::deque< EpochedPage > pageVersions
Definition: Page.h:81
size_t File_Namespace::FileBuffer::pageCount ( ) const
inlineoverridevirtual

Returns the number of pages in the FileBuffer.

Implements Data_Namespace::AbstractBuffer.

Definition at line 130 of file FileBuffer.h.

130 { return multiPages_.size(); }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
virtual size_t File_Namespace::FileBuffer::pageDataSize ( ) const
inlinevirtual

Returns the size in bytes of the data portion of each page in the FileBuffer.

Definition at line 140 of file FileBuffer.h.

Referenced by File_Namespace::readForThread().

140 { return pageDataSize_; }

+ Here is the caller graph for this function:

size_t File_Namespace::FileBuffer::pageSize ( ) const
inlineoverridevirtual

Returns the size in bytes of each page in the FileBuffer.

Implements Data_Namespace::AbstractBuffer.

Definition at line 137 of file FileBuffer.h.

Referenced by File_Namespace::readForThread(), and writeHeader().

137 { return pageSize_; }

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::read ( int8_t *const  dst,
const size_t  numBytes = 0,
const size_t  offset = 0,
const MemoryLevel  dstMemoryLevel = CPU_LEVEL,
const int32_t  deviceId = -1 
)
override

Definition at line 297 of file FileBuffer.cpp.

References threading_serial::async(), CHECK, Data_Namespace::CPU_LEVEL, logger::FATAL, fm_, getMultiPage(), File_Namespace::FileMgr::getNumReaderThreads(), LOG, File_Namespace::readThreadDS::multiPages, multiPages_, pageDataSize_, File_Namespace::readForThread(), File_Namespace::readThreadDS::t_bytesLeft, File_Namespace::readThreadDS::t_curPtr, File_Namespace::readThreadDS::t_endPage, File_Namespace::readThreadDS::t_fm, File_Namespace::readThreadDS::t_isFirstPage, File_Namespace::readThreadDS::t_startPage, and File_Namespace::readThreadDS::t_startPageOffset.

301  {
302  if (dstBufferType != CPU_LEVEL) {
303  LOG(FATAL) << "Unsupported Buffer type";
304  }
305 
306  // variable declarations
307  size_t startPage = offset / pageDataSize_;
308  size_t startPageOffset = offset % pageDataSize_;
309  size_t numPagesToRead =
310  (numBytes + startPageOffset + pageDataSize_ - 1) / pageDataSize_;
311  /*
312  if (startPage + numPagesToRead > multiPages_.size()) {
313  cout << "Start page: " << startPage << endl;
314  cout << "Num pages to read: " << numPagesToRead << endl;
315  cout << "Num multipages: " << multiPages_.size() << endl;
316  cout << "Offset: " << offset << endl;
317  cout << "Num bytes: " << numBytes << endl;
318  }
319  */
320 
321  CHECK(startPage + numPagesToRead <= multiPages_.size())
322  << "Requested page out of bounds";
323 
324  size_t numPagesPerThread = 0;
325  size_t numBytesCurrent = numBytes; // total number of bytes still to be read
326  size_t bytesRead = 0; // total number of bytes already being read
327  size_t bytesLeftForThread = 0; // number of bytes to be read in the thread
328  size_t numExtraPages = 0; // extra pages to be assigned one per thread as needed
329  size_t numThreads = fm_->getNumReaderThreads();
330  std::vector<readThreadDS>
331  threadDSArr; // array of threadDS, needed to avoid racing conditions
332 
333  if (numPagesToRead > numThreads) {
334  numPagesPerThread = numPagesToRead / numThreads;
335  numExtraPages = numPagesToRead - (numThreads * numPagesPerThread);
336  } else {
337  numThreads = numPagesToRead;
338  numPagesPerThread = 1;
339  }
340 
341  /* set threadDS for the first thread */
342  readThreadDS threadDS;
343  threadDS.t_fm = fm_;
344  threadDS.t_startPage = offset / pageDataSize_;
345  if (numExtraPages > 0) {
346  threadDS.t_endPage = threadDS.t_startPage + numPagesPerThread + 1;
347  numExtraPages--;
348  } else {
349  threadDS.t_endPage = threadDS.t_startPage + numPagesPerThread;
350  }
351  threadDS.t_curPtr = dst;
352  threadDS.t_startPageOffset = offset % pageDataSize_;
353  threadDS.t_isFirstPage = true;
354 
355  bytesLeftForThread = min(((threadDS.t_endPage - threadDS.t_startPage) * pageDataSize_ -
356  threadDS.t_startPageOffset),
357  numBytesCurrent);
358  threadDS.t_bytesLeft = bytesLeftForThread;
359  threadDS.multiPages = getMultiPage();
360 
361  if (numThreads == 1) {
362  bytesRead += readForThread(this, threadDS);
363  } else {
364  std::vector<std::future<size_t>> threads;
365 
366  for (size_t i = 0; i < numThreads; i++) {
367  threadDSArr.push_back(threadDS);
368  threads.push_back(
369  std::async(std::launch::async, readForThread, this, threadDSArr[i]));
370 
371  // calculate elements of threadDS
372  threadDS.t_fm = fm_;
373  threadDS.t_isFirstPage = false;
374  threadDS.t_curPtr += bytesLeftForThread;
375  threadDS.t_startPage +=
376  threadDS.t_endPage -
377  threadDS.t_startPage; // based on # of pages read on previous iteration
378  if (numExtraPages > 0) {
379  threadDS.t_endPage = threadDS.t_startPage + numPagesPerThread + 1;
380  numExtraPages--;
381  } else {
382  threadDS.t_endPage = threadDS.t_startPage + numPagesPerThread;
383  }
384  numBytesCurrent -= bytesLeftForThread;
385  bytesLeftForThread = min(
386  ((threadDS.t_endPage - threadDS.t_startPage) * pageDataSize_), numBytesCurrent);
387  threadDS.t_bytesLeft = bytesLeftForThread;
388  threadDS.multiPages = getMultiPage();
389  }
390 
391  for (auto& p : threads) {
392  p.wait();
393  }
394  for (auto& p : threads) {
395  bytesRead += p.get();
396  }
397  }
398  CHECK(bytesRead == numBytes);
399 }
virtual std::vector< MultiPage > getMultiPage() const
Returns vector of MultiPages in the FileBuffer.
Definition: FileBuffer.h:147
static size_t readForThread(FileBuffer *fileBuffer, const readThreadDS threadDS)
Definition: FileBuffer.cpp:256
#define LOG(tag)
Definition: Logger.h:285
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
future< Result > async(Fn &&fn, Args &&...args)
#define CHECK(condition)
Definition: Logger.h:291
size_t getNumReaderThreads()
Returns number of threads defined by parameter num-reader-threads which should be used during initial...
Definition: FileMgr.h:316

+ Here is the call graph for this function:

void File_Namespace::FileBuffer::readMetadata ( const Page page)
private

Definition at line 446 of file FileBuffer.cpp.

References CHECK, Data_Namespace::AbstractBuffer::encoder_, f(), File_Namespace::Page::fileId, fm_, File_Namespace::FileMgr::getFileForFileId(), Data_Namespace::AbstractBuffer::initEncoder(), METADATA_VERSION, metadataPageSize_, NUM_METADATA, File_Namespace::Page::pageNum, pageSize_, reservedHeaderSize_, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_dimension(), SQLTypeInfo::set_notnull(), SQLTypeInfo::set_scale(), SQLTypeInfo::set_size(), SQLTypeInfo::set_subtype(), SQLTypeInfo::set_type(), Data_Namespace::AbstractBuffer::size_, Data_Namespace::AbstractBuffer::sql_type_, and setup::version.

Referenced by initMetadataAndPageDataSize().

446  {
447  FILE* f = fm_->getFileForFileId(page.fileId);
448  fseek(f, page.pageNum * metadataPageSize_ + reservedHeaderSize_, SEEK_SET);
449  fread((int8_t*)&pageSize_, sizeof(size_t), 1, f);
450  fread((int8_t*)&size_, sizeof(size_t), 1, f);
451  vector<int32_t> typeData(
452  NUM_METADATA); // assumes we will encode hasEncoder, bufferType,
453  // encodingType, encodingBits all as int
454  fread((int8_t*)&(typeData[0]), sizeof(int32_t), typeData.size(), f);
455  int32_t version = typeData[0];
456  CHECK(version == METADATA_VERSION); // add backward compatibility code here
457  bool has_encoder = static_cast<bool>(typeData[1]);
458  if (has_encoder) {
459  sql_type_.set_type(static_cast<SQLTypes>(typeData[2]));
460  sql_type_.set_subtype(static_cast<SQLTypes>(typeData[3]));
461  sql_type_.set_dimension(typeData[4]);
462  sql_type_.set_scale(typeData[5]);
463  sql_type_.set_notnull(static_cast<bool>(typeData[6]));
464  sql_type_.set_compression(static_cast<EncodingType>(typeData[7]));
465  sql_type_.set_comp_param(typeData[8]);
466  sql_type_.set_size(typeData[9]);
468  encoder_->readMetadata(f);
469  }
470 }
void set_compression(EncodingType c)
Definition: sqltypes.h:481
void set_size(int s)
Definition: sqltypes.h:478
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:471
const size_t metadataPageSize_
Definition: FileBuffer.h:198
void initEncoder(const SQLTypeInfo &tmp_sql_type)
string version
Definition: setup.in.py:73
void set_scale(int s)
Definition: sqltypes.h:475
FILE * getFileForFileId(const int32_t fileId)
Returns FILE pointer associated with requested fileId.
Definition: FileMgr.cpp:1003
void set_comp_param(int p)
Definition: sqltypes.h:482
#define NUM_METADATA
Definition: FileBuffer.h:35
void set_dimension(int d)
Definition: sqltypes.h:472
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
std::unique_ptr< Encoder > encoder_
void set_notnull(bool n)
Definition: sqltypes.h:477
#define CHECK(condition)
Definition: Logger.h:291
#define METADATA_VERSION
Definition: FileBuffer.h:36
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:470

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::reserve ( const size_t  numBytes)
overridevirtual

Implements Data_Namespace::AbstractBuffer.

Definition at line 135 of file FileBuffer.cpp.

References addNewMultiPage(), getFileMgrEpoch(), multiPages_, pageSize_, and writeHeader().

135  {
136  size_t numPagesRequested = (numBytes + pageSize_ - 1) / pageSize_;
137  size_t numCurrentPages = multiPages_.size();
138  auto epoch = getFileMgrEpoch();
139  for (size_t pageNum = numCurrentPages; pageNum < numPagesRequested; ++pageNum) {
140  Page page = addNewMultiPage(epoch);
141  writeHeader(page, pageNum, epoch);
142  }
143 }
Page addNewMultiPage(const int32_t epoch)
Definition: FileBuffer.cpp:419
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
void writeHeader(Page &page, const int32_t pageId, const int32_t epoch, const bool writeMetadata=false)
Write header writes header at top of page in format.
Definition: FileBuffer.cpp:427

+ Here is the call graph for this function:

virtual size_t File_Namespace::FileBuffer::reservedHeaderSize ( ) const
inlinevirtual

Returns the size in bytes of the reserved header portion of each page in the FileBuffer.

Definition at line 144 of file FileBuffer.h.

Referenced by File_Namespace::readForThread().

144 { return reservedHeaderSize_; }

+ Here is the caller graph for this function:

size_t File_Namespace::FileBuffer::reservedSize ( ) const
inlineoverridevirtual

Returns the total number of bytes allocated for the FileBuffer.

Implements Data_Namespace::AbstractBuffer.

Definition at line 151 of file FileBuffer.h.

151 { return multiPages_.size() * pageSize_; }
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
void File_Namespace::FileBuffer::setBufferHeaderSize ( )
private

Definition at line 157 of file FileBuffer.cpp.

References File_Namespace::anonymous_namespace{FileBuffer.cpp}::calculate_buffer_header_size(), chunkKey_, and reservedHeaderSize_.

Referenced by FileBuffer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::write ( int8_t *  src,
const size_t  numBytes,
const size_t  offset = 0,
const MemoryLevel  srcMemoryLevel = CPU_LEVEL,
const int32_t  deviceId = -1 
)
override

Writes the contents of source (src) into new versions of the affected logical pages.

This method will write the contents of source (src) into new version of the affected logical pages. New pages are only appended if the value of epoch (in FileMgr)

Definition at line 547 of file FileBuffer.cpp.

References addNewMultiPage(), CHECK, copyPage(), Data_Namespace::CPU_LEVEL, File_Namespace::Page::fileId, fm_, File_Namespace::FileMgr::getFileInfoForFileId(), getFileMgrEpoch(), multiPages_, pageDataSize_, File_Namespace::Page::pageNum, pageSize_, File_Namespace::FileMgr::requestFreePage(), reservedHeaderSize_, Data_Namespace::AbstractBuffer::setAppended(), Data_Namespace::AbstractBuffer::setDirty(), Data_Namespace::AbstractBuffer::setUpdated(), Data_Namespace::AbstractBuffer::size_, File_Namespace::FileInfo::write(), and writeHeader().

551  {
552  CHECK(srcBufferType == CPU_LEVEL) << "Unsupported Buffer type";
553 
554  bool tempIsAppended = false;
555  setDirty();
556  if (offset < size_) {
557  setUpdated();
558  }
559  if (offset + numBytes > size_) {
560  tempIsAppended = true; // because is_appended_ could have already been true - to
561  // avoid rewriting header
562  setAppended();
563  size_ = offset + numBytes;
564  }
565 
566  size_t startPage = offset / pageDataSize_;
567  size_t startPageOffset = offset % pageDataSize_;
568  size_t numPagesToWrite =
569  (numBytes + startPageOffset + pageDataSize_ - 1) / pageDataSize_;
570  size_t bytesLeft = numBytes;
571  int8_t* curPtr = src; // a pointer to the current location in dst being written to
572  size_t initialNumPages = multiPages_.size();
573  auto epoch = getFileMgrEpoch();
574 
575  if (startPage >
576  initialNumPages) { // means there is a gap we need to allocate pages for
577  for (size_t pageNum = initialNumPages; pageNum < startPage; ++pageNum) {
578  Page page = addNewMultiPage(epoch);
579  writeHeader(page, pageNum, epoch);
580  }
581  }
582  for (size_t pageNum = startPage; pageNum < startPage + numPagesToWrite; ++pageNum) {
583  Page page;
584  if (pageNum >= initialNumPages) {
585  page = addNewMultiPage(epoch);
586  writeHeader(page, pageNum, epoch);
587  } else if (multiPages_[pageNum].current().epoch <
588  epoch) { // need to create new page b/c this current one lags epoch and we
589  // can't overwrite it also need to copy if we are on first or
590  // last page
591  Page lastPage = multiPages_[pageNum].current().page;
592  page = fm_->requestFreePage(pageSize_, false);
593  multiPages_[pageNum].push(page, epoch);
594  if (pageNum == startPage && startPageOffset > 0) {
595  // copyPage takes care of header offset so don't worry
596  // about it
597  copyPage(lastPage, page, startPageOffset, 0);
598  }
599  if (pageNum == (startPage + numPagesToWrite - 1) &&
600  bytesLeft > 0) { // bytesLeft should always > 0
601  copyPage(lastPage,
602  page,
603  pageDataSize_ - bytesLeft,
604  bytesLeft); // these would be empty if we're appending but we won't
605  // worry about it right now
606  }
607  writeHeader(page, pageNum, epoch);
608  } else {
609  // we already have a new page at current
610  // epoch for this page - just grab this page
611  page = multiPages_[pageNum].current().page;
612  }
613  CHECK(page.fileId >= 0); // make sure page was initialized
614  FileInfo* fileInfo = fm_->getFileInfoForFileId(page.fileId);
615  size_t bytesWritten;
616  if (pageNum == startPage) {
617  bytesWritten = fileInfo->write(
618  page.pageNum * pageSize_ + startPageOffset + reservedHeaderSize_,
619  min(pageDataSize_ - startPageOffset, bytesLeft),
620  curPtr);
621  } else {
622  bytesWritten = fileInfo->write(page.pageNum * pageSize_ + reservedHeaderSize_,
623  min(pageDataSize_, bytesLeft),
624  curPtr);
625  }
626  curPtr += bytesWritten;
627  bytesLeft -= bytesWritten;
628  if (tempIsAppended && pageNum == startPage + numPagesToWrite - 1) { // if last page
629  //@todo below can lead to undefined - we're overwriting num
630  // bytes valid at checkpoint
631  writeHeader(page, 0, multiPages_[0].current().epoch, true);
632  }
633  }
634  CHECK(bytesLeft == 0);
635 }
size_t write(const size_t offset, const size_t size, const int8_t *buf)
Definition: FileInfo.cpp:64
virtual Page requestFreePage(size_t pagesize, const bool isMetadata)
Definition: FileMgr.cpp:877
Page addNewMultiPage(const int32_t epoch)
Definition: FileBuffer.cpp:419
std::vector< MultiPage > multiPages_
Definition: FileBuffer.h:200
void writeHeader(Page &page, const int32_t pageId, const int32_t epoch, const bool writeMetadata=false)
Write header writes header at top of page in format.
Definition: FileBuffer.cpp:427
#define CHECK(condition)
Definition: Logger.h:291
FileInfo * getFileInfoForFileId(const int32_t fileId) const
Definition: FileMgr.h:229
void copyPage(Page &srcPage, Page &destPage, const size_t numBytes, const size_t offset=0)
Definition: FileBuffer.cpp:401

+ Here is the call graph for this function:

void File_Namespace::FileBuffer::writeHeader ( Page page,
const int32_t  pageId,
const int32_t  epoch,
const bool  writeMetadata = false 
)
private

Write header writes header at top of page in format.

Definition at line 427 of file FileBuffer.cpp.

References chunkKey_, gpu_enabled::copy(), File_Namespace::Page::fileId, fm_, File_Namespace::FileMgr::getFileInfoForFileId(), report::header, metadataPageSize_, File_Namespace::Page::pageNum, pageSize(), pageSize_, and File_Namespace::FileInfo::write().

Referenced by append(), reserve(), write(), and writeMetadata().

430  {
431  int32_t intHeaderSize = chunkKey_.size() + 3; // does not include chunkSize
432  vector<int32_t> header(intHeaderSize);
433  // in addition to chunkkey we need size of header, pageId, version
434  header[0] =
435  (intHeaderSize - 1) * sizeof(int32_t); // don't need to include size of headerSize
436  // value - sizeof(size_t) is for chunkSize
437  std::copy(chunkKey_.begin(), chunkKey_.end(), header.begin() + 1);
438  header[intHeaderSize - 2] = pageId;
439  header[intHeaderSize - 1] = epoch;
440  FileInfo* fileInfo = fm_->getFileInfoForFileId(page.fileId);
442  fileInfo->write(
443  page.pageNum * pageSize, (intHeaderSize) * sizeof(int32_t), (int8_t*)&header[0]);
444 }
void writeMetadata(const int32_t epoch)
Definition: FileBuffer.cpp:472
const size_t metadataPageSize_
Definition: FileBuffer.h:198
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
size_t pageSize() const override
Returns the size in bytes of each page in the FileBuffer.
Definition: FileBuffer.h:137
list header
Definition: report.py:113
FileInfo * getFileInfoForFileId(const int32_t fileId) const
Definition: FileMgr.h:229

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::FileBuffer::writeMetadata ( const int32_t  epoch)
private

Definition at line 472 of file FileBuffer.cpp.

References Data_Namespace::AbstractBuffer::encoder_, f(), File_Namespace::Page::fileId, fm_, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_size(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), File_Namespace::FileMgr::getFileForFileId(), Data_Namespace::AbstractBuffer::hasEncoder(), METADATA_VERSION, metadataPages_, metadataPageSize_, NUM_METADATA, File_Namespace::Page::pageNum, pageSize_, File_Namespace::MultiPage::push(), File_Namespace::FileMgr::requestFreePage(), reservedHeaderSize_, Data_Namespace::AbstractBuffer::size_, Data_Namespace::AbstractBuffer::sql_type_, and writeHeader().

472  {
473  // Right now stats page is size_ (in bytes), bufferType, encodingType,
474  // encodingDataType, numElements
475  Page page = fm_->requestFreePage(metadataPageSize_, true);
476  writeHeader(page, -1, epoch, true);
477  FILE* f = fm_->getFileForFileId(page.fileId);
478  fseek(f, page.pageNum * metadataPageSize_ + reservedHeaderSize_, SEEK_SET);
479  fwrite((int8_t*)&pageSize_, sizeof(size_t), 1, f);
480  fwrite((int8_t*)&size_, sizeof(size_t), 1, f);
481  vector<int32_t> typeData(
482  NUM_METADATA); // assumes we will encode hasEncoder, bufferType,
483  // encodingType, encodingBits all as int32_t
484  typeData[0] = METADATA_VERSION;
485  typeData[1] = static_cast<int32_t>(hasEncoder());
486  if (hasEncoder()) {
487  typeData[2] = static_cast<int32_t>(sql_type_.get_type());
488  typeData[3] = static_cast<int32_t>(sql_type_.get_subtype());
489  typeData[4] = sql_type_.get_dimension();
490  typeData[5] = sql_type_.get_scale();
491  typeData[6] = static_cast<int32_t>(sql_type_.get_notnull());
492  typeData[7] = static_cast<int32_t>(sql_type_.get_compression());
493  typeData[8] = sql_type_.get_comp_param();
494  typeData[9] = sql_type_.get_size();
495  }
496  fwrite((int8_t*)&(typeData[0]), sizeof(int32_t), typeData.size(), f);
497  if (hasEncoder()) { // redundant
498  encoder_->writeMetadata(f);
499  }
500  metadataPages_.push(page, epoch);
501 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
virtual Page requestFreePage(size_t pagesize, const bool isMetadata)
Definition: FileMgr.cpp:877
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
const size_t metadataPageSize_
Definition: FileBuffer.h:198
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
FILE * getFileForFileId(const int32_t fileId)
Returns FILE pointer associated with requested fileId.
Definition: FileMgr.cpp:1003
void writeHeader(Page &page, const int32_t pageId, const int32_t epoch, const bool writeMetadata=false)
Write header writes header at top of page in format.
Definition: FileBuffer.cpp:427
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
#define NUM_METADATA
Definition: FileBuffer.h:35
void push(const Page &page, const int epoch)
Pushes a new page with epoch value.
Definition: Page.h:102
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
std::unique_ptr< Encoder > encoder_
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
#define METADATA_VERSION
Definition: FileBuffer.h:36

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class CachingFileMgr
friend

Definition at line 59 of file FileBuffer.h.

friend class FileMgr
friend

Definition at line 58 of file FileBuffer.h.

Member Data Documentation

ChunkKey File_Namespace::FileBuffer::chunkKey_
private
constexpr size_t File_Namespace::FileBuffer::kHeaderBufferOffset {32}
static
MultiPage File_Namespace::FileBuffer::metadataPages_
private
const size_t File_Namespace::FileBuffer::metadataPageSize_
private

Definition at line 198 of file FileBuffer.h.

Referenced by readMetadata(), writeHeader(), and writeMetadata().

std::vector<MultiPage> File_Namespace::FileBuffer::multiPages_
private
size_t File_Namespace::FileBuffer::pageDataSize_
private
size_t File_Namespace::FileBuffer::pageSize_
private
size_t File_Namespace::FileBuffer::reservedHeaderSize_
private

The documentation for this class was generated from the following files: