Don't fail with error when registering master if schema already defined

Registering a master creates the schema, but it may be desirable
to forcibly reregister a master without deleting the schema, so
uncouple the dependency.

Also ensure schema creation is atomic by wrapping it in a transaction.

Per GitHub issue #49.
This commit is contained in:
Ian Barwick
2015-09-24 16:00:00 +09:00
committed by Ian Barwick
parent 03b88178c1
commit c429b0b186
3 changed files with 158 additions and 74 deletions

View File

@@ -82,6 +82,72 @@ establish_db_connection_by_params(const char *keywords[], const char *values[],
}
bool
begin_transaction(PGconn *conn)
{
PGresult *res;
res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
log_err(_("Unable to begin transaction: %s\n"),
PQerrorMessage(conn));
PQclear(res);
return false;
}
PQclear(res);
return true;
}
bool
commit_transaction(PGconn *conn)
{
PGresult *res;
res = PQexec(conn, "COMMIT");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
log_err(_("Unable to commit transaction: %s\n"),
PQerrorMessage(conn));
PQclear(res);
return false;
}
PQclear(res);
return true;
}
bool
rollback_transaction(PGconn *conn)
{
PGresult *res;
res = PQexec(conn, "ROLLBACK");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
log_err(_("Unable to rollback transaction: %s\n"),
PQerrorMessage(conn));
PQclear(res);
return false;
}
PQclear(res);
return true;
}
bool
check_cluster_schema(PGconn *conn)
{