diff --git a/storage/oasis/client.go b/storage/oasis/client.go index 2fbf28d83..cb189fb34 100644 --- a/storage/oasis/client.go +++ b/storage/oasis/client.go @@ -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" @@ -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 @@ -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 } } diff --git a/storage/oasis/nodeapi/file/kvstore.go b/storage/oasis/nodeapi/file/kvstore.go index 7f823b74a..5831988e4 100644 --- a/storage/oasis/nodeapi/file/kvstore.go +++ b/storage/oasis/nodeapi/file/kvstore.go @@ -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 } @@ -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: