Skip to content

Commit

Permalink
Merge #24612
Browse files Browse the repository at this point in the history
24612: workload: tpcc: fix partitioning of history table r=arjunravinarayan a=arjunravinarayan

The previous partitioning code was incorrectly ported from loadgen, as
the Cockroach UUID library doesn't work with a direct SetBytes.

The previous code panicked with the following error:

```
panic: Couldn't exec ALTER TABLE history PARTITION BY RANGE (rowid) (
  PARTITION p0 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p1 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p2 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p3 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p4 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p5 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p6 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p7 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p8 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('00000000-0000-0000-0000-000000000000'),
  PARTITION p9 VALUES FROM ('00000000-0000-0000-0000-000000000000') to ('ffffffff-ffff-ffff-ffff-ffffffffffff')
)
: pq: PARTITION p0: empty range: lower bound ('00000000-0000-0000-0000-000000000000') is equal to upper bound ('00000000-0000-0000-0000-000000000000')
```

The modified code partitions successfully.

Co-authored-by: Arjun Narayan <[email protected]>
  • Loading branch information
craig[bot] and Arjun Narayan committed Apr 9, 2018
2 parents 74c7d18 + c13aa32 commit a087abc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/workload/tpcc/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,21 @@ func partitionCustomer(db *gosql.DB, wIDs []int, partitions int) {

func partitionHistory(db *gosql.DB, wIDs []int, partitions int) {
const maxVal = math.MaxUint64
temp := make([]byte, 16)
rowids := make([]uuid.UUID, partitions+1)
for i := 0; i < partitions; i++ {
var err error

// We're splitting the UUID rowid column evenly into N partitions. The
// column is sorted lexicographically on the bytes of the UUID which means
// we should put the partitioning values at the front of the UUID.
binary.BigEndian.PutUint64(rowids[i].GetBytes()[:], uint64(i)*(maxVal/uint64(partitions)))
binary.BigEndian.PutUint64(temp, uint64(i)*(maxVal/uint64(partitions)))
rowids[i], err = uuid.FromBytes(temp)
if err != nil {
panic(err)
}
}

rowids[partitions], _ = uuid.FromString("ffffffff-ffff-ffff-ffff-ffffffffffff")

var buf bytes.Buffer
Expand Down

0 comments on commit a087abc

Please sign in to comment.