Mercurial > nomad
changeset 765:38eb5030420a
objstore: add "log an entry" transaction function
This changes the required flow to:
1. txn_begin
2. a number of:
a. txn_alloc_entry
b. fill in the txn_entry
c. txn_log_entry
3. txn_commit or txn_abort
The explicit "we're done with this entry" allows for additional checks and
for transaction log record writes to happen earlier.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 30 Mar 2020 11:20:37 -0400 |
parents | dd2a3aad09cf |
children | 87f69b55be61 |
files | src/objstore/include/nomad/objstore_backend.h src/objstore/objstore_impl.h src/objstore/txn.c src/objstore/vol.c |
diffstat | 4 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/include/nomad/objstore_backend.h Mon Mar 30 10:45:23 2020 -0400 +++ b/src/objstore/include/nomad/objstore_backend.h Mon Mar 30 11:20:37 2020 -0400 @@ -228,6 +228,7 @@ const struct nvclock *clock, const struct nattr *attrs); int (*txn_begin)(struct txn *txn); + int (*txn_log_entry)(struct txn *txn, struct txn_entry *entry); int (*txn_commit)(struct txn *txn); int (*txn_complete)(struct txn *txn); void (*txn_abort)(struct txn *txn);
--- a/src/objstore/objstore_impl.h Mon Mar 30 10:45:23 2020 -0400 +++ b/src/objstore/objstore_impl.h Mon Mar 30 11:20:37 2020 -0400 @@ -102,6 +102,7 @@ extern int txn_commit(struct txn *txn); extern void txn_abort(struct txn *txn); extern struct txn_entry *txn_alloc_entry(struct txn *txn); +extern void txn_log_entry(struct txn *txn, struct txn_entry *entry); static inline int txn_commitabort(struct txn *txn, int err) {
--- a/src/objstore/txn.c Mon Mar 30 10:45:23 2020 -0400 +++ b/src/objstore/txn.c Mon Mar 30 11:20:37 2020 -0400 @@ -219,3 +219,19 @@ panic("failed to allocate new transaction entry (txn %p)", txn); } + +void txn_log_entry(struct txn *txn, struct txn_entry *entry) +{ + int ret; + + ASSERT3P(entry->perform, !=, NULL); + + ret = txn->clone->ops->txn_log_entry(txn, entry); + + entry->failed = (ret != 0); + + /* TODO: in the future, we'll want to return the error to the caller */ + if (ret) + panic("failed to log entry (txn %p, entry %p): %s", txn, entry, + xstrerror(ret)); +}
--- a/src/objstore/vol.c Mon Mar 30 10:45:23 2020 -0400 +++ b/src/objstore/vol.c Mon Mar 30 11:20:37 2020 -0400 @@ -112,8 +112,9 @@ else if (!clone->ops->initobj) cmn_err(CE_INFO, "Object init function is required (backend: %s)", vdev->def->name); - else if (!clone->ops->txn_begin || !clone->ops->txn_commit || - !clone->ops->txn_complete || !clone->ops->txn_abort) + else if (!clone->ops->txn_begin || !clone->ops->txn_log_entry || + !clone->ops->txn_commit || !clone->ops->txn_complete || + !clone->ops->txn_abort) cmn_err(CE_INFO, "Transaction functions are required " "(backend: %s)", vdev->def->name); }