Runner.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. "use strict";
  2. /**
  3. * This class is an implementation of the base class for runners used in MongoDB
  4. *
  5. * Note that a lot of stuff here is not used by our code yet. Check the existing implementations
  6. * for what we currently use
  7. *
  8. **/
  9. var klass = module.exports = function Runner(){
  10. }, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  11. klass.RunnerState = {
  12. // We successfully populated the out parameter.
  13. RUNNER_ADVANCED: "RUNNER_ADVANCED",
  14. // We're EOF. We won't return any more results (edge case exception: capped+tailable).
  15. RUNNER_EOF: "RUNNER_EOF",
  16. // We were killed or had an error.
  17. RUNNER_DEAD: "RUNNER_DEAD",
  18. // getNext was asked for data it cannot provide, or the underlying PlanStage had an
  19. // unrecoverable error.
  20. // If the underlying PlanStage has any information on the error, it will be available in
  21. // the objOut parameter. Call WorkingSetCommon::toStatusString() to retrieve the error
  22. // details from the output BSON object.
  23. RUNNER_ERROR: "RUNNER_ERROR"
  24. };
  25. klass.YieldPolicy = {
  26. // Any call to getNext() may yield. In particular, the runner may be killed during any
  27. // call to getNext(). If this occurs, getNext() will return RUNNER_DEAD.
  28. //
  29. // If you are enabling autoyield, you must register the Runner with ClientCursor via
  30. // ClientCursor::registerRunner and deregister via ClientCursor::deregisterRunnerwhen
  31. // done. Registered runners are informed about DiskLoc deletions and Namespace
  32. // invalidations and other important events.
  33. //
  34. // Exception: This is not required if the Runner is cached inside of a ClientCursor.
  35. // This is only done if the Runner is cached and can be referred to by a cursor id.
  36. // This is not a popular thing to do.
  37. YIELD_AUTO: "YIELD_AUTO",
  38. // Owner must yield manually if yields are requested. How to yield yourself:
  39. //
  40. // 0. Let's say you have Runner* runner.
  41. //
  42. // 1. Register your runner with ClientCursor. Registered runners are informed about
  43. // DiskLoc deletions and Namespace invalidation and other important events. Do this by
  44. // calling ClientCursor::registerRunner(runner). This could be done once when you get
  45. // your runner, or per-yield.
  46. //
  47. // 2. Call runner->saveState() before you yield.
  48. //
  49. // 3. Call RunnerYieldPolicy::staticYield(runner->ns(), NULL) to yield. Any state that
  50. // may change between yields must be checked by you. (For example, DiskLocs may not be
  51. // valid across yielding, indices may be dropped, etc.)
  52. //
  53. // 4. Call runner->restoreState() before using the runner again.
  54. //
  55. // 5. Your runner's next call to getNext may return RUNNER_DEAD.
  56. //
  57. // 6. When you're done with your runner, deregister it from ClientCursor via
  58. // ClientCursor::deregister(runner).
  59. YIELD_MANUAL: "YIELD_MANUAL"
  60. };
  61. /**
  62. * Set the yielding policy of the underlying runner. See the RunnerYieldPolicy enum above.
  63. *
  64. * @method setYieldPolicy
  65. * @param [policy]
  66. */
  67. proto.setYieldPolicy = function setYieldPolicy(policy) {
  68. throw new Error('Not implemented');
  69. };
  70. /**
  71. * Get the next result from the query.
  72. *
  73. * If objOut is not NULL, only results that have a BSONObj are returned. The BSONObj may
  74. * point to on-disk data (isOwned will be false) and must be copied by the caller before
  75. * yielding.
  76. *
  77. * If dlOut is not NULL, only results that have a valid DiskLoc are returned.
  78. *
  79. * If both objOut and dlOut are not NULL, only results with both a valid BSONObj and DiskLoc
  80. * will be returned. The BSONObj is the object located at the DiskLoc provided.
  81. *
  82. * If the underlying query machinery produces a result that does not have the data requested
  83. * by the user, it will be silently dropped.
  84. *
  85. * If the caller is running a query, they probably only care about the object.
  86. * If the caller is an internal client, they may only care about DiskLocs (index scan), or
  87. * about object + DiskLocs (collection scan).
  88. *
  89. * Some notes on objOut and ownership:
  90. *
  91. * objOut may be an owned object in certain cases: invalidation of the underlying DiskLoc,
  92. * the object is created from covered index key data, the object is projected or otherwise
  93. * the result of a computation.
  94. *
  95. * objOut will also be owned when the underlying PlanStage has provided error details in the
  96. * event of a RUNNER_ERROR. Call WorkingSetCommon::toStatusString() to convert the object
  97. * to a loggable format.
  98. *
  99. * objOut will be unowned if it's the result of a fetch or a collection scan.
  100. *
  101. * @method getNext
  102. * @param [callback] {Function}
  103. */
  104. proto.getNext = function getNext(callback) {
  105. throw new Error('Not implemented');
  106. };
  107. /**
  108. * Will the next call to getNext() return EOF? It's useful to know if the runner is done
  109. * without having to take responsibility for a result.
  110. *
  111. * @method isEOF
  112. */
  113. proto.isEOF = function isEOF(){
  114. throw new Error('Not implemented');
  115. };
  116. /**
  117. * Inform the runner about changes to DiskLoc(s) that occur while the runner is yielded.
  118. * The runner must take any actions required to continue operating correctly, including
  119. * broadcasting the invalidation request to the PlanStage tree being run.
  120. *
  121. * Called from CollectionCursorCache::invalidateDocument.
  122. *
  123. * See db/invalidation_type.h for InvalidationType.
  124. *
  125. * @method invalidate
  126. * @param [dl]
  127. * @param [type]
  128. */
  129. proto.invalidate = function invalidate(dl, type) {
  130. throw new Error('Not implemented');
  131. };
  132. /**
  133. * Mark the Runner as no longer valid. Can happen when a runner yields and the underlying
  134. * database is dropped/indexes removed/etc. All future to calls to getNext return
  135. * RUNNER_DEAD. Every other call is a NOOP.
  136. *
  137. * The runner must guarantee as a postcondition that future calls to collection() will
  138. * return NULL.
  139. *
  140. * @method kill
  141. */
  142. proto.kill = function kill() {
  143. throw new Error('Not implemented');
  144. };
  145. /**
  146. * Save any state required to yield.
  147. *
  148. * @method saveState
  149. */
  150. proto.saveState = function saveState() {
  151. throw new Error('Not implemented');
  152. };
  153. /**
  154. * Restore saved state, possibly after a yield. Return true if the runner is OK, false if
  155. * it was killed.
  156. *
  157. * @method restoreState
  158. */
  159. proto.restoreState = function restoreState() {
  160. throw new Error('Not implemented');
  161. };
  162. /**
  163. * Return the NS that the query is running over.
  164. *
  165. * @method ns
  166. */
  167. proto.ns = function ns() {
  168. throw new Error('Not implemented');
  169. };
  170. /**
  171. * Return the Collection that the query is running over.
  172. *
  173. * @method collection
  174. */
  175. proto.collection = function collection() {
  176. throw new Error('Not implemented');
  177. };
  178. /**
  179. * Returns OK, allocating and filling '*explain' or '*planInfo' with a description of the
  180. * chosen plan, depending on which is non-NULL (one of the two should be NULL). Caller
  181. * takes onwership of either '*explain' and '*planInfo'. Otherwise, returns false
  182. * a detailed error status.
  183. *
  184. * If 'explain' is NULL, then this out-parameter is ignored. Similarly, if 'staticInfo'
  185. * is NULL, then no static debug information is produced.
  186. *
  187. * @method getInfo
  188. * @param [explain]
  189. * @param [planInfo]
  190. */
  191. proto.getInfo = function getInfo(explain, planInfo) {
  192. throw new Error('Not implemented');
  193. };
  194. /**
  195. * dispose of the Runner.
  196. *
  197. * @method reset
  198. */
  199. proto.reset = function reset(){
  200. throw new Error('Not implemented');
  201. };