mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 01:20:39 +00:00
gcs_client: add object_exists helper
Introduce `object_exists` to the GCS client to check whether an object exists. This is primarily useful for test scenarios.
This commit is contained in:
@@ -1156,6 +1156,25 @@ seekable_data_source utils::gcp::storage::client::create_download_source(std::st
|
||||
return seekable_data_source(std::make_unique<object_data_source>(_impl, bucket, object_name, as));
|
||||
}
|
||||
|
||||
future<bool> storage::client::object_exists(std::string_view bucket, std::string_view object_name, seastar::abort_source* as) const {
|
||||
gcp_storage.debug("Get object metadata {}:{}", bucket, object_name);
|
||||
|
||||
auto path = fmt::format("/storage/v1/b/{}/o/{}", bucket, seastar::http::internal::url_encode(object_name));
|
||||
try {
|
||||
auto res = co_await _impl->send_with_retry(path, GCP_OBJECT_SCOPE_READ_ONLY, ""s, ""s, httpclient::method_type::GET, {}, as);
|
||||
if (res.result() != status_type::ok) {
|
||||
throw failed_operation(
|
||||
fmt::format("Could not retrieve object metadata {}:{}: {} ({})", bucket, object_name, res.result(), get_gcp_error_message(res.body())));
|
||||
}
|
||||
} catch (const storage_io_error& e) {
|
||||
if (e.code().value() == ENOENT) {
|
||||
co_return false;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
co_return true;
|
||||
}
|
||||
|
||||
future<> utils::gcp::storage::client::close() {
|
||||
return _impl->close();
|
||||
}
|
||||
|
||||
@@ -154,7 +154,10 @@ namespace utils::gcp::storage {
|
||||
* Creates a data_source for reading from a named object.
|
||||
*/
|
||||
seekable_data_source create_download_source(std::string_view bucket, std::string_view object_name, seastar::abort_source* = nullptr) const;
|
||||
|
||||
/**
|
||||
* Checks if an object exists.
|
||||
*/
|
||||
future<bool> object_exists(std::string_view bucket, std::string_view object_name, seastar::abort_source* as = nullptr) const;
|
||||
/**
|
||||
* Destroys resources. Must be called before releasing object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user