1- //! In-memory storage.
2- //!
3- //! RisingLight's in-memory representation of data is very simple. Currently,
4- //! it is simple a vector of `DataChunk`. Upon insertion, users' data are
5- //! simply appended to the end of the vector.
1+ //! On-disk storage
62
7- use std:: collections:: HashMap ;
8- use std:: sync:: { Arc , Mutex , RwLock } ;
3+ use std:: sync:: Arc ;
94
105use crate :: array:: DataChunk ;
116use crate :: catalog:: TableRefId ;
127
138/// The error type of storage operations.
149#[ derive( thiserror:: Error , Debug ) ]
15- pub enum StorageError {
16- #[ error( "table not found: {0:?}" ) ]
17- NotFound ( TableRefId ) ,
18- }
10+ #[ error( "{0:?}" ) ]
11+ pub struct StorageError ( #[ from] anyhow:: Error ) ;
1912
2013/// A specialized `Result` type for storage operations.
2114pub type StorageResult < T > = std:: result:: Result < T , StorageError > ;
2215
2316pub type StorageRef = Arc < DiskStorage > ;
24- pub type DiskTableRef = Arc < DiskTable > ;
17+ pub type StorageTableRef = Arc < DiskTable > ;
18+
19+ /// On-disk storage.
20+ #[ derive( Clone ) ]
21+ pub struct DiskStorage ;
2522
26- /// In-memory storage.
27- pub struct DiskStorage {
28- tables : Mutex < HashMap < TableRefId , DiskTableRef > > ,
23+ /// An on-disk table.
24+ pub struct DiskTable {
25+ #[ allow( dead_code) ]
26+ id : TableRefId ,
2927}
3028
3129impl Default for DiskStorage {
@@ -37,59 +35,28 @@ impl Default for DiskStorage {
3735impl DiskStorage {
3836 /// Create a new in-memory storage.
3937 pub fn new ( ) -> Self {
40- DiskStorage {
41- tables : Mutex :: new ( HashMap :: new ( ) ) ,
42- }
38+ DiskStorage
4339 }
4440
4541 /// Add a table.
46- pub fn add_table ( & self , id : TableRefId ) -> StorageResult < ( ) > {
47- let table = Arc :: new ( DiskTable :: new ( id) ) ;
48- self . tables . lock ( ) . unwrap ( ) . insert ( id, table) ;
49- Ok ( ( ) )
42+ pub fn add_table ( & self , _id : TableRefId ) -> StorageResult < ( ) > {
43+ todo ! ( )
5044 }
5145
5246 /// Get a table.
53- pub fn get_table ( & self , id : TableRefId ) -> StorageResult < DiskTableRef > {
54- self . tables
55- . lock ( )
56- . unwrap ( )
57- . get ( & id)
58- . cloned ( )
59- . ok_or ( StorageError :: NotFound ( id) )
47+ pub fn get_table ( & self , _id : TableRefId ) -> StorageResult < StorageTableRef > {
48+ todo ! ( )
6049 }
6150}
6251
63- /// A table in in-memory engine.
64- pub struct DiskTable {
65- #[ allow( dead_code) ]
66- id : TableRefId ,
67- inner : RwLock < DiskTableInner > ,
68- }
69-
70- #[ derive( Default ) ]
71- struct DiskTableInner {
72- chunks : Vec < DataChunk > ,
73- }
74-
7552impl DiskTable {
76- fn new ( id : TableRefId ) -> Self {
77- Self {
78- id,
79- inner : RwLock :: new ( DiskTableInner :: default ( ) ) ,
80- }
81- }
82-
8353 /// Append a chunk to the table.
84- pub fn append ( & self , chunk : DataChunk ) -> StorageResult < ( ) > {
85- let mut inner = self . inner . write ( ) . unwrap ( ) ;
86- inner. chunks . push ( chunk) ;
87- Ok ( ( ) )
54+ pub async fn append ( & self , _chunk : DataChunk ) -> StorageResult < ( ) > {
55+ todo ! ( )
8856 }
8957
9058 /// Get all chunks of the table.
91- pub fn all_chunks ( & self ) -> StorageResult < Vec < DataChunk > > {
92- let inner = self . inner . read ( ) . unwrap ( ) ;
93- Ok ( inner. chunks . clone ( ) )
59+ pub async fn all_chunks ( & self ) -> StorageResult < Vec < DataChunk > > {
60+ todo ! ( )
9461 }
9562}
0 commit comments