2009-10-14 18:57:50 +00:00
|
|
|
/*
|
|
|
|
* transactionTable.h
|
|
|
|
*
|
|
|
|
* Created on: Oct 14, 2009
|
|
|
|
* Author: sears
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TRANSACTIONTABLE_H_
|
|
|
|
#define TRANSACTIONTABLE_H_
|
|
|
|
|
|
|
|
#include <stasis/common.h>
|
2009-10-14 21:22:50 +00:00
|
|
|
|
2009-12-15 06:30:37 +00:00
|
|
|
typedef int (*stasis_transaction_table_callback_t)(int, void*);
|
|
|
|
|
|
|
|
typedef struct stasis_transaction_table_callback_list_t stasis_transaction_table_callback_list_t;
|
2009-10-14 21:22:50 +00:00
|
|
|
typedef struct stasis_transaction_table_entry_t stasis_transaction_table_entry_t;
|
|
|
|
typedef struct stasis_transaction_table_t stasis_transaction_table_t;
|
2009-10-14 18:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Contains the state needed by the logging layer to perform
|
|
|
|
operations on a transaction.
|
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
struct stasis_transaction_table_entry_t {
|
2009-10-14 18:57:50 +00:00
|
|
|
int xid;
|
2010-11-05 18:57:18 +00:00
|
|
|
/**
|
|
|
|
Identifies where the entry was allocated from (and must be returned to):
|
|
|
|
- INVALID_XTABLE_XID: global pool (used only during recovery)
|
|
|
|
- RESERVED_XTABLE_XID: local thread pool
|
|
|
|
*/
|
|
|
|
int xidWhenFree;
|
2009-10-14 18:57:50 +00:00
|
|
|
lsn_t prevLSN;
|
|
|
|
lsn_t recLSN;
|
2009-12-15 06:30:37 +00:00
|
|
|
void ** commitArgs[3];
|
2010-11-05 18:57:18 +00:00
|
|
|
/**
|
|
|
|
Thread id (as returned by gettid()) of the thread which owns this entry
|
|
|
|
or -1 if not owned by any thread
|
|
|
|
*/
|
|
|
|
pid_t tid;
|
2009-10-15 22:46:25 +00:00
|
|
|
#ifndef HAVE_GCC_ATOMICS
|
2009-10-14 18:57:50 +00:00
|
|
|
pthread_mutex_t mut;
|
2009-10-15 22:46:25 +00:00
|
|
|
#endif
|
2009-10-14 18:57:50 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
Initialize Stasis' transaction table. Called by Tinit() and unit
|
|
|
|
tests that wish to test portions of Stasis in isolation.
|
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
stasis_transaction_table_t* stasis_transaction_table_init();
|
2009-10-14 18:57:50 +00:00
|
|
|
/** Free resources associated with the transaction table */
|
2009-10-14 21:22:50 +00:00
|
|
|
void stasis_transaction_table_deinit(stasis_transaction_table_t*);
|
2009-10-14 18:57:50 +00:00
|
|
|
|
2010-11-05 18:57:18 +00:00
|
|
|
void stasis_transaction_post_recovery(stasis_transaction_table_t *tbl);
|
|
|
|
|
2009-10-14 21:22:50 +00:00
|
|
|
int stasis_transaction_table_roll_forward(stasis_transaction_table_t*,int xid, lsn_t lsn, lsn_t prevLSN);
|
2009-10-14 18:57:50 +00:00
|
|
|
/**
|
|
|
|
@todo update Tprepare() to not write reclsn to log, then remove
|
|
|
|
this function.
|
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
int stasis_transaction_table_roll_forward_with_reclsn(stasis_transaction_table_t*,int xid, lsn_t lsn,
|
2009-10-14 18:57:50 +00:00
|
|
|
lsn_t prevLSN,
|
|
|
|
lsn_t recLSN);
|
|
|
|
/**
|
|
|
|
This is used by log truncation.
|
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
lsn_t stasis_transaction_table_minRecLSN(stasis_transaction_table_t*);
|
2009-10-14 18:57:50 +00:00
|
|
|
|
2009-10-14 21:22:50 +00:00
|
|
|
stasis_transaction_table_entry_t * stasis_transaction_table_begin(stasis_transaction_table_t*,int * xid);
|
|
|
|
stasis_transaction_table_entry_t * stasis_transaction_table_get(stasis_transaction_table_t*,int xid);
|
|
|
|
int stasis_transaction_table_commit(stasis_transaction_table_t*,int xid);
|
|
|
|
int stasis_transaction_table_forget(stasis_transaction_table_t*,int xid);
|
2009-10-14 18:57:50 +00:00
|
|
|
|
2009-10-15 20:11:43 +00:00
|
|
|
int stasis_transaction_table_num_active_threads(stasis_transaction_table_t*);
|
|
|
|
int* stasis_transaction_table_list_active(stasis_transaction_table_t*, int *count);
|
2009-10-14 21:22:50 +00:00
|
|
|
int stasis_transaction_table_is_active(stasis_transaction_table_t*, int xid);
|
2009-10-14 18:57:50 +00:00
|
|
|
|
2009-12-15 06:30:37 +00:00
|
|
|
typedef enum {
|
|
|
|
PRE_COMMIT = 0,
|
|
|
|
AT_COMMIT = 1,
|
|
|
|
POST_COMMIT = 2
|
|
|
|
} stasis_transaction_table_callback_type_t;
|
|
|
|
|
|
|
|
int stasis_transaction_table_register_callback(stasis_transaction_table_t *tbl,
|
|
|
|
stasis_transaction_table_callback_t cb,
|
|
|
|
stasis_transaction_table_callback_type_t type);
|
|
|
|
int stasis_transaction_table_invoke_callbacks(stasis_transaction_table_t *tbl,
|
|
|
|
stasis_transaction_table_entry_t *entry,
|
|
|
|
stasis_transaction_table_callback_type_t type);
|
|
|
|
int stasis_transaction_table_set_argument(stasis_transaction_table_t *tbl, int xid, int callback_id,
|
|
|
|
stasis_transaction_table_callback_type_t type, void *arg);
|
|
|
|
|
2009-10-14 18:57:50 +00:00
|
|
|
#endif /* TRANSACTIONTABLE_H_ */
|