From a2c3b4e72222a00173fbdf53261aee73a8b33549 Mon Sep 17 00:00:00 2001 From: Ryo Kanbayashi Date: Thu, 12 Sep 2024 18:44:24 +0900 Subject: [PATCH] Integer and Varchar testcase passed. Varchar(all writes and reads get giant exclusive lock, 50bytes fixed size key) --- lib/storage/index/btree_index.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/storage/index/btree_index.go b/lib/storage/index/btree_index.go index ec41f7b9..7e0103f9 100644 --- a/lib/storage/index/btree_index.go +++ b/lib/storage/index/btree_index.go @@ -150,7 +150,11 @@ func (btidx *BTreeIndex) ScanKey(key *tuple.Tuple, txn interface{}) []page.RID { smallestKeyVal := samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgKeyVal, &page.RID{0, 0}) biggestKeyVal := samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgKeyVal, &page.RID{math.MaxInt32, math.MaxUint32}) - btidx.rwMtx.RLock() + if orgKeyVal.ValueType() == types.Varchar { + btidx.rwMtx.Lock() + } else { + btidx.rwMtx.RLock() + } // Attention: returned itr's containing keys are string type Value which is constructed with byte arr of concatenated original key and value rangeItr := btidx.container.GetRangeItr(smallestKeyVal.SerializeOnlyVal(), biggestKeyVal.SerializeOnlyVal()) @@ -162,7 +166,11 @@ func (btidx *BTreeIndex) ScanKey(key *tuple.Tuple, txn interface{}) []page.RID { //uintRID := binary.BigEndian.Uint64(eightBytesRID[:]) retArr = append(retArr, samehada_util.Unpack8BytesToRID(eightBytesRID[:])) } - btidx.rwMtx.RUnlock() + if orgKeyVal.ValueType() == types.Varchar { + btidx.rwMtx.Unlock() + } else { + btidx.rwMtx.RUnlock() + } return retArr } @@ -192,8 +200,13 @@ func (btidx *BTreeIndex) GetRangeScanIterator(start_key *tuple.Tuple, end_key *t biggestKeyVal = samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgEndKeyVal, &page.RID{math.MaxInt32, math.MaxUint32}) } - btidx.rwMtx.RLock() - defer btidx.rwMtx.RUnlock() + if tupleSchema_.GetColumns()[btidx.col_idx].GetType() == types.Varchar { + btidx.rwMtx.Lock() + defer btidx.rwMtx.Unlock() + } else { + btidx.rwMtx.RLock() + defer btidx.rwMtx.RUnlock() + } var smalledKeyBytes []byte var biggestKeyBytes []byte