Add Tablet.SetTimestampAt with rowIndex validation#169
Conversation
|
Could we preserve the existing Adding an type TimestampSetter interface {
SetTimestamp(int64, int)
}
var _ TimestampSetter = (*client.Tablet)(nil)
var setter func(int64, int) = tablet.SetTimestampSince this module already has v2 releases, keeping |
Tablet.SetTimestamp writes to t.timestamps[rowIndex] without validating rowIndex, so an out-of-range row (e.g. SetTimestamp(ts, 1) on a tablet created with NewTablet(..., 1)) panics with an index-out-of-range error. Per review, SetTimestamp's signature is kept unchanged for source compatibility (it is part of a v2 public API). This adds a checked alternative, SetTimestampAt(timestamp, rowIndex) error, which validates rowIndex and returns an "illegal argument rowIndex" error, consistent with SetValueAt and GetValueAt, plus a regression test. Follow-up to apache#168. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
514b827 to
d3607ad
Compare
|
Thanks @HTHou — good point on the interface/method-value compatibility, and you're right that a v2 public API shouldn't change |
Problem
Tablet.SetTimestampwrites tot.timestamps[rowIndex]without validatingrowIndex, so an out-of-range row panics with an index-out-of-range errorinstead of returning one. For example, with a tablet created via
NewTablet(..., 1)(only row index 0 is valid),SetTimestamp(ts, 1)panics.Fix
As @HTHou noted, adding an
errorreturn toSetTimestampwould break sourcecompatibility for consumers relying on its signature (interface satisfaction,
method values), and this module already has v2 releases. So
SetTimestampisleft unchanged, and a checked alternative is added:
SetTimestampAtmirrors the bounds handling ofSetValueAt/GetValueAt,returning an
illegal argument rowIndexerror for a negative or out-of-rangerow. The PR is purely additive;
SetTimestampcan be deprecated indocumentation later if callers should migrate to the checked API.
Tests
Added
TestTablet_SetTimestampAtRowIndexBounds: a valid row index returns noerror; out-of-range indices (1 on a one-row tablet, and -1) return an error
instead of panicking.
go build ./...andgo test ./client/pass.Follow-up to #168.