@nxtedition/rocksdb 5.2.36 → 5.2.39

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 (190) hide show
  1. package/binding.cc +66 -91
  2. package/deps/liburing/liburing/COPYING +502 -0
  3. package/deps/liburing/liburing/COPYING.GPL +339 -0
  4. package/deps/liburing/liburing/LICENSE +7 -0
  5. package/deps/liburing/liburing/Makefile +84 -0
  6. package/deps/liburing/liburing/Makefile.quiet +11 -0
  7. package/deps/liburing/liburing/README +46 -0
  8. package/deps/liburing/liburing/configure +420 -0
  9. package/deps/liburing/liburing/debian/README.Debian +7 -0
  10. package/deps/liburing/liburing/debian/changelog +27 -0
  11. package/deps/liburing/liburing/debian/compat +1 -0
  12. package/deps/liburing/liburing/debian/control +48 -0
  13. package/deps/liburing/liburing/debian/copyright +49 -0
  14. package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
  15. package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
  16. package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
  17. package/deps/liburing/liburing/debian/liburing1.install +1 -0
  18. package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
  19. package/deps/liburing/liburing/debian/patches/series +1 -0
  20. package/deps/liburing/liburing/debian/rules +81 -0
  21. package/deps/liburing/liburing/debian/source/format +1 -0
  22. package/deps/liburing/liburing/debian/source/local-options +2 -0
  23. package/deps/liburing/liburing/debian/source/options +1 -0
  24. package/deps/liburing/liburing/debian/watch +3 -0
  25. package/deps/liburing/liburing/examples/Makefile +29 -0
  26. package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
  27. package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
  28. package/deps/liburing/liburing/examples/link-cp.c +193 -0
  29. package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
  30. package/deps/liburing/liburing/liburing.pc.in +12 -0
  31. package/deps/liburing/liburing/liburing.spec +66 -0
  32. package/deps/liburing/liburing/make-debs.sh +53 -0
  33. package/deps/liburing/liburing/man/io_uring.7 +736 -0
  34. package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
  35. package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
  36. package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
  37. package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
  38. package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
  39. package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
  40. package/deps/liburing/liburing/src/Makefile +76 -0
  41. package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
  42. package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
  43. package/deps/liburing/liburing/src/include/liburing.h +775 -0
  44. package/deps/liburing/liburing/src/liburing.map +46 -0
  45. package/deps/liburing/liburing/src/queue.c +403 -0
  46. package/deps/liburing/liburing/src/register.c +299 -0
  47. package/deps/liburing/liburing/src/setup.c +356 -0
  48. package/deps/liburing/liburing/src/syscall.c +73 -0
  49. package/deps/liburing/liburing/src/syscall.h +20 -0
  50. package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
  51. package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
  52. package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
  53. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
  54. package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
  55. package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
  56. package/deps/liburing/liburing/test/Makefile +312 -0
  57. package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
  58. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
  59. package/deps/liburing/liburing/test/accept-link.c +251 -0
  60. package/deps/liburing/liburing/test/accept-reuse.c +164 -0
  61. package/deps/liburing/liburing/test/accept-test.c +79 -0
  62. package/deps/liburing/liburing/test/accept.c +476 -0
  63. package/deps/liburing/liburing/test/across-fork.c +283 -0
  64. package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
  65. package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
  66. package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
  67. package/deps/liburing/liburing/test/close-opath.c +122 -0
  68. package/deps/liburing/liburing/test/config +10 -0
  69. package/deps/liburing/liburing/test/connect.c +398 -0
  70. package/deps/liburing/liburing/test/cq-full.c +96 -0
  71. package/deps/liburing/liburing/test/cq-overflow.c +294 -0
  72. package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
  73. package/deps/liburing/liburing/test/cq-ready.c +94 -0
  74. package/deps/liburing/liburing/test/cq-size.c +58 -0
  75. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
  76. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
  77. package/deps/liburing/liburing/test/defer.c +307 -0
  78. package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
  79. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
  80. package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
  81. package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
  82. package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
  83. package/deps/liburing/liburing/test/eventfd.c +112 -0
  84. package/deps/liburing/liburing/test/fadvise.c +202 -0
  85. package/deps/liburing/liburing/test/fallocate.c +249 -0
  86. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
  87. package/deps/liburing/liburing/test/file-register.c +843 -0
  88. package/deps/liburing/liburing/test/file-update.c +173 -0
  89. package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
  90. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
  91. package/deps/liburing/liburing/test/fixed-link.c +90 -0
  92. package/deps/liburing/liburing/test/fsync.c +224 -0
  93. package/deps/liburing/liburing/test/hardlink.c +136 -0
  94. package/deps/liburing/liburing/test/helpers.c +135 -0
  95. package/deps/liburing/liburing/test/helpers.h +67 -0
  96. package/deps/liburing/liburing/test/io-cancel.c +537 -0
  97. package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
  98. package/deps/liburing/liburing/test/io_uring_register.c +664 -0
  99. package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
  100. package/deps/liburing/liburing/test/iopoll.c +366 -0
  101. package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
  102. package/deps/liburing/liburing/test/lfs-openat.c +273 -0
  103. package/deps/liburing/liburing/test/link-timeout.c +1107 -0
  104. package/deps/liburing/liburing/test/link.c +496 -0
  105. package/deps/liburing/liburing/test/link_drain.c +229 -0
  106. package/deps/liburing/liburing/test/madvise.c +195 -0
  107. package/deps/liburing/liburing/test/mkdir.c +108 -0
  108. package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
  109. package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
  110. package/deps/liburing/liburing/test/nop.c +115 -0
  111. package/deps/liburing/liburing/test/open-close.c +146 -0
  112. package/deps/liburing/liburing/test/openat2.c +240 -0
  113. package/deps/liburing/liburing/test/personality.c +204 -0
  114. package/deps/liburing/liburing/test/pipe-eof.c +81 -0
  115. package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
  116. package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
  117. package/deps/liburing/liburing/test/poll-cancel.c +135 -0
  118. package/deps/liburing/liburing/test/poll-link.c +227 -0
  119. package/deps/liburing/liburing/test/poll-many.c +208 -0
  120. package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
  121. package/deps/liburing/liburing/test/poll-ring.c +48 -0
  122. package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
  123. package/deps/liburing/liburing/test/poll.c +109 -0
  124. package/deps/liburing/liburing/test/probe.c +137 -0
  125. package/deps/liburing/liburing/test/read-write.c +876 -0
  126. package/deps/liburing/liburing/test/register-restrictions.c +633 -0
  127. package/deps/liburing/liburing/test/rename.c +134 -0
  128. package/deps/liburing/liburing/test/ring-leak.c +173 -0
  129. package/deps/liburing/liburing/test/ring-leak2.c +249 -0
  130. package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
  131. package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
  132. package/deps/liburing/liburing/test/runtests.sh +170 -0
  133. package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
  134. package/deps/liburing/liburing/test/self.c +91 -0
  135. package/deps/liburing/liburing/test/send_recv.c +291 -0
  136. package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
  137. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
  138. package/deps/liburing/liburing/test/shared-wq.c +84 -0
  139. package/deps/liburing/liburing/test/short-read.c +75 -0
  140. package/deps/liburing/liburing/test/shutdown.c +163 -0
  141. package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
  142. package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
  143. package/deps/liburing/liburing/test/socket-rw.c +147 -0
  144. package/deps/liburing/liburing/test/splice.c +511 -0
  145. package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
  146. package/deps/liburing/liburing/test/sq-full.c +45 -0
  147. package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
  148. package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
  149. package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
  150. package/deps/liburing/liburing/test/sq-space_left.c +159 -0
  151. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
  152. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
  153. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
  154. package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
  155. package/deps/liburing/liburing/test/statx.c +172 -0
  156. package/deps/liburing/liburing/test/stdout.c +232 -0
  157. package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
  158. package/deps/liburing/liburing/test/submit-reuse.c +239 -0
  159. package/deps/liburing/liburing/test/symlink.c +116 -0
  160. package/deps/liburing/liburing/test/teardowns.c +58 -0
  161. package/deps/liburing/liburing/test/thread-exit.c +131 -0
  162. package/deps/liburing/liburing/test/timeout-new.c +246 -0
  163. package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
  164. package/deps/liburing/liburing/test/timeout.c +1354 -0
  165. package/deps/liburing/liburing/test/unlink.c +111 -0
  166. package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
  167. package/deps/liburing/liburing.gyp +20 -0
  168. package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
  169. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
  170. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
  171. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
  172. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
  173. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
  174. package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
  175. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
  176. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
  177. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
  178. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
  179. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
  180. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  181. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
  182. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
  183. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
  184. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
  185. package/deps/rocksdb/rocksdb.gyp +4 -3
  186. package/package.json +1 -1
  187. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  188. package/prebuilds/darwin-x64/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.node +0 -0
  190. package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
@@ -0,0 +1,111 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: run various nop tests
4
+ *
5
+ */
6
+ #include <errno.h>
7
+ #include <stdio.h>
8
+ #include <unistd.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <fcntl.h>
12
+
13
+ #include "liburing.h"
14
+
15
+ static int test_unlink(struct io_uring *ring, const char *old)
16
+ {
17
+ struct io_uring_cqe *cqe;
18
+ struct io_uring_sqe *sqe;
19
+ int ret;
20
+
21
+ sqe = io_uring_get_sqe(ring);
22
+ if (!sqe) {
23
+ fprintf(stderr, "get sqe failed\n");
24
+ goto err;
25
+ }
26
+ io_uring_prep_unlinkat(sqe, AT_FDCWD, old, 0);
27
+
28
+ ret = io_uring_submit(ring);
29
+ if (ret <= 0) {
30
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
31
+ goto err;
32
+ }
33
+
34
+ ret = io_uring_wait_cqe(ring, &cqe);
35
+ if (ret < 0) {
36
+ fprintf(stderr, "wait completion %d\n", ret);
37
+ goto err;
38
+ }
39
+ ret = cqe->res;
40
+ io_uring_cqe_seen(ring, cqe);
41
+ return ret;
42
+ err:
43
+ return 1;
44
+ }
45
+
46
+ static int stat_file(const char *buf)
47
+ {
48
+ struct stat sb;
49
+
50
+ if (!stat(buf, &sb))
51
+ return 0;
52
+
53
+ return errno;
54
+ }
55
+
56
+ int main(int argc, char *argv[])
57
+ {
58
+ struct io_uring ring;
59
+ char buf[32] = "./XXXXXX";
60
+ int ret;
61
+
62
+ if (argc > 1)
63
+ return 0;
64
+
65
+ ret = io_uring_queue_init(1, &ring, 0);
66
+ if (ret) {
67
+ fprintf(stderr, "ring setup failed: %d\n", ret);
68
+ return 1;
69
+ }
70
+
71
+ ret = mkstemp(buf);
72
+ if (ret < 0) {
73
+ perror("mkstemp");
74
+ return 1;
75
+ }
76
+ close(ret);
77
+
78
+ if (stat_file(buf) != 0) {
79
+ perror("stat");
80
+ return 1;
81
+ }
82
+
83
+ ret = test_unlink(&ring, buf);
84
+ if (ret < 0) {
85
+ if (ret == -EBADF || ret == -EINVAL) {
86
+ fprintf(stdout, "Unlink not supported, skipping\n");
87
+ unlink(buf);
88
+ return 0;
89
+ }
90
+ fprintf(stderr, "rename: %s\n", strerror(-ret));
91
+ goto err;
92
+ } else if (ret)
93
+ goto err;
94
+
95
+ ret = stat_file(buf);
96
+ if (ret != ENOENT) {
97
+ fprintf(stderr, "stat got %s\n", strerror(ret));
98
+ return 1;
99
+ }
100
+
101
+ ret = test_unlink(&ring, "/3/2/3/1/z/y");
102
+ if (ret != -ENOENT) {
103
+ fprintf(stderr, "invalid unlink got %s\n", strerror(-ret));
104
+ return 1;
105
+ }
106
+
107
+ return 0;
108
+ err:
109
+ unlink(buf);
110
+ return 1;
111
+ }
@@ -0,0 +1,162 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ #include <sys/eventfd.h>
3
+ #include <unistd.h>
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+ #include <pthread.h>
8
+ #include <liburing.h>
9
+ #include <fcntl.h>
10
+ #include <poll.h>
11
+ #include <sys/time.h>
12
+
13
+ struct thread_data {
14
+ struct io_uring *ring;
15
+ int write_fd;
16
+ };
17
+
18
+ static void error_exit(char *message)
19
+ {
20
+ perror(message);
21
+ exit(1);
22
+ }
23
+
24
+ static void *listener_thread(void *data)
25
+ {
26
+ struct thread_data *td = data;
27
+ struct io_uring_cqe *cqe;
28
+ int ret;
29
+
30
+ ret = io_uring_wait_cqe(td->ring, &cqe);
31
+ if (ret < 0) {
32
+ fprintf(stderr, "Error waiting for completion: %s\n",
33
+ strerror(-ret));
34
+ goto err;
35
+ }
36
+ if (cqe->res < 0) {
37
+ fprintf(stderr, "Error in async operation: %s\n", strerror(-cqe->res));
38
+ goto err;
39
+ }
40
+ io_uring_cqe_seen(td->ring, cqe);
41
+ return NULL;
42
+ err:
43
+ return (void *) 1;
44
+ }
45
+
46
+ static void *wakeup_io_uring(void *data)
47
+ {
48
+ struct thread_data *td = data;
49
+ int res;
50
+
51
+ res = eventfd_write(td->write_fd, (eventfd_t) 1L);
52
+ if (res < 0) {
53
+ perror("eventfd_write");
54
+ return (void *) 1;
55
+ }
56
+ return NULL;
57
+ }
58
+
59
+ static int test_pipes(void)
60
+ {
61
+ struct io_uring_sqe *sqe;
62
+ struct thread_data td;
63
+ struct io_uring ring;
64
+ pthread_t t1, t2;
65
+ int ret, fds[2];
66
+ void *pret;
67
+
68
+ if (pipe(fds) < 0)
69
+ error_exit("eventfd");
70
+
71
+ ret = io_uring_queue_init(8, &ring, 0);
72
+ if (ret) {
73
+ fprintf(stderr, "Unable to setup io_uring: %s\n", strerror(-ret));
74
+ return 1;
75
+ }
76
+
77
+ td.write_fd = fds[1];
78
+ td.ring = &ring;
79
+
80
+ sqe = io_uring_get_sqe(&ring);
81
+ io_uring_prep_poll_add(sqe, fds[0], POLLIN);
82
+ sqe->user_data = 2;
83
+ ret = io_uring_submit(&ring);
84
+ if (ret != 1) {
85
+ fprintf(stderr, "ring_submit=%d\n", ret);
86
+ return 1;
87
+ }
88
+
89
+ pthread_create(&t1, NULL, listener_thread, &td);
90
+
91
+ sleep(1);
92
+
93
+ pthread_create(&t2, NULL, wakeup_io_uring, &td);
94
+ pthread_join(t1, &pret);
95
+
96
+ io_uring_queue_exit(&ring);
97
+ return pret != NULL;
98
+ }
99
+
100
+ static int test_eventfd(void)
101
+ {
102
+ struct io_uring_sqe *sqe;
103
+ struct thread_data td;
104
+ struct io_uring ring;
105
+ pthread_t t1, t2;
106
+ int efd, ret;
107
+ void *pret;
108
+
109
+ efd = eventfd(0, 0);
110
+ if (efd < 0)
111
+ error_exit("eventfd");
112
+
113
+ ret = io_uring_queue_init(8, &ring, 0);
114
+ if (ret) {
115
+ fprintf(stderr, "Unable to setup io_uring: %s\n", strerror(-ret));
116
+ return 1;
117
+ }
118
+
119
+ td.write_fd = efd;
120
+ td.ring = &ring;
121
+
122
+ sqe = io_uring_get_sqe(&ring);
123
+ io_uring_prep_poll_add(sqe, efd, POLLIN);
124
+ sqe->user_data = 2;
125
+ ret = io_uring_submit(&ring);
126
+ if (ret != 1) {
127
+ fprintf(stderr, "ring_submit=%d\n", ret);
128
+ return 1;
129
+ }
130
+
131
+ pthread_create(&t1, NULL, listener_thread, &td);
132
+
133
+ sleep(1);
134
+
135
+ pthread_create(&t2, NULL, wakeup_io_uring, &td);
136
+ pthread_join(t1, &pret);
137
+
138
+ io_uring_queue_exit(&ring);
139
+ return pret != NULL;
140
+ }
141
+
142
+ int main(int argc, char *argv[])
143
+ {
144
+ int ret;
145
+
146
+ if (argc > 1)
147
+ return 0;
148
+
149
+ ret = test_pipes();
150
+ if (ret) {
151
+ fprintf(stderr, "test_pipe failed\n");
152
+ return ret;
153
+ }
154
+
155
+ ret = test_eventfd();
156
+ if (ret) {
157
+ fprintf(stderr, "test_eventfd failed\n");
158
+ return ret;
159
+ }
160
+
161
+ return 0;
162
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "variables": { "openssl_fips": "0" },
3
+ "targets":
4
+ [
5
+ {
6
+ "target_name": "liburing",
7
+ "type": "static_library",
8
+ "include_dirs": ["linux", "liburing/src/include"],
9
+ "direct_dependent_settings":
10
+ { "include_dirs": ["linux", "liburing/src/include"] },
11
+ "sources":
12
+ [
13
+ "liburing/src/queue.c",
14
+ "liburing/src/register.c",
15
+ "liburing/src/setup.c",
16
+ "liburing/src/syscall.c",
17
+ ],
18
+ },
19
+ ],
20
+ }
@@ -337,6 +337,68 @@ TEST_F(CorruptionTest, Recovery) {
337
337
  Check(36, 36);
338
338
  }
339
339
 
340
+ TEST_F(CorruptionTest, PostPITRCorruptionWALsRetained) {
341
+ // Repro for bug where WALs following the point-in-time recovery were not
342
+ // retained leading to the next recovery failing.
343
+ CloseDb();
344
+
345
+ options_.wal_recovery_mode = WALRecoveryMode::kPointInTimeRecovery;
346
+
347
+ const std::string test_cf_name = "test_cf";
348
+ std::vector<ColumnFamilyDescriptor> cf_descs;
349
+ cf_descs.emplace_back(kDefaultColumnFamilyName, ColumnFamilyOptions());
350
+ cf_descs.emplace_back(test_cf_name, ColumnFamilyOptions());
351
+
352
+ uint64_t log_num;
353
+ {
354
+ options_.create_missing_column_families = true;
355
+ std::vector<ColumnFamilyHandle*> cfhs;
356
+ ASSERT_OK(DB::Open(options_, dbname_, cf_descs, &cfhs, &db_));
357
+
358
+ ASSERT_OK(db_->Put(WriteOptions(), cfhs[0], "k", "v"));
359
+ ASSERT_OK(db_->Put(WriteOptions(), cfhs[1], "k", "v"));
360
+ ASSERT_OK(db_->Put(WriteOptions(), cfhs[0], "k2", "v2"));
361
+ std::vector<uint64_t> file_nums;
362
+ GetSortedWalFiles(file_nums);
363
+ log_num = file_nums.back();
364
+ for (auto* cfh : cfhs) {
365
+ delete cfh;
366
+ }
367
+ CloseDb();
368
+ }
369
+
370
+ CorruptFileWithTruncation(FileType::kWalFile, log_num,
371
+ /*bytes_to_truncate=*/1);
372
+
373
+ {
374
+ // Recover "k" -> "v" for both CFs. "k2" -> "v2" is lost due to truncation.
375
+ options_.avoid_flush_during_recovery = true;
376
+ std::vector<ColumnFamilyHandle*> cfhs;
377
+ ASSERT_OK(DB::Open(options_, dbname_, cf_descs, &cfhs, &db_));
378
+ // Flush one but not both CFs and write some data so there's a seqno gap
379
+ // between the PITR corruption and the next DB session's first WAL.
380
+ ASSERT_OK(db_->Put(WriteOptions(), cfhs[1], "k2", "v2"));
381
+ ASSERT_OK(db_->Flush(FlushOptions(), cfhs[1]));
382
+
383
+ for (auto* cfh : cfhs) {
384
+ delete cfh;
385
+ }
386
+ CloseDb();
387
+ }
388
+
389
+ // With the bug, this DB open would remove the WALs following the PITR
390
+ // corruption. Then, the next recovery would fail.
391
+ for (int i = 0; i < 2; ++i) {
392
+ std::vector<ColumnFamilyHandle*> cfhs;
393
+ ASSERT_OK(DB::Open(options_, dbname_, cf_descs, &cfhs, &db_));
394
+
395
+ for (auto* cfh : cfhs) {
396
+ delete cfh;
397
+ }
398
+ CloseDb();
399
+ }
400
+ }
401
+
340
402
  TEST_F(CorruptionTest, RecoverWriteError) {
341
403
  env_->writable_file_error_ = true;
342
404
  Status s = TryReopen();
@@ -1240,43 +1240,6 @@ class DBImpl : public DB {
1240
1240
 
1241
1241
  std::atomic<bool> shutting_down_;
1242
1242
 
1243
- // RecoveryContext struct stores the context about version edits along
1244
- // with corresponding column_family_data and column_family_options.
1245
- class RecoveryContext {
1246
- public:
1247
- ~RecoveryContext() {
1248
- for (auto& edit_list : edit_lists_) {
1249
- for (auto* edit : edit_list) {
1250
- delete edit;
1251
- }
1252
- edit_list.clear();
1253
- }
1254
- cfds_.clear();
1255
- mutable_cf_opts_.clear();
1256
- edit_lists_.clear();
1257
- files_to_delete_.clear();
1258
- }
1259
-
1260
- void UpdateVersionEdits(ColumnFamilyData* cfd, const VersionEdit& edit) {
1261
- if (map_.find(cfd->GetID()) == map_.end()) {
1262
- uint32_t size = static_cast<uint32_t>(map_.size());
1263
- map_.emplace(cfd->GetID(), size);
1264
- cfds_.emplace_back(cfd);
1265
- mutable_cf_opts_.emplace_back(cfd->GetLatestMutableCFOptions());
1266
- edit_lists_.emplace_back(autovector<VersionEdit*>());
1267
- }
1268
- uint32_t i = map_[cfd->GetID()];
1269
- edit_lists_[i].emplace_back(new VersionEdit(edit));
1270
- }
1271
-
1272
- std::unordered_map<uint32_t, uint32_t> map_; // cf_id to index;
1273
- autovector<ColumnFamilyData*> cfds_;
1274
- autovector<const MutableCFOptions*> mutable_cf_opts_;
1275
- autovector<autovector<VersionEdit*>> edit_lists_;
1276
- // files_to_delete_ contains sst files
1277
- std::set<std::string> files_to_delete_;
1278
- };
1279
-
1280
1243
  // Except in DB::Open(), WriteOptionsFile can only be called when:
1281
1244
  // Persist options to options file.
1282
1245
  // If need_mutex_lock = false, the method will lock DB mutex.
@@ -1393,19 +1356,16 @@ class DBImpl : public DB {
1393
1356
  // be made to the descriptor are added to *edit.
1394
1357
  // recovered_seq is set to less than kMaxSequenceNumber if the log's tail is
1395
1358
  // skipped.
1396
- // recovery_ctx stores the context about version edits and all those
1397
- // edits are persisted to new Manifest after successfully syncing the new WAL.
1398
1359
  virtual Status Recover(
1399
1360
  const std::vector<ColumnFamilyDescriptor>& column_families,
1400
1361
  bool read_only = false, bool error_if_wal_file_exists = false,
1401
1362
  bool error_if_data_exists_in_wals = false,
1402
- uint64_t* recovered_seq = nullptr,
1403
- RecoveryContext* recovery_ctx = nullptr);
1363
+ uint64_t* recovered_seq = nullptr);
1404
1364
 
1405
1365
  virtual bool OwnTablesAndLogs() const { return true; }
1406
1366
 
1407
1367
  // Set DB identity file, and write DB ID to manifest if necessary.
1408
- Status SetDBId(bool read_only, RecoveryContext* recovery_ctx);
1368
+ Status SetDBId(bool read_only);
1409
1369
 
1410
1370
  // REQUIRES: db mutex held when calling this function, but the db mutex can
1411
1371
  // be released and re-acquired. Db mutex will be held when the function
@@ -1414,15 +1374,12 @@ class DBImpl : public DB {
1414
1374
  // not referenced in the MANIFEST (e.g.
1415
1375
  // 1. It's best effort recovery;
1416
1376
  // 2. The VersionEdits referencing the SST files are appended to
1417
- // RecoveryContext, DB crashes when syncing the MANIFEST, the VersionEdits are
1377
+ // MANIFEST, DB crashes when syncing the MANIFEST, the VersionEdits are
1418
1378
  // still not synced to MANIFEST during recovery.)
1419
- // It stores the SST files to be deleted in RecoveryContext. In the
1379
+ // We delete these SST files. In the
1420
1380
  // meantime, we find out the largest file number present in the paths, and
1421
1381
  // bump up the version set's next_file_number_ to be 1 + largest_file_number.
1422
- // recovery_ctx stores the context about version edits and files to be
1423
- // deleted. All those edits are persisted to new Manifest after successfully
1424
- // syncing the new WAL.
1425
- Status DeleteUnreferencedSstFiles(RecoveryContext* recovery_ctx);
1382
+ Status DeleteUnreferencedSstFiles();
1426
1383
 
1427
1384
  // SetDbSessionId() should be called in the constuctor DBImpl()
1428
1385
  // to ensure that db_session_id_ gets updated every time the DB is opened
@@ -1432,11 +1389,6 @@ class DBImpl : public DB {
1432
1389
  Status FailIfTsSizesMismatch(const ColumnFamilyHandle* column_family,
1433
1390
  const Slice& ts) const;
1434
1391
 
1435
- // recovery_ctx stores the context about version edits and
1436
- // LogAndApplyForRecovery persist all those edits to new Manifest after
1437
- // successfully syncing new WAL.
1438
- Status LogAndApplyForRecovery(const RecoveryContext& recovery_ctx);
1439
-
1440
1392
  private:
1441
1393
  friend class DB;
1442
1394
  friend class ErrorHandler;
@@ -1691,10 +1643,9 @@ class DBImpl : public DB {
1691
1643
 
1692
1644
  // REQUIRES: log_numbers are sorted in ascending order
1693
1645
  // corrupted_log_found is set to true if we recover from a corrupted log file.
1694
- Status RecoverLogFiles(std::vector<uint64_t>& log_numbers,
1646
+ Status RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
1695
1647
  SequenceNumber* next_sequence, bool read_only,
1696
- bool* corrupted_log_found,
1697
- RecoveryContext* recovery_ctx);
1648
+ bool* corrupted_log_found);
1698
1649
 
1699
1650
  // The following two methods are used to flush a memtable to
1700
1651
  // storage. The first one is used at database RecoveryTime (when the
@@ -1704,12 +1655,6 @@ class DBImpl : public DB {
1704
1655
  Status WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd,
1705
1656
  MemTable* mem, VersionEdit* edit);
1706
1657
 
1707
- // Move all the WAL files starting from corrupted WAL found to
1708
- // max_wal_number to avoid column family inconsistency error on recovery. It
1709
- // also removes the deleted file from the vector wal_numbers.
1710
- void MoveCorruptedWalFiles(std::vector<uint64_t>& wal_numbers,
1711
- uint64_t corrupted_wal_number);
1712
-
1713
1658
  // Get the size of a log file and, if truncate is true, truncate the
1714
1659
  // log file to its actual size, thereby freeing preallocated space.
1715
1660
  // Return success even if truncate fails
@@ -863,7 +863,7 @@ uint64_t PrecomputeMinLogNumberToKeep2PC(
863
863
  return min_log_number_to_keep;
864
864
  }
865
865
 
866
- Status DBImpl::SetDBId(bool read_only, RecoveryContext* recovery_ctx) {
866
+ Status DBImpl::SetDBId(bool read_only) {
867
867
  Status s;
868
868
  // Happens when immutable_db_options_.write_dbid_to_manifest is set to true
869
869
  // the very first time.
@@ -890,14 +890,14 @@ Status DBImpl::SetDBId(bool read_only, RecoveryContext* recovery_ctx) {
890
890
  }
891
891
  s = GetDbIdentityFromIdentityFile(&db_id_);
892
892
  if (immutable_db_options_.write_dbid_to_manifest && s.ok()) {
893
- assert(!read_only);
894
- assert(recovery_ctx != nullptr);
895
- assert(versions_->GetColumnFamilySet() != nullptr);
896
893
  VersionEdit edit;
897
894
  edit.SetDBId(db_id_);
895
+ Options options;
896
+ MutableCFOptions mutable_cf_options(options);
898
897
  versions_->db_id_ = db_id_;
899
- recovery_ctx->UpdateVersionEdits(
900
- versions_->GetColumnFamilySet()->GetDefault(), edit);
898
+ s = versions_->LogAndApply(versions_->GetColumnFamilySet()->GetDefault(),
899
+ mutable_cf_options, &edit, &mutex_, nullptr,
900
+ /* new_descriptor_log */ false);
901
901
  }
902
902
  } else if (!read_only) {
903
903
  s = SetIdentityFile(env_, dbname_, db_id_);
@@ -905,7 +905,7 @@ Status DBImpl::SetDBId(bool read_only, RecoveryContext* recovery_ctx) {
905
905
  return s;
906
906
  }
907
907
 
908
- Status DBImpl::DeleteUnreferencedSstFiles(RecoveryContext* recovery_ctx) {
908
+ Status DBImpl::DeleteUnreferencedSstFiles() {
909
909
  mutex_.AssertHeld();
910
910
  std::vector<std::string> paths;
911
911
  paths.push_back(NormalizePath(dbname_ + std::string(1, kFilePathSeparator)));
@@ -925,6 +925,7 @@ Status DBImpl::DeleteUnreferencedSstFiles(RecoveryContext* recovery_ctx) {
925
925
 
926
926
  uint64_t next_file_number = versions_->current_next_file_number();
927
927
  uint64_t largest_file_number = next_file_number;
928
+ std::set<std::string> files_to_delete;
928
929
  Status s;
929
930
  for (const auto& path : paths) {
930
931
  std::vector<std::string> files;
@@ -942,9 +943,8 @@ Status DBImpl::DeleteUnreferencedSstFiles(RecoveryContext* recovery_ctx) {
942
943
  const std::string normalized_fpath = path + fname;
943
944
  largest_file_number = std::max(largest_file_number, number);
944
945
  if (type == kTableFile && number >= next_file_number &&
945
- recovery_ctx->files_to_delete_.find(normalized_fpath) ==
946
- recovery_ctx->files_to_delete_.end()) {
947
- recovery_ctx->files_to_delete_.insert(normalized_fpath);
946
+ files_to_delete.find(normalized_fpath) == files_to_delete.end()) {
947
+ files_to_delete.insert(normalized_fpath);
948
948
  }
949
949
  }
950
950
  }
@@ -961,7 +961,21 @@ Status DBImpl::DeleteUnreferencedSstFiles(RecoveryContext* recovery_ctx) {
961
961
  assert(versions_->GetColumnFamilySet());
962
962
  ColumnFamilyData* default_cfd = versions_->GetColumnFamilySet()->GetDefault();
963
963
  assert(default_cfd);
964
- recovery_ctx->UpdateVersionEdits(default_cfd, edit);
964
+ s = versions_->LogAndApply(
965
+ default_cfd, *default_cfd->GetLatestMutableCFOptions(), &edit, &mutex_,
966
+ directories_.GetDbDir(), /*new_descriptor_log*/ false);
967
+ if (!s.ok()) {
968
+ return s;
969
+ }
970
+
971
+ mutex_.Unlock();
972
+ for (const auto& fname : files_to_delete) {
973
+ s = env_->DeleteFile(fname);
974
+ if (!s.ok()) {
975
+ break;
976
+ }
977
+ }
978
+ mutex_.Lock();
965
979
  return s;
966
980
  }
967
981