donau-httpd_db.h (3396B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file donau/donau-httpd_db.h 18 * @brief High-level (transactional-layer) database operations for the donau 19 * @author Johannes Casaburi 20 */ 21 #ifndef DONAU_HTTPD_DB_H 22 #define DONAU_HTTPD_DB_H 23 24 #include <microhttpd.h> 25 #include <gnunet/gnunet_mhd_compat.h> 26 27 28 /** 29 * How often should we retry a transaction before giving up 30 * (for transactions resulting in serialization/dead locks only). 31 * 32 * The current value is likely too high for production. We might want to 33 * benchmark good values once we have a good database setup. The code is 34 * expected to work correctly with any positive value, albeit inefficiently if 35 * we too aggressively force clients to retry the HTTP request merely because 36 * we have database serialization issues. 37 */ 38 #define MAX_TRANSACTION_COMMIT_RETRIES 100 39 40 41 /** 42 * Function implementing a database transaction. Runs the transaction 43 * logic; IF it returns a non-error code, the transaction logic MUST 44 * NOT queue a MHD response. IF it returns an hard error, the 45 * transaction logic MUST queue a MHD response and set @a mhd_ret. IF 46 * it returns the soft error code, the function MAY be called again to 47 * retry and MUST not queue a MHD response. 48 * 49 * @param cls closure 50 * @param connection MHD request which triggered the transaction 51 * @param[out] mhd_ret set to MHD response status for @a connection, 52 * if transaction failed (!) 53 * @return transaction status 54 */ 55 typedef enum GNUNET_DB_QueryStatus 56 (*DH_DB_TransactionCallback)(void *cls, 57 struct MHD_Connection *connection, 58 enum MHD_Result *mhd_ret); 59 60 61 /** 62 * Run a database transaction for @a connection. 63 * Starts a transaction and calls @a cb. Upon success, 64 * attempts to commit the transaction. Upon soft failures, 65 * retries @a cb a few times. Upon hard or persistent soft 66 * errors, generates an error message for @a connection. 67 * 68 * @param connection MHD connection to run @a cb for, can be NULL 69 * @param name name of the transaction (for debugging) 70 * @param[out] mhd_ret set to MHD response code, if transaction failed (returned #GNUNET_SYSERR); 71 * NULL if we are not running with a @a connection and thus 72 * must not queue MHD replies 73 * @param cb callback implementing transaction logic 74 * @param cb_cls closure for @a cb, must be read-only! 75 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 76 */ 77 enum GNUNET_GenericReturnValue 78 DH_DB_run_transaction (struct MHD_Connection *connection, 79 const char *name, 80 enum MHD_Result *mhd_ret, 81 DH_DB_TransactionCallback cb, 82 void *cb_cls); 83 84 85 #endif 86 /* DONAU_HTTPD_DB_H */