Skip to content

Commit

Permalink
cats: rename batch insert functions for file table
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Feb 27, 2020
1 parent ba478be commit 690e968
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 58 deletions.
6 changes: 3 additions & 3 deletions core/src/cats/bdb_dbi.h
Expand Up @@ -70,9 +70,9 @@ class BareosDbDBI : public BareosDbPrivateInterface {
SQL_FIELD* SqlFetchField(void);
bool SqlFieldIsNotNull(int field_type);
bool SqlFieldIsNumeric(int field_type);
bool SqlBatchStart(JobControlRecord* jcr);
bool SqlBatchEnd(JobControlRecord* jcr, const char* error);
bool SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar);
bool SqlBatchStartFileTable(JobControlRecord* jcr);
bool SqlBatchEndFileTable(JobControlRecord* jcr, const char* error);
bool SqlBatchInsertFileTable(JobControlRecord* jcr, AttributesDbRecord* ar);

public:
/*
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/bdb_mysql.h
Expand Up @@ -75,9 +75,9 @@ class BareosDbMysql : public BareosDbPrivateInterface {
SQL_FIELD* SqlFetchField(void) override;
bool SqlFieldIsNotNull(int field_type) override;
bool SqlFieldIsNumeric(int field_type) override;
bool SqlBatchStart(JobControlRecord* jcr) override;
bool SqlBatchEnd(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar) override;
bool SqlBatchStartFileTable(JobControlRecord* jcr) override;
bool SqlBatchEndFileTable(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsertFileTable(JobControlRecord* jcr, AttributesDbRecord* ar) override;

public:
/*
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/bdb_postgresql.h
Expand Up @@ -74,9 +74,9 @@ class BareosDbPostgresql : public BareosDbPrivateInterface {
SQL_FIELD* SqlFetchField(void) override;
bool SqlFieldIsNotNull(int field_type) override;
bool SqlFieldIsNumeric(int field_type) override;
bool SqlBatchStart(JobControlRecord* jcr) override;
bool SqlBatchEnd(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar) override;
bool SqlBatchStartFileTable(JobControlRecord* jcr) override;
bool SqlBatchEndFileTable(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsertFileTable(JobControlRecord* jcr, AttributesDbRecord* ar) override;

bool CheckDatabaseEncoding(JobControlRecord* jcr);

Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/bdb_priv.h
Expand Up @@ -64,10 +64,10 @@ class BareosDbPrivateInterface : public BareosDb {
virtual SQL_FIELD* SqlFetchField(void) override = 0;
virtual bool SqlFieldIsNotNull(int field_type) override = 0;
virtual bool SqlFieldIsNumeric(int field_type) override = 0;
virtual bool SqlBatchStart(JobControlRecord* jcr) override = 0;
virtual bool SqlBatchEnd(JobControlRecord* jcr,
virtual bool SqlBatchStartFileTable(JobControlRecord* jcr) override = 0;
virtual bool SqlBatchEndFileTable(JobControlRecord* jcr,
const char* error) override = 0;
virtual bool SqlBatchInsert(JobControlRecord* jcr,
virtual bool SqlBatchInsertFileTable(JobControlRecord* jcr,
AttributesDbRecord* ar) override = 0;

public:
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/bdb_sqlite.h
Expand Up @@ -62,9 +62,9 @@ class BareosDbSqlite : public BareosDbPrivateInterface {
SQL_FIELD* SqlFetchField(void) override;
bool SqlFieldIsNotNull(int field_type) override;
bool SqlFieldIsNumeric(int field_type) override;
bool SqlBatchStart(JobControlRecord* jcr) override;
bool SqlBatchEnd(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar) override;
bool SqlBatchStartFileTable(JobControlRecord* jcr) override;
bool SqlBatchEndFileTable(JobControlRecord* jcr, const char* error) override;
bool SqlBatchInsertFileTable(JobControlRecord* jcr, AttributesDbRecord* ar) override;

public:
/*
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/cats.h
Expand Up @@ -1081,9 +1081,9 @@ class BareosDb : public BareosDbQueryEnum {
virtual SQL_FIELD* SqlFetchField(void) = 0;
virtual bool SqlFieldIsNotNull(int field_type) = 0;
virtual bool SqlFieldIsNumeric(int field_type) = 0;
virtual bool SqlBatchStart(JobControlRecord* jcr) = 0;
virtual bool SqlBatchEnd(JobControlRecord* jcr, const char* error) = 0;
virtual bool SqlBatchInsert(JobControlRecord* jcr,
virtual bool SqlBatchStartFileTable(JobControlRecord* jcr) = 0;
virtual bool SqlBatchEndFileTable(JobControlRecord* jcr, const char* error) = 0;
virtual bool SqlBatchInsertFileTable(JobControlRecord* jcr,
AttributesDbRecord* ar) = 0;
#endif
};
Expand Down
42 changes: 21 additions & 21 deletions core/src/cats/dbi.cc
Expand Up @@ -1144,12 +1144,12 @@ static char* postgresql_copy_escape(char* dest, char* src, size_t len)
* Returns true if OK
* false if failed
*/
bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
bool BareosDbDBI::SqlBatchStartFileTable(JobControlRecord* jcr)
{
bool retval = true;
const char* query = "COPY batch FROM STDIN";

Dmsg0(500, "SqlBatchStart started\n");
Dmsg0(500, "SqlBatchStartFileTable started\n");

DbLock(this);
switch (db_type_) {
Expand All @@ -1162,10 +1162,10 @@ bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
"LStat tinyblob,"
"MD5 tinyblob,"
"DeltaSeq smallint)")) {
Dmsg0(500, "SqlBatchStart failed\n");
Dmsg0(500, "SqlBatchStartFileTable failed\n");
goto bail_out;
}
Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");
goto ok_out;
case SQL_TYPE_POSTGRESQL:
if (!SqlQueryWithoutHandler("CREATE TEMPORARY TABLE batch ("
Expand All @@ -1176,7 +1176,7 @@ bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
"LStat varchar,"
"MD5 varchar,"
"DeltaSeq int)")) {
Dmsg0(500, "SqlBatchStart failed\n");
Dmsg0(500, "SqlBatchStartFileTable failed\n");
goto bail_out;
}

Expand Down Expand Up @@ -1214,7 +1214,7 @@ bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
goto bail_out;
}

Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");
goto ok_out;
case SQL_TYPE_SQLITE3:
if (!SqlQueryWithoutHandler("CREATE TEMPORARY TABLE batch ("
Expand All @@ -1225,10 +1225,10 @@ bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
"LStat tinyblob,"
"MD5 tinyblob,"
"DeltaSeq smallint)")) {
Dmsg0(500, "SqlBatchStart failed\n");
Dmsg0(500, "SqlBatchStartFileTable failed\n");
goto bail_out;
}
Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");
goto ok_out;
}

Expand All @@ -1247,14 +1247,14 @@ bool BareosDbDBI::SqlBatchStart(JobControlRecord* jcr)
/**
* Set error to something to abort operation
*/
bool BareosDbDBI::SqlBatchEnd(JobControlRecord* jcr, const char* error)
bool BareosDbDBI::SqlBatchEndFileTable(JobControlRecord* jcr, const char* error)
{
int res = 0;
int count = 30;
int (*custom_function)(void*, const char*) = NULL;
dbi_conn_t* myconn = (dbi_conn_t*)(db_handle_);

Dmsg0(500, "SqlBatchStart started\n");
Dmsg0(500, "SqlBatchStartFileTable started\n");

switch (db_type_) {
case SQL_TYPE_MYSQL:
Expand Down Expand Up @@ -1285,7 +1285,7 @@ bool BareosDbDBI::SqlBatchEnd(JobControlRecord* jcr, const char* error)
break;
}

Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");

return true;
}
Expand All @@ -1295,7 +1295,7 @@ bool BareosDbDBI::SqlBatchEnd(JobControlRecord* jcr, const char* error)
* In near future is better split in small functions
* and refactory.
*/
bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
bool BareosDbDBI::SqlBatchInsertFileTable(JobControlRecord* jcr, AttributesDbRecord* ar)
{
int res;
int count = 30;
Expand All @@ -1306,7 +1306,7 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
char* digest;
char ed1[50];

Dmsg0(500, "SqlBatchStart started \n");
Dmsg0(500, "SqlBatchStartFileTable started \n");

esc_name = CheckPoolMemorySize(esc_name, fnl * 2 + 1);
esc_path = CheckPoolMemorySize(esc_path, pnl * 2 + 1);
Expand All @@ -1328,11 +1328,11 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
ar->attr, digest, ar->DeltaSeq);

if (!SqlQueryWithoutHandler(cmd)) {
Dmsg0(500, "SqlBatchStart failed\n");
Dmsg0(500, "SqlBatchStartFileTable failed\n");
goto bail_out;
}

Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");

return true;
break;
Expand All @@ -1347,7 +1347,7 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
* libdbi don't support CopyData and we need call a postgresql
* specific function to do this work
*/
Dmsg2(500, "SqlBatchInsert :\n %s \ncmd_size: %d", cmd, len);
Dmsg2(500, "SqlBatchInsertFileTable :\n %s \ncmd_size: %d", cmd, len);
custom_function = (custom_function_insert_t)dbi_driver_specific_function(
dbi_conn_get_driver(myconn), "PQputCopyData");
if (custom_function != NULL) {
Expand All @@ -1362,11 +1362,11 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
}

if (res <= 0) {
Dmsg0(500, "SqlBatchInsert failed\n");
Dmsg0(500, "SqlBatchInsertFileTable failed\n");
goto bail_out;
}

Dmsg0(500, "SqlBatchInsert finishing\n");
Dmsg0(500, "SqlBatchInsertFileTable finishing\n");
return true;
} else {
/*
Expand All @@ -1375,7 +1375,7 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
custom_function_error =
(custom_function_error_t)dbi_driver_specific_function(
dbi_conn_get_driver(myconn), "PQerrorMessage");
Dmsg1(500, "SqlBatchInsert failed\n PQerrorMessage: %s",
Dmsg1(500, "SqlBatchInsertFileTable failed\n PQerrorMessage: %s",
(*custom_function_error)(myconn->connection));
goto bail_out;
}
Expand All @@ -1390,11 +1390,11 @@ bool BareosDbDBI::SqlBatchInsert(JobControlRecord* jcr, AttributesDbRecord* ar)
ar->attr, digest, ar->DeltaSeq);

if (!SqlQueryWithoutHandler(cmd)) {
Dmsg0(500, "SqlBatchInsert failed\n");
Dmsg0(500, "SqlBatchInsertFileTable failed\n");
goto bail_out;
}

Dmsg0(500, "SqlBatchInsert finishing\n");
Dmsg0(500, "SqlBatchInsertFileTable finishing\n");

return true;
break;
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/mysql.cc
Expand Up @@ -691,7 +691,7 @@ bool BareosDbMysql::SqlFieldIsNumeric(int field_type)
* Returns true if OK
* false if failed
*/
bool BareosDbMysql::SqlBatchStart(JobControlRecord* jcr)
bool BareosDbMysql::SqlBatchStartFileTable(JobControlRecord* jcr)
{
bool retval;

Expand Down Expand Up @@ -722,7 +722,7 @@ bool BareosDbMysql::SqlBatchStart(JobControlRecord* jcr)
* Returns true if OK
* false if failed
*/
bool BareosDbMysql::SqlBatchEnd(JobControlRecord* jcr, const char* error)
bool BareosDbMysql::SqlBatchEndFileTable(JobControlRecord* jcr, const char* error)
{
status_ = 0;

Expand All @@ -738,7 +738,7 @@ bool BareosDbMysql::SqlBatchEnd(JobControlRecord* jcr, const char* error)
* Returns true if OK
* false if failed
*/
bool BareosDbMysql::SqlBatchInsert(JobControlRecord* jcr,
bool BareosDbMysql::SqlBatchInsertFileTable(JobControlRecord* jcr,
AttributesDbRecord* ar)
{
const char* digest;
Expand Down
21 changes: 11 additions & 10 deletions core/src/cats/postgresql.cc
Expand Up @@ -1019,11 +1019,11 @@ static char* pgsql_copy_escape(char* dest, char* src, size_t len)
return dest;
}

bool BareosDbPostgresql::SqlBatchStart(JobControlRecord* jcr)
bool BareosDbPostgresql::SqlBatchStartFileTable(JobControlRecord* jcr)
{
const char* query = "COPY batch FROM STDIN";

Dmsg0(500, "SqlBatchStart started\n");
Dmsg0(500, "SqlBatchStartFileTable started\n");

if (!SqlQueryWithoutHandler("CREATE TEMPORARY TABLE batch ("
"FileIndex int,"
Expand All @@ -1035,7 +1035,7 @@ bool BareosDbPostgresql::SqlBatchStart(JobControlRecord* jcr)
"DeltaSeq smallint,"
"Fhinfo NUMERIC(20),"
"Fhnode NUMERIC(20))")) {
Dmsg0(500, "SqlBatchStart failed\n");
Dmsg0(500, "SqlBatchStartFileTable failed\n");
return false;
}

Expand Down Expand Up @@ -1071,7 +1071,7 @@ bool BareosDbPostgresql::SqlBatchStart(JobControlRecord* jcr)
goto bail_out;
}

Dmsg0(500, "SqlBatchStart finishing\n");
Dmsg0(500, "SqlBatchStartFileTable finishing\n");

return true;

Expand All @@ -1086,13 +1086,14 @@ bool BareosDbPostgresql::SqlBatchStart(JobControlRecord* jcr)
/**
* Set error to something to abort operation
*/
bool BareosDbPostgresql::SqlBatchEnd(JobControlRecord* jcr, const char* error)
bool BareosDbPostgresql::SqlBatchEndFileTable(JobControlRecord* jcr,
const char* error)
{
int res;
int count = 30;
PGresult* pg_result;

Dmsg0(500, "SqlBatchEnd started\n");
Dmsg0(500, "SqlBatchEndFileTable started\n");

do {
res = PQputCopyEnd(db_handle_, error);
Expand Down Expand Up @@ -1121,13 +1122,13 @@ bool BareosDbPostgresql::SqlBatchEnd(JobControlRecord* jcr, const char* error)

PQclear(pg_result);

Dmsg0(500, "SqlBatchEnd finishing\n");
Dmsg0(500, "SqlBatchEndFileTable finishing\n");

return true;
}

bool BareosDbPostgresql::SqlBatchInsert(JobControlRecord* jcr,
AttributesDbRecord* ar)
bool BareosDbPostgresql::SqlBatchInsertFileTable(JobControlRecord* jcr,
AttributesDbRecord* ar)
{
int res;
int count = 30;
Expand Down Expand Up @@ -1170,7 +1171,7 @@ bool BareosDbPostgresql::SqlBatchInsert(JobControlRecord* jcr,
Dmsg1(500, "failure %s\n", errmsg);
}

Dmsg0(500, "SqlBatchInsert finishing\n");
Dmsg0(500, "SqlBatchInsertFileTable finishing\n");

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/sql_create.cc
Expand Up @@ -830,7 +830,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
"Insert of attributes batch table with %u entries start\n",
jcr->db_batch->changes);

if (!jcr->db_batch->SqlBatchEnd(jcr, NULL)) {
if (!jcr->db_batch->SqlBatchEndFileTable(jcr, NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Batch end %s\n", errmsg);
goto bail_out;
}
Expand Down Expand Up @@ -911,7 +911,7 @@ bool BareosDb::CreateBatchFileAttributesRecord(JobControlRecord* jcr,
*/
if (!jcr->batch_started) {
if (!OpenBatchConnection(jcr)) { return false; /* error already printed */ }
if (!jcr->db_batch->SqlBatchStart(jcr)) {
if (!jcr->db_batch->SqlBatchStartFileTable(jcr)) {
Mmsg1(errmsg, "Can't start batch mode: ERR=%s",
jcr->db_batch->strerror());
Jmsg(jcr, M_FATAL, 0, "%s", errmsg);
Expand All @@ -922,7 +922,7 @@ bool BareosDb::CreateBatchFileAttributesRecord(JobControlRecord* jcr,

jcr->db_batch->SplitPathAndFile(jcr, ar->fname);

return jcr->db_batch->SqlBatchInsert(jcr, ar);
return jcr->db_batch->SqlBatchInsertFileTable(jcr, ar);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/sqlite.cc
Expand Up @@ -576,7 +576,7 @@ bool BareosDbSqlite::SqlFieldIsNumeric(int field_type)
* Returns true if OK
* false if failed
*/
bool BareosDbSqlite::SqlBatchStart(JobControlRecord* jcr)
bool BareosDbSqlite::SqlBatchStartFileTable(JobControlRecord* jcr)
{
bool retval;

Expand All @@ -603,7 +603,7 @@ bool BareosDbSqlite::SqlBatchStart(JobControlRecord* jcr)
* Returns true if OK
* false if failed
*/
bool BareosDbSqlite::SqlBatchEnd(JobControlRecord* jcr, const char* error)
bool BareosDbSqlite::SqlBatchEndFileTable(JobControlRecord* jcr, const char* error)
{
status_ = 0;

Expand All @@ -614,7 +614,7 @@ bool BareosDbSqlite::SqlBatchEnd(JobControlRecord* jcr, const char* error)
* Returns true if OK
* false if failed
*/
bool BareosDbSqlite::SqlBatchInsert(JobControlRecord* jcr,
bool BareosDbSqlite::SqlBatchInsertFileTable(JobControlRecord* jcr,
AttributesDbRecord* ar)
{
const char* digest;
Expand Down

0 comments on commit 690e968

Please sign in to comment.