Skip to content
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

storage/oasis: Cache init failure is not longer fatal #619

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions storage/oasis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/oasisprotocol/nexus/common"
"github.com/oasisprotocol/nexus/config"
"github.com/oasisprotocol/nexus/log"
"github.com/oasisprotocol/nexus/storage/oasis/nodeapi"
"github.com/oasisprotocol/nexus/storage/oasis/nodeapi/file"
"github.com/oasisprotocol/nexus/storage/oasis/nodeapi/history"
Expand All @@ -24,9 +25,13 @@ func NewConsensusClient(ctx context.Context, sourceConfig *config.SourceConfig)
}
if sourceConfig.Cache != nil {
cachePath := filepath.Join(sourceConfig.Cache.CacheDir, "consensus")
nodeApi, err = file.NewFileConsensusApiLite(cachePath, nodeApi)
wrappedNodeApi, err := file.NewFileConsensusApiLite(cachePath, nodeApi)
if err != nil {
return nil, fmt.Errorf("error instantiating cache-based consensusApi: %w", err)
// Continue without a cache, but warn.
// (The "analyzer" tag is not technically true as we're not in an analyzer, but is helpful when reading logs)
log.NewDefaultLogger("init").With("analyzer", "consensus").Warn("error instantiating cache-based consensusApi, continuing without a cache", "kvstore_err", err)
} else {
nodeApi = wrappedNodeApi
}
}
return nodeApi, nil
Expand All @@ -41,9 +46,13 @@ func NewRuntimeClient(ctx context.Context, sourceConfig *config.SourceConfig, ru
}
if sourceConfig.Cache != nil {
cachePath := filepath.Join(sourceConfig.Cache.CacheDir, string(runtime))
nodeApi, err = file.NewFileRuntimeApiLite(runtime, cachePath, nodeApi)
wrappedNodeApi, err := file.NewFileRuntimeApiLite(runtime, cachePath, nodeApi)
if err != nil {
return nil, fmt.Errorf("error instantiating cache-based runtimeApi: %w", err)
// Continue without a cache, but warn.
// (The "analyzer" tag is not technically true as we're not in an analyzer, but is helpful when reading logs)
log.NewDefaultLogger("init").With("analyzer", "consensus").Warn("error instantiating cache-based runtimeApi, continuing without a cache", "kvstore_err", err)
} else {
nodeApi = wrappedNodeApi
}
}

Expand Down
12 changes: 8 additions & 4 deletions storage/oasis/nodeapi/file/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type pogrebKVStore struct {
metrics *metrics.AnalysisMetrics // if nil, no metrics are emitted

// Address of the atomic variable that indicates whether the store is initialized.
// Synchronisation is required because the store is opened in background goroutine.
// Synchronisation is required because the store is opened in a background goroutine.
initialized uint32
}

Expand Down Expand Up @@ -104,10 +104,14 @@ func (s *pogrebKVStore) init() error {
// Initializes a new KVStore backed by a database at `path`, or opens an existing one.
// `metrics` can be `nil`, in which case no metrics are emitted during operation.
func OpenKVStore(logger *log.Logger, path string, metrics *metrics.AnalysisMetrics) (KVStore, error) {
// An unitialized `pogrebKVStore`. Its methods can still be used, they just do nothing:
// Reads will indicate a cache miss, and writes will fail.
store := &pogrebKVStore{
logger: logger,
path: path,
metrics: metrics,
path: path,
logger: logger,
metrics: metrics,
db: nil, // to be constructed during init()
initialized: 0,
}

// Open the database in background as it is possible it will do a full-reindex on startup after a crash:
Expand Down
Loading