MCPcopy Create free account
hub / github.com/apache/arrow / Resize

Method Resize

cpp/src/arrow/io/file.cc:484–528  ·  view source on GitHub ↗

Resize the mmap and file to the specified size. Resize on memory mapped file region is not supported.

Source from the content-addressed store, hash-verified

482 // Resize the mmap and file to the specified size.
483 // Resize on memory mapped file region is not supported.
484 Status Resize(const int64_t new_size) {
485 if (!writable()) {
486 return Status::IOError("Cannot resize a readonly memory map");
487 }
488 if (map_len_ != file_size_) {
489 return Status::IOError("Cannot resize a partial memory map");
490 }
491 if (region_.use_count() > 1) {
492 // There are buffer exports currently, the MemoryMapRemap() call
493 // would make the buffers invalid
494 return Status::IOError("Cannot resize memory map while there are active readers");
495 }
496
497 if (new_size == 0) {
498 if (map_len_ > 0) {
499 // Just unmap the mmap and truncate the file to 0 size
500 region_.reset();
501 RETURN_NOT_OK(::arrow::internal::FileTruncate(file_->fd(), 0));
502 map_len_ = offset_ = file_size_ = 0;
503 }
504 position_ = 0;
505 return Status::OK();
506 }
507
508 if (map_len_ > 0) {
509 void* result;
510 auto data = region_->data();
511 RETURN_NOT_OK(::arrow::internal::MemoryMapRemap(data, map_len_, new_size,
512 file_->fd(), &result));
513 region_->Detach(); // avoid munmap() on destruction
514 region_ = std::make_shared<Region>(shared_from_this(),
515 static_cast<uint8_t*>(result), new_size);
516 map_len_ = file_size_ = new_size;
517 offset_ = 0;
518 if (position_ > map_len_) {
519 position_ = map_len_;
520 }
521 } else {
522 DCHECK_EQ(position_, 0);
523 // the mmap is not yet initialized, resize the underlying
524 // file, since it might have been 0-sized
525 RETURN_NOT_OK(InitMMap(new_size, /*resize_file*/ true));
526 }
527 return Status::OK();
528 }
529
530 Status Seek(int64_t position) {
531 if (position < 0) {

Callers

nothing calls this directly

Calls 8

IOErrorFunction · 0.85
FileTruncateFunction · 0.85
MemoryMapRemapFunction · 0.85
OKFunction · 0.50
resetMethod · 0.45
fdMethod · 0.45
dataMethod · 0.45
DetachMethod · 0.45

Tested by

no test coverage detected