Transaction never completes when using DatabaseCommands.Put

178 views
Skip to first unread message

Lars Udengaard

unread,
Apr 26, 2012, 6:59:34 AM4/26/12
to ravendb
Hi,

When using DocumentStore.DatabaseCommands.Put in a transactionscope,
it seems like the transaction is never completed.
The following test gives this error:
Raven.Client.Exceptions.NonAuthoritativeInformationException: Document
TheDocuments/1 returned Non Authoritative Information (probably
modified by a transaction in progress) and
AllowNonAuthoritativeInformation is set to false

Here is the failing test. The problem is the same for both embedded
and regular DocumentStore:
https://gist.github.com/2498717

public class TheTest
{
[Fact]
public void transaction_can_commit_when_using_embedded_store()
{
using (var store = new EmbeddableDocumentStore
{
RunInMemory = true,
})
{
store.Initialize();

string id;
using (var session = store.OpenSession())
{
var document = new TheDocument();
session.Store(document);
session.SaveChanges();
id = document.Id;
}

using (var tx = new
TransactionScope(TransactionScopeOption.RequiresNew,
TimeSpan.FromMinutes(10)))
{
var jsonDocument = store.DatabaseCommands.Get(id);
var ravenJObject = jsonDocument.DataAsJson;
store.DatabaseCommands.Put(id, null, ravenJObject,
jsonDocument.Metadata);
tx.Complete();
}

using (var session = store.OpenSession())
{
session.Advanced.AllowNonAuthoritativeInformation =
false;
Assert.DoesNotThrow(() =>
session.Load<TheDocument>(id));
}
}
}

public class TheDocument
{
public string Id { get; set; }
public string TheProp { get; set; }
}
}

Can anyone help? :)

/Lars

Lars Udengaard

unread,
Apr 26, 2012, 8:34:38 AM4/26/12
to ravendb
I forgot to mention, i am using build 888.

Oren Eini (Ayende Rahien)

unread,
Apr 27, 2012, 3:35:29 PM4/27/12
to rav...@googlegroups.com
The transaction enlistment is actually handled by the session, not the database commands object.
You need to use a session for this.
If you want to use commands, use Defer, and then call SaveChanges()

Chris Marisic

unread,
May 1, 2012, 2:28:26 PM5/1/12
to rav...@googlegroups.com
Can you elaborate on this? Suppose:

var commandDatas = new List<ICommandData> { i have commands }

Is this the expected behavior?

unreliable, non transactional {
Session.Advanced.DatabaseCommands.Batch(commandDatas); 
}

consistent, transactional {
Session.Advanced.Defer(commandDatas);
Session.SaveChanges()

Oren Eini (Ayende Rahien)

unread,
May 2, 2012, 12:50:28 AM5/2/12
to rav...@googlegroups.com
Chris,
Both of which would be transactional, in the sense of ACID.

The problem is what happens when you use DTC with this, the first will not work (it will run under the transaction, but won't enlist to it, so it will never get the commit notification.
Reply all
Reply to author
Forward
0 new messages