Skip to content

Commit

Permalink
obj: introduce pmemobj_tx_set_failure_event
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_get_failure_event
which allows to query current setting of a transaction.
  • Loading branch information
igchor committed Apr 15, 2020
1 parent e4b6025 commit 4b6d319
Show file tree
Hide file tree
Showing 18 changed files with 515 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_failure_event**(),
**pmemobj_tx_get_failure_event**()
- 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_failure_event(enum pobj_tx_failure_event event);
enum pobj_tx_failure_event pmemobj_tx_get_failure_event(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_failure_event**() specifies what should happen in case of an error
within the transaction. It only affects functions which take a NO_ABORT flag.
If **pmemobj_tx_set_failure_event**() is called with POBJ_TX_FAILURE_RETURN a NO_ABORT
flag is implicitly passed to all functions which accept this flag. If called
with POBJ_TX_FAILURE_ABORT then all functions abort the transaction (unless NO_ABORT
flag is passed explicitly). This setting is inherited by inner transactions. It does
not affect any of the outer transactions. Aborting on failure is the default behaviour.
**pmemobj_tx_get_failure_event**() returns failure event for the current transaction.
Both **pmemobj_tx_set_failure_event**() and **pmemobj_tx_get_failure_event**()
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 @@ -50,6 +50,11 @@ enum pobj_log_type {
TX_LOG_TYPE_INTENT,
};

enum pobj_tx_failure_event {
POBJ_TX_FAILURE_ABORT,
POBJ_TX_FAILURE_RETURN,
};

#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,20 @@ void pmemobj_tx_set_user_data(void *data);
*/
void *pmemobj_tx_get_user_data(void);

/*
* Sets the failure behaviour of transactional functions.
*
* This function must be called during TX_STAGE_WORK.
*/
void pmemobj_tx_set_failure_event(enum pobj_tx_failure_event event);

/*
* Returns failure event for the current transaction.
*
* This function must be called during TX_STAGE_WORK.
*/
enum pobj_tx_failure_event pmemobj_tx_get_failure_event(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_failure_event
pmemobj_tx_get_failure_event
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_failure_event;
pmemobj_tx_get_failure_event;
pmemobj_memcpy;
pmemobj_memcpy_persist;
pmemobj_memmove;
Expand Down
Loading

0 comments on commit 4b6d319

Please sign in to comment.