Skip to content

Commit

Permalink
historyarchive: Improve existence checks and performance (#5179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Jan 25, 2024
1 parent bfaf9e1 commit 93f9d70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion historyarchive/archive_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,26 @@ func (abc *ArchiveBucketCache) GetFile(
}

func (abc *ArchiveBucketCache) Exists(filepath string) bool {
return abc.lru.Contains(path.Join(abc.path, filepath))
localPath := path.Join(abc.path, filepath)

// First, check if the file exists in the cache.
if abc.lru.Contains(localPath) {
return true
}

// If it doesn't, it may still exist on the disk which is still a cheaper
// check than going upstream.
//
// Note that this means the cache and disk are out of sync (perhaps due to
// other archives using the same cache location) so we can update it. This
// situation is well-handled by `GetFile`.
_, statErr := os.Stat(localPath)
if statErr == nil || os.IsExist(statErr) {
abc.lru.Add(localPath, struct{}{})
return true
}

return false
}

// Close purges the cache and cleans up the filesystem.
Expand Down
2 changes: 1 addition & 1 deletion ingest/verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (v *StateVerifier) GetLedgerEntries(count int) ([]xdr.LedgerEntry, error) {
}

entries := make([]xdr.LedgerEntry, 0, count)
v.currentEntries = make(map[string]xdr.LedgerEntry)
v.currentEntries = make(map[string]xdr.LedgerEntry, count)

for count > 0 {
entryChange, err := v.stateReader.Read()
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func (s *system) verifyState(verifyAgainstLatestCheckpoint bool) error {
}
}
}
log.WithField("duration", duration).Info("State verification finished")

localLog.WithField("duration", duration).Info("State verification finished")
}()

localLog.Info("Creating state reader...")
Expand Down

0 comments on commit 93f9d70

Please sign in to comment.