1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/****************************************************************
* *
* Copyright 2001, 2013 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/
#include "mdef.h"
#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "filestruct.h" /* needed for jnl.h */
#include "gdscc.h" /* needed for tp.h */
#include "jnl.h" /* needed for tp.h */
#include "gdskill.h" /* needed for tp.h */
#include "buddy_list.h" /* needed for tp.h */
#include "hashtab_int4.h" /* needed for tp.h */
#include "tp.h" /* needed for T_BEGIN_READ_NONTP_OR_TP macro */
#include "gvcst_protos.h"
#include "change_reg.h"
#include "op.h"
#include "op_tcommit.h"
#include "tp_frame.h"
#include "tp_restart.h"
#include "targ_alloc.h"
#include "error.h"
#include "stack_frame.h"
#include "gtmimagename.h"
LITREF mval literal_batch;
GBLREF gv_key *gv_currkey, *gv_altkey;
GBLREF gd_region *gv_cur_region;
GBLREF uint4 dollar_tlevel;
DEFINE_NSB_CONDITION_HANDLER(gvcst_spr_query_ch)
boolean_t gvcst_spr_query(void)
{
boolean_t spr_tpwrapped;
boolean_t est_first_pass;
boolean_t found, cumul_found;
int reg_index;
gd_binding *start_map, *end_map, *map, *prev_end_map;
gd_region *reg, *gd_reg_start;
gd_addr *addr;
gv_namehead *start_map_gvt;
gvnh_reg_t *gvnh_reg;
trans_num gd_targ_tn, *tn_array;
char cumul_key[MAX_KEY_SZ];
int cumul_key_len, prev;
# ifdef DEBUG
int save_dollar_tlevel;
# endif
DCL_THREADGBL_ACCESS;
SETUP_THREADGBL_ACCESS;
start_map = TREF(gd_targ_map); /* set up by op_gvname/op_gvnaked/op_gvextnam done just before invoking op_gvquery */
start_map_gvt = gv_target; /* save gv_target corresponding to start_map so we can restore at end */
/* Do any initialization that is independent of retries BEFORE the op_tstart */
addr = TREF(gd_targ_addr);
assert(NULL != addr);
gd_reg_start = &addr->regions[0];
tn_array = TREF(gd_targ_reg_array);
gvnh_reg = TREF(gd_targ_gvnh_reg);
assert(NULL != gvnh_reg);
assert(NULL != gvnh_reg->gvspan);
/* Now that we know the keyrange maps to more than one region, go through each of them and do the $query
* Since multiple regions are potentially involved, need a TP fence.
*/
DEBUG_ONLY(save_dollar_tlevel = dollar_tlevel);
if (!dollar_tlevel)
{
spr_tpwrapped = TRUE;
op_tstart((IMPLICIT_TSTART), TRUE, &literal_batch, 0);
ESTABLISH_NORET(gvcst_spr_query_ch, est_first_pass);
GVCST_ROOT_SEARCH_AND_PREP(est_first_pass);
} else
spr_tpwrapped = FALSE;
assert(gv_cur_region == start_map->reg.addr);
DBG_CHECK_GVTARGET_GVCURRKEY_IN_SYNC(CHECK_CSA_TRUE);
/* Do any initialization that is dependent on retries AFTER the op_tstart */
map = start_map;
cumul_found = FALSE;
cumul_key_len = 0;
DEBUG_ONLY(cumul_key[cumul_key_len] = KEY_DELIMITER;)
INCREMENT_GD_TARG_TN(gd_targ_tn); /* takes a copy of incremented "TREF(gd_targ_tn)" into local variable "gd_targ_tn" */
assert(0 < gvnh_reg->gvspan->end_map_index);
assert(gvnh_reg->gvspan->end_map_index < addr->n_maps);
end_map = &addr->maps[gvnh_reg->gvspan->end_map_index];
/* Verify that initializations that happened before op_tstart are still unchanged */
assert(addr == TREF(gd_targ_addr));
assert(tn_array == TREF(gd_targ_reg_array));
assert(gvnh_reg == TREF(gd_targ_gvnh_reg));
for ( ; map <= end_map; map++)
{ /* Scan through each map in the gld and do gvcst_query calls in each map's region.
* Note down the smallest key found across the scanned regions until we find a key that belongs to the
* same map (in the gld) as the currently scanned "map". At which point, the region-spanning query is done.
*/
reg = map->reg.addr;
GET_REG_INDEX(addr, gd_reg_start, reg, reg_index); /* sets "reg_index" */
assert((map != start_map) || (tn_array[reg_index] != gd_targ_tn));
assert(TREF(gd_targ_reg_array_size) > reg_index);
if (tn_array[reg_index] == gd_targ_tn)
continue;
if (map != start_map)
GV_BIND_SUBSREG(addr, reg, gvnh_reg); /* sets gv_target/gv_cur_region/cs_addrs */
assert(reg->open);
if (gv_target->root)
{
found = gvcst_query();
if (found)
{
cumul_found = TRUE;
assert(gv_altkey->end);
assert(KEY_DELIMITER == gv_altkey->base[gv_altkey->end]);
assert(!cumul_key_len || (KEY_DELIMITER == cumul_key[cumul_key_len - 1]));
if (!cumul_key_len || (0 < memcmp(&cumul_key[0], &gv_altkey->base[0], cumul_key_len)))
{ /* just found alt_key is less (collation-wise) than cumul_key so update cumul_key */
cumul_key_len = gv_altkey->end + 1;
assert(cumul_key_len);
assert(cumul_key_len < ARRAYSIZE(cumul_key));
memcpy(&cumul_key[0], &gv_altkey->base[0], cumul_key_len);
DEBUG_ONLY(prev_end_map = end_map;)
/* update end_map as well now that we got an earlier cumul_key */
end_map = gv_srch_map_linear(map, (char *)&gv_altkey->base[0], gv_altkey->end - 1);
BACK_OFF_ONE_MAP_ENTRY_IF_EDGECASE(gv_altkey->base, gv_altkey->end - 1, end_map);
assert(prev_end_map >= end_map);
}
}
}
tn_array[reg_index] = gd_targ_tn;
}
if (gv_target != start_map_gvt)
{ /* Restore gv_cur_region/gv_target etc. */
gv_target = start_map_gvt;
gv_cur_region = start_map->reg.addr;
change_reg();
}
DBG_CHECK_GVTARGET_GVCURRKEY_IN_SYNC(CHECK_CSA_TRUE);
if (spr_tpwrapped)
{
op_tcommit();
REVERT; /* remove our condition handler */
}
assert(save_dollar_tlevel == dollar_tlevel);
if (cumul_found)
{ /* Restore accumulated minimal key into gv_altkey */
assert(cumul_key_len);
memcpy(&gv_altkey->base[0], &cumul_key[0], cumul_key_len);
gv_altkey->end = cumul_key_len - 1;
assert(KEY_DELIMITER == gv_altkey->base[gv_altkey->end]);
}
return cumul_found;
}
|