Skip to content

Commit 2259a0b

Browse files
authored
Merge pull request #1354 from spacejam/tyler_copy_error
Make Error Copy
2 parents e466bcc + 67c1ff1 commit 2259a0b

File tree

16 files changed

+96
-137
lines changed

16 files changed

+96
-137
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ jobs:
9898
- name: Cache target
9999
uses: actions/cache@v2
100100
env:
101-
cache-name: cache-stress2-target-and-lockfile
101+
cache-name: cache-stress2-asan-target-and-lockfile
102102
with:
103103
path: |
104104
benchmarks/stress2/target
105105
benchmarks/stress2/Cargo.lock
106+
~/.rustup
106107
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}
107108
- name: burn in
108109
run: |
@@ -111,8 +112,14 @@ jobs:
111112
ulimit -c unlimited
112113
echo "$PWD/core-dumps/corefile-%e-%p-%t" | sudo tee /proc/sys/kernel/core_pattern
113114
mkdir core-dumps
115+
rustup toolchain install nightly
116+
rustup toolchain install nightly --component rust-src
117+
rustup update
114118
rm -rf default.sled || true
115-
cargo run --release -- --duration=60
119+
export RUSTFLAGS="-Z sanitizer=address"
120+
export ASAN_OPTIONS="detect_odr_violation=0"
121+
cargo +nightly build --release --target x86_64-unknown-linux-gnu
122+
target/x86_64-unknown-linux-gnu/release/stress2 --duration=240
116123
rm -rf default.sled
117124
- name: print backtraces with gdb
118125
if: ${{ failure() }}

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
## Breaking Changes
2525

26-
* #1349 The "measure_allocs" feature has been removed.
2726
* #1135 The "no_metrics" anti-feature has been replaced with
2827
the "metrics" positive feature.
2928
* #1178 the `Event` enum has become a unified struct that allows
@@ -52,6 +51,9 @@
5251
* #1314 `Subscriber::next_timeout` now requires a mutable self
5352
reference.
5453
* #1337 Bump MSRV to 1.48.
54+
* #1349 The "measure_allocs" feature has been removed.
55+
* #1354 `Error` has been modified to be Copy, removing all
56+
heap-allocated variants.
5557

5658

5759
## Bug Fixes

src/config.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ impl StorageParameters {
6868
return Err(Error::Unsupported(
6969
"failed to open database that may \
7070
have been created using a sled version \
71-
earlier than 0.29"
72-
.to_string(),
71+
earlier than 0.29",
7372
));
7473
};
7574
let mut split = line.split(": ").map(String::from);
@@ -282,7 +281,7 @@ impl Inner {
282281
macro_rules! supported {
283282
($cond:expr, $msg:expr) => {
284283
if !$cond {
285-
return Err(Error::Unsupported($msg.to_owned()));
284+
return Err(Error::Unsupported($msg));
286285
}
287286
};
288287
}
@@ -550,15 +549,11 @@ impl Config {
550549
file.try_lock_exclusive()
551550
};
552551

553-
if let Err(e) = try_lock {
554-
return Err(Error::Io(io::Error::new(
552+
if try_lock.is_err() {
553+
return Err(Error::Io(
555554
ErrorKind::Other,
556-
format!(
557-
"could not acquire lock on {:?}: {:?}",
558-
self.db_path().to_string_lossy(),
559-
e
560-
),
561-
)));
555+
"could not acquire database file lock",
556+
));
562557
}
563558
}
564559

@@ -568,28 +563,27 @@ impl Config {
568563
fn verify_config(&self) -> Result<()> {
569564
match self.read_config() {
570565
Ok(Some(old)) => {
571-
supported!(
572-
self.use_compression == old.use_compression,
573-
format!(
574-
"cannot change compression values across restarts. \
575-
old value of use_compression loaded from disk: {}, \
576-
currently set value: {}.",
577-
old.use_compression, self.use_compression,
578-
)
579-
);
566+
if self.use_compression {
567+
supported!(
568+
old.use_compression,
569+
"cannot change compression configuration across restarts. \
570+
this database was created without compression enabled."
571+
);
572+
} else {
573+
supported!(
574+
!old.use_compression,
575+
"cannot change compression configuration across restarts. \
576+
this database was created with compression enabled."
577+
);
578+
}
580579

581580
supported!(
582581
self.segment_size == old.segment_size,
583-
format!(
584-
"cannot change the io buffer size across restarts. \
585-
please change it back to {}",
586-
old.segment_size
587-
)
582+
"cannot change the io buffer size across restarts."
588583
);
589584

590-
supported!(
591-
self.version == old.version,
592-
format!(
585+
if self.version != old.version {
586+
error!(
593587
"This database was created using \
594588
pagecache version {}.{}, but our pagecache \
595589
version is {}.{}. Please perform an upgrade \
@@ -599,8 +593,13 @@ impl Config {
599593
old.version.1,
600594
self.version.0,
601595
self.version.1,
602-
)
603-
);
596+
);
597+
supported!(
598+
self.version == old.version,
599+
"The stored database must use a compatible sled version.
600+
See error log for more details."
601+
);
602+
}
604603
Ok(())
605604
}
606605
Ok(None) => self.write_config(),
@@ -697,7 +696,7 @@ impl Config {
697696
} else {
698697
#[allow(unsafe_code)]
699698
unsafe {
700-
Err(ge.deref().clone())
699+
Err(*ge.deref())
701700
}
702701
}
703702
}

src/db.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ impl Db {
146146
pub fn drop_tree<V: AsRef<[u8]>>(&self, name: V) -> Result<bool> {
147147
let name_ref = name.as_ref();
148148
if name_ref == DEFAULT_TREE_ID {
149-
return Err(Error::Unsupported(
150-
"cannot remove the core structures".into(),
151-
));
149+
return Err(Error::Unsupported("cannot remove the default tree"));
152150
}
153151
trace!("dropping tree {:?}", name_ref,);
154152

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
// clippy::wildcard_enum_match_arm,
163163
)
164164
)]
165+
#![allow(clippy::comparison_chain)]
165166

166167
macro_rules! io_fail {
167168
($config:expr, $e:expr) => {

src/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
merge_operator: RwLock::new(None),
5555
})));
5656
}
57-
Err(Error::CollectionNotFound(_)) => {}
57+
Err(Error::CollectionNotFound) => {}
5858
Err(other) => return Err(other),
5959
}
6060

src/pagecache/iobuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ pub(in crate::pagecache) fn maybe_seal_and_write_iobuf(
12001200
match iobufs.with_sa(|sa| sa.next(next_lsn)) {
12011201
Ok(ret) => ret,
12021202
Err(e) => {
1203-
iobufs.set_global_error(e.clone());
1203+
iobufs.set_global_error(e);
12041204
return Err(e);
12051205
}
12061206
}

src/pagecache/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ fn check_contiguity_in_unstable_tail(
447447
};
448448

449449
// run the iterator to completion
450-
while let Some(_) = iter.next() {}
450+
for _ in &mut iter {}
451451

452452
// `cur_lsn` is set to the beginning
453453
// of the next message

src/pagecache/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Log {
118118
);
119119

120120
if let Err(e) = &ret {
121-
self.iobufs.set_global_error(e.clone());
121+
self.iobufs.set_global_error(*e);
122122
}
123123

124124
ret
@@ -169,7 +169,7 @@ impl Log {
169169
let ret = self.reserve_inner(log_kind, pid, item, None, guard);
170170

171171
if let Err(e) = &ret {
172-
self.iobufs.set_global_error(e.clone());
172+
self.iobufs.set_global_error(*e);
173173
}
174174

175175
ret

src/pagecache/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ impl PageCache {
840840
// changing.
841841
let ts = old.ts() + 1;
842842

843-
let cache_info = CacheInfo { lsn, pointer, ts };
843+
let cache_info = CacheInfo { ts, lsn, pointer };
844844

845845
let mut new_cache_infos =
846846
Vec::with_capacity(old.cache_infos.len() + 1);
@@ -944,13 +944,13 @@ impl PageCache {
944944
'inner: loop {
945945
let pg_view = self.inner.get(pid, &guard);
946946

947-
match &*pg_view.cache_infos {
948-
&[_single_cache_info] => {
947+
match *pg_view.cache_infos {
948+
[_single_cache_info] => {
949949
let page_state = pg_view.to_page_state();
950950
page_states.push(page_state);
951951
break 'inner;
952952
}
953-
&[_first_of_several, ..] => {
953+
[_first_of_several, ..] => {
954954
// If a page has multiple disk locations,
955955
// rewrite it to a single one before storing
956956
// a single 8-byte pointer to its cold location.
@@ -965,7 +965,7 @@ impl PageCache {
965965
}
966966
continue 'inner;
967967
}
968-
&[] => {
968+
[] => {
969969
// there is a benign race with the thread
970970
// that is allocating this page. the allocating
971971
// thread has not yet written the new page to disk,
@@ -1661,8 +1661,7 @@ impl PageCacheInner {
16611661
"{:?}",
16621662
Error::ReportableBug(
16631663
"failed to retrieve META page \
1664-
which should always be present"
1665-
.into(),
1664+
which should always be present"
16661665
)
16671666
)
16681667
}
@@ -1684,8 +1683,7 @@ impl PageCacheInner {
16841683
"{:?}",
16851684
Error::ReportableBug(
16861685
"failed to retrieve counter page \
1687-
which should always be present"
1688-
.into(),
1686+
which should always be present"
16891687
)
16901688
)
16911689
}
@@ -1904,7 +1902,7 @@ impl PageCacheInner {
19041902
if let Some(root) = m.get_root(name) {
19051903
Ok(root)
19061904
} else {
1907-
Err(Error::CollectionNotFound(name.into()))
1905+
Err(Error::CollectionNotFound)
19081906
}
19091907
}
19101908

@@ -1948,8 +1946,7 @@ impl PageCacheInner {
19481946
Err(None) => {
19491947
return Err(Error::ReportableBug(
19501948
"replacing the META page has failed because \
1951-
the pagecache does not think it currently exists."
1952-
.into(),
1949+
the pagecache does not think it currently exists.",
19531950
));
19541951
}
19551952
}
@@ -2088,10 +2085,10 @@ impl PageCacheInner {
20882085

20892086
// TODO this feels racy, test it better?
20902087
if let Update::Free = update {
2091-
Err(Error::ReportableBug(format!(
2092-
"non-link/replace found in pull of pid {}",
2093-
pid
2094-
)))
2088+
error!("non-link/replace found in pull of pid {}", pid);
2089+
Err(Error::ReportableBug(
2090+
"non-link/replace found in pull of page fragments",
2091+
))
20952092
} else {
20962093
Ok(update)
20972094
}

0 commit comments

Comments
 (0)