Skip to content

Commit

Permalink
removed read lock at BTreeIndex::{ScanKey, GetRangeScanIterator} and …
Browse files Browse the repository at this point in the history
…decided BTreeIndex doesn't support Varchar.
  • Loading branch information
ryogrid committed Sep 3, 2024
1 parent 9adffe0 commit 12540af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
20 changes: 11 additions & 9 deletions lib/execution/executors/executor_test/btree_index_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func testBTreeParallelTxnStrideRoot[T int32 | float32 | string](t *testing.T, ke
//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 400, 5000, 17, 0, bpoolSize, index_constants.INDEX_KIND_SKIP_LIST, PARALLEL_EXEC, 20)
//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 400, 5000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, PARALLEL_EXEC, 20)
//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 400, 1000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, SERIAL_EXEC, 1)
InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 800, 5000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, SERIAL_EXEC, 1)
//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 800, 5000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, SERIAL_EXEC, 1)

//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 400, 3000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, PARALLEL_EXEC, 20)
//InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 800, 30000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, PARALLEL_EXEC, 20)
InnerTestParallelTxnsQueryingIndexUsedColumns[T](t, keyType, 800, 30000, 17, 0, bpoolSize, index_constants.INDEX_KIND_BTREE, PARALLEL_EXEC, 20)
default:
panic("not implemented!")
}
Expand Down Expand Up @@ -173,10 +173,12 @@ func TestKeyDuplicateBTreePrallelTxnStrideFloat(t *testing.T) {
testBTreeParallelTxnStrideRoot[float32](t, types.Float)
}

func TestKeyDuplicateBTreePrallelTxnStrideVarchar(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skip this in short mode.")
}
testBTreeParallelTxnStrideRoot[string](t, types.Varchar)
}
// BTreeIndex doesn't support Varchar

//func TestKeyDuplicateBTreePrallelTxnStrideVarchar(t *testing.T) {
// t.Parallel()
// if testing.Short() {
// t.Skip("skip this in short mode.")
// }
// testBTreeParallelTxnStrideRoot[string](t, types.Varchar)
//}
26 changes: 13 additions & 13 deletions lib/storage/index/btree_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ type BTreeIndex struct {
// idx of target column on table
col_idx uint32
log_manager *recovery.LogManager
// UpdateEntry only get Write lock
updateMtx sync.RWMutex
// write operations are mutually exclusive
rwMtx sync.RWMutex
// for call of Close method ....
bufMgr *blink_tree.BufMgr
}
Expand All @@ -84,7 +84,7 @@ func NewBTreeIndex(metadata *IndexMetadata, buffer_pool_manager *buffer.BufferPo
bufMgr := blink_tree.NewBufMgr(12, blink_tree.HASH_TABLE_ENTRY_CHAIN_LEN*common.MaxTxnThreadNum*2, btree.NewParentBufMgrImpl(buffer_pool_manager), lastPageZeroId)
ret.container = blink_tree.NewBLTree(bufMgr)
ret.col_idx = col_idx
ret.updateMtx = sync.RWMutex{}
ret.rwMtx = sync.RWMutex{}
ret.log_manager = log_manager
ret.bufMgr = bufMgr
return ret
Expand All @@ -97,8 +97,8 @@ func (btidx *BTreeIndex) insertEntryInner(key *tuple.Tuple, rid page.RID, txn in
convedKeyVal := samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgKeyVal, &rid)

if isNoLock == false {
btidx.updateMtx.Lock()
defer btidx.updateMtx.Unlock()
btidx.rwMtx.Lock()
defer btidx.rwMtx.Unlock()
}

packedRID := samehada_util.PackRIDtoUint64(&rid)
Expand All @@ -122,8 +122,8 @@ func (btidx *BTreeIndex) deleteEntryInner(key *tuple.Tuple, rid page.RID, txn in
convedKeyVal := samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgKeyVal, &rid)

if isNoLock == false {
btidx.updateMtx.Lock()
defer btidx.updateMtx.Unlock()
btidx.rwMtx.Lock()
defer btidx.rwMtx.Unlock()
}
btidx.container.DeleteKey(convedKeyVal.SerializeOnlyVal(), 0)
}
Expand All @@ -138,7 +138,7 @@ 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.updateMtx.RLock()
//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())

Expand All @@ -149,14 +149,14 @@ func (btidx *BTreeIndex) ScanKey(key *tuple.Tuple, txn interface{}) []page.RID {
uintRID := binary.BigEndian.Uint64(eightBytesRID[:])
retArr = append(retArr, samehada_util.UnpackUint64toRID(uintRID))
}
btidx.updateMtx.RUnlock()
//btidx.rwMtx.RUnlock()

return retArr
}

func (btidx *BTreeIndex) UpdateEntry(oldKey *tuple.Tuple, oldRID page.RID, newKey *tuple.Tuple, newRID page.RID, txn interface{}) {
btidx.updateMtx.Lock()
defer btidx.updateMtx.Unlock()
btidx.rwMtx.Lock()
defer btidx.rwMtx.Unlock()
btidx.deleteEntryInner(oldKey, oldRID, txn, true)
btidx.insertEntryInner(newKey, newRID, txn, true)
}
Expand All @@ -179,8 +179,8 @@ func (btidx *BTreeIndex) GetRangeScanIterator(start_key *tuple.Tuple, end_key *t
biggestKeyVal = samehada_util.EncodeValueAndRIDToDicOrderComparableVarchar(&orgEndKeyVal, &page.RID{math.MaxInt32, math.MaxUint32})
}

btidx.updateMtx.RLock()
defer btidx.updateMtx.RUnlock()
//btidx.rwMtx.RLock()
//defer btidx.rwMtx.RUnlock()
var smalledKeyBytes []byte
var biggestKeyBytes []byte

Expand Down

0 comments on commit 12540af

Please sign in to comment.