-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (clientcache): use a persistent cache (#5051)
By default, we will use a persistent cache for the client cache. This will allow us to keep the cache across restarts of the server and it will also reduce the amount of time it takes to start the server while reducing the amount of memory used. This change also includes a validation of the cache schema version. If the schema version is different from the one expected, the cache will be reset/recreated.
- Loading branch information
Showing
12 changed files
with
289 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package db | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOpen(t *testing.T) { | ||
ctx := context.Background() | ||
t.Run("success-file-url-with-reopening", func(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
db, err := Open(ctx, WithUrl(tmpDir+"/test.db"+fkPragma)) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
assert.FileExists(t, tmpDir+"/test.db") | ||
|
||
info, err := os.Stat(tmpDir + "/test.db") | ||
require.NoError(t, err) | ||
origCreatedAt := info.ModTime() | ||
|
||
// Reopen the db and make sure the file is not recreated | ||
db, err = Open(ctx, WithUrl(tmpDir+"/test.db"+fkPragma)) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
info, err = os.Stat(tmpDir + "/test.db") | ||
require.NoError(t, err) | ||
assert.Equal(t, origCreatedAt, info.ModTime()) | ||
}) | ||
t.Run("success-mem-default-url", func(t *testing.T) { | ||
db, err := Open(ctx) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
}) | ||
t.Run("recreate-on-version-mismatch", func(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
db, err := Open(ctx, WithUrl(tmpDir+"/test.db"+fkPragma)) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
assert.FileExists(t, tmpDir+"/test.db") | ||
info, err := os.Stat(tmpDir + "/test.db") | ||
require.NoError(t, err) | ||
origCreatedAt := info.ModTime() | ||
|
||
// Reopen the db with a different schema version: forcing the db to be recreated | ||
db, err = Open(ctx, WithUrl(tmpDir+"/test.db"+fkPragma), withTestValidSchemaVersion("2")) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
info, err = os.Stat(tmpDir + "/test.db") | ||
require.NoError(t, err) | ||
// The file should have been recreated with a new timestamp | ||
assert.NotEqual(t, origCreatedAt, info.ModTime()) | ||
}) | ||
} | ||
|
||
const ( | ||
dotDirname = ".boundary" | ||
dbFileName = "cache.db" | ||
fkPragma = "?_pragma=foreign_keys(1)" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.