Skip to content

Commit

Permalink
obj: introduce pmemobj_tx_set_abort_on_failure
Browse files Browse the repository at this point in the history
This function can be used to disable or enable aborting tx
in case of an error (for example when allocation fails).

This patch also introduces pmemobj_tx_is_abort_on_failure
which allows to query current setting of a transaction.
  • Loading branch information
igchor committed Mar 18, 2020
1 parent e4b6025 commit 66e7940
Show file tree
Hide file tree
Showing 23 changed files with 533 additions and 45 deletions.
21 changes: 20 additions & 1 deletion doc/libpmemobj/pmemobj_tx_begin.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ date: pmemobj API version 2.3
**pmemobj_tx_log_intents_max_size**(),

**pmemobj_tx_set_user_data**(),
**pmemobj_tx_get_user_data**()
**pmemobj_tx_get_user_data**(),

**pmemobj_tx_set_abort_on_failure**(),
**pmemobj_tx_get_abort_on_failure**()
- transactional object manipulation

# SYNOPSIS #
Expand Down Expand Up @@ -72,6 +75,9 @@ size_t pmemobj_tx_log_intents_max_size(size_t nintents);
void pmemobj_tx_set_user_data(void *data);
void *pmemobj_tx_get_user_data(void);
void pmemobj_tx_set_abort_on_failure(int enable);
int pmemobj_tx_get_abort_on_failure(void);
```

# DESCRIPTION #
Expand Down Expand Up @@ -412,6 +418,19 @@ If **pmemobj_tx_set_user_data**() was not called for a current transaction,
during **TX_STAGE_WORK** or **TX_STAGE_ONABORT** or **TX_STAGE_ONCOMMIT** or
**TX_STAGE_FINALLY**.

**pmemobj_tx_set_abort_on_failure**() enables or disables automatic transaction
abort in case **pmemobj_tx_add_rage**, **pmemobj_tx_add_rage_direct**, **pmemobj_tx_alloc**,
**pmemobj_tx_free**, **pmemobj_tx_wcsdup**, **pmemobj_tx_lock**, **pmemobj_tx_strdup**,
**pmemobj_tx_xpublish** or **pmemobj_tx_log_append_buffer** fails. If called with
**enable** == 0 *_NO_ABORT flag will be implicitly passed to all of those functions. If
**pmemobj_tx_set_abort_on_failure** is not called (or called with **enable** == 1),
the transaction will abort if any of the previously listed functions fails (unless
*_NO_ABORT flag was passed expliciltly). This functions affects the current transaction
and all inner transactions. It does not affect any outer transactions.
**pmemobj_tx_get_abort_on_failure**() function returns 1 if transaction automatically
aborts on failure, 0 otherwise. Both **pmemobj_tx_set_abort_on_failure**() and
**pmemobj_tx_get_abort_on_failure**() must be called during **TX_STAGE_WORK**.

# RETURN VALUE #

The **pmemobj_tx_stage**() function returns the stage of the current transaction
Expand Down
19 changes: 19 additions & 0 deletions src/include/libpmemobj/tx_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,25 @@ void pmemobj_tx_set_user_data(void *data);
*/
void *pmemobj_tx_get_user_data(void);

/*
* Enables or disables automatic transaction abort in case of an error.
* If called with enable == 0 _NO_ABORT flag will be implicitly passed to
* functions which accept such flag.
*
* This setting is inherited by inner transactions. Aborting on failure is
* the default behaviour.
*
* This function must be called during TX_STAGE_WORK.
*/
void pmemobj_tx_set_abort_on_failure(int enable);

/*
* Returns 1 if transaction automatically aborts on failure, 0 otherwise.
*
* This function must be called during TX_STAGE_WORK.
*/
int pmemobj_tx_get_abort_on_failure(void);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/libpmemobj/libpmemobj.def
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ EXPORTS
pmemobj_tx_log_intents_max_size
pmemobj_tx_set_user_data
pmemobj_tx_get_user_data
pmemobj_tx_set_abort_on_failure
pmemobj_tx_get_abort_on_failure
pmemobj_memcpy
pmemobj_memcpy_persist
pmemobj_memmove
Expand Down
2 changes: 2 additions & 0 deletions src/libpmemobj/libpmemobj.link.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ LIBPMEMOBJ_1.0 {
pmemobj_tx_log_intents_max_size;
pmemobj_tx_set_user_data;
pmemobj_tx_get_user_data;
pmemobj_tx_set_abort_on_failure;
pmemobj_tx_get_abort_on_failure;
pmemobj_memcpy;
pmemobj_memcpy_persist;
pmemobj_memmove;
Expand Down
Loading

0 comments on commit 66e7940

Please sign in to comment.