pigeonhole-db 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +37 -16
  3. data/Cargo.toml +11 -5
  4. data/extconf.rb +2 -0
  5. data/lib/pigeonhole/api.rb +149 -13
  6. data/lib/pigeonhole/fiber.rb +184 -0
  7. data/lib/pigeonhole/memory.rb +114 -12
  8. data/lib/pigeonhole/version.rb +1 -1
  9. data/lib/pigeonhole.rb +1 -0
  10. data/sig/pigeonhole.rbs +30 -1
  11. data/src/classes.rs +44 -7
  12. data/src/db.rs +54 -0
  13. data/src/feed.rs +62 -113
  14. data/src/fiber.rs +394 -0
  15. data/src/lib.rs +123 -6
  16. data/src/memory.rs +304 -98
  17. data/src/memory_fiber.rs +400 -0
  18. data/src/offload.rs +217 -0
  19. data/src/table.rs +301 -11
  20. data/src/waits.rs +461 -0
  21. data/vendor/bundle/ruby/3.4.0/cache/async-2.46.0.gem +0 -0
  22. data/vendor/bundle/ruby/3.4.0/cache/console-1.38.0.gem +0 -0
  23. data/vendor/bundle/ruby/3.4.0/cache/fiber-annotation-0.2.0.gem +0 -0
  24. data/vendor/bundle/ruby/3.4.0/cache/fiber-local-1.1.0.gem +0 -0
  25. data/vendor/bundle/ruby/3.4.0/cache/fiber-storage-1.0.1.gem +0 -0
  26. data/vendor/bundle/ruby/3.4.0/cache/io-event-1.22.3.gem +0 -0
  27. data/vendor/bundle/ruby/3.4.0/cache/json-3.1.0.gem +0 -0
  28. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/io-event-1.22.3/IO_Event.so +0 -0
  29. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/io-event-1.22.3/gem.build_complete +0 -0
  30. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/io-event-1.22.3/gem_make.out +45 -0
  31. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/io-event-1.22.3/mkmf.log +506 -0
  32. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/json-3.1.0/gem.build_complete +0 -0
  33. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/json-3.1.0/gem_make.out +31 -0
  34. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/json-3.1.0/json/ext/generator.so +0 -0
  35. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/json-3.1.0/json/ext/parser.so +0 -0
  36. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/json-3.1.0/mkmf.log +347 -0
  37. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/prism-1.9.0/gem_make.out +14 -6
  38. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/prism-1.9.0/prism/prism.so +0 -0
  39. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/rbs-4.2.0/gem_make.out +5 -5
  40. data/vendor/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/rbs-4.2.0/rbs_extension.so +0 -0
  41. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/best-practices.md +209 -0
  42. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/debugging.md +63 -0
  43. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/getting-started.md +213 -0
  44. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/index.yaml +31 -0
  45. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/scheduler.md +109 -0
  46. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/tasks.md +453 -0
  47. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/context/thread-safety.md +694 -0
  48. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/barrier.md +41 -0
  49. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/barrier.rb +132 -0
  50. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/cancel.rb +80 -0
  51. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/clock.rb +95 -0
  52. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/condition.md +31 -0
  53. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/condition.rb +65 -0
  54. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/console.rb +42 -0
  55. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/deadline.rb +71 -0
  56. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/error.rb +17 -0
  57. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/fork_handler.rb +32 -0
  58. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/idler.rb +71 -0
  59. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/limited_queue.rb +13 -0
  60. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/list.rb +319 -0
  61. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/loop.rb +84 -0
  62. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/node.rb +347 -0
  63. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/notification.rb +39 -0
  64. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/priority_queue.rb +253 -0
  65. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/promise.rb +266 -0
  66. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/queue.rb +155 -0
  67. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/reactor.rb +34 -0
  68. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/scheduler.rb +710 -0
  69. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/semaphore.md +41 -0
  70. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/semaphore.rb +127 -0
  71. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/stop.rb +10 -0
  72. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/task.rb +549 -0
  73. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/timeout.rb +88 -0
  74. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/variable.rb +64 -0
  75. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/version.rb +9 -0
  76. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async/waiter.rb +61 -0
  77. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/async.rb +13 -0
  78. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/kernel/async.rb +43 -0
  79. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/kernel/barrier.rb +31 -0
  80. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/kernel/sync.rb +43 -0
  81. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/metrics/provider/async/task.rb +20 -0
  82. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/metrics/provider/async.rb +6 -0
  83. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/traces/provider/async/barrier.rb +17 -0
  84. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/traces/provider/async/task.rb +40 -0
  85. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/lib/traces/provider/async.rb +7 -0
  86. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/license.md +58 -0
  87. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/readme.md +118 -0
  88. data/vendor/bundle/ruby/3.4.0/gems/async-2.46.0/releases.md +488 -0
  89. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/bake/console.rb +18 -0
  90. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/command-line.md +47 -0
  91. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/configuration.md +23 -0
  92. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/events.md +71 -0
  93. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/getting-started.md +170 -0
  94. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/index.yaml +28 -0
  95. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/context/integration.md +37 -0
  96. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/adapter.rb +10 -0
  97. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/capture.rb +126 -0
  98. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/clock.rb +48 -0
  99. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/compatible/logger.rb +104 -0
  100. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/config.rb +96 -0
  101. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/event/failure.rb +108 -0
  102. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/event/generic.rb +47 -0
  103. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/event/spawn.rb +111 -0
  104. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/event.rb +13 -0
  105. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/filter.rb +235 -0
  106. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/format/safe.rb +283 -0
  107. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/format.rb +18 -0
  108. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/interface.rb +61 -0
  109. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/logger.rb +66 -0
  110. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/default.rb +51 -0
  111. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/failure.rb +42 -0
  112. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/null.rb +24 -0
  113. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/sensitive.rb +146 -0
  114. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/serialized.rb +102 -0
  115. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/split.rb +39 -0
  116. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/terminal.rb +310 -0
  117. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output/wrapper.rb +39 -0
  118. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/output.rb +36 -0
  119. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/progress.rb +168 -0
  120. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/resolver.rb +120 -0
  121. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/formatter/failure.rb +69 -0
  122. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/formatter/progress.rb +69 -0
  123. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/formatter/spawn.rb +53 -0
  124. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/formatter.rb +16 -0
  125. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/text.rb +129 -0
  126. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal/xterm.rb +91 -0
  127. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/terminal.rb +21 -0
  128. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/version.rb +8 -0
  129. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console/warn.rb +33 -0
  130. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/lib/console.rb +15 -0
  131. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/license.md +34 -0
  132. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/readme.md +122 -0
  133. data/vendor/bundle/ruby/3.4.0/gems/console-1.38.0/releases.md +147 -0
  134. data/vendor/bundle/ruby/3.4.0/gems/fiber-annotation-0.2.0/lib/fiber/annotation/version.rb +10 -0
  135. data/vendor/bundle/ruby/3.4.0/gems/fiber-annotation-0.2.0/lib/fiber/annotation.rb +58 -0
  136. data/vendor/bundle/ruby/3.4.0/gems/fiber-annotation-0.2.0/license.md +21 -0
  137. data/vendor/bundle/ruby/3.4.0/gems/fiber-annotation-0.2.0/readme.md +19 -0
  138. data/vendor/bundle/ruby/3.4.0/gems/fiber-local-1.1.0/lib/fiber/local/version.rb +10 -0
  139. data/vendor/bundle/ruby/3.4.0/gems/fiber-local-1.1.0/lib/fiber/local.rb +56 -0
  140. data/vendor/bundle/ruby/3.4.0/gems/fiber-local-1.1.0/license.md +21 -0
  141. data/vendor/bundle/ruby/3.4.0/gems/fiber-local-1.1.0/readme.md +82 -0
  142. data/vendor/bundle/ruby/3.4.0/gems/fiber-storage-1.0.1/lib/fiber/storage/version.rb +12 -0
  143. data/vendor/bundle/ruby/3.4.0/gems/fiber-storage-1.0.1/lib/fiber/storage.rb +89 -0
  144. data/vendor/bundle/ruby/3.4.0/gems/fiber-storage-1.0.1/license.md +21 -0
  145. data/vendor/bundle/ruby/3.4.0/gems/fiber-storage-1.0.1/readme.md +43 -0
  146. data/vendor/bundle/ruby/3.4.0/gems/fiber-storage-1.0.1/releases.md +5 -0
  147. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/context/futex.md +208 -0
  148. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/context/getting-started.md +93 -0
  149. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/context/index.yaml +15 -0
  150. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/design.md +63 -0
  151. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/Makefile +273 -0
  152. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/extconf.h +16 -0
  153. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/extconf.rb +88 -0
  154. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/array.h +175 -0
  155. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/event.c +41 -0
  156. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/event.h +24 -0
  157. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/fiber.c +63 -0
  158. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/fiber.h +23 -0
  159. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/futex.c +489 -0
  160. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/futex.h +42 -0
  161. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/interrupt.c +100 -0
  162. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/interrupt.h +30 -0
  163. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/list.h +107 -0
  164. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/epoll.c +1194 -0
  165. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/epoll.h +10 -0
  166. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/kqueue.c +1196 -0
  167. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/kqueue.h +10 -0
  168. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/pidfd.c +21 -0
  169. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/selector.c +424 -0
  170. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/selector.h +194 -0
  171. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/uring.c +2017 -0
  172. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/selector/uring.h +10 -0
  173. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/time.c +35 -0
  174. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/time.h +17 -0
  175. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/worker_pool.c +520 -0
  176. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/worker_pool.h +8 -0
  177. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/worker_pool_test.c +205 -0
  178. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/ext/io/event/worker_pool_test.h +9 -0
  179. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/IO_Event.so +0 -0
  180. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/debug/selector.rb +219 -0
  181. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/interrupt.rb +49 -0
  182. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/native.rb +11 -0
  183. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/priority_heap.rb +263 -0
  184. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/selector/nonblock.rb +21 -0
  185. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/selector/select.rb +430 -0
  186. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/selector.rb +62 -0
  187. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/support.rb +16 -0
  188. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/timers.rb +220 -0
  189. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event/version.rb +12 -0
  190. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/lib/io/event.rb +10 -0
  191. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/license.md +42 -0
  192. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/readme.md +101 -0
  193. data/vendor/bundle/ruby/3.4.0/gems/io-event-1.22.3/releases.md +190 -0
  194. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/BSDL +22 -0
  195. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/CHANGES.md +877 -0
  196. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/COPYING +56 -0
  197. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/LEGAL +20 -0
  198. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/README.md +228 -0
  199. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/fbuffer/fbuffer.h +263 -0
  200. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/generator/Makefile +273 -0
  201. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/generator/extconf.rb +19 -0
  202. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/generator/generator.c +2172 -0
  203. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/json.h +202 -0
  204. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/parser/Makefile +273 -0
  205. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/parser/extconf.rb +43 -0
  206. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/parser/parser.c +2925 -0
  207. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/simd/conf.rb +24 -0
  208. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/simd/simd.h +208 -0
  209. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/vendor/fast_float_parser.h +814 -0
  210. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/vendor/fpconv.c +480 -0
  211. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
  212. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/json.gemspec +62 -0
  213. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/common.rb +923 -0
  214. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/ext/generator/state.rb +73 -0
  215. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/ext/generator.so +0 -0
  216. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/ext/parser.so +0 -0
  217. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/ext.rb +195 -0
  218. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/truffle_ruby/generator.rb +828 -0
  219. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json/version.rb +5 -0
  220. data/vendor/bundle/ruby/3.4.0/gems/json-3.1.0/lib/json.rb +460 -0
  221. data/vendor/bundle/ruby/3.4.0/gems/prism-1.9.0/lib/prism/prism.so +0 -0
  222. data/vendor/bundle/ruby/3.4.0/gems/rbs-4.2.0/lib/rbs_extension.so +0 -0
  223. data/vendor/bundle/ruby/3.4.0/specifications/async-2.46.0.gemspec +27 -0
  224. data/vendor/bundle/ruby/3.4.0/specifications/console-1.38.0.gemspec +27 -0
  225. data/vendor/bundle/ruby/3.4.0/specifications/fiber-annotation-0.2.0.gemspec +21 -0
  226. data/vendor/bundle/ruby/3.4.0/specifications/fiber-local-1.1.0.gemspec +25 -0
  227. data/vendor/bundle/ruby/3.4.0/specifications/fiber-storage-1.0.1.gemspec +21 -0
  228. data/vendor/bundle/ruby/3.4.0/specifications/io-event-1.22.3.gemspec +24 -0
  229. data/vendor/bundle/ruby/3.4.0/specifications/json-3.1.0.gemspec +0 -0
  230. data/vendor/cache/Cargo.toml +2 -2
  231. data/vendor/cache/src/lib.rs +60 -23
  232. data/vendor/cache/src/s3fifo.rs +215 -44
  233. data/vendor/cache/src/tests.rs +2 -1
  234. data/vendor/compaction/Cargo.toml +6 -6
  235. data/vendor/engine/Cargo.toml +11 -11
  236. data/vendor/engine/src/clock.rs +14 -0
  237. data/vendor/engine/src/compact.rs +26 -14
  238. data/vendor/engine/src/engine/hooks.rs +88 -13
  239. data/vendor/engine/src/engine/info.rs +5 -2
  240. data/vendor/engine/src/engine.rs +1296 -30
  241. data/vendor/engine/src/error.rs +1 -1
  242. data/vendor/engine/src/feed.rs +408 -40
  243. data/vendor/engine/src/feed_reader.rs +1507 -274
  244. data/vendor/engine/src/flush.rs +45 -5
  245. data/vendor/engine/src/lib.rs +10 -4
  246. data/vendor/engine/src/maintenance.rs +620 -444
  247. data/vendor/engine/src/manifest.rs +157 -7
  248. data/vendor/engine/src/options.rs +34 -2
  249. data/vendor/engine/src/read/keys.rs +106 -12
  250. data/vendor/engine/src/read/knn.rs +35 -3
  251. data/vendor/engine/src/read/reduce.rs +18 -12
  252. data/vendor/engine/src/read/reduce_async.rs +396 -0
  253. data/vendor/engine/src/read/traverse.rs +12 -1
  254. data/vendor/engine/src/read.rs +524 -41
  255. data/vendor/engine/src/row_cache.rs +6 -0
  256. data/vendor/engine/src/shard/tablets.rs +2 -1
  257. data/vendor/engine/src/shard.rs +433 -27
  258. data/vendor/engine/src/snapshot.rs +26 -0
  259. data/vendor/engine/src/source.rs +10 -0
  260. data/vendor/engine/src/watermark_waiters.rs +92 -3
  261. data/vendor/engine/src/write.rs +130 -3
  262. data/vendor/format/Cargo.toml +1 -1
  263. data/vendor/format/src/block.rs +7 -0
  264. data/vendor/format/src/feed.rs +138 -8
  265. data/vendor/format/src/manifest.rs +27 -0
  266. data/vendor/format/src/shm.rs +5 -0
  267. data/vendor/format/src/superblock.rs +3 -2
  268. data/vendor/format/src/version.rs +5 -2
  269. data/vendor/format/src/wal.rs +22 -1
  270. data/vendor/io/Cargo.toml +2 -2
  271. data/vendor/io/src/async_poll.rs +19 -0
  272. data/vendor/io/src/lib.rs +3 -1
  273. data/vendor/io/src/os/unix.rs +30 -0
  274. data/vendor/io/src/os/windows.rs +18 -0
  275. data/vendor/io/src/pread.rs +4 -0
  276. data/vendor/io/src/sim.rs +81 -15
  277. data/vendor/io/src/sys.rs +9 -0
  278. data/vendor/io/src/uring.rs +4 -0
  279. data/vendor/io/src/vfs.rs +10 -0
  280. data/vendor/memory/Cargo.toml +11 -5
  281. data/vendor/memory/README.md +1 -1
  282. data/vendor/memory/src/consolidate.rs +68 -58
  283. data/vendor/memory/src/feed_loop.rs +113 -58
  284. data/vendor/memory/src/forget.rs +63 -37
  285. data/vendor/memory/src/hooks.rs +19 -0
  286. data/vendor/memory/src/ivf.rs +70 -26
  287. data/vendor/memory/src/lib.rs +2 -2
  288. data/vendor/memory/src/recall.rs +865 -231
  289. data/vendor/memory/src/store.rs +405 -135
  290. data/vendor/memtable/Cargo.toml +3 -3
  291. data/vendor/memtable/src/lib.rs +29 -3
  292. data/vendor/memtable/src/tests.rs +35 -0
  293. data/vendor/pager/Cargo.toml +3 -3
  294. data/vendor/pager/src/lib.rs +56 -0
  295. data/vendor/pigeonhole/Cargo.toml +7 -5
  296. data/vendor/pigeonhole/README.md +1 -1
  297. data/vendor/pigeonhole/src/cell.rs +233 -2
  298. data/vendor/pigeonhole/src/db.rs +224 -8
  299. data/vendor/pigeonhole/src/feed.rs +573 -98
  300. data/vendor/pigeonhole/src/files.rs +270 -0
  301. data/vendor/pigeonhole/src/info.rs +7 -2
  302. data/vendor/pigeonhole/src/lib.rs +14 -3
  303. data/vendor/pigeonhole/src/metrics.rs +246 -1
  304. data/vendor/pigeonhole/src/nonblocking.rs +160 -94
  305. data/vendor/pigeonhole/src/options.rs +197 -21
  306. data/vendor/pigeonhole/src/read/budget.rs +178 -51
  307. data/vendor/pigeonhole/src/read.rs +468 -19
  308. data/vendor/pigeonhole/src/recovery.rs +9 -3
  309. data/vendor/pigeonhole/src/replication.rs +648 -0
  310. data/vendor/pigeonhole/src/table.rs +17 -1
  311. data/vendor/pigeonhole/src/write.rs +612 -26
  312. data/vendor/runtime/Cargo.toml +2 -2
  313. data/vendor/runtime/src/cell.rs +832 -0
  314. data/vendor/runtime/src/drivers.rs +210 -69
  315. data/vendor/runtime/src/lib.rs +327 -27
  316. data/vendor/runtime/src/pool.rs +3 -1
  317. data/vendor/runtime/src/sched.rs +5 -1
  318. data/vendor/runtime/src/signal.rs +8 -0
  319. data/vendor/shm/Cargo.toml +3 -3
  320. data/vendor/shm/src/lib.rs +1 -1
  321. data/vendor/shm/src/lock.rs +15 -0
  322. data/vendor/shm/src/region.rs +218 -160
  323. data/vendor/sst/Cargo.toml +4 -4
  324. data/vendor/sst/src/blob.rs +1 -0
  325. data/vendor/sst/src/iter.rs +14 -0
  326. data/vendor/sst/src/lib.rs +1 -0
  327. data/vendor/sst/src/reader.rs +34 -31
  328. data/vendor/text/Cargo.toml +9 -2
  329. data/vendor/text/src/fuzzy.rs +178 -57
  330. data/vendor/text/src/index.rs +84 -19
  331. data/vendor/text/src/maxscore.rs +964 -145
  332. data/vendor/text/src/query.rs +14 -0
  333. data/vendor/text/src/search.rs +413 -84
  334. data/vendor/vector/Cargo.toml +2 -2
  335. data/vendor/vector/src/hooks.rs +8 -0
  336. data/vendor/vector/src/index.rs +59 -10
  337. data/vendor/wal/Cargo.toml +3 -3
  338. data/vendor/wal/src/recovery.rs +17 -29
  339. data/vendor/wal/src/stream.rs +137 -120
  340. metadata +213 -1
@@ -70,16 +70,17 @@ module Pigeonhole
70
70
  end
71
71
 
72
72
  # `verify`'s counts.
73
- # `ivf_mismatched` (how far an IVF index's vector count is from the memories with an
74
- # embedding) and `ivf_counter_drift` (namespaces whose counter is off) are for a quiet
75
- # store, and `consistent?` leaves them out, as the crate does.
73
+ # `ivf_mismatched` counts the memories with an embedding missing from an IVF index plus
74
+ # the index's vectors with no such memory, read at verify's snapshot (#1427), and
75
+ # `consistent?` counts it. `ivf_counter_drift` (namespaces whose counter is off) is
76
+ # advisory, and `consistent?` leaves it out, as the crate does.
76
77
  StoreStats = Data.define(:memories, :no_content, :stale_dedup, :broken_links,
77
78
  :missing_embeddings, :dangling_superseded,
78
79
  :text_index_inconsistent, :ivf_mismatched, :ivf_counter_drift) do
79
80
  # Whether every count of a problem is zero.
80
81
  def consistent?
81
82
  [no_content, stale_dedup, broken_links, missing_embeddings, dangling_superseded].all?(&:zero?) &&
82
- !text_index_inconsistent
83
+ !text_index_inconsistent && ivf_mismatched.zero?
83
84
  end
84
85
  end
85
86
 
@@ -284,7 +285,14 @@ module Pigeonhole
284
285
  # `timeout: nil` waits until a commit comes or the thread is interrupted (perf2's N2 on
285
286
  # #1441). `FeedExpired` once the history it needs is gone.
286
287
  def next(timeout: nil)
287
- c = native_next(timeout)
288
+ b = Native::FiberBridge.current
289
+ c = if b
290
+ r = b.await(native_next_op(b.native),
291
+ deadline: timeout && Native::FiberBridge.deadline(timeout))
292
+ r.equal?(Native::FiberBridge::TIMED_OUT) ? nil : r
293
+ else
294
+ native_next(timeout)
295
+ end
288
296
  c && Build.commit(c)
289
297
  end
290
298
 
@@ -323,12 +331,49 @@ module Pigeonhole
323
331
  # whose block the interrupt lands in is refused as well; a commit already under way
324
332
  # finishes first. (`break` in the block raises `LocalJumpError`, a
325
333
  # `StandardError`: the block outlives the `consolidate_loop` call that took it.)
334
+ #
335
+ # Under a fiber scheduler (ICR 0126), the step's wait for new memories and its wait for
336
+ # the block's groups let the thread's other fibers run, and the block runs on the
337
+ # calling fiber, so it may itself yield (an HTTP call under Async, say). A stop or
338
+ # timeout raised into the step's wait loses nothing (the next step reads what it
339
+ # would have); raised into its passes, the pass still ends first, as an interrupt
340
+ # does, and then it takes effect. A loop's first step starts it without waiting.
326
341
  def run_once(timeout = 1.0)
327
- events, passes, failed, stopped, interrupted, next_due, token = native_run_once(timeout, @consolidator)
342
+ b = Native::FiberBridge.current
343
+ raw = b ? fiber_step(b, timeout) : native_run_once(timeout, @consolidator)
344
+ events, passes, failed, stopped, interrupted, next_due, token = raw
328
345
  pairs = ->(list) { list.map { |ns, p| [ns, ConsolidatePass.new(*p)].freeze }.freeze }
329
346
  LoopStep.new(events, pairs.(passes), failed.map { |ns, e| [ns, e].freeze }.freeze, pairs.(stopped),
330
347
  interrupted, next_due, token)
331
348
  end
349
+
350
+ private
351
+
352
+ # `run_once` under a scheduler: waits through the bridge, one commit at a time, until
353
+ # `timeout` or the next pass falls due, then runs the step's passes, whose groups it
354
+ # also waits for through the bridge.
355
+ def fiber_step(bridge, timeout)
356
+ started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
357
+ events = 0
358
+ while true # rubocop:disable Style/InfiniteLoop -- `loop` would swallow StopIteration
359
+ wait = timeout - (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started)
360
+ due = next_due
361
+ wait = [wait, (due - loop_now_us) / 1e6].min if due
362
+ break if wait <= 0
363
+
364
+ n = bridge.await(native_wait_op(bridge.native), deadline: Native::FiberBridge.deadline(wait))
365
+ # 0: the loop hasn't stepped yet (its step starts it), or its history was recycled.
366
+ break if n.equal?(Native::FiberBridge::TIMED_OUT) || n.zero?
367
+
368
+ events += n
369
+ end
370
+ native_run_once_fiber(bridge, events, @consolidator)
371
+ end
372
+
373
+ # The loop's clock now (µs since the Unix epoch), with its `clock_offset:`.
374
+ def loop_now_us
375
+ Process.clock_gettime(Process::CLOCK_REALTIME, :microsecond) + @clock_offset_us.to_i
376
+ end
332
377
  end
333
378
 
334
379
  # The recall methods `Store` and `ReadStore` share.
@@ -355,7 +400,8 @@ module Pigeonhole
355
400
  now_us:, half_life:, fusion:, weights:, include_superseded:,
356
401
  session:, with_signals:, with_embeddings:, expand:, exact:,
357
402
  nprobe:)
358
- Build.hits(native_recall(args))
403
+ b = Native::FiberBridge.current
404
+ Build.hits(b ? b.await(native_recall_op(b.native, args)) : native_recall(args))
359
405
  end
360
406
 
361
407
  # One memory, or nil.
@@ -386,6 +432,7 @@ module Pigeonhole
386
432
  def create(db, name, embedding: nil, forget: nil, episodic_ttl: nil, near_dedup: nil,
387
433
  normalization: nil, ivf: nil, &)
388
434
  s = native_create(db, name, embedding, forget, episodic_ttl, near_dedup, normalization, ivf)
435
+ s.instance_variable_set(:@db, db)
389
436
  block_given? ? scoped(s, &) : s
390
437
  end
391
438
 
@@ -395,6 +442,7 @@ module Pigeonhole
395
442
  # `remember` or `supersede`).
396
443
  def open(db, name, model:, &)
397
444
  s = native_open(db, name, model)
445
+ s.instance_variable_set(:@db, db)
398
446
  block_given? ? scoped(s, &) : s
399
447
  end
400
448
 
@@ -417,10 +465,41 @@ module Pigeonhole
417
465
  # Remembers one memory in namespace `ns`, in one transaction (a `Remembered`). An exact
418
466
  # duplicate (after trimming and collapsing whitespace) of a live memory merges into it;
419
467
  # with near dedup set, a near duplicate is handled by its policy.
468
+ #
469
+ # The writes (`remember`, `delete`, `link`, `supersede`, `mark_used`) and `recall` let
470
+ # the thread's other fibers run while they wait under a fiber scheduler (ICR 0126): a
471
+ # write's commit yields as `Database#transact`'s does, and its other waits (the
472
+ # near-dedup lookup, an IVF store's settle) and `recall` run on a worker thread. A write
473
+ # stopped while it waits ends as a stopped `transact` does (D210).
420
474
  def remember(ns, text, embedding: nil, kind: nil, importance: nil, source: nil, session: nil,
421
475
  links: nil, pinned: false)
422
- Remembered.new(*native_remember(ns, text, embedding, kind, importance, source, session, links,
423
- pinned))
476
+ args = [ns, text, embedding, kind, importance, source, session, links, pinned]
477
+ b = Native::FiberBridge.current
478
+ return Remembered.new(*native_remember(*args)) unless b
479
+
480
+ # The near-dedup lookup reads outside the transaction (a vector search): off the thread.
481
+ prepared = if native_near_dedup_on
482
+ b.await(native_prepare_remember_op(b.native, *args))
483
+ else
484
+ native_prepare_remember(*args)
485
+ end
486
+ Remembered.new(*fiber_write(b, settle: true) { |t| native_remember_prepared_in(t, prepared) })
487
+ end
488
+
489
+ # Deletes the memory `id` and its links; whether it existed.
490
+ def delete(id)
491
+ b = Native::FiberBridge.current
492
+ return native_delete(id) unless b
493
+
494
+ fiber_write(b, settle: true) { |t| delete_in(t, id) }
495
+ end
496
+
497
+ # Marks `old` superseded by `new` (one namespace), linking them.
498
+ def supersede(old, new)
499
+ b = Native::FiberBridge.current
500
+ return native_supersede(old, new) unless b
501
+
502
+ fiber_write(b) { |t| native_supersede_in(t, old, new) }
424
503
  end
425
504
 
426
505
  # `remember` inside `txn`, committed with it. It skips near dedup (call
@@ -434,10 +513,18 @@ module Pigeonhole
434
513
 
435
514
  # Links `from` to `to` (one namespace) with a link type (`LinkType`, or an
436
515
  # application's from 16) and a weight from 0 to 1.
437
- def link(from, to, link_type, weight = 1.0) = native_link(from, to, link_type, weight)
516
+ def link(from, to, link_type, weight = 1.0)
517
+ b = Native::FiberBridge.current
518
+ return native_link(from, to, link_type, weight) unless b
519
+
520
+ fiber_write(b) { |t| native_link_in(t, from, to, link_type, weight) }
521
+ end
438
522
 
439
523
  # Counts a use of each memory of `ids` (a `Marked`).
440
- def mark_used(ids) = Marked.new(*native_mark_used(ids))
524
+ def mark_used(ids)
525
+ b = Native::FiberBridge.current
526
+ Marked.new(*(b ? fiber_write(b) { |t| native_mark_used_in(t, ids) } : native_mark_used(ids)))
527
+ end
441
528
 
442
529
  # One forget pass (T2) under `policy`, else the store's persisted one
443
530
  # (`InvalidArgument` with neither); `after` resumes where an earlier pass stopped.
@@ -479,6 +566,19 @@ module Pigeonhole
479
566
  "MergeFailed", MERGE_FAILED_CODE_NUM, consolidated: pass),
480
567
  cause: failure
481
568
  end
569
+
570
+ private
571
+
572
+ # A write under a fiber scheduler, as the crate's own runs it (ICR 0123): the store's
573
+ # `*_in` form in a `transact` (retried as the crate retries, its commit yielding), then
574
+ # with `settle:` an IVF store's parked writes handed on, on a worker thread. Unlike the
575
+ # crate's, a write whose transaction raises doesn't settle: anything parked goes with
576
+ # the next write's settle, which is harmless for recall (cli692's N3 on #1614).
577
+ def fiber_write(bridge, settle: false)
578
+ out = @db.transact { |t| yield t }
579
+ bridge.await(native_settle_op(bridge.native)) if settle && native_has_ivf
580
+ out
581
+ end
482
582
  end
483
583
 
484
584
  class Store
@@ -490,9 +590,11 @@ module Pigeonhole
490
590
  def consolidate_loop(name, policy: nil, namespaces: nil, clock_offset: nil, &block)
491
591
  raise ArgumentError, "consolidate_loop needs a block: the consolidator" unless block
492
592
 
493
- lp = native_consolidate_loop(name, policy, namespaces, clock_offset && (clock_offset * 1_000_000).to_i)
593
+ offset_us = clock_offset && (clock_offset * 1_000_000).to_i
594
+ lp = native_consolidate_loop(name, policy, namespaces, offset_us)
494
595
  consolidator = proc { |group| block.call(Build.group(group)) }
495
596
  lp.instance_variable_set(:@consolidator, consolidator)
597
+ lp.instance_variable_set(:@clock_offset_us, offset_us)
496
598
  lp
497
599
  end
498
600
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Pigeonhole
4
4
  # The gem's version: the `pigeonhole` crate's.
5
- VERSION = "1.1.2"
5
+ VERSION = "1.2.0"
6
6
  end
data/lib/pigeonhole.rb CHANGED
@@ -42,6 +42,7 @@ module Pigeonhole
42
42
  end
43
43
  end
44
44
 
45
+ require_relative "pigeonhole/fiber"
45
46
  require_relative "pigeonhole/api"
46
47
  require_relative "pigeonhole/memory"
47
48
  require_relative "pigeonhole/index"
data/sig/pigeonhole.rbs CHANGED
@@ -30,6 +30,11 @@ module Pigeonhole
30
30
  # Keys or seeds: an Array of Strings, or another Enumerable of them (a Set).
31
31
  type keys = Array[String] | Enumerable[String]
32
32
 
33
+ # Whether the waiting calls yield to a running fiber scheduler (default true); false keeps
34
+ # them blocking process-wide (ICR 0126).
35
+ def self.fiber_scheduler: () -> bool
36
+ def self.fiber_scheduler=: (boolish on) -> boolish
37
+
33
38
  def self.open: (path path, ?create: bool, ?shards: Integer?, ?durability: durability?,
34
39
  ?block_cache: Integer?, ?row_cache: Integer?, ?memtable_budget: Integer?,
35
40
  ?shm_dir: path?, ?read_only_fallback: bool?, ?change_feed: Integer?,
@@ -246,20 +251,44 @@ module Pigeonhole
246
251
  def put_vector: (name family, String qualifier, vector_in vector, ?ts: Integer?) -> self
247
252
  def delete: (?name? family, ?String? qualifier, ?ts: Integer?) -> self
248
253
  def durability: (durability durability) -> self
254
+ def return_previous: (name family, String qualifier) -> self
249
255
  def commit: () -> Integer
250
256
  def commit_if: (Condition condition) -> Integer?
251
257
  def commit_returning: () -> Incremented
258
+ def return_current: (name family, String qualifier) -> self
259
+ def commit_if_returning: (Condition condition) -> Checked
260
+ end
261
+
262
+ # What Mutation#commit_if_returning returns: whether the condition held, with the row
263
+ # either way.
264
+ class Checked
265
+ attr_reader returned: Incremented?
266
+ attr_reader seen: Seen?
267
+ def initialize: (Incremented? returned, Seen? seen) -> void
268
+ def applied?: () -> bool
269
+ def inspect: () -> String
252
270
  end
253
271
 
254
- # The counter cells a Mutation#commit_returning wrote, after its commit.
272
+ # The row as a failed Mutation#commit_if_returning's condition saw it.
273
+ class Seen
274
+ def current: (name family, String qualifier) -> Cell?
275
+ end
276
+
277
+ # The counter cells a Mutation#commit_returning wrote, after its commit, and the columns
278
+ # return_previous asked for, as they were before it.
255
279
  class Incremented
256
280
  def seqno: () -> Integer
257
281
  def value: (name family, String qualifier, ?ts: Integer?) -> Integer?
282
+ def previous: (name family, String qualifier) -> Cell?
283
+ def current: (name family, String qualifier) -> Cell?
258
284
  def to_h: () -> Hash[[String, String, Integer], Integer?]
259
285
  def size: () -> Integer
260
286
  def inspect: () -> String
261
287
  end
262
288
 
289
+ # Incremented's name since 1.2 (ICR 0113): the same class.
290
+ class Returned = Incremented
291
+
263
292
  # Writes to any rows and tables, committed atomically.
264
293
  class WriteBatch
265
294
  def put: (Table table, String row, name family, String qualifier, value value, ?ts: Integer?) -> self
data/src/classes.rs CHANGED
@@ -48,9 +48,32 @@ pub(crate) struct MutationState {
48
48
  pub(crate) row: Vec<u8>,
49
49
  /// `None` once committed.
50
50
  pub(crate) ops: Mutex<Option<Vec<Op>>>,
51
+ /// The columns `return_previous` and `return_current` asked for (ICR 0113).
52
+ pub(crate) asked: Mutex<Asked>,
51
53
  pub(crate) durability: Mutex<Option<Durability>>,
52
54
  }
53
55
 
56
+ /// A column: family and qualifier.
57
+ pub(crate) type Column = (String, Vec<u8>);
58
+
59
+ /// The columns a mutation's `return_previous` and `return_current` asked for (ICR 0113).
60
+ #[derive(Debug, Clone, Default)]
61
+ pub(crate) struct Asked {
62
+ pub(crate) previous: Vec<Column>,
63
+ pub(crate) current: Vec<Column>,
64
+ }
65
+
66
+ impl Asked {
67
+ /// Whether `return_current` asked for the column, or it's `condition`'s (always
68
+ /// reported).
69
+ pub(crate) fn has_current(&self, family: &str, q: &[u8], condition: Option<&Column>) -> bool {
70
+ self.current
71
+ .iter()
72
+ .chain(condition)
73
+ .any(|(f, cq)| f == family && cq == q)
74
+ }
75
+ }
76
+
54
77
  /// `Pigeonhole::Mutation`.
55
78
  #[magnus::wrap(class = "Pigeonhole::Mutation", free_immediately, size)]
56
79
  pub(crate) struct Mutation(pub(crate) ForkSafe<MutationState>);
@@ -82,10 +105,22 @@ pub(crate) struct Snapshot(pub(crate) ForkSafe<Mutex<Option<pigeonhole::Snapshot
82
105
  #[magnus::wrap(class = "Pigeonhole::Cell", free_immediately, size)]
83
106
  pub(crate) struct Cell(pub(crate) pigeonhole::Cell);
84
107
 
85
- /// `Pigeonhole::Incremented`: the counter cells a `Mutation#commit_returning` wrote, after
86
- /// its commit (D314). Plain data: no handle, so nothing to guard across a fork.
108
+ /// `Pigeonhole::Incremented` (also `Pigeonhole::Returned`): the counter cells a
109
+ /// `Mutation#commit_returning` (or an applied `commit_if_returning`) wrote, after its commit
110
+ /// (D314), and the columns `return_previous` and `return_current` asked for, with those
111
+ /// requests and the condition's column. Plain data: no handle, so nothing to guard across a
112
+ /// fork.
87
113
  #[magnus::wrap(class = "Pigeonhole::Incremented", free_immediately, size)]
88
- pub(crate) struct Incremented(pub(crate) pigeonhole::Incremented);
114
+ pub(crate) struct Incremented(
115
+ pub(crate) pigeonhole::Incremented,
116
+ pub(crate) Asked,
117
+ pub(crate) Option<Column>,
118
+ );
119
+
120
+ /// `Pigeonhole::Seen`: the row as a failed `Mutation#commit_if_returning`'s condition saw it
121
+ /// (D314 amendment 2). Plain data.
122
+ #[magnus::wrap(class = "Pigeonhole::Seen", free_immediately, size)]
123
+ pub(crate) struct Seen(pub(crate) pigeonhole::Seen);
89
124
 
90
125
  /// `Pigeonhole::Row`.
91
126
  #[magnus::wrap(class = "Pigeonhole::Row", free_immediately, size)]
@@ -164,9 +199,9 @@ pub(crate) struct PagesState {
164
199
  #[magnus::wrap(class = "Pigeonhole::Pages", free_immediately, size)]
165
200
  pub(crate) struct Pages(pub(crate) ForkSafe<Mutex<PagesState>>);
166
201
 
167
- /// `Pigeonhole::Feed`: a change feed subscription (its state is `crate::feed::FeedState`).
202
+ /// `Pigeonhole::Feed`: a change feed subscription, a `crate::waits` stream.
168
203
  #[magnus::wrap(class = "Pigeonhole::Feed", free_immediately, size)]
169
- pub(crate) struct Feed(pub(crate) ForkSafe<crate::feed::FeedState>);
204
+ pub(crate) struct Feed(pub(crate) ForkSafe<crate::waits::Waits<crate::feed::FeedSource>>);
170
205
 
171
206
  // ---- Pigeonhole::Memory (PR 3a; methods in memory.rs) ------------------------------
172
207
 
@@ -272,8 +307,10 @@ pub(crate) struct VectorBulkLoad(pub(crate) ForkSafe<Mutex<Option<crate::index::
272
307
 
273
308
  /// `Pigeonhole::Memory::Watch`: a store's memory events (T9); `None` once closed.
274
309
  #[magnus::wrap(class = "Pigeonhole::Memory::Watch", free_immediately, size)]
275
- pub(crate) struct Watch(pub(crate) ForkSafe<crate::index::Fair<Option<pigeonhole_memory::Watch>>>);
310
+ pub(crate) struct Watch(pub(crate) ForkSafe<crate::waits::Waits<crate::memory::WatchSource>>);
276
311
 
277
312
  /// `Pigeonhole::Memory::ConsolidateLoop`: feed-driven consolidation (T9).
278
313
  #[magnus::wrap(class = "Pigeonhole::Memory::ConsolidateLoop", free_immediately, size)]
279
- pub(crate) struct ConsolidateLoop(pub(crate) ForkSafe<Mutex<crate::memory::LoopSlot>>);
314
+ pub(crate) struct ConsolidateLoop(
315
+ pub(crate) ForkSafe<std::sync::Arc<Mutex<crate::memory::LoopSlot>>>,
316
+ );
data/src/db.rs CHANGED
@@ -683,3 +683,57 @@ impl Transaction {
683
683
  without_gvl(ruby, move || lock(m).is_some())
684
684
  }
685
685
  }
686
+
687
+ // ---- Under a fiber scheduler (#1574, ICR 0126) ---------------------------------------------
688
+
689
+ #[cfg(unix)]
690
+ impl WriteBatch {
691
+ /// `native_commit_op(bridge, durability)`: `commit`, as a fiber op. The writes are taken
692
+ /// and submitted at the call, as the blocking form does.
693
+ pub(crate) fn commit_op(
694
+ ruby: &Ruby,
695
+ rb_self: &Self,
696
+ bridge: &crate::fiber::FiberBridge,
697
+ durability: Option<Durability>,
698
+ ) -> Result<crate::fiber::FiberOp, Error> {
699
+ let state = rb_self.0.get(ruby)?;
700
+ crate::fiber::FiberBridge::start(ruby, bridge, move || {
701
+ let Some(ops) = lock(&state.ops).take() else {
702
+ return crate::fiber::ready(Box::new(|ruby: &Ruby| Err(spent(ruby, BATCH_SPENT))));
703
+ };
704
+ let mut b = state.db.write_batch();
705
+ for (t, row, op) in &ops {
706
+ apply!(&mut b, t, row, op);
707
+ }
708
+ let fut = match durability {
709
+ Some(d) => b.commit_with_async(d.into()),
710
+ None => b.commit_async(),
711
+ };
712
+ crate::fiber::map(fut, |ruby, r| Ok(ruby.into_value(r.or_rb(ruby)?.seqno)))
713
+ })
714
+ }
715
+ }
716
+
717
+ #[cfg(unix)]
718
+ impl Transaction {
719
+ /// `native_commit_op(bridge, durability)`: `commit`, as a fiber op; `Conflict` as the
720
+ /// blocking form raises it.
721
+ pub(crate) fn commit_op(
722
+ ruby: &Ruby,
723
+ rb_self: &Self,
724
+ bridge: &crate::fiber::FiberBridge,
725
+ durability: Option<Durability>,
726
+ ) -> Result<crate::fiber::FiberOp, Error> {
727
+ let m = rb_self.0.get(ruby)?;
728
+ crate::fiber::FiberBridge::start(ruby, bridge, move || {
729
+ let Some(txn) = lock(m).take() else {
730
+ return crate::fiber::ready(Box::new(|ruby: &Ruby| Err(spent(ruby, TXN_SPENT))));
731
+ };
732
+ let fut = match durability {
733
+ Some(d) => txn.commit_with_async(d.into()),
734
+ None => txn.commit_async(),
735
+ };
736
+ crate::fiber::map(fut, |ruby, r| Ok(ruby.into_value(r.or_rb(ruby)?.seqno)))
737
+ })
738
+ }
739
+ }
data/src/feed.rs CHANGED
@@ -4,69 +4,56 @@
4
4
  //! timestamp, value], ...]]`, which `lib/pigeonhole/api.rb` turns into frozen `Commit` and
5
5
  //! `Change` objects.
6
6
 
7
- use std::sync::atomic::{AtomicUsize, Ordering};
8
- use std::sync::{Mutex, MutexGuard};
9
- use std::time::{Duration, Instant};
7
+ use std::time::Duration;
10
8
 
11
9
  use magnus::{Error, RArray, RString, Ruby, TryConvert, prelude::*};
12
- use pigeonhole::{ChangeKind, ErrorCode};
10
+ use pigeonhole::ChangeKind;
13
11
 
14
12
  use crate::classes::{Feed, Snapshot, Table};
15
- use crate::convert::{Bytes, Secs, arg_error, binary, frozen, lock};
16
- use crate::error::{engine, with_code};
13
+ use crate::convert::{Bytes, Secs, arg_error, binary, frozen};
14
+ use crate::error::engine;
17
15
  use crate::fork::ForkSafe;
18
- use crate::gvl::without_gvl;
19
16
  use crate::read::{snapshot_arg, typed};
20
17
  use crate::table::{Handle, either};
21
18
 
22
- /// The longest a wait runs with the GVL released before it checks for an interrupt
23
- /// (`Thread#raise`, `Thread#kill`, Ctrl-C), so a consumer blocked in `next` stays
24
- /// interruptible although one engine call isn't.
25
- const SLICE: Duration = Duration::from_millis(100);
19
+ /// A feed as a stream's source (`crate::waits`): its sync reads, the fiber wait's poll and
20
+ /// its token, shared with the memory store's watch.
21
+ pub(crate) struct FeedSource(pigeonhole::Feed);
26
22
 
27
- /// A feed's state: the subscription (`None` once closed) behind a mutex, and how many
28
- /// threads are waiting to take it.
29
- ///
30
- /// A consumer in `next` holds the mutex for each slice and takes it again right after, and
31
- /// `std`'s mutex isn't fair, so without `wanted` it kept winning: `token` and `close` from
32
- /// another thread waited many slices (perf2 measured 1.46 s), with the GVL released and no
33
- /// way to interrupt them (perf2's S1 on #1411). Every lock goes through
34
- /// [`acquire`](Self::acquire), which counts the thread in `wanted` while it waits, and
35
- /// `next` gives way between slices while `wanted` isn't 0, so any other caller, a second
36
- /// consumer included, waits at most about one slice.
37
- pub(crate) struct FeedState {
38
- feed: Mutex<Option<pigeonhole::Feed>>,
39
- wanted: AtomicUsize,
40
- }
23
+ impl crate::waits::Source for FeedSource {
24
+ type Item = pigeonhole::Commit;
25
+ type Error = pigeonhole::Error;
26
+ const NAME: &'static str = "feed";
41
27
 
42
- impl FeedState {
43
- fn new(feed: pigeonhole::Feed) -> Self {
44
- Self {
45
- feed: Mutex::new(Some(feed)),
46
- wanted: AtomicUsize::new(0),
47
- }
28
+ fn next(&mut self, d: Duration) -> pigeonhole::Result<Option<pigeonhole::Commit>> {
29
+ self.0.next(d).map(Option::<&pigeonhole::Commit>::cloned)
48
30
  }
49
31
 
50
- /// The subscription, counted in `wanted` until the lock is ours.
51
- fn acquire(&self) -> MutexGuard<'_, Option<pigeonhole::Feed>> {
52
- self.wanted.fetch_add(1, Ordering::SeqCst);
53
- let guard = lock(&self.feed);
54
- self.wanted.fetch_sub(1, Ordering::SeqCst);
55
- guard
32
+ fn try_next(&mut self) -> pigeonhole::Result<Option<pigeonhole::Commit>> {
33
+ self.0.try_next().map(Option::<&pigeonhole::Commit>::cloned)
56
34
  }
57
35
 
58
- /// Waits, with the GVL released, until no other thread wants the lock or `limit` (at
59
- /// most a slice) has passed: a consumer between slices lets the others in first.
60
- fn give_way(&self, ruby: &Ruby, limit: Duration) -> Result<(), Error> {
61
- if self.wanted.load(Ordering::SeqCst) == 0 {
62
- return Ok(());
63
- }
64
- without_gvl(ruby, || {
65
- let start = Instant::now();
66
- while self.wanted.load(Ordering::SeqCst) > 0 && start.elapsed() < limit {
67
- std::thread::sleep(Duration::from_millis(1));
68
- }
69
- })
36
+ fn poll_next(
37
+ &mut self,
38
+ cx: &mut std::task::Context<'_>,
39
+ ) -> std::task::Poll<pigeonhole::Result<pigeonhole::Commit>> {
40
+ self.0.poll_next(cx).map(|r| r.cloned())
41
+ }
42
+
43
+ fn token(&self) -> Vec<u8> {
44
+ self.0.token().as_bytes().to_vec()
45
+ }
46
+
47
+ fn oldest_retained(&self) -> Option<u64> {
48
+ self.0.oldest_retained()
49
+ }
50
+
51
+ fn to_rb(ruby: &Ruby, item: pigeonhole::Commit) -> Result<magnus::Value, Error> {
52
+ commit(ruby, &item).map(|a| a.as_value())
53
+ }
54
+
55
+ fn error(ruby: &Ruby, e: pigeonhole::Error) -> Error {
56
+ crate::error::to_rb(ruby, &e)
70
57
  }
71
58
  }
72
59
 
@@ -125,7 +112,9 @@ impl Table {
125
112
  }
126
113
  b.open()
127
114
  })?;
128
- Ok(Feed(ForkSafe::new(FeedState::new(feed))))
115
+ Ok(Feed(ForkSafe::new(crate::waits::Waits::new(FeedSource(
116
+ feed,
117
+ )))))
129
118
  }
130
119
  }
131
120
 
@@ -175,30 +164,6 @@ fn commit(ruby: &Ruby, c: &pigeonhole::Commit) -> Result<RArray, Error> {
175
164
  }
176
165
 
177
166
  impl Feed {
178
- /// One wait of at most `slice` (`None`: no wait), with the GVL released. `Closed` for a
179
- /// closed feed.
180
- fn poll(
181
- ruby: &Ruby,
182
- rb_self: &Self,
183
- slice: Option<Duration>,
184
- ) -> Result<Option<pigeonhole::Commit>, Error> {
185
- let state = rb_self.0.get(ruby)?;
186
- // The mutex is taken only inside the call, so a thread waiting on it (behind a
187
- // consumer's slice) never holds the GVL.
188
- let polled = engine(ruby, || {
189
- let mut guard = state.acquire();
190
- let Some(f) = guard.as_mut() else {
191
- return Ok(None);
192
- };
193
- let next = match slice {
194
- Some(d) => f.next(d)?,
195
- None => f.try_next()?,
196
- };
197
- Ok(Some(next.cloned()))
198
- })?;
199
- polled.ok_or_else(|| with_code(ruby, ErrorCode::Closed, "the feed is closed"))
200
- }
201
-
202
167
  /// `native_next(timeout)`: the next commit, waiting up to `timeout` seconds (`nil`
203
168
  /// waits until one comes), in slices with an interrupt check between them; `nil` if
204
169
  /// none came in time.
@@ -207,70 +172,54 @@ impl Feed {
207
172
  rb_self: &Self,
208
173
  timeout: Option<Secs>,
209
174
  ) -> Result<Option<RArray>, Error> {
210
- let deadline = timeout.and_then(|t| Instant::now().checked_add(t.0));
211
175
  let state = rb_self.0.get(ruby)?;
212
- loop {
213
- // Another thread waiting for the feed (`token`, `close`, a second consumer) goes
214
- // first; then this one checks for interrupts before its next slice.
215
- // Never past a short `timeout:`'s deadline (ai1249's nit on #1411).
216
- let left = || {
217
- deadline.map_or(SLICE, |d| {
218
- d.saturating_duration_since(Instant::now()).min(SLICE)
219
- })
220
- };
221
- state.give_way(ruby, left())?;
222
- ruby.thread_check_ints()?;
223
- let slice = left();
224
- if let Some(c) = Self::poll(ruby, rb_self, Some(slice))? {
225
- return commit(ruby, &c).map(Some);
226
- }
227
- if deadline.is_some_and(|d| Instant::now() >= d) {
228
- return Ok(None);
229
- }
230
- }
176
+ state
177
+ .wait(ruby, timeout.map(|t| t.0))?
178
+ .map(|c| commit(ruby, &c))
179
+ .transpose()
231
180
  }
232
181
 
233
182
  /// `native_try_next`: the next commit if one is ready, else `nil`. Never waits.
234
183
  pub(crate) fn try_next(ruby: &Ruby, rb_self: &Self) -> Result<Option<RArray>, Error> {
235
- Self::poll(ruby, rb_self, None)?
184
+ rb_self
185
+ .0
186
+ .get(ruby)?
187
+ .try_next(ruby)?
236
188
  .map(|c| commit(ruby, &c))
237
189
  .transpose()
238
190
  }
239
191
 
192
+ /// `native_next_op(bridge)`: the next commit as a fiber op (#1574 PR 2).
193
+ #[cfg(unix)]
194
+ pub(crate) fn next_op(
195
+ ruby: &Ruby,
196
+ rb_self: &Self,
197
+ bridge: &crate::fiber::FiberBridge,
198
+ ) -> Result<crate::fiber::FiberOp, Error> {
199
+ rb_self.0.get(ruby)?.next_op(ruby, bridge)
200
+ }
201
+
240
202
  /// Where the feed is, as bytes: `Table#feed(resume:)` continues after the last commit
241
203
  /// delivered, in this open of the database or a later one.
242
204
  pub(crate) fn token(ruby: &Ruby, rb_self: &Self) -> Result<RString, Error> {
243
- let state = rb_self.0.get(ruby)?;
244
- // A thread waiting in `next` holds the lock for up to a slice, then gives way.
245
- let token = without_gvl(ruby, || {
246
- state.acquire().as_ref().map(pigeonhole::Feed::token)
247
- })?
248
- .ok_or_else(|| with_code(ruby, ErrorCode::Closed, "the feed is closed"))?;
249
- Ok(binary(ruby, token.as_bytes()))
205
+ let t = rb_self.0.get(ruby)?.token(ruby)?;
206
+ Ok(binary(ruby, &t))
250
207
  }
251
208
 
252
209
  /// Once the feed expired: the oldest commit seqno its history still holds, when known.
253
210
  pub(crate) fn oldest_retained(ruby: &Ruby, rb_self: &Self) -> Result<Option<u64>, Error> {
254
- let state = rb_self.0.get(ruby)?;
255
- without_gvl(ruby, || {
256
- state
257
- .acquire()
258
- .as_ref()
259
- .and_then(pigeonhole::Feed::oldest_retained)
260
- })
211
+ rb_self.0.get(ruby)?.oldest_retained(ruby)
261
212
  }
262
213
 
263
214
  /// Ends the subscription now. Calls afterwards raise `Closed`; closing twice does
264
215
  /// nothing.
265
216
  pub(crate) fn close(ruby: &Ruby, rb_self: &Self) -> Result<(), Error> {
266
- let state = rb_self.0.get(ruby)?;
267
- without_gvl(ruby, || drop(state.acquire().take()))
217
+ rb_self.0.get(ruby)?.close(ruby)
268
218
  }
269
219
 
270
220
  /// Whether `close` was called.
271
221
  pub(crate) fn is_closed(ruby: &Ruby, rb_self: &Self) -> Result<bool, Error> {
272
- let state = rb_self.0.get(ruby)?;
273
- without_gvl(ruby, || state.acquire().is_none())
222
+ rb_self.0.get(ruby)?.is_closed(ruby)
274
223
  }
275
224
  }
276
225