MCPcopy Create free account
hub / github.com/apache/impala / PinStream

Method PinStream

be/src/runtime/buffered-tuple-stream.cc:663–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

661}
662
663Status BufferedTupleStream::PinStream(bool* pinned) {
664 DCHECK(!closed_);
665 CHECK_CONSISTENCY_FULL(read_it_);
666 if (pinned_) {
667 *pinned = true;
668 return Status::OK();
669 }
670 *pinned = false;
671 // First, make sure we have the reservation to pin all the pages for reading.
672 int64_t bytes_to_pin = 0;
673 for (Page& page : pages_) {
674 bytes_to_pin += (ExpectedPinCount(true, &page) - page.pin_count()) * page.len();
675 }
676
677 // Check if we have some reservation to restore.
678 bool restore_write_reservation =
679 NeedWriteReservation(false) && !NeedWriteReservation(true);
680 bool restore_read_reservation =
681 NeedReadReservation(false) && !NeedReadReservation(true);
682 int64_t increase_needed = bytes_to_pin
683 - (restore_write_reservation ? default_page_len_ : 0)
684 - (restore_read_reservation ? default_page_len_ : 0);
685 bool reservation_granted =
686 buffer_pool_client_->IncreaseReservationToFit(increase_needed);
687 if (!reservation_granted) return Status::OK();
688
689 // If there is no current write page we should have some saved reservation to use.
690 // Only continue saving it if the stream is empty and need it to pin the first page.
691 if (restore_write_reservation) {
692 buffer_pool_client_->RestoreReservation(&write_page_reservation_, default_page_len_);
693 }
694 if (restore_read_reservation) {
695 buffer_pool_client_->RestoreReservation(&read_page_reservation_, default_page_len_);
696 }
697
698 // At this point success is guaranteed - go through to pin the pages we need to pin.
699 // If the page data was evicted from memory, the read I/O can happen in parallel
700 // because we defer calling GetBuffer() until NextReadPage().
701 for (Page& page : pages_) RETURN_IF_ERROR(PinPageIfNeeded(&page, true));
702
703 pinned_ = true;
704 *pinned = true;
705 CHECK_CONSISTENCY_FULL(read_it_);
706 return Status::OK();
707}
708
709Status BufferedTupleStream::UnpinStream(UnpinMode mode) {
710 CHECK_CONSISTENCY_FULL(read_it_);

Callers 3

BuildHashTableMethod · 0.80
TestUnpinPinMethod · 0.80

Calls 5

OKFunction · 0.85
RestoreReservationMethod · 0.80
pin_countMethod · 0.45
lenMethod · 0.45

Tested by 1

TestUnpinPinMethod · 0.64