From 7ef0474abd20048230183ed01eea547ce9647588 Mon Sep 17 00:00:00 2001 From: Renato Costa Date: Mon, 8 May 2023 10:55:07 -0400 Subject: [PATCH] workload: remove initial prefix from bank workload payload 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] c1a574cc5428e116d9af5cb7d1a25da3a582a7f5 Epic: none Release note: None --- pkg/workload/bank/bank.go | 4 +--- pkg/workload/csv_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/workload/bank/bank.go b/pkg/workload/bank/bank.go index 4cee03320f58..4035e39ca2f5 100644 --- a/pkg/workload/bank/bank.go +++ b/pkg/workload/bank/bank.go @@ -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) diff --git a/pkg/workload/csv_test.go b/pkg/workload/csv_test.go index af684614fae4..db6edbcb9413 100644 --- a/pkg/workload/csv_test.go +++ b/pkg/workload/csv_test.go @@ -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`, }, } @@ -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))) }