sessions: copies an older magpie left are swept when a live store is read in place (#1988)
1dc20e73f reads a live Cursor's state.vscdb in place, but the sweep of
magpie-cursor-* folders older than an hour ran only when a copy was
made. A user upgrading from a version that copied keeps whatever it
left (Echo-Huang0010 had ~7.1 GiB of such copies) for as long as Cursor
runs. openCursorEditorStore now runs the same once-per-process sweep
first.
Run at this head:
- mote: go vet ./internal/sessions for darwin, linux, windows ok;
go test -count=3 -run Cursor ./internal/sessions ok.
- xiaomi-gpu (win-run): go test -count=3 -run Cursor ./internal/sessions ok.
- Broken by hand: sweep line removed, TestCursorEditorReadInPlaceWhileLive
fails with magpie-cursor-left still in the temp folder.
This commit is contained in:
@@ -54,6 +54,8 @@ func openCursorEditorDB(path string) *sql.DB {
|
||||
// live -wal there is no Cursor running to share it with, and it is opened
|
||||
// as a chat's store is (openCursorStore).
|
||||
func openCursorEditorStore(path string) (*sql.DB, func(), error) {
|
||||
// copies an older magpie left, which no copy made here would sweep
|
||||
cursorSnaps.sweep.Do(sweepCursorSnaps)
|
||||
wal, werr := os.Stat(path + "-wal")
|
||||
_, serr := os.Stat(path + "-shm")
|
||||
if !cursorReadInPlace || werr != nil || wal.Size() == 0 || serr != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -155,7 +156,8 @@ func TestCursorEditorCopiedOncePerChange(t *testing.T) {
|
||||
// copied a ~10.6 GB state.vscdb to the temp folder each time Cursor had
|
||||
// written since the last copy. The store is read where it is, as one more
|
||||
// of the readers Cursor's own processes are: nothing is copied, a row
|
||||
// Cursor writes is read at once, and Cursor can still write after it.
|
||||
// Cursor writes is read at once, and Cursor can still write after it. A
|
||||
// copy an older magpie left is still swept.
|
||||
func TestCursorEditorReadInPlaceWhileLive(t *testing.T) {
|
||||
cursorSetup(t)
|
||||
cursorTempDir(t)
|
||||
@@ -163,6 +165,17 @@ func TestCursorEditorReadInPlaceWhileLive(t *testing.T) {
|
||||
cursorSnapMin = 0
|
||||
t.Cleanup(func() { cursorSnapMin = minWas })
|
||||
|
||||
// a copy an older magpie left, from before reads were in place
|
||||
left := filepath.Join(os.TempDir(), "magpie-cursor-left")
|
||||
if err := os.MkdirAll(left, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := time.Now().Add(-2 * cursorSnapStale)
|
||||
if err := os.Chtimes(left, old, old); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cursorSnaps.sweep = sync.Once{}
|
||||
|
||||
put, ids, at := cursorLiveEditor(t)
|
||||
copies, inPlace := cursorCopies.Load(), cursorInPlace.Load()
|
||||
for round := range 3 {
|
||||
|
||||
Reference in New Issue
Block a user