2525
2626using namespace FDB ;
2727
28+ std::string fullCollNameToString (Namespace const & ns) {
29+ return ns.first + " ." + (ns.second .empty () ? " $cmd" : ns.second );
30+ }
31+
2832Future<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 {
0 commit comments