-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
historyarchive: Introduce a History Archive pool that's selected from for all calls #3402
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
895f456
Add initial draft version of the pooled archive type
Shaptic b0a1bcf
Make Captive Core backend use the new pool
Shaptic f023572
Add logging messages
Shaptic 3da69c1
Convert pool object to just be a collection of archives
Shaptic c342951
Add ArchiveInterface-compatible methods back to PooledArchive
Shaptic 10b88f8
Use the new interface when running Captive Core
Shaptic fdc2e20
Rename object to ArchivePool
Shaptic 8a80c1a
Allow the methods to work on pointers
Shaptic b819a57
Fix pointer issue (thx go vet!)
Shaptic ccab114
Change filename and constructor name to match type
Shaptic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2016 Stellar Development Foundation and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the COPYING file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package historyarchive | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/stellar/go/support/errors" | ||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
// Type PooledArchive forwards all API calls to a random ArchiveInterface within | ||
// its internal pool. | ||
type PooledArchive struct { | ||
Shaptic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pool []ArchiveInterface | ||
} | ||
|
||
var _ ArchiveInterface = &PooledArchive{} | ||
|
||
func CreatePool(archives ...ArchiveInterface) (*PooledArchive, error) { | ||
if len(archives) <= 0 { | ||
return nil, errors.New("No history archives provided") | ||
} | ||
return &PooledArchive{pool: archives}, nil | ||
} | ||
|
||
func (pa *PooledArchive) GetAnyArchive() ArchiveInterface { | ||
return pa.pool[rand.Intn(len(pa.pool))] | ||
} | ||
|
||
// Below are the ArchiveInterface method implementations. | ||
|
||
func (pa *PooledArchive) GetPathHAS(path string) (HistoryArchiveState, error) { | ||
return pa.GetAnyArchive().GetPathHAS(path) | ||
} | ||
|
||
func (pa *PooledArchive) PutPathHAS(path string, has HistoryArchiveState, opts *CommandOptions) error { | ||
return pa.GetAnyArchive().PutPathHAS(path, has, opts) | ||
} | ||
|
||
func (pa *PooledArchive) BucketExists(bucket Hash) (bool, error) { | ||
return pa.GetAnyArchive().BucketExists(bucket) | ||
} | ||
|
||
func (pa *PooledArchive) CategoryCheckpointExists(cat string, chk uint32) (bool, error) { | ||
return pa.GetAnyArchive().CategoryCheckpointExists(cat, chk) | ||
} | ||
|
||
func (pa *PooledArchive) GetLedgerHeader(chk uint32) (xdr.LedgerHeaderHistoryEntry, error) { | ||
return pa.GetAnyArchive().GetLedgerHeader(chk) | ||
} | ||
|
||
func (pa *PooledArchive) GetRootHAS() (HistoryArchiveState, error) { | ||
return pa.GetAnyArchive().GetRootHAS() | ||
} | ||
|
||
func (pa *PooledArchive) GetCheckpointHAS(chk uint32) (HistoryArchiveState, error) { | ||
return pa.GetAnyArchive().GetCheckpointHAS(chk) | ||
} | ||
|
||
func (pa *PooledArchive) PutCheckpointHAS(chk uint32, has HistoryArchiveState, opts *CommandOptions) error { | ||
return pa.GetAnyArchive().PutCheckpointHAS(chk, has, opts) | ||
} | ||
|
||
func (pa *PooledArchive) PutRootHAS(has HistoryArchiveState, opts *CommandOptions) error { | ||
return pa.GetAnyArchive().PutRootHAS(has, opts) | ||
} | ||
|
||
func (pa *PooledArchive) ListBucket(dp DirPrefix) (chan string, chan error) { | ||
return pa.GetAnyArchive().ListBucket(dp) | ||
} | ||
|
||
func (pa *PooledArchive) ListAllBuckets() (chan string, chan error) { | ||
return pa.GetAnyArchive().ListAllBuckets() | ||
} | ||
|
||
func (pa *PooledArchive) ListAllBucketHashes() (chan Hash, chan error) { | ||
return pa.GetAnyArchive().ListAllBucketHashes() | ||
} | ||
|
||
func (pa *PooledArchive) ListCategoryCheckpoints(cat string, pth string) (chan uint32, chan error) { | ||
return pa.GetAnyArchive().ListCategoryCheckpoints(cat, pth) | ||
} | ||
|
||
func (pa *PooledArchive) GetXdrStreamForHash(hash Hash) (*XdrStream, error) { | ||
return pa.GetAnyArchive().GetXdrStreamForHash(hash) | ||
} | ||
|
||
func (pa *PooledArchive) GetXdrStream(pth string) (*XdrStream, error) { | ||
return pa.GetAnyArchive().GetXdrStream(pth) | ||
} | ||
|
||
func (pa *PooledArchive) GetCheckpointManager() CheckpointManager { | ||
return pa.GetAnyArchive().GetCheckpointManager() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need copyright comment on top of this file. At least we don't have it in most of other files. @ire-and-curses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: copyright - let's just follow whatever we do everywhere else in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so I was confused by this, too. In the
historyarchive
package, all of the files have copyright notices. The years are mixed, but all of them have one. So I added it here.