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

Function RefreshCurrentVersion

pg_documentdb/src/utils/version_utils.c:199–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197
198
199static ExtensionVersion
200RefreshCurrentVersion(void)
201{
202 ExtensionVersion currentVersion = { 0 };
203
204 if (unlikely(CurrentVersion == NULL))
205 {
206 /* Shared memory is not initialized */
207 return currentVersion;
208 }
209
210 pg_memory_barrier();
211 currentVersion = *CurrentVersion;
212
213 if (currentVersion.Major > DocDB_V0 ||
214 (currentVersion.Major == DocDB_V0 && currentVersion.Minor > 0))
215 {
216 return currentVersion;
217 }
218
219 /*
220 * Temporarily disable unimportant logs related to version lookup
221 * so that regression test outputs don't become flaky (e.g.: due to commands
222 * being executed locally).
223 */
224 int savedGUCLevel = NewGUCNestLevel();
225 SetGUCLocally("client_min_messages", "WARNING");
226
227 bool readOnly = true;
228 bool isNull = false;
229
230 char *versionString = ExtensionExecuteQueryOnLocalhostViaLibPQ(
231 GetVersionRefreshQuery());
232
233 if (strcmp(versionString, "") == 0)
234 {
235 RollbackGUCChange(savedGUCLevel);
236 return currentVersion;
237 }
238
239 int nargs = 1;
240 Oid argTypes[1] = { TEXTOID };
241 Datum argValues[1] = { CStringGetTextDatum(versionString) };
242 char *argNulls = NULL;
243
244 /* LibPQ returns an array as a string in the form of {Major,Minor,Hotfix}, so instead
245 * of parsing the string directly, let's use postgres to cast it to an array as a datum
246 * and just use the deconstructed array to get the values out of it. */
247 Datum versionDatum = ExtensionExecuteQueryWithArgsViaSPI("SELECT $1::int4[]",
248 nargs, argTypes, argValues,
249 argNulls, readOnly,
250 SPI_OK_SELECT, &isNull);
251
252 ArrayType *arrayValue = DatumGetArrayTypeP(versionDatum);
253 RollbackGUCChange(savedGUCLevel);
254
255 Datum *elements = NULL;
256 int numElements = 0;

Calls 5

SetGUCLocallyFunction · 0.85
GetVersionRefreshQueryFunction · 0.85
RollbackGUCChangeFunction · 0.85

Tested by

no test coverage detected