MCPcopy Create free account
hub / github.com/apache/cloudberry / libpq_executeFileMap

Function libpq_executeFileMap

src/bin/pg_rewind/libpq_fetch.c:443–529  ·  view source on GitHub ↗

* Fetch all changed blocks from remote source data directory. */

Source from the content-addressed store, hash-verified

441 * Fetch all changed blocks from remote source data directory.
442 */
443void
444libpq_executeFileMap(filemap_t *map)
445{
446 file_entry_t *entry;
447 const char *sql;
448 PGresult *res;
449 int i;
450
451 /*
452 * First create a temporary table, and load it with the blocks that we
453 * need to fetch.
454 */
455 sql = "CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4);";
456 run_simple_command(sql);
457
458 sql = "COPY fetchchunks FROM STDIN";
459 res = PQexec(conn, sql);
460
461 if (PQresultStatus(res) != PGRES_COPY_IN)
462 pg_fatal("could not send file list: %s",
463 PQresultErrorMessage(res));
464 PQclear(res);
465
466 for (i = 0; i < map->narray; i++)
467 {
468 entry = map->array[i];
469
470 /* If this is a relation file, copy the modified blocks */
471 execute_pagemap(&entry->target_pages_to_overwrite, entry->path);
472
473 switch (entry->action)
474 {
475 case FILE_ACTION_NONE:
476 /* nothing else to do */
477 break;
478
479 case FILE_ACTION_COPY:
480 /* Truncate the old file out of the way, if any */
481 open_target_file(entry->path, true);
482 fetch_file_range(entry->path, 0, entry->source_size);
483 break;
484
485 case FILE_ACTION_TRUNCATE:
486 truncate_target_file(entry->path, entry->source_size);
487 break;
488
489 case FILE_ACTION_COPY_TAIL:
490 fetch_file_range(entry->path, entry->target_size, entry->source_size);
491 break;
492
493 case FILE_ACTION_REMOVE:
494 remove_target(entry);
495 break;
496
497 case FILE_ACTION_CREATE:
498 create_target(entry);
499 break;
500

Callers

nothing calls this directly

Calls 15

PQexecFunction · 0.85
PQresultStatusFunction · 0.85
pg_fatalFunction · 0.85
PQresultErrorMessageFunction · 0.85
PQclearFunction · 0.85
open_target_fileFunction · 0.85
fetch_file_rangeFunction · 0.85
truncate_target_fileFunction · 0.85
remove_targetFunction · 0.85
create_targetFunction · 0.85
PQputCopyEndFunction · 0.85
PQerrorMessageFunction · 0.85

Tested by

no test coverage detected