Note that versionTimestamps are only loaded on the active node.
This commit is contained in:
parent
c2d9215d1d
commit
1ec904976a
|
@ -570,9 +570,11 @@ type Core struct {
|
||||||
enableResponseHeaderHostname bool
|
enableResponseHeaderHostname bool
|
||||||
enableResponseHeaderRaftNodeID bool
|
enableResponseHeaderRaftNodeID bool
|
||||||
|
|
||||||
// VersionTimestamps is a map of vault versions to timestamps when the version
|
// versionTimestamps is a map of vault versions to timestamps when the version
|
||||||
// was first run
|
// was first run. Note that because perf standbys should be upgraded first, and
|
||||||
VersionTimestamps map[string]time.Time
|
// 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 {
|
func (c *Core) HAState() consts.HAState {
|
||||||
|
@ -1037,9 +1039,9 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.VersionTimestamps == nil {
|
if c.versionTimestamps == nil {
|
||||||
c.logger.Info("Initializing VersionTimestamps for core")
|
c.logger.Info("Initializing versionTimestamps for core")
|
||||||
c.VersionTimestamps = make(map[string]time.Time)
|
c.versionTimestamps = make(map[string]time.Time)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|
|
@ -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.
|
// after a core has been unsealed.
|
||||||
func TestCore_HasVaultVersion(t *testing.T) {
|
func TestCore_HasVaultVersion(t *testing.T) {
|
||||||
c, _, _ := TestCoreUnsealed(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")
|
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 {
|
if !ok {
|
||||||
t.Fatalf("%s upgrade time not found", version.Version)
|
t.Fatalf("%s upgrade time not found", version.Version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// upgrade timestamp from storage. The earliest version this can be (barring
|
||||||
// downgrades) is 1.9.0.
|
// downgrades) is 1.9.0.
|
||||||
func (c *Core) FindOldestVersionTimestamp() (string, time.Time, error) {
|
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")
|
return "", time.Time{}, fmt.Errorf("version timestamps are not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize oldestUpgradeTime to current time
|
// initialize oldestUpgradeTime to current time
|
||||||
oldestUpgradeTime := time.Now()
|
oldestUpgradeTime := time.Now()
|
||||||
var oldestVersion string
|
var oldestVersion string
|
||||||
for version, upgradeTime := range c.VersionTimestamps {
|
for version, upgradeTime := range c.versionTimestamps {
|
||||||
if upgradeTime.Before(oldestUpgradeTime) {
|
if upgradeTime.Before(oldestUpgradeTime) {
|
||||||
oldestVersion = version
|
oldestVersion = version
|
||||||
oldestUpgradeTime = upgradeTime
|
oldestUpgradeTime = upgradeTime
|
||||||
|
@ -83,7 +83,7 @@ func (c *Core) loadVersionTimestamps(ctx context.Context) (retErr error) {
|
||||||
if vaultVersion.Version == "" || vaultVersion.TimestampInstalled.IsZero() {
|
if vaultVersion.Version == "" || vaultVersion.TimestampInstalled.IsZero() {
|
||||||
return fmt.Errorf("found empty serialized vault version at path %s", versionPath)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestStoreMultipleVaultVersions(t *testing.T) {
|
||||||
if err != nil || wasStored {
|
if err != nil || wasStored {
|
||||||
t.Fatalf("vault version was re-stored: %v, err is: %s", wasStored, err.Error())
|
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 {
|
if !ok {
|
||||||
t.Fatalf("no %s version timestamp found", version.Version)
|
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.1", upgradeTimePlusEpsilon.Add(-4*time.Hour))
|
||||||
c.storeVersionTimestamp(context.Background(), "1.9.2", upgradeTimePlusEpsilon.Add(2*time.Hour))
|
c.storeVersionTimestamp(context.Background(), "1.9.2", upgradeTimePlusEpsilon.Add(2*time.Hour))
|
||||||
c.loadVersionTimestamps(c.activeContext)
|
c.loadVersionTimestamps(c.activeContext)
|
||||||
if len(c.VersionTimestamps) != 3 {
|
if len(c.versionTimestamps) != 3 {
|
||||||
t.Fatalf("expected 3 entries in timestamps map after refresh, found: %d", len(c.VersionTimestamps))
|
t.Fatalf("expected 3 entries in timestamps map after refresh, found: %d", len(c.versionTimestamps))
|
||||||
}
|
}
|
||||||
v, tm, err := c.FindOldestVersionTimestamp()
|
v, tm, err := c.FindOldestVersionTimestamp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue