Skip to content

Commit

Permalink
fixed some lingering merge details from 2.28.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Jan 27, 2024
1 parent b84f126 commit 8338a1c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
26 changes: 9 additions & 17 deletions historyarchive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ type Ledger struct {
TransactionResult xdr.TransactionHistoryResultEntry
}

type ArchiveBackend interface {
Exists(path string) (bool, error)
Size(path string) (int64, error)
GetFile(path string) (io.ReadCloser, error)
PutFile(path string, in io.ReadCloser) error
ListFiles(path string) (chan string, chan error)
CanListFiles() bool
}

type ArchiveInterface interface {
GetPathHAS(path string) (HistoryArchiveState, error)
PutPathHAS(path string, has HistoryArchiveState, opts *CommandOptions) error
Expand Down Expand Up @@ -112,8 +103,8 @@ type Archive struct {

checkpointManager CheckpointManager

backend ArchiveBackend
cache *ArchiveBucketCache
backend storage.Storage
cache *ArchiveBucketCache
stats archiveStats
}

Expand Down Expand Up @@ -443,11 +434,11 @@ func Connect(u string, opts ArchiveOptions) (*Archive, error) {

var err error
arch.backend, err = ConnectBackend(u, opts.ConnectOptions)
if (err != nil) {
if err != nil {
return &arch, err
}

if opts.CacheConfig.Cache {
if opts.CacheConfig.Cache {
cache, innerErr := MakeArchiveBucketCache(opts.CacheConfig)
if innerErr != nil {
return &arch, innerErr
Expand All @@ -456,8 +447,7 @@ func Connect(u string, opts ArchiveOptions) (*Archive, error) {
arch.cache = cache
}

parsed, err := url.Parse(u)
arch.stats = archiveStats{backendName: parsed.String()}
arch.stats = archiveStats{backendName: u}
return &arch, nil
}

Expand All @@ -466,19 +456,21 @@ func ConnectBackend(u string, opts storage.ConnectOptions) (storage.Storage, err
return nil, errors.New("URL is empty")
}

var err error
parsed, err := url.Parse(u)
if err != nil {
return nil, err
}

var backend storage.Storage

if parsed.Scheme == "mock" {
backend = makeMockBackend()
} else {
backend, err = storage.ConnectBackend(u, opts)
}

return backend, nil
return backend, err
}

func MustConnect(u string, opts ArchiveOptions) *Archive {
Expand All @@ -487,4 +479,4 @@ func MustConnect(u string, opts ArchiveOptions) *Archive {
log.Fatal(err)
}
return arch
}
}
3 changes: 2 additions & 1 deletion historyarchive/archive_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

lru "github.com/hashicorp/golang-lru"
log "github.com/stellar/go/support/log"
"github.com/stellar/go/support/storage"
)

type CacheOptions struct {
Expand Down Expand Up @@ -61,7 +62,7 @@ func MakeArchiveBucketCache(opts CacheOptions) (*ArchiveBucketCache, error) {
// cache, and any error.
func (abc *ArchiveBucketCache) GetFile(
filepath string,
upstream ArchiveBackend,
upstream storage.Storage,
) (io.ReadCloser, bool, error) {
L := abc.log.WithField("key", filepath)
localPath := path.Join(abc.path, filepath)
Expand Down
20 changes: 11 additions & 9 deletions historyarchive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func GetTestS3Archive() *Archive {
}

func GetTestMockArchive() *Archive {
return MustConnect("mock://test",
ArchiveOptions{CheckpointFrequency: 64,
CacheConfig: CacheOptions{
Cache: true,
Path: filepath.Join(os.TempDir(), "history-archive-test-cache"),
MaxFiles: 5,
}})
return MustConnect("mock://test",
ArchiveOptions{CheckpointFrequency: 64,
CacheConfig: CacheOptions{
Cache: true,
Path: filepath.Join(os.TempDir(), "history-archive-test-cache"),
MaxFiles: 5,
}})
}

var tmpdirs []string
Expand Down Expand Up @@ -200,8 +200,10 @@ func TestConfiguresHttpUserAgent(t *testing.T) {
}))
defer server.Close()

archive, err := Connect(server.URL, ConnectOptions{
UserAgent: "uatest",
archive, err := Connect(server.URL, ArchiveOptions{
ConnectOptions: storage.ConnectOptions{
UserAgent: "uatest",
},
})
assert.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func NewSystem(config Config) (System, error) {
CheckpointFrequency: config.CheckpointFrequency,
ConnectOptions: storage.ConnectOptions{
Context: ctx,
UserAgent: fmt.Sprintf("horizon/%s golang/%s", apkg.Version(), runtime.Version()),},
UserAgent: fmt.Sprintf("horizon/%s golang/%s", apkg.Version(), runtime.Version())},
CacheConfig: historyarchive.CacheOptions{
Cache: true,
Path: path.Join(config.CaptiveCoreStoragePath, "bucket-cache"),
Expand Down

0 comments on commit 8338a1c

Please sign in to comment.