Bug 1168606 - Set flag to invalidate in-flight responses as well. r=asuth
authorSimon Giesecke <sgiesecke@mozilla.com>
Thu, 14 Nov 2019 16:14:02 +0000
changeset 501978 1ca7e5b24181b20b3a63c3b11227ba46afabdb94
parent 501977 fc34f807986e87758aa1433c228497fd9eb1c974
child 501979 5ee8c7c51c04274fe88aa28cf7b3e3008d7a6da8
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1168606
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168606 - Set flag to invalidate in-flight responses as well. r=asuth Differential Revision: https://phabricator.services.mozilla.com/D52559
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/ActorsChild.h
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -3256,34 +3256,36 @@ BackgroundCursorChild::BackgroundCursorC
                                              IDBObjectStore* aObjectStore,
                                              Direction aDirection)
     : mRequest(aRequest),
       mTransaction(aRequest->GetTransaction()),
       mObjectStore(aObjectStore),
       mIndex(nullptr),
       mCursor(nullptr),
       mStrongRequest(aRequest),
-      mDirection(aDirection) {
+      mDirection(aDirection),
+      mInFlightResponseInvalidationNeeded(false) {
   MOZ_ASSERT(aObjectStore);
   aObjectStore->AssertIsOnOwningThread();
   MOZ_ASSERT(mTransaction);
 
   MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
 }
 
 BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest,
                                              IDBIndex* aIndex,
                                              Direction aDirection)
     : mRequest(aRequest),
       mTransaction(aRequest->GetTransaction()),
       mObjectStore(nullptr),
       mIndex(aIndex),
       mCursor(nullptr),
       mStrongRequest(aRequest),
-      mDirection(aDirection) {
+      mDirection(aDirection),
+      mInFlightResponseInvalidationNeeded(false) {
   MOZ_ASSERT(aIndex);
   aIndex->AssertIsOnOwningThread();
   MOZ_ASSERT(mTransaction);
 
   MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
 }
 
 BackgroundCursorChild::~BackgroundCursorChild() {
@@ -3491,16 +3493,29 @@ void BackgroundCursorChild::InvalidateCa
   // need to care, etc.
 
   IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
       "PRELOAD: Invalidating all %zu cached responses", "Invalidating",
       mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
       mCachedResponses.size());
 
   mCachedResponses.clear();
+
+  // We only hold a strong cursor reference in mStrongCursor when
+  // continue()/similar has been called. In those cases we expect a response
+  // that will be received in the future, and it may include prefetched data
+  // that needs to be discarded.
+  if (mStrongCursor) {
+    IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
+        "PRELOAD: Setting flag to invalidate in-flight responses",
+        "Set flag to invalidate in-flight responses",
+        mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber());
+
+    mInFlightResponseInvalidationNeeded = true;
+  }
 }
 
 template <typename Condition>
 void BackgroundCursorChild::DiscardCachedResponses(
     const Condition& aConditionFunc) {
   size_t discardedCount = 0;
   while (!mCachedResponses.empty() &&
          aConditionFunc(mCachedResponses.front())) {
@@ -3596,16 +3611,27 @@ void BackgroundCursorChild::HandleMultip
 
     // TODO: At the moment, we only send a cursor request to the parent if
     // requested by the user code. Therefore, the first result is always used as
     // the current result, and the potential extra results are cached. If we
     // extended this towards preloading in the background, all results might
     // need to be cached.
     aHandleRecord(/* aUseAsCurrentResult */ isFirst, response);
     isFirst = false;
+
+    if (mInFlightResponseInvalidationNeeded) {
+      IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
+          "PRELOAD: Discarding remaining responses since "
+          "mInFlightResponseInvalidationNeeded is set",
+          "Discarding responses", mTransaction->LoggingSerialNumber(),
+          mRequest->LoggingSerialNumber());
+
+      mInFlightResponseInvalidationNeeded = false;
+      break;
+    }
   }
 
   ResultHelper helper(mRequest, mTransaction, mCursor);
   DispatchSuccessEvent(&helper);
 }
 
 void BackgroundCursorChild::HandleResponse(
     const nsTArray<ObjectStoreCursorResponse>& aResponses) {
--- a/dom/indexedDB/ActorsChild.h
+++ b/dom/indexedDB/ActorsChild.h
@@ -653,16 +653,17 @@ class BackgroundCursorChild final : publ
   RefPtr<IDBRequest> mStrongRequest;
   RefPtr<IDBCursor> mStrongCursor;
 
   Direction mDirection;
 
   NS_DECL_OWNINGTHREAD
 
   std::deque<CachedResponse> mCachedResponses, mDelayedResponses;
+  bool mInFlightResponseInvalidationNeeded;
 
  public:
   BackgroundCursorChild(IDBRequest* aRequest, IDBObjectStore* aObjectStore,
                         Direction aDirection);
 
   BackgroundCursorChild(IDBRequest* aRequest, IDBIndex* aIndex,
                         Direction aDirection);