#分布式数据库 #分布式 #分布式系统 #设置

datacake-lmdb

使用 LMDB 的 datacake 存储 trait 的预构建实现

2 个不稳定版本

0.2.0 2023 年 6 月 22 日
0.1.0 2023 年 4 月 6 日

#2129数据库接口


用于 datacake

MIT 许可证

350KB
7.5K SLoC

Datacake LMDB

datacake 最终一致性 Storage trait 的预构建实现,这允许您立即设置持久集群而无需任何正确存储的实现麻烦。

更多信息请见 https://github.com/lnx-search/datacake

示例

use std::env::temp_dir;                                                            
use anyhow::Result;                                                                
use uuid::Uuid;                                                                    
use datacake_eventual_consistency::EventuallyConsistentStoreExtension;             
use datacake_node::{                                                               
    ConnectionConfig,                                                              
    Consistency,                                                                   
    DCAwareSelector,                                                               
    DatacakeNodeBuilder,                                                           
};                                                                                 
use datacake_lmdb::LmdbStorage;                                                    
                                                                                   
static KEYSPACE: &str = "lmdb-store";                                              
                                                                                   
#[tokio::main]                                                                     
async fn main() -> Result<()> {                                                    
    tracing_subscriber::fmt::init();                                               
                                                                                   
    let temp_dir = temp_dir().join(Uuid::new_v4().to_string());                    
    std::fs::create_dir_all(&temp_dir)?;                                           
                                                                                   
    let store = LmdbStorage::open(temp_dir).await?;                                
                                                                                   
    let addr = test_helper::get_unused_addr();                                     
    let connection_cfg = ConnectionConfig::new(addr, addr, Vec::<String>::new());  
                                                                                   
    let node = DatacakeNodeBuilder::<DCAwareSelector>::new(1, connection_cfg)      
        .connect()                                                                 
        .await?;                                                                   
    let store = node                                                               
        .add_extension(EventuallyConsistentStoreExtension::new(store))             
        .await?;                                                                   
                                                                                   
    let handle = store.handle();                                                   
                                                                                   
    handle.put(KEYSPACE, 1, b"Hello, world".to_vec(), Consistency::All).await?;    
                                                                                   
    let doc = handle                                                               
        .get(KEYSPACE, 1)                                                          
        .await?                                                                    
        .expect("Document should not be none");                                    
    assert_eq!(doc.id(), 1);                                                       
    assert_eq!(doc.data(), b"Hello, world");                                       
                                                                                   
    handle.del(KEYSPACE, 1, Consistency::All).await?;                              
    let doc = handle.get(KEYSPACE, 1).await?;                                      
    assert!(doc.is_none(), "No document should not exist!");                       
                                                                                   
    handle.del(KEYSPACE, 2, Consistency::All).await?;                              
    let doc = handle.get(KEYSPACE, 2).await?;                                      
    assert!(doc.is_none(), "No document should not exist!");                       
                                                                                   
    node.shutdown().await;                                                         
                                                                                   
    Ok(())                                                                         
}                                                                                  






依赖项

~9–20MB
~270K SLoC