GODT-2224: Allow the user to specify max sync memory usage in Vault

This commit is contained in:
Leander Beernaert
2023-01-31 09:13:41 +01:00
parent c8065c8092
commit c0aacb7d62
7 changed files with 67 additions and 9 deletions

View File

@ -178,7 +178,7 @@ func (vault *Vault) SetLastVersion(version *semver.Version) error {
})
}
// GetFirstStart sets whether this is the first time the bridge has been started.
// GetFirstStart returns whether this is the first time the bridge has been started.
func (vault *Vault) GetFirstStart() bool {
return vault.get().Settings.FirstStart
}
@ -189,3 +189,21 @@ func (vault *Vault) SetFirstStart(firstStart bool) error {
data.Settings.FirstStart = firstStart
})
}
// GetMaxSyncMemory returns the maximum amount of memory the sync process should use.
func (vault *Vault) GetMaxSyncMemory() uint64 {
v := vault.get().Settings.MaxSyncMemory
// can be zero if never written to vault before.
if v == 0 {
return DefaultMaxSyncMemory
}
return v
}
// SetMaxSyncMemory sets the maximum amount of memory the sync process should use.
func (vault *Vault) SetMaxSyncMemory(maxMemory uint64) error {
return vault.mod(func(data *Data) {
data.Settings.MaxSyncMemory = maxMemory
})
}

View File

@ -202,3 +202,11 @@ func TestVault_Settings_FirstStart(t *testing.T) {
// Check the new first start value.
require.Equal(t, false, s.GetFirstStart())
}
func TestVault_Settings_MaxSyncMemory(t *testing.T) {
// create a new test vault.
s := newVault(t)
// Check the default first start value.
require.Equal(t, vault.DefaultMaxSyncMemory, s.GetMaxSyncMemory())
}

View File

@ -42,8 +42,12 @@ type Settings struct {
LastVersion string
FirstStart bool
MaxSyncMemory uint64
}
const DefaultMaxSyncMemory = 2 * 1024 * uint64(1024*1024)
func newDefaultSettings(gluonDir string) Settings {
return Settings{
GluonDir: gluonDir,
@ -64,5 +68,7 @@ func newDefaultSettings(gluonDir string) Settings {
LastVersion: "0.0.0",
FirstStart: true,
MaxSyncMemory: DefaultMaxSyncMemory,
}
}