Skip to content

Commit 4e5447f

Browse files
authored
chore(cubestore) Metastore constructor refactoring (#5734)
1 parent a6915e8 commit 4e5447f

File tree

7 files changed

+56
-36
lines changed

7 files changed

+56
-36
lines changed

rust/cubestore/cubestore/src/cachestore/cache_rocksstore.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ impl RocksCacheStore {
5454
path: &Path,
5555
metastore_fs: Arc<dyn MetaStoreFs>,
5656
config: Arc<dyn ConfigObj>,
57-
) -> Arc<Self> {
58-
Self::new_from_store(RocksStore::with_listener(
57+
) -> Result<Arc<Self>, CubeError> {
58+
Ok(Self::new_from_store(RocksStore::with_listener(
5959
path,
6060
vec![],
6161
metastore_fs,
6262
config,
6363
Arc::new(RocksCacheStoreDetails {}),
64-
))
64+
)?))
6565
}
6666

6767
fn new_from_store(store: Arc<RocksStore>) -> Arc<Self> {
@@ -145,7 +145,8 @@ impl RocksCacheStore {
145145
BaseRocksStoreFs::new(remote_fs.clone(), "cachestore"),
146146
config.config_obj(),
147147
details,
148-
);
148+
)
149+
.unwrap();
149150

150151
(remote_fs, Self::new_from_store(store))
151152
}

rust/cubestore/cubestore/src/metastore/mod.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,14 @@ impl RocksMetaStore {
10961096
path: &Path,
10971097
metastore_fs: Arc<dyn MetaStoreFs>,
10981098
config: Arc<dyn ConfigObj>,
1099-
) -> Arc<Self> {
1100-
Self::new_from_store(RocksStore::with_listener(
1099+
) -> Result<Arc<Self>, CubeError> {
1100+
Ok(Self::new_from_store(RocksStore::with_listener(
11011101
path,
11021102
vec![],
11031103
metastore_fs,
11041104
config,
11051105
Arc::new(RocksMetaStoreDetails {}),
1106-
))
1106+
)?))
11071107
}
11081108

11091109
fn new_from_store(store: Arc<RocksStore>) -> Arc<Self> {
@@ -1187,7 +1187,8 @@ impl RocksMetaStore {
11871187
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
11881188
config.config_obj(),
11891189
details,
1190-
);
1190+
)
1191+
.unwrap();
11911192

11921193
(remote_fs, Self::new_from_store(store))
11931194
}
@@ -4151,7 +4152,8 @@ mod tests {
41514152
store_path.join("metastore").as_path(),
41524153
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
41534154
config.config_obj(),
4154-
);
4155+
)
4156+
.unwrap();
41554157

41564158
let schema_1 = meta_store
41574159
.create_schema("foo".to_string(), false)
@@ -4338,7 +4340,8 @@ mod tests {
43384340
store_path.join("metastore").as_path(),
43394341
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
43404342
config.config_obj(),
4341-
);
4343+
)
4344+
.unwrap();
43424345

43434346
let schema1 = meta_store
43444347
.create_schema("foo".to_string(), false)
@@ -4416,7 +4419,8 @@ mod tests {
44164419
store_path.join("metastore").as_path(),
44174420
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
44184421
config.config_obj(),
4419-
);
4422+
)
4423+
.unwrap();
44204424

44214425
meta_store
44224426
.create_schema("foo".to_string(), false)
@@ -4464,7 +4468,8 @@ mod tests {
44644468
store_path.clone().join("metastore").as_path(),
44654469
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
44664470
config.config_obj(),
4467-
);
4471+
)
4472+
.unwrap();
44684473

44694474
let schema_1 = meta_store
44704475
.create_schema("foo".to_string(), false)
@@ -4571,7 +4576,8 @@ mod tests {
45714576
store_path.clone().join("metastore").as_path(),
45724577
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
45734578
config.config_obj(),
4574-
);
4579+
)
4580+
.unwrap();
45754581

45764582
meta_store
45774583
.create_schema("foo".to_string(), false)
@@ -4658,7 +4664,8 @@ mod tests {
46584664
store_path.clone().join("metastore").as_path(),
46594665
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
46604666
config.config_obj(),
4661-
);
4667+
)
4668+
.unwrap();
46624669

46634670
meta_store
46644671
.create_schema("foo".to_string(), false)
@@ -5138,7 +5145,8 @@ mod tests {
51385145
store_path.join("metastore").as_path(),
51395146
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
51405147
config.config_obj(),
5141-
);
5148+
)
5149+
.unwrap();
51425150
meta_store
51435151
.create_schema("foo".to_string(), false)
51445152
.await
@@ -5275,7 +5283,8 @@ mod tests {
52755283
store_path.join("metastore").as_path(),
52765284
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
52775285
config.config_obj(),
5278-
);
5286+
)
5287+
.unwrap();
52795288
meta_store
52805289
.create_schema("foo".to_string(), false)
52815290
.await

rust/cubestore/cubestore/src/metastore/rocks_fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl MetaStoreFs for BaseRocksStoreFs {
298298

299299
return self
300300
.check_rocks_store(
301-
RocksStore::new(Path::new(path), self.clone(), config, rocks_details),
301+
RocksStore::new(Path::new(path), self.clone(), config, rocks_details)?,
302302
Some(snapshot),
303303
)
304304
.await;
@@ -313,7 +313,7 @@ impl MetaStoreFs for BaseRocksStoreFs {
313313

314314
return self
315315
.check_rocks_store(
316-
RocksStore::new(Path::new(path), self.clone(), config, rocks_details),
316+
RocksStore::new(Path::new(path), self.clone(), config, rocks_details)?,
317317
None,
318318
)
319319
.await;

rust/cubestore/cubestore/src/metastore/rocks_store.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ impl RocksStore {
400400
metastore_fs: Arc<dyn MetaStoreFs>,
401401
config: Arc<dyn ConfigObj>,
402402
details: Arc<dyn RocksStoreDetails>,
403-
) -> Arc<Self> {
404-
let meta_store = Self::with_listener_impl(path, listeners, metastore_fs, config, details);
405-
Arc::new(meta_store)
403+
) -> Result<Arc<Self>, CubeError> {
404+
let meta_store = Self::with_listener_impl(path, listeners, metastore_fs, config, details)?;
405+
Ok(Arc::new(meta_store))
406406
}
407407

408408
pub fn with_listener_impl(
@@ -411,8 +411,8 @@ impl RocksStore {
411411
metastore_fs: Arc<dyn MetaStoreFs>,
412412
config: Arc<dyn ConfigObj>,
413413
details: Arc<dyn RocksStoreDetails>,
414-
) -> Self {
415-
let db = details.open_db(path).unwrap();
414+
) -> Result<Self, CubeError> {
415+
let db = details.open_db(path)?;
416416
let db_arc = Arc::new(db);
417417

418418
let (rw_loop_tx, rw_loop_rx) = std::sync::mpsc::sync_channel::<
@@ -449,15 +449,15 @@ impl RocksStore {
449449
details,
450450
};
451451

452-
meta_store
452+
Ok(meta_store)
453453
}
454454

455455
pub fn new(
456456
path: &Path,
457457
metastore_fs: Arc<dyn MetaStoreFs>,
458458
config: Arc<dyn ConfigObj>,
459459
details: Arc<dyn RocksStoreDetails>,
460-
) -> Arc<Self> {
460+
) -> Result<Arc<Self>, CubeError> {
461461
Self::with_listener(path, vec![], metastore_fs, config, details)
462462
}
463463

@@ -484,7 +484,7 @@ impl RocksStore {
484484
);
485485
}
486486

487-
let meta_store = Self::new(path, metastore_fs, config, details);
487+
let meta_store = Self::new(path, metastore_fs, config, details)?;
488488
Self::check_all_indexes(&meta_store).await?;
489489

490490
Ok(meta_store)

rust/cubestore/cubestore/src/sql/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1783,12 +1783,14 @@ mod tests {
17831783
&Path::new(path).join("metastore"),
17841784
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
17851785
config.config_obj(),
1786-
);
1786+
)
1787+
.unwrap();
17871788
let cache_store = RocksCacheStore::new(
17881789
&Path::new(path).join("cachestore"),
17891790
BaseRocksStoreFs::new(remote_fs.clone(), "cachestore"),
17901791
config.config_obj(),
1791-
);
1792+
)
1793+
.unwrap();
17921794
let rows_per_chunk = 10;
17931795
let query_timeout = Duration::from_secs(30);
17941796
let store = ChunkStore::new(
@@ -1853,12 +1855,14 @@ mod tests {
18531855
&Path::new(path).join("metastore"),
18541856
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
18551857
config.config_obj(),
1856-
);
1858+
)
1859+
.unwrap();
18571860
let cache_store = RocksCacheStore::new(
18581861
&Path::new(path).join("cachestore"),
18591862
BaseRocksStoreFs::new(remote_fs.clone(), "cachestore"),
18601863
config.config_obj(),
1861-
);
1864+
)
1865+
.unwrap();
18621866
let rows_per_chunk = 10;
18631867
let query_timeout = Duration::from_secs(30);
18641868
let chunk_store = ChunkStore::new(
@@ -1952,12 +1956,14 @@ mod tests {
19521956
&Path::new(path).join("metastore"),
19531957
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
19541958
config.config_obj(),
1955-
);
1959+
)
1960+
.unwrap();
19561961
let cache_store = RocksCacheStore::new(
19571962
&Path::new(path).join("cachestore"),
19581963
BaseRocksStoreFs::new(remote_fs.clone(), "cachestore"),
19591964
config.config_obj(),
1960-
);
1965+
)
1966+
.unwrap();
19611967
let rows_per_chunk = 10;
19621968
let query_timeout = Duration::from_secs(30);
19631969
let chunk_store = ChunkStore::new(

rust/cubestore/cubestore/src/store/compaction.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,8 @@ mod tests {
16651665
Path::new(path),
16661666
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
16671667
config.config_obj(),
1668-
);
1668+
)
1669+
.unwrap();
16691670
let chunk_store = ChunkStore::new(
16701671
metastore.clone(),
16711672
remote_fs.clone(),

rust/cubestore/cubestore/src/store/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ mod tests {
631631
Path::new(path),
632632
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
633633
config.config_obj(),
634-
),
634+
)
635+
.unwrap(),
635636
remote_fs.clone(),
636637
10,
637638
);
@@ -722,7 +723,8 @@ mod tests {
722723
Path::new(path),
723724
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
724725
config.config_obj(),
725-
);
726+
)
727+
.unwrap();
726728
let chunk_store = ChunkStore::new(
727729
meta_store.clone(),
728730
remote_fs.clone(),
@@ -820,7 +822,8 @@ mod tests {
820822
Path::new(path),
821823
BaseRocksStoreFs::new(remote_fs.clone(), "metastore"),
822824
config.config_obj(),
823-
);
825+
)
826+
.unwrap();
824827
let chunk_store = ChunkStore::new(
825828
meta_store.clone(),
826829
remote_fs.clone(),

0 commit comments

Comments
 (0)