2323#include < string>
2424#include < utility>
2525
26+ #include " absl/base/attributes.h"
2627#include " absl/container/fixed_array.h"
2728#include " absl/container/inlined_vector.h"
2829#include " absl/strings/cord.h"
3233#include " tensorstore/internal/cache/cache.h"
3334#include " tensorstore/internal/cache/chunk_cache.h"
3435#include " tensorstore/internal/cache/kvs_backed_cache.h"
36+ #include " tensorstore/internal/log/verbose_flag.h"
3537#include " tensorstore/internal/memory.h"
38+ #include " tensorstore/internal/tracing/logged_trace_span.h"
3639#include " tensorstore/util/execution/execution.h"
3740#include " tensorstore/util/result.h"
3841#include " tensorstore/util/span.h"
4144
4245namespace tensorstore {
4346namespace internal {
47+ namespace {
48+ ABSL_CONST_INIT internal_log::VerboseFlag verbose_logging (
49+ " kvs_backed_chunk_cache" );
50+ }
4451
4552std::string KvsBackedChunkCache::Entry::GetKeyValueStoreKey () {
4653 auto & cache = GetOwningCache (*this );
@@ -56,12 +63,16 @@ void KvsBackedChunkCache::Entry::DoDecode(std::optional<absl::Cord> value,
5663 return ;
5764 }
5865 auto & cache = GetOwningCache (*this );
66+ internal_tracing::LoggedTraceSpan trace_span (
67+ __func__, verbose_logging.Level (2 ),
68+ {{" cache" , static_cast <void *>(&cache)}});
5969 auto decoded_result =
6070 cache.DecodeChunk (this ->cell_indices (), *std::move (value));
6171 if (!decoded_result.ok ()) {
62- execution::set_error (receiver,
63- internal::ConvertInvalidArgumentToFailedPrecondition (
64- std::move (decoded_result).status ()));
72+ auto status = internal::ConvertInvalidArgumentToFailedPrecondition (
73+ std::move (decoded_result).status ());
74+ execution::set_error (
75+ receiver, std::move (trace_span).EndWithStatus (std::move (status)));
6576 return ;
6677 }
6778 const size_t num_components = this ->component_specs ().size ();
@@ -80,8 +91,12 @@ void KvsBackedChunkCache::Entry::DoEncode(std::shared_ptr<const ReadData> data,
8091 execution::set_value (receiver, std::nullopt );
8192 return ;
8293 }
94+
8395 auto & entry = GetOwningEntry (*this );
8496 auto & cache = GetOwningCache (entry);
97+ internal_tracing::LoggedTraceSpan trace_span (
98+ __func__, verbose_logging.Level (2 ),
99+ {{" cache" , static_cast <void *>(&cache)}});
85100 // Convert from array of `SharedArray<const void>` to array of
86101 // `SharedArrayView<const void>`.
87102 auto * components = data.get ();
@@ -101,7 +116,9 @@ void KvsBackedChunkCache::Entry::DoEncode(std::shared_ptr<const ReadData> data,
101116 }
102117 auto encoded_result = cache.EncodeChunk (cell_indices, component_arrays);
103118 if (!encoded_result.ok ()) {
104- execution::set_error (receiver, std::move (encoded_result).status ());
119+ execution::set_error (
120+ receiver, std::move (trace_span)
121+ .EndWithStatus (std::move (encoded_result).status ()));
105122 return ;
106123 }
107124 execution::set_value (receiver, *std::move (encoded_result));
0 commit comments