Skip to content

Commit 2996126

Browse files
authored
Add debug info to TPathChecker (#10217)
1 parent 6c244f7 commit 2996126

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

ydb/core/config/init/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <ydb/core/driver_lib/run/service_mask.h>
44
#include <ydb/core/base/event_filter.h>
5-
#include <ydb/core/config/init/source_location.h>
5+
#include <ydb/core/util/source_location.h>
66
#include <ydb/core/protos/config.pb.h>
77
#include <ydb/library/actors/core/interconnect.h>
88
#include <ydb/public/lib/deprecated/kicli/kicli.h>

ydb/core/tx/schemeshard/schemeshard_path.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
namespace NKikimr::NSchemeShard {
1010

11-
TPath::TChecker::TChecker(const TPath& path)
11+
TPath::TChecker::TChecker(const TPath& path, const NCompat::TSourceLocation location)
1212
: Path(path)
1313
, Failed(false)
1414
, Status(EStatus::StatusSuccess)
15+
, Location(location)
1516
{
1617
}
1718

@@ -32,7 +33,14 @@ const TPath::TChecker& TPath::TChecker::Fail(EStatus status, const TString& erro
3233
Status = status;
3334
Error = TStringBuilder() << "Check failed"
3435
<< ": path: '" << Path.PathString() << "'"
35-
<< ", error: " << error;
36+
<< ", error: " << error
37+
// this line included only in debug error
38+
// because we do not want to forward information
39+
// about our sources to db user
40+
#ifndef NDEBUG
41+
<< ", source_location: " << NUtil::TrimSourceFileName(Location.file_name()) << ":" << Location.line()
42+
#endif
43+
;
3644

3745
return *this;
3846
}
@@ -1102,8 +1110,8 @@ TPath::TPath(TVector<TPathElement::TPtr>&& elements, TSchemeShard* ss)
11021110
Y_ABORT_UNLESS(IsResolved());
11031111
}
11041112

1105-
TPath::TChecker TPath::Check() const {
1106-
return TChecker(*this);
1113+
TPath::TChecker TPath::Check(const NCompat::TSourceLocation location) const {
1114+
return TChecker(*this, location);
11071115
}
11081116

11091117
bool TPath::IsEmpty() const {

ydb/core/tx/schemeshard/schemeshard_path.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "schemeshard_info_types.h"
55

66
#include <ydb/core/protos/flat_tx_scheme.pb.h>
7+
#include <ydb/core/util/source_location.h>
78

89
#include <util/generic/maybe.h>
910

@@ -19,18 +20,18 @@ class TPath {
1920
public:
2021
class TChecker {
2122
using EStatus = NKikimrScheme::EStatus;
22-
2323
const TPath& Path;
2424
mutable bool Failed;
2525
mutable EStatus Status;
2626
mutable TString Error;
27+
NCompat::TSourceLocation Location;
2728

2829
private:
2930
TString BasicPathInfo(TPathElement::TPtr element) const;
3031
const TChecker& Fail(EStatus status, const TString& error) const;
3132

3233
public:
33-
explicit TChecker(const TPath& path);
34+
explicit TChecker(const TPath& path, const NCompat::TSourceLocation location = NCompat::TSourceLocation::current());
3435

3536
explicit operator bool() const;
3637
EStatus GetStatus() const;
@@ -122,8 +123,7 @@ class TPath {
122123
static TPath ResolveWithInactive(TOperationId opId, const TString path, TSchemeShard* ss);
123124

124125
static TPath Init(const TPathId pathId, TSchemeShard* ss);
125-
126-
TChecker Check() const;
126+
TChecker Check(const NCompat::TSourceLocation location = NCompat::TSourceLocation::current()) const;
127127
bool IsEmpty() const;
128128
bool IsResolved() const;
129129

ydb/core/util/source_location.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "source_location.h"
2+
3+
#include <string_view>
4+
5+
namespace NKikimr::NUtil {
6+
7+
constexpr inline auto ThisFileLocation = NCompat::TSourceLocation::current();
8+
constexpr inline ui64 ThisFileSuffixLength = 33; // length of "ydb/core/util/source_location.cpp"
9+
constexpr inline ui64 ThisFileLength = std::string_view(ThisFileLocation.file_name()).length();
10+
constexpr inline ui64 PrefixLength = ThisFileLength - ThisFileSuffixLength;
11+
12+
TString TrimSourceFileName(const char* fileName) {
13+
if constexpr (NCompat::HasSourceLocation) {
14+
static_assert(std::string_view(ThisFileLocation.file_name()).substr(PrefixLength) == std::string_view("ydb/core/util/source_location.cpp"));
15+
16+
if (!std::string_view(fileName).starts_with(std::string_view(ThisFileLocation.file_name()).substr(0, PrefixLength))) {
17+
return fileName;
18+
}
19+
20+
return TString(fileName + PrefixLength);
21+
}
22+
23+
return fileName;
24+
}
25+
26+
} // namespace NKikimr::NUtil

ydb/core/config/init/source_location.h renamed to ydb/core/util/source_location.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#pragma once
22

3+
#include <util/generic/string.h>
4+
35
#if __has_builtin(__builtin_source_location)
46
#include <source_location>
57

68
namespace NKikimr::NCompat {
79

810
using TSourceLocation = std::source_location;
911

12+
constexpr inline bool HasSourceLocation = true;
13+
1014
} // namespace NCompat
1115
#else
1216
namespace NKikimr::NCompat {
@@ -28,5 +32,13 @@ struct TSourceLocation {
2832
}
2933
};
3034

35+
constexpr inline bool HasSourceLocation = false;
36+
3137
} // namespace NCompat
3238
#endif
39+
40+
namespace NKikimr::NUtil {
41+
42+
TString TrimSourceFileName(const char* fileName);
43+
44+
} // namespace NKikimrNUtil

ydb/core/util/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SRCS(
4444
simple_cache.h
4545
single_thread_ic_mock.cpp
4646
single_thread_ic_mock.h
47+
source_location.cpp
4748
stlog.cpp
4849
stlog.h
4950
testactorsys.cpp

0 commit comments

Comments
 (0)