1 /* Copyright (c) 2007, 2021, Oracle and/or its affiliates. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 22 23 #ifndef DICT_SIGNAL_HPP 24 #define DICT_SIGNAL_HPP 25 26 #include <Bitmask.hpp> 27 28 #define JAM_FILE_ID 187 29 30 31 struct DictSignal 32 { 33 // DICT transaction and operation REQs include Uint32 requestInfo 34 // implementation signals have only requestType 35 // requestInfo format should be as follows 36 37 // byte 0: requestType (usually enum) 38 39 static Uint32 getRequestTypeDictSignal40 getRequestType(const Uint32& info) { 41 return BitmaskImpl::getField(1, &info, 0, 8); 42 } 43 44 static void setRequestTypeDictSignal45 setRequestType(Uint32& info, Uint32 val) { 46 assert(val < (1 << 8)); 47 BitmaskImpl::setField(1, &info, 0, 8, val); 48 } 49 50 // byte 1: extra case-dependent usage within DICT 51 52 static Uint32 getRequestExtraDictSignal53 getRequestExtra(const Uint32& info) { 54 return BitmaskImpl::getField(1, &info, 8, 8); 55 } 56 57 static void setRequestExtraDictSignal58 setRequestExtra(Uint32& info, Uint32 val) { 59 assert(val < (1 << 8)); 60 BitmaskImpl::setField(1, &info, 8, 8, val); 61 } 62 63 static void addRequestExtraDictSignal64 addRequestExtra(Uint32& dst_info, const Uint32& src_info) { 65 Uint32 val = getRequestExtra(src_info); 66 setRequestExtra(dst_info, val); 67 } 68 69 // byte 2: global flags: passed everywhere 70 // byte 3: local flags: consumed by current op 71 72 private: 73 74 // flag bits are defined relative to entire requestInfo word 75 enum { RequestFlagsMask = 0xffff0000 }; 76 enum { RequestFlagsGlobalMask = 0x00ff0000 }; 77 78 public: 79 80 enum RequestFlags { 81 // global 82 83 /* 84 * This node is transaction coordinator and the only participant. 85 * Used by node doing NR to activate each index. 86 */ 87 RF_LOCAL_TRANS = (1 << 16), 88 89 /* 90 * Activate index but do not build it. On SR, the build is done 91 * in a later start phase (for non-logged index). On NR, the build 92 * on this node takes place automatically during data copy. 93 */ 94 RF_NO_BUILD = (1 << 17) 95 96 }; 97 98 static void addRequestFlagsDictSignal99 addRequestFlags(Uint32& dst_info, const Uint32& src_info) { 100 dst_info |= src_info & RequestFlagsMask; 101 } 102 103 static void addRequestFlagsGlobalDictSignal104 addRequestFlagsGlobal(Uint32& dst_info, const Uint32& src_info) { 105 dst_info |= src_info & RequestFlagsGlobalMask; 106 } 107 108 static const char* getRequestFlagsTextDictSignal109 getRequestFlagsText(const Uint32& info) { 110 static char buf[100]; 111 buf[0] = buf[1] = 0; 112 if (info & RF_LOCAL_TRANS) 113 strcat(buf, " LOCAL_TRANS"); 114 if (info & RF_NO_BUILD) 115 strcat(buf, " NO_BUILD"); 116 return &buf[1]; 117 } 118 119 static const char* getRequestInfoTextDictSignal120 getRequestInfoText(const Uint32& info) { 121 static char buf[100]; 122 sprintf(buf, "type: %u extra: %u flags: %s", 123 getRequestType(info), (info >> 8) & 0xff, getRequestFlagsText(info)); 124 return buf; 125 } 126 127 // these match Dbdict.hpp 128 129 static const char* getTransModeNameDictSignal130 getTransModeName(Uint32 val) { 131 static const char* name[] = { 132 "Undef", "Normal", "Rollback", "Abort" 133 }; 134 Uint32 size = sizeof(name)/sizeof(name[0]); 135 return val < size ? name[val] : "?"; 136 } 137 138 static const char* getTransPhaseNameDictSignal139 getTransPhaseName(Uint32 val) { 140 static const char* name[] = { 141 "Undef", "Begin", "Parse", "Prepare", "Commit", "Complete", "End" 142 }; 143 Uint32 size = sizeof(name)/sizeof(name[0]); 144 return val < size ? name[val] : "?"; 145 } 146 147 static const char* getTransStateNameDictSignal148 getTransStateName(Uint32 val) { 149 static const char* name[] = { 150 "Undef", "Ok", "Error", "NodeFail", "NeedTrans", "NoTrans", "NeedOp", "NoOp" 151 }; 152 Uint32 size = sizeof(name)/sizeof(name[0]); 153 return val < size ? name[val] : "?"; 154 } 155 }; 156 157 158 #undef JAM_FILE_ID 159 160 #endif 161