Skip to content

Commit 55fcbfd

Browse files
committed
Adding log messages on metadata opreations
1 parent 9168603 commit 55fcbfd

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/ExtCmd.actor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ACTOR static Future<std::pair<int, int>> dropIndexMatching(Reference<DocTransact
5050
state std::vector<bson::BSONObj> indexes = wait(getIndexesTransactionally(indexesPlan, tr));
5151
state int count = 0;
5252
state bool any = false;
53+
state bson::BSONObj matchingIndexObj;
5354
state Reference<QueryContext> matchingIndex;
5455
state std::string matchingName;
5556

@@ -63,13 +64,15 @@ ACTOR static Future<std::pair<int, int>> dropIndexMatching(Reference<DocTransact
6364
if (value.getBSONType() == bson::BSONType::String) {
6465
if (value.getString() == indexObj.getStringField(field.c_str())) {
6566
any = true;
67+
matchingIndexObj = indexObj;
6668
matchingIndex = indexesCollection->bindCollectionContext(tr)->cx->getSubContext(
6769
DataValue(indexObj.getField(DocLayerConstants::ID_FIELD)).encode_key_part());
6870
matchingName = std::string(indexObj.getStringField(DocLayerConstants::NAME_FIELD));
6971
}
7072
} else if (value.getBSONType() == bson::BSONType::Object) {
7173
if (value.getPackedObject().woCompare(indexObj.getObjectField(field.c_str())) == 0) {
7274
any = true;
75+
matchingIndexObj = indexObj;
7376
matchingIndex = indexesCollection->bindCollectionContext(tr)->cx->getSubContext(
7477
DataValue(indexObj.getField(DocLayerConstants::ID_FIELD)).encode_key_part());
7578
matchingName = std::string(indexObj.getStringField(DocLayerConstants::NAME_FIELD));
@@ -82,6 +85,11 @@ ACTOR static Future<std::pair<int, int>> dropIndexMatching(Reference<DocTransact
8285
matchingIndex->clearDescendants();
8386
matchingIndex->clearRoot();
8487

88+
TraceEvent(SevInfo, "BumpMetadataVersion")
89+
.detail("reason", "dropIndex")
90+
.detail("ns", fullCollNameToString(ns))
91+
.detail("index", matchingIndexObj.toString());
92+
8593
Void _ = wait(matchingIndex->commitChanges());
8694

8795
Key indexKey = targetedCollection->getIndexesSubspace().withSuffix(StringRef(encodeMaybeDotted(matchingName)));
@@ -356,6 +364,9 @@ ACTOR static Future<int> internal_doDropIndexesActor(Reference<DocTransaction> t
356364
Key indexes = unbound->getIndexesSubspace();
357365
tr->tr->clear(FDB::KeyRangeRef(indexes, strinc(indexes)));
358366
unbound->bindCollectionContext(tr)->bumpMetadataVersion();
367+
TraceEvent(SevInfo, "BumpMetadataVersion")
368+
.detail("reason", "dropAllIndexes")
369+
.detail("ns", fullCollNameToString(ns));
359370

360371
return count;
361372
}

src/ExtMsg.actor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ Namespace getDBCollectionPair(const char* ns, std::pair<std::string, std::string
6363
return std::make_pair(std::string(ns, dotPtr - ns), std::string(dotPtr + 1));
6464
}
6565

66-
std::string fullCollNameToString(Namespace const& ns) {
67-
return ns.first + "." + (ns.second.empty() ? "$cmd" : ns.second);
68-
}
69-
7066
/**
7167
* query := { $bool_op : [ query* ], * (a predicate)
7268
* path : literal_match, *

src/MetadataManager.actor.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
using namespace FDB;
2727

28+
std::string fullCollNameToString(Namespace const& ns) {
29+
return ns.first + "." + (ns.second.empty() ? "$cmd" : ns.second);
30+
}
31+
2832
Future<uint64_t> getMetadataVersion(Reference<DocTransaction> tr, Reference<DirectorySubspace> metadataDirectory) {
2933
std::string versionKey = metadataDirectory->key().toString() +
3034
DataValue(DocLayerConstants::VERSION_KEY, DVTypeCode::STRING).encode_key_part();
@@ -157,6 +161,9 @@ ACTOR static Future<std::pair<Reference<UnboundCollectionContext>, uint64_t>> co
157161
// collectionName.c_str(), printable(tcollectionDirectory->key()).c_str(),
158162
// printable(tmetadataDirectory->key()).c_str(), "");
159163
tcx->bindCollectionContext(tr)->bumpMetadataVersion(); // We start at version 1.
164+
TraceEvent(SevInfo, "BumpMetadataVersion")
165+
.detail("reason", "createCollection")
166+
.detail("ns", fullCollNameToString(ns));
160167

161168
return std::make_pair(tcx, -1); // So we don't pollute the cache in case this transaction never commits
162169
}
@@ -179,6 +186,9 @@ ACTOR static Future<Reference<UnboundCollectionContext>> assembleCollectionConte
179186
// Here and below don't pollute the cache if we just created the directory, since this transaction might
180187
// not commit.
181188
if (unboundPair.second != -1) {
189+
TraceEvent(SevInfo, "MetadataCacheAdd")
190+
.detail("ns", fullCollNameToString(ns))
191+
.detail("version", unboundPair.second);
182192
auto insert_result = self->contexts.insert(std::make_pair(ns, unboundPair));
183193
// Somebody else may have done the lookup and finished ahead of us. Either way, replace it with ours (can no
184194
// longer optimize this by only replacing if ours is newer, because the directory may have moved or
@@ -199,14 +209,16 @@ ACTOR static Future<Reference<UnboundCollectionContext>> assembleCollectionConte
199209
// Create the iterator again instead of making the previous value state, because the map could have
200210
// changed during the previous wait. Either way, replace it with ours (can no longer optimize this by
201211
// only replacing if ours is newer, because the directory may have moved or vanished.
202-
// std::map<std::pair<std::string, std::string>, std::pair<Reference<UnboundCollectionContext>,
203-
// uint64_t>>::iterator match = self->contexts.find(ns);
204212
auto match = self->contexts.find(ns);
205-
206213
if (match != self->contexts.end())
207214
match->second = unboundPair;
208215
else
209216
self->contexts.insert(std::make_pair(ns, unboundPair));
217+
218+
TraceEvent(SevInfo, "MetadataCacheUpdate")
219+
.detail("ns", fullCollNameToString(ns))
220+
.detail("oldVersion", oldVersion)
221+
.detail("newVersion", unboundPair.second);
210222
}
211223
return unboundPair.first;
212224
} else {

src/MetadataManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
using Namespace = std::pair<std::string, std::string>;
3333

34+
std::string fullCollNameToString(Namespace const& ns);
35+
3436
struct MetadataManager : ReferenceCounted<MetadataManager>, NonCopyable {
3537
explicit MetadataManager(struct DocumentLayer* docLayer) : docLayer(docLayer) {}
3638
~MetadataManager() = default;

src/QLPlan.actor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,10 @@ ACTOR static Future<Void> doIndexInsert(PlanCheckpoint* checkpoint,
14181418

14191419
Reference<IReadWriteContext> doc = wait(indexInsert->insert(unbound->bindCollectionContext(tr)));
14201420
mcx->bindCollectionContext(tr)->bumpMetadataVersion();
1421+
TraceEvent(SevInfo, "BumpMetadataVersion")
1422+
.detail("reason", "createIndex")
1423+
.detail("ns", fullCollNameToString(ns))
1424+
.detail("index", indexObj.toString());
14211425
output.send(ref(new ScanReturnedContext(doc, -1, Key())));
14221426
throw end_of_stream();
14231427
} catch (Error& e) {
@@ -1590,6 +1594,11 @@ ACTOR static Future<Void> updateIndexStatus(PlanCheckpoint* checkpoint,
15901594
DataValue(DocLayerConstants::CURRENTLY_PROCESSING_DOC_FIELD, DVTypeCode::STRING).encode_key_part());
15911595
indexDoc->clear(DataValue(DocLayerConstants::BUILD_ID_FIELD, DVTypeCode::STRING).encode_key_part());
15921596
mcx->bumpMetadataVersion();
1597+
TraceEvent(SevInfo, "BumpMetadataVersion")
1598+
.detail("reason", "updateIndexStatus")
1599+
.detail("ns", fullCollNameToString(ns))
1600+
.detail("indexID", printable(encodedIndexId))
1601+
.detail("status", newStatus);
15931602
output.send(ref(new ScanReturnedContext(indexDoc, -1, Key())));
15941603
throw end_of_stream();
15951604
} else {

0 commit comments

Comments
 (0)