move functions need to recheck insert_aggregation_tracking
This commit is contained in:
parent
f51e8a7150
commit
bd0e2aac92
@ -1 +1 @@
|
||||
Subproject commit 6b9824cb4d4561f1167c7f518998a226a82222d6
|
||||
Subproject commit d83d2584fd4698719b8eb78a4e0e9c8dad698aca
|
@ -69,12 +69,17 @@ endif
|
||||
libtaler_plugin_exchangedb_postgres_la_SOURCES = \
|
||||
plugin_exchangedb_common.c plugin_exchangedb_common.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_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_commit.h pg_commit.c \
|
||||
pg_get_coin_transactions.c pg_get_coin_transactions.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_reserve_history.c pg_get_reserve_history.h \
|
||||
pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \
|
||||
|
66
src/exchangedb/pg_create_shard_tables.c
Normal file
66
src/exchangedb/pg_create_shard_tables.c
Normal 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;
|
||||
}
|
39
src/exchangedb/pg_create_shard_tables.h
Normal file
39
src/exchangedb/pg_create_shard_tables.h
Normal 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
|
59
src/exchangedb/pg_drop_tables.c
Normal file
59
src/exchangedb/pg_drop_tables.c
Normal 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;
|
||||
}
|
38
src/exchangedb/pg_drop_tables.h
Normal file
38
src/exchangedb/pg_drop_tables.h
Normal 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
|
54
src/exchangedb/pg_insert_aggregation_tracking.c
Normal file
54
src/exchangedb/pg_insert_aggregation_tracking.c
Normal 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);
|
||||
}
|
||||
|
42
src/exchangedb/pg_insert_aggregation_tracking.h
Normal file
42
src/exchangedb/pg_insert_aggregation_tracking.h
Normal 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
|
@ -59,7 +59,8 @@ TEH_PG_insert_close_request (
|
||||
",close_fee_frac"
|
||||
",payto_uri"
|
||||
")"
|
||||
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8)"
|
||||
"VALUES "
|
||||
"($1, $2, $3, $4, $5, $6, $7, $8)"
|
||||
" ON CONFLICT DO NOTHING;");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"insert_account_close",
|
||||
|
@ -63,6 +63,28 @@ TEH_PG_insert_purse_request (
|
||||
};
|
||||
|
||||
*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,
|
||||
"insert_purse_request",
|
||||
params);
|
||||
@ -107,3 +129,6 @@ TEH_PG_insert_purse_request (
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
64
src/exchangedb/pg_prefligth.c
Normal file
64
src/exchangedb/pg_prefligth.c
Normal 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;
|
||||
}
|
43
src/exchangedb/pg_prefligth.h
Normal file
43
src/exchangedb/pg_prefligth.h
Normal 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
|
26
src/exchangedb/pg_setup_partitions.c
Normal file
26
src/exchangedb/pg_setup_partitions.c
Normal 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"
|
39
src/exchangedb/pg_setup_partitions.h
Normal file
39
src/exchangedb/pg_setup_partitions.h
Normal 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
|
@ -63,10 +63,12 @@
|
||||
/**WHAT I ADD**/
|
||||
#include "pg_insert_purse_request.h"
|
||||
#include "pg_iterate_active_signkeys.h"
|
||||
|
||||
#include "pg_prefligth.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
|
||||
* slow down things a _lot_, but also provide extensive logging
|
||||
@ -93,38 +95,6 @@
|
||||
} 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
|
||||
@ -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
|
||||
@ -591,6 +468,7 @@ prepare_statements (struct PostgresClosure *pg)
|
||||
",amount_frac"
|
||||
",master_sig"
|
||||
") VALUES ($1, $2, $3, $4, $5, $6, $7);"),
|
||||
|
||||
/* Used in #postgres_profit_drains_get_pending() */
|
||||
GNUNET_PQ_make_prepare (
|
||||
"get_ready_profit_drain",
|
||||
@ -1458,14 +1336,7 @@ prepare_statements (struct PostgresClosure *pg)
|
||||
" WHERE dep.coin_pub=$1"
|
||||
" AND dep.merchant_pub=$3"
|
||||
" 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() */
|
||||
GNUNET_PQ_make_prepare (
|
||||
"get_wire_fee",
|
||||
@ -2088,26 +1959,7 @@ prepare_statements (struct PostgresClosure *pg)
|
||||
",contract_sig"
|
||||
" FROM contracts"
|
||||
" 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 */
|
||||
GNUNET_PQ_make_prepare (
|
||||
"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.
|
||||
@ -2451,7 +2257,7 @@ postgres_start (void *cls,
|
||||
|
||||
GNUNET_assert (NULL != name);
|
||||
if (GNUNET_SYSERR ==
|
||||
postgres_preflight (pg))
|
||||
TEH_PG_preflight (pg))
|
||||
return GNUNET_SYSERR;
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Starting transaction `%s'\n",
|
||||
@ -2489,7 +2295,7 @@ postgres_start_read_committed (void *cls,
|
||||
|
||||
GNUNET_assert (NULL != name);
|
||||
if (GNUNET_SYSERR ==
|
||||
postgres_preflight (pg))
|
||||
TEH_PG_preflight (pg))
|
||||
return GNUNET_SYSERR;
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Starting READ COMMITTED transaction `%s`\n",
|
||||
@ -2528,7 +2334,7 @@ postgres_start_read_only (void *cls,
|
||||
|
||||
GNUNET_assert (NULL != name);
|
||||
if (GNUNET_SYSERR ==
|
||||
postgres_preflight (pg))
|
||||
TEH_PG_preflight (pg))
|
||||
return GNUNET_SYSERR;
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"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.
|
||||
@ -6597,7 +6376,7 @@ postgres_start_deferred_wire_out (void *cls)
|
||||
};
|
||||
|
||||
if (GNUNET_SYSERR ==
|
||||
postgres_preflight (pg))
|
||||
TEH_PG_preflight (pg))
|
||||
return GNUNET_SYSERR;
|
||||
if (GNUNET_OK !=
|
||||
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->cls = pg;
|
||||
plugin->drop_tables = &postgres_drop_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->start = &postgres_start;
|
||||
plugin->start_read_committed = &postgres_start_read_committed;
|
||||
plugin->start_read_only = &postgres_start_read_only;
|
||||
|
||||
plugin->preflight = &postgres_preflight;
|
||||
plugin->rollback = &postgres_rollback;
|
||||
plugin->event_listen = &postgres_event_listen;
|
||||
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->lookup_wire_transfer = &postgres_lookup_wire_transfer;
|
||||
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_global_fee = &postgres_insert_global_fee;
|
||||
plugin->get_wire_fee = &postgres_get_wire_fee;
|
||||
@ -12035,6 +11810,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
||||
= &postgres_expire_purse;
|
||||
plugin->select_purse_by_merge_pub
|
||||
= &postgres_select_purse_by_merge_pub;
|
||||
|
||||
plugin->do_purse_deposit
|
||||
= &postgres_do_purse_deposit;
|
||||
plugin->set_purse_balance
|
||||
@ -12080,6 +11856,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
||||
/* NEW style, sort alphabetically! */
|
||||
plugin->do_reserve_open
|
||||
= &TEH_PG_do_reserve_open;
|
||||
plugin->drop_tables
|
||||
= &TEH_PG_drop_tables;
|
||||
plugin->do_withdraw
|
||||
= &TEH_PG_do_withdraw;
|
||||
plugin->free_coin_transaction_list
|
||||
@ -12140,6 +11918,14 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
||||
= &TEH_PG_iterate_active_signkeys;
|
||||
plugin->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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user