8000 Fix confusion around reporting operations in progress. by dimitri · Pull Request #658 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix confusion around reporting operations in progress. #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bin/pgcopydb/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -6911,9 +6911,7 @@ catalog_iter_s_table_in_copy_init(SourceTableIterator *iter)
" select t.oid, qname, nspname, relname, amname, restore_list_name, "
" relpages, reltuples, t.bytes, t.bytes_pretty, "
" exclude_data, part_key, "
" part.partcount, s.partnum, part.min, part.max, "
" c.srcrowcount, c.srcsum, c.dstrowcount, c.dstsum, "
" sum(s.duration), sum(s.bytes) "
" part.partcount, s.partnum, part.min, part.max "

" from process p "
" join s_table t on p.tableoid = t.oid "
Expand Down
84 changes: 82 additions & 2 deletions src/bin/pgcopydb/progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ static bool copydb_table_array_as_json(DatabaseCatalog *sourceDB,
JSON_Object *jsobj,
const char *key);

static bool copydb_table_in_progress_as_json(DatabaseCatalog *sourceDB,
SourceTableArray *tableInProgress,
JSON_Object *jsobj,
const char *key);

static bool copydb_index_in_progress_as_json(SourceIndexArray *indexInProgress,
JSON_Object *jsobj,
const char *key);

static bool copydb_index_array_as_json(DatabaseCatalog *sourceDB,
JSON_Object *jsobj,
const char *key);
Expand Down Expand Up @@ -242,6 +251,43 @@ copydb_table_array_as_json(DatabaseCatalog *sourceDB,
}


/*
* copydb_table_in_progress_as_json prepares the given SourceTableArray as a
* JSON array of objects within the given JSON_Object.
*/
static bool
copydb_table_in_progress_as_json(DatabaseCatalog *sourceDB,
SourceTableArray *tableInProgress,
JSON_Object *jsobj,
const char *key)
{
JSON_Value *jsTables = json_value_init_array();
JSON_Array *jsTableArray = json_value_get_array(jsTables);

TableContext context = {
.sourceDB = sourceDB,
.jsTableArray = jsTableArray
};

for (int i = 0; i < tableInProgress->count; i++)
{
SourceTable *table = &(tableInProgress->array[i]);

if (!copydb_table_array_as_json_hook(&context, table))
{
log_error("Failed to populate the JSON array of tables in progress, "
"see above for details");
return false;
}
}

/* attach the JSON array to the main JSON object under the provided key */
json_object_set_value(jsobj, key, jsTables);

return true;
}


/*
* copydb_table_array_as_json_hook is an iterator callback function.
*/
Expand Down Expand Up @@ -400,6 +446,37 @@ copydb_index_array_as_json(DatabaseCatalog *sourceDB,
}


/*
* copydb_index_in_progress_as_json prepares the given SourceIndexArray as a
* JSON array of objects within the given JSON_Object.
*/
static bool
copydb_index_in_progress_as_json(SourceIndexArray *indexInProgress,
JSON_Object *jsobj,
const char *key)
{
JSON_Value *jsIndexes = json_value_init_array();
JSON_Array *jsIndexArray = json_value_get_array(jsIndexes);

for (int i = 0; i < indexInProgress->count; i++)
{
SourceIndex *index = &(indexInProgress->array[i]);

if (!copydb_index_array_as_json_hook(jsIndexArray, index))
{
log_error("Failed to populate the JSON array of indexs in progress, "
"see above for details");
return false;
}
}

/* attach the JSON array to the main JSON object under the provided key */
json_object_set_value(jsobj, key, jsIndexes);

return true;
}


/*
* copydb_index_array_as_json_hook is an iterator callback function.
*/
Expand Down Expand Up @@ -832,7 +909,10 @@ copydb_progress_as_json(CopyDataSpec *copySpecs,
/* in-progress */
SourceTableArray *tableArray = &(progress->tableInProgress);

if (!copydb_table_array_as_json(sourceDB, jsTableObj, "in-progress"))
if (!copydb_table_in_progress_as_json(sourceDB,
tableArray,
jsTableObj,
"in-progress"))
{
/* errors have already been logged */
return false;
Expand Down Expand Up @@ -868,7 +948,7 @@ copydb_progress_as_json(CopyDataSpec *copySpecs,
/* in-progress */
SourceIndexArray *indexArray = &(progress->indexInProgress);

if (!copydb_index_array_as_json(sourceDB, jsIndexObj, "in-progress"))
if (!copydb_index_in_progress_as_json(indexArray, jsIndexObj, "in-progress"))
{
/* errors have already been logged */
return false;
Expand Down
0