1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-11 20:29:52 +00:00

Reset db more selectively: approach #2 (#745)

* On Reset, remove all the sqlite files, not just the main one.

* Avoid resetting the database and cache when not needed.

Avoid resetting when a change doesn't bring in new schema fields.

Always reset when a CRD is deleted.

* Force a database reset when a new CRD is added.

* Improve code readability. No functional change.
This commit is contained in:
Eric Promislow
2025-07-31 10:43:55 -07:00
committed by GitHub
parent e92b9cf7ea
commit 5f08feeb5f
5 changed files with 188 additions and 49 deletions

View File

@@ -21,6 +21,7 @@ import (
"errors"
"github.com/rancher/steve/pkg/sqlcache/db/transaction"
"github.com/sirupsen/logrus"
// needed for drivers
_ "modernc.org/sqlite"
@@ -416,9 +417,12 @@ func (c *client) NewConnection(useTempDir bool) (string, error) {
}
}
if !useTempDir {
err := os.RemoveAll(InformerObjectCacheDBPath)
if err != nil {
return "", err
for _, suffix := range []string{"", "-shm", "-wal"} {
f := InformerObjectCacheDBPath + suffix
err := os.RemoveAll(f)
if err != nil {
logrus.Errorf("error removing existing db file %s: %v", f, err)
}
}
}