public inbox for [email protected]help / color / mirror / Atom feed
[PATCH 2/2] Fast COPY FROM into the foreign or sharded table. 4+ messages / 4 participants [nested] [flat]
* [PATCH 2/2] Fast COPY FROM into the foreign or sharded table. @ 2021-01-12 03:54 Andrey Lepikhov <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Andrey Lepikhov @ 2021-01-12 03:54 UTC (permalink / raw) This feature enables bulk COPY into foreign table in the case of multi inserts is possible and foreign table has non-zero number of columns. FDWAPI was extended by next routines: * BeginForeignCopy * EndForeignCopy * ExecForeignCopy BeginForeignCopy and EndForeignCopy initialize and free the CopyState of bulk COPY. The ExecForeignCopy routine send 'COPY ... FROM STDIN' command to the foreign server, in iterative manner send tuples by CopyTo() machinery, send EOF to this connection. Code that constructed list of columns for a given foreign relation in the deparseAnalyzeSql() routine is separated to the deparseRelColumnList(). It is reused in the deparseCopyFromSql(). Added TAP-tests on the specific corner cases of COPY FROM STDIN operation. By the analogy of CopyFrom() the CopyState structure was extended with data_dest_cb callback. It is used for send text representation of a tuple to a custom destination. The PgFdwModifyState structure is extended with the cstate field. It is needed for avoid repeated initialization of CopyState. ALso for this reason CopyTo() routine was split into the set of routines CopyToStart()/ CopyTo()/CopyToFinish(). Enum CopyInsertMethod removed. This logic implements by ri_usesMultiInsert field of the ResultRelInfo sructure. Discussion: https://www.postgresql.org/message-id/flat/3d0909dc-3691-a576-208a-90986e55489f%40postgrespro.ru Authors: Andrey Lepikhov, Ashutosh Bapat, Amit Langote --- contrib/postgres_fdw/deparse.c | 60 ++++++-- .../postgres_fdw/expected/postgres_fdw.out | 46 ++++++- contrib/postgres_fdw/postgres_fdw.c | 130 ++++++++++++++++++ contrib/postgres_fdw/postgres_fdw.h | 1 + contrib/postgres_fdw/sql/postgres_fdw.sql | 45 ++++++ doc/src/sgml/fdwhandler.sgml | 73 ++++++++++ src/backend/commands/copy.c | 4 +- src/backend/commands/copyfrom.c | 126 ++++++++++------- src/backend/commands/copyto.c | 84 ++++++++--- src/backend/executor/execMain.c | 8 +- src/backend/executor/execPartition.c | 27 +++- src/include/commands/copy.h | 8 +- src/include/foreign/fdwapi.h | 15 ++ 13 files changed, 533 insertions(+), 94 deletions(-) diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index 3cf7b4eb1e..b1ca479a65 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -184,6 +184,8 @@ static void appendAggOrderBy(List *orderList, List *targetList, static void appendFunctionName(Oid funcid, deparse_expr_cxt *context); static Node *deparseSortGroupClause(Index ref, List *tlist, bool force_colno, deparse_expr_cxt *context); +static List *deparseRelColumnList(StringInfo buf, Relation rel, + bool enclose_in_parens); /* * Helper functions @@ -1763,6 +1765,20 @@ deparseInsertSql(StringInfo buf, RangeTblEntry *rte, withCheckOptionList, returningList, retrieved_attrs); } +/* + * Deparse COPY FROM into given buf. + * We need to use list of parameters at each query. + */ +void +deparseCopyFromSql(StringInfo buf, Relation rel) +{ + appendStringInfoString(buf, "COPY "); + deparseRelation(buf, rel); + (void) deparseRelColumnList(buf, rel, true); + + appendStringInfoString(buf, " FROM STDIN "); +} + /* * deparse remote UPDATE statement * @@ -2066,6 +2082,30 @@ deparseAnalyzeSizeSql(StringInfo buf, Relation rel) */ void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs) +{ + appendStringInfoString(buf, "SELECT "); + *retrieved_attrs = deparseRelColumnList(buf, rel, false); + + /* Don't generate bad syntax for zero-column relation. */ + if (list_length(*retrieved_attrs) == 0) + appendStringInfoString(buf, "NULL"); + + /* + * Construct FROM clause + */ + appendStringInfoString(buf, " FROM "); + deparseRelation(buf, rel); +} + +/* + * Construct the list of columns of given foreign relation in the order they + * appear in the tuple descriptor of the relation. Ignore any dropped columns. + * Use column names on the foreign server instead of local names. + * + * Optionally enclose the list in parantheses. + */ +static List * +deparseRelColumnList(StringInfo buf, Relation rel, bool enclose_in_parens) { Oid relid = RelationGetRelid(rel); TupleDesc tupdesc = RelationGetDescr(rel); @@ -2074,10 +2114,8 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs) List *options; ListCell *lc; bool first = true; + List *retrieved_attrs = NIL; - *retrieved_attrs = NIL; - - appendStringInfoString(buf, "SELECT "); for (i = 0; i < tupdesc->natts; i++) { /* Ignore dropped columns. */ @@ -2086,6 +2124,9 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs) if (!first) appendStringInfoString(buf, ", "); + else if (enclose_in_parens) + appendStringInfoChar(buf, '('); + first = false; /* Use attribute name or column_name option. */ @@ -2105,18 +2146,13 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs) appendStringInfoString(buf, quote_identifier(colname)); - *retrieved_attrs = lappend_int(*retrieved_attrs, i + 1); + retrieved_attrs = lappend_int(retrieved_attrs, i + 1); } - /* Don't generate bad syntax for zero-column relation. */ - if (first) - appendStringInfoString(buf, "NULL"); + if (enclose_in_parens && list_length(retrieved_attrs) > 0) + appendStringInfoChar(buf, ')'); - /* - * Construct FROM clause - */ - appendStringInfoString(buf, " FROM "); - deparseRelation(buf, rel); + return retrieved_attrs; } /* diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out index c11092f8cc..db7b09c1fe 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -8076,8 +8076,9 @@ copy rem2 from stdin; copy rem2 from stdin; -- ERROR ERROR: new row for relation "loc2" violates check constraint "loc2_f1positive" DETAIL: Failing row contains (-1, xyzzy). -CONTEXT: remote SQL command: INSERT INTO public.loc2(f1, f2) VALUES ($1, $2) -COPY rem2, line 1: "-1 xyzzy" +CONTEXT: COPY loc2, line 1: "-1 xyzzy" +remote SQL command: COPY public.loc2(f1, f2) FROM STDIN +COPY rem2, line 2 select * from rem2; f1 | f2 ----+----- @@ -8088,6 +8089,19 @@ select * from rem2; alter foreign table rem2 drop constraint rem2_f1positive; alter table loc2 drop constraint loc2_f1positive; delete from rem2; +create table foo (a int) partition by list (a); +create table foo1 (like foo); +create foreign table ffoo1 partition of foo for values in (1) + server loopback options (table_name 'foo1'); +create table foo2 (like foo); +create foreign table ffoo2 partition of foo for values in (2) + server loopback options (table_name 'foo2'); +create function print_new_row() returns trigger language plpgsql as $$ + begin raise notice '%', new; return new; end; $$; +create trigger ffoo1_br_trig before insert on ffoo1 + for each row execute function print_new_row(); +copy foo from stdin; +NOTICE: (1) -- Test local triggers create trigger trig_stmt_before before insert on rem2 for each statement execute procedure trigger_func(); @@ -8196,6 +8210,34 @@ drop trigger rem2_trig_row_before on rem2; drop trigger rem2_trig_row_after on rem2; drop trigger loc2_trig_row_before_insert on loc2; delete from rem2; +alter table loc2 drop column f1; +alter table loc2 drop column f2; +copy rem2 from stdin; +ERROR: column "f1" of relation "loc2" does not exist +CONTEXT: remote SQL command: COPY public.loc2(f1, f2) FROM STDIN +COPY rem2, line 3 +alter table loc2 add column f1 int; +alter table loc2 add column f2 int; +select * from rem2; + f1 | f2 +----+---- +(0 rows) + +-- dropped columns locally and on the foreign server +alter table rem2 drop column f1; +alter table rem2 drop column f2; +copy rem2 from stdin; +select * from rem2; +-- +(2 rows) + +alter table loc2 drop column f1; +alter table loc2 drop column f2; +copy rem2 from stdin; +select * from rem2; +-- +(4 rows) + -- test COPY FROM with foreign table created in the same transaction create table loc3 (f1 int, f2 text); begin; diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 2f2d4d171c..fa0eccb485 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -18,6 +18,7 @@ #include "access/sysattr.h" #include "access/table.h" #include "catalog/pg_class.h" +#include "commands/copy.h" #include "commands/defrem.h" #include "commands/explain.h" #include "commands/vacuum.h" @@ -191,6 +192,7 @@ typedef struct PgFdwModifyState /* for update row movement if subplan result rel */ struct PgFdwModifyState *aux_fmstate; /* foreign-insert state, if * created */ + CopyToState cstate; /* foreign COPY state, if used */ } PgFdwModifyState; /* @@ -357,6 +359,13 @@ static void postgresBeginForeignInsert(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo); static void postgresEndForeignInsert(EState *estate, ResultRelInfo *resultRelInfo); +static void postgresBeginForeignCopy(ModifyTableState *mtstate, + ResultRelInfo *resultRelInfo); +static void postgresEndForeignCopy(EState *estate, + ResultRelInfo *resultRelInfo); +static void postgresExecForeignCopy(ResultRelInfo *resultRelInfo, + TupleTableSlot **slots, + int nslots); static int postgresIsForeignRelUpdatable(Relation rel); static bool postgresPlanDirectModify(PlannerInfo *root, ModifyTable *plan, @@ -535,6 +544,9 @@ postgres_fdw_handler(PG_FUNCTION_ARGS) routine->EndForeignModify = postgresEndForeignModify; routine->BeginForeignInsert = postgresBeginForeignInsert; routine->EndForeignInsert = postgresEndForeignInsert; + routine->BeginForeignCopy = postgresBeginForeignCopy; + routine->EndForeignCopy = postgresEndForeignCopy; + routine->ExecForeignCopy = postgresExecForeignCopy; routine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable; routine->PlanDirectModify = postgresPlanDirectModify; routine->BeginDirectModify = postgresBeginDirectModify; @@ -2052,6 +2064,124 @@ postgresEndForeignInsert(EState *estate, finish_foreign_modify(fmstate); } +static PgFdwModifyState *copy_fmstate = NULL; + +static void +pgfdw_copy_dest_cb(void *buf, int len) +{ + PGconn *conn = copy_fmstate->conn; + + if (PQputCopyData(conn, (char *) buf, len) <= 0) + pgfdw_report_error(ERROR, NULL, conn, false, copy_fmstate->query); +} + +/* + * postgresBeginForeignCopy + * Begin an COPY operation on a foreign table + */ +static void +postgresBeginForeignCopy(ModifyTableState *mtstate, + ResultRelInfo *resultRelInfo) +{ + PgFdwModifyState *fmstate; + StringInfoData sql; + RangeTblEntry *rte; + Relation rel = resultRelInfo->ri_RelationDesc; + + rte = exec_rt_fetch(resultRelInfo->ri_RangeTableIndex, mtstate->ps.state); + initStringInfo(&sql); + deparseCopyFromSql(&sql, rel); + + fmstate = create_foreign_modify(mtstate->ps.state, + rte, + resultRelInfo, + CMD_INSERT, + NULL, + sql.data, + NIL, + false, + NIL); + + fmstate->cstate = BeginCopyTo(NULL, NULL, RelationGetDescr(rel), NULL, + InvalidOid, NULL, false, pgfdw_copy_dest_cb, + NIL, NIL); + CopyToStart(fmstate->cstate); + resultRelInfo->ri_FdwState = fmstate; +} + +/* + * postgresEndForeignCopy + * Finish an COPY operation on a foreign table + */ +static void +postgresEndForeignCopy(EState *estate, ResultRelInfo *resultRelInfo) +{ + PgFdwModifyState *fmstate = (PgFdwModifyState *) resultRelInfo->ri_FdwState; + + /* Check correct use of CopyIn FDW API. */ + Assert(fmstate->cstate != NULL); + CopyToFinish(fmstate->cstate); + pfree(fmstate->cstate); + fmstate->cstate = NULL; + finish_foreign_modify(fmstate); +} + +/* + * postgresExecForeignCopy + * Send a number of tuples to the foreign relation. + */ +static void +postgresExecForeignCopy(ResultRelInfo *resultRelInfo, + TupleTableSlot **slots, int nslots) +{ + PgFdwModifyState *fmstate = resultRelInfo->ri_FdwState; + PGresult *res; + PGconn *conn = fmstate->conn; + bool OK = false; + int i; + + /* Check correct use of CopyIn FDW API. */ + Assert(fmstate->cstate != NULL); + + res = PQexec(conn, fmstate->query); + if (PQresultStatus(res) != PGRES_COPY_IN) + pgfdw_report_error(ERROR, res, conn, true, fmstate->query); + PQclear(res); + + PG_TRY(); + { + copy_fmstate = fmstate; + for (i = 0; i < nslots; i++) + CopyOneRowTo(fmstate->cstate, slots[i]); + + OK = true; + } + PG_FINALLY(); + { + /* + * Finish COPY IN protocol. It is needed to do after successful copy or + * after an error. + */ + if (PQputCopyEnd(conn, OK ? NULL : _("canceled by server")) <= 0 || + PQflush(conn)) + pgfdw_report_error(ERROR, NULL, fmstate->conn, false, fmstate->query); + + /* After successfully sending an EOF signal, check command OK. */ + res = PQgetResult(conn); + if ((!OK && PQresultStatus(res) != PGRES_FATAL_ERROR) || + (OK && PQresultStatus(res) != PGRES_COMMAND_OK)) + pgfdw_report_error(ERROR, res, fmstate->conn, true, fmstate->query); + + PQclear(res); + /* Do this to ensure we've pumped libpq back to idle state */ + if (PQgetResult(conn) != NULL) + ereport(ERROR, + (errmsg("unexpected extra results during COPY of table: %s", + PQerrorMessage(conn)))); + } + PG_END_TRY(); +} + /* * postgresIsForeignRelUpdatable * Determine whether a foreign table supports INSERT, UPDATE and/or diff --git a/contrib/postgres_fdw/postgres_fdw.h b/contrib/postgres_fdw/postgres_fdw.h index 19ea27a1bc..c38c219adf 100644 --- a/contrib/postgres_fdw/postgres_fdw.h +++ b/contrib/postgres_fdw/postgres_fdw.h @@ -162,6 +162,7 @@ extern void deparseInsertSql(StringInfo buf, RangeTblEntry *rte, List *targetAttrs, bool doNothing, List *withCheckOptionList, List *returningList, List **retrieved_attrs); +extern void deparseCopyFromSql(StringInfo buf, Relation rel); extern void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index 25dbc08b98..53b9d865da 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -2212,6 +2212,23 @@ alter table loc2 drop constraint loc2_f1positive; delete from rem2; +create table foo (a int) partition by list (a); +create table foo1 (like foo); +create foreign table ffoo1 partition of foo for values in (1) + server loopback options (table_name 'foo1'); +create table foo2 (like foo); +create foreign table ffoo2 partition of foo for values in (2) + server loopback options (table_name 'foo2'); +create function print_new_row() returns trigger language plpgsql as $$ + begin raise notice '%', new; return new; end; $$; +create trigger ffoo1_br_trig before insert on ffoo1 + for each row execute function print_new_row(); + +copy foo from stdin; +1 +2 +\. + -- Test local triggers create trigger trig_stmt_before before insert on rem2 for each statement execute procedure trigger_func(); @@ -2312,6 +2329,34 @@ drop trigger loc2_trig_row_before_insert on loc2; delete from rem2; +alter table loc2 drop column f1; +alter table loc2 drop column f2; +copy rem2 from stdin; +1 foo +2 bar +\. + +alter table loc2 add column f1 int; +alter table loc2 add column f2 int; +select * from rem2; + +-- dropped columns locally and on the foreign server +alter table rem2 drop column f1; +alter table rem2 drop column f2; +copy rem2 from stdin; + + +\. +select * from rem2; + +alter table loc2 drop column f1; +alter table loc2 drop column f2; +copy rem2 from stdin; + + +\. +select * from rem2; + -- test COPY FROM with foreign table created in the same transaction create table loc3 (f1 int, f2 text); begin; diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index 9c9293414c..a9a7402440 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -796,6 +796,79 @@ EndForeignInsert(EState *estate, <para> <programlisting> +void +BeginForeignCopy(ModifyTableState *mtstate, + ResultRelInfo *rinfo); +</programlisting> + + Begin executing an copy operation on a foreign table. This routine is + called right before the first call of <function>ExecForeignCopy</function> + routine for the foreign table. It should perform any initialization needed + prior to the actual COPY FROM operation. + Subsequently, <function>ExecForeignCopy</function> will be called for + a bulk of tuples to be copied into the foreign table. + </para> + + <para> + <literal>mtstate</literal> is the overall state of the + <structname>ModifyTable</structname> plan node being executed; global data about + the plan and execution state is available via this structure. + <literal>rinfo</literal> is the <structname>ResultRelInfo</structname> struct describing + the target foreign table. (The <structfield>ri_FdwState</structfield> field of + <structname>ResultRelInfo</structname> is available for the FDW to store any + private state it needs for this operation.) + </para> + + <para> + When this is called by a <command>COPY FROM</command> command, the + plan-related global data in <literal>mtstate</literal> is not provided. + </para> + + <para> + If the <function>BeginForeignCopy</function> pointer is set to + <literal>NULL</literal>, no action is taken for the initialization. + </para> + + <para> +<programlisting> +void +EndForeignCopy(EState *estate, + ResultRelInfo *rinfo); +</programlisting> + + End the copy operation and release resources. It is normally not important + to release palloc'd memory, but for example open files and connections + to remote servers should be cleaned up. + </para> + + <para> + If the <function>EndForeignCopy</function> pointer is set to + <literal>NULL</literal>, no action is taken for the termination. + </para> + + <para> +<programlisting> +void +ExecForeignCopy(ResultRelInfo *rinfo, + TupleTableSlot **slots, + int nslots); +</programlisting> + + Copy a bulk of tuples into the foreign table. + <literal>rinfo</literal> is the <structname>ResultRelInfo</structname> struct describing + the target foreign table. + <literal>slots</literal> contains the tuples to be inserted; it will match the + row-type definition of the foreign table. + <literal>nslots</literal> is a number of tuples in the <literal>slots</literal> + </para> + + <para> + If the <function>ExecForeignCopy</function> pointer is set to + <literal>NULL</literal>, the <function>ExecForeignInsert</function> routine will be used to run COPY on the foreign table. + </para> + + <para> +<programlisting> int IsForeignRelUpdatable(Relation rel); </programlisting> diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 8c712c8737..cd8aa57026 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -303,8 +303,8 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, { CopyToState cstate; - cstate = BeginCopyTo(pstate, rel, query, relid, - stmt->filename, stmt->is_program, + cstate = BeginCopyTo(pstate, rel, NULL, query, relid, + stmt->filename, stmt->is_program, NULL, stmt->attlist, stmt->options); *processed = DoCopyTo(cstate); /* copy from database to file */ EndCopyTo(cstate); diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 4e2320e2fa..57e4addabf 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -316,54 +316,63 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo, cstate->line_buf_valid = false; save_cur_lineno = cstate->cur_lineno; - /* - * table_multi_insert may leak memory, so switch to short-lived memory - * context before calling it. - */ - oldcontext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); - table_multi_insert(resultRelInfo->ri_RelationDesc, - slots, - nused, - mycid, - ti_options, - buffer->bistate); - MemoryContextSwitchTo(oldcontext); - - for (i = 0; i < nused; i++) + if (resultRelInfo->ri_RelationDesc->rd_rel->relkind == RELKIND_FOREIGN_TABLE) + { + /* Flush into foreign table or partition */ + resultRelInfo->ri_FdwRoutine->ExecForeignCopy(resultRelInfo, + slots, + nused); + } + else { /* - * If there are any indexes, update them for all the inserted tuples, - * and run AFTER ROW INSERT triggers. + * table_multi_insert may leak memory, so switch to short-lived memory + * context before calling it. */ - if (resultRelInfo->ri_NumIndices > 0) - { - List *recheckIndexes; - - cstate->cur_lineno = buffer->linenos[i]; - recheckIndexes = - ExecInsertIndexTuples(resultRelInfo, - buffer->slots[i], estate, false, NULL, - NIL); - ExecARInsertTriggers(estate, resultRelInfo, - slots[i], recheckIndexes, - cstate->transition_capture); - list_free(recheckIndexes); - } + oldcontext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); + table_multi_insert(resultRelInfo->ri_RelationDesc, + slots, + nused, + mycid, + ti_options, + buffer->bistate); + MemoryContextSwitchTo(oldcontext); - /* - * There's no indexes, but see if we need to run AFTER ROW INSERT - * triggers anyway. - */ - else if (resultRelInfo->ri_TrigDesc != NULL && - (resultRelInfo->ri_TrigDesc->trig_insert_after_row || - resultRelInfo->ri_TrigDesc->trig_insert_new_table)) + for (i = 0; i < nused; i++) { - cstate->cur_lineno = buffer->linenos[i]; - ExecARInsertTriggers(estate, resultRelInfo, - slots[i], NIL, cstate->transition_capture); - } + /* + * If there are any indexes, update them for all the inserted tuples, + * and run AFTER ROW INSERT triggers. + */ + if (resultRelInfo->ri_NumIndices > 0) + { + List *recheckIndexes; + + cstate->cur_lineno = buffer->linenos[i]; + recheckIndexes = + ExecInsertIndexTuples(resultRelInfo, buffer->slots[i], + estate, false, NULL, NIL); + ExecARInsertTriggers(estate, resultRelInfo, + slots[i], recheckIndexes, + cstate->transition_capture); + list_free(recheckIndexes); + } + + /* + * There's no indexes, but see if we need to run AFTER ROW INSERT + * triggers anyway. + */ + else if (resultRelInfo->ri_TrigDesc != NULL && + (resultRelInfo->ri_TrigDesc->trig_insert_after_row || + resultRelInfo->ri_TrigDesc->trig_insert_new_table)) + { + cstate->cur_lineno = buffer->linenos[i]; + ExecARInsertTriggers(estate, resultRelInfo, + slots[i], NIL, cstate->transition_capture); + } - ExecClearTuple(slots[i]); + ExecClearTuple(slots[i]); + } } /* Mark that all slots are free */ @@ -668,8 +677,11 @@ CopyFrom(CopyFromState cstate) * checked by calling ExecSetRelationUsesMultiInsert(). It does not matter * whether partitions have any volatile default expressions as we use the * defaults from the target of the COPY command. + * Also, the COPY command requires a non-zero input list of attributes. + * Therefore, the length of the attribute list is checked here. */ if (!cstate->volatile_defexprs && + list_length(cstate->attnumlist) > 0 && !contain_volatile_functions(cstate->whereClause)) target_resultRelInfo->ri_usesMultiInsert = ExecSetRelationUsesMultiInsert(target_resultRelInfo, NULL); @@ -693,10 +705,18 @@ CopyFrom(CopyFromState cstate) * Init copying process into foreign table. Initialization of copying into * foreign partitions will be done later. */ - if (resultRelInfo->ri_FdwRoutine != NULL && - resultRelInfo->ri_FdwRoutine->BeginForeignInsert != NULL) - resultRelInfo->ri_FdwRoutine->BeginForeignInsert(mtstate, - resultRelInfo); + if (target_resultRelInfo->ri_FdwRoutine != NULL) + { + if (target_resultRelInfo->ri_usesMultiInsert) + { + Assert(target_resultRelInfo->ri_FdwRoutine->BeginForeignCopy != NULL); + target_resultRelInfo->ri_FdwRoutine->BeginForeignCopy(mtstate, + resultRelInfo); + } + else if (target_resultRelInfo->ri_FdwRoutine->BeginForeignInsert != NULL) + target_resultRelInfo->ri_FdwRoutine->BeginForeignInsert(mtstate, + resultRelInfo); + } /* Prepare to catch AFTER triggers. */ AfterTriggerBeginQuery(); @@ -1075,10 +1095,16 @@ CopyFrom(CopyFromState cstate) ExecResetTupleTable(estate->es_tupleTable, false); /* Allow the FDW to shut down */ - if (target_resultRelInfo->ri_FdwRoutine != NULL && - target_resultRelInfo->ri_FdwRoutine->EndForeignInsert != NULL) - target_resultRelInfo->ri_FdwRoutine->EndForeignInsert(estate, - target_resultRelInfo); + if (target_resultRelInfo->ri_FdwRoutine != NULL) + { + if (target_resultRelInfo->ri_usesMultiInsert && + target_resultRelInfo->ri_FdwRoutine->EndForeignCopy != NULL) + target_resultRelInfo->ri_FdwRoutine->EndForeignCopy(estate, + target_resultRelInfo); + else if (target_resultRelInfo->ri_FdwRoutine->EndForeignInsert != NULL) + target_resultRelInfo->ri_FdwRoutine->EndForeignInsert(estate, + target_resultRelInfo); + } /* Tear down the multi-insert buffer data */ CopyMultiInsertInfoCleanup(&multiInsertInfo); diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index e04ec1e331..7a10c9dc9e 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -52,6 +52,7 @@ typedef enum CopyDest COPY_FILE, /* to file (or a piped program) */ COPY_OLD_FE, /* to frontend (2.0 protocol) */ COPY_NEW_FE, /* to frontend (3.0 protocol) */ + COPY_CALLBACK /* to callback function */ } CopyDest; /* @@ -82,11 +83,14 @@ typedef struct CopyToStateData /* parameters from the COPY command */ Relation rel; /* relation to copy to */ + TupleDesc tupDesc; /* COPY TO will be used for manual tuple copying + * into the destination */ QueryDesc *queryDesc; /* executable query to copy from */ List *attnumlist; /* integer list of attnums to copy */ char *filename; /* filename, or NULL for STDOUT */ bool is_program; /* is 'filename' a program to popen? */ + copy_data_dest_cb data_dest_cb; /* function for writing data */ CopyFormatOptions opts; Node *whereClause; /* WHERE condition (or NULL) */ @@ -117,7 +121,6 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0"; static void EndCopy(CopyToState cstate); static void ClosePipeToProgram(CopyToState cstate); static uint64 CopyTo(CopyToState cstate); -static void CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot); static void CopyAttributeOutText(CopyToState cstate, char *string); static void CopyAttributeOutCSV(CopyToState cstate, char *string, bool use_quote, bool single_attr); @@ -289,6 +292,14 @@ CopySendEndOfRow(CopyToState cstate) /* Dump the accumulated row as one CopyData message */ (void) pq_putmessage('d', fe_msgbuf->data, fe_msgbuf->len); break; + case COPY_CALLBACK: + Assert(!cstate->opts.binary); +#ifndef WIN32 + CopySendChar(cstate, '\n'); +#else + CopySendString(cstate, "\r\n"); +#endif + cstate->data_dest_cb(fe_msgbuf->data, fe_msgbuf->len); } /* Update the progress */ @@ -382,19 +393,24 @@ EndCopy(CopyToState cstate) CopyToState BeginCopyTo(ParseState *pstate, Relation rel, + TupleDesc srcTupDesc, RawStmt *raw_query, Oid queryRelId, const char *filename, bool is_program, + copy_data_dest_cb data_dest_cb, List *attnamelist, List *options) { CopyToState cstate; - bool pipe = (filename == NULL); + bool pipe = (filename == NULL) && (data_dest_cb == NULL); TupleDesc tupDesc; int num_phys_attrs; MemoryContext oldcontext; + /* Impossible to mix CopyTo modes */ + Assert(rel == NULL || srcTupDesc == NULL); + if (rel != NULL && rel->rd_rel->relkind != RELKIND_RELATION) { if (rel->rd_rel->relkind == RELKIND_VIEW) @@ -459,6 +475,11 @@ BeginCopyTo(ParseState *pstate, tupDesc = RelationGetDescr(cstate->rel); } + else if (srcTupDesc) + { + Assert(!raw_query); + tupDesc = cstate->tupDesc = srcTupDesc; + } else { List *rewritten; @@ -704,6 +725,11 @@ BeginCopyTo(ParseState *pstate, if (whereToSendOutput != DestRemote) cstate->copy_file = stdout; } + else if (data_dest_cb) + { + cstate->copy_dest = COPY_CALLBACK; + cstate->data_dest_cb = data_dest_cb; + } else { cstate->filename = pstrdup(filename); @@ -786,7 +812,7 @@ BeginCopyTo(ParseState *pstate, uint64 DoCopyTo(CopyToState cstate) { - bool pipe = (cstate->filename == NULL); + bool pipe = (cstate->filename == NULL) && (cstate->data_dest_cb == NULL); bool fe_copy = (pipe && whereToSendOutput == DestRemote); uint64 processed; @@ -795,7 +821,9 @@ DoCopyTo(CopyToState cstate) if (fe_copy) SendCopyBegin(cstate); + CopyToStart(cstate); processed = CopyTo(cstate); + CopyToFinish(cstate); if (fe_copy) SendCopyEnd(cstate); @@ -835,18 +863,22 @@ EndCopyTo(CopyToState cstate) } /* - * Copy from relation or query TO file. + * Start COPY TO operation. + * Separated to the routine to prevent duplicate operations in the case of + * manual mode, where tuples are copied to the destination one by one, by call of + * the CopyOneRowTo() routine. */ -static uint64 -CopyTo(CopyToState cstate) +void +CopyToStart(CopyToState cstate) { TupleDesc tupDesc; int num_phys_attrs; ListCell *cur; - uint64 processed; if (cstate->rel) tupDesc = RelationGetDescr(cstate->rel); + else if (cstate->tupDesc) + tupDesc = cstate->tupDesc; else tupDesc = cstate->queryDesc->tupDesc; num_phys_attrs = tupDesc->natts; @@ -933,6 +965,32 @@ CopyTo(CopyToState cstate) CopySendEndOfRow(cstate); } } +} + +/* + * Finish COPY TO operation. + */ +void +CopyToFinish(CopyToState cstate) +{ + if (cstate->opts.binary) + { + /* Generate trailer for a binary copy */ + CopySendInt16(cstate, -1); + /* Need to flush out the trailer */ + CopySendEndOfRow(cstate); + } + + MemoryContextDelete(cstate->rowcontext); +} + +/* + * Copy from relation or query TO file. + */ +static uint64 +CopyTo(CopyToState cstate) +{ + uint64 processed; if (cstate->rel) { @@ -967,23 +1025,13 @@ CopyTo(CopyToState cstate) processed = ((DR_copy *) cstate->queryDesc->dest)->processed; } - if (cstate->opts.binary) - { - /* Generate trailer for a binary copy */ - CopySendInt16(cstate, -1); - /* Need to flush out the trailer */ - CopySendEndOfRow(cstate); - } - - MemoryContextDelete(cstate->rowcontext); - return processed; } /* * Emit one row during CopyTo(). */ -static void +void CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot) { bool need_delim = false; diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index f217486b85..fcfd6027cc 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1294,8 +1294,12 @@ ExecSetRelationUsesMultiInsert(const ResultRelInfo *rri, rri->ri_TrigDesc->trig_insert_new_table) return false; - /* Foreign tables don't support multi-inserts. */ - if (rri->ri_FdwRoutine != NULL) + if (rri->ri_FdwRoutine != NULL && + rri->ri_FdwRoutine->ExecForeignCopy == NULL) + /* + * Foreign tables don't support multi-inserts, unless their FDW + * provides the necessary COPY interface. + */ return false; /* OK, caller can use multi-insert on this relation. */ diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 1f5f392bf9..386a2a9013 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -996,9 +996,16 @@ ExecInitRoutingInfo(ModifyTableState *mtstate, * If the partition is a foreign table, let the FDW init itself for * routing tuples to the partition. */ - if (partRelInfo->ri_FdwRoutine != NULL && - partRelInfo->ri_FdwRoutine->BeginForeignInsert != NULL) - partRelInfo->ri_FdwRoutine->BeginForeignInsert(mtstate, partRelInfo); + if (partRelInfo->ri_FdwRoutine != NULL) + { + if (partRelInfo->ri_usesMultiInsert) + { + Assert(partRelInfo->ri_FdwRoutine->BeginForeignCopy != NULL); + partRelInfo->ri_FdwRoutine->BeginForeignCopy(mtstate, partRelInfo); + } + else if (partRelInfo->ri_FdwRoutine->BeginForeignInsert != NULL) + partRelInfo->ri_FdwRoutine->BeginForeignInsert(mtstate, partRelInfo); + } partRelInfo->ri_CopyMultiInsertBuffer = NULL; @@ -1199,10 +1206,16 @@ ExecCleanupTupleRouting(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo = proute->partitions[i]; /* Allow any FDWs to shut down */ - if (resultRelInfo->ri_FdwRoutine != NULL && - resultRelInfo->ri_FdwRoutine->EndForeignInsert != NULL) - resultRelInfo->ri_FdwRoutine->EndForeignInsert(mtstate->ps.state, - resultRelInfo); + if (resultRelInfo->ri_FdwRoutine != NULL) + { + if (resultRelInfo->ri_usesMultiInsert && + resultRelInfo->ri_FdwRoutine->EndForeignCopy != NULL) + resultRelInfo->ri_FdwRoutine->EndForeignCopy(mtstate->ps.state, + resultRelInfo); + else if (resultRelInfo->ri_FdwRoutine->EndForeignInsert != NULL) + resultRelInfo->ri_FdwRoutine->EndForeignInsert(mtstate->ps.state, + resultRelInfo); + } /* * Check if this result rel is one belonging to the node's subplans, diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h index 8c4748e33d..a7e7224ac8 100644 --- a/src/include/commands/copy.h +++ b/src/include/commands/copy.h @@ -55,6 +55,7 @@ typedef struct CopyFromStateData *CopyFromState; typedef struct CopyToStateData *CopyToState; typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread); +typedef void (*copy_data_dest_cb) (void *outbuf, int len); extern void DoCopy(ParseState *state, const CopyStmt *stmt, int stmt_location, int stmt_len, @@ -78,12 +79,17 @@ extern DestReceiver *CreateCopyDestReceiver(void); /* * internal prototypes */ -extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query, +extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, + TupleDesc tupDesc, RawStmt *query, Oid queryRelId, const char *filename, bool is_program, + copy_data_dest_cb data_dest_cb, List *attnamelist, List *options); extern void EndCopyTo(CopyToState cstate); extern uint64 DoCopyTo(CopyToState cstate); extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist); +extern void CopyToStart(CopyToState cstate); +extern void CopyToFinish(CopyToState cstate); +extern void CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot); #endif /* COPY_H */ diff --git a/src/include/foreign/fdwapi.h b/src/include/foreign/fdwapi.h index 2953499fb1..38e5dbb8e2 100644 --- a/src/include/foreign/fdwapi.h +++ b/src/include/foreign/fdwapi.h @@ -104,6 +104,16 @@ typedef void (*BeginForeignInsert_function) (ModifyTableState *mtstate, typedef void (*EndForeignInsert_function) (EState *estate, ResultRelInfo *rinfo); +typedef void (*BeginForeignCopy_function) (ModifyTableState *mtstate, + ResultRelInfo *rinfo); + +typedef void (*ExecForeignCopy_function) (ResultRelInfo *rinfo, + TupleTableSlot **slots, + int nslots); + +typedef void (*EndForeignCopy_function) (EState *estate, + ResultRelInfo *rinfo); + typedef int (*IsForeignRelUpdatable_function) (Relation rel); typedef bool (*PlanDirectModify_function) (PlannerInfo *root, @@ -220,6 +230,11 @@ typedef struct FdwRoutine IterateDirectModify_function IterateDirectModify; EndDirectModify_function EndDirectModify; + /* Support functions for COPY into foreign tables */ + BeginForeignCopy_function BeginForeignCopy; + ExecForeignCopy_function ExecForeignCopy; + EndForeignCopy_function EndForeignCopy; + /* Functions for SELECT FOR UPDATE/SHARE row locking */ GetForeignRowMarkType_function GetForeignRowMarkType; RefetchForeignRow_function RefetchForeignRow; -- 2.25.1 --------------5FF89B363D34DDCF74284633-- ^ permalink raw reply [nested|flat] 4+ messages in thread
* Regression tests fail on OpenBSD due to low semmns value @ 2024-12-16 05:00 Alexander Lakhin <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Alexander Lakhin @ 2024-12-16 05:00 UTC (permalink / raw) To: pgsql-hackers Hello hackers, A recent buildfarm timeout failure on sawshark [1] made me wonder, what's wrong with that animal — beside that failure, this animal (running on OpenBSD 7.4) produced "too many clients" errors from time to time, e. g., [2], [3]. I deployed OpenBSD 7.4 locally and reproduced "too many clients" and that hang as well. It turned out that OpenBSD has semmns as low as 60 (see [4]) and as a consequence, initdb sets max_connections = 20 for the regression test database. (This can be helpful sometimes, see e.g., [5].) At the same time, paralell_schedule contains groups of 20 tests, for instance: # parallel group (20 tests): select_into random delete select_having select_distinct_on case prepared_xacts namespace select_implicit union arrays portals transactions select_distinct subselect update join aggregates hash_index btree_index Moreover, prepared_xacts performs "\c", and it adds one more connection for a short time, according to postmaster.log: 2024-12-16 06:18:20.290 EET [regression][1563560:91][client backend] [pg_regress/prepared_xacts] LOG: statement: rollback; ... 2024-12-16 06:18:20.290 EET [regression][1563561:2][client backend] [[unknown]] FATAL: sorry, too many clients already ... 2024-12-16 06:18:20.291 EET [regression][1563560:95][client backend] [pg_regress/prepared_xacts] LOG: disconnection: session time: 0:00:00.018 user=law database=regression host=[local] sysctl kern.seminfo.semmns=120 makes the issue go away on this OS; on the hand, "too many clients" failures can be reproduced on other OS, with "max_connections=20" in TEMP_CONFIG. As to the hang, it can be reproduced easily with: TEMP_CONFIG containing max_connections=2 superuser_reserved_connections=0 and parallel_schedule as simple as: test: transactions prepared_xacts test: transactions prepared_xacts Running `TEMP_CONFIG=.../extra.config make -s check`, I can see: # +++ regress check in src/test/regress +++ ... # parallel group (2 tests): prepared_xacts transactions not ok 1 + transactions 56 ms not ok 2 + prepared_xacts 21 ms # (test process exited with exit code 2) # parallel group (2 tests): ### the test is hanging here ### with one backend waiting inside: #0 0x000070c41ed2a007 in epoll_wait (epfd=6, events=0x629f1ce529e8, maxevents=1, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30 #1 0x0000629f1410d64a in WaitEventSetWaitBlock (set=0x629f1ce52980, cur_timeout=-1, occurred_events=0x7ffd4c4ffed0, nevents=1) at latch.c:1564 #2 0x0000629f1410d534 in WaitEventSetWait (set=0x629f1ce52980, timeout=-1, occurred_events=0x7ffd4c4ffed0, nevents=1, wait_event_info=134217779) at latch.c:1510 #3 0x0000629f1410c764 in WaitLatch (latch=0x70c41b86bc24, wakeEvents=33, timeout=0, wait_event_info=134217779) at latch.c:538 #4 0x0000629f1413d032 in ProcWaitForSignal (wait_event_info=134217779) at proc.c:1893 #5 0x0000629f14132eb9 in GetSafeSnapshot (origSnapshot=0x629f147ad360 <CurrentSnapshotData>) at predicate.c:1579 #6 0x0000629f14133261 in GetSerializableTransactionSnapshot (snapshot=0x629f147ad360 <CurrentSnapshotData>) at predicate.c:1695 #7 0x0000629f143afafe in GetTransactionSnapshot () at snapmgr.c:253 #8 0x0000629f1414a7b8 in exec_simple_query (query_string=0x629f1ce580f0 "SELECT * FROM writetest;") at postgres.c:1172 ... So GetSafeSnapshot() waits indefinitely for possibleUnsafeConflicts to become empty (for other backend to remove itself from the list of possible conflicts inside ReleasePredicateLocks()), but it doesn't happen. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=sawshark&dt=2024-12-11%2012%3A20%3A05 [2] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=sawshark&dt=2024-07-22%2001%3A20%3A22 [3] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=sawshark&dt=2024-11-25%2006%3A20%3A22 [4] https://man.openbsd.org/options [5] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=73c9f91a1 Best regards, Alexander ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Regression tests fail on OpenBSD due to low semmns value @ 2024-12-17 03:11 Thomas Munro <[email protected]> parent: Alexander Lakhin <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Thomas Munro @ 2024-12-17 03:11 UTC (permalink / raw) To: Alexander Lakhin <[email protected]>; +Cc: pgsql-hackers On Mon, Dec 16, 2024 at 6:00 PM Alexander Lakhin <[email protected]> wrote: > It turned out that OpenBSD has semmns as low as 60 (see [4]) Whenever I run into this, or my Mac requires manual ipcrm to clean up leaked SysV kernel junk, I rebase my patch for sema_kind = 'futex'. Here it goes. It could be updated to support NetBSD I believe, but I didn't try as its futex stuff came out later. Then I remember why I didn't go anywhere with it. It triggers a thought loop about flipping it all around: use futexes to implement lwlocks directly in place, and get rid of semaphores completely, but that involves a few rabbit holes and sub-projects. From memory: classic r/w lock implementation on futexes is tricky but doable in the portability constraints, futex fallback implementation even works surprisingly well but has fun memory map sub-problems, actually lwlock is not really a classic r/w lock as it has sprouted extra funky APIs that lead the intrepid rabbit-holer to design an entirely different new concurrency primitive that is really wanted for those users, a couple of other places use raw semaphores directly namely procarray.c and clog.c and if you stare at those for long you will be overwhelmed with a desire to rewrite them, EOVERFLOW. Attachments: [application/x-patch] 0001-A-basic-API-for-futexes.patch (10.9K, ../../CA+hUKGKumYUweDKnF5S1Y_jKxMa94w_q8=j8-xDdhOgxcaVCiQ@mail.gmail.com/2-0001-A-basic-API-for-futexes.patch) download | inline diff: From 42054d64062da58e44a383d0ed0c1c6bb2ba88e1 Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Sun, 24 Oct 2021 21:48:26 +1300 Subject: [PATCH 1/3] A basic API for futexes. A thin wrapper for basic 32 bit futex wait and wake. Currently, it maps to native support on Linux, DragonFlyBSD, FreeBSD, OpenBSD and macOS, with detection via configure/meson. NetBSD could probably be added, no investigated. Windows' WaitOnAddress() can't because it only works between threads. A latch-based backend-only fallback implementation is plausible. --- configure | 4 +- configure.ac | 5 + meson.build | 5 + src/backend/port/meson.build | 2 +- src/include/pg_config.h.in | 15 +++ src/include/port/pg_futex.h | 171 +++++++++++++++++++++++++++++++++++ 6 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 src/include/port/pg_futex.h diff --git a/configure b/configure index 518c33b73a9..6eb25178dab 100755 --- a/configure +++ b/configure @@ -13227,7 +13227,7 @@ fi ## Header files ## -for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h mbarrier.h sys/epoll.h sys/event.h sys/personality.h sys/prctl.h sys/procctl.h sys/signalfd.h sys/ucred.h termios.h ucred.h xlocale.h +for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h linux/futex.h mbarrier.h sys/epoll.h sys/event.h sys/futex.h sys/personality.h sys/prctl.h sys/procctl.h sys/signalfd.h sys/ucred.h sys/umtx.h termios.h ucred.h xlocale.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -15044,7 +15044,7 @@ fi LIBS_including_readline="$LIBS" LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'` -for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l +for ac_func in __ulock_wait backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range umtx_sleep uselocale wcstombs_l do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 247ae97fa4c..6b4f3e0f2e5 100644 --- a/configure.ac +++ b/configure.ac @@ -1438,14 +1438,17 @@ AC_CHECK_HEADERS(m4_normalize([ execinfo.h getopt.h ifaddrs.h + linux/futex.h mbarrier.h sys/epoll.h sys/event.h + sys/futex.h sys/personality.h sys/prctl.h sys/procctl.h sys/signalfd.h sys/ucred.h + sys/umtx.h termios.h ucred.h xlocale.h @@ -1707,6 +1710,7 @@ LIBS_including_readline="$LIBS" LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'` AC_CHECK_FUNCS(m4_normalize([ + __ulock_wait backtrace_symbols copyfile copy_file_range @@ -1727,6 +1731,7 @@ AC_CHECK_FUNCS(m4_normalize([ strsignal syncfs sync_file_range + umtx_sleep uselocale wcstombs_l ])) diff --git a/meson.build b/meson.build index e5ce437a5c7..5c9775f1a6e 100644 --- a/meson.build +++ b/meson.build @@ -2380,15 +2380,18 @@ header_checks = [ 'execinfo.h', 'getopt.h', 'ifaddrs.h', + 'linux/futex.h', 'mbarrier.h', 'strings.h', 'sys/epoll.h', 'sys/event.h', + 'sys/futex.h', 'sys/personality.h', 'sys/prctl.h', 'sys/procctl.h', 'sys/signalfd.h', 'sys/ucred.h', + 'sys/umtx.h', 'termios.h', 'ucred.h', 'xlocale.h', @@ -2611,6 +2614,7 @@ endif # XXX: Might be worth conditioning some checks on the OS, to avoid doing # unnecessary checks over and over, particularly on windows. func_checks = [ + ['__ulock_wait'], ['backtrace_symbols', {'dependencies': [execinfo_dep]}], ['clock_gettime', {'dependencies': [rt_dep], 'define': false}], ['copyfile'], @@ -2654,6 +2658,7 @@ func_checks = [ ['strsignal'], ['sync_file_range'], ['syncfs'], + ['umtx_sleep'], ['uselocale'], ['wcstombs_l'], ] diff --git a/src/backend/port/meson.build b/src/backend/port/meson.build index 7820e86016d..e34499bafb3 100644 --- a/src/backend/port/meson.build +++ b/src/backend/port/meson.build @@ -5,7 +5,7 @@ backend_sources += files( ) -if cdata.has('USE_UNNAMED_POSIX_SEMAPHORES') or cdata.has('USE_NAMED_POSIX_SEMAPHORES') +if cdata.has('USE_UNNAMED_POSIX_SEMAPHORES') or cdata.has('USE_NAMED_POSIX_SEMAPHORES') or cdata.has('USE_FUTEX_SEMAPHORES') backend_sources += files('posix_sema.c') endif diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 07b2f798abd..19cbf6e74ee 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -265,6 +265,9 @@ /* Define to 1 if you have the `zstd' library (-lzstd). */ #undef HAVE_LIBZSTD +/* Define to 1 if you have the <linux/futex.h> header file. */ +#undef HAVE_LINUX_FUTEX_H + /* Define to 1 if you have the <mbarrier.h> header file. */ #undef HAVE_MBARRIER_H @@ -418,6 +421,9 @@ /* Define to 1 if you have the <sys/event.h> header file. */ #undef HAVE_SYS_EVENT_H +/* Define to 1 if you have the <sys/futex.h> header file. */ +#undef HAVE_SYS_FUTEX_H + /* Define to 1 if you have the <sys/personality.h> header file. */ #undef HAVE_SYS_PERSONALITY_H @@ -439,6 +445,9 @@ /* Define to 1 if you have the <sys/ucred.h> header file. */ #undef HAVE_SYS_UCRED_H +/* Define to 1 if you have the <sys/umtx.h> header file. */ +#undef HAVE_SYS_UMTX_H + /* Define to 1 if you have the <termios.h> header file. */ #undef HAVE_TERMIOS_H @@ -448,6 +457,9 @@ /* Define to 1 if you have the <ucred.h> header file. */ #undef HAVE_UCRED_H +/* Define to 1 if you have the `umtx_sleep' function. */ +#undef HAVE_UMTX_SLEEP + /* Define to 1 if the system has the type `union semun'. */ #undef HAVE_UNION_SEMUN @@ -538,6 +550,9 @@ /* Define to 1 if your compiler understands _Static_assert. */ #undef HAVE__STATIC_ASSERT +/* Define to 1 if you have the `__ulock_wait' function. */ +#undef HAVE___ULOCK_WAIT + /* Define as the maximum alignment requirement of any C data type. */ #undef MAXIMUM_ALIGNOF diff --git a/src/include/port/pg_futex.h b/src/include/port/pg_futex.h new file mode 100644 index 00000000000..e5ae05d1d5a --- /dev/null +++ b/src/include/port/pg_futex.h @@ -0,0 +1,171 @@ +/* + * Minimal wrapper over futex APIs. + */ + +#ifndef PG_FUTEX_H +#define PG_FUTEX_H + +#if defined(HAVE_LINUX_FUTEX_H) + +/* https://man7.org/linux/man-pages/man2/futex.2.html */ + +#include <linux/futex.h> +#include <sys/syscall.h> + +#elif defined(HAVE_SYS_FUTEX_H) + +/* https://man.openbsd.org/futex, since OpenBSD 6.2. */ + +#include <sys/time.h> +#include <sys/futex.h> + +#elif defined(HAVE_SYS_UMTX_H) + +/* https://www.freebsd.org/cgi/man.cgi?query=_umtx_op */ + +#include <sys/types.h> +#include <sys/umtx.h> + +#elif defined(HAVE_UMTX_SLEEP) + +/* https://man.dragonflybsd.org/?command=umtx§ion=2 */ + +#include <unistd.h> + +#elif defined(HAVE___ULOCK_WAIT) + +/* + * This interface is undocumented, but provided by libSystem.dylib since + * xnu-3789.1.32 (macOS 10.12, 2016) and is used by eg libc++. + * + * https://github.com/apple/darwin-xnu/blob/main/bsd/kern/sys_ulock.c + * https://github.com/apple/darwin-xnu/blob/main/bsd/sys/ulock.h + */ + +#include <stdint.h> + +#define UL_COMPARE_AND_WAIT_SHARED 3 +#define ULF_WAKE_ALL 0x00000100 + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern int __ulock_wait(uint32_t operation, + void *addr, + uint64_t value, + uint32_t timeout); +extern int __ulock_wake(uint32_t operation, + void *addr, + uint64_t wake_value); + +#ifdef __cplusplus +} +#endif + +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* + * Wait for someone to call pg_futex_wake() for the same address, with an + * initial check that the value pointed to by 'fut' matches 'value' and an + * optional timeout. Returns 0 when woken, and otherwise -1, with errno set to + * EAGAIN if the initial value check fails, and otherwise errors including + * EINTR, ETIMEDOUT and EFAULT. + */ +static int +pg_futex_wait_u32(volatile void *fut, + uint32 value, + struct timespec *timeout) +{ +#if defined(HAVE_LINUX_FUTEX_H) + if (syscall(SYS_futex, fut, FUTEX_WAIT, value, timeout, 0, 0) == 0) + return 0; +#elif defined(HAVE_SYS_FUTEX_H) + if ((errno = futex((void *) fut, FUTEX_WAIT, (int) value, timeout, NULL)) == 0) + return 0; + if (errno == ECANCELED) + errno = EINTR; +#elif defined(HAVE_SYS_UMTX_H) + if (_umtx_op((void *) fut, UMTX_OP_WAIT_UINT, value, 0, timeout) == 0) + return 0; +#elif defined(HAVE_UMTX_SLEEP) + if (umtx_sleep((volatile const int *) fut, + (int) value, + timeout ? timeout->tv_sec * 1000000 + timeout->tv_nsec / 1000 : 0) == 0) + return 0; + if (errno == EBUSY) + errno = EAGAIN; +#elif defined (HAVE___ULOCK_WAIT) + if (__ulock_wait(UL_COMPARE_AND_WAIT_SHARED, + (void *) fut, + value, + timeout ? timeout->tv_sec * 1000000 + timeout->tv_nsec / 1000 : 0) >= 0) + return 0; +#else + /* + * If we wanted to simulate futexes on systems that don't have them, here + * we could add a link from our PGPROC struct to a shared memory hash + * table using "fut" (ie address) as the key, then compare *fut == value. + * If false, remove link and fail with EAGAIN. If true, sleep on proc + * latch. This wouldn't work for DSM segments; for those, we could search + * for matching DSM segment mappings in this process, and convert the key + * to { segment ID, offset }, just like kernels do internally to make + * inter-process futexes work on shared memory, but... ugh. + */ + errno = ENOSYS; +#endif + + Assert(errno != 0); + + return -1; +} + +/* + * Wake up to nwaiters waiters that currently wait on the same address as + * 'fut'. Returns 0 on success, and -1 on failure, with errno set. Though + * some of these interfaces can tell us how many were woken, they can't all do + * that, so we'll hide that information. + */ +static int +pg_futex_wake(volatile void *fut, int nwaiters) +{ +#if defined(HAVE_LINUX_FUTEX_H) + if (syscall(SYS_futex, fut, FUTEX_WAKE, nwaiters, NULL, 0, 0) >= 0) + return 0; +#elif defined(HAVE_SYS_FUTEX_H) + if (futex(fut, FUTEX_WAKE, nwaiters, NULL, NULL) >= 0) + return 0; +#elif defined(HAVE_SYS_UMTX_H) + if (_umtx_op((void *) fut, UMTX_OP_WAKE, nwaiters, 0, 0) == 0) + return 0; +#elif defined(HAVE_UMTX_SLEEP) + if (umtx_wakeup((volatile const int *) fut, nwaiters) == 0) + return 0; +#elif defined (HAVE___ULOCK_WAIT) + if (__ulock_wake(UL_COMPARE_AND_WAIT_SHARED | (nwaiters > 1 ? ULF_WAKE_ALL : 0), + (void *) fut, + 0) >= 0) + return 0; + if (errno == ENOENT) + return 0; +#else + /* No implementation available. */ + errno = ENOSYS; +#endif + + Assert(errno != 0); + + return -1; +} + +#ifdef __cplusplus +} +#endif + +#endif /* PG_FUTEX_H */ -- 2.47.1 [application/x-patch] 0002-Add-futex-based-semaphore-replacement.patch (8.7K, ../../CA+hUKGKumYUweDKnF5S1Y_jKxMa94w_q8=j8-xDdhOgxcaVCiQ@mail.gmail.com/3-0002-Add-futex-based-semaphore-replacement.patch) download | inline diff: From 4614b62e6006f202a3a739175b73684e51c58914 Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Sun, 24 Oct 2021 21:48:26 +1300 Subject: [PATCH 2/3] Add futex-based semaphore replacement. Provide a drop-in replacement for POSIX unnamed semaphores using futexes. This is useful for systems that don't have unnamed semaphores at all, or don't have unnamed semaphores that work inter-process. This should be more convenient because the alternatives require kernel resources and configuration and can also leak in various scenarios. --- configure | 16 +++++- configure.ac | 16 +++++- src/backend/port/posix_sema.c | 100 +++++++++++++++++++++++++++++++++- src/include/pg_config.h.in | 3 + 4 files changed, 128 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 6eb25178dab..acbd7cecaac 100755 --- a/configure +++ b/configure @@ -17632,6 +17632,10 @@ if test "$ac_res" != no; then : fi fi + if test x"$PREFERRED_SEMAPHORES" = x"FUTEX" ; then + # Need futex implementation for this + USE_FUTEX_SEMAPHORES=1 + fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking which semaphore API to use" >&5 $as_echo_n "checking which semaphore API to use... " >&6; } if test x"$USE_NAMED_POSIX_SEMAPHORES" = x"1" ; then @@ -17648,11 +17652,19 @@ $as_echo "#define USE_UNNAMED_POSIX_SEMAPHORES 1" >>confdefs.h SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c" sematype="unnamed POSIX" else + if test x"$USE_FUTEX_SEMAPHORES" = x"1" ; then + +$as_echo "#define USE_FUTEX_SEMAPHORES 1" >>confdefs.h + + SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c" + sematype="futex" + else $as_echo "#define USE_SYSV_SEMAPHORES 1" >>confdefs.h - SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c" - sematype="System V" + SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c" + sematype="System V" + fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $sematype" >&5 diff --git a/configure.ac b/configure.ac index 6b4f3e0f2e5..9001c85a74e 100644 --- a/configure.ac +++ b/configure.ac @@ -2164,6 +2164,10 @@ if test "$PORTNAME" != "win32"; then # Need sem_init for this AC_SEARCH_LIBS(sem_init, [rt pthread], [USE_UNNAMED_POSIX_SEMAPHORES=1]) fi + if test x"$PREFERRED_SEMAPHORES" = x"FUTEX" ; then + # Need futex implementation for this + USE_FUTEX_SEMAPHORES=1 + fi AC_MSG_CHECKING([which semaphore API to use]) if test x"$USE_NAMED_POSIX_SEMAPHORES" = x"1" ; then AC_DEFINE(USE_NAMED_POSIX_SEMAPHORES, 1, [Define to select named POSIX semaphores.]) @@ -2175,9 +2179,15 @@ if test "$PORTNAME" != "win32"; then SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c" sematype="unnamed POSIX" else - AC_DEFINE(USE_SYSV_SEMAPHORES, 1, [Define to select SysV-style semaphores.]) - SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c" - sematype="System V" + if test x"$USE_FUTEX_SEMAPHORES" = x"1" ; then + AC_DEFINE(USE_FUTEX_SEMAPHORES, 1, [Define to select futex semaphores.]) + SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c" + sematype="futex" + else + AC_DEFINE(USE_SYSV_SEMAPHORES, 1, [Define to select SysV-style semaphores.]) + SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c" + sematype="System V" + fi fi fi AC_MSG_RESULT([$sematype]) diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c index 64186ec0a7e..88feec98d40 100644 --- a/src/backend/port/posix_sema.c +++ b/src/backend/port/posix_sema.c @@ -36,6 +36,10 @@ #include "storage/pg_sema.h" #include "storage/shmem.h" +#if defined(USE_FUTEX_SEMAPHORES) +#include "port/atomics.h" +#include "port/pg_futex.h" +#endif /* see file header comment */ #if defined(USE_NAMED_POSIX_SEMAPHORES) && defined(EXEC_BACKEND) @@ -45,6 +49,9 @@ typedef union SemTPadded { sem_t pgsem; +#if defined(USE_FUTEX_SEMAPHORES) + pg_atomic_uint32 futexsem; +#endif char pad[PG_CACHE_LINE_SIZE]; } SemTPadded; @@ -70,6 +77,72 @@ static int nextSemKey; /* next name to try */ static void ReleaseSemaphores(int status, Datum arg); +#ifdef USE_FUTEX_SEMAPHORES + +/* + * An implementation of POSIX unnamed semaphores in shared memory, for OSes + * that lack them but have futexes. + */ + +/* + * Like standard sem_init() with pshared set to 1, meaning that it can work in + * shared memory. + */ +static void +pg_futex_sem_init(pg_atomic_uint32 *fut, uint32 value) +{ + pg_atomic_init_u32(fut, value); +} + +/* + * Like standard sem_post(). + */ +static int +pg_futex_sem_post(pg_atomic_uint32 *fut) +{ + pg_atomic_fetch_add_u32(fut, 1); + + /* + * XXX If some bits held a waiter count, then the result of the above could + * be checked to see if we can skip this call. Currently we use semaphores + * as the slow path for lwlocks, so there is always expected to be a + * waiter. + */ + return pg_futex_wake(fut, INT_MAX); +} + +/* + * Like standard sem_wait(). + */ +static int +pg_futex_sem_wait(pg_atomic_uint32 *fut) +{ + uint32 value = 1; + + /* + * The futex API takes void *, so there is no type checking or casting. + * Assert that pg_atomic_uint32 is really just a wrapped uint32_t as + * required by the kernel for 32 bit futex pre-check. + */ + StaticAssertStmt(sizeof(*fut) == sizeof(uint32), "unexpected size"); + + while (!pg_atomic_compare_exchange_u32(fut, &value, value - 1)) + { + if (value == 0) + { + /* Wait for someone else to move it above 0. */ + if (pg_futex_wait_u32(fut, 0, NULL) < 0) + { + if (errno != EAGAIN) + return -1; + /* The value changed under our feet. Try again. */ + } + } + } + return 0; +} + +#endif #ifdef USE_NAMED_POSIX_SEMAPHORES @@ -124,7 +197,7 @@ PosixSemaphoreCreate(void) return mySem; } -#else /* !USE_NAMED_POSIX_SEMAPHORES */ +#elif defined(USE_UNNAMED_POSIX_SEMAPHORES) /* * PosixSemaphoreCreate @@ -139,6 +212,7 @@ PosixSemaphoreCreate(sem_t *sem) } #endif /* USE_NAMED_POSIX_SEMAPHORES */ +#ifndef USE_FUTEX_SEMAPHORES /* * PosixSemaphoreKill - removes a semaphore @@ -156,6 +230,7 @@ PosixSemaphoreKill(sem_t *sem) elog(LOG, "sem_destroy failed: %m"); #endif } +#endif /* @@ -238,18 +313,22 @@ PGReserveSemaphores(int maxSemas) static void ReleaseSemaphores(int status, Datum arg) { +#ifdef USE_NAMED_POSIX_SEMAPHORES int i; -#ifdef USE_NAMED_POSIX_SEMAPHORES for (i = 0; i < numSems; i++) PosixSemaphoreKill(mySemPointers[i]); free(mySemPointers); #endif #ifdef USE_UNNAMED_POSIX_SEMAPHORES + int i; + for (i = 0; i < numSems; i++) PosixSemaphoreKill(PG_SEM_REF(sharedSemas + i)); #endif + + /* Futex-based semaphores have no kernel resource to clean up. */ } /* @@ -261,7 +340,9 @@ PGSemaphore PGSemaphoreCreate(void) { PGSemaphore sema; +#ifndef USE_FUTEX_SEMAPHORES sem_t *newsem; +#endif /* Can't do this in a backend, because static state is postmaster's */ Assert(!IsUnderPostmaster); @@ -274,6 +355,9 @@ PGSemaphoreCreate(void) /* Remember new sema for ReleaseSemaphores */ mySemPointers[numSems] = newsem; sema = (PGSemaphore) newsem; +#elif defined(USE_FUTEX_SEMAPHORES) + sema = &sharedSemas[numSems]; + pg_futex_sem_init(&sema->sem_padded.futexsem, 1); #else sema = &sharedSemas[numSems]; newsem = PG_SEM_REF(sema); @@ -293,6 +377,9 @@ PGSemaphoreCreate(void) void PGSemaphoreReset(PGSemaphore sema) { +#ifdef USE_FUTEX_SEMAPHORES + pg_atomic_write_u32(&sema->sem_padded.futexsem, 0); +#else /* * There's no direct API for this in POSIX, so we have to ratchet the * semaphore down to 0 with repeated trywait's. @@ -308,6 +395,7 @@ PGSemaphoreReset(PGSemaphore sema) elog(FATAL, "sem_trywait failed: %m"); } } +#endif } /* @@ -323,7 +411,11 @@ PGSemaphoreLock(PGSemaphore sema) /* See notes in sysv_sema.c's implementation of PGSemaphoreLock. */ do { +#if defined(USE_FUTEX_SEMAPHORES) + errStatus = pg_futex_sem_wait(&sema->sem_padded.futexsem); +#else errStatus = sem_wait(PG_SEM_REF(sema)); +#endif } while (errStatus < 0 && errno == EINTR); if (errStatus < 0) @@ -348,7 +440,11 @@ PGSemaphoreUnlock(PGSemaphore sema) */ do { +#if defined(USE_FUTEX_SEMAPHORES) + errStatus = pg_futex_sem_post(&sema->sem_padded.futexsem); +#else errStatus = sem_post(PG_SEM_REF(sema)); +#endif } while (errStatus < 0 && errno == EINTR); if (errStatus < 0) diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 19cbf6e74ee..3fe34e91e1b 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -669,6 +669,9 @@ /* Define to 1 to build with BSD Authentication support. (--with-bsd-auth) */ #undef USE_BSD_AUTH +/* Define to select futex semaphores. */ +#undef USE_FUTEX_SEMAPHORES + /* Define to build with ICU support. (--with-icu) */ #undef USE_ICU -- 2.47.1 [application/x-patch] 0003-Use-futex-based-semaphores-on-macOS.patch (1.3K, ../../CA+hUKGKumYUweDKnF5S1Y_jKxMa94w_q8=j8-xDdhOgxcaVCiQ@mail.gmail.com/4-0003-Use-futex-based-semaphores-on-macOS.patch) download | inline diff: From aca7b842282f2f180ff497072079a9c40556f6fc Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Thu, 26 Oct 2023 18:43:26 +1300 Subject: [PATCH 3/3] Use futex-based semaphores on macOS. --- meson.build | 2 ++ src/template/darwin | 13 +------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index 5c9775f1a6e..0e713f65a66 100644 --- a/meson.build +++ b/meson.build @@ -205,6 +205,8 @@ if host_system == 'cygwin' mod_link_with_dir = 'libdir' elif host_system == 'darwin' + sema_kind = 'futex' + dlsuffix = '.dylib' library_path_var = 'DYLD_LIBRARY_PATH' diff --git a/src/template/darwin b/src/template/darwin index e8eb9390687..d3c78805401 100644 --- a/src/template/darwin +++ b/src/template/darwin @@ -14,17 +14,6 @@ fi # Extra CFLAGS for code that will go into a shared library CFLAGS_SL="" -# Select appropriate semaphore support. Darwin 6.0 (macOS 10.2) and up -# support System V semaphores; before that we have to use named POSIX -# semaphores, which are less good for our purposes because they eat a -# file descriptor per backend per max_connection slot. -case $host_os in - darwin[015].*) - USE_NAMED_POSIX_SEMAPHORES=1 - ;; - *) - USE_SYSV_SEMAPHORES=1 - ;; -esac +USE_FUTEX_SEMAPHORES=1 DLSUFFIX=".dylib" -- 2.47.1 ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Regression tests fail on OpenBSD due to low semmns value @ 2024-12-17 04:29 Tom Lane <[email protected]> parent: Thomas Munro <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2024-12-17 04:29 UTC (permalink / raw) To: Thomas Munro <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; pgsql-hackers Thomas Munro <[email protected]> writes: > Whenever I run into this, or my Mac requires manual ipcrm to clean up > leaked SysV kernel junk, I rebase my patch for sema_kind = 'futex'. > Here it goes. It could be updated to support NetBSD I believe, but I > didn't try as its futex stuff came out later. FWIW, I looked at a nearby NetBSD 10.0 machine. It has /usr/include/sys/futex.h, which includes this enticing comment: /* * Definitions for the __futex(2) synchronization primitive. * * These definitions are intended to be ABI-compatible with the * Linux futex(2) system call. */ However, the complete lack of any user-level documentation makes me misdoubt the extent of their commitment to this :-( I have the same concern about depending on undocumented macOS APIs. Other than that, getting off of SysV semaphores would be a nice thing to do. regards, tom lane ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-12-17 04:29 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-01-12 03:54 [PATCH 2/2] Fast COPY FROM into the foreign or sharded table. Andrey Lepikhov <[email protected]> 2024-12-16 05:00 Regression tests fail on OpenBSD due to low semmns value Alexander Lakhin <[email protected]> 2024-12-17 03:11 ` Re: Regression tests fail on OpenBSD due to low semmns value Thomas Munro <[email protected]> 2024-12-17 04:29 ` Re: Regression tests fail on OpenBSD due to low semmns value Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox