Fix bug in dictinary creation

This commit is contained in:
Konstantin Knizhnik
2022-04-30 00:41:04 +03:00
parent fc7d1ba043
commit 0e49d748b8
2 changed files with 12 additions and 7 deletions

View File

@@ -1989,13 +1989,17 @@ impl LayeredTimeline {
prefetched.push((key, lsn, value));
while let Some(y) = all_values_iter.next() {
let (key, lsn, value) = y?;
samples.push(Value::ser(&value)?);
prefetched.push((key, lsn, value));
if samples.len() == config::ZSTD_MAX_SAMPLES {
if let Ok((key, lsn, value)) = y {
samples.push(Value::ser(&value)?);
prefetched.push((key, lsn, value));
if samples.len() == config::ZSTD_MAX_SAMPLES {
break;
}
} else {
break;
}
}
let dictionary = if samples.len() >= config::ZSTD_MIN_SAMPLES {
zstd::dict::from_samples(&samples, config::ZSTD_MAX_DICTIONARY_SIZE)?
} else {

View File

@@ -327,17 +327,18 @@ impl InMemoryLayer {
let mut cursor = inner.file.block_cursor();
// First learn dictionary */
for (_key, vec_map) in keys.iter() {
// First learn dictionary
'train: for (_key, vec_map) in keys.iter() {
// Write all page versions
for (_lsn, pos) in vec_map.as_slice() {
cursor.read_blob_into_buf(*pos, &mut buf)?;
samples.push(buf.clone());
if samples.len() == config::ZSTD_MAX_SAMPLES {
break;
break 'train;
}
}
}
let dictionary = if samples.len() >= config::ZSTD_MIN_SAMPLES {
zstd::dict::from_samples(&samples, config::ZSTD_MAX_DICTIONARY_SIZE)?
} else {