Skip to content

Commit

Permalink
enhance: support deallocated page reuse even if reuse occurs after re…
Browse files Browse the repository at this point in the history
…launch

support deallocated page reuse after relaunch: WIP.

support deallocated page reuse after relaunch: almost main parts are implemented. but several tests fail. (several logging needed points are not implemented yet but these should not make tests failed)

support deallocated page reuse after relaunch: existing testcases passed (several logging needed points are not implemented yet and modification specific testcases does not exist)

support deallocated page reuse after relaunch: implements for persistence are all finished. adding a testcase for the support is not done yet.

support deallocated page reuse after relaunch: implemented tesscases of the support and these passed.
  • Loading branch information
ryogrid committed Jun 23, 2024
1 parent 7b8dad0 commit e2a897a
Show file tree
Hide file tree
Showing 20 changed files with 564 additions and 85 deletions.
6 changes: 4 additions & 2 deletions lib/catalog/table_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func RecoveryCatalogFromCatalogPage(bpm *buffer.BufferPoolManager, log_manager *
schema.NewSchema(columns),
name,
access.InitTableHeap(bpm, types.PageID(firstPage), log_manager, lock_manager),
uint32(oid))
uint32(oid),
log_manager,
)

tableIds[uint32(oid)] = tableMetadata
tableNames[name] = tableMetadata
Expand Down Expand Up @@ -169,7 +171,7 @@ func (c *Catalog) CreateTable(name string, schema_ *schema.Schema, txn *access.T
// attach table name as prefix to all columns name
attachTableNameToColumnsName(schema_, name_)

tableMetadata := NewTableMetadata(schema_, name_, tableHeap, oid)
tableMetadata := NewTableMetadata(schema_, name_, tableHeap, oid, c.Log_manager)

c.tableIdsMutex.Lock()
c.tableIds[oid] = tableMetadata
Expand Down
5 changes: 3 additions & 2 deletions lib/catalog/table_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package catalog

import (
"github.com/ryogrid/SamehadaDB/lib/common"
"github.com/ryogrid/SamehadaDB/lib/recovery"
"github.com/ryogrid/SamehadaDB/lib/storage/access"
"github.com/ryogrid/SamehadaDB/lib/storage/index"
"github.com/ryogrid/SamehadaDB/lib/storage/index/index_constants"
Expand All @@ -23,7 +24,7 @@ type TableMetadata struct {
oid uint32
}

func NewTableMetadata(schema *schema.Schema, name string, table *access.TableHeap, oid uint32) *TableMetadata {
func NewTableMetadata(schema *schema.Schema, name string, table *access.TableHeap, oid uint32, log_manager *recovery.LogManager) *TableMetadata {
ret := new(TableMetadata)
ret.schema = schema
ret.name = name
Expand Down Expand Up @@ -58,7 +59,7 @@ func NewTableMetadata(schema *schema.Schema, name string, table *access.TableHea
// currently, SkipList Index always use new pages even if relaunch
im := index.NewIndexMetadata(column_.GetColumnName()+"_index", name, schema, []uint32{uint32(idx)})
// TODO: (SDB) need to add index headae ID argument like HashIndex (NewTableMetadata)
slIdx := index.NewSkipListIndex(im, table.GetBufferPoolManager(), uint32(idx))
slIdx := index.NewSkipListIndex(im, table.GetBufferPoolManager(), uint32(idx), log_manager)

indexes = append(indexes, slIdx)
//column_.SetIndexHeaderPageId(slIdx.GetHeaderPageId())
Expand Down
12 changes: 7 additions & 5 deletions lib/container/skip_list/skip_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package skip_list
import (
"fmt"
"github.com/ryogrid/SamehadaDB/lib/common"
"github.com/ryogrid/SamehadaDB/lib/recovery"
"github.com/ryogrid/SamehadaDB/lib/storage/buffer"
"github.com/ryogrid/SamehadaDB/lib/storage/page/skip_list_page"
"github.com/ryogrid/SamehadaDB/lib/types"
Expand Down Expand Up @@ -35,14 +36,16 @@ type SkipList struct {
SentinelNodeID types.PageID
bpm *buffer.BufferPoolManager
headerPageLatch common.ReaderWriterLatch
log_manager *recovery.LogManager
}

func NewSkipList(bpm *buffer.BufferPoolManager, keyType types.TypeID) *SkipList {
func NewSkipList(bpm *buffer.BufferPoolManager, keyType types.TypeID, log_manager *recovery.LogManager) *SkipList {
ret := new(SkipList)
ret.bpm = bpm
var sentinelNode *skip_list_page.SkipListBlockPage
ret.headerPage, ret.startNode, sentinelNode = skip_list_page.NewSkipListHeaderPage(bpm, keyType)
ret.SentinelNodeID = sentinelNode.GetPageId()
ret.log_manager = log_manager

return ret
}
Expand Down Expand Up @@ -292,15 +295,14 @@ func (sl *SkipList) Remove(key *types.Value, value uint64) (isDeleted_ bool) {
continue
}

pageId := node.GetPageId()

// locking is not needed because already have lock with FindNode method call
isNodeShouldBeDeleted, isDeleted, isNeedRetry = node.Remove(sl.bpm, key, predOfCorners, corners)
// lock and pin which is got FindNode are released on Remove method

if isNodeShouldBeDeleted {
// page's isDeleted is set in Remove method
// then node is deallocated in BPM and do nothing here

//sl.bpm.DeallocatePage(pageId)
sl.bpm.DeallocatePage(pageId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func genInitialSLAndWorkArr(dbName string) (*skip_list.SkipList, *workArray) {
shi := samehada.NewSamehadaInstance(dbName, 4000) //cover 100% of filled data
bpm := shi.GetBufferPoolManager()

sl := skip_list.NewSkipList(bpm, types.Integer)
sl := skip_list.NewSkipList(bpm, types.Integer, nil)
wArray := NewWorkArray()

// insert initial values and fill work array
Expand Down
16 changes: 8 additions & 8 deletions lib/container/skip_list/skip_list_test/skip_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func testSkipListMix[T int32 | float32 | string](t *testing.T, keyType types.Typ

checkDupMap := make(map[T]T)

sl := skip_list.NewSkipList(bpm, keyType)
sl := skip_list.NewSkipList(bpm, keyType, nil)

// override global rand seed (seed has been set on NewSkipList)
rand.Seed(3)
Expand Down Expand Up @@ -735,7 +735,7 @@ func testSkipListMixParallel[T int32 | float32 | string](t *testing.T, keyType t
shi := samehada.NewSamehadaInstance(t.Name(), common.BufferPoolMaxFrameNumForTest)

bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, keyType)
sl := skip_list.NewSkipList(bpm, keyType, nil)

checkDupMap := make(map[T]T)

Expand Down Expand Up @@ -919,7 +919,7 @@ func testSkipListMixParallelBulk[T int32 | float32 | string](t *testing.T, keyTy

shi := samehada.NewSamehadaInstance(t.Name(), common.BufferPoolMaxFrameNumForTest)
bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, keyType)
sl := skip_list.NewSkipList(bpm, keyType, nil)

checkDupMap := make(map[T]T)

Expand Down Expand Up @@ -1114,7 +1114,7 @@ func testSkipListMixParallelStride[T int32 | float32 | string](t *testing.T, key

shi := samehada.NewSamehadaInstance(t.Name(), int(bpoolSize))
bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, keyType)
sl := skip_list.NewSkipList(bpm, keyType, nil)

checkDupMap := make(map[T]T)

Expand Down Expand Up @@ -1333,7 +1333,7 @@ func testSkipListMixParallelStrideAddedIterator[T int32 | float32 | string](t *t
shi := samehada.NewSamehadaInstance(t.Name(), int(bpoolSize))

bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, keyType)
sl := skip_list.NewSkipList(bpm, keyType, nil)

checkDupMap := make(map[T]T)

Expand Down Expand Up @@ -1934,7 +1934,7 @@ func TestSkipListParallelSimpleInteger(t *testing.T) {

shi := samehada.NewSamehadaInstance(t.Name(), 30)
bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, types.Integer)
sl := skip_list.NewSkipList(bpm, types.Integer, nil)

ch1 := make(chan string)
ch2 := make(chan string)
Expand Down Expand Up @@ -1964,7 +1964,7 @@ func TestSkipListParallelSimpleInteger2(t *testing.T) {

shi := samehada.NewSamehadaInstance(t.Name(), 30)
bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, types.Integer)
sl := skip_list.NewSkipList(bpm, types.Integer, nil)

ch1 := make(chan string)
ch2 := make(chan string)
Expand Down Expand Up @@ -1995,7 +1995,7 @@ func TestSkipListParallelSimpleInteger3Stride(t *testing.T) {

shi := samehada.NewSamehadaInstance(t.Name(), 20)
bpm := shi.GetBufferPoolManager()
sl := skip_list.NewSkipList(bpm, types.Integer)
sl := skip_list.NewSkipList(bpm, types.Integer, nil)

ch1 := make(chan string)
ch2 := make(chan string)
Expand Down
Loading

0 comments on commit e2a897a

Please sign in to comment.