advanced.write-flags.txt 2.4 KB

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