func()

in tx.go [733:766]


func (tx *Tx) rollbackChanges() {
	tracef("rollback changes in transaction: %p\n", tx)
	tx.onRollback()

	tx.file.allocator.Rollback(&tx.alloc)

	maxPages := tx.file.allocator.maxPages
	if maxPages == 0 {
		return
	}

	// compute endmarker from before running the last transaction
	endMarker := tx.file.allocator.meta.endMarker
	if dataEnd := tx.file.allocator.data.endMarker; dataEnd > endMarker {
		endMarker = dataEnd
	}

	sz, err := tx.file.file.Size()
	if err != nil {
		// getting file size failed. State is valid, but we can not truncate
		// ¯\_(ツ)_/¯
		return
	}

	truncateSz := uint(endMarker) * tx.file.allocator.pageSize
	if uint(sz) > uint(truncateSz) {
		// ignore truncate error, as truncating a memory mapped file might not be
		// supported by all OSes/filesystems.
		err := tx.file.file.Truncate(int64(truncateSz))
		if err != nil {
			traceln("rollback file truncate failed with:", err)
		}
	}
}