Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: net/http/http_cache.h

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Simplified ActiveEntry's state transitions Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/http/http_cache.cc » ('j') | net/http/http_cache.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache.h
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index 635cb92d557d17c6c60ca459f4117deb075f71f7..2ec0262584ba8654071361a30c35f16f0cd2d6f6 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -69,6 +69,10 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
DISABLE
};
+ class Transaction;
+ using TransactionList = std::list<Transaction*>;
+ using TransactionSet = std::unordered_set<Transaction*>;
+
// A BackendFactory creates a backend object to be used by the HttpCache.
class NET_EXPORT BackendFactory {
public:
@@ -238,14 +242,11 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
class MetadataWriter;
class QuicServerInfoFactoryAdaptor;
- class Transaction;
class WorkItem;
friend class Transaction;
friend class ViewCacheHelper;
struct PendingOp; // Info for an entry under construction.
- using TransactionList = std::list<Transaction*>;
- using TransactionSet = std::unordered_set<Transaction*>;
typedef std::list<std::unique_ptr<WorkItem>> WorkItemList;
struct ActiveEntry {
@@ -256,12 +257,59 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// Returns true if no transactions are associated with this entry.
bool HasNoTransactions();
- disk_cache::Entry* disk_entry;
- Transaction* writer;
+ // Returns true if no active readers/writer transactions are associated
+ // with this entry.
+ bool HasNoActiveTransactions();
+
+ // Returns true if the given transaction is a reader.
+ bool IsReader(Transaction* transaction);
shivanisha 2017/03/16 15:43:26 Will remove this function since it is no longer in
shivanisha 2017/03/20 16:34:52 done
+
+ disk_cache::Entry* disk_entry = nullptr;
+
+ // We implement a basic reader/writer lock for the disk cache entry. If
+ // there is a writer, then all read-only transactions must wait. Non
+ // read-only transactions can proceed to their validation phase. Validation
+ // is allowed for one transaction at a time so that we do not end up with
+ // wasted network requests.
+
+ // The following variables represent the various transactions associated
+ // with this entry in different stages. A transaction goes through these
+ // transitions.
+ //
+ // Write mode transactions:
+ // add_to_entry_queue-> headers_transaction -> done_headers_queue ->
+ // writer
+ // add_to_entry_queue-> headers_transaction -> done_headers_queue ->
+ // readers (once the data is written to the cache by another writer)
+ //
+ // Read only transactions:
+ // add_to_entry_queue-> readers (once the data is written to the cache by
+ // the writer)
+
+ // Transactions waiting to be added to entry.
+ TransactionList add_to_entry_queue;
+
+ // Transaction currently in the headers phase, either validating the
+ // response or getting new headers. This can exist simultaneously with
+ // writer or readers while validating existing headers.
+ Transaction* headers_transaction = nullptr;
+
+ // Transactions that have completed their headers phase and are waiting
+ // to read the response body or write the response body.
+ TransactionList done_headers_queue;
+
+ // Transaction currently reading from the network and writing to the cache.
+ Transaction* writer = nullptr;
+
+ // Transactions that can only read from the cache. Only one of writer or
+ // readers can exist at a time.
TransactionSet readers;
- TransactionList pending_queue;
- bool will_process_pending_queue;
- bool doomed;
+
+ // The following variables are true if OnProcessQueuedTransactions is posted
+ bool will_process_queued_transactions = false;
+
+ // True if entry is doomed.
+ bool doomed = false;
};
using ActiveEntriesMap =
@@ -342,12 +390,30 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// Destroys an ActiveEntry (active or doomed).
void DestroyEntry(ActiveEntry* entry);
- // Adds a transaction to an ActiveEntry. If this method returns ERR_IO_PENDING
- // the transaction will be notified about completion via its IO callback. This
- // method returns ERR_CACHE_RACE to signal the transaction that it cannot be
- // added to the provided entry, and it should retry the process with another
- // one (in this case, the entry is no longer valid).
- int AddTransactionToEntry(ActiveEntry* entry, Transaction* trans);
+ // Adds a transaction to an ActiveEntry. This method returns ERR_IO_PENDING
+ // and the transaction will be notified about completion via its IO callback.
+ int AddTransactionToEntry(ActiveEntry* entry, Transaction* transaction);
+
+ // Checks if a transaction can be added to the entry. If yes, it will
+ // invoke the IO callback of the transaction.
+ void ProcessAddToEntryTransaction(ActiveEntry* entry);
+
+ // Checks if a transaction that has already completed the response headers
+ // phase can resume reading/writing the response body. If yes, it will
+ // invoke the IO callback of the transaction.
+ void ProcessDoneHeadersTransaction(ActiveEntry* entry);
Randy Smith (Not in Mondays) 2017/03/17 18:13:05 Suggestion: Include in the comments that the above
shivanisha 2017/03/20 16:34:52 Done
+
+ // Transaction invokes this when its response headers phase is complete
+ // either on validating existing headers/ skippig validation or getting new
shivanisha 2017/03/16 00:54:54 *skipping
shivanisha 2017/03/20 16:34:52 done
+ // headers. is_match should be passed as true if the validation was a match or
+ // it was new headers.
shivanisha 2017/03/16 15:43:26 *or headers were retrieved the first time.
shivanisha 2017/03/20 16:34:52 done
+ // If its not a match, this entry is doomed/destroyed and pending
+ // transactions are restarted. Returns OK.
+ // If it is a match, the transaction is added to a queue and a task is posted
+ // to process queued transactions of the entry. Returns ERR_IO_PENDING.
+ int DoneResponseHeaders(ActiveEntry* entry,
+ Transaction* transaction,
+ bool is_match);
// Called when the transaction has finished working with this entry. |cancel|
// is true if the operation was cancelled by the caller instead of running
@@ -356,14 +422,25 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// Called when the transaction has finished writing to this entry. |success|
// is false if the cache entry should be deleted.
- void DoneWritingToEntry(ActiveEntry* entry, bool success);
+ void DoneWritingToEntry(ActiveEntry* entry,
+ bool success,
+ Transaction* transaction);
+
+ // Processes other transactions when a transaction is done writing to the
+ // entry, based on success or failure of this transaction.
+ void DoneWritingToEntryProcessOtherTransactions(ActiveEntry* entry,
+ bool success);
shivanisha 2017/03/16 15:43:26 Will remove this function declaration as it is no
shivanisha 2017/03/20 16:34:52 done
// Called when the transaction has finished reading from this entry.
- void DoneReadingFromEntry(ActiveEntry* entry, Transaction* trans);
+ void DoneReadingFromEntry(ActiveEntry* entry, Transaction* transaction);
- // Converts the active writer transaction to a reader so that other
- // transactions can start reading from this entry.
- void ConvertWriterToReader(ActiveEntry* entry);
+ // Converts the active writer/validating transaction to a reader so that other
+ // transactions can start reading from this entry. It is invoked in the
+ // validation phase of a transaction when the current entry is validated. It
+ // needs to differentiate between the scenarios when the entry is already
+ // completely written to by another transaction or is currently being written.
+ // In the former case, the transaction will become a reader at this time.
+ // void ConvertWriterToReader(ActiveEntry* entry, Transaction* transaction);
shivanisha 2017/03/16 00:54:54 Will remove this commented code.
shivanisha 2017/03/20 16:34:52 done
// Returns the LoadState of the provided pending transaction.
LoadState GetLoadStateForPendingTransaction(const Transaction* trans);
@@ -379,12 +456,22 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// Removes the transaction |trans|, from the pending list of |pending_op|.
bool RemovePendingTransactionFromPendingOp(PendingOp* pending_op,
Transaction* trans);
- // Resumes processing the pending list of |entry|.
- void ProcessPendingQueue(ActiveEntry* entry);
+
+ // Returns all queued transactions in the list in FIFO order. This included
+ // transactions that have completed te headers phase and those that have not
+ // been added to the entry yet.
+ TransactionList GetAllPendingTransactions(ActiveEntry* entry);
+
+ // Resumes processing the queued transactions of |entry|.
+ void ProcessQueuedTransactions(ActiveEntry* entry);
+
+ // Processes either writer's failure to write response body or
+ // headers_transactions's failure to write headers.
+ void ProcessEntryFailure(ActiveEntry* entry);
// Events (called via PostTask) ---------------------------------------------
- void OnProcessPendingQueue(ActiveEntry* entry);
+ void OnProcessQueuedTransactions(ActiveEntry* entry);
// Callbacks ----------------------------------------------------------------
« no previous file with comments | « no previous file | net/http/http_cache.cc » ('j') | net/http/http_cache.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698