Motr  M0
tx.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 #ifndef __MOTR_BE_TX_H__
25 #define __MOTR_BE_TX_H__
26 
27 #include "lib/misc.h" /* M0_BITS */
28 #include "lib/buf.h" /* m0_buf */
29 
30 #include "sm/sm.h" /* m0_sm */
31 
32 #include "be/tx_regmap.h" /* m0_be_reg_area */
33 
34 struct m0_be_domain;
35 struct m0_be_tx_group;
36 struct m0_be_fmt_tx;
37 struct m0_fol_rec;
38 
256  /*
257  * All transaction updates made it to the log.
258  */
271 };
272 
273 /*
274  * NOTE: Call-backs of this type must be asynchronous, because they can be
275  * called from state transition functions.
276  */
277 typedef void (*m0_be_tx_cb_t)(const struct m0_be_tx *tx);
280 struct m0_be_tx {
281  struct m0_sm t_sm;
282 
284  uint64_t t_id;
292 
297  uint64_t t_magic;
298 
302 
309 
319 
332  void (*t_filler)(struct m0_be_tx *tx, void *payload);
333 
339  void *t_datum;
344  uint64_t t_lsn;
374  uint32_t t_ref;
377  /* XXX TODO merge with t_log_reserved. */
383  bool t_fast;
393  void (*t_gc_free)(struct m0_be_tx *tx, void *param);
394  void *t_gc_param;
407  bool t_grouped;
425 };
426 
431  uint64_t tri_txid;
432  uint64_t tri_locality;
433 } M0_XCA_RECORD M0_XCA_DOMAIN(be|rpc);
434 
435 #if M0_DEBUG_BE_CREDITS == 1
436 
441 #define M0_BE_CREDIT_INC(n, cr_user, credit) ({ \
442  typeof(cr_user) cu = (cr_user); \
443  typeof(credit) cr = (credit); \
444  cr->tc_balance[cu] += (n); \
445  M0_LOG(M0_DEBUG, "INC cr=%p user=%d balance=%d", cr, (int)cu, \
446  cr->tc_balance[cu]); \
447 })
448 
454 #define M0_BE_CREDIT_DEC(cr_user, tx) ({ \
455  struct m0_be_tx_credit *cr = &(tx)->t_prepared; \
456  typeof(cr_user) cu = (cr_user); \
457  M0_LOG(M0_DEBUG, "DEC cr=%p user=%d balance=%d", cr, (int)cu, \
458  cr->tc_balance[cu]); \
459  M0_CNT_DEC(cr->tc_balance[cu]); \
460 })
461 
462 #else
463 
464 #define M0_BE_CREDIT_INC(n, cr_user, credit)
465 #define M0_BE_CREDIT_DEC(cr_user, tx)
466 
467 #endif
468 
469 M0_INTERNAL bool m0_be_tx__invariant(const struct m0_be_tx *tx);
470 
471 M0_INTERNAL void m0_be_tx_init(struct m0_be_tx *tx,
472  uint64_t tid,
473  struct m0_be_domain *dom,
474  struct m0_sm_group *sm_group,
475  m0_be_tx_cb_t persistent,
476  m0_be_tx_cb_t discarded,
477  void (*filler)(struct m0_be_tx *tx,
478  void *payload),
479  void *datum);
480 
481 M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx);
482 
483 M0_INTERNAL void m0_be_tx_prep(struct m0_be_tx *tx,
484  const struct m0_be_tx_credit *credit);
485 
494 M0_INTERNAL void m0_be_tx_payload_prep(struct m0_be_tx *tx, m0_bcount_t size);
495 
496 M0_INTERNAL void m0_be_tx_open(struct m0_be_tx *tx);
497 M0_INTERNAL void m0_be_tx_exclusive_open(struct m0_be_tx *tx);
498 
499 M0_INTERNAL void m0_be_tx_capture(struct m0_be_tx *tx,
500  const struct m0_be_reg *reg);
501 M0_INTERNAL void m0_be_tx_uncapture(struct m0_be_tx *tx,
502  const struct m0_be_reg *reg);
503 
504 /* XXX change to (tx, seg, ptr) */
505 #define M0_BE_TX_CAPTURE_PTR(seg, tx, ptr) \
506  m0_be_tx_capture((tx), &M0_BE_REG((seg), sizeof *(ptr), (ptr)))
507 #define M0_BE_TX_CAPTURE_ARR(seg, tx, arr, nr) \
508  m0_be_tx_capture((tx), &M0_BE_REG((seg), (nr) * sizeof((arr)[0]), (arr)))
509 #define M0_BE_TX_CAPTURE_BUF(seg, tx, buf) \
510  m0_be_tx_capture((tx), &M0_BE_REG((seg), (buf)->b_nob, (buf)->b_addr))
511 
512 M0_INTERNAL void m0_be_tx_close(struct m0_be_tx *tx);
513 
520 M0_INTERNAL void m0_be_tx_get(struct m0_be_tx *tx);
530 M0_INTERNAL void m0_be_tx_put(struct m0_be_tx *tx);
531 
537 M0_INTERNAL void m0_be_tx_force(struct m0_be_tx *tx);
538 
545 M0_INTERNAL int m0_be_tx_timedwait(struct m0_be_tx *tx,
546  uint64_t states,
547  m0_time_t deadline);
548 
549 M0_INTERNAL enum m0_be_tx_state m0_be_tx_state(const struct m0_be_tx *tx);
550 M0_INTERNAL const char *m0_be_tx_state_name(enum m0_be_tx_state state);
551 
559 M0_INTERNAL int m0_be_tx_open_sync(struct m0_be_tx *tx);
560 M0_INTERNAL int m0_be_tx_exclusive_open_sync(struct m0_be_tx *tx);
561 
566 M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx);
567 
572 M0_INTERNAL bool m0_be_tx__is_fast(struct m0_be_tx *tx);
573 
575 M0_INTERNAL int m0_be_tx_fol_add(struct m0_be_tx *tx, struct m0_fol_rec *rec);
576 
581 M0_INTERNAL void m0_be_tx_force (struct m0_be_tx *tx);
582 
586 M0_INTERNAL bool m0_be_tx__is_exclusive(const struct m0_be_tx *tx);
587 
601 M0_INTERNAL void m0_be_tx__recovering_set(struct m0_be_tx *tx);
602 M0_INTERNAL bool m0_be_tx__is_recovering(struct m0_be_tx *tx);
603 
604 M0_INTERNAL void m0_be_tx_deconstruct(struct m0_be_tx *tx,
605  struct m0_be_fmt_tx *ftx);
606 /*
607  * @pre m0_be_tx_state(tx) == M0_BTS_PREPARE
608  */
609 M0_INTERNAL void m0_be_tx_reconstruct(struct m0_be_tx *tx,
610  const struct m0_be_fmt_tx *ftx);
611 
612 /*
613  * Assign tx to a group.
614  *
615  * Does nothing if m0_be_tx__is_recovering(tx).
616  */
617 M0_INTERNAL void m0_be_tx__group_assign(struct m0_be_tx *tx,
618  struct m0_be_tx_group *gr);
619 
620 M0_INTERNAL bool m0_be_tx_should_break(struct m0_be_tx *tx,
621  const struct m0_be_tx_credit *c);
622 
656 M0_INTERNAL void m0_be_tx_gc_enable(struct m0_be_tx *tx,
657  void (*gc_free)(struct m0_be_tx *,
658  void *param),
659  void *param);
660 
661 M0_INTERNAL bool m0_be_should_break(struct m0_be_engine *eng,
662  const struct m0_be_tx_credit *accum,
663  const struct m0_be_tx_credit *delta);
664 
665 M0_INTERNAL bool m0_be_should_break_half(struct m0_be_engine *eng,
666  const struct m0_be_tx_credit *accum,
667  const struct m0_be_tx_credit *delta);
668 
669 
670 M0_INTERNAL void m0_be_tx_lsn_set(struct m0_be_tx *tx,
671  m0_bindex_t lsn,
672  m0_bindex_t lsn_discarded);
673 M0_INTERNAL void m0_be_tx_lsn_get(struct m0_be_tx *tx,
674  m0_bindex_t *lsn,
675  m0_bindex_t *lsn_discarded);
676 
678 #endif /* __MOTR_BE_TX_H__ */
679 
680 /*
681  * Local variables:
682  * c-indentation-style: "K&R"
683  * c-basic-offset: 8
684  * tab-width: 8
685  * fill-column: 80
686  * scroll-step: 1
687  * End:
688  */
689 /*
690  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
691  */
struct m0_be_tx_credit t_prepared
Definition: tx.h:300
struct m0_sm_ast t_ast_grouping
Definition: tx.h:366
bool t_recovering
Definition: tx.h:402
struct m0_sm_ast t_ast_placed
Definition: tx.h:370
struct m0_sm_ast t_ast_logged
Definition: tx.h:369
M0_INTERNAL void m0_be_tx_lsn_set(struct m0_be_tx *tx, m0_bindex_t lsn, m0_bindex_t lsn_discarded)
Definition: tx.c:743
m0_bcount_t t_log_reserved_size
Definition: tx.h:378
struct m0_atomic64 t_fdmi_ref
Definition: tx.h:412
bool t_gc_enabled
Definition: tx.h:392
M0_INTERNAL int m0_be_tx_timedwait(struct m0_be_tx *tx, uint64_t states, m0_time_t deadline)
Definition: stubs.c:215
m0_be_tx_state
Definition: tx.h:214
uint64_t m0_time_t
Definition: time.h:37
struct m0_tlink t_fdmi_linkage
Definition: tx.h:418
M0_INTERNAL void m0_be_tx__recovering_set(struct m0_be_tx *tx)
Definition: tx.c:654
M0_INTERNAL bool m0_be_tx_should_break(struct m0_be_tx *tx, const struct m0_be_tx_credit *c)
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
struct m0_sm_ast t_ast_done
Definition: tx.h:371
M0_INTERNAL void m0_be_tx_exclusive_open(struct m0_be_tx *tx)
Definition: tx.c:588
struct m0_tlink t_engine_linkage
Definition: tx.h:294
M0_INTERNAL void m0_be_tx_prep(struct m0_be_tx *tx, const struct m0_be_tx_credit *credit)
Definition: stubs.c:175
uint64_t m0_bindex_t
Definition: types.h:80
uint64_t m0_bcount_t
Definition: types.h:77
Definition: sm.h:504
M0_INTERNAL bool m0_be_tx__is_fast(struct m0_be_tx *tx)
Definition: tx.c:625
m0_be_tx_cb_t t_discarded
Definition: tx.h:318
struct m0_be_domain * t_dom
Definition: tx.h:291
Definition: buf.h:37
void * t_datum
Definition: tx.h:339
struct m0_tlink t_group_linkage
Definition: tx.h:296
struct m0_tlink t_first_capture_linkage
Definition: tx.h:396
void * t_gc_param
Definition: tx.h:394
M0_INTERNAL void m0_be_tx_deconstruct(struct m0_be_tx *tx, struct m0_be_fmt_tx *ftx)
Definition: tx.c:664
struct m0_be_tx_group * t_group
Definition: tx.h:372
M0_INTERNAL void m0_be_tx__group_assign(struct m0_be_tx *tx, struct m0_be_tx_group *gr)
Definition: tx.c:689
bool t_grouped
Definition: tx.h:407
static struct m0_addb2_callback c
Definition: consumer.c:41
bool t_log_reserved
Definition: tx.h:376
struct m0_sm_ast t_ast_active
Definition: tx.h:367
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL int m0_be_tx_open_sync(struct m0_be_tx *tx)
Definition: stubs.c:199
m0_bcount_t t_payload_prepared
Definition: tx.h:365
M0_INTERNAL void m0_be_tx_close(struct m0_be_tx *tx)
Definition: stubs.c:194
M0_INTERNAL int m0_be_tx_exclusive_open_sync(struct m0_be_tx *tx)
Definition: tx.c:594
M0_INTERNAL bool m0_be_tx__is_exclusive(const struct m0_be_tx *tx)
Definition: tx.c:649
m0_bindex_t t_lsn_discarded
Definition: tx.h:350
M0_INTERNAL void m0_be_tx_lsn_get(struct m0_be_tx *tx, m0_bindex_t *lsn, m0_bindex_t *lsn_discarded)
Definition: tx.c:761
uint64_t t_magic
Definition: tx.h:297
M0_INTERNAL bool m0_be_should_break_half(struct m0_be_engine *eng, const struct m0_be_tx_credit *accum, const struct m0_be_tx_credit *delta)
Definition: tx.c:721
uint32_t t_ref
Definition: tx.h:374
M0_INTERNAL void m0_be_tx_get(struct m0_be_tx *tx)
Definition: stubs.c:167
uint64_t t_id
Definition: tx.h:284
struct m0_sm_ast t_ast_failed
Definition: tx.h:368
uint64_t tri_txid
Definition: tx.h:431
struct m0_sm t_sm
Definition: tx.h:281
Definition: seg.h:142
bool t_fast
Definition: tx.h:383
uint64_t tri_locality
Definition: tx.h:432
M0_INTERNAL void m0_be_tx_init(struct m0_be_tx *tx, uint64_t tid, struct m0_be_domain *dom, struct m0_sm_group *sm_group, m0_be_tx_cb_t persistent, m0_be_tx_cb_t discarded, void(*filler)(struct m0_be_tx *tx, void *payload), void *datum)
Definition: stubs.c:150
struct m0_sm_ast t_fdmi_put_ast
Definition: tx.h:424
M0_INTERNAL void m0_be_tx_reconstruct(struct m0_be_tx *tx, const struct m0_be_fmt_tx *ftx)
Definition: tx.c:670
bool t_exclusive
Definition: tx.h:388
void(* t_gc_free)(struct m0_be_tx *tx, void *param)
Definition: tx.h:393
uint64_t t_lsn
Definition: tx.h:344
M0_INTERNAL void m0_be_tx_open(struct m0_be_tx *tx)
Definition: stubs.c:184
m0_be_tx_cb_t t_persistent
Definition: tx.h:308
Definition: sm.h:301
M0_INTERNAL void m0_be_tx_uncapture(struct m0_be_tx *tx, const struct m0_be_reg *reg)
Definition: tx.c:325
m0_bcount_t size
Definition: di.c:39
M0_INTERNAL bool m0_be_should_break(struct m0_be_engine *eng, const struct m0_be_tx_credit *accum, const struct m0_be_tx_credit *delta)
Definition: tx.c:714
struct m0_buf t_payload
Definition: tx.h:364
M0_INTERNAL void m0_be_tx_put(struct m0_be_tx *tx)
Definition: stubs.c:171
M0_INTERNAL bool m0_be_tx__is_recovering(struct m0_be_tx *tx)
Definition: tx.c:659
M0_INTERNAL void m0_be_tx_gc_enable(struct m0_be_tx *tx, void(*gc_free)(struct m0_be_tx *, void *param), void *param)
Definition: tx.c:728
void(* t_filler)(struct m0_be_tx *tx, void *payload)
Definition: tx.h:332
M0_INTERNAL void m0_be_tx_capture(struct m0_be_tx *tx, const struct m0_be_reg *reg)
Definition: stubs.c:190
M0_INTERNAL const char * m0_be_tx_state_name(enum m0_be_tx_state state)
Definition: tx.c:417
struct m0_be_reg_area t_reg_area
Definition: tx.h:301
M0_INTERNAL void m0_be_tx_payload_prep(struct m0_be_tx *tx, m0_bcount_t size)
Definition: stubs.c:180
Definition: tx.h:270
int m0_be_tx_fol_add(struct m0_be_tx *tx, struct m0_fol_rec *rec)
Definition: stubs.c:295
M0_INTERNAL bool m0_be_tx__invariant(const struct m0_be_tx *tx)
Definition: tx.c:555
void(* m0_be_tx_cb_t)(const struct m0_be_tx *tx)
Definition: tx.h:277
struct m0_be_tx_remid M0_XCA_DOMAIN(be|rpc)
static struct m0_sm_state_descr states[C_NR]
Definition: sm.c:512
static struct m0_be_ut_backend be
Definition: service_ut.c:59
M0_INTERNAL void m0_be_tx_force(struct m0_be_tx *tx)
Definition: tx.c:638
struct m0_be_engine * t_engine
Definition: tx.h:285
M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx)
Definition: stubs.c:205
const uint64_t payload[]
Definition: base.c:65
Definition: tx.h:280