Skip to content

Commit 1d0612e

Browse files
authored
Merge pull request #199 from zuyue/master
complete
2 parents 3883185 + 0f49882 commit 1d0612e

23 files changed

+2566
-4988
lines changed

postgresql/doc/src/sgml/bgworker.sgml

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ typedef struct BackgroundWorker
7979
int bgw_flags;
8080
BgWorkerStartTime bgw_start_time;
8181
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
82-
bgworker_main_type bgw_main;
83-
char bgw_library_name[BGW_MAXLEN]; /* only if bgw_main is NULL */
84-
char bgw_function_name[BGW_MAXLEN]; /* only if bgw_main is NULL */
82+
char bgw_library_name[BGW_MAXLEN];
83+
char bgw_function_name[BGW_MAXLEN];
8584
Datum bgw_main_arg;
8685
char bgw_extra[BGW_EXTRALEN];
8786
int bgw_notify_pid;
@@ -98,9 +97,8 @@ typedef struct BackgroundWorker
9897
int bgw_flags;
9998
BgWorkerStartTime bgw_start_time;
10099
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
101-
bgworker_main_type bgw_main;
102-
char bgw_library_name[BGW_MAXLEN]; /* only if bgw_main is NULL */
103-
char bgw_function_name[BGW_MAXLEN]; /* only if bgw_main is NULL */
100+
char bgw_library_name[BGW_MAXLEN];
101+
char bgw_function_name[BGW_MAXLEN];
104102
Datum bgw_main_arg;
105103
char bgw_extra[BGW_EXTRALEN];
106104
int bgw_notify_pid;
@@ -218,37 +216,20 @@ ____________________________________________________________________________-->
218216
<structfield>bgw_restart_time</structfield>是在崩溃情况下<command>postgres</command>启动进程之前等待的时间间隔,以秒计。它可以是任何正值,或者<literal>BGW_NEVER_RESTART</literal>,表示在出现崩溃后不重启进程。
219217
</para>
220218

221-
<!--==========================orignal english content==========================
222-
<para>
223-
<structfield>bgw_main</structfield> is a pointer to the function to run when
224-
the process is started. This field can only safely be used to launch
225-
functions within the core server, because shared libraries may be loaded
226-
at different starting addresses in different backend processes. This will
227-
happen on all platforms when the library is loaded using any mechanism
228-
other than <xref linkend="guc-shared-preload-libraries">. Even when that
229-
mechanism is used, address space layout variations will still occur on
230-
Windows, and when <literal>EXEC_BACKEND</> is used. Therefore, most users
231-
of this API should set this field to NULL. If it is non-NULL, it takes
232-
precedence over <structfield>bgw_library_name</> and
233-
<structfield>bgw_function_name</>.
234-
</para>
235-
____________________________________________________________________________-->
236-
<para>
237-
<structfield>bgw_main</structfield>是进程被启动后要运行的函数指针。这个域只有在核心服务器中被用来执行函数时才是安全的,因为共享库在不同的后端进程中可能被载入到不同的起始地址。当使用除<xref linkend="guc-shared-preload-libraries">之外的任何机制载入共享库时,这种情况会在所有的平台上发生。即便是使用<xref linkend="guc-shared-preload-libraries">机制,在 Windows 上使用了<literal>EXEC_BACKEND</>的情况下,地址空间布局变化也仍然会发生。因此,这个 API 的大部分使用者应该把这个域设置为 NULL。如果这个域为非 NULL,它会优先于<structfield>bgw_library_name</>和<structfield>bgw_function_name</>。
238-
</para>
239-
240219
<!--==========================orignal english content==========================
241220
<para>
242221
<structfield>bgw_library_name</structfield> is the name of a library in
243222
which the initial entry point for the background worker should be sought.
244223
The named library will be dynamically loaded by the worker process and
245224
<structfield>bgw_function_name</structfield> will be used to identify the
246-
function to be called. If loading a function from the core code,
247-
<structfield>bgw_main</> should be set instead.
225+
function to be called. If loading a function from the core code, this must
226+
be set to "postgres".
248227
</para>
249228
____________________________________________________________________________-->
250229
<para>
251-
<structfield>bgw_library_name</structfield>是应该在其中定位后台工作者初始入口点的库名称。所指的库将被工作者进程动态载入并且<structfield>bgw_function_name</structfield>将被用来标识要调用的函数。如果从核心代码载入一个函数,应该设置<structfield>bgw_main</>。
230+
<structfield>bgw_library_name</structfield>是应该在其中定位后台工作者初始入口点的库名称。
231+
所指的库将被工作者进程动态载入并且<structfield>bgw_function_name</structfield>将被用来标识要调用的函数。
232+
如果从核心代码载入一个函数,则必须设置为"postgres"。
252233
</para>
253234

254235
<!--==========================orignal english content==========================
@@ -265,20 +246,17 @@ ____________________________________________________________________________-->
265246
<!--==========================orignal english content==========================
266247
<para>
267248
<structfield>bgw_main_arg</structfield> is the <type>Datum</> argument
268-
to the background worker main function. Regardless of whether that
269-
function is specified via <structfield>bgw_main</> or via the combination
270-
of <function>bgw_library_name</> and <function>bgw_function_name</>,
271-
this main function should take a single argument of type <type>Datum</>
272-
and return <type>void</>. <structfield>bgw_main_arg</structfield> will be
273-
passed as the argument. In addition, the global variable
274-
<literal>MyBgworkerEntry</literal>
249+
to the background worker main function. This main function should take a
250+
single argument of type <type>Datum</> and return <type>void</>.
251+
<structfield>bgw_main_arg</structfield> will be passed as the argument.
252+
In addition, the global variable <literal>MyBgworkerEntry</literal>
275253
points to a copy of the <structname>BackgroundWorker</structname> structure
276254
passed at registration time; the worker may find it helpful to examine
277255
this structure.
278256
</para>
279257
____________________________________________________________________________-->
280258
<para>
281-
<structfield>bgw_main_arg</structfield>是后台工作者主函数的<type>Datum</>参数。不管是通过<structfield>bgw_main</>还是通过<function>bgw_library_name</>和<function>bgw_function_name</>的组合指定这个函数,这个主函数应该有一个单一的<type>Datum</>类型的参数,并且返回<type>void</>。<structfield>bgw_main_arg</structfield>将被作为参数传递。此外,全局变量<literal>MyBgworkerEntry</literal>指向注册时传入的<structname>BackgroundWorker</structname>结构的一份拷贝,工作者会发现检查这个结构会很有用。
259+
<structfield>bgw_main_arg</structfield>是后台工作者主函数的<type>Datum</>参数。这个主函数应该有一个单一的<type>Datum</>类型的参数,并且返回<type>void</>。<structfield>bgw_main_arg</structfield>将被作为参数传递。此外,全局变量<literal>MyBgworkerEntry</literal>指向注册时传入的<structname>BackgroundWorker</structname>结构的一份拷贝,工作者会发现检查这个结构会很有用。
282260
</para>
283261

284262
<!--==========================orignal english content==========================
@@ -348,15 +326,15 @@ ____________________________________________________________________________-->
348326
<!--==========================orignal english content==========================
349327
<para>
350328
Signals are initially blocked when control reaches the
351-
<structfield>bgw_main</> function, and must be unblocked by it; this is to
329+
background worker's main function, and must be unblocked by it; this is to
352330
allow the process to customize its signal handlers, if necessary.
353331
Signals can be unblocked in the new process by calling
354332
<function>BackgroundWorkerUnblockSignals</> and blocked by calling
355333
<function>BackgroundWorkerBlockSignals</>.
356334
</para>
357335
____________________________________________________________________________-->
358336
<para>
359-
当控制到达<structfield>bgw_main</>函数时,信号初始会被阻塞,并且必须被它解除阻塞。这是为了允许进程自定义它的信号处理器。在新进程中可以通过调用<function>BackgroundWorkerUnblockSignals</>来解除对信号的阻塞,还可以通过调用<function>BackgroundWorkerBlockSignals</>来阻塞信号。
337+
当控制到达后台进程的主函数时,信号初始会被阻塞,并且必须被它解除阻塞。这是为了允许进程自定义它的信号处理器。在新进程中可以通过调用<function>BackgroundWorkerUnblockSignals</>来解除对信号的阻塞,还可以通过调用<function>BackgroundWorkerBlockSignals</>来阻塞信号。
360338
</para>
361339

362340
<!--==========================orignal english content==========================

0 commit comments

Comments
 (0)