From 1fab64e9c6bd1b7b7c52e87e4346e9ba50038aa8 Mon Sep 17 00:00:00 2001 From: divyaac Date: Mon, 16 Dec 2024 13:39:07 -0800 Subject: [PATCH] OSS-Changes Patch (#29193) --- vault/activity_log.go | 12 +++++++++--- vault/activity_log_util_common.go | 23 ----------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/vault/activity_log.go b/vault/activity_log.go index aa15828c6274..820834b8a592 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -4095,11 +4095,10 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f func (c *Core) activityLogMigrationTask(ctx context.Context) { manager := c.activityLog if !c.IsPerfSecondary() { - // If the oldest version is less than 1.19 and no migrations tasks have been run, kick off the migration task - if !manager.OldestVersionHasDeduplicatedClients(ctx) && !manager.hasDedupClientsUpgrade(ctx) { + // If no migrations tasks have been run, kick off the migration task + if !manager.hasDedupClientsUpgrade(ctx) { go c.primaryDuplicateClientMigrationWorker(ctx) } else { - // Store that upgrade processes have already been completed manager.writeDedupClientsUpgrade(ctx) } } else { @@ -4108,6 +4107,8 @@ func (c *Core) activityLogMigrationTask(ctx context.Context) { // already upgraded primary if !manager.hasDedupClientsUpgrade(ctx) { go c.secondaryDuplicateClientMigrationWorker(ctx) + } else { + manager.writeDedupClientsUpgrade(ctx) } } } @@ -4118,7 +4119,12 @@ func (c *Core) activityLogMigrationTask(ctx context.Context) { // current cluster. This method wil only exit once all connected secondary clusters have // upgraded to 1.19, and this cluster receives global data from all of them. func (c *Core) primaryDuplicateClientMigrationWorker(ctx context.Context) error { + c.activityLogLock.Lock() a := c.activityLog + c.activityLogLock.Unlock() + if a == nil { + return fmt.Errorf("activity log not configured") + } a.logger.Trace("started primary activity log migration worker") ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/vault/activity_log_util_common.go b/vault/activity_log_util_common.go index 8b1bea9bcbb0..e8b85bf20daf 100644 --- a/vault/activity_log_util_common.go +++ b/vault/activity_log_util_common.go @@ -15,7 +15,6 @@ import ( "time" "github.com/axiomhq/hyperloglog" - semver "github.com/hashicorp/go-version" "github.com/hashicorp/vault/helper/timeutil" "github.com/hashicorp/vault/sdk/logical" "github.com/hashicorp/vault/vault/activity" @@ -640,28 +639,6 @@ func (a *ActivityLog) getAllEntitySegmentsForMonth(ctx context.Context, path str return segments, nil } -// OldestVersionHasDeduplicatedClients returns whether this cluster is 1.19+, and -// hence supports deduplicated clients -func (a *ActivityLog) OldestVersionHasDeduplicatedClients(ctx context.Context) bool { - oldestVersionIsDedupClients := a.core.IsNewInstall(ctx) - if !oldestVersionIsDedupClients { - if v, _, err := a.core.FindOldestVersionTimestamp(); err == nil { - oldestVersion, err := semver.NewSemver(v) - if err != nil { - a.core.logger.Debug("could not extract version instance", "version", v) - return false - } - dedupChangeVersion, err := semver.NewSemver(DeduplicatedClientMinimumVersion) - if err != nil { - a.core.logger.Debug("could not extract version instance", "version", DeduplicatedClientMinimumVersion) - return false - } - oldestVersionIsDedupClients = oldestVersionIsDedupClients || oldestVersion.GreaterThanOrEqual(dedupChangeVersion) - } - } - return oldestVersionIsDedupClients -} - func (a *ActivityLog) loadClientDataIntoSegment(ctx context.Context, pathPrefix string, startTime time.Time, seqNum uint64, currentSegment *segmentInfo) ([]*activity.EntityRecord, error) { path := pathPrefix + activityEntityBasePath + fmt.Sprint(startTime.Unix()) + "/" + strconv.FormatUint(seqNum, 10) out, err := a.readEntitySegmentAtPath(ctx, path)