Open ShauneStark opened 8 years ago
Hi, Error raised is - not_master. You are trying to read from master or slave? What are your read preferences?
I'm new to Elixir/Erlang, but from the Mongo docs, I thought I would be able to read from secondary servers by specifying rp_mode
= secondary
or secondaryPreferred
, but the driver returns an error when I reference a topology with that rp_mode
selected... Am I misunderstanding the Mongo driver specs or am I mis-configuring the driver? I seed it with 3 mongo servers in our replica set, one of which is primary of course. We would like for reads to be able to continue even if the primary goes down, but since we cannot read from a secondary at all, we cannot test that scenario.
Please, show the code of randomlyreadrecords/2
def randomlyreadrecords(:mytopology, mongodbmap) do
Logger.info "Starting Reads from: " <> mongodbmap.collection
numrandom = :rand.uniform(100000)
maxnumberreads = 1000000
currentreadnumber = 1
MUVPROC.read(:mytopology, mongodbmap, numrandom, currentreadnumber, maxnumberreads)
Logger.info "Ending Reads from: " <> mongodbmap.collection
{:ok, %{}}
end
def read(:mytopology, mongodbmap, numrandom, currentreadnumber, maxnumberreads) do
record = :mongoc.transaction_query(
:mytopology,
fn(worker) ->
:mongoc.find_one(worker, mongodbmap.collection, %{}, %{}, numrandom)
end,
[],
5000
)
IO.inspect(record)
numrandom = :rand.uniform(100000)
currentreadnumber = currentreadnumber + 1
read(:mytopology, mongodbmap, numrandom, currentreadnumber, maxnumberreads)
end
The thing is - you create a connection and specify {:rp_mode, :primary}
.
When you use :mongoc.transaction_query
you did not specify your read preference, so driver takes primary (which is default) and which you specified on start.
Request comes to slave - so error not master
returns.
Do you have master in your hostlist?
When I change the rp_mode to secondary or secondaryPreferred when I create the topology, all reads fail immediately. The code I sent you uses primary because that's the only value that appears to work... When I change it to anything else, I get the no_master error. Do I need to set it to secondary when I create the topology AND when I try to read? IE in both places? I thought if I specified rp_mode in creating the connection/topology that that would be the default for all reads/writes using that connection/topology...
Try to use secondary or secondaryPreferred when reading.
I do not know elexir, but in erlang you should pass proplist [{rp_mode, secondaryPreferred}] to mongoc:transaction_query/3
as third parameter
Just to make sure, when I run this code
# Get MongoDB connection
{:ok, mtconn} = :mongoc.connect(
{:rs, mongodbmapbase.replicasetname, mongodbmapbase.hostlist},
[
{:name, :vertifypool},
{:register, :vertifytopology},
{:rp_mode, :secondaryPreferred}
],
[
{:database, mongodbmapbase.database}
]
)
I still need to specify rp_mode = secondaryPreferred to mongoc:transaction_query/3 ? The reason I ask is because I just tried this and it still returns the erlang error not_master...
read with rp_mode = secondaryPreferred return not_master error?
Yes, sir it did...
hostlist: ['mongo1.mydomain.com:27017', 'mongo2.mydomain.com:27017', 'mongo3.mydomain.com:27017']
who is master in this replica set?
mongo3
I have tried listing the master first, last and in the middle, but it does not seem to make a difference....
Ok, please, try { unknown, ["hostname1:port1", "hostname2:port2"] } instead of rs
Yes, sir... One moment please...
I tried the following:
# Get MongoDB connection
{:ok, mtconn} = :mongoc.connect(
{:unknown, ['mongo1.mydomain.com:27017', 'mongo2.mydomain.com:27017', 'mongo3.mydomain.com:27017']},
[
{:name, :mypool},
{:register, :mytopology},
{:rp_mode, :secondaryPreferred}
],
[
{:database, mongodbmapbase.database}
]
)
And still got the no_master error...
I also removed the mongo3 server from the list and got the same error...
Please try tag v.1.1.4
Changed deps to use tag v1.1.4 and still get the same no_master error, sadly...
@alttagil need your help in mongoc
ShauneStark, may I ask you to email me directly?
I would be happy to email you directly, but I don't see an email address in your profile... You may reach me at sstark@thenewoffice.com if you would rather not publish your email address... Thank you for your willingness to help!
ShauneStark, I've sent an email to you.
I am new to Elixir/Erlang so please excuse me if this question is stupid... I am trying to use this driver from within Elixir, and am connecting to a MongoDB replicaset using the following code:
This code simply reads a record at a random position in the collection until a certain number of reads has been performed, just to support load testing. However, when we try to use any rp_mode other than primary or primaryPreferred we get a not_master error as soon as we try to read a record...
The error I get is:
Any help would be appreciated!!!