Note that versionTimestamps are only loaded on the active node.

This commit is contained in:
Nick Cabatoff 2021-11-16 15:05:59 -05:00 committed by GitHub
parent c2d9215d1d
commit 1ec904976a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 15 deletions

View file

@ -570,9 +570,11 @@ type Core struct {
enableResponseHeaderHostname bool
enableResponseHeaderRaftNodeID bool
// VersionTimestamps is a map of vault versions to timestamps when the version
// was first run
VersionTimestamps map[string]time.Time
// versionTimestamps is a map of vault versions to timestamps when the version
// was first run. Note that because perf standbys should be upgraded first, and
// only the active node will actually write the new version timestamp, a perf
// standby shouldn't rely on the stored version timestamps being present.
versionTimestamps map[string]time.Time
}
func (c *Core) HAState() consts.HAState {
@ -1037,9 +1039,9 @@ func NewCore(conf *CoreConfig) (*Core, error) {
return nil, err
}
if c.VersionTimestamps == nil {
c.logger.Info("Initializing VersionTimestamps for core")
c.VersionTimestamps = make(map[string]time.Time)
if c.versionTimestamps == nil {
c.logger.Info("Initializing versionTimestamps for core")
c.versionTimestamps = make(map[string]time.Time)
}
return c, nil

View file

@ -55,14 +55,14 @@ func TestSealConfig_Invalid(t *testing.T) {
}
}
// TestCore_HasVaultVersion checks that VersionTimestamps are correct and initialized
// TestCore_HasVaultVersion checks that versionTimestamps are correct and initialized
// after a core has been unsealed.
func TestCore_HasVaultVersion(t *testing.T) {
c, _, _ := TestCoreUnsealed(t)
if c.VersionTimestamps == nil {
if c.versionTimestamps == nil {
t.Fatalf("Version timestamps for core were not initialized for a new core")
}
upgradeTime, ok := c.VersionTimestamps[version.Version]
upgradeTime, ok := c.versionTimestamps[version.Version]
if !ok {
t.Fatalf("%s upgrade time not found", version.Version)
}

View file

@ -43,14 +43,14 @@ func (c *Core) storeVersionTimestamp(ctx context.Context, version string, curren
// upgrade timestamp from storage. The earliest version this can be (barring
// downgrades) is 1.9.0.
func (c *Core) FindOldestVersionTimestamp() (string, time.Time, error) {
if c.VersionTimestamps == nil || len(c.VersionTimestamps) == 0 {
if c.versionTimestamps == nil || len(c.versionTimestamps) == 0 {
return "", time.Time{}, fmt.Errorf("version timestamps are not initialized")
}
// initialize oldestUpgradeTime to current time
oldestUpgradeTime := time.Now()
var oldestVersion string
for version, upgradeTime := range c.VersionTimestamps {
for version, upgradeTime := range c.versionTimestamps {
if upgradeTime.Before(oldestUpgradeTime) {
oldestVersion = version
oldestUpgradeTime = upgradeTime
@ -83,7 +83,7 @@ func (c *Core) loadVersionTimestamps(ctx context.Context) (retErr error) {
if vaultVersion.Version == "" || vaultVersion.TimestampInstalled.IsZero() {
return fmt.Errorf("found empty serialized vault version at path %s", versionPath)
}
c.VersionTimestamps[vaultVersion.Version] = vaultVersion.TimestampInstalled
c.versionTimestamps[vaultVersion.Version] = vaultVersion.TimestampInstalled
}
return nil
}

View file

@ -17,7 +17,7 @@ func TestStoreMultipleVaultVersions(t *testing.T) {
if err != nil || wasStored {
t.Fatalf("vault version was re-stored: %v, err is: %s", wasStored, err.Error())
}
upgradeTime, ok := c.VersionTimestamps[version.Version]
upgradeTime, ok := c.versionTimestamps[version.Version]
if !ok {
t.Fatalf("no %s version timestamp found", version.Version)
}
@ -35,8 +35,8 @@ func TestGetOldestVersion(t *testing.T) {
c.storeVersionTimestamp(context.Background(), "1.9.1", upgradeTimePlusEpsilon.Add(-4*time.Hour))
c.storeVersionTimestamp(context.Background(), "1.9.2", upgradeTimePlusEpsilon.Add(2*time.Hour))
c.loadVersionTimestamps(c.activeContext)
if len(c.VersionTimestamps) != 3 {
t.Fatalf("expected 3 entries in timestamps map after refresh, found: %d", len(c.VersionTimestamps))
if len(c.versionTimestamps) != 3 {
t.Fatalf("expected 3 entries in timestamps map after refresh, found: %d", len(c.versionTimestamps))
}
v, tm, err := c.FindOldestVersionTimestamp()
if err != nil {