Skip to content

Commit 3fd26f1

Browse files
chore: Remove old storage logic (#3708)
Remove (most of) pre-LSMT logic --------- Co-authored-by: Stefan Schneider <31004026+schneiderstefan@users.noreply.github.com>
1 parent fbe09a6 commit 3fd26f1

File tree

16 files changed

+218
-1531
lines changed

16 files changed

+218
-1531
lines changed

rs/config/src/state_manager.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::path::PathBuf;
44

55
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
66
pub struct LsmtConfig {
7-
/// Whether LSMT is enabled or not.
8-
pub lsmt_status: FlagStatus,
97
/// Number of pages per shard in sharded overlays; u64::MAX if unlimited.
108
pub shard_num_pages: u64,
119
}
@@ -47,7 +45,6 @@ fn file_backed_memory_allocator_default() -> FlagStatus {
4745

4846
pub fn lsmt_config_default() -> LsmtConfig {
4947
LsmtConfig {
50-
lsmt_status: FlagStatus::Enabled,
5148
// 40GiB
5249
// DO NOT CHANGE after LSMT is enabled, as it would crash the new replica trying to merge
5350
// old data.

rs/replicated_state/src/page_map.rs

Lines changed: 15 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ pub mod test_utils;
66

77
use bit_vec::BitVec;
88
pub use checkpoint::{CheckpointSerialization, MappingSerialization};
9-
use ic_config::flag_status::FlagStatus;
109
use ic_config::state_manager::LsmtConfig;
1110
use ic_metrics::buckets::{decimal_buckets, linear_buckets};
1211
use ic_metrics::MetricsRegistry;
13-
use ic_sys::{fs::write_all_vectored, PageBytes};
12+
use ic_sys::PageBytes;
1413
pub use ic_sys::{PageIndex, PAGE_SIZE};
1514
use ic_utils::deterministic_operations::deterministic_copy_from_slice;
1615
pub use page_allocator::{
@@ -32,15 +31,10 @@ use page_allocator::Page;
3231
use prometheus::{Histogram, HistogramVec, IntCounter, IntCounterVec};
3332
use serde::{Deserialize, Serialize};
3433
use std::collections::HashMap;
35-
use std::fs::{File, OpenOptions};
3634
use std::ops::Range;
3735
use std::os::unix::io::RawFd;
38-
use std::path::Path;
3936
use std::sync::Arc;
4037

41-
// When persisting data we expand dirty pages to an aligned bucket of given size.
42-
const WRITE_BUCKET_PAGES: u64 = 16;
43-
4438
const LABEL_OP: &str = "op";
4539
const LABEL_TYPE: &str = "type";
4640
const LABEL_OP_FLUSH: &str = "flush";
@@ -128,39 +122,6 @@ impl StorageMetrics {
128122
}
129123
}
130124

131-
struct WriteBuffer<'a> {
132-
content: Vec<&'a [u8]>,
133-
start_index: PageIndex,
134-
}
135-
136-
impl WriteBuffer<'_> {
137-
fn apply_to_file(&mut self, file: &mut File, path: &Path) -> Result<(), PersistenceError> {
138-
use std::io::{Seek, SeekFrom};
139-
140-
let offset = self.start_index.get() * PAGE_SIZE as u64;
141-
file.seek(SeekFrom::Start(offset))
142-
.map_err(|err| PersistenceError::FileSystemError {
143-
path: path.display().to_string(),
144-
context: format!("Failed to seek to {}", offset),
145-
internal_error: err.to_string(),
146-
})?;
147-
148-
write_all_vectored(file, &self.content).map_err(|err| {
149-
PersistenceError::FileSystemError {
150-
path: path.display().to_string(),
151-
context: format!(
152-
"Failed to copy page range #{}..{}",
153-
self.start_index,
154-
self.start_index.get() + self.content.len() as u64
155-
),
156-
internal_error: err.to_string(),
157-
}
158-
})?;
159-
160-
Ok(())
161-
}
162-
}
163-
164125
/// `PageDelta` represents a changeset of the module heap.
165126
///
166127
/// NOTE: We use a persistent map to make snapshotting of a PageMap a cheap
@@ -590,16 +551,13 @@ impl PageMap {
590551
lsmt_config: &LsmtConfig,
591552
metrics: &StorageMetrics,
592553
) -> Result<(), PersistenceError> {
593-
match lsmt_config.lsmt_status {
594-
FlagStatus::Disabled => self.persist_to_file(&self.page_delta, &storage_layout.base()),
595-
FlagStatus::Enabled => self.persist_to_overlay(
596-
&self.page_delta,
597-
storage_layout,
598-
height,
599-
lsmt_config,
600-
metrics,
601-
),
602-
}
554+
self.persist_to_overlay(
555+
&self.page_delta,
556+
storage_layout,
557+
height,
558+
lsmt_config,
559+
metrics,
560+
)
603561
}
604562

605563
/// Persists the unflushed delta contained in this page map to the specified
@@ -611,18 +569,13 @@ impl PageMap {
611569
lsmt_config: &LsmtConfig,
612570
metrics: &StorageMetrics,
613571
) -> Result<(), PersistenceError> {
614-
match lsmt_config.lsmt_status {
615-
FlagStatus::Disabled => {
616-
self.persist_to_file(&self.unflushed_delta, &storage_layout.base())
617-
}
618-
FlagStatus::Enabled => self.persist_to_overlay(
619-
&self.unflushed_delta,
620-
storage_layout,
621-
height,
622-
lsmt_config,
623-
metrics,
624-
),
625-
}
572+
self.persist_to_overlay(
573+
&self.unflushed_delta,
574+
storage_layout,
575+
height,
576+
lsmt_config,
577+
metrics,
578+
)
626579
}
627580

628581
fn persist_to_overlay(
@@ -903,66 +856,6 @@ impl PageMap {
903856
self.unflushed_delta.update(delta)
904857
}
905858

906-
/// Persists the given delta to the specified destination.
907-
fn persist_to_file(&self, page_delta: &PageDelta, dst: &Path) -> Result<(), PersistenceError> {
908-
let mut file = OpenOptions::new()
909-
.write(true)
910-
.create(true)
911-
.truncate(false)
912-
.open(dst)
913-
.map_err(|err| PersistenceError::FileSystemError {
914-
path: dst.display().to_string(),
915-
context: "Failed to open file".to_string(),
916-
internal_error: err.to_string(),
917-
})?;
918-
self.apply_delta_to_file(&mut file, page_delta, dst)?;
919-
Ok(())
920-
}
921-
922-
/// Applies the given delta to the specified file.
923-
/// Precondition: `file` is seekable and writeable.
924-
fn apply_delta_to_file(
925-
&self,
926-
file: &mut File,
927-
page_delta: &PageDelta,
928-
path: &Path,
929-
) -> Result<(), PersistenceError> {
930-
// Empty delta
931-
if page_delta.max_page_index().is_none() {
932-
return Ok(());
933-
}
934-
935-
let mut last_applied_index: Option<PageIndex> = None;
936-
let num_host_pages = self.num_host_pages() as u64;
937-
for (index, _) in page_delta.iter() {
938-
debug_assert!(self.page_delta.0.get(index).is_some());
939-
assert!(*index < num_host_pages.into());
940-
941-
if last_applied_index.is_some() && last_applied_index.unwrap() >= *index {
942-
continue;
943-
}
944-
945-
let bucket_start_index =
946-
PageIndex::from((index.get() / WRITE_BUCKET_PAGES) * WRITE_BUCKET_PAGES);
947-
let mut buffer = WriteBuffer {
948-
content: vec![],
949-
start_index: bucket_start_index,
950-
};
951-
for i in 0..WRITE_BUCKET_PAGES {
952-
let index_to_apply = PageIndex::from(bucket_start_index.get() + i);
953-
// We don't expand past the end of file to make bucketing transparent.
954-
if index_to_apply.get() < num_host_pages {
955-
let content = self.get_page(index_to_apply);
956-
buffer.content.push(content);
957-
last_applied_index = Some(index_to_apply);
958-
}
959-
}
960-
buffer.apply_to_file(file, path)?;
961-
}
962-
963-
Ok(())
964-
}
965-
966859
/// Returns the number of delta pages included in this PageMap.
967860
pub fn num_delta_pages(&self) -> usize {
968861
self.page_delta.len()

rs/replicated_state/src/page_map/storage/tests.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::page_map::{
1919
};
2020
use assert_matches::assert_matches;
2121
use bit_vec::BitVec;
22-
use ic_config::flag_status::FlagStatus;
2322
use ic_config::state_manager::LsmtConfig;
2423
use ic_metrics::MetricsRegistry;
2524
use ic_sys::{PageIndex, PAGE_SIZE};
@@ -475,26 +474,19 @@ fn write_overlay(
475474
delta,
476475
&storage_layout,
477476
height,
478-
&LsmtConfig {
479-
lsmt_status: FlagStatus::Enabled,
480-
shard_num_pages: u64::MAX,
481-
},
477+
&lsmt_config_unsharded(),
482478
metrics,
483479
)
484480
}
485481

486482
fn lsmt_config_unsharded() -> LsmtConfig {
487483
LsmtConfig {
488-
lsmt_status: FlagStatus::Enabled,
489484
shard_num_pages: u64::MAX,
490485
}
491486
}
492487

493488
fn lsmt_config_sharded() -> LsmtConfig {
494-
LsmtConfig {
495-
lsmt_status: FlagStatus::Enabled,
496-
shard_num_pages: 3,
497-
}
489+
LsmtConfig { shard_num_pages: 3 }
498490
}
499491

500492
/// This function applies `instructions` to a new `Storage` in a temporary directory.
@@ -913,10 +905,7 @@ fn wrong_shard_pages_is_an_error() {
913905
WriteOverlay((0..9).collect::<Vec<_>>()),
914906
WriteOverlay((0..9).collect::<Vec<_>>()),
915907
],
916-
&LsmtConfig {
917-
lsmt_status: FlagStatus::Enabled,
918-
shard_num_pages: 4,
919-
},
908+
&LsmtConfig { shard_num_pages: 4 },
920909
&tempdir,
921910
);
922911
let merge_candidates = MergeCandidate::new(
@@ -927,10 +916,7 @@ fn wrong_shard_pages_is_an_error() {
927916
},
928917
Height::from(0),
929918
9, /* num_pages */
930-
&LsmtConfig {
931-
lsmt_status: FlagStatus::Enabled,
932-
shard_num_pages: 3,
933-
},
919+
&LsmtConfig { shard_num_pages: 3 },
934920
&StorageMetrics::new(&MetricsRegistry::new()),
935921
)
936922
.unwrap();
@@ -1075,7 +1061,6 @@ fn test_make_none_merge_candidate() {
10751061
fn test_make_merge_candidates_to_overlay() {
10761062
let tempdir = tempdir().unwrap();
10771063
let lsmt_config = LsmtConfig {
1078-
lsmt_status: FlagStatus::Enabled,
10791064
shard_num_pages: 15,
10801065
};
10811066

@@ -1349,10 +1334,7 @@ fn can_write_shards() {
13491334

13501335
write_overlays_and_verify_with_tempdir(
13511336
instructions,
1352-
&LsmtConfig {
1353-
lsmt_status: FlagStatus::Enabled,
1354-
shard_num_pages: 1,
1355-
},
1337+
&LsmtConfig { shard_num_pages: 1 },
13561338
&tempdir,
13571339
);
13581340
let files = storage_files(tempdir.path());
@@ -1374,10 +1356,7 @@ fn overlapping_shards_is_an_error() {
13741356

13751357
write_overlays_and_verify_with_tempdir(
13761358
instructions,
1377-
&LsmtConfig {
1378-
lsmt_status: FlagStatus::Enabled,
1379-
shard_num_pages: 1,
1380-
},
1359+
&LsmtConfig { shard_num_pages: 1 },
13811360
&tempdir,
13821361
);
13831362
let files = storage_files(tempdir.path());

0 commit comments

Comments
 (0)