A helper function to actually read the data from GCS.
| 992 | |
| 993 | // A helper function to actually read the data from GCS. |
| 994 | Status GcsFileSystem::LoadBufferFromGCS(const string& fname, size_t offset, |
| 995 | size_t n, char* buffer, |
| 996 | size_t* bytes_transferred) { |
| 997 | *bytes_transferred = 0; |
| 998 | |
| 999 | string bucket, object; |
| 1000 | TF_RETURN_IF_ERROR(ParseGcsPath(fname, false, &bucket, &object)); |
| 1001 | |
| 1002 | std::unique_ptr<HttpRequest> request; |
| 1003 | TF_RETURN_WITH_CONTEXT_IF_ERROR(CreateHttpRequest(&request), |
| 1004 | "when reading gs://", bucket, "/", object); |
| 1005 | |
| 1006 | request->SetUri(strings::StrCat("https://", kStorageHost, "/", bucket, "/", |
| 1007 | request->EscapeString(object))); |
| 1008 | request->SetRange(offset, offset + n - 1); |
| 1009 | request->SetResultBufferDirect(buffer, n); |
| 1010 | request->SetTimeouts(timeouts_.connect, timeouts_.idle, timeouts_.read); |
| 1011 | |
| 1012 | if (stats_ != nullptr) { |
| 1013 | stats_->RecordBlockLoadRequest(fname, offset); |
| 1014 | } |
| 1015 | |
| 1016 | TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when reading gs://", |
| 1017 | bucket, "/", object); |
| 1018 | |
| 1019 | size_t bytes_read = request->GetResultBufferDirectBytesTransferred(); |
| 1020 | *bytes_transferred = bytes_read; |
| 1021 | VLOG(1) << "Successful read of gs://" << bucket << "/" << object << " @ " |
| 1022 | << offset << " of size: " << bytes_read; |
| 1023 | |
| 1024 | if (stats_ != nullptr) { |
| 1025 | stats_->RecordBlockRetrieved(fname, offset, bytes_read); |
| 1026 | } |
| 1027 | |
| 1028 | throttle_.RecordResponse(bytes_read); |
| 1029 | |
| 1030 | if (bytes_read < n) { |
| 1031 | // Check stat cache to see if we encountered an interrupted read. |
| 1032 | GcsFileStat stat; |
| 1033 | if (stat_cache_->Lookup(fname, &stat)) { |
| 1034 | if (offset + bytes_read < stat.base.length) { |
| 1035 | return errors::Internal(strings::Printf( |
| 1036 | "File contents are inconsistent for file: %s @ %lu.", fname.c_str(), |
| 1037 | offset)); |
| 1038 | } |
| 1039 | VLOG(2) << "Successful integrity check for: gs://" << bucket << "/" |
| 1040 | << object << " @ " << offset; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | return Status::OK(); |
| 1045 | } |
| 1046 | |
| 1047 | void GcsFileSystem::ClearFileCaches(const string& fname) { |
| 1048 | tf_shared_lock l(block_cache_lock_); |
nothing calls this directly
no test coverage detected