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 23, 2020
1 parent e4b6025 commit 570c6be
Show file tree
Hide file tree
Showing 32 changed files with 511 additions and 48 deletions.
21 changes: 19 additions & 2 deletions doc/libpmemobj/pmemobj_tx_begin.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ date: pmemobj API version 2.3
...

[comment]: <> (SPDX-License-Identifier: BSD-3-Clause)
[comment]: <> (Copyright 2017-2019, Intel Corporation)
[comment]: <> (Copyright 2017-2020, Intel Corporation)

[comment]: <> (pmemobj_tx_begin.3 -- man page for transactional object manipulation)

Expand Down 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,17 @@ 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 any transactional function accepting NO_ABORT flag fails. If called with
**enable** == 0 a 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 above mentioned functions fails (unless
a NO_ABORT flag was passed expliciltly). These 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
4 changes: 3 additions & 1 deletion src/libpmemobj/libpmemobj.def
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;;; Begin Copyright Notice
; SPDX-License-Identifier: BSD-3-Clause
; Copyright 2015-2018, Intel Corporation
; Copyright 2015-2020, Intel Corporation
;;;; End Copyright Notice

LIBRARY libpmemobj
Expand Down 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
4 changes: 3 additions & 1 deletion src/libpmemobj/libpmemobj.link.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2014-2019, Intel Corporation
# Copyright 2014-2020, Intel Corporation
#
#
# src/libpmemobj.link -- linker link file for libpmemobj
Expand Down 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 570c6be

Please sign in to comment.