question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transaction Propose

See original GitHub issue

Hello everyone! In v4, transactions are removed to avoid keep datafile locked between commands. It was a hard decision, but was important to fix some v3 concurrency problems.

But transaction are awesome in some applications are really important. So I’m working on another way to implement “transaction-like” operation. My ideia is implement something like Entity Framework do: operate with objects in memory and, when call “SaveChanges”, save all changes in a single datafile operation (and if any error occurs, rollback everything).

So, here my propose:

using(var db = new LiteDatabase("..."))
{
    var customers = db.GetCollection<Customer>("customers");
    var orders = db.GetCollection<Order>("orders");
    
    var cust1 = new Customer { Name = "John" };
    var order1 = new Order { Date = DateTime.Now, Customer = cust1 };
    
    customers.Add(cust1);
    orders.Add(order1);
    
    // no datafile operation until here
    // all entities are in memory (as a List<Entity> Changes)
    // so, "customers.FindById(1) == null"
    
    db.SaveChanges(); 
    // now, in a single datafile operation:
    // - "cust1" will be serialized, inserted and setted "CustomerId"
    // - "order1" will be serialized (and will get reference from cust1), inserted and setted "OrderId"
    
    // "Updating"
    
    var cust2 = customers.FindById(2);
    
    cust2.Name = "Newton";
    
    customers.Set(cust2);
    
    // to avoid track all return objects (from Find), you will need use "Set" to be updated later
    
    db.SaveChanges();
    
    // also, will be avaiable
    // customers.Save(entity) - works as Upsert()
    // customers.Remove(entity) - works as Delete()
    
}
  • This 4 methods will works with a change list (List<Entity>) that will be execute in order as included in this list when SaveChanges are called
  • Current Insert(), Update(), Delete() method will work as excepted
  • Until SaveChanges() all added/updated/deleted entities are not reflected in Find operations

Leave your comments, ideas and considerations 👍

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
mbdavidcommented, Jan 13, 2018

Hi @masilver99, no. LiteDB has internal transactions (even in v4) but not expose to user to avoid keep opened. So, if engine has a fixed list of items to insert/update/delete, all operations can be done in a single transaction.

But, my “problem” now is that I read and understand more about WAL (Write Ahead Logging). All major databases implement this technique (SQL server, Postgres, Sqlite, MongoDB, …) and are great to work with transactions. WAL support multiple write threads and implement atomicity and durability So, I’m implementing WAL in LiteDB and BeginTrans() will be back in next major version.

1reaction
mbdavidcommented, Nov 4, 2017

Hi @ovule, problems with concurrency was not about using rollback journal, but way I implemented locks. Yes, using rollback journal needs lock file in write mode and lock readers too. I read about WAL long time ago and don’t was interested… until now. Reading in sqlite, WAL can be very useful to avoid writer lock reader… I will try this… thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transaction Proposal Definition: 243 Samples
Define Transaction Proposal. means any unsolicited written bona fide proposal made by a third party relating to (i) any direct or indirect acquisition...
Read more >
Proposed Transaction Definition: 737 Samples
Proposed Transaction means acquisition of management control or acquisition of assets or any other transaction as envisaged in the Resolution Plan. Sample 1 ......
Read more >
How would you define "Proposed Transaction" in a legal ...
Proposed Transaction. ' is: Atlassian anticipates that it would acquire the Company through a reverse triangular merger (the "Proposed Transaction").
Read more >
proposed transaction collocation | meaning and examples of use
an occasion when someone buys or sells something, or when money is exchanged or the activity of buying or ... See more at...
Read more >
How To Propose A Multisig Transaction
To propose a transaction, submit a transaction to the propose action of the eosio.msig account. Serializing Actions. The data field of the propose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found