Skip to content

Commit

Permalink
workload: remove initial prefix from bank workload payload
Browse files Browse the repository at this point in the history
An `initial-` prefix is added to the payload column of the `bank`
table when the workload is initialized. It was introduced about 6
years ago [1] and its purpose at the time is not clear. There are two
main problems with it:

* the `initial-` prefix suggests the payload may be updated, but that
actually never happens.
* as currently implemented, it assumes that the `payload-bytes`
command line flag is at least `len([]byte("initial-"))`. Passing a
lower value to that command line flag leads to a panic. This is an
implicit assumption that should not exist.

This changes the row generation function so that `payload-bytes` bytes
are randomly generated and inserted into the `payload` column, without
the `initial-` prefix.

[1] c1a574c

Epic: none

Release note: None
  • Loading branch information
renatolabs committed May 8, 2023
1 parent 2973e83 commit 7ef0474
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions pkg/workload/bank/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ func (b *bank) Tables() []workload.Table {
for rowIdx := rowBegin; rowIdx < rowEnd; rowIdx++ {
var payload []byte
*a, payload = a.Alloc(b.payloadBytes, 0 /* extraCap */)
const initialPrefix = `initial-`
copy(payload[:len(initialPrefix)], []byte(initialPrefix))
randStringLetters(rng, payload[len(initialPrefix):])
randStringLetters(rng, payload)

rowOffset := rowIdx - rowBegin
idCol[rowOffset] = int64(rowIdx)
Expand Down
10 changes: 5 additions & 5 deletions pkg/workload/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func TestHandleCSV(t *testing.T) {
}{
{
`?rows=1`, `
0,0,initial-dTqnRurXztAPkykhZWvsCmeJkMwRNcJAvTlNbgUEYfagEQJaHmfPsquKZUBOGwpAjPtATpGXFJkrtQCEJODSlmQctvyh`,
0,0,dTqnRurXztAPkykhZWvsCmeJkMwRNcJAvTlNbgUEYfagEQJaHmfPsquKZUBOGwpAjPtATpGXFJkrtQCEJODSlmQctvyhWevfEafP`,
},
{
`?rows=5&row-start=1&row-end=3&batch-size=1`, `
1,0,initial-vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZT
2,0,initial-qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZz`,
1,0,vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZTLdqDkrhj
2,0,qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZzvGuJkQXu`,
},
}

Expand Down Expand Up @@ -123,8 +123,8 @@ func TestCSVRowsReader(t *testing.T) {
b, err := io.ReadAll(r)
require.NoError(t, err)
expected := `
1,0,initial-vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZT
2,0,initial-qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZz
1,0,vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZTLdqDkrhj
2,0,qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZzvGuJkQXu
`
require.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(b)))
}
Expand Down

0 comments on commit 7ef0474

Please sign in to comment.