usage: a chunk without calls is read back from requests-v1.bin without a Latest, so a new version pairs its history on one start (#2278)
diskEntry wrote a chunk's Latest as c.Latest.UnixNano(). For a chunk
without calls Latest is the zero time, whose UnixNano is out of int64's
range and is written as another time; readDiskEntry read it back as a
call on 1969-12-31. heatSplit and effortSplit count a chunk with a zero
Latest as recent, but one read back so as settled, so the settled set
after a build (14426 chunks on the real history) differed from the one
after a read (15677). The key heat-v1.json and effort-v1.json were
written under on a new version's first start missed on its second, and
the whole history was paired again: two cold peaks, not one.
A zero Latest is now written as 0 and read back as the zero time.
Old data: requests-v1.bin is rewritten under the new binary (its key
holds requestDiskBinary()), so nothing old is read by the new reader.
Run:
- TestDiskEntryKeepsNoLatest round-trips a zero Latest and
time.Unix(1790000100,5). Red on the old reader ("Latest 0001-01-01
... read back as 1969-12-31 16:00:00 -0800 PST"), green with the fix.
- Real history on mote (sandbox HOME, copy of the owner's sessions and
requests): the first start wrote heat-v1.json and effort-v1.json, the
second and third didn't rewrite them (both hit), and the heatmap's
JSON had the same md5 on all three starts.
- Rebased onto 244d80e23; at the pushed tree on mote:
go test -count=1 ./internal/usage ok (53.3s), gofmt clean,
go vet -tags nogui ./internal/usage for windows ok (linux, darwin ok
before the rebase, which touched no file of this commit).
Not tried: a full ./... suite.
This commit is contained in:
@@ -123,7 +123,15 @@ func diskEntry(b []byte, c *rowChunk) []byte {
|
||||
put(uint64(s.Size))
|
||||
put(uint64(s.Modified.UnixNano()))
|
||||
put(uint64(c.Count))
|
||||
put(uint64(c.Latest.UnixNano()))
|
||||
// a chunk without calls has no Latest: the zero time's UnixNano is
|
||||
// another time, read back as a call long ago, and such a chunk was
|
||||
// settled after a read where it wasn't after a build (heatSplit), so a
|
||||
// new version paired its whole history on two starts, not one (#2278)
|
||||
latest := int64(0)
|
||||
if !c.Latest.IsZero() {
|
||||
latest = c.Latest.UnixNano()
|
||||
}
|
||||
put(uint64(latest))
|
||||
put(uint64(len(locations)))
|
||||
for _, loc := range locations {
|
||||
name, offset := time.Unix(0, 0).In(loc).Zone()
|
||||
@@ -180,7 +188,9 @@ func readDiskEntry(b []byte) (*rowChunk, error) {
|
||||
c.Source.Size = int64(take())
|
||||
c.Source.Modified = time.Unix(0, int64(take()))
|
||||
c.Count = int(take())
|
||||
c.Latest = time.Unix(0, int64(take())).In(time.Local)
|
||||
if latest := int64(take()); latest != 0 {
|
||||
c.Latest = time.Unix(0, latest).In(time.Local)
|
||||
}
|
||||
n := take()
|
||||
if b == nil || n > uint64(len(b)) {
|
||||
return nil, errDiskEntry
|
||||
|
||||
@@ -77,3 +77,22 @@ func TestDiskEntryAllocatesOnce(t *testing.T) {
|
||||
t.Errorf("reading an entry's archive allocated %v times", n)
|
||||
}
|
||||
}
|
||||
|
||||
// A chunk without calls reads back without a Latest, as it was built: read
|
||||
// as a call long ago, it was settled after a read and not after a build,
|
||||
// and the heatmap's and effort's kept days were counted again (#2278).
|
||||
func TestDiskEntryKeepsNoLatest(t *testing.T) {
|
||||
for _, latest := range []time.Time{{}, time.Unix(1790000100, 5)} {
|
||||
chunk := &rowChunk{
|
||||
Source: sessions.CallSource{Path: "/s/rollout.jsonl", Key: "k", Agent: "codex", Size: 1, Modified: time.Unix(1790000000, 0)},
|
||||
Latest: latest, Archive: []byte{1},
|
||||
}
|
||||
got, err := readDiskEntry(diskEntry(nil, chunk))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Latest.IsZero() != latest.IsZero() || !got.Latest.Equal(latest) {
|
||||
t.Errorf("Latest %v read back as %v", latest, got.Latest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user