diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/auth_provider.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/auth_provider.h index 969b8bc0cea23e..4b1b2927581b72 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/auth_provider.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/auth_provider.h @@ -31,9 +31,9 @@ class AuthProvider { /// \brief Returns the short-term authentication bearer token. /// /// Safe for concurrent use by multiple threads. - virtual Status GetToken(string* t) = 0; + virtual absl::Status GetToken(string* t) = 0; - static Status GetToken(AuthProvider* provider, string* token) { + static absl::Status GetToken(AuthProvider* provider, string* token) { if (!provider) { return errors::Internal("Auth provider is required."); } @@ -44,9 +44,9 @@ class AuthProvider { /// No-op auth provider, which will only work for public objects. class EmptyAuthProvider : public AuthProvider { public: - Status GetToken(string* token) override { + absl::Status GetToken(string* token) override { *token = ""; - return OkStatus(); + return absl::OkStatus(); } }; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.cc index 7be3af7019050f..7a41c8f37b7536 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.cc @@ -40,7 +40,7 @@ ComputeEngineMetadataClient::ComputeEngineMetadataClient( : http_request_factory_(std::move(http_request_factory)), retry_config_(config) {} -Status ComputeEngineMetadataClient::GetMetadata( +absl::Status ComputeEngineMetadataClient::GetMetadata( const string& path, std::vector* response_buffer) { const auto get_metadata_from_gce = [path, response_buffer, this]() { string metadata_url; @@ -56,7 +56,7 @@ Status ComputeEngineMetadataClient::GetMetadata( request->AddHeader("Metadata-Flavor", "Google"); request->SetResultBuffer(response_buffer); TF_RETURN_IF_ERROR(request->Send()); - return OkStatus(); + return absl::OkStatus(); }; return RetryingUtils::CallWithRetries(get_metadata_from_gce, retry_config_); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.h index fac94cdb1c9c8c..1337d33c8e1895 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_metadata_client.h @@ -51,8 +51,8 @@ class ComputeEngineMetadataClient { /// To get the zone of an instance: /// compute_engine_metadata_client.GetMetadata( /// "instance/zone", response_buffer); - virtual Status GetMetadata(const string& path, - std::vector* response_buffer); + virtual absl::Status GetMetadata(const string& path, + std::vector* response_buffer); private: std::shared_ptr http_request_factory_; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.cc index 7720784db75eac..19f27556d44991 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.cc @@ -28,15 +28,15 @@ ComputeEngineZoneProvider::ComputeEngineZoneProvider( std::shared_ptr google_metadata_client) : google_metadata_client_(std::move(google_metadata_client)) {} -Status ComputeEngineZoneProvider::GetZone(string* zone) { +absl::Status ComputeEngineZoneProvider::GetZone(string* zone) { if (!cached_zone.empty()) { *zone = cached_zone; - return OkStatus(); + return absl::OkStatus(); } std::vector response_buffer; TF_RETURN_IF_ERROR(google_metadata_client_->GetMetadata(kGceMetadataZonePath, &response_buffer)); - StringPiece location(&response_buffer[0], response_buffer.size()); + absl::string_view location(&response_buffer[0], response_buffer.size()); std::vector elems = str_util::Split(location, "/"); if (elems.size() == 4) { @@ -47,7 +47,7 @@ Status ComputeEngineZoneProvider::GetZone(string* zone) { << string(location); } - return OkStatus(); + return absl::OkStatus(); } ComputeEngineZoneProvider::~ComputeEngineZoneProvider() {} diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.h index a37b43c22a484f..99ed41fca7d881 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/compute_engine_zone_provider.h @@ -27,7 +27,7 @@ class ComputeEngineZoneProvider : public ZoneProvider { std::shared_ptr google_metadata_client); virtual ~ComputeEngineZoneProvider(); - Status GetZone(string* zone) override; + absl::Status GetZone(string* zone) override; private: std::shared_ptr google_metadata_client_; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.cc index c41f967c04b055..44eeab7f511fb9 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.cc @@ -230,8 +230,8 @@ void CurlHttpRequest::SetDeleteRequest() { libcurl_->curl_easy_setopt(curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); } -Status CurlHttpRequest::SetPutFromFile(const string& body_filepath, - size_t offset) { +absl::Status CurlHttpRequest::SetPutFromFile(const string& body_filepath, + size_t offset) { CheckNotSent(); CheckMethodNotSet(); is_method_set_ = true; @@ -257,7 +257,7 @@ Status CurlHttpRequest::SetPutFromFile(const string& body_filepath, reinterpret_cast(put_body_))); // Using the default CURLOPT_READFUNCTION, which is doing an fread() on the // FILE * userdata set with CURLOPT_READDATA. - return OkStatus(); + return absl::OkStatus(); } void CurlHttpRequest::SetPutEmptyBody() { @@ -286,7 +286,7 @@ void CurlHttpRequest::SetPostFromBuffer(const char* buffer, size_t size) { reinterpret_cast(this))); CHECK_CURL_OK(libcurl_->curl_easy_setopt(curl_, CURLOPT_READFUNCTION, &CurlHttpRequest::ReadCallback)); - post_body_buffer_ = StringPiece(buffer, size); + post_body_buffer_ = absl::string_view(buffer, size); } void CurlHttpRequest::SetPostEmptyBody() { @@ -397,8 +397,8 @@ size_t CurlHttpRequest::HeaderCallback(const void* ptr, size_t size, size_t nmemb, void* this_object) { CHECK(ptr); auto that = reinterpret_cast(this_object); - StringPiece header(reinterpret_cast(ptr), size * nmemb); - StringPiece name, value; + absl::string_view header(reinterpret_cast(ptr), size * nmemb); + absl::string_view name, value; // The supplied header has the form ": ", parse it. if (strings::Scanner(header) .ScanEscapedUntil(':') @@ -412,7 +412,7 @@ size_t CurlHttpRequest::HeaderCallback(const void* ptr, size_t size, return size * nmemb; } -Status CurlHttpRequest::Send() { +absl::Status CurlHttpRequest::Send() { CheckNotSent(); CHECK(is_uri_set_) << "URI has not been set."; @@ -457,7 +457,7 @@ Status CurlHttpRequest::Send() { auto get_error_message = [this]() -> string { string error_message = strings::StrCat( "Error executing an HTTP request: HTTP response code ", response_code_); - StringPiece body = GetResponse(); + absl::string_view body = GetResponse(); if (!body.empty()) { return strings::StrCat( error_message, " with body '", @@ -466,7 +466,7 @@ Status CurlHttpRequest::Send() { return error_message; }; - Status result; + absl::Status result; switch (response_code_) { // The group of response codes indicating that the request achieved // the expected goal. @@ -474,7 +474,7 @@ Status CurlHttpRequest::Send() { case 201: // Created case 204: // No Content case 206: // Partial Content - result = OkStatus(); + result = absl::OkStatus(); break; case 416: // Requested Range Not Satisfiable @@ -485,7 +485,7 @@ Status CurlHttpRequest::Send() { if (IsDirectResponse()) { direct_response_.bytes_transferred_ = 0; } - result = OkStatus(); + result = absl::OkStatus(); break; // INVALID_ARGUMENT indicates a problem with how the request is constructed. @@ -556,13 +556,14 @@ void CurlHttpRequest::CheckNotSent() const { CHECK(!is_sent_) << "The request has already been sent."; } -StringPiece CurlHttpRequest::GetResponse() const { - StringPiece response; +absl::string_view CurlHttpRequest::GetResponse() const { + absl::string_view response; if (IsDirectResponse()) { - response = StringPiece(direct_response_.buffer_, - direct_response_.bytes_transferred_); + response = absl::string_view(direct_response_.buffer_, + direct_response_.bytes_transferred_); } else { - response = StringPiece(response_buffer_->data(), response_buffer_->size()); + response = + absl::string_view(response_buffer_->data(), response_buffer_->size()); } return response; } @@ -627,10 +628,10 @@ int CurlHttpRequest::ProgressCallback(void* this_object, curl_off_t dltotal, return 0; } -Status CurlHttpRequest::CURLcodeToStatus(CURLcode code, - const char* error_buffer) { +absl::Status CurlHttpRequest::CURLcodeToStatus(CURLcode code, + const char* error_buffer) { if (code == CURLE_OK) { - return OkStatus(); + return absl::OkStatus(); } string error_message = strings::StrCat( "Error executing an HTTP request: libcurl code ", code, " meaning '", @@ -648,7 +649,7 @@ Status CurlHttpRequest::CURLcodeToStatus(CURLcode code, // a response body (e.g. GCS sends one with an error message) but we // pretend as though they don't, so actually ignore this error. if (get_response_result == CURLE_OK && response_code == 416) { - return OkStatus(); + return absl::OkStatus(); } return errors::FailedPrecondition( strings::StrCat(error_message, overflow_message)); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.h index b5c728520dc693..4c64758a0bda8b 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request.h @@ -86,7 +86,8 @@ class CurlHttpRequest : public HttpRequest { /// /// The request body will be taken from the specified file starting from /// the given offset. - Status SetPutFromFile(const string& body_filepath, size_t offset) override; + absl::Status SetPutFromFile(const string& body_filepath, + size_t offset) override; /// Makes the request a PUT request with an empty body. void SetPutEmptyBody() override; @@ -140,7 +141,7 @@ class CurlHttpRequest : public HttpRequest { /// /// If the result buffer was defined, the response will be written there. /// The object is not designed to be re-used after Send() is executed. - Status Send() override; + absl::Status Send() override; // Url encodes str and returns a new string. string EscapeString(const string& str) override; @@ -167,18 +168,18 @@ class CurlHttpRequest : public HttpRequest { curl_off_t ulnow); void CheckMethodNotSet() const; void CheckNotSent() const; - StringPiece GetResponse() const; + absl::string_view GetResponse() const; /// Helper to convert the given CURLcode and error buffer, representing the /// result of performing a transfer, into a Status with an error message. - Status CURLcodeToStatus(CURLcode code, const char* error_buffer); + absl::Status CURLcodeToStatus(CURLcode code, const char* error_buffer); LibCurl* libcurl_; Env* env_; FILE* put_body_ = nullptr; - StringPiece post_body_buffer_; + absl::string_view post_body_buffer_; size_t post_body_read_ = 0; std::vector* response_buffer_ = nullptr; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request_test.cc index 272210f11c485d..31cde679f4978b 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/curl_http_request_test.cc @@ -151,8 +151,8 @@ class FakeLibCurl : public LibCurl { posted_content_ = ""; do { bytes_read = read_callback_(buffer, 1, sizeof(buffer), read_data_); - posted_content_ = - strings::StrCat(posted_content_, StringPiece(buffer, bytes_read)); + posted_content_ = strings::StrCat( + posted_content_, absl::string_view(buffer, bytes_read)); } while (bytes_read > 0); } if (write_data_ || write_callback_) { @@ -366,7 +366,7 @@ TEST(CurlHttpRequestTest, GetRequest_Direct_ResponseTooLarge) { http_request.SetUri("http://www.testuri.com"); http_request.SetResultBufferDirect(scratch.data(), scratch.size()); - const Status& status = http_request.Send(); + const absl::Status& status = http_request.Send(); EXPECT_EQ(error::FAILED_PRECONDITION, status.code()); EXPECT_EQ( "Error executing an HTTP request: libcurl code 23 meaning " @@ -770,7 +770,7 @@ class TestStats : public HttpRequest::RequestStats { void RecordResponse(const HttpRequest* request, const string& uri, HttpRequest::RequestMethod method, - const Status& result) override { + const absl::Status& result) override { has_recorded_response_ = true; record_response_request_ = request; record_response_uri_ = uri; @@ -787,7 +787,7 @@ class TestStats : public HttpRequest::RequestStats { string record_response_uri_ = "http://www.testuri.com"; HttpRequest::RequestMethod record_response_method_ = HttpRequest::RequestMethod::kGet; - Status record_response_result_; + absl::Status record_response_result_; bool has_recorded_request_ = false; bool has_recorded_response_ = false; @@ -864,7 +864,7 @@ TEST(CurlHttpRequestTest, StatsGetNotFound) { http_request.AddAuthBearerHeader("fake-bearer"); http_request.SetRange(100, 199); http_request.SetResultBuffer(&scratch); - Status s = http_request.Send(); + absl::Status s = http_request.Send(); // Check interaction with stats. ASSERT_TRUE(stats.has_recorded_request_); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache.h index 1def81b6d0d562..d3a15bc9fa3781 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache.h @@ -71,13 +71,13 @@ class ExpiringLRUCache { return LookupLocked(key, value); } - typedef std::function ComputeFunc; + typedef std::function ComputeFunc; /// Look up the entry with key `key` and copy it to `value` if found. If not /// found, call `compute_func`. If `compute_func` returns successfully, store /// a copy of the output parameter in the cache, and another copy in `value`. - Status LookupOrCompute(const string& key, T* value, - const ComputeFunc& compute_func) { + absl::Status LookupOrCompute(const string& key, T* value, + const ComputeFunc& compute_func) { if (max_age_ == 0) { return compute_func(key, value); } @@ -88,9 +88,9 @@ class ExpiringLRUCache { // key if this proves to be a significant performance bottleneck. mutex_lock lock(mu_); if (LookupLocked(key, value)) { - return OkStatus(); + return absl::OkStatus(); } - Status s = compute_func(key, value); + absl::Status s = compute_func(key, value); if (s.ok()) { InsertLocked(key, *value); } diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache_test.cc index 75dc4c04f2b898..7225dca6e50ce1 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/expiring_lru_cache_test.cc @@ -97,7 +97,7 @@ TEST(ExpiringLRUCacheTest, LookupOrCompute) { [&num_compute_calls](const string& key, int* value) { *value = num_compute_calls; num_compute_calls++; - return OkStatus(); + return absl::OkStatus(); }; ExpiringLRUCache cache1(0, 4); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/file_block_cache.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/file_block_cache.h index e336a42835c9f9..59927545f7eb76 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/file_block_cache.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/file_block_cache.h @@ -70,9 +70,9 @@ class FileBlockCache { /// cache is constructed. The returned Status should be OK as long as the /// read from the remote filesystem succeeded (similar to the semantics of the /// read(2) system call). - typedef std::function + typedef std::function BlockFetcher; virtual ~FileBlockCache() {} @@ -91,8 +91,8 @@ class FileBlockCache { /// placed in `out`. /// 4) OK otherwise (i.e. the read succeeded, and at least one byte was placed /// in `out`). - virtual Status Read(const string& filename, size_t offset, size_t n, - char* buffer, size_t* bytes_transferred) = 0; + virtual absl::Status Read(const string& filename, size_t offset, size_t n, + char* buffer, size_t* bytes_transferred) = 0; // Validate the given file signature with the existing file signature in the // cache. Returns true if the signature doesn't change or the file did not diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache.cc index 4819b49fc31338..594703f31ffef2 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache.cc @@ -41,7 +41,8 @@ namespace { const std::vector& kCachedDomainNames = *new std::vector{"www.googleapis.com", "storage.googleapis.com"}; -inline void print_getaddrinfo_error(const string& name, Status return_status) { +inline void print_getaddrinfo_error(const string& name, + absl::Status return_status) { // Status doesn't map well to EAI type errors. LOG(ERROR) << "Error resolving " << name << ": " << return_status; } @@ -104,13 +105,13 @@ void GcsDnsCache::AnnotateRequest(HttpRequest* request) { /* max_delay_time_us = */ 50 * 1000 * 5000, /* max_retries = */ 5); - const Status getaddrinfo_status = RetryingUtils::CallWithRetries( + const absl::Status getaddrinfo_status = RetryingUtils::CallWithRetries( [&name, &hints, &result]() { int return_code = getaddrinfo(name.c_str(), nullptr, &hints, &result); absl::Status return_status; switch (return_code) { case 0: - return_status = OkStatus(); + return_status = absl::OkStatus(); break; #ifndef _WIN32 case EAI_ADDRFAMILY: @@ -175,7 +176,7 @@ void GcsDnsCache::AnnotateRequest(HttpRequest* request) { #endif } - return Status(return_status); + return absl::Status(return_status); }, retryConfig); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache_test.cc index 069dcb546f0ebb..a5ce0882ba5688 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_dns_cache_test.cc @@ -40,8 +40,9 @@ class TestHttpRequest : public HttpRequest { void SetRequestStats(HttpRequest::RequestStats* stats) override {} void SetDeleteRequest() override {} - Status SetPutFromFile(const string& body_filepath, size_t offset) override { - return OkStatus(); + absl::Status SetPutFromFile(const string& body_filepath, + size_t offset) override { + return absl::OkStatus(); } void SetPutEmptyBody() override {} void SetPostFromBuffer(const char* buffer, size_t size) override {} @@ -52,7 +53,7 @@ class TestHttpRequest : public HttpRequest { string GetResponseHeader(const string& name) const override { return ""; } uint64 GetResponseCode() const override { return 0; } - Status Send() override { return OkStatus(); } + absl::Status Send() override { return absl::OkStatus(); } string EscapeString(const string& str) override { return ""; } void SetTimeouts(uint32 connection, uint32 inactivity, diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.cc index 8b593d5390f621..c1cc244e0dc173 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.cc @@ -163,9 +163,9 @@ constexpr char kAppendMode[] = "GCS_APPEND_MODE"; // objects. constexpr char kComposeAppend[] = "compose"; -Status GetTmpFilename(string* filename) { +absl::Status GetTmpFilename(string* filename) { *filename = io::GetTempFilename(""); - return OkStatus(); + return absl::OkStatus(); } /// Appends a trailing slash if the name doesn't already have one. @@ -199,7 +199,7 @@ std::set AddAllSubpaths(const std::vector& paths) { std::set result; result.insert(paths.begin(), paths.end()); for (const string& path : paths) { - StringPiece subpath = io::Dirname(path); + absl::string_view subpath = io::Dirname(path); // If `path` starts with `/`, `subpath` will be `/` and then we get into an // infinite loop. Same behavior happens if there is a `//` pattern in // `path`, so we check for that and leave the loop quicker. @@ -211,32 +211,32 @@ std::set AddAllSubpaths(const std::vector& paths) { return result; } -Status ParseJson(StringPiece json, Json::Value* result) { +absl::Status ParseJson(absl::string_view json, Json::Value* result) { Json::Reader reader; if (!reader.parse(json.data(), json.data() + json.size(), *result)) { return errors::Internal("Couldn't parse JSON response from GCS."); } - return OkStatus(); + return absl::OkStatus(); } -Status ParseJson(const std::vector& json, Json::Value* result) { - return ParseJson(StringPiece{json.data(), json.size()}, result); +absl::Status ParseJson(const std::vector& json, Json::Value* result) { + return ParseJson(absl::string_view{json.data(), json.size()}, result); } /// Reads a JSON value with the given name from a parent JSON value. -Status GetValue(const Json::Value& parent, const char* name, - Json::Value* result) { +absl::Status GetValue(const Json::Value& parent, const char* name, + Json::Value* result) { *result = parent.get(name, Json::Value::null); if (result->isNull()) { return errors::Internal("The field '", name, "' was expected in the JSON response."); } - return OkStatus(); + return absl::OkStatus(); } /// Reads a string JSON value with the given name from a parent JSON value. -Status GetStringValue(const Json::Value& parent, const char* name, - string* result) { +absl::Status GetStringValue(const Json::Value& parent, const char* name, + string* result) { Json::Value result_value; TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value)); if (!result_value.isString()) { @@ -245,21 +245,21 @@ Status GetStringValue(const Json::Value& parent, const char* name, "' in the JSON response was expected to be a string."); } *result = result_value.asString(); - return OkStatus(); + return absl::OkStatus(); } /// Reads a long JSON value with the given name from a parent JSON value. -Status GetInt64Value(const Json::Value& parent, const char* name, - int64_t* result) { +absl::Status GetInt64Value(const Json::Value& parent, const char* name, + int64_t* result) { Json::Value result_value; TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value)); if (result_value.isNumeric()) { *result = result_value.asInt64(); - return OkStatus(); + return absl::OkStatus(); } if (result_value.isString() && strings::safe_strto64(result_value.asCString(), result)) { - return OkStatus(); + return absl::OkStatus(); } return errors::Internal( "The field '", name, @@ -267,7 +267,8 @@ Status GetInt64Value(const Json::Value& parent, const char* name, } /// Reads a boolean JSON value with the given name from a parent JSON value. -Status GetBoolValue(const Json::Value& parent, const char* name, bool* result) { +absl::Status GetBoolValue(const Json::Value& parent, const char* name, + bool* result) { Json::Value result_value; TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value)); if (!result_value.isBool()) { @@ -276,7 +277,7 @@ Status GetBoolValue(const Json::Value& parent, const char* name, bool* result) { "' in the JSON response was expected to be a boolean."); } *result = result_value.asBool(); - return OkStatus(); + return absl::OkStatus(); } /// Get GCS Retry Config by applying user overrides through env if any. @@ -314,21 +315,21 @@ RetryConfig GetGcsRetryConfig() { /// A GCS-based implementation of a random access file with an LRU block cache. class GcsRandomAccessFile : public RandomAccessFile { public: - using ReadFn = - std::function; + using ReadFn = std::function; GcsRandomAccessFile(const string& filename, ReadFn read_fn) : filename_(filename), read_fn_(std::move(read_fn)) {} - Status Name(StringPiece* result) const override { + absl::Status Name(absl::string_view* result) const override { *result = filename_; - return OkStatus(); + return absl::OkStatus(); } /// The implementation of reads with an LRU block cache. Thread safe. - Status Read(uint64 offset, size_t n, StringPiece* result, - char* scratch) const override { + absl::Status Read(uint64 offset, size_t n, absl::string_view* result, + char* scratch) const override { return read_fn_(filename_, offset, n, result, scratch); } @@ -342,9 +343,9 @@ class GcsRandomAccessFile : public RandomAccessFile { /// A GCS-based implementation of a random access file with a read buffer. class BufferedGcsRandomAccessFile : public RandomAccessFile { public: - using ReadFn = - std::function; + using ReadFn = std::function; // Initialize the reader. Provided read_fn should be thread safe. BufferedGcsRandomAccessFile(const string& filename, uint64 buffer_size, @@ -355,16 +356,16 @@ class BufferedGcsRandomAccessFile : public RandomAccessFile { buffer_start_(0), buffer_end_is_past_eof_(false) {} - Status Name(StringPiece* result) const override { + absl::Status Name(absl::string_view* result) const override { *result = filename_; - return OkStatus(); + return absl::OkStatus(); } /// The implementation of reads with an read buffer. Thread safe. /// Returns `OUT_OF_RANGE` if fewer than n bytes were stored in `*result` /// because of EOF. - Status Read(uint64 offset, size_t n, StringPiece* result, - char* scratch) const override { + absl::Status Read(uint64 offset, size_t n, absl::string_view* result, + char* scratch) const override { if (n > buffer_size_) { return read_fn_(filename_, offset, n, result, scratch); } @@ -375,12 +376,12 @@ class BufferedGcsRandomAccessFile : public RandomAccessFile { if (offset < buffer_end && offset >= buffer_start_) { copy_size = std::min(n, static_cast(buffer_end - offset)); memcpy(scratch, buffer_.data() + (offset - buffer_start_), copy_size); - *result = StringPiece(scratch, copy_size); + *result = absl::string_view(scratch, copy_size); } bool consumed_buffer_to_eof = offset + copy_size >= buffer_end && buffer_end_is_past_eof_; if (copy_size < n && !consumed_buffer_to_eof) { - Status status = FillBuffer(offset + copy_size); + absl::Status status = FillBuffer(offset + copy_size); if (!status.ok() && !absl::IsOutOfRange(status)) { // Empty the buffer to avoid caching bad reads. buffer_.resize(0); @@ -389,7 +390,7 @@ class BufferedGcsRandomAccessFile : public RandomAccessFile { size_t remaining_copy = std::min(n - copy_size, buffer_.size()); memcpy(scratch + copy_size, buffer_.data(), remaining_copy); copy_size += remaining_copy; - *result = StringPiece(scratch, copy_size); + *result = absl::string_view(scratch, copy_size); } if (copy_size < n) { // Forget the end-of-file flag to allow for clients that poll on the @@ -399,17 +400,17 @@ class BufferedGcsRandomAccessFile : public RandomAccessFile { " bytes from ", offset, "."); } } - return OkStatus(); + return absl::OkStatus(); } private: - Status FillBuffer(uint64 start) const + absl::Status FillBuffer(uint64 start) const TF_EXCLUSIVE_LOCKS_REQUIRED(buffer_mutex_) { buffer_start_ = start; buffer_.resize(buffer_size_); - StringPiece str_piece; - Status status = read_fn_(filename_, buffer_start_, buffer_size_, &str_piece, - &(buffer_[0])); + absl::string_view str_piece; + absl::Status status = read_fn_(filename_, buffer_start_, buffer_size_, + &str_piece, &(buffer_[0])); buffer_end_is_past_eof_ = absl::IsOutOfRange(status); buffer_.resize(str_piece.size()); return status; @@ -437,28 +438,28 @@ class BufferedGcsRandomAccessFile : public RandomAccessFile { }; // Function object declaration with params needed to create upload sessions. -typedef std::function SessionCreator; // Function object declaration with params needed to upload objects. -typedef std::function +typedef std::function ObjectUploader; // Function object declaration with params needed to poll upload status. -typedef std::function +typedef std::function StatusPoller; // Function object declaration with params needed to poll upload status. -typedef std::function +typedef std::function GenerationGetter; /// \brief GCS-based implementation of a writeable file. @@ -534,7 +535,7 @@ class GcsWritableFile : public WritableFile { std::remove(tmp_content_filename_.c_str()); } - Status Append(StringPiece data) override { + absl::Status Append(absl::string_view data) override { TF_RETURN_IF_ERROR(CheckWritable()); VLOG(3) << "Append: " << GetGcsPath() << " size " << data.length(); sync_needed_ = true; @@ -543,38 +544,38 @@ class GcsWritableFile : public WritableFile { return errors::Internal( "Could not append to the internal temporary file."); } - return OkStatus(); + return absl::OkStatus(); } - Status Close() override { + absl::Status Close() override { VLOG(3) << "Close:" << GetGcsPath(); if (outfile_.is_open()) { - Status sync_status = Sync(); + absl::Status sync_status = Sync(); if (sync_status.ok()) { outfile_.close(); } return sync_status; } - return OkStatus(); + return absl::OkStatus(); } - Status Flush() override { + absl::Status Flush() override { VLOG(3) << "Flush:" << GetGcsPath(); return Sync(); } - Status Name(StringPiece* result) const override { + absl::Status Name(absl::string_view* result) const override { *result = object_; return absl::OkStatus(); } - Status Sync() override { + absl::Status Sync() override { VLOG(3) << "Sync started:" << GetGcsPath(); TF_RETURN_IF_ERROR(CheckWritable()); if (!sync_needed_) { - return OkStatus(); + return absl::OkStatus(); } - Status status = SyncImpl(); + absl::Status status = SyncImpl(); VLOG(3) << "Sync finished " << GetGcsPath(); if (status.ok()) { sync_needed_ = false; @@ -582,12 +583,12 @@ class GcsWritableFile : public WritableFile { return status; } - Status Tell(int64_t* position) override { + absl::Status Tell(int64_t* position) override { *position = outfile_.tellp(); if (*position == -1) { return errors::Internal("tellp on the internal temporary file failed"); } - return OkStatus(); + return absl::OkStatus(); } private: @@ -597,7 +598,7 @@ class GcsWritableFile : public WritableFile { /// In case of a failure, it resumes failed uploads as recommended by the GCS /// resumable API documentation. When the whole upload needs to be /// restarted, Sync() returns UNAVAILABLE and relies on RetryingFileSystem. - Status SyncImpl() { + absl::Status SyncImpl() { outfile_.flush(); if (!outfile_.good()) { return errors::Internal( @@ -621,7 +622,7 @@ class GcsWritableFile : public WritableFile { &session_handle)); uint64 already_uploaded = 0; bool first_attempt = true; - const Status upload_status = RetryingUtils::CallWithRetries( + const absl::Status upload_status = RetryingUtils::CallWithRetries( [&first_attempt, &already_uploaded, &session_handle, &start_offset, this]() { if (session_handle.resumable && !first_attempt) { @@ -638,7 +639,7 @@ class GcsWritableFile : public WritableFile { // It's unclear why UploadToSession didn't return OK in the // previous attempt, but GCS reports that the file is fully // uploaded, so succeed. - return OkStatus(); + return absl::OkStatus(); } } first_attempt = false; @@ -662,28 +663,28 @@ class GcsWritableFile : public WritableFile { return upload_status; } - Status CheckWritable() const { + absl::Status CheckWritable() const { if (!outfile_.is_open()) { return errors::FailedPrecondition( "The internal temporary file is not writable."); } - return OkStatus(); + return absl::OkStatus(); } - Status GetCurrentFileSize(uint64* size) { + absl::Status GetCurrentFileSize(uint64* size) { const auto tellp = outfile_.tellp(); if (tellp == static_cast(-1)) { return errors::Internal( "Could not get the size of the internal temporary file."); } *size = tellp; - return OkStatus(); + return absl::OkStatus(); } /// Initiates a new resumable upload session. - Status CreateNewUploadSession(uint64 start_offset, - std::string object_to_upload, - UploadSessionHandle* session_handle) { + absl::Status CreateNewUploadSession(uint64 start_offset, + std::string object_to_upload, + UploadSessionHandle* session_handle) { uint64 file_size; TF_RETURN_IF_ERROR(GetCurrentFileSize(&file_size)); return session_creator_(start_offset, object_to_upload, bucket_, file_size, @@ -692,7 +693,7 @@ class GcsWritableFile : public WritableFile { /// Appends the data of append_object to the original object and deletes /// append_object. - Status AppendObject(string append_object) { + absl::Status AppendObject(string append_object) { const string append_object_path = GetGcsPathWithObject(append_object); VLOG(3) << "AppendObject: " << append_object_path << " to " << GetGcsPath(); @@ -719,7 +720,7 @@ class GcsWritableFile : public WritableFile { request->SetPostFromBuffer(request_body.c_str(), request_body.size()); TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when composing to ", GetGcsPath()); - return OkStatus(); + return absl::OkStatus(); }, retry_config_)); @@ -735,8 +736,8 @@ class GcsWritableFile : public WritableFile { /// If the upload has already succeeded, sets 'completed' to true. /// Otherwise sets 'completed' to false and 'uploaded' to the currently /// uploaded size in bytes. - Status RequestUploadSessionStatus(const string& session_uri, bool* completed, - uint64* uploaded) { + absl::Status RequestUploadSessionStatus(const string& session_uri, + bool* completed, uint64* uploaded) { uint64 file_size; TF_RETURN_IF_ERROR(GetCurrentFileSize(&file_size)); return status_poller_(session_uri, file_size, GetGcsPath(), completed, @@ -744,11 +745,11 @@ class GcsWritableFile : public WritableFile { } /// Uploads data to object. - Status UploadToSession(const string& session_uri, uint64 start_offset, - uint64 already_uploaded) { + absl::Status UploadToSession(const string& session_uri, uint64 start_offset, + uint64 already_uploaded) { uint64 file_size; TF_RETURN_IF_ERROR(GetCurrentFileSize(&file_size)); - Status status = + absl::Status status = object_uploader_(session_uri, start_offset, already_uploaded, tmp_content_filename_, file_size, GetGcsPath()); if (status.ok()) { @@ -796,14 +797,14 @@ class GcsReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { uint64 length_; }; -bool StringPieceIdentity(StringPiece str, StringPiece* value) { +bool StringPieceIdentity(absl::string_view str, absl::string_view* value) { *value = str; return true; } /// \brief Utility function to split a comma delimited list of strings to an /// unordered set, lowercasing all values. -bool SplitByCommaToLowercaseSet(StringPiece list, +bool SplitByCommaToLowercaseSet(absl::string_view list, std::unordered_set* set) { std::vector vector = absl::StrSplit(absl::AsciiStrToLower(list), ','); *set = std::unordered_set(vector.begin(), vector.end()); @@ -898,14 +899,14 @@ GcsFileSystem::GcsFileSystem(bool make_default_cache) { } // Get the additional header - StringPiece add_header_contents; + absl::string_view add_header_contents; if (GetEnvVar(kAdditionalRequestHeader, StringPieceIdentity, &add_header_contents)) { size_t split = add_header_contents.find(':', 0); - if (split != StringPiece::npos) { - StringPiece header_name = add_header_contents.substr(0, split); - StringPiece header_value = add_header_contents.substr(split + 1); + if (split != absl::string_view::npos) { + absl::string_view header_name = add_header_contents.substr(0, split); + absl::string_view header_value = add_header_contents.substr(split + 1); if (!header_name.empty() && !header_value.empty()) { additional_header_.reset(new std::pair( @@ -969,7 +970,7 @@ GcsFileSystem::GcsFileSystem(bool make_default_cache) { GetEnvVar(kAllowedBucketLocations, SplitByCommaToLowercaseSet, &allowed_locations_); - StringPiece append_mode; + absl::string_view append_mode; GetEnvVar(kAppendMode, StringPieceIdentity, &append_mode); if (append_mode == kComposeAppend) { compose_append_ = true; @@ -1007,7 +1008,7 @@ GcsFileSystem::GcsFileSystem( compose_append_(compose_append), additional_header_(additional_header) {} -Status GcsFileSystem::NewRandomAccessFile( +absl::Status GcsFileSystem::NewRandomAccessFile( const string& fname, TransactionToken* token, std::unique_ptr* result) { string bucket, object; @@ -1017,7 +1018,7 @@ Status GcsFileSystem::NewRandomAccessFile( result->reset(new GcsRandomAccessFile(fname, [this, bucket, object]( const string& fname, uint64 offset, size_t n, - StringPiece* result, + absl::string_view* result, char* scratch) { tf_shared_lock l(block_cache_lock_); GcsFileStat stat; @@ -1032,37 +1033,37 @@ Status GcsFileSystem::NewRandomAccessFile( << "File signature has been changed. Refreshing the cache. Path: " << fname; } - *result = StringPiece(); + *result = absl::string_view(); size_t bytes_transferred; TF_RETURN_IF_ERROR(file_block_cache_->Read(fname, offset, n, scratch, &bytes_transferred)); - *result = StringPiece(scratch, bytes_transferred); + *result = absl::string_view(scratch, bytes_transferred); if (bytes_transferred < n) { return errors::OutOfRange("EOF reached, ", result->size(), " bytes were read out of ", n, " bytes requested."); } - return OkStatus(); + return absl::OkStatus(); })); } else { result->reset(new BufferedGcsRandomAccessFile( fname, block_size_, [this, bucket, object](const string& fname, uint64 offset, size_t n, - StringPiece* result, char* scratch) { - *result = StringPiece(); + absl::string_view* result, char* scratch) { + *result = absl::string_view(); size_t bytes_transferred; TF_RETURN_IF_ERROR( LoadBufferFromGCS(fname, offset, n, scratch, &bytes_transferred)); - *result = StringPiece(scratch, bytes_transferred); + *result = absl::string_view(scratch, bytes_transferred); if (bytes_transferred < n) { return errors::OutOfRange("EOF reached, ", result->size(), " bytes were read out of ", n, " bytes requested."); } - return OkStatus(); + return absl::OkStatus(); })); } - return OkStatus(); + return absl::OkStatus(); } void GcsFileSystem::ResetFileBlockCache(size_t block_size_bytes, @@ -1093,9 +1094,10 @@ std::unique_ptr GcsFileSystem::MakeFileBlockCache( } // A helper function to actually read the data from GCS. -Status GcsFileSystem::LoadBufferFromGCS(const string& fname, size_t offset, - size_t n, char* buffer, - size_t* bytes_transferred) { +absl::Status GcsFileSystem::LoadBufferFromGCS(const string& fname, + size_t offset, size_t n, + char* buffer, + size_t* bytes_transferred) { *bytes_transferred = 0; string bucket, object; @@ -1149,11 +1151,11 @@ Status GcsFileSystem::LoadBufferFromGCS(const string& fname, size_t offset, } } - return OkStatus(); + return absl::OkStatus(); } /// Initiates a new upload session. -Status GcsFileSystem::CreateNewUploadSession( +absl::Status GcsFileSystem::CreateNewUploadSession( uint64 start_offset, const std::string& object_to_upload, const std::string& bucket, uint64 file_size, const std::string& gcs_path, UploadSessionHandle* session_handle) { @@ -1180,15 +1182,13 @@ Status GcsFileSystem::CreateNewUploadSession( gcs_path, ": 'Location' header not returned."); } } - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::UploadToSession(const std::string& session_uri, - uint64 start_offset, - uint64 already_uploaded, - const std::string& tmp_content_filename, - uint64 file_size, - const std::string& file_path) { +absl::Status GcsFileSystem::UploadToSession( + const std::string& session_uri, uint64 start_offset, + uint64 already_uploaded, const std::string& tmp_content_filename, + uint64 file_size, const std::string& file_path) { std::unique_ptr request; TF_RETURN_IF_ERROR(CreateHttpRequest(&request)); request->SetUri(session_uri); @@ -1204,14 +1204,12 @@ Status GcsFileSystem::UploadToSession(const std::string& session_uri, start_offset + already_uploaded)); TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when uploading ", file_path); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::RequestUploadSessionStatus(const string& session_uri, - uint64 file_size, - const std::string& gcs_path, - bool* completed, - uint64* uploaded) { +absl::Status GcsFileSystem::RequestUploadSessionStatus( + const string& session_uri, uint64 file_size, const std::string& gcs_path, + bool* completed, uint64* uploaded) { CHECK(completed != nullptr) << "RequestUploadSessionStatus() called with out " "param 'completed' == nullptr."; // Crash ok CHECK(uploaded != nullptr) << "RequestUploadSessionStatus() called with out " @@ -1222,10 +1220,10 @@ Status GcsFileSystem::RequestUploadSessionStatus(const string& session_uri, request->SetTimeouts(timeouts_.connect, timeouts_.idle, timeouts_.metadata); request->AddHeader("Content-Range", strings::StrCat("bytes */", file_size)); request->SetPutEmptyBody(); - Status status = request->Send(); + absl::Status status = request->Send(); if (status.ok()) { *completed = true; - return OkStatus(); + return absl::OkStatus(); } *completed = false; if (request->GetResponseCode() != HTTP_CODE_RESUME_INCOMPLETE) { @@ -1236,7 +1234,7 @@ Status GcsFileSystem::RequestUploadSessionStatus(const string& session_uri, // This means GCS doesn't have any bytes of the file yet. *uploaded = 0; } else { - StringPiece range_piece(received_range); + absl::string_view range_piece(received_range); absl::ConsumePrefix(&range_piece, "bytes="); // May or may not be present. @@ -1270,13 +1268,15 @@ Status GcsFileSystem::RequestUploadSessionStatus(const string& session_uri, // If GCS returned "Range: 0-10", this means 11 bytes were uploaded. *uploaded = range_parts[1] + 1; } - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::ParseGcsPathForScheme(StringPiece fname, string scheme, - bool empty_object_ok, - string* bucket, string* object) { - StringPiece parsed_scheme, bucketp, objectp; +absl::Status GcsFileSystem::ParseGcsPathForScheme(absl::string_view fname, + string scheme, + bool empty_object_ok, + string* bucket, + string* object) { + absl::string_view parsed_scheme, bucketp, objectp; io::ParseURI(fname, &parsed_scheme, &bucketp, &objectp); if (parsed_scheme != scheme) { return errors::InvalidArgument("GCS path doesn't start with 'gs://': ", @@ -1293,11 +1293,12 @@ Status GcsFileSystem::ParseGcsPathForScheme(StringPiece fname, string scheme, return errors::InvalidArgument("GCS path doesn't contain an object name: ", fname); } - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::ParseGcsPath(StringPiece fname, bool empty_object_ok, - string* bucket, string* object) { +absl::Status GcsFileSystem::ParseGcsPath(absl::string_view fname, + bool empty_object_ok, string* bucket, + string* object) { return ParseGcsPathForScheme(fname, "gs", empty_object_ok, bucket, object); } @@ -1309,9 +1310,9 @@ void GcsFileSystem::ClearFileCaches(const string& fname) { // MatchingPathsCache as well. } -Status GcsFileSystem::NewWritableFile(const string& fname, - TransactionToken* token, - std::unique_ptr* result) { +absl::Status GcsFileSystem::NewWritableFile( + const string& fname, TransactionToken* token, + std::unique_ptr* result) { string bucket, object; TF_RETURN_IF_ERROR(ParseGcsPath(fname, false, &bucket, &object)); @@ -1345,7 +1346,7 @@ Status GcsFileSystem::NewWritableFile(const string& fname, }, retry_config_)); *generation = stat.generation_number; - return OkStatus(); + return absl::OkStatus(); }; result->reset(new GcsWritableFile( @@ -1353,20 +1354,20 @@ Status GcsFileSystem::NewWritableFile(const string& fname, [this, fname]() { ClearFileCaches(fname); }, retry_config_, compose_append_, session_creator, object_uploader, status_poller, generation_getter)); - return OkStatus(); + return absl::OkStatus(); } // Reads the file from GCS in chunks and stores it in a tmp file, // which is then passed to GcsWritableFile. -Status GcsFileSystem::NewAppendableFile(const string& fname, - TransactionToken* token, - std::unique_ptr* result) { +absl::Status GcsFileSystem::NewAppendableFile( + const string& fname, TransactionToken* token, + std::unique_ptr* result) { std::unique_ptr reader; TF_RETURN_IF_ERROR(NewRandomAccessFile(fname, token, &reader)); std::unique_ptr buffer(new char[kReadAppendableFileBufferSize]); - Status status; + absl::Status status; uint64 offset = 0; - StringPiece read_chunk; + absl::string_view read_chunk; // Read the file from GCS in chunks and save it to a tmp file. string old_content_filename; @@ -1422,7 +1423,7 @@ Status GcsFileSystem::NewAppendableFile(const string& fname, }, retry_config_)); *generation = stat.generation_number; - return OkStatus(); + return absl::OkStatus(); }; // Create a writable file and pass the old content to it. @@ -1433,10 +1434,10 @@ Status GcsFileSystem::NewAppendableFile(const string& fname, [this, fname]() { ClearFileCaches(fname); }, retry_config_, compose_append_, session_creator, object_uploader, status_poller, generation_getter)); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::NewReadOnlyMemoryRegionFromFile( +absl::Status GcsFileSystem::NewReadOnlyMemoryRegionFromFile( const string& fname, TransactionToken* token, std::unique_ptr* result) { uint64 size; @@ -1446,21 +1447,22 @@ Status GcsFileSystem::NewReadOnlyMemoryRegionFromFile( std::unique_ptr file; TF_RETURN_IF_ERROR(NewRandomAccessFile(fname, token, &file)); - StringPiece piece; + absl::string_view piece; TF_RETURN_IF_ERROR(file->Read(0, size, &piece, data.get())); result->reset(new GcsReadOnlyMemoryRegion(std::move(data), size)); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::FileExists(const string& fname, TransactionToken* token) { +absl::Status GcsFileSystem::FileExists(const string& fname, + TransactionToken* token) { string bucket, object; TF_RETURN_IF_ERROR(ParseGcsPath(fname, true, &bucket, &object)); if (object.empty()) { bool result; TF_RETURN_IF_ERROR(BucketExists(bucket, &result)); if (result) { - return OkStatus(); + return absl::OkStatus(); } else { return absl::NotFoundError( absl::StrCat("The specified bucket ", fname, " was not found.")); @@ -1469,7 +1471,7 @@ Status GcsFileSystem::FileExists(const string& fname, TransactionToken* token) { // Check if the object exists. GcsFileStat stat; - const Status status = StatForObject(fname, bucket, object, &stat); + const absl::Status status = StatForObject(fname, bucket, object, &stat); if (!absl::IsNotFound(status)) { return status; } @@ -1478,31 +1480,32 @@ Status GcsFileSystem::FileExists(const string& fname, TransactionToken* token) { bool result; TF_RETURN_IF_ERROR(FolderExists(fname, &result)); if (result) { - return OkStatus(); + return absl::OkStatus(); } return errors::NotFound("The specified path ", fname, " was not found."); } -Status GcsFileSystem::ObjectExists(const string& fname, const string& bucket, - const string& object, bool* result) { +absl::Status GcsFileSystem::ObjectExists(const string& fname, + const string& bucket, + const string& object, bool* result) { GcsFileStat stat; - const Status status = StatForObject(fname, bucket, object, &stat); + const absl::Status status = StatForObject(fname, bucket, object, &stat); switch (static_cast(status.code())) { case static_cast(error::Code::OK): *result = !stat.base.is_directory; - return OkStatus(); + return absl::OkStatus(); case static_cast(error::Code::NOT_FOUND): *result = false; - return OkStatus(); + return absl::OkStatus(); default: return status; } } -Status GcsFileSystem::UncachedStatForObject(const string& fname, - const string& bucket, - const string& object, - GcsFileStat* stat) { +absl::Status GcsFileSystem::UncachedStatForObject(const string& fname, + const string& bucket, + const string& object, + GcsFileStat* stat) { std::vector output_buffer; std::unique_ptr request; TF_RETURN_WITH_CONTEXT_IF_ERROR(CreateHttpRequest(&request), @@ -1543,7 +1546,7 @@ Status GcsFileSystem::UncachedStatForObject(const string& fname, << "; mtime_nsec: " << stat->base.mtime_nsec << "; updated: " << updated; - if (str_util::EndsWith(fname, "/")) { + if (absl::EndsWith(fname, "/")) { // In GCS a path can be both a directory and a file, both it is uncommon for // other file systems. To avoid the ambiguity, if a path ends with "/" in // GCS, we always regard it as a directory mark or a virtual directory. @@ -1551,11 +1554,13 @@ Status GcsFileSystem::UncachedStatForObject(const string& fname, } else { stat->base.is_directory = false; } - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::StatForObject(const string& fname, const string& bucket, - const string& object, GcsFileStat* stat) { +absl::Status GcsFileSystem::StatForObject(const string& fname, + const string& bucket, + const string& object, + GcsFileStat* stat) { if (object.empty()) { return errors::InvalidArgument(strings::Printf( "'object' must be a non-empty string. (File: %s)", fname.c_str())); @@ -1566,26 +1571,27 @@ Status GcsFileSystem::StatForObject(const string& fname, const string& bucket, [this, &bucket, &object](const string& fname, GcsFileStat* stat) { return UncachedStatForObject(fname, bucket, object, stat); })); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::BucketExists(const string& bucket, bool* result) { - const Status status = GetBucketMetadata(bucket, nullptr); +absl::Status GcsFileSystem::BucketExists(const string& bucket, bool* result) { + const absl::Status status = GetBucketMetadata(bucket, nullptr); switch (static_cast(status.code())) { case absl::StatusCode::kOk: *result = true; - return OkStatus(); + return absl::OkStatus(); case absl::StatusCode::kNotFound: *result = false; - return OkStatus(); + return absl::OkStatus(); default: return status; } } -Status GcsFileSystem::CheckBucketLocationConstraint(const string& bucket) { +absl::Status GcsFileSystem::CheckBucketLocationConstraint( + const string& bucket) { if (allowed_locations_.empty()) { - return OkStatus(); + return absl::OkStatus(); } // Avoid calling external API's in the constructor @@ -1598,7 +1604,7 @@ Status GcsFileSystem::CheckBucketLocationConstraint(const string& bucket) { string location; TF_RETURN_IF_ERROR(GetBucketLocation(bucket, &location)); if (allowed_locations_.find(location) != allowed_locations_.end()) { - return OkStatus(); + return absl::OkStatus(); } return errors::FailedPrecondition(strings::Printf( @@ -1607,11 +1613,11 @@ Status GcsFileSystem::CheckBucketLocationConstraint(const string& bucket) { absl::StrJoin(allowed_locations_, ", ").c_str())); } -Status GcsFileSystem::GetBucketLocation(const string& bucket, - string* location) { +absl::Status GcsFileSystem::GetBucketLocation(const string& bucket, + string* location) { auto compute_func = [this](const string& bucket, string* location) { std::vector result_buffer; - Status status = GetBucketMetadata(bucket, &result_buffer); + absl::Status status = GetBucketMetadata(bucket, &result_buffer); Json::Value result; TF_RETURN_IF_ERROR(ParseJson(result_buffer, &result)); string bucket_location; @@ -1619,17 +1625,17 @@ Status GcsFileSystem::GetBucketLocation(const string& bucket, GetStringValue(result, kBucketMetadataLocationKey, &bucket_location)); // Lowercase the GCS location to be case insensitive for allowed locations. *location = absl::AsciiStrToLower(bucket_location); - return OkStatus(); + return absl::OkStatus(); }; TF_RETURN_IF_ERROR( bucket_location_cache_->LookupOrCompute(bucket, location, compute_func)); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::GetBucketMetadata(const string& bucket, - std::vector* result_buffer) { +absl::Status GcsFileSystem::GetBucketMetadata( + const string& bucket, std::vector* result_buffer) { std::unique_ptr request; TF_RETURN_IF_ERROR(CreateHttpRequest(&request)); request->SetUri(strings::StrCat(kGcsUriBase, "b/", bucket)); @@ -1642,7 +1648,7 @@ Status GcsFileSystem::GetBucketMetadata(const string& bucket, return request->Send(); } -Status GcsFileSystem::FolderExists(const string& dirname, bool* result) { +absl::Status GcsFileSystem::FolderExists(const string& dirname, bool* result) { StatCache::ComputeFunc compute_func = [this](const string& dirname, GcsFileStat* stat) { std::vector children; @@ -1651,36 +1657,36 @@ Status GcsFileSystem::FolderExists(const string& dirname, bool* result) { true /* include_self_directory_marker */)); if (!children.empty()) { stat->base = DIRECTORY_STAT; - return OkStatus(); + return absl::OkStatus(); } else { return errors::InvalidArgument("Not a directory!"); } }; GcsFileStat stat; - Status s = stat_cache_->LookupOrCompute(MaybeAppendSlash(dirname), &stat, - compute_func); + absl::Status s = stat_cache_->LookupOrCompute(MaybeAppendSlash(dirname), + &stat, compute_func); if (s.ok()) { *result = stat.base.is_directory; - return OkStatus(); + return absl::OkStatus(); } if (absl::IsInvalidArgument(s)) { *result = false; - return OkStatus(); + return absl::OkStatus(); } return s; } -Status GcsFileSystem::GetChildren(const string& dirname, - TransactionToken* token, - std::vector* result) { +absl::Status GcsFileSystem::GetChildren(const string& dirname, + TransactionToken* token, + std::vector* result) { return GetChildrenBounded(dirname, UINT64_MAX, result, false /* recursively */, false /* include_self_directory_marker */); } -Status GcsFileSystem::GetMatchingPaths(const string& pattern, - TransactionToken* token, - std::vector* results) { +absl::Status GcsFileSystem::GetMatchingPaths(const string& pattern, + TransactionToken* token, + std::vector* results) { MatchingPathsCache::ComputeFunc compute_func = [this](const string& pattern, std::vector* results) { results->clear(); @@ -1701,7 +1707,7 @@ Status GcsFileSystem::GetMatchingPaths(const string& pattern, // To handle `/` in the object names, we need to remove it from `dir` // and then use `StrCat` to insert it back. - const StringPiece dir_no_slash = str_util::StripSuffix(dir, "/"); + const absl::string_view dir_no_slash = absl::StripSuffix(dir, "/"); // Match all obtained paths to the input pattern. for (const auto& path : files_and_folders) { @@ -1716,18 +1722,16 @@ Status GcsFileSystem::GetMatchingPaths(const string& pattern, results->push_back(full_path); } } - return OkStatus(); + return absl::OkStatus(); }; TF_RETURN_IF_ERROR( matching_paths_cache_->LookupOrCompute(pattern, results, compute_func)); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::GetChildrenBounded(const string& dirname, - uint64 max_results, - std::vector* result, - bool recursive, - bool include_self_directory_marker) { +absl::Status GcsFileSystem::GetChildrenBounded( + const string& dirname, uint64 max_results, std::vector* result, + bool recursive, bool include_self_directory_marker) { if (!result) { return errors::InvalidArgument("'result' cannot be null"); } @@ -1787,7 +1791,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, // The names should be relative to the 'dirname'. That means the // 'object_prefix', which is part of 'dirname', should be removed from // the beginning of 'name'. - StringPiece relative_path(name); + absl::string_view relative_path(name); if (!absl::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal(strings::StrCat( "Unexpected response: the returned file name ", name, @@ -1797,7 +1801,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, result->emplace_back(relative_path); } if (++retrieved_results >= max_results) { - return OkStatus(); + return absl::OkStatus(); } } } @@ -1816,7 +1820,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, "response."); } const string& prefix_str = prefix.asString(); - StringPiece relative_path(prefix_str); + absl::string_view relative_path(prefix_str); if (!absl::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal( "Unexpected response: the returned folder name ", prefix_str, @@ -1824,13 +1828,13 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, } result->emplace_back(relative_path); if (++retrieved_results >= max_results) { - return OkStatus(); + return absl::OkStatus(); } } } const auto token = root.get("nextPageToken", Json::Value::null); if (token.isNull()) { - return OkStatus(); + return absl::OkStatus(); } if (!token.isString()) { return errors::Internal( @@ -1840,8 +1844,8 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, } } -Status GcsFileSystem::Stat(const string& fname, TransactionToken* token, - FileStatistics* stat) { +absl::Status GcsFileSystem::Stat(const string& fname, TransactionToken* token, + FileStatistics* stat) { if (!stat) { return errors::Internal("'stat' cannot be nullptr."); } @@ -1852,16 +1856,16 @@ Status GcsFileSystem::Stat(const string& fname, TransactionToken* token, TF_RETURN_IF_ERROR(BucketExists(bucket, &is_bucket)); if (is_bucket) { *stat = DIRECTORY_STAT; - return OkStatus(); + return absl::OkStatus(); } return errors::NotFound("The specified bucket ", fname, " was not found."); } GcsFileStat gcs_stat; - const Status status = StatForObject(fname, bucket, object, &gcs_stat); + const absl::Status status = StatForObject(fname, bucket, object, &gcs_stat); if (status.ok()) { *stat = gcs_stat.base; - return OkStatus(); + return absl::OkStatus(); } if (!absl::IsNotFound(status)) { return status; @@ -1870,12 +1874,13 @@ Status GcsFileSystem::Stat(const string& fname, TransactionToken* token, TF_RETURN_IF_ERROR(FolderExists(fname, &is_folder)); if (is_folder) { *stat = DIRECTORY_STAT; - return OkStatus(); + return absl::OkStatus(); } return errors::NotFound("The specified path ", fname, " was not found."); } -Status GcsFileSystem::DeleteFile(const string& fname, TransactionToken* token) { +absl::Status GcsFileSystem::DeleteFile(const string& fname, + TransactionToken* token) { string bucket, object; TF_RETURN_IF_ERROR(ParseGcsPath(fname, false, &bucket, &object)); @@ -1888,11 +1893,11 @@ Status GcsFileSystem::DeleteFile(const string& fname, TransactionToken* token) { TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when deleting ", fname); ClearFileCaches(fname); - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::CreateDir(const string& dirname, - TransactionToken* token) { +absl::Status GcsFileSystem::CreateDir(const string& dirname, + TransactionToken* token) { string dirname_with_slash = MaybeAppendSlash(dirname); VLOG(3) << "CreateDir: creating directory with dirname: " << dirname << " and dirname_with_slash: " << dirname_with_slash; @@ -1902,7 +1907,7 @@ Status GcsFileSystem::CreateDir(const string& dirname, if (object.empty()) { bool is_bucket; TF_RETURN_IF_ERROR(BucketExists(bucket, &is_bucket)); - return is_bucket ? OkStatus() + return is_bucket ? absl::OkStatus() : errors::NotFound("The specified bucket ", dirname_with_slash, " was not found."); } @@ -1925,10 +1930,10 @@ Status GcsFileSystem::CreateDir(const string& dirname, request->SetPostEmptyBody(); request->SetTimeouts(timeouts_.connect, timeouts_.idle, timeouts_.metadata); - const Status& status = request->Send(); + const absl::Status& status = request->Send(); if (status.ok()) { VLOG(3) << "CreateDir: finished uploading directory " << dirname; - return OkStatus(); + return absl::OkStatus(); } if (request->GetResponseCode() != HTTP_CODE_PRECONDITION_FAILED) { TF_RETURN_WITH_CONTEXT_IF_ERROR(status, " when uploading ", @@ -1941,8 +1946,8 @@ Status GcsFileSystem::CreateDir(const string& dirname, // Checks that the directory is empty (i.e no objects with this prefix exist). // Deletes the GCS directory marker if it exists. -Status GcsFileSystem::DeleteDir(const string& dirname, - TransactionToken* token) { +absl::Status GcsFileSystem::DeleteDir(const string& dirname, + TransactionToken* token) { std::vector children; // A directory is considered empty either if there are no matching objects // with the corresponding name prefix or if there is exactly one matching @@ -1959,11 +1964,12 @@ Status GcsFileSystem::DeleteDir(const string& dirname, // This is the directory marker object. Delete it. return DeleteFile(MaybeAppendSlash(dirname), token); } - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::GetFileSize(const string& fname, TransactionToken* token, - uint64* file_size) { +absl::Status GcsFileSystem::GetFileSize(const string& fname, + TransactionToken* token, + uint64* file_size) { if (!file_size) { return errors::Internal("'file_size' cannot be nullptr."); } @@ -1975,11 +1981,11 @@ Status GcsFileSystem::GetFileSize(const string& fname, TransactionToken* token, FileStatistics stat; TF_RETURN_IF_ERROR(Stat(fname, token, &stat)); *file_size = stat.length; - return OkStatus(); + return absl::OkStatus(); } -Status GcsFileSystem::RenameFile(const string& src, const string& target, - TransactionToken* token) { +absl::Status GcsFileSystem::RenameFile(const string& src, const string& target, + TransactionToken* token) { if (!IsDirectory(src, token).ok()) { return RenameObject(src, target); } @@ -1992,11 +1998,12 @@ Status GcsFileSystem::RenameFile(const string& src, const string& target, TF_RETURN_IF_ERROR( RenameObject(JoinGcsPath(src, subpath), JoinGcsPath(target, subpath))); } - return OkStatus(); + return absl::OkStatus(); } // Uses a GCS API command to copy the object and then deletes the old one. -Status GcsFileSystem::RenameObject(const string& src, const string& target) { +absl::Status GcsFileSystem::RenameObject(const string& src, + const string& target) { VLOG(3) << "RenameObject: started gs://" << src << " to " << target; string src_bucket, src_object, target_bucket, target_object; TF_RETURN_IF_ERROR(ParseGcsPath(src, false, &src_bucket, &src_object)); @@ -2041,15 +2048,15 @@ Status GcsFileSystem::RenameObject(const string& src, const string& target) { [this, &src]() { return DeleteFile(src, nullptr); }, retry_config_); } -Status GcsFileSystem::IsDirectory(const string& fname, - TransactionToken* token) { +absl::Status GcsFileSystem::IsDirectory(const string& fname, + TransactionToken* token) { string bucket, object; TF_RETURN_IF_ERROR(ParseGcsPath(fname, true, &bucket, &object)); if (object.empty()) { bool is_bucket; TF_RETURN_IF_ERROR(BucketExists(bucket, &is_bucket)); if (is_bucket) { - return OkStatus(); + return absl::OkStatus(); } return errors::NotFound("The specified bucket gs://", bucket, " was not found."); @@ -2057,7 +2064,7 @@ Status GcsFileSystem::IsDirectory(const string& fname, bool is_folder; TF_RETURN_IF_ERROR(FolderExists(fname, &is_folder)); if (is_folder) { - return OkStatus(); + return absl::OkStatus(); } bool is_object; TF_RETURN_IF_ERROR(ObjectExists(fname, bucket, object, &is_object)); @@ -2068,10 +2075,10 @@ Status GcsFileSystem::IsDirectory(const string& fname, return errors::NotFound("The specified path ", fname, " was not found."); } -Status GcsFileSystem::DeleteRecursively(const string& dirname, - TransactionToken* token, - int64_t* undeleted_files, - int64_t* undeleted_dirs) { +absl::Status GcsFileSystem::DeleteRecursively(const string& dirname, + TransactionToken* token, + int64_t* undeleted_files, + int64_t* undeleted_dirs) { if (!undeleted_files || !undeleted_dirs) { return errors::Internal( "'undeleted_files' and 'undeleted_dirs' cannot be nullptr."); @@ -2080,7 +2087,7 @@ Status GcsFileSystem::DeleteRecursively(const string& dirname, *undeleted_dirs = 0; if (!IsDirectory(dirname, token).ok()) { *undeleted_dirs = 1; - return Status( + return absl::Status( absl::StatusCode::kNotFound, strings::StrCat(dirname, " doesn't exist or not a directory.")); } @@ -2107,7 +2114,7 @@ Status GcsFileSystem::DeleteRecursively(const string& dirname, } } } - return OkStatus(); + return absl::OkStatus(); } // Flushes all caches for filesystem metadata and file contents. Useful for @@ -2149,7 +2156,8 @@ void GcsFileSystem::SetAuthProvider( // Creates an HttpRequest and sets several parameters that are common to all // requests. All code (in GcsFileSystem) that creates an HttpRequest should // go through this method, rather than directly using http_request_factory_. -Status GcsFileSystem::CreateHttpRequest(std::unique_ptr* request) { +absl::Status GcsFileSystem::CreateHttpRequest( + std::unique_ptr* request) { std::unique_ptr new_request{http_request_factory_->Create()}; if (dns_cache_) { dns_cache_->AnnotateRequest(new_request.get()); @@ -2178,7 +2186,7 @@ Status GcsFileSystem::CreateHttpRequest(std::unique_ptr* request) { } *request = std::move(new_request); - return OkStatus(); + return absl::OkStatus(); } RetryingGcsFileSystem::RetryingGcsFileSystem() diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.h index 17725e8d5b01e6..f7452a4eb69989 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system.h @@ -66,7 +66,7 @@ constexpr uint64 kDefaultMaxStaleness = 0; // Helper function to extract an environment variable and convert it into a // value of type T. template -bool GetEnvVar(const char* varname, bool (*convert)(StringPiece, T*), +bool GetEnvVar(const char* varname, bool (*convert)(absl::string_view, T*), T* value) { const char* env_value = std::getenv(varname); if (env_value == nullptr) { @@ -144,48 +144,54 @@ class GcsFileSystem : public FileSystem { TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT; - Status NewRandomAccessFile( + absl::Status NewRandomAccessFile( const string& fname, TransactionToken* token, std::unique_ptr* result) override; - Status NewWritableFile(const string& fname, TransactionToken* token, - std::unique_ptr* result) override; + absl::Status NewWritableFile(const string& fname, TransactionToken* token, + std::unique_ptr* result) override; - Status NewAppendableFile(const string& fname, TransactionToken* token, - std::unique_ptr* result) override; + absl::Status NewAppendableFile( + const string& fname, TransactionToken* token, + std::unique_ptr* result) override; - Status NewReadOnlyMemoryRegionFromFile( + absl::Status NewReadOnlyMemoryRegionFromFile( const string& fname, TransactionToken* token, std::unique_ptr* result) override; - Status FileExists(const string& fname, TransactionToken* token) override; + absl::Status FileExists(const string& fname, + TransactionToken* token) override; - Status Stat(const string& fname, TransactionToken* token, - FileStatistics* stat) override; + absl::Status Stat(const string& fname, TransactionToken* token, + FileStatistics* stat) override; - Status GetChildren(const string& dir, TransactionToken* token, - std::vector* result) override; + absl::Status GetChildren(const string& dir, TransactionToken* token, + std::vector* result) override; - Status GetMatchingPaths(const string& pattern, TransactionToken* token, - std::vector* results) override; + absl::Status GetMatchingPaths(const string& pattern, TransactionToken* token, + std::vector* results) override; - Status DeleteFile(const string& fname, TransactionToken* token) override; + absl::Status DeleteFile(const string& fname, + TransactionToken* token) override; - Status CreateDir(const string& dirname, TransactionToken* token) override; + absl::Status CreateDir(const string& dirname, + TransactionToken* token) override; - Status DeleteDir(const string& dirname, TransactionToken* token) override; + absl::Status DeleteDir(const string& dirname, + TransactionToken* token) override; - Status GetFileSize(const string& fname, TransactionToken* token, - uint64* file_size) override; + absl::Status GetFileSize(const string& fname, TransactionToken* token, + uint64* file_size) override; - Status RenameFile(const string& src, const string& target, - TransactionToken* token) override; + absl::Status RenameFile(const string& src, const string& target, + TransactionToken* token) override; - Status IsDirectory(const string& fname, TransactionToken* token) override; + absl::Status IsDirectory(const string& fname, + TransactionToken* token) override; - Status DeleteRecursively(const string& dirname, TransactionToken* token, - int64_t* undeleted_files, - int64_t* undeleted_dirs) override; + absl::Status DeleteRecursively(const string& dirname, TransactionToken* token, + int64_t* undeleted_files, + int64_t* undeleted_dirs) override; void FlushCaches(TransactionToken* token) override; @@ -267,7 +273,7 @@ class GcsFileSystem : public FileSystem { write(write) {} }; - Status CreateHttpRequest(std::unique_ptr* request); + absl::Status CreateHttpRequest(std::unique_ptr* request); /// \brief Sets a new AuthProvider on the GCS FileSystem. /// @@ -289,37 +295,38 @@ class GcsFileSystem : public FileSystem { size_t block_size, size_t max_bytes, uint64 max_staleness); /// Loads file contents from GCS for a given filename, offset, and length. - virtual Status LoadBufferFromGCS(const string& fname, size_t offset, size_t n, - char* buffer, size_t* bytes_transferred); + virtual absl::Status LoadBufferFromGCS(const string& fname, size_t offset, + size_t n, char* buffer, + size_t* bytes_transferred); // Creates an upload session for an upcoming GCS object upload. - virtual Status CreateNewUploadSession(uint64 start_offset, - const std::string& object_to_upload, - const std::string& bucket, - uint64 file_size, - const std::string& gcs_path, - UploadSessionHandle* session_handle); + virtual absl::Status CreateNewUploadSession( + uint64 start_offset, const std::string& object_to_upload, + const std::string& bucket, uint64 file_size, const std::string& gcs_path, + UploadSessionHandle* session_handle); // Uploads object data to session. - virtual Status UploadToSession(const std::string& session_uri, - uint64 start_offset, uint64 already_uploaded, - const std::string& tmp_content_filename, - uint64 file_size, - const std::string& file_path); + virtual absl::Status UploadToSession(const std::string& session_uri, + uint64 start_offset, + uint64 already_uploaded, + const std::string& tmp_content_filename, + uint64 file_size, + const std::string& file_path); /// \brief Requests status of a previously initiated upload session. /// /// If the upload has already succeeded, sets 'completed' to true. /// Otherwise sets 'completed' to false and 'uploaded' to the currently /// uploaded size in bytes. - virtual Status RequestUploadSessionStatus(const string& session_uri, - uint64 file_size, - const std::string& gcs_path, - bool* completed, uint64* uploaded); + virtual absl::Status RequestUploadSessionStatus(const string& session_uri, + uint64 file_size, + const std::string& gcs_path, + bool* completed, + uint64* uploaded); - Status ParseGcsPathForScheme(StringPiece fname, string scheme, - bool empty_object_ok, string* bucket, - string* object); + absl::Status ParseGcsPathForScheme(absl::string_view fname, string scheme, + bool empty_object_ok, string* bucket, + string* object); /// \brief Splits a GCS path to a bucket and an object. /// @@ -327,8 +334,9 @@ class GcsFileSystem : public FileSystem { /// "bucket-name" and "path/to/file.txt". /// If fname only contains the bucket and empty_object_ok = true, the returned /// object is empty. - virtual Status ParseGcsPath(StringPiece fname, bool empty_object_ok, - string* bucket, string* object); + virtual absl::Status ParseGcsPath(absl::string_view fname, + bool empty_object_ok, string* bucket, + string* object); std::shared_ptr compute_engine_metadata_client_; @@ -348,7 +356,7 @@ class GcsFileSystem : public FileSystem { /// \brief Checks if the bucket exists. Returns OK if the check succeeded. /// /// 'result' is set if the function returns OK. 'result' cannot be nullptr. - Status BucketExists(const string& bucket, bool* result); + absl::Status BucketExists(const string& bucket, bool* result); /// \brief Retrieves the GCS bucket location. Returns OK if the location was /// retrieved. @@ -359,28 +367,28 @@ class GcsFileSystem : public FileSystem { /// This requires the bucket metadata permission. /// Repeated calls for the same bucket are cached so this function can be /// called frequently without causing an extra API call - Status GetBucketLocation(const string& bucket, string* location); + absl::Status GetBucketLocation(const string& bucket, string* location); /// \brief Check if the GCS buckets location is allowed with the current /// constraint configuration - Status CheckBucketLocationConstraint(const string& bucket); + absl::Status CheckBucketLocationConstraint(const string& bucket); /// \brief Given the input bucket `bucket`, fills `result_buffer` with the /// results of the metadata. Returns OK if the API call succeeds without /// error. - Status GetBucketMetadata(const string& bucket, - std::vector* result_buffer); + absl::Status GetBucketMetadata(const string& bucket, + std::vector* result_buffer); /// \brief Checks if the object exists. Returns OK if the check succeeded. /// /// 'result' is set if the function returns OK. 'result' cannot be nullptr. - Status ObjectExists(const string& fname, const string& bucket, - const string& object, bool* result); + absl::Status ObjectExists(const string& fname, const string& bucket, + const string& object, bool* result); /// \brief Checks if the folder exists. Returns OK if the check succeeded. /// /// 'result' is set if the function returns OK. 'result' cannot be nullptr. - Status FolderExists(const string& dirname, bool* result); + absl::Status FolderExists(const string& dirname, bool* result); /// \brief Internal version of GetChildren with more knobs. /// @@ -390,19 +398,19 @@ class GcsFileSystem : public FileSystem { /// If 'include_self_directory_marker' is true and there is a GCS directory /// marker at the path 'dir', GetChildrenBound will return an empty string /// as one of the children that represents this marker. - Status GetChildrenBounded(const string& dir, uint64 max_results, - std::vector* result, bool recursively, - bool include_self_directory_marker); + absl::Status GetChildrenBounded(const string& dir, uint64 max_results, + std::vector* result, bool recursively, + bool include_self_directory_marker); /// Retrieves file statistics assuming fname points to a GCS object. The data /// may be read from cache or from GCS directly. - Status StatForObject(const string& fname, const string& bucket, - const string& object, GcsFileStat* stat); + absl::Status StatForObject(const string& fname, const string& bucket, + const string& object, GcsFileStat* stat); /// Retrieves file statistics of file fname directly from GCS. - Status UncachedStatForObject(const string& fname, const string& bucket, - const string& object, GcsFileStat* stat); + absl::Status UncachedStatForObject(const string& fname, const string& bucket, + const string& object, GcsFileStat* stat); - Status RenameObject(const string& src, const string& target); + absl::Status RenameObject(const string& src, const string& target); // Clear all the caches related to the file with name `filename`. void ClearFileCaches(const string& fname); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system_test.cc index d9c860fcb4f38a..9d9d3088467df0 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/gcs_file_system_test.cc @@ -45,17 +45,17 @@ static std::unordered_set* kAllowedLocationsAuto = class FakeAuthProvider : public AuthProvider { public: - Status GetToken(string* token) override { + absl::Status GetToken(string* token) override { *token = "fake_token"; - return OkStatus(); + return absl::OkStatus(); } }; class FakeZoneProvider : public ZoneProvider { public: - Status GetZone(string* zone) override { + absl::Status GetZone(string* zone) override { *zone = "us-east1-b"; - return OkStatus(); + return absl::OkStatus(); } }; @@ -88,12 +88,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_NoBlockCache) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[6]; - StringPiece result; + absl::string_view result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -135,12 +135,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[6]; - StringPiece result; + absl::string_view result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -183,12 +183,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_Errors) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[6]; - StringPiece result; + absl::string_view result; // Read the first chunk. EXPECT_TRUE( @@ -230,12 +230,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_ReadAtEOF) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[10]; - StringPiece result; + absl::string_view result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -271,12 +271,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_CachedOutOfRange) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[5]; - StringPiece result; + absl::string_view result; // Read the first chunk. Even though the backend response is out-of-range, // we should get a OK status since we're just reading the first 5 bytes. @@ -323,12 +323,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_CachedNotSequential) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[5]; - StringPiece result; + absl::string_view result; TF_EXPECT_OK(file->Read(1, sizeof(scratch), &result, scratch)); EXPECT_EQ("12345", result); @@ -365,12 +365,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_Growing) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[10]; - StringPiece result; + absl::string_view result; // Read the first chunk. Since the first read is out-of-range, // we don't cache the out-of-range flag and each subsequent read triggers a @@ -413,12 +413,12 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_ReadBackwards) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); - StringPiece filename; + absl::string_view filename; TF_EXPECT_OK(file->Name(&filename)); EXPECT_EQ(filename, "gs://bucket/random_access.txt"); char scratch[10]; - StringPiece result; + absl::string_view result; // Read the first chunk. EXPECT_TRUE( @@ -574,7 +574,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_NoBlockCache_DifferentN) { fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); char small_scratch[3]; - StringPiece result; + absl::string_view result; // Read the first chunk. TF_EXPECT_OK(file->Read(0, sizeof(small_scratch), &result, small_scratch)); @@ -629,7 +629,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache) { nullptr /* gcs additional header */, false /* compose append */); char scratch[100]; - StringPiece result; + absl::string_view result; { // We are instantiating this in an enclosed scope to make sure after the // unique ptr goes out of scope, we can still access result. @@ -716,7 +716,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache_Flush) { nullptr /* gcs additional header */, false /* compose append */); char scratch[100]; - StringPiece result; + absl::string_view result; std::unique_ptr file; TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); @@ -766,7 +766,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithBlockCache_MaxStaleness) { kTestTimeoutConfig, *kAllowedLocationsDefault, nullptr /* gcs additional header */, false /* compose append */); char scratch[100]; - StringPiece result; + absl::string_view result; // There should only be two HTTP requests issued to GCS even though we iterate // this loop 10 times. This shows that the underlying FileBlockCache persists // across file close/open boundaries. @@ -841,7 +841,7 @@ TEST(GcsFileSystemTest, fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); char scratch[5]; - StringPiece result; + absl::string_view result; // First read. TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); @@ -908,7 +908,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_InconsistentRead) { fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); char scratch[6]; - StringPiece result; + absl::string_view result; EXPECT_TRUE( errors::IsInternal(file->Read(0, sizeof(scratch), &result, scratch))); @@ -972,7 +972,7 @@ TEST(GcsFileSystemTest, NewWritableFile) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/path/writeable", nullptr, &rfile)); char scratch[100]; - StringPiece result; + absl::string_view result; TF_EXPECT_OK(rfile->Read(0, 4, &result, scratch)); EXPECT_EQ("0123", result); // Open the writable file. @@ -1107,7 +1107,7 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadSucceedsOnGetStatus) { "Timeouts: 5 1 10\n" "Header Content-Range: bytes */17\n" "Put: yes\n", - "", OkStatus(), nullptr, {}, 201), + "", absl::OkStatus(), nullptr, {}, 201), new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" "path%2Fwriteable?fields=size%2Cgeneration%2Cupdated\n" @@ -1138,7 +1138,7 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadSucceedsOnGetStatus) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/path/writeable", nullptr, &rfile)); char scratch[100]; - StringPiece result; + absl::string_view result; TF_EXPECT_OK(rfile->Read(0, 4, &result, scratch)); EXPECT_EQ("0123", result); // Now write to the same file. Once the write succeeds, the cached block will @@ -1402,7 +1402,7 @@ TEST(GcsFileSystemTest, NewAppendableFile) { TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/path/appendable", nullptr, &rfile)); char scratch[100]; - StringPiece result; + absl::string_view result; TF_EXPECT_OK(rfile->Read(0, 8, &result, scratch)); EXPECT_EQ("content1", result); // Closing the appendable file will flush its contents to GCS, triggering HTTP @@ -1496,8 +1496,9 @@ TEST(GcsFileSystemTest, NewReadOnlyMemoryRegionFromFile) { TF_EXPECT_OK(fs.NewReadOnlyMemoryRegionFromFile( "gs://bucket/path/random_access.txt", nullptr, ®ion)); - EXPECT_EQ(content, StringPiece(reinterpret_cast(region->data()), - region->length())); + EXPECT_EQ(content, + absl::string_view(reinterpret_cast(region->data()), + region->length())); } TEST(GcsFileSystemTest, NewReadOnlyMemoryRegionFromFile_NoObjectName) { @@ -2262,7 +2263,7 @@ TEST(GcsFileSystemTest, DeleteFile) { // Do an initial read of the file to load its contents into the block cache. char scratch[100]; - StringPiece result; + absl::string_view result; std::unique_ptr file; TF_EXPECT_OK( fs.NewRandomAccessFile("gs://bucket/path/file1.txt", nullptr, &file)); @@ -2656,7 +2657,7 @@ TEST(GcsFileSystemTest, RenameFile_Object) { // Do an initial read of the source and destination files to load their // contents into the block cache. char scratch[100]; - StringPiece result; + absl::string_view result; std::unique_ptr src; std::unique_ptr dst; TF_EXPECT_OK( @@ -3798,7 +3799,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_StatsRecording) { fs.NewRandomAccessFile("gs://bucket/random_access.txt", nullptr, &file)); char scratch[6]; - StringPiece result; + absl::string_view result; TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); EXPECT_EQ("012345", result); diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.cc index f1b62fb0b26c9b..7f1f94dc778e1e 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.cc @@ -82,7 +82,7 @@ bool IsFile(const string& filename) { } /// Returns the credentials file name from the env variable. -Status GetEnvironmentVariableFileName(string* filename) { +absl::Status GetEnvironmentVariableFileName(string* filename) { if (!filename) { return errors::FailedPrecondition("'filename' cannot be nullptr."); } @@ -92,11 +92,11 @@ Status GetEnvironmentVariableFileName(string* filename) { " is not set or corrupt.")); } *filename = result; - return OkStatus(); + return absl::OkStatus(); } /// Returns the well known file produced by command 'gcloud auth login'. -Status GetWellKnownFileName(string* filename) { +absl::Status GetWellKnownFileName(string* filename) { if (!filename) { return errors::FailedPrecondition("'filename' cannot be nullptr."); } @@ -118,7 +118,7 @@ Status GetWellKnownFileName(string* filename) { "Could not find the credentials file in the standard gcloud location."); } *filename = result; - return OkStatus(); + return absl::OkStatus(); } } // namespace @@ -138,42 +138,42 @@ GoogleAuthProvider::GoogleAuthProvider( std::move(compute_engine_metadata_client)), env_(env) {} -Status GoogleAuthProvider::GetToken(string* t) { +absl::Status GoogleAuthProvider::GetToken(string* t) { mutex_lock lock(mu_); const uint64 now_sec = env_->NowSeconds(); if (now_sec + kExpirationTimeMarginSec < expiration_timestamp_sec_) { *t = current_token_; - return OkStatus(); + return absl::OkStatus(); } if (GetTokenForTesting().ok()) { *t = current_token_; - return OkStatus(); + return absl::OkStatus(); } auto token_from_files_status = GetTokenFromFiles(); if (token_from_files_status.ok()) { *t = current_token_; - return OkStatus(); + return absl::OkStatus(); } char* no_gce_check_var = std::getenv(kNoGceCheck); bool skip_gce_check = no_gce_check_var != nullptr && absl::EqualsIgnoreCase(no_gce_check_var, "true"); - Status token_from_gce_status; + absl::Status token_from_gce_status; if (skip_gce_check) { token_from_gce_status = - Status(absl::StatusCode::kCancelled, - strings::StrCat("GCE check skipped due to presence of $", - kNoGceCheck, " environment variable.")); + absl::Status(absl::StatusCode::kCancelled, + strings::StrCat("GCE check skipped due to presence of $", + kNoGceCheck, " environment variable.")); } else { token_from_gce_status = GetTokenFromGce(); } if (token_from_gce_status.ok()) { *t = current_token_; - return OkStatus(); + return absl::OkStatus(); } if (skip_gce_check) { @@ -203,10 +203,10 @@ Status GoogleAuthProvider::GetToken(string* t) { } current_token_ = ""; - return OkStatus(); + return absl::OkStatus(); } -Status GoogleAuthProvider::GetTokenFromFiles() { +absl::Status GoogleAuthProvider::GetTokenFromFiles() { string credentials_filename; if (!GetEnvironmentVariableFileName(&credentials_filename).ok() && !GetWellKnownFileName(&credentials_filename).ok()) { @@ -231,33 +231,33 @@ Status GoogleAuthProvider::GetTokenFromFiles() { return errors::FailedPrecondition( "Unexpected content of the JSON credentials file."); } - return OkStatus(); + return absl::OkStatus(); } -Status GoogleAuthProvider::GetTokenFromGce() { +absl::Status GoogleAuthProvider::GetTokenFromGce() { std::vector response_buffer; const uint64 request_timestamp_sec = env_->NowSeconds(); TF_RETURN_IF_ERROR(compute_engine_metadata_client_->GetMetadata( kGceTokenPath, &response_buffer)); - StringPiece response = - StringPiece(&response_buffer[0], response_buffer.size()); + absl::string_view response = + absl::string_view(&response_buffer[0], response_buffer.size()); TF_RETURN_IF_ERROR(oauth_client_->ParseOAuthResponse( response, request_timestamp_sec, ¤t_token_, &expiration_timestamp_sec_)); - return OkStatus(); + return absl::OkStatus(); } -Status GoogleAuthProvider::GetTokenForTesting() { +absl::Status GoogleAuthProvider::GetTokenForTesting() { const char* token = std::getenv(kGoogleAuthTokenForTesting); if (!token) { return errors::NotFound("The env variable for testing was not set."); } expiration_timestamp_sec_ = UINT64_MAX; current_token_ = token; - return OkStatus(); + return absl::OkStatus(); } } // namespace tsl diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.h index 63b7ea63abf5f3..38ab66df63c25c 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider.h @@ -40,20 +40,20 @@ class GoogleAuthProvider : public AuthProvider { /// \brief Returns the short-term authentication bearer token. /// /// Safe for concurrent use by multiple threads. - Status GetToken(string* token) override; + absl::Status GetToken(string* token) override; private: /// \brief Gets the bearer token from files. /// /// Tries the file from $GOOGLE_APPLICATION_CREDENTIALS and the /// standard gcloud tool's location. - Status GetTokenFromFiles() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); + absl::Status GetTokenFromFiles() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); /// Gets the bearer token from Google Compute Engine environment. - Status GetTokenFromGce() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); + absl::Status GetTokenFromGce() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); /// Gets the bearer token from the system env variable, for testing purposes. - Status GetTokenForTesting() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); + absl::Status GetTokenForTesting() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); std::unique_ptr oauth_client_; std::shared_ptr compute_engine_metadata_client_; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider_test.cc index 6b17f76cb0cd6c..e7d6c4aab68634 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/google_auth_provider_test.cc @@ -40,23 +40,24 @@ class FakeEnv : public EnvWrapper { class FakeOAuthClient : public OAuthClient { public: - Status GetTokenFromServiceAccountJson( - Json::Value json, StringPiece oauth_server_uri, StringPiece scope, - string* token, uint64* expiration_timestamp_sec) override { + absl::Status GetTokenFromServiceAccountJson( + Json::Value json, absl::string_view oauth_server_uri, + absl::string_view scope, string* token, + uint64* expiration_timestamp_sec) override { provided_credentials_json = json; *token = return_token; *expiration_timestamp_sec = return_expiration_timestamp; - return OkStatus(); + return absl::OkStatus(); } /// Retrieves a bearer token using a refresh token. - Status GetTokenFromRefreshTokenJson( - Json::Value json, StringPiece oauth_server_uri, string* token, + absl::Status GetTokenFromRefreshTokenJson( + Json::Value json, absl::string_view oauth_server_uri, string* token, uint64* expiration_timestamp_sec) override { provided_credentials_json = json; *token = return_token; *expiration_timestamp_sec = return_expiration_timestamp; - return OkStatus(); + return absl::OkStatus(); } string return_token; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request.h index a3a3136d66e6f7..8102dd666a7c08 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request.h @@ -85,7 +85,8 @@ class HttpRequest { /// RecordResponse is called after the response has been received. virtual void RecordResponse(const HttpRequest* request, const string& uri, - RequestMethod method, const Status& result) = 0; + RequestMethod method, + const absl::Status& result) = 0; }; HttpRequest() {} @@ -124,7 +125,8 @@ class HttpRequest { /// /// The request body will be taken from the specified file starting from /// the given offset. - virtual Status SetPutFromFile(const string& body_filepath, size_t offset) = 0; + virtual absl::Status SetPutFromFile(const string& body_filepath, + size_t offset) = 0; /// Makes the request a PUT request with an empty body. virtual void SetPutEmptyBody() = 0; @@ -169,7 +171,7 @@ class HttpRequest { /// /// If the result buffer was defined, the response will be written there. /// The object is not designed to be re-used after Send() is executed. - virtual Status Send() = 0; + virtual absl::Status Send() = 0; // Url encodes str and returns a new string. virtual string EscapeString(const string& str) = 0; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request_fake.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request_fake.h index da8742ae3f0f5a..869d2abca6ee70 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request_fake.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/http_request_fake.h @@ -38,12 +38,13 @@ class FakeHttpRequest : public CurlHttpRequest { public: /// Return the response for the given request. FakeHttpRequest(const string& request, const string& response) - : FakeHttpRequest(request, response, OkStatus(), nullptr, {}, 200) {} + : FakeHttpRequest(request, response, absl::OkStatus(), nullptr, {}, 200) { + } /// Return the response with headers for the given request. FakeHttpRequest(const string& request, const string& response, const std::map& response_headers) - : FakeHttpRequest(request, response, OkStatus(), nullptr, + : FakeHttpRequest(request, response, absl::OkStatus(), nullptr, response_headers, 200) {} /// \brief Return the response for the request and capture the POST body. @@ -51,12 +52,12 @@ class FakeHttpRequest : public CurlHttpRequest { /// Post body is not expected to be a part of the 'request' parameter. FakeHttpRequest(const string& request, const string& response, string* captured_post_body) - : FakeHttpRequest(request, response, OkStatus(), captured_post_body, {}, - 200) {} + : FakeHttpRequest(request, response, absl::OkStatus(), captured_post_body, + {}, 200) {} /// \brief Return the response and the status for the given request. FakeHttpRequest(const string& request, const string& response, - Status response_status, uint64 response_code) + absl::Status response_status, uint64 response_code) : FakeHttpRequest(request, response, response_status, nullptr, {}, response_code) {} @@ -65,7 +66,7 @@ class FakeHttpRequest : public CurlHttpRequest { /// /// Post body is not expected to be a part of the 'request' parameter. FakeHttpRequest(const string& request, const string& response, - Status response_status, string* captured_post_body, + absl::Status response_status, string* captured_post_body, const std::map& response_headers, uint64 response_code) : expected_request_(request), @@ -88,20 +89,21 @@ class FakeHttpRequest : public CurlHttpRequest { actual_request_ += "Auth Token: " + auth_token + "\n"; } void SetDeleteRequest() override { actual_request_ += "Delete: yes\n"; } - Status SetPutFromFile(const string& body_filepath, size_t offset) override { + absl::Status SetPutFromFile(const string& body_filepath, + size_t offset) override { std::ifstream stream(body_filepath); const string& content = string(std::istreambuf_iterator(stream), std::istreambuf_iterator()) .substr(offset); actual_request_ += "Put body: " + content + "\n"; - return OkStatus(); + return absl::OkStatus(); } void SetPostFromBuffer(const char* buffer, size_t size) override { if (captured_post_body_) { *captured_post_body_ = string(buffer, size); } else { actual_request_ += - strings::StrCat("Post body: ", StringPiece(buffer, size), "\n"); + strings::StrCat("Post body: ", absl::string_view(buffer, size), "\n"); } } void SetPutEmptyBody() override { actual_request_ += "Put: yes\n"; } @@ -123,7 +125,7 @@ class FakeHttpRequest : public CurlHttpRequest { size_t GetResultBufferDirectBytesTransferred() override { return direct_result_bytes_transferred_; } - Status Send() override { + absl::Status Send() override { EXPECT_EQ(expected_request_, actual_request()) << "Unexpected HTTP request."; if (buffer_) { @@ -182,7 +184,7 @@ class FakeHttpRequest : public CurlHttpRequest { string actual_uri_; string actual_request_; string response_; - Status response_status_; + absl::Status response_status_; string* captured_post_body_ = nullptr; std::map response_headers_; uint64 response_code_ = 0; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.cc index c983577204b436..74806805abea51 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.cc @@ -49,8 +49,8 @@ constexpr char kJwtType[] = "JWT"; constexpr char kGrantType[] = "urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer"; -Status ReadJsonValue(const Json::Value& json, const string& name, - Json::Value* value) { +absl::Status ReadJsonValue(const Json::Value& json, const string& name, + Json::Value* value) { if (!value) { return errors::FailedPrecondition("'value' cannot be nullptr."); } @@ -59,11 +59,11 @@ Status ReadJsonValue(const Json::Value& json, const string& name, return errors::FailedPrecondition( strings::StrCat("Couldn't read a JSON value '", name, "'.")); } - return OkStatus(); + return absl::OkStatus(); } -Status ReadJsonString(const Json::Value& json, const string& name, - string* value) { +absl::Status ReadJsonString(const Json::Value& json, const string& name, + string* value) { Json::Value json_value; TF_RETURN_IF_ERROR(ReadJsonValue(json, name, &json_value)); if (!json_value.isString()) { @@ -71,11 +71,11 @@ Status ReadJsonString(const Json::Value& json, const string& name, strings::StrCat("JSON value '", name, "' is not string.")); } *value = json_value.asString(); - return OkStatus(); + return absl::OkStatus(); } -Status ReadJsonInt(const Json::Value& json, const string& name, - int64_t* value) { +absl::Status ReadJsonInt(const Json::Value& json, const string& name, + int64_t* value) { Json::Value json_value; TF_RETURN_IF_ERROR(ReadJsonValue(json, name, &json_value)); if (!json_value.isIntegral()) { @@ -83,11 +83,11 @@ Status ReadJsonInt(const Json::Value& json, const string& name, strings::StrCat("JSON value '", name, "' is not integer.")); } *value = json_value.asInt64(); - return OkStatus(); + return absl::OkStatus(); } -Status CreateSignature(RSA* private_key, StringPiece to_sign, - string* signature) { +absl::Status CreateSignature(RSA* private_key, absl::string_view to_sign, + string* signature) { if (!private_key || !signature) { return errors::FailedPrecondition( "'private_key' and 'signature' cannot be nullptr."); @@ -126,14 +126,15 @@ Status CreateSignature(RSA* private_key, StringPiece to_sign, if (EVP_DigestSignFinal(md_ctx.get(), sig.get(), &sig_len) != 1) { return errors::Internal("DigestFinal (signature compute) failed."); } - return Base64Encode(StringPiece(reinterpret_cast(sig.get()), sig_len), - signature); + return Base64Encode( + absl::string_view(reinterpret_cast(sig.get()), sig_len), + signature); } /// Encodes a claim for a JSON web token (JWT) to make an OAuth request. -Status EncodeJwtClaim(StringPiece client_email, StringPiece scope, - StringPiece audience, uint64 request_timestamp_sec, - string* encoded) { +absl::Status EncodeJwtClaim(absl::string_view client_email, + absl::string_view scope, absl::string_view audience, + uint64 request_timestamp_sec, string* encoded) { // Step 1: create the JSON with the claim. Json::Value root; root["iss"] = Json::Value(client_email.data(), @@ -155,7 +156,7 @@ Status EncodeJwtClaim(StringPiece client_email, StringPiece scope, } /// Encodes a header for a JSON web token (JWT) to make an OAuth request. -Status EncodeJwtHeader(StringPiece key_id, string* encoded) { +absl::Status EncodeJwtHeader(absl::string_view key_id, string* encoded) { // Step 1: create the JSON with the header. Json::Value root; root["alg"] = kCryptoAlgorithm; @@ -180,9 +181,9 @@ OAuthClient::OAuthClient( std::unique_ptr http_request_factory, Env* env) : http_request_factory_(std::move(http_request_factory)), env_(env) {} -Status OAuthClient::GetTokenFromServiceAccountJson( - Json::Value json, StringPiece oauth_server_uri, StringPiece scope, - string* token, uint64* expiration_timestamp_sec) { +absl::Status OAuthClient::GetTokenFromServiceAccountJson( + Json::Value json, absl::string_view oauth_server_uri, + absl::string_view scope, string* token, uint64* expiration_timestamp_sec) { if (!token || !expiration_timestamp_sec) { return errors::FailedPrecondition( "'token' and 'expiration_timestamp_sec' cannot be nullptr."); @@ -228,15 +229,15 @@ Status OAuthClient::GetTokenFromServiceAccountJson( request->SetResultBuffer(&response_buffer); TF_RETURN_IF_ERROR(request->Send()); - StringPiece response = - StringPiece(response_buffer.data(), response_buffer.size()); + absl::string_view response = + absl::string_view(response_buffer.data(), response_buffer.size()); TF_RETURN_IF_ERROR(ParseOAuthResponse(response, request_timestamp_sec, token, expiration_timestamp_sec)); - return OkStatus(); + return absl::OkStatus(); } -Status OAuthClient::GetTokenFromRefreshTokenJson( - Json::Value json, StringPiece oauth_server_uri, string* token, +absl::Status OAuthClient::GetTokenFromRefreshTokenJson( + Json::Value json, absl::string_view oauth_server_uri, string* token, uint64* expiration_timestamp_sec) { if (!token || !expiration_timestamp_sec) { return errors::FailedPrecondition( @@ -260,17 +261,17 @@ Status OAuthClient::GetTokenFromRefreshTokenJson( request->SetResultBuffer(&response_buffer); TF_RETURN_IF_ERROR(request->Send()); - StringPiece response = - StringPiece(response_buffer.data(), response_buffer.size()); + absl::string_view response = + absl::string_view(response_buffer.data(), response_buffer.size()); TF_RETURN_IF_ERROR(ParseOAuthResponse(response, request_timestamp_sec, token, expiration_timestamp_sec)); - return OkStatus(); + return absl::OkStatus(); } -Status OAuthClient::ParseOAuthResponse(StringPiece response, - uint64 request_timestamp_sec, - string* token, - uint64* expiration_timestamp_sec) { +absl::Status OAuthClient::ParseOAuthResponse(absl::string_view response, + uint64 request_timestamp_sec, + string* token, + uint64* expiration_timestamp_sec) { if (!token || !expiration_timestamp_sec) { return errors::FailedPrecondition( "'token' and 'expiration_timestamp_sec' cannot be nullptr."); @@ -292,7 +293,7 @@ Status OAuthClient::ParseOAuthResponse(StringPiece response, *expiration_timestamp_sec = request_timestamp_sec + expires_in; TF_RETURN_IF_ERROR(ReadJsonString(root, "access_token", token)); - return OkStatus(); + return absl::OkStatus(); } } // namespace tsl diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.h index 895c2d01cd5f8f..19d8b4fb1589c2 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client.h @@ -37,20 +37,20 @@ class OAuthClient { /// /// Retrieves the authentication bearer token using a JSON file /// with the client's private key. - virtual Status GetTokenFromServiceAccountJson( - Json::Value json, StringPiece oauth_server_uri, StringPiece scope, - string* token, uint64* expiration_timestamp_sec); + virtual absl::Status GetTokenFromServiceAccountJson( + Json::Value json, absl::string_view oauth_server_uri, + absl::string_view scope, string* token, uint64* expiration_timestamp_sec); /// Retrieves a bearer token using a refresh token. - virtual Status GetTokenFromRefreshTokenJson(Json::Value json, - StringPiece oauth_server_uri, - string* token, - uint64* expiration_timestamp_sec); + virtual absl::Status GetTokenFromRefreshTokenJson( + Json::Value json, absl::string_view oauth_server_uri, string* token, + uint64* expiration_timestamp_sec); /// Parses the JSON response with the token from an OAuth 2.0 server. - virtual Status ParseOAuthResponse(StringPiece response, - uint64 request_timestamp_sec, string* token, - uint64* expiration_timestamp_sec); + virtual absl::Status ParseOAuthResponse(absl::string_view response, + uint64 request_timestamp_sec, + string* token, + uint64* expiration_timestamp_sec); private: std::unique_ptr http_request_factory_; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client_test.cc index 74b2f52220cc02..dc4c116583b400 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/oauth_client_test.cc @@ -118,7 +118,7 @@ TEST(OAuthClientTest, GetTokenFromServiceAccountJson) { EXPECT_EQ(13920, expiration_timestamp); // Now look at the JWT claim that was sent to the OAuth server. - StringPiece grant_type, assertion; + absl::string_view grant_type, assertion; ASSERT_TRUE(strings::Scanner(post_body) .OneLiteral("grant_type=") .RestartCapture() diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.cc index f16ab818b92687..57330d1ad30afe 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.cc @@ -68,12 +68,12 @@ void RamFileBlockCache::Trim() { } /// Move the block to the front of the LRU list if it isn't already there. -Status RamFileBlockCache::UpdateLRU(const Key& key, - const std::shared_ptr& block) { +absl::Status RamFileBlockCache::UpdateLRU(const Key& key, + const std::shared_ptr& block) { mutex_lock lock(mu_); if (block->timestamp == 0) { // The block was evicted from another thread. Allow it to remain evicted. - return OkStatus(); + return absl::OkStatus(); } if (block->lru_iterator != lru_list_.begin()) { lru_list_.erase(block->lru_iterator); @@ -95,11 +95,11 @@ Status RamFileBlockCache::UpdateLRU(const Key& key, Trim(); - return OkStatus(); + return absl::OkStatus(); } -Status RamFileBlockCache::MaybeFetch(const Key& key, - const std::shared_ptr& block) { +absl::Status RamFileBlockCache::MaybeFetch( + const Key& key, const std::shared_ptr& block) { bool downloaded_block = false; auto reconcile_state = absl::MakeCleanup([this, &downloaded_block, &key, &block] { @@ -123,7 +123,7 @@ Status RamFileBlockCache::MaybeFetch(const Key& key, // Loop until either block content is successfully fetched, or our request // encounters an error. mutex_lock l(block->mu); - Status status = OkStatus(); + absl::Status status = absl::OkStatus(); while (true) { switch (block->state) { case FetchState::ERROR: @@ -155,23 +155,24 @@ Status RamFileBlockCache::MaybeFetch(const Key& key, case FetchState::FETCHING: block->cond_var.wait_for(l, std::chrono::seconds(60)); if (block->state == FetchState::FINISHED) { - return OkStatus(); + return absl::OkStatus(); } // Re-loop in case of errors. break; case FetchState::FINISHED: - return OkStatus(); + return absl::OkStatus(); } } return errors::Internal( "Control flow should never reach the end of RamFileBlockCache::Fetch."); } -Status RamFileBlockCache::Read(const string& filename, size_t offset, size_t n, - char* buffer, size_t* bytes_transferred) { +absl::Status RamFileBlockCache::Read(const string& filename, size_t offset, + size_t n, char* buffer, + size_t* bytes_transferred) { *bytes_transferred = 0; if (n == 0) { - return OkStatus(); + return absl::OkStatus(); } if (!IsCacheEnabled() || (n > max_bytes_)) { // The cache is effectively disabled, so we pass the read through to the @@ -226,7 +227,7 @@ Status RamFileBlockCache::Read(const string& filename, size_t offset, size_t n, } } *bytes_transferred = total_bytes_transferred; - return OkStatus(); + return absl::OkStatus(); } bool RamFileBlockCache::ValidateAndUpdateFileSignature(const string& filename, diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.h index 76cf7eb237dc53..627cf6f2c808fa 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache.h @@ -45,9 +45,9 @@ class RamFileBlockCache : public FileBlockCache { /// cache is constructed. The returned Status should be OK as long as the /// read from the remote filesystem succeeded (similar to the semantics of the /// read(2) system call). - typedef std::function + typedef std::function BlockFetcher; RamFileBlockCache(size_t block_size, size_t max_bytes, uint64 max_staleness, @@ -88,8 +88,8 @@ class RamFileBlockCache : public FileBlockCache { /// placed in `out`. /// 4) OK otherwise (i.e. the read succeeded, and at least one byte was placed /// in `out`). - Status Read(const string& filename, size_t offset, size_t n, char* buffer, - size_t* bytes_transferred) override; + absl::Status Read(const string& filename, size_t offset, size_t n, + char* buffer, size_t* bytes_transferred) override; // Validate the given file signature with the existing file signature in the // cache. Returns true if the signature doesn't change or the file doesn't @@ -197,14 +197,14 @@ class RamFileBlockCache : public FileBlockCache { /// Look up a Key in the block cache. std::shared_ptr Lookup(const Key& key) TF_LOCKS_EXCLUDED(mu_); - Status MaybeFetch(const Key& key, const std::shared_ptr& block) + absl::Status MaybeFetch(const Key& key, const std::shared_ptr& block) TF_LOCKS_EXCLUDED(mu_); /// Trim the block cache to make room for another entry. void Trim() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); /// Update the LRU iterator for the block at `key`. - Status UpdateLRU(const Key& key, const std::shared_ptr& block) + absl::Status UpdateLRU(const Key& key, const std::shared_ptr& block) TF_LOCKS_EXCLUDED(mu_); /// Remove all blocks of a file, with mu_ already held. diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache_test.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache_test.cc index 8ae1fe1b453bc2..cc716011a9b26e 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache_test.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/ram_file_block_cache_test.cc @@ -27,12 +27,12 @@ limitations under the License. namespace tsl { namespace { -Status ReadCache(RamFileBlockCache* cache, const string& filename, - size_t offset, size_t n, std::vector* out) { +absl::Status ReadCache(RamFileBlockCache* cache, const string& filename, + size_t offset, size_t n, std::vector* out) { out->clear(); out->resize(n, 0); size_t bytes_transferred = 0; - Status status = + absl::Status status = cache->Read(filename, offset, n, out->data(), &bytes_transferred); EXPECT_LE(bytes_transferred, n); out->resize(bytes_transferred, n); @@ -43,7 +43,7 @@ TEST(RamFileBlockCacheTest, IsCacheEnabled) { auto fetcher = [](const string& filename, size_t offset, size_t n, char* buffer, size_t* bytes_transferred) { // Do nothing. - return OkStatus(); + return absl::OkStatus(); }; RamFileBlockCache cache1(0, 0, 0, fetcher); RamFileBlockCache cache2(16, 0, 0, fetcher); @@ -63,7 +63,7 @@ TEST(RamFileBlockCacheTest, ValidateAndUpdateFileSignature) { calls++; memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; string filename = "file"; RamFileBlockCache cache(16, 32, 0, fetcher); @@ -99,7 +99,7 @@ TEST(RamFileBlockCacheTest, PassThrough) { calls++; memset(buffer, 'x', got_n); *bytes_transferred = got_n; - return OkStatus(); + return absl::OkStatus(); }; // If block_size, max_bytes, or both are zero, or want_n is larger than // max_bytes the cache is a pass-through. @@ -136,7 +136,7 @@ TEST(RamFileBlockCacheTest, BlockAlignment) { } else { *bytes_transferred = 0; } - return OkStatus(); + return absl::OkStatus(); }; for (size_t block_size = 2; block_size <= 4; block_size++) { // Make a cache of N-byte block size (1 block) and verify that reads of @@ -181,7 +181,7 @@ TEST(RamFileBlockCacheTest, CacheHits) { calls.insert(offset); memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; const uint32 block_count = 256; RamFileBlockCache cache(block_size, block_count * block_size, 0, fetcher); @@ -222,7 +222,7 @@ TEST(RamFileBlockCacheTest, OutOfRange) { second_block = true; } *bytes_transferred = bytes_to_copy; - return OkStatus(); + return absl::OkStatus(); }; RamFileBlockCache cache(block_size, block_size, 0, fetcher); std::vector out; @@ -233,7 +233,7 @@ TEST(RamFileBlockCacheTest, OutOfRange) { // Reading at offset file_size + 4 will read the second block (since the read // at file_size + 4 = 28 will be aligned to an offset of 16) but will return // OutOfRange because the offset is past the end of the 24-byte file. - Status status = ReadCache(&cache, "", file_size + 4, 4, &out); + absl::Status status = ReadCache(&cache, "", file_size + 4, 4, &out); EXPECT_EQ(status.code(), error::OUT_OF_RANGE); EXPECT_TRUE(second_block); // Reading the second full block will return 8 bytes, from a cache hit. @@ -255,7 +255,7 @@ TEST(RamFileBlockCacheTest, Inconsistent) { EXPECT_GE(n, 1); memset(buffer, 'x', 1); *bytes_transferred = 1; - return OkStatus(); + return absl::OkStatus(); }; RamFileBlockCache cache(block_size, 2 * block_size, 0, fetcher); std::vector out; @@ -264,7 +264,7 @@ TEST(RamFileBlockCacheTest, Inconsistent) { EXPECT_EQ(out.size(), 1); // Now read the first block; this should yield an INTERNAL error because we // had already cached a partial block at a later position. - Status status = ReadCache(&cache, "", 0, block_size, &out); + absl::Status status = ReadCache(&cache, "", 0, block_size, &out); EXPECT_EQ(status.code(), error::INTERNAL); } @@ -282,7 +282,7 @@ TEST(RamFileBlockCacheTest, LRU) { } memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; const uint32 block_count = 2; RamFileBlockCache cache(block_size, block_count * block_size, 0, fetcher); @@ -324,7 +324,7 @@ TEST(RamFileBlockCacheTest, MaxStaleness) { calls++; memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; std::vector out; std::unique_ptr env(new NowSecondsEnv); @@ -369,7 +369,7 @@ TEST(RamFileBlockCacheTest, RemoveFile) { } memset(buffer, c, n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; // This cache has space for 4 blocks; we'll read from two files. const size_t n = 3; @@ -426,7 +426,7 @@ TEST(RamFileBlockCacheTest, Prune) { calls++; memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; std::vector out; // Our fake environment is initialized with the current timestamp. @@ -493,7 +493,7 @@ TEST(RamFileBlockCacheTest, ParallelReads) { } memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; const int block_size = 8; RamFileBlockCache cache(block_size, 2 * callers * block_size, 0, fetcher); @@ -529,7 +529,7 @@ TEST(RamFileBlockCacheTest, CoalesceConcurrentReads) { notification.Notify(); // Wait for other thread to issue read. Env::Default()->SleepForMicroseconds(100000); // 0.1 secs - return OkStatus(); + return absl::OkStatus(); }; RamFileBlockCache cache(block_size, block_size, 0, fetcher); // Fork off thread for parallel read. @@ -554,7 +554,7 @@ TEST(RamFileBlockCacheTest, Flush) { calls++; memset(buffer, 'x', n); *bytes_transferred = n; - return OkStatus(); + return absl::OkStatus(); }; RamFileBlockCache cache(16, 32, 0, fetcher); std::vector out; diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.cc b/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.cc index fecba6b1c8f742..62f8258bbf3ec0 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.cc +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.cc @@ -34,7 +34,7 @@ constexpr int64_t kNanosecondsPerSecond = 1000 * 1000 * 1000; // Only implements one special case of RFC 3339 which is returned by // GCS API, e.g 2016-04-29T23:15:24.896Z. -Status ParseRfc3339Time(const string& time, int64_t* mtime_nsec) { +absl::Status ParseRfc3339Time(const string& time, int64_t* mtime_nsec) { tm parsed{0}; float seconds; if (sscanf(time.c_str(), "%4d-%2d-%2dT%2d:%2d:%fZ", &(parsed.tm_year), @@ -52,7 +52,7 @@ Status ParseRfc3339Time(const string& time, int64_t* mtime_nsec) { static_cast(std::floor((seconds - int_seconds) * kNanosecondsPerSecond)); - return OkStatus(); + return absl::OkStatus(); } } // namespace tsl diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.h index 5eb116c6aca75d..4dd2d29ff15772 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/time_util.h @@ -22,7 +22,7 @@ namespace tsl { /// Parses the timestamp in RFC 3339 format and returns it /// as nanoseconds since epoch. -Status ParseRfc3339Time(const string& time, int64_t* mtime_nsec); +absl::Status ParseRfc3339Time(const string& time, int64_t* mtime_nsec); } // namespace tsl diff --git a/third_party/xla/third_party/tsl/tsl/platform/cloud/zone_provider.h b/third_party/xla/third_party/tsl/tsl/platform/cloud/zone_provider.h index 8c000e08437d4e..14b64ea9955aae 100644 --- a/third_party/xla/third_party/tsl/tsl/platform/cloud/zone_provider.h +++ b/third_party/xla/third_party/tsl/tsl/platform/cloud/zone_provider.h @@ -34,9 +34,9 @@ class ZoneProvider { /// Returns an empty string in the case where the zone does not match the /// expected format /// Safe for concurrent use by multiple threads. - virtual Status GetZone(string* zone) = 0; + virtual absl::Status GetZone(string* zone) = 0; - static Status GetZone(ZoneProvider* provider, string* zone) { + static absl::Status GetZone(ZoneProvider* provider, string* zone) { if (!provider) { return errors::Internal("Zone provider is required."); }