Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/cloud/storage/internal/async/connection_tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "google/cloud/storage/internal/async/connection_tracing.h"
#include "google/cloud/storage/async/writer_connection.h"
#include "google/cloud/storage/internal/async/object_descriptor_connection_tracing.h"
#include "google/cloud/storage/internal/async/options.h"
#include "google/cloud/storage/internal/async/reader_connection_tracing.h"
#include "google/cloud/storage/internal/async/rewriter_connection_tracing.h"
#include "google/cloud/storage/internal/async/writer_connection_tracing.h"
Expand Down Expand Up @@ -63,6 +64,10 @@ class AsyncConnectionTracing : public storage::AsyncConnection {
OpenParams p) override {
auto span = internal::MakeSpan("storage::AsyncConnection::Open");
EnrichSpan(*span, p.options, p.read_spec.bucket());
if (p.options.has<ReadRangesOption>()) {
auto const& ranges = p.options.get<ReadRangesOption>();
span->SetAttribute("fast_open_ranges", ranges.size());
}
internal::OTelScope scope(span);
return impl_->Open(std::move(p))
.then([oc = opentelemetry::context::RuntimeContext::GetCurrent(),
Expand Down
19 changes: 15 additions & 4 deletions google/cloud/storage/internal/async/object_descriptor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ std::unique_ptr<storage::AsyncReaderConnection> ObjectDescriptorImpl::Read(
// Check if this range matches a pre-warmed range.
auto cache_key = std::make_pair(p.start, p.length);
auto cache_it = prewarmed_ranges_.find(cache_key);
absl::string_view cache_status = "MISS";

if (cache_it != prewarmed_ranges_.end()) {
cache_status = "HIT";
// Cache hit. Claim the pre-warmed range and return it to the user.
auto prewarmed = std::move(cache_it->second);
prewarmed_ranges_.erase(cache_it);
Expand All @@ -247,7 +250,13 @@ std::unique_ptr<storage::AsyncReaderConnection> ObjectDescriptorImpl::Read(
return std::unique_ptr<storage::AsyncReaderConnection>(
std::make_unique<ObjectDescriptorReader>(std::move(prewarmed.range)));
}
return MakeTracingObjectDescriptorReader(std::move(prewarmed.range));
return MakeTracingObjectDescriptorReader(std::move(prewarmed.range),
cache_status);
}

// If not hit, check if it was evicted earlier due to pacing.
if (evicted_ranges_.erase(cache_key) != 0) {
cache_status = "EVICTED";
}

if (stream_manager_->Empty()) {
Expand All @@ -258,7 +267,7 @@ std::unique_ptr<storage::AsyncReaderConnection> ObjectDescriptorImpl::Read(
return std::unique_ptr<storage::AsyncReaderConnection>(
std::make_unique<ObjectDescriptorReader>(std::move(range)));
}
return MakeTracingObjectDescriptorReader(std::move(range));
return MakeTracingObjectDescriptorReader(std::move(range), cache_status);
}

auto it = stream_manager_->GetLeastBusyStream();
Expand All @@ -274,8 +283,7 @@ std::unique_ptr<storage::AsyncReaderConnection> ObjectDescriptorImpl::Read(
return std::unique_ptr<storage::AsyncReaderConnection>(
std::make_unique<ObjectDescriptorReader>(std::move(range)));
}

return MakeTracingObjectDescriptorReader(std::move(range));
return MakeTracingObjectDescriptorReader(std::move(range), cache_status);
}

std::shared_ptr<storage::internal::HashFunction>
Expand Down Expand Up @@ -429,6 +437,9 @@ void ObjectDescriptorImpl::OnRead(
max_prewarmed_buffer_size_) {
// Evict the range if it exceeds the pacing limit.
total_prewarmed_bytes_buffered_ -= unclaimed_it->second.bytes_buffered;
if (evicted_ranges_.size() < 1000) {
evicted_ranges_.insert(unclaimed_it->second.cache_it->first);
}
prewarmed_ranges_.erase(unclaimed_it->second.cache_it);
unclaimed_ranges_.erase(unclaimed_it);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class ObjectDescriptorImpl

// Map of read_id to unclaimed range state (bytes buffered and original key).
std::unordered_map<std::int64_t, UnclaimedRangeState> unclaimed_ranges_;
// Set capturing tombstones for evicted pre-warmed ranges.
std::set<std::pair<std::int64_t, std::int64_t>> evicted_ranges_;
// Total bytes currently buffered across all unclaimed pre-warmed ranges.
std::size_t total_prewarmed_bytes_buffered_ = 0;
// Maximum bytes allowed to be buffered across all unclaimed pre-warmed ranges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ namespace sc = ::opentelemetry::semconv;

class ObjectDescriptorReaderTracing : public ObjectDescriptorReader {
public:
explicit ObjectDescriptorReaderTracing(std::shared_ptr<ReadRange> impl)
: ObjectDescriptorReader(std::move(impl)) {}
explicit ObjectDescriptorReaderTracing(std::shared_ptr<ReadRange> impl,
absl::string_view cache_status)
: ObjectDescriptorReader(std::move(impl)), cache_status_(cache_status) {}

~ObjectDescriptorReaderTracing() override = default;

future<ObjectDescriptorReader::ReadResponse> Read() override {
auto span = internal::MakeSpan("storage::AsyncConnection::ReadRange");
if (!cache_status_.empty()) {
span->SetAttribute("fast_open_cache_status", std::string(cache_status_));
}
internal::OTelScope scope(span);
return ObjectDescriptorReader::Read().then(
[span = std::move(span),
Expand All @@ -64,13 +68,18 @@ class ObjectDescriptorReaderTracing : public ObjectDescriptorReader {
return result;
});
}

private:
absl::string_view cache_status_;
};

} // namespace

std::unique_ptr<storage::AsyncReaderConnection>
MakeTracingObjectDescriptorReader(std::shared_ptr<ReadRange> impl) {
return std::make_unique<ObjectDescriptorReaderTracing>(std::move(impl));
MakeTracingObjectDescriptorReader(std::shared_ptr<ReadRange> impl,
absl::string_view cache_status) {
return std::make_unique<ObjectDescriptorReaderTracing>(std::move(impl),
cache_status);
}
Comment thread
kalragauri marked this conversation as resolved.

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace storage_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

std::unique_ptr<storage::AsyncReaderConnection>
MakeTracingObjectDescriptorReader(std::shared_ptr<ReadRange> impl);
MakeTracingObjectDescriptorReader(std::shared_ptr<ReadRange> impl,
absl::string_view cache_status);

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace storage_internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ TEST(ObjectDescriptorReaderTracing, Read) {
auto span_catcher = InstallSpanCatcher();

auto impl = std::make_shared<ReadRange>(10000, 30);
auto reader = MakeTracingObjectDescriptorReader(impl);
auto reader =
MakeTracingObjectDescriptorReader(impl, /*cache_status=*/"TEST");

auto data = google::storage::v2::ObjectRangeData{};
auto constexpr kData0 = R"pb(
Expand Down Expand Up @@ -73,7 +74,8 @@ TEST(ObjectDescriptorReaderTracing, Read) {
TEST(ObjectDescriptorReaderTracing, ReadError) {
auto span_catcher = InstallSpanCatcher();
auto impl = std::make_shared<ReadRange>(10000, 30);
auto reader = MakeTracingObjectDescriptorReader(impl);
auto reader =
MakeTracingObjectDescriptorReader(impl, /*cache_status=*/"TEST");

impl->OnFinish(PermanentError());

Expand Down
Loading