Commit e4250194 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 1597211 - Adjust parameters and return types to allow passing response...

Bug 1597211 - Adjust parameters and return types to allow passing response size information. r=dom-workers-and-storage-reviewers,ytausky

Differential Revision: https://phabricator.services.mozilla.com/D53935

--HG--
extra : moz-landing-system : lando
parent 0a9705f2
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "mozilla/LazyIdleThread.h" #include "mozilla/LazyIdleThread.h"
#include "mozilla/Maybe.h" #include "mozilla/Maybe.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/Result.h"
#include "mozilla/SnappyCompressOutputStream.h" #include "mozilla/SnappyCompressOutputStream.h"
#include "mozilla/SnappyUncompressInputStream.h" #include "mozilla/SnappyUncompressInputStream.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
...@@ -7726,20 +7727,23 @@ class Cursor::CursorOpBase : public TransactionDatabaseOperationBase { ...@@ -7726,20 +7727,23 @@ class Cursor::CursorOpBase : public TransactionDatabaseOperationBase {
   
void Cleanup() override; void Cleanup() override;
   
nsresult PopulateResponseFromStatement(mozIStorageStatement* aStmt, using ResponseSizeOrError = mozilla::Result<size_t, nsresult>;
bool aInitializeResponse,
Key* const aOptOutSortKey); ResponseSizeOrError PopulateResponseFromStatement(mozIStorageStatement* aStmt,
bool aInitializeResponse,
Key* const aOptOutSortKey);
   
nsresult PopulateExtraResponses(mozIStorageStatement* aStmt, nsresult PopulateExtraResponses(mozIStorageStatement* aStmt,
uint32_t aMaxExtraCount, uint32_t aMaxExtraCount,
const size_t aInitialResponseSize,
const nsCString& aOperation, const nsCString& aOperation,
Key* const aOptPreviousSortKey); Key* const aOptPreviousSortKey);
   
private: private:
template <enum OpenCursorParams::Type CursorType> template <enum OpenCursorParams::Type CursorType>
nsresult PopulateResponseFromTypedStatement(mozIStorageStatement* const aStmt, ResponseSizeOrError PopulateResponseFromTypedStatement(
const bool aInitializeResponse, mozIStorageStatement* const aStmt, const bool aInitializeResponse,
Key* const aOptOutSortKey); Key* const aOptOutSortKey);
}; };
   
class Cursor::OpenOp final : public Cursor::CursorOpBase { class Cursor::OpenOp final : public Cursor::CursorOpBase {
...@@ -25938,7 +25942,8 @@ void Cursor::CursorOpBase::Cleanup() { ...@@ -25938,7 +25942,8 @@ void Cursor::CursorOpBase::Cleanup() {
} }
   
template <enum OpenCursorParams::Type CursorType> template <enum OpenCursorParams::Type CursorType>
nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement( Cursor::CursorOpBase::ResponseSizeOrError
Cursor::CursorOpBase::PopulateResponseFromTypedStatement(
mozIStorageStatement* const aStmt, const bool aInitializeResponse, mozIStorageStatement* const aStmt, const bool aInitializeResponse,
Key* const aOptOutSortKey) { Key* const aOptOutSortKey) {
auto cursorTypeTraits = CursorTypeTraits<CursorType>{*this}; auto cursorTypeTraits = CursorTypeTraits<CursorType>{*this};
...@@ -25947,7 +25952,7 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement( ...@@ -25947,7 +25952,7 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement(
{ {
const auto rv = cursorTypeTraits.GetKeys(aStmt, aOptOutSortKey); const auto rv = cursorTypeTraits.GetKeys(aStmt, aOptOutSortKey);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return Err(rv);
} }
} }
   
...@@ -25956,14 +25961,14 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement( ...@@ -25956,14 +25961,14 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement(
// currently do not filter these out. // currently do not filter these out.
if (aOptOutSortKey && !previousKey.IsUnset() && if (aOptOutSortKey && !previousKey.IsUnset() &&
previousKey == *aOptOutSortKey) { previousKey == *aOptOutSortKey) {
return NS_OK; return 0;
} }
   
{ {
const auto rv = const auto rv =
cursorTypeTraits.MaybeGetCloneInfo(aStmt, mCursor->mFileManager); cursorTypeTraits.MaybeGetCloneInfo(aStmt, mCursor->mFileManager);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return Err(rv);
} }
} }
   
...@@ -25983,10 +25988,12 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement( ...@@ -25983,10 +25988,12 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromTypedStatement(
cursorTypeTraits.FillKeys(response); cursorTypeTraits.FillKeys(response);
cursorTypeTraits.MaybeFillCloneInfo(response, &mFiles); cursorTypeTraits.MaybeFillCloneInfo(response, &mFiles);
   
return NS_OK; // TODO: Calculate real size and return it.
return 0;
} }
   
nsresult Cursor::CursorOpBase::PopulateResponseFromStatement( Cursor::CursorOpBase::ResponseSizeOrError
Cursor::CursorOpBase::PopulateResponseFromStatement(
mozIStorageStatement* const aStmt, const bool aInitializeResponse, mozIStorageStatement* const aStmt, const bool aInitializeResponse,
Key* const aOptOutSortKey) { Key* const aOptOutSortKey) {
Transaction()->AssertIsOnConnectionThread(); Transaction()->AssertIsOnConnectionThread();
...@@ -26001,7 +26008,8 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromStatement( ...@@ -26001,7 +26008,8 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromStatement(
mResponse.type() == CursorResponse::TArrayOfIndexCursorResponse), mResponse.type() == CursorResponse::TArrayOfIndexCursorResponse),
aInitializeResponse); aInitializeResponse);
   
nsresult (CursorOpBase::*populateFunc)(mozIStorageStatement*, bool, Key*); ResponseSizeOrError (CursorOpBase::*populateFunc)(mozIStorageStatement*, bool,
Key*);
   
switch (mCursor->mType) { switch (mCursor->mType) {
case OpenCursorParams::TObjectStoreOpenCursorParams: case OpenCursorParams::TObjectStoreOpenCursorParams:
...@@ -26033,7 +26041,8 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromStatement( ...@@ -26033,7 +26041,8 @@ nsresult Cursor::CursorOpBase::PopulateResponseFromStatement(
   
nsresult Cursor::CursorOpBase::PopulateExtraResponses( nsresult Cursor::CursorOpBase::PopulateExtraResponses(
mozIStorageStatement* const aStmt, const uint32_t aMaxExtraCount, mozIStorageStatement* const aStmt, const uint32_t aMaxExtraCount,
const nsCString& aOperation, Key* const aOptPreviousSortKey) { const size_t aInitialResponseSize, const nsCString& aOperation,
Key* const aOptPreviousSortKey) {
AssertIsOnConnectionThread(); AssertIsOnConnectionThread();
   
uint32_t extraCount = 0; uint32_t extraCount = 0;
...@@ -26056,8 +26065,9 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses( ...@@ -26056,8 +26065,9 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses(
// any remaining entries, and signal overall success. Probably, future // any remaining entries, and signal overall success. Probably, future
// attempts to access the same entry will fail as well, but it might never // attempts to access the same entry will fail as well, but it might never
// be accessed by the application. // be accessed by the application.
rv = PopulateResponseFromStatement(aStmt, false, aOptPreviousSortKey); const auto res =
if (NS_WARN_IF(NS_FAILED(rv))) { PopulateResponseFromStatement(aStmt, false, aOptPreviousSortKey);
if (NS_WARN_IF(res.isErr())) {
// TODO: Maybe disable preloading for this cursor? The problem will // TODO: Maybe disable preloading for this cursor? The problem will
// probably reoccur on the next attempt, and disabling preloading will // probably reoccur on the next attempt, and disabling preloading will
// reduce latency. However, if some problematic entry will be skipped // reduce latency. However, if some problematic entry will be skipped
...@@ -26068,6 +26078,9 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses( ...@@ -26068,6 +26078,9 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses(
break; break;
} }
   
// TODO: Check accumulated size of individual responses and maybe break
// early.
// TODO: Do not count entries skipped for unique cursors. // TODO: Do not count entries skipped for unique cursors.
++extraCount; ++extraCount;
} while (true); } while (true);
...@@ -26245,9 +26258,9 @@ nsresult Cursor::OpenOp::ProcessStatementSteps( ...@@ -26245,9 +26258,9 @@ nsresult Cursor::OpenOp::ProcessStatementSteps(
Key previousKey; Key previousKey;
auto* optPreviousKey = IsUnique(mCursor->mDirection) ? &previousKey : nullptr; auto* optPreviousKey = IsUnique(mCursor->mDirection) ? &previousKey : nullptr;
   
rv = PopulateResponseFromStatement(aStmt, true, optPreviousKey); const auto res = PopulateResponseFromStatement(aStmt, true, optPreviousKey);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(res.isErr())) {
return rv; return res.inspectErr();
} }
   
// The degree to which extra responses on OpenOp can actually be used depends // The degree to which extra responses on OpenOp can actually be used depends
...@@ -26256,7 +26269,7 @@ nsresult Cursor::OpenOp::ProcessStatementSteps( ...@@ -26256,7 +26269,7 @@ nsresult Cursor::OpenOp::ProcessStatementSteps(
// //
// TODO: We should somehow evaluate the effects of this. Maybe use a smaller // TODO: We should somehow evaluate the effects of this. Maybe use a smaller
// extra count than for ContinueOp? // extra count than for ContinueOp?
return PopulateExtraResponses(aStmt, mCursor->mMaxExtraCount, return PopulateExtraResponses(aStmt, mCursor->mMaxExtraCount, res.inspect(),
NS_LITERAL_CSTRING("OpenOp"), optPreviousKey); NS_LITERAL_CSTRING("OpenOp"), optPreviousKey);
} }
   
...@@ -26790,13 +26803,14 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26790,13 +26803,14 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) {
Key previousKey; Key previousKey;
auto* optPreviousKey = IsUnique(mCursor->mDirection) ? &previousKey : nullptr; auto* optPreviousKey = IsUnique(mCursor->mDirection) ? &previousKey : nullptr;
   
rv = PopulateResponseFromStatement(&*stmt, true, optPreviousKey); const auto res = PopulateResponseFromStatement(&*stmt, true, optPreviousKey);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(res.isErr())) {
return rv; return res.inspectErr();
} }
   
return PopulateExtraResponses( return PopulateExtraResponses(&*stmt, maxExtraCount, res.inspect(),
&*stmt, maxExtraCount, NS_LITERAL_CSTRING("ContinueOp"), optPreviousKey); NS_LITERAL_CSTRING("ContinueOp"),
optPreviousKey);
} }
   
Utils::Utils() Utils::Utils()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment