Skip to content

Commit

Permalink
Problem: don't support dependency pre-analysis (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yihuang authored Sep 11, 2024
1 parent 09a6474 commit 92839e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
18 changes: 17 additions & 1 deletion mvmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,35 @@ 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,
data: data,
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 {
Expand Down
17 changes: 16 additions & 1 deletion stm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 92839e7

Please sign in to comment.