|
40 | 40 |
|
41 | 41 | PG_MODULE_MAGIC;
|
42 | 42 |
|
43 |
| -typedef struct BasicArchiveData |
44 |
| -{ |
45 |
| - MemoryContext context; |
46 |
| -} BasicArchiveData; |
47 |
| - |
48 | 43 | static char *archive_directory = NULL;
|
49 | 44 |
|
50 |
| -static void basic_archive_startup(ArchiveModuleState *state); |
51 | 45 | static bool basic_archive_configured(ArchiveModuleState *state);
|
52 | 46 | static bool basic_archive_file(ArchiveModuleState *state, const char *file, const char *path);
|
53 |
| -static void basic_archive_file_internal(const char *file, const char *path); |
54 | 47 | static bool check_archive_directory(char **newval, void **extra, GucSource source);
|
55 | 48 | static bool compare_files(const char *file1, const char *file2);
|
56 |
| -static void basic_archive_shutdown(ArchiveModuleState *state); |
57 | 49 |
|
58 | 50 | static const ArchiveModuleCallbacks basic_archive_callbacks = {
|
59 |
| - .startup_cb = basic_archive_startup, |
| 51 | + .startup_cb = NULL, |
60 | 52 | .check_configured_cb = basic_archive_configured,
|
61 | 53 | .archive_file_cb = basic_archive_file,
|
62 |
| - .shutdown_cb = basic_archive_shutdown |
| 54 | + .shutdown_cb = NULL |
63 | 55 | };
|
64 | 56 |
|
65 | 57 | /*
|
@@ -93,24 +85,6 @@ _PG_archive_module_init(void)
|
93 | 85 | return &basic_archive_callbacks;
|
94 | 86 | }
|
95 | 87 |
|
96 |
| -/* |
97 |
| - * basic_archive_startup |
98 |
| - * |
99 |
| - * Creates the module's memory context. |
100 |
| - */ |
101 |
| -void |
102 |
| -basic_archive_startup(ArchiveModuleState *state) |
103 |
| -{ |
104 |
| - BasicArchiveData *data; |
105 |
| - |
106 |
| - data = (BasicArchiveData *) MemoryContextAllocZero(TopMemoryContext, |
107 |
| - sizeof(BasicArchiveData)); |
108 |
| - data->context = AllocSetContextCreate(TopMemoryContext, |
109 |
| - "basic_archive", |
110 |
| - ALLOCSET_DEFAULT_SIZES); |
111 |
| - state->private_data = (void *) data; |
112 |
| -} |
113 |
| - |
114 | 88 | /*
|
115 | 89 | * check_archive_directory
|
116 | 90 | *
|
@@ -176,74 +150,6 @@ basic_archive_configured(ArchiveModuleState *state)
|
176 | 150 | */
|
177 | 151 | static bool
|
178 | 152 | basic_archive_file(ArchiveModuleState *state, const char *file, const char *path)
|
179 |
| -{ |
180 |
| - sigjmp_buf local_sigjmp_buf; |
181 |
| - MemoryContext oldcontext; |
182 |
| - BasicArchiveData *data = (BasicArchiveData *) state->private_data; |
183 |
| - MemoryContext basic_archive_context = data->context; |
184 |
| - |
185 |
| - /* |
186 |
| - * We run basic_archive_file_internal() in our own memory context so that |
187 |
| - * we can easily reset it during error recovery (thus avoiding memory |
188 |
| - * leaks). |
189 |
| - */ |
190 |
| - oldcontext = MemoryContextSwitchTo(basic_archive_context); |
191 |
| - |
192 |
| - /* |
193 |
| - * Since the archiver operates at the bottom of the exception stack, |
194 |
| - * ERRORs turn into FATALs and cause the archiver process to restart. |
195 |
| - * However, using ereport(ERROR, ...) when there are problems is easy to |
196 |
| - * code and maintain. Therefore, we create our own exception handler to |
197 |
| - * catch ERRORs and return false instead of restarting the archiver |
198 |
| - * whenever there is a failure. |
199 |
| - */ |
200 |
| - if (sigsetjmp(local_sigjmp_buf, 1) != 0) |
201 |
| - { |
202 |
| - /* Since not using PG_TRY, must reset error stack by hand */ |
203 |
| - error_context_stack = NULL; |
204 |
| - |
205 |
| - /* Prevent interrupts while cleaning up */ |
206 |
| - HOLD_INTERRUPTS(); |
207 |
| - |
208 |
| - /* Report the error and clear ErrorContext for next time */ |
209 |
| - EmitErrorReport(); |
210 |
| - FlushErrorState(); |
211 |
| - |
212 |
| - /* Close any files left open by copy_file() or compare_files() */ |
213 |
| - AtEOSubXact_Files(false, InvalidSubTransactionId, InvalidSubTransactionId); |
214 |
| - |
215 |
| - /* Reset our memory context and switch back to the original one */ |
216 |
| - MemoryContextSwitchTo(oldcontext); |
217 |
| - MemoryContextReset(basic_archive_context); |
218 |
| - |
219 |
| - /* Remove our exception handler */ |
220 |
| - PG_exception_stack = NULL; |
221 |
| - |
222 |
| - /* Now we can allow interrupts again */ |
223 |
| - RESUME_INTERRUPTS(); |
224 |
| - |
225 |
| - /* Report failure so that the archiver retries this file */ |
226 |
| - return false; |
227 |
| - } |
228 |
| - |
229 |
| - /* Enable our exception handler */ |
230 |
| - PG_exception_stack = &local_sigjmp_buf; |
231 |
| - |
232 |
| - /* Archive the file! */ |
233 |
| - basic_archive_file_internal(file, path); |
234 |
| - |
235 |
| - /* Remove our exception handler */ |
236 |
| - PG_exception_stack = NULL; |
237 |
| - |
238 |
| - /* Reset our memory context and switch back to the original one */ |
239 |
| - MemoryContextSwitchTo(oldcontext); |
240 |
| - MemoryContextReset(basic_archive_context); |
241 |
| - |
242 |
| - return true; |
243 |
| -} |
244 |
| - |
245 |
| -static void |
246 |
| -basic_archive_file_internal(const char *file, const char *path) |
247 | 153 | {
|
248 | 154 | char destination[MAXPGPATH];
|
249 | 155 | char temp[MAXPGPATH + 256];
|
@@ -277,7 +183,7 @@ basic_archive_file_internal(const char *file, const char *path)
|
277 | 183 | fsync_fname(destination, false);
|
278 | 184 | fsync_fname(archive_directory, true);
|
279 | 185 |
|
280 |
| - return; |
| 186 | + return true; |
281 | 187 | }
|
282 | 188 |
|
283 | 189 | ereport(ERROR,
|
@@ -317,6 +223,8 @@ basic_archive_file_internal(const char *file, const char *path)
|
317 | 223 |
|
318 | 224 | ereport(DEBUG1,
|
319 | 225 | (errmsg("archived \"%s\" via basic_archive", file)));
|
| 226 | + |
| 227 | + return true; |
320 | 228 | }
|
321 | 229 |
|
322 | 230 | /*
|
@@ -399,35 +307,3 @@ compare_files(const char *file1, const char *file2)
|
399 | 307 |
|
400 | 308 | return ret;
|
401 | 309 | }
|
402 |
| - |
403 |
| -/* |
404 |
| - * basic_archive_shutdown |
405 |
| - * |
406 |
| - * Frees our allocated state. |
407 |
| - */ |
408 |
| -static void |
409 |
| -basic_archive_shutdown(ArchiveModuleState *state) |
410 |
| -{ |
411 |
| - BasicArchiveData *data = (BasicArchiveData *) state->private_data; |
412 |
| - MemoryContext basic_archive_context; |
413 |
| - |
414 |
| - /* |
415 |
| - * If we didn't get to storing the pointer to our allocated state, we |
416 |
| - * don't have anything to clean up. |
417 |
| - */ |
418 |
| - if (data == NULL) |
419 |
| - return; |
420 |
| - |
421 |
| - basic_archive_context = data->context; |
422 |
| - Assert(CurrentMemoryContext != basic_archive_context); |
423 |
| - |
424 |
| - if (MemoryContextIsValid(basic_archive_context)) |
425 |
| - MemoryContextDelete(basic_archive_context); |
426 |
| - data->context = NULL; |
427 |
| - |
428 |
| - /* |
429 |
| - * Finally, free the state. |
430 |
| - */ |
431 |
| - pfree(data); |
432 |
| - state->private_data = NULL; |
433 |
| -} |
0 commit comments