MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / LoadBufferFromGCS

Method LoadBufferFromGCS

tensorflow/core/platform/cloud/gcs_file_system.cc:994–1045  ·  view source on GitHub ↗

A helper function to actually read the data from GCS.

Source from the content-addressed store, hash-verified

992
993// A helper function to actually read the data from GCS.
994Status 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
1047void GcsFileSystem::ClearFileCaches(const string& fname) {
1048 tf_shared_lock l(block_cache_lock_);

Callers

nothing calls this directly

Calls 15

ParseGcsPathFunction · 0.85
InternalFunction · 0.85
PrintfFunction · 0.85
RecordBlockRetrievedMethod · 0.80
c_strMethod · 0.80
StrCatFunction · 0.50
SetUriMethod · 0.45
EscapeStringMethod · 0.45
SetRangeMethod · 0.45
SetResultBufferDirectMethod · 0.45
SetTimeoutsMethod · 0.45

Tested by

no test coverage detected