From 92839e79a3aee4fd187396d74a300ee06cc41a60 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 11 Sep 2024 16:11:42 +0800 Subject: [PATCH] Problem: don't support dependency pre-analysis (#13) * Problem: don't support dependency pre-analysis Solution: - add api to support caller providing custom dependencies estimation in advance. * public type * fix * fix build * use MultiLocations * fix build * revert dependents changes * cleanup --- mvmemory.go | 18 +++++++++++++++++- stm.go | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mvmemory.go b/mvmemory.go index 990d9b1..600315d 100644 --- a/mvmemory.go +++ b/mvmemory.go @@ -25,12 +25,20 @@ type MVMemory struct { func NewMVMemory( block_size int, stores map[storetypes.StoreKey]int, storage MultiStore, scheduler *Scheduler, +) *MVMemory { + return NewMVMemoryWithEstimates(block_size, stores, storage, scheduler, nil) +} + +func NewMVMemoryWithEstimates( + block_size int, stores map[storetypes.StoreKey]int, + storage MultiStore, scheduler *Scheduler, estimates map[int]MultiLocations, ) *MVMemory { data := make([]MVStore, len(stores)) for key, i := range stores { data[i] = NewMVStore(key) } - return &MVMemory{ + + mv := &MVMemory{ storage: storage, scheduler: scheduler, stores: stores, @@ -38,6 +46,14 @@ func NewMVMemory( lastWrittenLocations: make([]atomic.Pointer[MultiLocations], block_size), lastReadSet: make([]atomic.Pointer[MultiReadSet], block_size), } + + // init with pre-estimates + for txn, est := range estimates { + mv.rcuUpdateWrittenLocations(TxnIndex(txn), est) + mv.ConvertWritesToEstimates(TxnIndex(txn)) + } + + return mv } func (mv *MVMemory) Record(version TxnVersion, view *MultiMVMemoryView) bool { diff --git a/stm.go b/stm.go index e40fb48..faa9424 100644 --- a/stm.go +++ b/stm.go @@ -17,6 +17,21 @@ func ExecuteBlock( storage MultiStore, executors int, txExecutor TxExecutor, +) error { + return ExecuteBlockWithEstimates( + ctx, blockSize, stores, storage, executors, + nil, txExecutor, + ) +} + +func ExecuteBlockWithEstimates( + ctx context.Context, + blockSize int, + stores map[storetypes.StoreKey]int, + storage MultiStore, + executors int, + estimates map[int]MultiLocations, // txn -> multi-locations + txExecutor TxExecutor, ) error { if executors < 0 { return fmt.Errorf("invalid number of executors: %d", executors) @@ -27,7 +42,7 @@ func ExecuteBlock( // Create a new scheduler scheduler := NewScheduler(blockSize) - mvMemory := NewMVMemory(blockSize, stores, storage, scheduler) + mvMemory := NewMVMemoryWithEstimates(blockSize, stores, storage, scheduler, estimates) var wg sync.WaitGroup wg.Add(executors)