Skip to content

Commit

Permalink
Eliminate the DatabaseConsistencyError. (#2557)
Browse files Browse the repository at this point in the history
* Several things:
* Separate the code for the store into a store.rs file.
* Move the MIN_TAG_VIEW to the views.
* Eliminate the DatabaseConsistencyError.
* Avoid the abstraction leakage.
  • Loading branch information
MathieuDutSik authored Oct 4, 2024
1 parent 2d5b67e commit 7ff558d
Show file tree
Hide file tree
Showing 66 changed files with 961 additions and 904 deletions.
2 changes: 1 addition & 1 deletion linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use linera_core::client::BlanketMessagePolicy;
use linera_execution::{
committee::ValidatorName, ResourceControlPolicy, WasmRuntime, WithWasmDefault as _,
};
use linera_views::common::CommonStoreConfig;
use linera_views::store::CommonStoreConfig;

#[cfg(feature = "fs")]
use crate::config::GenesisConfig;
Expand Down
6 changes: 3 additions & 3 deletions linera-client/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use linera_execution::WasmRuntime;
use linera_storage::{DbStorage, Storage};
#[cfg(feature = "storage-service")]
use linera_storage_service::{client::ServiceStoreClient, common::ServiceStoreConfig};
#[cfg(with_storage)]
use linera_views::common::LocalAdminKeyValueStore as _;
#[cfg(feature = "dynamodb")]
use linera_views::dynamo_db::{get_config, DynamoDbStore, DynamoDbStoreConfig};
#[cfg(with_storage)]
use linera_views::store::LocalAdminKeyValueStore as _;
use linera_views::{
common::CommonStoreConfig,
memory::{MemoryStore, MemoryStoreConfig},
store::CommonStoreConfig,
views::ViewError,
};
use tracing::error;
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/unit_tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use tokio::sync::oneshot;
use tokio_stream::wrappers::UnboundedReceiverStream;
#[cfg(feature = "rocksdb")]
use {
linera_views::common::AdminKeyValueStore as _,
linera_views::rocks_db::RocksDbStore,
linera_views::store::AdminKeyValueStore as _,
tokio::sync::{Semaphore, SemaphorePermit},
};

Expand Down
10 changes: 2 additions & 8 deletions linera-indexer/lib/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use axum::{extract::Extension, routing::get, Router};
use linera_base::{crypto::CryptoHash, data_types::BlockHeight, identifiers::ChainId};
use linera_chain::data_types::HashedCertificateValue;
use linera_views::{
common::KeyValueStore,
context::{Context, ViewContext},
map_view::MapView,
register_view::RegisterView,
set_view::SetView,
value_splitting::DatabaseConsistencyError,
store::KeyValueStore,
views::{RootView, View},
};
use tokio::sync::Mutex;
Expand Down Expand Up @@ -60,12 +59,7 @@ enum LatestBlock {
impl<S> Indexer<S>
where
S: KeyValueStore + Clone + Send + Sync + 'static,
S::Error: From<bcs::Error>
+ From<DatabaseConsistencyError>
+ Send
+ Sync
+ std::error::Error
+ 'static,
S::Error: Send + Sync + std::error::Error + 'static,
{
/// Loads the indexer using a database backend with an `indexer` prefix.
pub async fn load(store: S) -> Result<Self, IndexerError> {
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use async_graphql::{EmptyMutation, EmptySubscription, ObjectType, Schema};
use axum::Router;
use linera_chain::data_types::HashedCertificateValue;
use linera_views::{common::KeyValueStore, context::ViewContext, views::View};
use linera_views::{context::ViewContext, store::KeyValueStore, views::View};
use tokio::sync::Mutex;

use crate::common::IndexerError;
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/lib/src/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::path::PathBuf;

use clap::Parser as _;
use linera_views::{
common::{AdminKeyValueStore, CommonStoreConfig},
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
store::{AdminKeyValueStore, CommonStoreConfig},
};

use crate::{
Expand Down
9 changes: 2 additions & 7 deletions linera-indexer/lib/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! This module defines the trait for indexer runners.

use linera_base::identifiers::ChainId;
use linera_views::{common::KeyValueStore, value_splitting::DatabaseConsistencyError};
use linera_views::store::KeyValueStore;
use tokio::select;
use tracing::{info, warn};

Expand Down Expand Up @@ -46,12 +46,7 @@ where
Self: Send,
Config: Clone + std::fmt::Debug + Send + Sync + clap::Parser + clap::Args,
S: KeyValueStore + Clone + Send + Sync + 'static,
S::Error: From<bcs::Error>
+ From<DatabaseConsistencyError>
+ Send
+ Sync
+ std::error::Error
+ 'static,
S::Error: Send + Sync + std::error::Error + 'static,
{
/// Loads a new runner
pub async fn new(config: IndexerConfig<Config>, store: S) -> Result<Self, IndexerError>
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/lib/src/scylla_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use linera_views::{
common::{AdminKeyValueStore, CommonStoreConfig},
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
store::{AdminKeyValueStore, CommonStoreConfig},
};

use crate::{
Expand Down
9 changes: 2 additions & 7 deletions linera-indexer/lib/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use linera_base::{
use linera_chain::data_types::HashedCertificateValue;
use linera_core::worker::Reason;
use linera_service_graphql_client::{block, chains, notifications, Block, Chains, Notifications};
use linera_views::{common::KeyValueStore, value_splitting::DatabaseConsistencyError};
use linera_views::store::KeyValueStore;
use tokio::runtime::Handle;
use tracing::error;

Expand Down Expand Up @@ -130,12 +130,7 @@ impl Listener {
) -> Result<ChainId, IndexerError>
where
S: KeyValueStore + Clone + Send + Sync + 'static,
S::Error: From<bcs::Error>
+ From<DatabaseConsistencyError>
+ Send
+ Sync
+ std::error::Error
+ 'static,
S::Error: Send + Sync + std::error::Error + 'static,
{
let mut request = self.service.websocket().into_client_request()?;
request.headers_mut().insert(
Expand Down
2 changes: 1 addition & 1 deletion linera-indexer/plugins/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use linera_indexer::{
plugin::{load, route, sdl, Plugin},
};
use linera_views::{
common::KeyValueStore,
context::{Context, ViewContext},
map_view::MapView,
store::KeyValueStore,
views::RootView,
};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/src/views/mock_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::{
use futures::FutureExt as _;
use linera_views::{
batch::Batch,
common::{ReadableKeyValueStore, WritableKeyValueStore},
memory::{create_test_memory_store, MemoryStore},
store::{ReadableKeyValueStore, WritableKeyValueStore},
};

/// A mock [`KeyValueStore`] implementation using a [`MemoryStore`].
Expand Down
4 changes: 2 additions & 2 deletions linera-sdk/src/views/system_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use linera_base::ensure;
use linera_views::{
batch::Batch,
common::{ReadableKeyValueStore, WithError, WritableKeyValueStore},
store::{ReadableKeyValueStore, WithError, WritableKeyValueStore},
};
use thiserror::Error;

Expand Down Expand Up @@ -95,7 +95,7 @@ pub enum KeyValueStoreError {
Bcs(#[from] bcs::Error),
}

impl linera_views::common::KeyValueStoreError for KeyValueStoreError {
impl linera_views::store::KeyValueStoreError for KeyValueStoreError {
const BACKEND: &'static str = "key_value_store";
}

Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/database_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::process;

use linera_client::storage::StorageConfigNamespace;
use linera_views::common::CommonStoreConfig;
use linera_views::store::CommonStoreConfig;

#[derive(clap::Parser)]
#[command(
Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use linera_rpc::{
use linera_service::prometheus_server;
use linera_service::{grpc_proxy::GrpcProxy, util};
use linera_storage::Storage;
use linera_views::common::CommonStoreConfig;
use linera_views::store::CommonStoreConfig;
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
use tracing::{error, info, instrument};
Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use linera_rpc::{
use linera_service::prometheus_server;
use linera_service::util;
use linera_storage::Storage;
use linera_views::common::CommonStoreConfig;
use linera_views::store::CommonStoreConfig;
use serde::Deserialize;
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
Expand Down
4 changes: 2 additions & 2 deletions linera-storage-service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use linera_views::metering::MeteredStore;
use linera_views::test_utils::generate_test_namespace;
use linera_views::{
batch::{Batch, WriteOperation},
common::{
lru_caching::LruCachingStore,
store::{
AdminKeyValueStore, CommonStoreConfig, ReadableKeyValueStore, WithError,
WritableKeyValueStore,
},
lru_caching::LruCachingStore,
};
use serde::de::DeserializeOwned;
use tonic::transport::{Channel, Endpoint};
Expand Down
8 changes: 2 additions & 6 deletions linera-storage-service/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use linera_base::command::resolve_binary;
#[cfg(with_metrics)]
use linera_views::metering::KeyValueStoreMetrics;
use linera_views::{
common::{CommonStoreConfig, KeyValueStoreError, MIN_VIEW_TAG},
value_splitting::DatabaseConsistencyError,
store::{CommonStoreConfig, KeyValueStoreError},
views::MIN_VIEW_TAG,
};
use thiserror::Error;
use tonic::Status;
Expand Down Expand Up @@ -72,10 +72,6 @@ pub enum ServiceStoreError {
/// An error occurred during BCS serialization
#[error("An error occurred during BCS serialization")]
Serialization(#[from] bcs::Error),

/// The database is not consistent
#[error(transparent)]
DatabaseConsistencyError(#[from] DatabaseConsistencyError),
}

impl KeyValueStoreError for ServiceStoreError {
Expand Down
4 changes: 2 additions & 2 deletions linera-storage-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use async_lock::RwLock;
use linera_storage_service::common::{KeyTag, MAX_PAYLOAD_SIZE};
use linera_views::{
batch::Batch,
common::{CommonStoreConfig, ReadableKeyValueStore, WritableKeyValueStore},
memory::MemoryStore,
store::{CommonStoreConfig, ReadableKeyValueStore, WritableKeyValueStore},
};
#[cfg(with_rocksdb)]
use linera_views::{
common::AdminKeyValueStore,
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
store::AdminKeyValueStore as _,
};
use serde::Serialize;
use tonic::{transport::Server, Request, Response, Status};
Expand Down
14 changes: 5 additions & 9 deletions linera-storage/src/db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ use linera_execution::{
use linera_views::{
backends::dual::{DualStoreRootKeyAssignment, StoreInUse},
batch::Batch,
common::KeyValueStore,
context::ViewContext,
value_splitting::DatabaseConsistencyError,
store::KeyValueStore,
views::{View, ViewError},
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -357,8 +356,7 @@ impl<Store, C> Storage for DbStorage<Store, C>
where
Store: KeyValueStore + Clone + Send + Sync + 'static,
C: Clock + Clone + Send + Sync + 'static,
Store::Error:
From<bcs::Error> + From<DatabaseConsistencyError> + Send + Sync + serde::ser::StdError,
Store::Error: Send + Sync,
{
type Context = ViewContext<ChainRuntimeContext<Self>, Store>;
type Clock = C;
Expand Down Expand Up @@ -662,7 +660,7 @@ impl<Store, C> DbStorage<Store, C>
where
Store: KeyValueStore + Clone + Send + Sync + 'static,
C: Clock,
Store::Error: From<bcs::Error> + Send + Sync + serde::ser::StdError,
Store::Error: Send + Sync,
{
fn add_hashed_cert_value_to_batch(
value: &HashedCertificateValue,
Expand Down Expand Up @@ -729,8 +727,7 @@ where
impl<Store> DbStorage<Store, WallClock>
where
Store: KeyValueStore + Clone + Send + Sync + 'static,
Store::Error:
From<bcs::Error> + From<DatabaseConsistencyError> + Send + Sync + serde::ser::StdError,
Store::Error: Send + Sync,
{
pub async fn initialize(
config: Store::Config,
Expand All @@ -757,8 +754,7 @@ where
impl<Store> DbStorage<Store, TestClock>
where
Store: KeyValueStore + Clone + Send + Sync + 'static,
Store::Error:
From<bcs::Error> + From<DatabaseConsistencyError> + Send + Sync + serde::ser::StdError,
Store::Error: Send + Sync,
{
pub async fn make_test_storage(wasm_runtime: Option<WasmRuntime>) -> Self {
let config = Store::new_test_config().await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions linera-views-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ fn generate_view_code(input: ItemStruct, root: bool) -> TokenStream2 {
num_init_keys_quotes.push(quote! { #g :: NUM_INIT_KEYS });
pre_load_keys_quotes.push(quote! {
let index = #idx_lit;
let base_key = context.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
let base_key = context.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
keys.extend(#g :: pre_load(&context.clone_with_base_key(base_key))?);
});
post_load_keys_quotes.push(quote! {
let index = #idx_lit;
let pos_next = pos + #g :: NUM_INIT_KEYS;
let base_key = context.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
let base_key = context.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
let #name = #g :: post_load(context.clone_with_base_key(base_key), &values[pos..pos_next])?;
pos = pos_next;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ where
let mut keys = Vec::new();
let index = 0;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
keys.extend(
RegisterView::<C, usize>::pre_load(&context.clone_with_base_key(base_key))?,
);
let index = 1;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
keys.extend(
CollectionView::<
C,
Expand All @@ -43,7 +43,7 @@ where
let index = 0;
let pos_next = pos + RegisterView::<C, usize>::NUM_INIT_KEYS;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
let register = RegisterView::<
C,
usize,
Expand All @@ -53,7 +53,7 @@ where
let pos_next = pos
+ CollectionView::<C, usize, RegisterView<C, usize>>::NUM_INIT_KEYS;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
let collection = CollectionView::<
C,
usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ where
let mut keys = Vec::new();
let index = 0;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
keys.extend(
RegisterView::<C, usize>::pre_load(&context.clone_with_base_key(base_key))?,
);
let index = 1;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
keys.extend(
CollectionView::<
C,
Expand All @@ -44,7 +44,7 @@ where
let index = 0;
let pos_next = pos + RegisterView::<C, usize>::NUM_INIT_KEYS;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
let register = RegisterView::<
C,
usize,
Expand All @@ -54,7 +54,7 @@ where
let pos_next = pos
+ CollectionView::<C, usize, RegisterView<C, usize>>::NUM_INIT_KEYS;
let base_key = context
.derive_tag_key(linera_views::common::MIN_VIEW_TAG, &index)?;
.derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
let collection = CollectionView::<
C,
usize,
Expand Down
Loading

0 comments on commit 7ff558d

Please sign in to comment.