Skip to content

Commit

Permalink
dbcopy: add counter and extra progress output
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jan 31, 2020
1 parent e892583 commit 14b0c72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion core/src/dird/dbconvert/database_export.cc
Expand Up @@ -88,7 +88,9 @@ void DatabaseExport::operator<<(const RowData& data)

void DatabaseExport::Start()
{
//
if (!db_->SqlQuery("BEGIN")) {
throw std::runtime_error(db_->get_errmsg());
}
}

struct SequenceSchema {
Expand Down Expand Up @@ -147,4 +149,7 @@ void DatabaseExport::End()
}
std::cout << "Updating sequence for table: " << s.table_name << std::endl;
}
if (!db_->SqlQuery("COMMIT")) {
throw std::runtime_error(db_->get_errmsg());
}
}
9 changes: 7 additions & 2 deletions core/src/dird/dbconvert/database_import.cc
Expand Up @@ -54,11 +54,14 @@ struct ResultHandlerContext {
DatabaseExport& exporter;
};

static int counter{};

void DatabaseImport::ExportTo(DatabaseExport& exporter)
{
exporter.Start();

for (const auto& t : table_descriptions_->tables) {
counter = 0;
auto start = std::chrono::steady_clock::now();
std::cout << "Converting table: " << t.table_name
<< ", duration: " << std::flush;
Expand All @@ -70,7 +73,7 @@ void DatabaseImport::ExportTo(DatabaseExport& exporter)
query.erase(query.cend() - 2);
query += "FROM ";
query += t.table_name;
query += " LIMIT 100000";
// query += " LIMIT 100000";

RowData row_data;
row_data.table_name = t.table_name;
Expand Down Expand Up @@ -114,6 +117,8 @@ int DatabaseImport::ResultHandler(void* ctx, int fields, char** row)
}

r->exporter << r->row_data;

if(!(++counter % 10000)) {
std::cout << "." << std::flush;
}
return 0;
}

0 comments on commit 14b0c72

Please sign in to comment.