| 156 | /*=================*/ |
| 157 | |
| 158 | static void |
| 159 | ValidateAndParseKillOpCommand(pgbson *commandSpec, ParsedKillOpArgs *parsedArgs) |
| 160 | { |
| 161 | bson_iter_t commandIter; |
| 162 | PgbsonInitIterator(commandSpec, &commandIter); |
| 163 | while (bson_iter_next(&commandIter)) |
| 164 | { |
| 165 | StringView keyView = bson_iter_key_string_view(&commandIter); |
| 166 | |
| 167 | if (StringViewEqualsCString(&keyView, "op")) |
| 168 | { |
| 169 | EnsureTopLevelFieldType("op", &commandIter, BSON_TYPE_UTF8); |
| 170 | uint32 length = 0; |
| 171 | const char *operationId = bson_iter_utf8(&commandIter, &length); |
| 172 | if (length == 0) |
| 173 | { |
| 174 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 175 | errmsg("The op field in killOp cannot be empty"))); |
| 176 | } |
| 177 | StringView operationIdView = CreateStringViewFromString(operationId); |
| 178 | |
| 179 | parsedArgs->opIdView = StringViewFindSuffix(&operationIdView, ':'); |
| 180 | if (parsedArgs->opIdView.length == 0 || |
| 181 | (parsedArgs->opIdView.length + 1 == operationIdView.length)) |
| 182 | { |
| 183 | /* |
| 184 | * Validate incorrect formats for the operationId |
| 185 | * such as '', ':<id>', '<id>:' |
| 186 | * Valid format is shardid:opid |
| 187 | */ |
| 188 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28625), |
| 189 | errmsg( |
| 190 | "The op argument to killOp must be of the format shardid:opid but found %.*s", |
| 191 | operationIdView.length, operationIdView.string), |
| 192 | errdetail_log( |
| 193 | "The op argument to killOp must be of the format shardid:opid but found %.*s", |
| 194 | operationIdView.length, operationIdView.string))); |
| 195 | } |
| 196 | |
| 197 | parsedArgs->shardIdView.string = operationIdView.string; |
| 198 | parsedArgs->shardIdView.length = operationIdView.length - |
| 199 | parsedArgs->opIdView.length - 1; /* -1 for `:` */ |
| 200 | |
| 201 | CheckValidIdentifier(&parsedArgs->shardIdView, "shardId"); |
| 202 | CheckValidIdentifier(&parsedArgs->opIdView, "opId"); |
| 203 | } |
| 204 | else if (StringViewEqualsCString(&keyView, "$db")) |
| 205 | { |
| 206 | EnsureTopLevelFieldType("$db", &commandIter, BSON_TYPE_UTF8); |
| 207 | parsedArgs->databaseName = (char *) bson_iter_utf8(&commandIter, NULL); |
| 208 | } |
| 209 | else if (StringViewEqualsCString(&keyView, "killOp")) |
| 210 | { |
| 211 | /* This is the command name, ignore */ |
| 212 | continue; |
| 213 | } |
| 214 | else if (!IsCommonSpecIgnoredField(keyView.string)) |
| 215 | { |
no test coverage detected