Skip to content

Commit

Permalink
storage/oasis: Cache init failure is not longer fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjat committed Jan 29, 2024
1 parent f6af89d commit 5d713f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit 5d713f0

Please sign in to comment.