Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Apr 22, 2024
1 parent f25966b commit 4d8fef9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/causality/conflict_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
// have their original orders preserved. Transactions in different
// channels can be executed concurrently.
type ConflictDetector[Txn txnEvent] struct {
// resovedTxnCaches are used to cache resolved transactions.
resovedTxnCaches []txnCache[Txn]
// resolvedTxnCaches are used to cache resolved transactions.
resolvedTxnCaches []txnCache[Txn]

// slots are used to find all unfinished transactions
// conflicting with an incoming transactions.
Expand All @@ -52,15 +52,15 @@ func NewConflictDetector[Txn txnEvent](
numSlots uint64, opt TxnCacheOption,
) *ConflictDetector[Txn] {
ret := &ConflictDetector[Txn]{
resovedTxnCaches: make([]txnCache[Txn], opt.Count),
slots: internal.NewSlots[*internal.Node](numSlots),
numSlots: numSlots,
notifiedNodes: chann.NewAutoDrainChann[func()](),
garbageNodes: chann.NewAutoDrainChann[*internal.Node](),
closeCh: make(chan struct{}),
resolvedTxnCaches: make([]txnCache[Txn], opt.Count),
slots: internal.NewSlots[*internal.Node](numSlots),
numSlots: numSlots,
notifiedNodes: chann.NewAutoDrainChann[func()](),
garbageNodes: chann.NewAutoDrainChann[*internal.Node](),
closeCh: make(chan struct{}),
}
for i := 0; i < opt.Count; i++ {
ret.resovedTxnCaches[i] = newTxnCache[Txn](opt)
ret.resolvedTxnCaches[i] = newTxnCache[Txn](opt)

Check warning on line 63 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L53-L63

Added lines #L53 - L63 were not covered by tests
}

ret.wg.Add(1)
Expand Down Expand Up @@ -96,7 +96,7 @@ func (d *ConflictDetector[Txn]) Add(txn Txn) {
// Try sending this txn to related cache as soon as all dependencies are resolved.
return d.sendToCache(txnWithNotifier, cacheID)

Check warning on line 97 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L95-L97

Added lines #L95 - L97 were not covered by tests
}
node.RandCacheID = func() int64 { return d.nextWorkerID.Add(1) % int64(len(d.resovedTxnCaches)) }
node.RandCacheID = func() int64 { return d.nextWorkerID.Add(1) % int64(len(d.resolvedTxnCaches)) }

Check warning on line 99 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L99

Added line #L99 was not covered by tests
node.OnNotified = func(callback func()) { d.notifiedNodes.In() <- callback }
d.slots.Add(node)

Check warning on line 101 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L101

Added line #L101 was not covered by tests
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (d *ConflictDetector[Txn]) sendToCache(txn TxnWithNotifier[Txn], id int64)
// Note OnConflictResolved must be called before add to cache. Otherwise, there will
// be a data race since the txn may be read before the OnConflictResolved is called.
txn.TxnEvent.OnConflictResolved()
cache := d.resovedTxnCaches[id]
cache := d.resolvedTxnCaches[id]
ok := cache.add(txn)
return ok

Check warning on line 142 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L139-L142

Added lines #L139 - L142 were not covered by tests
}
Expand All @@ -148,5 +148,5 @@ func (d *ConflictDetector[Txn]) GetOutChByCacheID(id int64) <-chan TxnWithNotifi
if id < 0 {
log.Panic("must assign with a valid cacheID", zap.Int64("cacheID", id))

Check warning on line 149 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L147-L149

Added lines #L147 - L149 were not covered by tests
}
return d.resovedTxnCaches[id].out()
return d.resolvedTxnCaches[id].out()

Check warning on line 151 in pkg/causality/conflict_detector.go

View check run for this annotation

Codecov / codecov/patch

pkg/causality/conflict_detector.go#L151

Added line #L151 was not covered by tests
}

0 comments on commit 4d8fef9

Please sign in to comment.