Skip to content

Commit

Permalink
Support parallel constraint checking
Browse files Browse the repository at this point in the history
This puts in place support for parallel constraint checking using
go-routines.  The implementation was surprisingly straightforward, and
offers excellent improvements.
  • Loading branch information
DavePearce committed Jul 26, 2024
1 parent 00ed0b9 commit 1f1b905
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/schema/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,30 @@ func ExpandTrace(schema Schema, trace tr.Trace) error {
//
//nolint:revive
func Accepts(schema Schema, trace tr.Trace) error {
var err error
// Determine how many constraints
n := schema.Constraints().Count()
// Construct a communication channel for errors.
c := make(chan error, 100)
// Check each constraint in turn
for i := schema.Constraints(); i.HasNext(); {
// Get ith constraint
ith := i.Next()
// Check it holds (or report an error)
if err := ith.Accepts(trace); err != nil {
return err
// Launch checker for constraint
go func() {
// Send outcome back
c <- ith.Accepts(trace)
}()
}
// Read responses back from each constraint.
for i := uint(0); i < n; i++ {
// Read from channel
if e := <-c; e != nil {
err = e
}
}
// Success
return nil
return err
}

// ColumnIndexOf returns the column index of the column with the given name, or
Expand Down

0 comments on commit 1f1b905

Please sign in to comment.