move functions need to recheck insert_aggregation_tracking

This commit is contained in:
Joseph 2022-11-08 11:40:47 -05:00
parent f51e8a7150
commit bd0e2aac92
No known key found for this signature in database
GPG Key ID: E709789D3076B5CC
15 changed files with 528 additions and 241 deletions

@ -1 +1 @@
Subproject commit 6b9824cb4d4561f1167c7f518998a226a82222d6 Subproject commit d83d2584fd4698719b8eb78a4e0e9c8dad698aca

View File

@ -69,12 +69,17 @@ endif
libtaler_plugin_exchangedb_postgres_la_SOURCES = \ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
plugin_exchangedb_common.c plugin_exchangedb_common.h \ plugin_exchangedb_common.c plugin_exchangedb_common.h \
plugin_exchangedb_postgres.c pg_helper.h \ plugin_exchangedb_postgres.c pg_helper.h \
pg_insert_aggregation_tracking.h pg_insert_aggregation_tracking.c \
pg_do_reserve_open.c pg_do_reserve_open.h \ pg_do_reserve_open.c pg_do_reserve_open.h \
pg_do_withdraw.h pg_do_withdraw.c \ pg_do_withdraw.h pg_do_withdraw.c \
pg_create_shard_tables.h pg_create_shard_tables.c \
pg_prefligth.h pg_prefligth.c \
pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \ pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
pg_commit.h pg_commit.c \ pg_commit.h pg_commit.c \
pg_get_coin_transactions.c pg_get_coin_transactions.h \ pg_get_coin_transactions.c pg_get_coin_transactions.h \
pg_get_expired_reserves.c pg_get_expired_reserves.h \ pg_get_expired_reserves.c pg_get_expired_reserves.h \
pg_setup_partitions.h pg_setup_partitions.c \
pg_insert_aggregation_tracking.h pg_insert_aggregation_tracking.c \
pg_get_purse_request.c pg_get_purse_request.h \ pg_get_purse_request.c pg_get_purse_request.h \
pg_get_reserve_history.c pg_get_reserve_history.h \ pg_get_reserve_history.c pg_get_reserve_history.h \
pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \ pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \

View File

@ -0,0 +1,66 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_create_shard_tables.c
* @brief Implementation of the create_shard_tables function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "pg_create_shard_tables.h"
#include "pg_helper.h"
enum GNUNET_GenericReturnValue
TEH_PG_create_shard_tables (void *cls,
uint32_t idx)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&idx),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("create_shard_tables",
"SELECT"
" setup_shard"
" ($1);"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
"shard-",
es,
ps);
if (NULL == conn)
return GNUNET_SYSERR;
if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
"create_shard_tables",
params))
ret = GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
return ret;
}

View File

@ -0,0 +1,39 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_create_shard_tables.h
* @brief implementation of the create_shard_tables function for Postgres
* @author Christian Grothoff
*/
#ifndef PG_CREATE_SHARD_TABLES_H
#define PG_CREATE_SHARD_TABLES_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
/**
* Create tables of a shard node with index idx
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param idx the shards index, will be appended as suffix to all tables
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
TEH_PG_create_shard_tables (void *cls,
uint32_t idx);
#endif

View File

@ -0,0 +1,59 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_drop_tables.c
* @brief Implementation of the drop_tables function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "pg_drop_tables.h"
#include "pg_helper.h"
/**
* Drop all Taler tables. This should only be used by testcases.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
TEH_PG_drop_tables (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret;
if (NULL != pg->conn)
{
GNUNET_PQ_disconnect (pg->conn);
pg->conn = NULL;
pg->init = false;
}
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
NULL,
NULL,
NULL);
if (NULL == conn)
return GNUNET_SYSERR;
ret = GNUNET_PQ_exec_sql (conn,
"drop");
GNUNET_PQ_disconnect (conn);
return ret;
}

View File

@ -0,0 +1,38 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_drop_tables.h
* @brief implementation of the drop_tables function for Postgres
* @author Christian Grothoff
*/
#ifndef PG_DROP_TABLES_H
#define PG_DROP_TABLES_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
/**
* Drop all Taler tables. This should only be used by testcases.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
TEH_PG_drop_tables (void *cls);
#endif

View File

@ -0,0 +1,54 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_insert_aggregation_tracking.c
* @brief Implementation of the insert_aggregation_tracking function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "pg_insert_aggregation_tracking.h"
#include "pg_helper.h"
enum GNUNET_DB_QueryStatus
TEH_PG_insert_aggregation_tracking (
void *cls,
const struct TALER_WireTransferIdentifierRawP *wtid,
unsigned long long deposit_serial_id)
{
struct PostgresClosure *pg = cls;
uint64_t rid = deposit_serial_id;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&rid),
GNUNET_PQ_query_param_auto_from_type (wtid),
GNUNET_PQ_query_param_end
};
PREPARE (pg,
"insert_aggregation_tracking",
"INSERT INTO aggregation_tracking "
"(deposit_serial_id"
",wtid_raw"
") VALUES "
"($1, $2);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_aggregation_tracking",
params);
}

View File

@ -0,0 +1,42 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_insert_aggregation_tracking.h
* @brief implementation of the insert_aggregation_tracking function for Postgres
* @author Christian Grothoff
*/
#ifndef PG_INSERT_AGGREGATION_TRACKING_H
#define PG_INSERT_AGGREGATION_TRACKING_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
/**
* Function called to insert aggregation information into the DB.
*
* @param cls closure
* @param wtid the raw wire transfer identifier we used
* @param deposit_serial_id row in the deposits table for which this is aggregation data
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
TEH_PG_insert_aggregation_tracking (
void *cls,
const struct TALER_WireTransferIdentifierRawP *wtid,
unsigned long long deposit_serial_id);
#endif

View File

@ -59,7 +59,8 @@ TEH_PG_insert_close_request (
",close_fee_frac" ",close_fee_frac"
",payto_uri" ",payto_uri"
")" ")"
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8)" "VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8)"
" ON CONFLICT DO NOTHING;"); " ON CONFLICT DO NOTHING;");
return GNUNET_PQ_eval_prepared_non_select (pg->conn, return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_account_close", "insert_account_close",

View File

@ -63,6 +63,28 @@ TEH_PG_insert_purse_request (
}; };
*in_conflict = false; *in_conflict = false;
PREPARE ( pg,
"insert_purse_request",
"INSERT INTO purse_requests"
" (purse_pub"
" ,merge_pub"
" ,purse_creation"
" ,purse_expiration"
" ,h_contract_terms"
" ,age_limit"
" ,flags"
" ,in_reserve_quota"
" ,amount_with_fee_val"
" ,amount_with_fee_frac"
" ,purse_fee_val"
" ,purse_fee_frac"
" ,purse_sig"
" ) VALUES "
" ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
" ON CONFLICT DO NOTHING;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_purse_request", "insert_purse_request",
params); params);
@ -107,3 +129,6 @@ TEH_PG_insert_purse_request (
} }

View File

@ -0,0 +1,64 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_prefligth.c
* @brief Implementation of the prefligth function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "pg_prefligth.h"
#include "pg_helper.h"
enum GNUNET_GenericReturnValue
TEH_PG_preflight (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute ("ROLLBACK"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
if (! pg->init)
{
if (GNUNET_OK !=
internal_setup (pg,
false))
return GNUNET_SYSERR;
}
if (NULL == pg->transaction_name)
return GNUNET_OK; /* all good */
if (GNUNET_OK ==
GNUNET_PQ_exec_statements (pg->conn,
es))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check rolled back transaction `%s'!\n",
pg->transaction_name);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check failed to rollback transaction `%s'!\n",
pg->transaction_name);
}
pg->transaction_name = NULL;
return GNUNET_NO;
}

View File

@ -0,0 +1,43 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_prefligth.h
* @brief implementation of the prefligth function for Postgres
* @author Christian Grothoff
*/
#ifndef PG_PREFLIGTH_H
#define PG_PREFLIGTH_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
/**
* Do a pre-flight check that we are not in an uncommitted transaction.
* If we are, try to commit the previous transaction and output a warning.
* Does not return anything, as we will continue regardless of the outcome.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK if everything is fine
* #GNUNET_NO if a transaction was rolled back
* #GNUNET_SYSERR on hard errors
*/
enum GNUNET_GenericReturnValue
TEH_PG_preflight (void *cls);
#endif

View File

@ -0,0 +1,26 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_setup_partitions.c
* @brief Implementation of the setup_partitions function for Postgres
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "pg_setup_partitions.h"
#include "pg_helper.h"

View File

@ -0,0 +1,39 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file exchangedb/pg_setup_partitions.h
* @brief implementation of the setup_partitions function for Postgres
* @author Christian Grothoff
*/
#ifndef PG_SETUP_PARTITIONS_H
#define PG_SETUP_PARTITIONS_H
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
/**
* Setup partitions of already existing tables
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param num the number of partitions to create for each partitioned table
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
TEH_PG_setup_partitions (void *cls,
uint32_t num);
#endif

View File

@ -63,10 +63,12 @@
/**WHAT I ADD**/ /**WHAT I ADD**/
#include "pg_insert_purse_request.h" #include "pg_insert_purse_request.h"
#include "pg_iterate_active_signkeys.h" #include "pg_iterate_active_signkeys.h"
#include "pg_prefligth.h"
#include "pg_commit.h" #include "pg_commit.h"
#include "pg_create_shard_tables.h"
#include "pg_insert_aggregation_tracking.h"
#include "pg_drop_tables.h"
#include "pg_setup_partitions.h"
/** /**
* Set to 1 to enable Postgres auto_explain module. This will * Set to 1 to enable Postgres auto_explain module. This will
* slow down things a _lot_, but also provide extensive logging * slow down things a _lot_, but also provide extensive logging
@ -93,38 +95,6 @@
} while (0) } while (0)
/**
* Drop all Taler tables. This should only be used by testcases.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
postgres_drop_tables (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret;
if (NULL != pg->conn)
{
GNUNET_PQ_disconnect (pg->conn);
pg->conn = NULL;
pg->init = false;
}
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
NULL,
NULL,
NULL);
if (NULL == conn)
return GNUNET_SYSERR;
ret = GNUNET_PQ_exec_sql (conn,
"drop");
GNUNET_PQ_disconnect (conn);
return ret;
}
/** /**
* Create the necessary tables if they are not present * Create the necessary tables if they are not present
@ -153,99 +123,6 @@ postgres_create_tables (void *cls)
} }
/**
* Create tables of a shard node with index idx
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param idx the shards index, will be appended as suffix to all tables
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
postgres_create_shard_tables (void *cls,
uint32_t idx)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&idx),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("create_shard_tables",
"SELECT"
" setup_shard"
" ($1);"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
"shard-",
es,
ps);
if (NULL == conn)
return GNUNET_SYSERR;
if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
"create_shard_tables",
params))
ret = GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
return ret;
}
/**
* Setup partitions of already existing tables
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param num the number of partitions to create for each partitioned table
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
postgres_setup_partitions (void *cls,
uint32_t num)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_Context *conn;
enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&num),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("setup_partitions",
"SELECT"
" create_partitions"
" ($1);"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"exchangedb-postgres",
NULL,
es,
ps);
if (NULL == conn)
return GNUNET_SYSERR;
ret = GNUNET_OK;
if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
"setup_partitions",
params))
ret = GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
return ret;
}
/** /**
* Setup foreign servers (shards) for already existing tables * Setup foreign servers (shards) for already existing tables
@ -591,6 +468,7 @@ prepare_statements (struct PostgresClosure *pg)
",amount_frac" ",amount_frac"
",master_sig" ",master_sig"
") VALUES ($1, $2, $3, $4, $5, $6, $7);"), ") VALUES ($1, $2, $3, $4, $5, $6, $7);"),
/* Used in #postgres_profit_drains_get_pending() */ /* Used in #postgres_profit_drains_get_pending() */
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"get_ready_profit_drain", "get_ready_profit_drain",
@ -1458,14 +1336,7 @@ prepare_statements (struct PostgresClosure *pg)
" WHERE dep.coin_pub=$1" " WHERE dep.coin_pub=$1"
" AND dep.merchant_pub=$3" " AND dep.merchant_pub=$3"
" AND dep.h_contract_terms=$2"), " AND dep.h_contract_terms=$2"),
/* Used in #postgres_insert_aggregation_tracking */
GNUNET_PQ_make_prepare (
"insert_aggregation_tracking",
"INSERT INTO aggregation_tracking "
"(deposit_serial_id"
",wtid_raw"
") VALUES "
"($1, $2);"),
/* Used in #postgres_get_wire_fee() */ /* Used in #postgres_get_wire_fee() */
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"get_wire_fee", "get_wire_fee",
@ -2088,26 +1959,7 @@ prepare_statements (struct PostgresClosure *pg)
",contract_sig" ",contract_sig"
" FROM contracts" " FROM contracts"
" WHERE purse_pub=$1;"), " WHERE purse_pub=$1;"),
/* Used in #postgres_insert_purse_request() */
GNUNET_PQ_make_prepare (
"insert_purse_request",
"INSERT INTO purse_requests"
" (purse_pub"
" ,merge_pub"
" ,purse_creation"
" ,purse_expiration"
" ,h_contract_terms"
" ,age_limit"
" ,flags"
" ,in_reserve_quota"
" ,amount_with_fee_val"
" ,amount_with_fee_frac"
" ,purse_fee_val"
" ,purse_fee_frac"
" ,purse_sig"
" ) VALUES "
" ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
" ON CONFLICT DO NOTHING;"),
/* Used in #postgres_select_purse_by_merge_pub */ /* Used in #postgres_select_purse_by_merge_pub */
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_purse_by_merge_pub", "select_purse_by_merge_pub",
@ -2384,52 +2236,6 @@ internal_setup (struct PostgresClosure *pg,
} }
/**
* Do a pre-flight check that we are not in an uncommitted transaction.
* If we are, try to commit the previous transaction and output a warning.
* Does not return anything, as we will continue regardless of the outcome.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK if everything is fine
* #GNUNET_NO if a transaction was rolled back
* #GNUNET_SYSERR on hard errors
*/
static enum GNUNET_GenericReturnValue
postgres_preflight (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute ("ROLLBACK"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
if (! pg->init)
{
if (GNUNET_OK !=
internal_setup (pg,
false))
return GNUNET_SYSERR;
}
if (NULL == pg->transaction_name)
return GNUNET_OK; /* all good */
if (GNUNET_OK ==
GNUNET_PQ_exec_statements (pg->conn,
es))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check rolled back transaction `%s'!\n",
pg->transaction_name);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check failed to rollback transaction `%s'!\n",
pg->transaction_name);
}
pg->transaction_name = NULL;
return GNUNET_NO;
}
/** /**
* Start a transaction. * Start a transaction.
@ -2451,7 +2257,7 @@ postgres_start (void *cls,
GNUNET_assert (NULL != name); GNUNET_assert (NULL != name);
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
postgres_preflight (pg)) TEH_PG_preflight (pg))
return GNUNET_SYSERR; return GNUNET_SYSERR;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting transaction `%s'\n", "Starting transaction `%s'\n",
@ -2489,7 +2295,7 @@ postgres_start_read_committed (void *cls,
GNUNET_assert (NULL != name); GNUNET_assert (NULL != name);
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
postgres_preflight (pg)) TEH_PG_preflight (pg))
return GNUNET_SYSERR; return GNUNET_SYSERR;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting READ COMMITTED transaction `%s`\n", "Starting READ COMMITTED transaction `%s`\n",
@ -2528,7 +2334,7 @@ postgres_start_read_only (void *cls,
GNUNET_assert (NULL != name); GNUNET_assert (NULL != name);
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
postgres_preflight (pg)) TEH_PG_preflight (pg))
return GNUNET_SYSERR; return GNUNET_SYSERR;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting READ ONLY transaction `%s`\n", "Starting READ ONLY transaction `%s`\n",
@ -5849,33 +5655,6 @@ postgres_lookup_transfer_by_deposit (
} }
/**
* Function called to insert aggregation information into the DB.
*
* @param cls closure
* @param wtid the raw wire transfer identifier we used
* @param deposit_serial_id row in the deposits table for which this is aggregation data
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_insert_aggregation_tracking (
void *cls,
const struct TALER_WireTransferIdentifierRawP *wtid,
unsigned long long deposit_serial_id)
{
struct PostgresClosure *pg = cls;
uint64_t rid = deposit_serial_id;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&rid),
GNUNET_PQ_query_param_auto_from_type (wtid),
GNUNET_PQ_query_param_end
};
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_aggregation_tracking",
params);
}
/** /**
* Obtain wire fee from database. * Obtain wire fee from database.
@ -6597,7 +6376,7 @@ postgres_start_deferred_wire_out (void *cls)
}; };
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
postgres_preflight (pg)) TEH_PG_preflight (pg))
return GNUNET_SYSERR; return GNUNET_SYSERR;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PQ_exec_statements (pg->conn, GNUNET_PQ_exec_statements (pg->conn,
@ -11856,16 +11635,13 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin); plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin);
plugin->cls = pg; plugin->cls = pg;
plugin->drop_tables = &postgres_drop_tables;
plugin->create_tables = &postgres_create_tables; plugin->create_tables = &postgres_create_tables;
plugin->create_shard_tables = &postgres_create_shard_tables;
plugin->setup_partitions = &postgres_setup_partitions;
plugin->setup_foreign_servers = &postgres_setup_foreign_servers; plugin->setup_foreign_servers = &postgres_setup_foreign_servers;
plugin->start = &postgres_start; plugin->start = &postgres_start;
plugin->start_read_committed = &postgres_start_read_committed; plugin->start_read_committed = &postgres_start_read_committed;
plugin->start_read_only = &postgres_start_read_only; plugin->start_read_only = &postgres_start_read_only;
plugin->preflight = &postgres_preflight;
plugin->rollback = &postgres_rollback; plugin->rollback = &postgres_rollback;
plugin->event_listen = &postgres_event_listen; plugin->event_listen = &postgres_event_listen;
plugin->event_listen_cancel = &postgres_event_listen_cancel; plugin->event_listen_cancel = &postgres_event_listen_cancel;
@ -11917,7 +11693,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->get_refresh_reveal = &postgres_get_refresh_reveal; plugin->get_refresh_reveal = &postgres_get_refresh_reveal;
plugin->lookup_wire_transfer = &postgres_lookup_wire_transfer; plugin->lookup_wire_transfer = &postgres_lookup_wire_transfer;
plugin->lookup_transfer_by_deposit = &postgres_lookup_transfer_by_deposit; plugin->lookup_transfer_by_deposit = &postgres_lookup_transfer_by_deposit;
plugin->insert_aggregation_tracking = &postgres_insert_aggregation_tracking;
plugin->insert_wire_fee = &postgres_insert_wire_fee; plugin->insert_wire_fee = &postgres_insert_wire_fee;
plugin->insert_global_fee = &postgres_insert_global_fee; plugin->insert_global_fee = &postgres_insert_global_fee;
plugin->get_wire_fee = &postgres_get_wire_fee; plugin->get_wire_fee = &postgres_get_wire_fee;
@ -12035,6 +11810,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_expire_purse; = &postgres_expire_purse;
plugin->select_purse_by_merge_pub plugin->select_purse_by_merge_pub
= &postgres_select_purse_by_merge_pub; = &postgres_select_purse_by_merge_pub;
plugin->do_purse_deposit plugin->do_purse_deposit
= &postgres_do_purse_deposit; = &postgres_do_purse_deposit;
plugin->set_purse_balance plugin->set_purse_balance
@ -12080,6 +11856,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
/* NEW style, sort alphabetically! */ /* NEW style, sort alphabetically! */
plugin->do_reserve_open plugin->do_reserve_open
= &TEH_PG_do_reserve_open; = &TEH_PG_do_reserve_open;
plugin->drop_tables
= &TEH_PG_drop_tables;
plugin->do_withdraw plugin->do_withdraw
= &TEH_PG_do_withdraw; = &TEH_PG_do_withdraw;
plugin->free_coin_transaction_list plugin->free_coin_transaction_list
@ -12140,6 +11918,14 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &TEH_PG_iterate_active_signkeys; = &TEH_PG_iterate_active_signkeys;
plugin->commit plugin->commit
= &TEH_PG_commit; = &TEH_PG_commit;
plugin->preflight
= &TEH_PG_preflight;
plugin->create_shard_tables
= &TEH_PG_create_shard_tables;
plugin->insert_aggregation_tracking
= &TEH_PG_insert_aggregation_tracking;
plugin->setup_partitions
= &TEH_PG_setup_partitions;
return plugin; return plugin;
} }