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 31, 2020
1 parent e4b6025 commit 5247578
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 51 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_action_on_failure**(),
**pmemobj_tx_get_action_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_action_on_failure(enum pobj_tx_action_on_failure action);
enum pobj_tx_action_on_failure pmemobj_tx_get_action_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_action_on_failure**() sets actions to be taken by transactional
functions in case of an error. It only affects functions which take a NO_ABORT flag.
If **pmemobj_tx_set_action_on_failure**() is called with POBJ_RETURN_ERROR a NO_ABORT
flag is implicitly passed to all functions which accept a NO_ABORT flag. If called
with POBJ_TX_ABORT then all functions behave normally. Action on failure setting is
inherited by inner transactions. It does not affect any of outer transactions.
Aborting on failure is the default behaviour. **pmemobj_tx_get_action_on_failure**()
returns action on failure for the current transaction.
Both **pmemobj_tx_set_action_on_failure**() and **pmemobj_tx_get_action_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
28 changes: 28 additions & 0 deletions src/include/libpmemobj/tx_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ enum pobj_log_type {
TX_LOG_TYPE_INTENT,
};

enum pobj_tx_action_on_failure {
POBJ_TX_ABORT,
POBJ_RETURN_ERROR,
};

#if !defined(pmdk_use_attr_deprec_with_msg) && defined(__COVERITY__)
#define pmdk_use_attr_deprec_with_msg 0
#endif
Expand Down Expand Up @@ -424,6 +429,29 @@ void pmemobj_tx_set_user_data(void *data);
*/
void *pmemobj_tx_get_user_data(void);

/*
* Sets action to be taken by transactional functions in case of an error.
* It only affects functions which take a NO_ABORT flag.
*
* If pmemobj_tx_set_action_on_failure is called with POBJ_RETURN_ERROR
* a NO_ABORT flag is implicitly passed to all functions which accept a NO_ABORT flag.
*
* If called with POBJ_TX_ABORT then all functions behave normally.
*
* 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_action_on_failure(enum pobj_tx_action_on_failure action);

/*
* Returns action on failure for the current transaction.
*
* This function must be called during TX_STAGE_WORK.
*/
enum pobj_tx_action_on_failure pmemobj_tx_get_action_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_action_on_failure
pmemobj_tx_get_action_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_action_on_failure;
pmemobj_tx_get_action_on_failure;
pmemobj_memcpy;
pmemobj_memcpy_persist;
pmemobj_memmove;
Expand Down
Loading

0 comments on commit 5247578

Please sign in to comment.