Setting up RavenDB as LocalService fails to start

109 views
Skip to first unread message

Kyle Levien

unread,
May 4, 2021, 6:00:02 PM5/4/21
to RavenDB - an awesome database
We are attempting to set up a RavenDB in our product installer and are using the rvn.exe windows-service register tool with the default LocalService user. We also then get the SID of the new service and add permissions for that identity to the DB directory and attempt to start the service. The service fails to start without any helpful message in the alert popup, ravendb log, or event logs. Manually adding the same permissions to the current user on the machine and running run.ps1 in powershell revealed the following exception:

System.InvalidOperationException: Unable to start the server due to invalid certificate configuration! Admin assistance required. ---> System.InvalidOperationException: Could not load certificate file C:\sites\locService\db\Server\server.certificate.igx.pfx ---> Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Access denied

This certificate is a self-signed certificate generated earlier using System.Security.Cryptography.X509Certificates from an installer option and imported into the local machine root.

Does anyone have any tips on what we might be doing wrong or what we're missing?

Igal Merhavia

unread,
May 5, 2021, 3:18:38 AM5/5/21
to rav...@googlegroups.com
Hi,

Can it be an anti-virus that causes the "Access denied"?

Best regards,
Igal

--
You received this message because you are subscribed to the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/bb167353-7967-4505-848c-3a6686d49568n%40googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
May 5, 2021, 10:11:56 AM5/5/21
to ravendb
It looks like the service user doesn't have access to the directory to real the pfx file?



--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  

Oren Eini (Ayende Rahien)

unread,
May 5, 2021, 10:12:08 AM5/5/21
to ravendb
Or doesn't have permissions to load a certificate entirely.

Kyle Levien

unread,
May 5, 2021, 5:33:07 PM5/5/21
to RavenDB - an awesome database
I've checked the localservice user permission to the directory and it's all set to full access.
I've also tried giving the service user access to the Rsa/MachineKeys directory on the machine with no luck.
What specific certificate loading permission are you referencing here?

>  Or doesn't have permissions to load a certificate entirely.

Kyle Levien

unread,
May 5, 2021, 5:36:32 PM5/5/21
to RavenDB - an awesome database
One other thing I'll add. Allowing the local users group access to the MachineKeys directory lets me run raven via run.ps1 while not in an administrator powershell. My hunch is the service was throwing the same access denied message that run.ps1 was, but it continues to fail. I cannot see the exact exception in the service as it does not return anything useful in the alert popup, event logs, or raven logs.

Egor Shamanaev

unread,
May 11, 2021, 6:27:44 AM5/11/21
to rav...@googlegroups.com
Hi Kyle,

Which user is running the RavenDB service? Can you make sure that it has access to the MachineKeys directory ? 

Can you try to run the service using different user and see if this works?



--
Egor
Developer   /   Hibernating Rhinos LTD

Kyle Levien

unread,
May 11, 2021, 12:08:53 PM5/11/21
to rav...@googlegroups.com
Hi Egor,
That was actually the solution I just worked out yesterday. The LocalService integrated user uses the AuthenticatedUser permission group, which did not have access to the MachineKeys directory. Adding that has resolved our issue.
Thanks,
Kyle

You received this message because you are subscribed to a topic in the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/4DYvR4uwAbk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/CAJvo4-kZskoiYnTF%3DbRPFOhwz1n8VmEgBD7Ycg_A02%3Dg3L8TCg%40mail.gmail.com.

Ryan Heath

unread,
May 11, 2021, 3:10:50 PM5/11/21
to rav...@googlegroups.com
I'm in the process to investigate an upgrade from 3.x to 5.x ravendb.

We used the HiLoKeyGenerator to get an id before a document is added into the db.
So we could link another document with it and store both changes in one go.

Something like:

var doc = new Doc();
var docId = hilo.NextId(documentStore.DatabaseCommands);
docid.Id += docId;
session.Store(doc);

treeOfDocs.Add(docId);
session.Store(treeOfDocs);

session.SaveChanges(); // saves both changes in one transaction

How do we do such in RavenDB 5.x?

// Ryan

Igal Merhavia

unread,
May 12, 2021, 4:12:52 AM5/12/21
to rav...@googlegroups.com
Hi,

You don’t need to call the hilo.NextId.
Just call session.Store and it will handle that behind the scene inside the session.Store.

var doc = new Doc();
session.Store(doc);treeOfDocs.Add(docId);
session.Store(treeOfDocs);

session.SaveChanges(); // saves both changes in one transaction


Best regards,
Igal

--
You received this message because you are subscribed to the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Ryan Heath

unread,
May 12, 2021, 6:22:41 AM5/12/21
to rav...@googlegroups.com
Hi Igal, 

Yes I know about that, but that is not working for my scenario. 

I need to know the id upfront, because the newly created doc’s id should be added to another document. And I want to do this in the same transaction. 

// Ryan

Igal Merhavia

unread,
May 12, 2021, 7:14:56 AM5/12/21
to rav...@googlegroups.com
Hi,

You can get it from the id property before the SaveChanges.

var doc = new Doc();
session.Store(doc);
treeOfDocs.Add(doc.Id); // first option if your class contains id property
treeOfDocs.Add(session.Advanced.GetDocumentId(comment)); // second option if your class does not contain id property
session.Store(treeOfDocs);

session.SaveChanges(); // saves both changes in one transaction

Best regards,
Igal

Ryan Heath

unread,
May 12, 2021, 7:38:05 AM5/12/21
to rav...@googlegroups.com
Ok, I get it, that should work. 

Thanks!

// Ryan

Ryan Heath

unread,
May 12, 2021, 12:33:03 PM5/12/21
to rav...@googlegroups.com
It works, but the generated ids are unexpectedly large, and they are not using the hilo document that is stored in the database.

What we did in 3.x is prefix the id another id and added the hilo

doc.id = "targets/123/docs/" + docsHilo.NextId()

But in 5.x we get an id padded with zero and the numeric id is way larger than the hilo document in the database.
For instance: "targets/123/docs/0000000000000247947-B"

The B node postfix is not really an issue, but I'd rather have no zero padding and a numeric value that uses the docs hilo in the database.
Perhaps it is possible with custom conventions? But I do not see how.

// Ryan

Ryan Heath

unread,
May 12, 2021, 8:03:11 PM5/12/21
to rav...@googlegroups.com
I end up using 

var doc = new Doc();
var docId =  documentStore.Conventions.GenerateDocumentId(documentStore.Database, doc);  
docid.Id += docId;
session.Store(doc);

treeOfDocs.Add(docId);
session.Store(treeOfDocs);

session.SaveChanges(); // saves both changes in one transaction


It would have been great(er) if a certain separator could support such behavior, mixing Hilo generated ids with a prefix.

Currently, this is already supported:
null => hilo => docs/1-A
prefix/ => server side id => prefix/0000000000000001-A

Mixed behavior could end with a \ separator (or another separator if \ is not possible)
prefix\ => hilo mixed with given prefix => prefix/docs/1-A

// Ryan



 

Ryan Heath

unread,
May 14, 2021, 9:19:50 AM5/14/21
to rav...@googlegroups.com
In RavenDB 3.x we use 
session.Advanced.UseOptimisticConcurrency = true;

we read 

using (var session = store.OpenSession(new SessionOptions
{
    TransactionMode = TransactionMode.ClusterWide
}))

and also

You can store, delete and edit documents and the session will track them as usual.

we see a fairly amount CompareExchangeValue usage involved.

1. Are we required to do CompareExchangeValue on certain attributes? Is this something RavenDB can not figure out itself?
2. Does it make sense to use OptimisticConcurrency in a cluster setup, don't we always want a (expensive) cluster wide transaction?

// Ryan (making his first steps into RavenDB 5.x :) )

Igal Merhavia

unread,
May 16, 2021, 2:28:12 AM5/16/21
to rav...@googlegroups.com
Hi,

In RavenDB any node in the database group can receive write requests.
So there can be simultaneous modifications to the same document.
In this case, when the nodes try to replicate the document they will get conflict - https://ravendb.net/docs/article-page/4.2/csharp/server/clustering/replication/replication-conflicts.
If your logic cannot stand a conflict you should use cluster-wide transaction.
If you want to prevent an override of document you should use cluster-wide transaction combines with compare exchange.
The common use case is registering a new user with a unique username.
You want it to be unique and you want it to stay valid after the user got confirmation about registration.
But those kinds of operations have cost in a matter of time and you should prevent them as possible.

Patch, counters, resolve conflict .etc are some techniques to achieve that.

Recently we open an issue to simplify the use of compare exchange with cluster-wide transactions and you can read and follow it here - https://issues.hibernatingrhinos.com/issue/RavenDB-16614

Best regards,
Igal


--
You received this message because you are subscribed to the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Ryan Heath

unread,
May 16, 2021, 7:53:02 AM5/16/21
to rav...@googlegroups.com
Hi Igal,

Thanks for your response.

What I still fail to grok is in what cluster wide transactions are different from compare exchanges.

Basically I have 2 needs:
1 uniqueness like a username
2 and protection of resource allocation (I cannot have two users allocate the same resource a the same time)

With RavenDB 3.x point 1 is protected by an id. Point 2 is protected by optimistic concurrency.

How would we do these points in RavenDB 5.x?

Also, how would we test these situations? The test runner seems to always start with a single node.

// Ryan

Oren Eini (Ayende Rahien)

unread,
May 18, 2021, 9:13:07 AM5/18/21
to ravendb
You can call to the hilo directly, create (and hold as a singleton) a AsyncHiLoIdGenerator and then call to:GetDocumentIdFromId


Igal Merhavia

unread,
May 18, 2021, 10:35:47 AM5/18/21
to rav...@googlegroups.com

Oren Eini (Ayende Rahien)

unread,
May 19, 2021, 8:15:08 AM5/19/21
to ravendb
To expand on that, we are adding a new feature for 5.2 which will ensure atomic writes for documents using cluster wide transactions.
That would mean that you don't need to explicitly use compare exchange values. 

Ryan Heath

unread,
May 19, 2021, 8:40:01 AM5/19/21
to rav...@googlegroups.com
Ayende, can you give an estimate on the release of 5.2?

// Ryan

Oren Eini (Ayende Rahien)

unread,
Jul 15, 2021, 7:17:26 AM7/15/21
to ravendb
Just circling back to it, this has been released in 5.2

Ryan Heath

unread,
Jul 15, 2021, 7:23:22 AM7/15/21
to rav...@googlegroups.com
Yes, it is on my radar.
Waiting for a blog post about it ;)

// Ryan

Oren Eini (Ayende Rahien)

unread,
Aug 1, 2021, 9:16:12 AM8/1/21
to ravendb
Reply all
Reply to author
Forward
0 new messages