@@ -42,9 +42,20 @@ SearchableBucketListSnapshot::getLedgerEntry(LedgerKey const& k)
42
42
ZoneScoped;
43
43
mSnapshotManager .maybeUpdateSnapshot (*this );
44
44
45
- // TODO: Metrics only on main thread
46
- auto timer = mSnapshotManager .getPointLoadTimer (k.type ()).TimeScope ();
45
+ if (threadIsMain ())
46
+ {
47
+ auto timer = mSnapshotManager .getPointLoadTimer (k.type ()).TimeScope ();
48
+ return getLedgerEntryInternal (k);
49
+ }
50
+ else
51
+ {
52
+ return getLedgerEntryInternal (k);
53
+ }
54
+ }
47
55
56
+ std::shared_ptr<LedgerEntry>
57
+ SearchableBucketListSnapshot::getLedgerEntryInternal (LedgerKey const & k)
58
+ {
48
59
std::shared_ptr<LedgerEntry> result{};
49
60
50
61
auto f = [&](SearchableBucketSnapshot const & b) {
@@ -68,16 +79,9 @@ SearchableBucketListSnapshot::getLedgerEntry(LedgerKey const& k)
68
79
}
69
80
70
81
std::vector<LedgerEntry>
71
- SearchableBucketListSnapshot::loadKeys (
82
+ SearchableBucketListSnapshot::loadKeysInternal (
72
83
std::set<LedgerKey, LedgerEntryIdCmp> const & inKeys)
73
84
{
74
- ZoneScoped;
75
- mSnapshotManager .maybeUpdateSnapshot (*this );
76
-
77
- auto timer =
78
- mSnapshotManager .recordBulkLoadMetrics (" prefetch" , inKeys.size ())
79
- .TimeScope ();
80
-
81
85
std::vector<LedgerEntry> entries;
82
86
83
87
// Make a copy of the key set, this loop is destructive
@@ -91,6 +95,26 @@ SearchableBucketListSnapshot::loadKeys(
91
95
return entries;
92
96
}
93
97
98
+ std::vector<LedgerEntry>
99
+ SearchableBucketListSnapshot::loadKeys (
100
+ std::set<LedgerKey, LedgerEntryIdCmp> const & inKeys)
101
+ {
102
+ ZoneScoped;
103
+ mSnapshotManager .maybeUpdateSnapshot (*this );
104
+
105
+ if (threadIsMain ())
106
+ {
107
+ auto timer =
108
+ mSnapshotManager .recordBulkLoadMetrics (" prefetch" , inKeys.size ())
109
+ .TimeScope ();
110
+ return loadKeysInternal (inKeys);
111
+ }
112
+ else
113
+ {
114
+ return loadKeysInternal (inKeys);
115
+ }
116
+ }
117
+
94
118
// This query has two steps:
95
119
// 1. For each bucket, determine what PoolIDs contain the target asset via the
96
120
// assetToPoolID index
@@ -101,6 +125,9 @@ SearchableBucketListSnapshot::loadPoolShareTrustLinesByAccountAndAsset(
101
125
AccountID const & accountID, Asset const & asset)
102
126
{
103
127
ZoneScoped;
128
+
129
+ // This query should only be called during TX apply
130
+ releaseAssert (threadIsMain ());
104
131
mSnapshotManager .maybeUpdateSnapshot (*this );
105
132
106
133
LedgerKeySet trustlinesToLoad;
@@ -119,7 +146,12 @@ SearchableBucketListSnapshot::loadPoolShareTrustLinesByAccountAndAsset(
119
146
};
120
147
121
148
loopAllBuckets (trustLineLoop);
122
- return loadKeys (trustlinesToLoad);
149
+
150
+ auto timer = mSnapshotManager
151
+ .recordBulkLoadMetrics (" poolshareTrustlines" ,
152
+ trustlinesToLoad.size ())
153
+ .TimeScope ();
154
+ return loadKeysInternal (trustlinesToLoad);
123
155
}
124
156
125
157
std::vector<InflationWinner>
@@ -129,6 +161,9 @@ SearchableBucketListSnapshot::loadInflationWinners(size_t maxWinners,
129
161
ZoneScoped;
130
162
mSnapshotManager .maybeUpdateSnapshot (*this );
131
163
164
+ // This is a legacy query, should only be called by main thread during
165
+ // catchup
166
+ releaseAssert (threadIsMain ());
132
167
auto timer = mSnapshotManager .recordBulkLoadMetrics (" inflationWinners" , 0 )
133
168
.TimeScope ();
134
169
0 commit comments