Skip to content

Commit

Permalink
TestKeyDuplicateSkipListPrallelTxnStrideInteger passed (serial, no ra…
Browse files Browse the repository at this point in the history
…nge scan).
  • Loading branch information
ryogrid committed Sep 1, 2024
1 parent 43121c6 commit 781e881
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
9 changes: 8 additions & 1 deletion lib/container/btree/parent_bufmgr_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,31 @@ import (

type ParentBufMgrImpl struct {
*buffer.BufferPoolManager
allocedPageNum int32
}

func NewParentBufMgrImpl(bpm *buffer.BufferPoolManager) interfaces.ParentBufMgr {
return &ParentBufMgrImpl{bpm}
return &ParentBufMgrImpl{bpm, 0}
}

func (p *ParentBufMgrImpl) FetchPPage(pageID int32) interfaces.ParentPage {
fmt.Println("ParentBufMgrImpl:FetchPPage pageID:", pageID)
p.allocedPageNum++
fmt.Println("ParentBufMgrImpl:FetchPPage allocedPageNum:", p.allocedPageNum)
return &ParentPageImpl{p.FetchPage(types.PageID(pageID))}
}

func (p *ParentBufMgrImpl) UnpinPPage(pageID int32, isDirty bool) error {
fmt.Println("ParentBufMgrImpl:UnpinPPage pageID:", pageID, "isDirty:", isDirty)
p.allocedPageNum--
fmt.Println("ParentBufMgrImpl:UnpinPPage allocedPageNum:", p.allocedPageNum)
return p.UnpinPage(types.PageID(pageID), isDirty)
}

func (p *ParentBufMgrImpl) NewPPage() interfaces.ParentPage {
//fmt.Println("ParentBufMgrImpl:NewPPage")
p.allocedPageNum++
fmt.Println("ParentBufMgrImpl:NewPPage allocedPageNum:", p.allocedPageNum)
return &ParentPageImpl{p.NewPage()}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,15 +768,15 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
//if jj == 22 {
// fmt.Println("insKeyVal: 779212422?")
//}
//// insert two same record
// insert two same record
executePlan(c, shi.GetBufferPoolManager(), txn_, insPlan)
if txn_.GetState() == access.ABORTED {
break
}
executePlan(c, shi.GetBufferPoolManager(), txn_, insPlan)
if txn_.GetState() == access.ABORTED {
break
}
//executePlan(c, shi.GetBufferPoolManager(), txn_, insPlan)
//if txn_.GetState() == access.ABORTED {
// break
//}
//fmt.Printf("sl.Insert at insertRandom: jj=%d, insKeyValBase=%d len(*insVals)=%d\n", jj, insKeyValBase, len(insVals))
}

Expand Down Expand Up @@ -864,8 +864,8 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
//if jj == 22 {
// fmt.Println("delKeyVal: 779212422")
//}
//results := executePlan(c, shi.GetBufferPoolManager(), txn_, delPlan)
executePlan(c, shi.GetBufferPoolManager(), txn_, delPlan)
results := executePlan(c, shi.GetBufferPoolManager(), txn_, delPlan)
//executePlan(c, shi.GetBufferPoolManager(), txn_, delPlan)

if txn_.GetState() == access.ABORTED {
break
Expand All @@ -874,7 +874,7 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
//if results == nil || len(results) != 1 {
// fmt.Println("results is nil or len(results) != 1")
//}
//common.SH_Assert(results != nil && len(results) == 2, "Delete(success) failed!")
common.SH_Assert(results != nil && len(results) == 2, "Delete(success) failed!")
//common.SH_Assert(results != nil && len(results) == 1, "Delete(success) failed!")
}

Expand Down Expand Up @@ -929,8 +929,8 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
common.ShPrintf(common.DEBUGGING, "Update (random) op start.")

updatePlan1 := createAccountIdUpdatePlanNode(updateKeyVal, updateNewKeyVal, c, tableMetadata, keyType, indexKind)
//results1 := executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan1)
executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan1)
results1 := executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan1)
//executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan1)

if txn_.GetState() == access.ABORTED {
break
Expand All @@ -939,19 +939,19 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
//if results1 == nil || len(results1) != 2 {
// fmt.Println("results1 is nil or len(results1) != 2")
//}
//common.SH_Assert(results1 != nil && len(results1) == 2, "Update failed!")
common.SH_Assert(results1 != nil && len(results1) == 2, "Update failed!")
//common.SH_Assert(results1 != nil && len(results1) == 1, "Update failed!")

updatePlan2 := createBalanceUpdatePlanNode(updateNewKeyVal, newBalanceVal, c, tableMetadata, keyType, indexKind)

//results2 := executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan2)
executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan2)
results2 := executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan2)
//executePlan(c, shi.GetBufferPoolManager(), txn_, updatePlan2)

if txn_.GetState() == access.ABORTED {
break
}

//common.SH_Assert(results2 != nil && len(results2) == 2, "Update failed!")
common.SH_Assert(results2 != nil && len(results2) == 2, "Update failed!")
//common.SH_Assert(results2 != nil && len(results2) == 1, "Update failed!")
}

Expand Down Expand Up @@ -1026,8 +1026,8 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t

common.ShPrintf(common.DEBUGGING, "Select(success) op start.")
selectPlan := createSpecifiedPointScanPlanNode(getKeyVal, c, tableMetadata, keyType, indexKind)
//results := executePlan(c, shi.GetBufferPoolManager(), txn_, selectPlan)
executePlan(c, shi.GetBufferPoolManager(), txn_, selectPlan)
results := executePlan(c, shi.GetBufferPoolManager(), txn_, selectPlan)
//executePlan(c, shi.GetBufferPoolManager(), txn_, selectPlan)

if txn_.GetState() == access.ABORTED {
break
Expand All @@ -1036,7 +1036,7 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
//if results == nil || len(results) != 2 {
// fmt.Println("results is nil or len(results) != 2")
//}
//common.SH_Assert(results != nil && len(results) == 2, "Select(success) should not be fail!")
common.SH_Assert(results != nil && len(results) == 2, "Select(success) should not be fail!")
//common.SH_Assert(results != nil && len(results) == 1, "Select(success) should not be fail!")
//collectVal := types.NewInteger(getInt32ValCorrespondToPassVal(getKeyVal))
//gotVal := results[0].GetValue(tableMetadata.Schema(), 1)
Expand Down Expand Up @@ -1159,8 +1159,8 @@ func InnerTestParallelTxnsQueryingIndexUsedColumns[T int32 | float32 | string](t
txn_.MakeNotAbortable()

// check record num (index of col1 is used)
//collectNum := stride*(int32(len(insVals)*2)+initialEntryNum) + ACCOUNT_NUM
collectNum := stride*int32(len(insVals)) + initialEntryNum + ACCOUNT_NUM
collectNum := stride*(int32(len(insVals)*2)+initialEntryNum) + ACCOUNT_NUM
//collectNum := stride*int32(len(insVals)) + initialEntryNum + ACCOUNT_NUM

rangeScanPlan1 := createSpecifiedRangeScanPlanNode[T](c, tableMetadata, keyType, 0, nil, nil, indexKind)
results1 := executePlan(c, shi.GetBufferPoolManager(), txn_, rangeScanPlan1)
Expand Down
7 changes: 6 additions & 1 deletion lib/storage/index/btree_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func NewBtreeIndexIterator(itr *blink_tree.BLTreeItr, valType types.TypeID) *Btr

func (btreeItr *BtreeIndexIterator) Next() (done bool, err error, key *types.Value, rid *page.RID) {
ok, keyBytes, packedRID := btreeItr.itr.Next()
if ok == false || len(packedRID) != 8 {
if len(packedRID) != 6 {
return true, nil, nil, &page.RID{-1, 0}
}
// packedRID is 6 bytes. so append 2 bytes of 0 to make it 8 bytes
packedRID = []byte{packedRID[0], packedRID[1], packedRID[2], packedRID[3], 0, 0, packedRID[4], packedRID[5]}
if ok == false {
return true, nil, nil, &page.RID{-1, 0}
}
uintRID := binary.BigEndian.Uint64(packedRID)
Expand Down
10 changes: 5 additions & 5 deletions lib/storage/index/index_test/btree_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestBTreeIndexKeyDuplicateInsertDeleteStrideSerialInt(t *testing.T) {
r := rand.New(rand.NewSource(int64(seed)))

//shi := samehada.NewSamehadaInstance(t.Name(), 500)
shi := samehada.NewSamehadaInstance(t.Name(), 1000)
shi := samehada.NewSamehadaInstance(t.Name(), 4000)

shi.GetLogManager().ActivateLogging()
testingpkg.Assert(t, shi.GetLogManager().IsEnabledLogging(), "")
Expand Down Expand Up @@ -244,10 +244,10 @@ func TestBTreeIndexKeyDuplicateInsertDeleteStrideSerialInt(t *testing.T) {
testingpkg.Assert(t, len(result1) == 0, "deleted key point scan got illegal results. (1)")

// index2
//tuple2 := tuple.NewTupleFromSchema([]types.Value{types.NewValue(int32(idx*stride + jj)), types.NewValue(int32(idx*stride + jj))}, schema_)
//result2 := indexTest2.ScanKey(tuple2, nil)
//indexTest2.ScanKey(tuple2, nil)
//testingpkg.Assert(t, len(result2) == 3, fmt.Sprintf("duplicated key point scan got illegal results.(2) idx: %d, jj: %d len(result1): %d", idx, jj, len(result2)))
tuple2 := tuple.NewTupleFromSchema([]types.Value{types.NewValue(int32(idx*stride + jj)), types.NewValue(int32(idx*stride + jj))}, schema_)
result2 := indexTest2.ScanKey(tuple2, nil)
indexTest2.ScanKey(tuple2, nil)
testingpkg.Assert(t, len(result2) == 3, fmt.Sprintf("duplicated key point scan got illegal results.(2) idx: %d, jj: %d len(result1): %d", idx, jj, len(result2)))
//testingpkg.Assert(t, len(result2) != 0, fmt.Sprintf("duplicated key point scan got illegal results.(2) idx: %d, jj: %d len(result1): %d", idx, jj, len(result2)))
//for _, res := range result2 {
// indexTest2.DeleteEntry(tuple2, res, nil)
Expand Down

0 comments on commit 781e881

Please sign in to comment.