Take a snapshot's start time from the moment in its ID (closes #482)
check / check (push) Waiting to run
check / check (push) Waiting to run
CreateSnapshotWithName read the clock once for the ID and again for started_at. When the second read fell in the next second, the snapshot shared its started_at with the next run of the same name, and ListRecent, which orders by started_at, could list the two in either order. That made TestBackupWithEmptySourcePathDoesNotPrune fail at random. The start time now comes from the same clock read as the ID, so successive runs of one name have distinct, increasing start times. Model: opus-5-5
This commit is contained in:
1 parent
547b9faf36
commit
98a36c6a0c
2 files changed
+61
-4
No files matched your search
@@ -118,17 +118,22 @@ func ShortHostname(hostname string) string {
|
||||
// hostname_timestamp if name is empty. The timestamp is in whole seconds.
|
||||
// If the local index already has a snapshot with that ID, from a run of the
|
||||
// same name that started in the same second, it waits a second and takes a
|
||||
// new timestamp.
|
||||
// new timestamp. The snapshot's start time is the moment in its ID, so a
|
||||
// later run of one name always has a later start time.
|
||||
func (sm *SnapshotManager) CreateSnapshotWithName(
|
||||
ctx context.Context, hostname, name, version, gitRevision string,
|
||||
) (string, error) {
|
||||
shortHostname := ShortHostname(hostname)
|
||||
|
||||
var snapshotID string
|
||||
var (
|
||||
snapshotID string
|
||||
startedAt time.Time
|
||||
)
|
||||
|
||||
for {
|
||||
// Build snapshot ID with optional name
|
||||
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
||||
startedAt = time.Now().UTC()
|
||||
timestamp := startedAt.Format("2006-01-02T15:04:05Z")
|
||||
|
||||
if name != "" {
|
||||
snapshotID = fmt.Sprintf("%s_%s_%s", shortHostname, name, timestamp)
|
||||
@@ -153,7 +158,7 @@ func (sm *SnapshotManager) CreateSnapshotWithName(
|
||||
Hostname: types.Hostname(hostname),
|
||||
VaultikVersion: types.Version(version),
|
||||
VaultikGitRevision: types.GitRevision(gitRevision),
|
||||
StartedAt: time.Now().UTC(),
|
||||
StartedAt: startedAt,
|
||||
CompletedAt: nil, // Not completed yet
|
||||
FileCount: 0,
|
||||
ChunkCount: 0,
|
||||
|
||||
Reference in new issue
Block a user