W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2012

[IndexedDB] coupled transactions

From: Kyaw Tun <kyawtun@yathit.com>
Date: Sun, 18 Nov 2012 23:54:28 +0800
Message-ID: <CAFPCW96oGggSLpZ57UKm4pjiAo3P6FLJh6tFFjVwcqT4pvVa0w@mail.gmail.com>
To: public-webapps@w3.org
Coupled transactions exists when two or more transactions should be
committed together but transactions are in different scopes or mode.
Currently I find this problem challenging to solve with IndexedDB API.

This can be solved by merging transactions into single transaction,
but it will be sub-optimal and require sharing transaction objects.

The use case appear when we want to use producer-consumer pattern as follow:

In producer object, a read transaction is created and index cursors
are scanning to find a matching keys. Whenever it find a match key, it
send to consumer object.

Consumer object, a read or write transaction is created when it first
received a key. The cursor value is use to render UI or update it to
the database. In general, we are expecting to receive ordered sequence
of keys. For optimal purpose, the transaction should be keep active.

Concrete example:

Consumer side

var out = new ydn.db.Streamer(db, 'animals', 'id');
  out.setSink(function(key, value) {
    console.log(['receiving', key, value]); // should be ['cow', 'cow']

Producer side
var q1 = ydn.db.Iterator.where('animals', 'color', '=', 'spots');
var q2 = ydn.db.Iterator.where('animals', 'horn', '=', 1);
var q3 = ydn.db.Iterator.where('animals', 'legs', '=', 4);
var solver = new ydn.db.algo.NestedLoop(out);
var req = db.scan([q1, q2, q3], solver);

animals = [
    {id: 'rat', color: 'brown', horn: 0, legs: 4},
    {id: 'cow', color: 'spots', horn: 1, legs: 4},
    {id: 'galon', color: 'gold', horn: 1, legs: 2},
    {id: 'snake', color: 'spots', horn: 0, legs: 0},
    {id: 'chicken', color: 'red', horn: 0, legs: 2}

Ref: test_31_scan_mutli_query_match in
Received on Sunday, 18 November 2012 15:54:55 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:50 UTC