in tx.go [618:654]
func checkTruncate(
st *txAllocState,
sz, mmapSz, maxSz int64,
pageSize uint,
) (int64, bool) {
if maxSz <= 0 { // file is unbounded, no truncate required
return 0, false
}
expectedFileSz := mmapSz
if expectedFileSz < maxSz {
expectedFileSz = maxSz
}
if expectedFileSz >= sz {
// Required size still surpasses the last known file size -> do not
// truncate.
return 0, false
}
lastEnd := st.data.endMarker
if metaEnd := st.meta.endMarker; metaEnd > lastEnd {
lastEnd = metaEnd
}
lastExpectedFileSz := int64(uint(lastEnd) * pageSize)
if lastExpectedFileSz < maxSz {
lastExpectedFileSz = maxSz
}
// Compute minimum required file size for the last two active transactions (maximum).
if lastExpectedFileSz > expectedFileSz {
expectedFileSz = lastExpectedFileSz
}
return expectedFileSz, expectedFileSz < sz
}