sapling/eden/fs/store/ObjectFetchContext.cpp
Stanislau Hlebik 14527beaf4 add ObjectFetchContext with causeDetail field
Summary:
As previous diffs in the stack show there were at least one place in the
codebase which used incorrect object context logger and that resulted in "blind
spots" in undesired file fetches logging i.e. undesired file fetches were
logged, but neither pid nor cmd-line was logged.

There are quite a few places in the codebase that use null
object fetch context, and threading the correct object fetch context to all of
them might be hard. Threading the context is a bit annoying, so it would be good to know something like "EdenDispatcher code is responsible for most of the blind spots, so let's thread the correct context there first". Or it would be equally good to know that none of the null object context are responsible for blind spots.

This diff might help us decide where we need to thread real object fetch context
first. Instead of passing null object fetch context let's pass null object
fetch context with causeDetail field. This field will be logged to scuba (see
BackingStoreLogger::logImport code), and instead of getting "Unknown" interface
we'll get e.g. "Unknown - EdenDispatcher::create", and that would highlight
where we need to thread the context.

A note about implementation - getNullContextWithCauseDetail returns a raw pointer
which is expected to be static i.e. it should work similarly to current
getNullContext implementation. It's quite a hack, but allows us to get rid of
memory allocations (we'd have one memory allocation per place in the code where
getNullContextWithCauseDetail). Let me know if you are ok with this hack.

Reviewed By: kmancini

Differential Revision: D23422526

fbshipit-source-id: e576bba9fc09e160fc42771c7589cdd1694d93c0
2020-09-01 03:39:18 -07:00

43 lines
1.0 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/store/ObjectFetchContext.h"
namespace {
using namespace facebook::eden;
class NullObjectFetchContext : public ObjectFetchContext {
public:
NullObjectFetchContext() = default;
explicit NullObjectFetchContext(std::optional<folly::StringPiece> causeDetail)
: causeDetail_(causeDetail) {}
std::optional<folly::StringPiece> getCauseDetail() const override {
return causeDetail_;
}
private:
std::optional<folly::StringPiece> causeDetail_;
};
} // namespace
namespace facebook {
namespace eden {
ObjectFetchContext& ObjectFetchContext::getNullContext() {
static auto* p = new NullObjectFetchContext;
return *p;
}
ObjectFetchContext* ObjectFetchContext::getNullContextWithCauseDetail(
folly::StringPiece causeDetail) {
return new NullObjectFetchContext(folly::StringPiece{causeDetail});
}
} // namespace eden
} // namespace facebook