difference between safe and sync options in PHP Driver

249 views
Skip to first unread message

Prajwal Tuladhar

unread,
Aug 26, 2010, 3:06:02 PM8/26/10
to mongodb-user
Hi,

Can anyone make me clear on following questions?

http://us3.php.net/manual/en/mongocollection.remove.php
http://us3.php.net/manual/en/mongocollection.insert.php
http://us3.php.net/manual/en/mongocollection.update.php

So does that mean safe and sync option variables when used as boolean
type are same And they are different only when fsync is used as an
integer?

And if I apply fsync, will that apply to slaves / other replica sets
also?

Thanks!

Kristina Chodorow

unread,
Aug 26, 2010, 3:14:31 PM8/26/10
to mongod...@googlegroups.com
safe and fsync are not the same, here's a rundown of the options:

safe => false: do not wait for a db response
safe => true: wait for a db response
safe => num: wait for that many servers to have the write before returning
fsync => true: fsync the write to disk before returning

fsync=>true implies safe=>true, but not visa versa.  If safe=>true, fsync=>false, the write could be in successfully applied to a mmapped file but not yet written to disk. 

Fsync is only applied to the server you're directly connected to, although more options may be available in the future.



--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Prajwal Tuladhar

unread,
Aug 26, 2010, 3:44:25 PM8/26/10
to mongodb-user
Kristina, thanks for the response!

So, lets say if safe => 3 then,does that mean database will wait for
response until write is applied to single master and 3 slaves there
respective mmapped files?

If its true then, safe => number will take more time to succeed than
safe => boolean depending on number of slaves.

On Aug 26, 3:14 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> safe and fsync are not the same, here's a rundown of the options:
>
> safe => false: do not wait for a db response
> safe => true: wait for a db response
> safe => num: wait for that many servers to have the write before returning
> fsync => true: fsync the write to disk before returning
>
> fsync=>true implies safe=>true, but not visa versa.  If safe=>true,
> fsync=>false, the write could be in successfully applied to a mmapped file
> but not yet written to disk.
>
> Fsync is only applied to the server you're directly connected to, although
> more options may be available in the future.
>
> On Thu, Aug 26, 2010 at 3:06 PM, Prajwal Tuladhar <dynamism...@gmail.com>wrote:
>
>
>
> > Hi,
>
> > Can anyone make me clear on following questions?
>
> >http://us3.php.net/manual/en/mongocollection.remove.php
> >http://us3.php.net/manual/en/mongocollection.insert.php
> >http://us3.php.net/manual/en/mongocollection.update.php
>
> > So does that mean safe and sync option variables when used as boolean
> > type are same And they are different only when fsync is used as an
> > integer?
>
> > And if I apply fsync, will that apply to slaves / other replica sets
> > also?
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>
> > .

Kristina Chodorow

unread,
Aug 26, 2010, 3:49:24 PM8/26/10
to mongod...@googlegroups.com
safe=>number includes the master, so 3 would be master+2 slaves.

safe=>number can definitely take a long time to succeed (it'll keep trying even if you only have 1 slave up or your slaves are hours behind).  It'll time out after MongoCollection::wtimeout milliseconds and return failure. 


To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

Prajwal Tuladhar

unread,
Aug 26, 2010, 4:11:10 PM8/26/10
to mongodb-user
So, it seems like use case scenario for safe=>number is quite minimal
unless one wants to have maximum level of consistency.

On Aug 26, 3:49 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> safe=>number includes the master, so 3 would be master+2 slaves.
>
> safe=>number can definitely take a long time to succeed (it'll keep trying
> even if you only have 1 slave up or your slaves are hours behind).  It'll
> time out after MongoCollection::wtimeout milliseconds and return failure.
>

Kristina Chodorow

unread,
Aug 26, 2010, 4:15:41 PM8/26/10
to mongod...@googlegroups.com
I guess it depends on how laggy your slaves are.  If you can keep your slaves up to date, it's the best way of keeping your data safe.  And you don't need to ensure it's made it to all of your slaves, just a majority. 


To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages