number of objects offline in UA with advanced indexing on specified object properties as keys for data retrieval. • A key has an associated type to one of: number, date, string, binary, or array. • http://w3c.github.io/IndexedDB/#introduction • https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm • https://docs.google.com/presentation/d/1U4KH1ZhBf4yZVN6wnam4KKF4SNxgVTlo2LckchRk6qE/edit?usp=sharing
db.transaction("books", "readonly"); var store = txn.objectStore("books"); var index = store.index("by_author"); var request = index.openCursor(IDBKeyRange.only("Fred")); request.onsuccess = function() { var cursor = request.result; if (cursor) { || Called for each matching record. report(cursor.value.isbn, cursor.value.title, cursor.value.author); cursor.continue(); } else { || No more matching records. report(null); } };
"readwrite"); store_t1 = trans1.objectStore("store"); store_t1.put("a"); // Will get key 1 store_t1.put("b"); // Will get key 2 trans1.abort(); // changes are rolled back after aborted // changes in trans2 will be started only if trans1 is finished. trans2 = db.transaction(["store"], "readwrite"); store_t2 = trans2.objectStore("store"); store_t2.put("c"); // Will get key 1 store_t2.put("d"); // Will get key 2
ObjectStoreOp (Create|Delete|Rename) IndexOp Normal TransactionOp IndexRequestOpBase ObjectStore AddOrPutRequestOp ObjectStore GetAllKeysRequestOp ObjectStore ClearRequestOp ObjectStore GetRequestOp ObjectStore DeleteRequestOp ObjectStore CountRequestOp Index GetRequestOp Index GetKeyRequestOp Index CountRequestOp Cursor:: CursorOp Cursor:: OpenOp Cursor:: ContinueOp IDBIndex.getAll() and IDBIndex.getAllKeys() are taken care by GetRequestOp and GetKeyRequestOp respectively IDBCursor.update() and IDBCursor.delete() utilize ObjectStoreAddOrPutRequestOp and ObjectStoreDeleteRequestOp respectively with primary key specified TransactionDatabase OperationBase
Begin Version Change Database Work Same to requested version 1. Start Permission Challenge if persistent storage type is specified. 2. Go to next state if permission granted from user. 3. Otherwise, go to SendResults Requested from IDBFactory.open() or IDBFactory.delete() 1. Ask QuotaManager to Create/Open directory and database files as followed: • Directory in • $profile/storage/(default|permanent|temporary)/$origin/idb/ • …./$origin/idb/$SHUFFLED_NAME.files/ • SQLite File: • …./$origin/idb/$SHUFFLED_NAME.sqlite • … 1. Go to BeginVersionChange, if • Open with requested version > stored version • Or deletion operation is requested 2. Otherwise, go to SendResults Not granted 1. If other connections are alive, • send versionChange event to these connections and • trigger IDBOpenRequest.onblocked(). 2. Wait for other connections to close. 3. For Open request, • Create a VersionChangeTransaction for the upgrade process of DB schema. • Trigger IDBOpenRequest.onupgradeneeded(). 4. For Delete request, Clear all IDB files from $origin/idb/ folder. 1. This eventually triggers • IDBOpenRequest.onsuccess() with IDBDatabase instance. • IDBOpenRequest.onerror() with proper error cause. Note: Multiple threads are invoked during this operation in different states, including: PBackground Thread, IO Thread, Connection Thread, Main Thread Error
after receiving IDBRequest from IDBObjectStore, IDBIndex or IDBCursor. (PBackground) 2.Dispatch itself into ConnectionPool (ConnectionThread) 3.Run SQL Statement via DatabaseConnection 4.Dispatch itself back to owning thread. (PBackground) 5.Send Operation Result back to IDBRequest
a MozStorageConnection for the access of SQLite DB. • ConnectionPool::GetOrCreateConnection() • Each connection handle all the IDBRequests of an open database in a connection thread assigned to the database. • ConnectionPool::Start() • ConnectionPool:ScheuleTransaction() • Maximal Number of Connection Threads = 20.
identify that there is no request after transaction is created at the next tick of the event loop? • https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ • https://www.w3.org/TR/html5/webappapis.html#processing-model-3
Metastable State Task#1 Task#2 Task#3 Event Queue Ex: DOM Event dispatched asynchronously MicroTask#1 MicroTask#2 MicroTask#3 MicroTask#4 MicroTask Queue Ex: Resolved Promise Note: 1. Metastable State is gecko-only. (Not specified in HTML 5. See Bug 1179909.) 2. See more discussion of microtasks and promises in Bug 1193394. 3. Stable State was removed from the steps of the latest #whatwg-eventloop-processing-model.
to the .sqlite file in • Linux: $HOME/.mozilla/firefox/$profile/storage/default/$origin/idb/ • OS X: $HOME/Library/Application Support/Firefox/$profile/storage/default/$origin/idb/ Note: unique_index_data set (index_id, value) as PRIMARY KEY to ensure the value of the index key in each entity is unique.