1/*
2 * transaction_policy.h
3 *
4 * Copyright (C) 2014-2016 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#pragma once
24
25//==========================================================
26// Typedefs & constants.
27//
28
29typedef enum {
30 // Server config override value only - means use policy sent by client.
31 AS_READ_CONSISTENCY_LEVEL_PROTO = -1,
32
33 // Must match AS_POLICY_CONSISTENCY_LEVEL_ONE in C Client v3 as_policy.h.
34 // Ignore duplicates - i.e. don't duplicate resolve.
35 AS_READ_CONSISTENCY_LEVEL_ONE,
36
37 // Must match AS_POLICY_CONSISTENCY_LEVEL_ALL in C Client v3 as_policy.h.
38 // Involve all duplicates in the operation - i.e. duplicate resolve.
39 AS_READ_CONSISTENCY_LEVEL_ALL,
40} as_read_consistency_level;
41
42typedef enum {
43 // Server config override value only - means use policy sent by client.
44 AS_WRITE_COMMIT_LEVEL_PROTO = -1,
45
46 // Must match AS_POLICY_COMMIT_LEVEL_ALL in C Client v3 as_policy.h.
47 // Respond to client only after successfully committing all replicas.
48 AS_WRITE_COMMIT_LEVEL_ALL,
49
50 // Must match AS_POLICY_COMMIT_LEVEL_MASTER in C Client v3 as_policy.h.
51 // Respond to client after successfully committing the master replica.
52 AS_WRITE_COMMIT_LEVEL_MASTER,
53} as_write_commit_level;
54
55
56//==========================================================
57// Public API - macros.
58//
59
60//------------------------------------------------
61// Extract levels from an as_msg.
62//
63
64#define PROTO_CONSISTENCY_LEVEL(asmsg) \
65 (((asmsg).info1 & AS_MSG_INFO1_CONSISTENCY_LEVEL_ALL) == 0 ? \
66 AS_READ_CONSISTENCY_LEVEL_ONE : AS_READ_CONSISTENCY_LEVEL_ALL)
67
68#define PROTO_COMMIT_LEVEL(asmsg) \
69 (((asmsg).info3 & AS_MSG_INFO3_COMMIT_LEVEL_MASTER) == 0 ? \
70 AS_WRITE_COMMIT_LEVEL_ALL : AS_WRITE_COMMIT_LEVEL_MASTER)
71
72//------------------------------------------------
73// Get levels for a transaction with reservation.
74//
75
76// Determine read consistency level for a transaction based on everything.
77#define TR_READ_CONSISTENCY_LEVEL(tr) \
78 (tr->rsv.ns->read_consistency_level == AS_READ_CONSISTENCY_LEVEL_PROTO ? \
79 PROTO_CONSISTENCY_LEVEL(tr->msgp->msg) : \
80 tr->rsv.ns->read_consistency_level)
81
82// Determine write commit level for a transaction based on everything.
83#define TR_WRITE_COMMIT_LEVEL(tr) \
84 (tr->rsv.ns->write_commit_level == AS_WRITE_COMMIT_LEVEL_PROTO ? \
85 PROTO_COMMIT_LEVEL(tr->msgp->msg) : \
86 tr->rsv.ns->write_commit_level)
87
88//------------------------------------------------
89// Get levels without need of reservation.
90//
91
92// Same as above, for use before tr->rsv has been made.
93#define READ_CONSISTENCY_LEVEL(ns, asmsg) \
94 (ns->read_consistency_level == AS_READ_CONSISTENCY_LEVEL_PROTO ? \
95 PROTO_CONSISTENCY_LEVEL(asmsg) : \
96 ns->read_consistency_level)
97
98//------------------------------------------------
99// Get config override values' names.
100//
101
102#define NS_READ_CONSISTENCY_LEVEL_NAME() \
103 (ns->read_consistency_level == AS_READ_CONSISTENCY_LEVEL_PROTO ? \
104 "off" : (ns->read_consistency_level == AS_READ_CONSISTENCY_LEVEL_ONE ? \
105 "one" : "all"))
106
107#define NS_WRITE_COMMIT_LEVEL_NAME() \
108 (ns->write_commit_level == AS_WRITE_COMMIT_LEVEL_PROTO ? \
109 "off" : (ns->write_commit_level == AS_WRITE_COMMIT_LEVEL_ALL ? \
110 "all" : "master"))
111