MCPcopy Create free account
hub / github.com/documentdb/documentdb / CancelIndexBuildRequest

Function CancelIndexBuildRequest

pg_documentdb/src/commands/drop_indexes.c:990–1053  ·  view source on GitHub ↗

* CancelIndexBuildRequest cancels an existing (if there is any) running Index Build request for the indexId. */

Source from the content-addressed store, hash-verified

988 * CancelIndexBuildRequest cancels an existing (if there is any) running Index Build request for the indexId.
989 */
990static void
991CancelIndexBuildRequest(int indexId)
992{
993 char *cancelIndexBuildRequestQueryStr = NULL;
994 cancelIndexBuildRequestQueryStr = TryGetCancelIndexBuildQuery(indexId,
995 CREATE_INDEX_COMMAND_TYPE);
996 if (cancelIndexBuildRequestQueryStr == NULL)
997 {
998 StringInfo cmdStr = makeStringInfo();
999 appendStringInfo(cmdStr,
1000 "SELECT iq.global_pid AS pid, iq.start_time AS timestamp");
1001 appendStringInfo(cmdStr,
1002 " FROM %s iq WHERE index_id = %d",
1003 GetIndexQueueName(), indexId);
1004
1005 cancelIndexBuildRequestQueryStr = cmdStr->data;
1006 }
1007
1008 bool readOnly = true;
1009 int numValues = 2;
1010 bool isNull[2];
1011 Datum results[2];
1012 ExtensionExecuteMultiValueQueryViaSPI(cancelIndexBuildRequestQueryStr, readOnly,
1013 SPI_OK_SELECT, results,
1014 isNull, numValues);
1015
1016 if (!isNull[0])
1017 {
1018 StringInfo cancelCmdStr = makeStringInfo();
1019 Datum pid = results[0];
1020 Datum startTime = results[1];
1021 appendStringInfo(cancelCmdStr,
1022 " SELECT pg_cancel_backend(pid) FROM pg_stat_activity ");
1023 appendStringInfo(cancelCmdStr, " WHERE pid = $1 AND query_start = $2");
1024
1025 int nargs = 2;
1026 Oid argTypes[2] = { INT4OID, TIMESTAMPTZOID };
1027 Datum argValues[2] = {
1028 pid, startTime
1029 };
1030
1031 const char **parameterValues = (const char **) palloc(nargs * sizeof(char *));
1032
1033 /* TODO Now we also have a provision to cancel create index only when authenticated user is same as user who has submitted the create index request if(GetAuthenticatedUserId == user_oid)*/
1034 for (int i = 0; i < nargs; i++)
1035 {
1036 bool isVarlen;
1037 Oid funcOutOid;
1038 getTypeOutputInfo(argTypes[i], &funcOutOid, &isVarlen);
1039 parameterValues[i] = OidOutputFunctionCall(funcOutOid, argValues[i]);
1040 }
1041
1042 /* Run pg_cancel_backend as super user via libpq otherwise we will not be able to cancel cron-job (launched as super user) */
1043 ExtensionExecuteQueryWithArgsAsUserOnLocalhostViaLibPQ(cancelCmdStr->data,
1044 DocumentDBApiExtensionOwner(),
1045 nargs, argTypes,
1046 parameterValues);
1047

Callers 1

Tested by

no test coverage detected