1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- Title: Write Queries Flags
- Author: Dariusz Górecki <darek.krk@gmail.com>
- ---
- > [important]
- > ### Quote from PHP Manual:
- >
- > #### "safe"
- > Can be a boolean or integer, defaults to FALSE. If FALSE, the program continues executing without waiting
- for a database response. If TRUE, the program will wait for the database response and throw a MongoCursorException
- if the write operation did not succeed.
- > If you are using replication and the master has changed, using "safe" will make the driver disconnect from
- the master, throw and exception, and attempt to find a new master on the next operation (your application must
- decide whether or not to retry the operation on the new master).
- > If you do not use "safe" with a replica set and the master changes, there will be no way for the driver
- to know about the change so it will continuously and silently fail to write.
- > If safe is an integer, will replicate the insert to that many machines before returning success (or throw
- an exception if the replication times out, see wtimeout).
- This overrides the w variable set on the collection.
- > #### "fsync"
- > Boolean, defaults to FALSE. Forces the insert to be synced to disk before returning success. If TRUE, a safe
- insert is implied and will override setting safe to FALSE.
- <!-- # -->
- We now can set value for write queries flags FSync and/or Safe on a different scopes:
- - Global scope, by setting it in EMongoDB component class itself (required)
- - Model scope, bu using `ModelClass::model()->setFsyncFlag($flagValue)` or `ModelClass::model()->setSafeFlag($flagValue)`
- - Single Model object by using `$singleModelObject->sefFsyncFlag($flag)` or `$singleModelObject->sefSafeFlag($flag)`
- > [important]
- > ### State of write queries flags is connected
- > Setting FSync to `TRUE`, will set Safe flag to `TRUE` automatically
- Now, we may want all DB operations to be synced to disk, and we set global FSync flag in MongoDB component config,
- but we feagure out that, for ie. massive temporary models like DB logging objects are not important, and for performance
- reasons, we whant to disable FSync for this models only.
- We may do so: `LogModelClass::model()->setFsyncFlag(false);`
- From now on, all LogModelClass objects will be written to DB without waiting to filesystem sync.
- For user comfort, FSync and Safe flags may be set just for single model instance by, `$singleModelInstance->setFsyncFlag(false)`,
- this will not affect any other model instance.
|