Skip to content

Commit c35f1c2

Browse files
committed
Suggested patch edits the polar_drop_log_page_cache function.
In particular: - an early return is added when open() fails to avoid calling fadvise()/close() on an invalid fd. - platform specific posix_fadvise() call was replaced with appropriate polar_posix_fadvise() call. The invocation is guarded with directives USE_POSIX_FADVISE and POSIX_FADV_DONTNEED. Falls back to no-op when the call is unavailable. This aligns the function's behavior with existing PolarDB practice in fd.c, xlog.c, etc. - the polar_fd.h header file was included to make the polar_posix_fadvise() function available.
1 parent 56d2eca commit c35f1c2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/backend/postmaster/syslogger.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
/* POLAR */
5858
#include "storage/fd.h"
59+
#include "storage/polar_fd.h"
5960
#include "utils/builtins.h"
6061

6162
/*
@@ -2092,9 +2093,20 @@ polar_drop_log_page_cache(const char *filename)
20922093
{
20932094
ereport(LOG,
20942095
(errmsg("the old log file doesn't exist")));
2096+
2097+
/* no need to go further */
2098+
return;
20952099
}
2096-
ret = posix_fadvise(last_log_fd, 0, 0, POSIX_FADV_DONTNEED);
2097-
/* return zero means success */
2100+
/*
2101+
* on platforms that support posix_fadvise, advise the kernel to drop
2102+
* cached pages for the old log file. Otherwise, skip silently.
2103+
*/
2104+
#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
2105+
ret = polar_posix_fadvise(last_log_fd, 0, 0, POSIX_FADV_DONTNEED);
2106+
#else
2107+
ret = 0;
2108+
#endif
2109+
20982110
if (ret != 0)
20992111
{
21002112
ereport(LOG,

0 commit comments

Comments
 (0)