public TouchedDocumentInfo GetRecentTouchesFor(string key) { TouchedDocumentInfo info; RecentTouches.TryGetValue(key, out info); return(info); }
internal void CheckReferenceBecauseOfDocumentUpdate(string key, IStorageActionsAccessor actions) { TouchedDocumentInfo touch; RecentTouches.TryRemove(key, out touch); foreach (var referencing in actions.Indexing.GetDocumentsReferencing(key)) { Etag preTouchEtag = null; Etag afterTouchEtag = null; try { actions.Documents.TouchDocument(referencing, out preTouchEtag, out afterTouchEtag); } catch (ConcurrencyException) { } if (preTouchEtag == null || afterTouchEtag == null) { continue; } actions.General.MaybePulseTransaction(); RecentTouches.Set(referencing, new TouchedDocumentInfo { PreTouchEtag = preTouchEtag, TouchedEtag = afterTouchEtag }); } }
internal void CheckReferenceBecauseOfDocumentUpdate(string key, IStorageActionsAccessor actions) { TouchedDocumentInfo touch; RecentTouches.TryRemove(key, out touch); Stopwatch sp = null; int count = 0; foreach (var referencing in actions.Indexing.GetDocumentsReferencing(key)) { Etag preTouchEtag = null; Etag afterTouchEtag = null; try { count++; actions.Documents.TouchDocument(referencing, out preTouchEtag, out afterTouchEtag); var docMetadata = actions.Documents.DocumentMetadataByKey(referencing); if (docMetadata != null) { var entityName = docMetadata.Metadata.Value <string>(Constants.RavenEntityName); if (string.IsNullOrEmpty(entityName) == false) { Database.LastCollectionEtags.Update(entityName, afterTouchEtag); } } } catch (ConcurrencyException) { } if (preTouchEtag == null || afterTouchEtag == null) { continue; } if (actions.General.MaybePulseTransaction()) { if (sp == null) { sp = Stopwatch.StartNew(); } if (sp.Elapsed >= TimeSpan.FromSeconds(30)) { throw new TimeoutException("Early failure when checking references for document '" + key + "', we waited over 30 seconds to touch all of the documents referenced by this document.\r\n" + "The operation (and transaction) has been aborted, since to try longer (we already touched " + count + " documents) risk a thread abort.\r\n" + "Consider restructuring your indexes to avoid LoadDocument on such a popular document."); } } RecentTouches.Set(referencing, new TouchedDocumentInfo { PreTouchEtag = preTouchEtag, TouchedEtag = afterTouchEtag }); } }
internal void CheckReferenceBecauseOfDocumentUpdate(string key, IStorageActionsAccessor actions) { TouchedDocumentInfo touch; RecentTouches.TryRemove(key, out touch); foreach (var referencing in actions.Indexing.GetDocumentsReferencing(key)) { Etag preTouchEtag = null; Etag afterTouchEtag = null; try { actions.Documents.TouchDocument(referencing, out preTouchEtag, out afterTouchEtag); var docMetadata = actions.Documents.DocumentMetadataByKey(referencing); if (docMetadata != null) { var entityName = docMetadata.Metadata.Value <string>(Constants.RavenEntityName); if (string.IsNullOrEmpty(entityName) == false) { Database.LastCollectionEtags.Update(entityName, afterTouchEtag); } } } catch (ConcurrencyException) { } if (preTouchEtag == null || afterTouchEtag == null) { continue; } actions.General.MaybePulseTransaction(); RecentTouches.Set(referencing, new TouchedDocumentInfo { PreTouchEtag = preTouchEtag, TouchedEtag = afterTouchEtag }); } }