Raven DB replication not working with ApiKey and Client .NET API

456 views
Skip to first unread message

Satish Harnol

unread,
Feb 20, 2013, 6:14:45 PM2/20/13
to rav...@googlegroups.com

 Raven DB client API not able to make graceful connection with slave server when master is unavailable.

In my web application I am using Raven DB Client .NET API (NuGet package v 2.0.2261 ) to talk with Raven DB server(database).

 I am following below steps with Master – Master replication

 1)      Host 2 Raven DB servers (A and B) in IIS.

 2)      Perform below steps on both server

a.       Create database with expiration and replication bundle.

b.      Create / Add windows Authentication user and assign database.

c.       Create API Key.

d.       Assign API Key to database.

e.      Setup replication settings (Url, Client visible Url, database, domain and ApiKey).

 Till here replication works fine (as observed from studio).

 For scalability testing

a)      Run application, observed documents got created/modified on server A are replicated on server B

b)      Took down Raven DB server A (by stopping IIS App Pool)

c)       Run application again. This time application not able to establish connection with Server B (as Server A is down). It throw exception “The remote server returned an error: (503) Server Unavailable.”

                 Raven.Abstractions.OAuth.SecuredAuthenticator.DoOAuthRequest(String oauthSource) in c:\Builds\RavenDB-Stable\Raven.Abstractions\OAuth\SecuredAuthenticator.cs:143

 Please suggest what steps I am missing ?

 Thanks

Satish

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2013, 1:15:45 AM2/21/13
to ravendb
Hm...
That most certainly should work.
Note that we will NOT be using the replication API Key in the client, the API Key that you define on the client needs to work on all servers.
Possibly it is that.


Satish

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chris Marisic

unread,
Feb 21, 2013, 8:25:08 AM2/21/13
to rav...@googlegroups.com
If the application is using Master as the configured connection string, does it store the Slave connection string in isolated storage or something? Otherwise with application being restarted and told to connect to Master how would it know where Slave is?

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2013, 9:45:19 AM2/21/13
to ravendb
Yes, it stores the data in isolated storage to survive restarts.

Satish Harnol

unread,
Feb 21, 2013, 10:30:49 AM2/21/13
to rav...@googlegroups.com

Thanks for reply
 
API Keys are setup on each server. My application able to talk with server A and server B by providing connection string having API Key of respective server.
 
When I debug inside Rave DB .NET API, I Observed below
1) When both server (A & B) are up, application able to talk with A and B will do replication
2) When I took down server A;  then API will make attempt to save data on server A which failed (with status code 503 Service Unavailable). Now API make call to sever B and able to read data.
3) Modify object accessed on step 2
4) Try to save object modified on step 3. When application try to save data; attempts to save on server A failed (as A is down so its correct). then attempt made to save data on server B also failed with web exception (The remote server returned an error: (401) Unauthorized.)
 
Please suggest what went wrong on step 4 ?
 
Thanks
Satish

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2013, 10:36:28 AM2/21/13
to ravendb
You need to use the _same_ API Key that would work on both servers.
You can do that by taking the Raven/ApiKeys/NAME document from Server A and putting it on Server B.

Failover will not be using the API key from the replication information.

Satish Harnol

unread,
Feb 21, 2013, 10:47:20 AM2/21/13
to rav...@googlegroups.com
How can I match same API Key on both servers ? Rave DB studio not allowing copy / paste Secret value in API Key. Only option available in Studio is to generate secret ?
 
Thanks
Satish

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2013, 11:23:01 AM2/21/13
to ravendb
You can do that by taking the Raven/ApiKeys/NAME document from Server A and putting it on Server B.

Satish Harnol

unread,
Feb 21, 2013, 11:42:20 AM2/21/13
to rav...@googlegroups.com
Thanks for reply; it helped.
 
I match API Key on both servers. Both servers are accessible directly from web application. 
Now I am getting below exception when server A is down and application (raven DB .NET API) try to save data on Server B
 
The remote server returned an error: (412) Precondition Failed.
 
Please suggest.
 
Thanks in advance.
Satish

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2013, 11:43:03 AM2/21/13
to ravendb
Can you send us a fiddler capture?

Satish Harnol

unread,
Feb 21, 2013, 1:48:56 PM2/21/13
to rav...@googlegroups.com
I am working on fiddler capture.
 
Mean while some more explanation about exception as below
 
Exception occured in ReadJsonInternal method of HttpJsonRequest.cs file. Its WebException with message The remote server returned an error: (412) Precondition Failed.

Response property of WebException object has HttpWebResponse with below header
 
{Cache-Control: private\r\nServer: Microsoft-IIS/8.0\r\nOAuth-Source: http://localhost:50041/OAuth/API-Key\r\nWWW-Authenticate: Bearer realm="Raven",
error="invalid_request",error_description="The access token is required"\r\nX-AspNet-Version: 4.0.30319\r\nX-Powered-By: ASP.NET\r\nDate: Thu, 21 Feb 2013 18:40:45 GMT\r\nContent-Length: 0\r\n\r\n}
 
Thanks
Satish

Satish Harnol

unread,
Feb 21, 2013, 3:32:48 PM2/21/13
to rav...@googlegroups.com
It worked when I change  AnonymousAccess access from Get to All in server B web.config.
 
With current workable below are settings that I am using
 
Server A and B has same below configuration
1)  IIS settings
    a) authentication enabled for Anonymous and Windows
    b) Authorization allow all users
2) Raven DB Server level Same API Key
3) Server web config
     a) Server A (Master) has <add key="Raven/AnonymousAccess" value="Get"/>
     b) Server B (Replication) has <add key="Raven/AnonymousAccess" value="All"/>
 
With above settings it is working smoothly.
 
Question is why it required AnonymousAccess = All on replication server ?
 
Thanks
Satish

Oren Eini (Ayende Rahien)

unread,
Feb 22, 2013, 8:07:51 AM2/22/13
to ravendb
Likely because it can't auth against server B.
When I'll have the fiddler trace, I'll be able to tell you why that is the case.

Satish Harnol

unread,
Feb 22, 2013, 8:53:00 AM2/22/13
to rav...@googlegroups.com
Thanks for response.
 
I tried to capture fiddler trace, but I noticed that fiddler is not capturing request for server B when server A is down. With Visual studio debug I can see clearly that Raven DB .NET API is calling server B.
 
Any suggestions to catch fiddler ?
 
Thanks
Satish

Reply all
Reply to author
Forward
0 new messages