1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
use std::fmt::{self, Debug};
use crate::{
chunker::{Chunker, ChunkerGuard},
settings::Settings,
};
use super::{
buffer::SliceReadMode,
loaded::SliceBound,
operation::{SliceOperation, WriteOperation, WriteOperationState},
store::{BlockStore, BlockStoreInput, DataStore, ReadBlock},
types::{
Block, BlockId, BlockIndex, BlockList, BlockOffset, BlockSignature, FileId, FileOffset,
HoleLen, IndexedBlock,
},
};
pub struct ChunkingBlockStoreAdapter<Store> {
inner: Store,
chunker: ChunkerGuard,
settings: Settings,
}
#[cfg_attr(coverage_nightly, coverage(off))]
impl<Store> Debug for ChunkingBlockStoreAdapter<Store>
where
Store: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ChunkingBlockStoreAdapter")
.field("inner", &self.inner)
.field("settings", &self.settings)
.finish()
}
}
impl<Store> ChunkingBlockStoreAdapter<Store> {
pub fn new(inner: Store, chunker: impl Chunker + 'static, settings: Settings) -> Self {
Self {
inner,
chunker: ChunkerGuard::new(Box::new(chunker)),
settings,
}
}
}
/// The position of an offset within a block list.
///
/// When writing blocks to the block store, we often need to split existing blocks. This type helps
/// us understand where in the block list a given offset falls, so we can choose the right strategy
/// for handling the write.
#[derive(Debug, Clone)]
enum BlockListOffset {
/// The very start of the block list (i.e. offset 0).
AtStart,
/// Somewhere before the end of the block list, which could be in the middle of a block or at a
/// block boundary.
BeforeEnd {
index: BlockIndex,
offset_in_block: BlockOffset,
block: Block,
},
/// The very end of the block list, at the end of the final block.
AtEnd,
/// Beyond the end of the block list. In this situation, sparse holes are usually involved.
AfterEnd,
}
/// The position of a slice of blocks within a block list.
///
/// This enum allows us to be extremely explicit about how we handle each possible edge case when
/// writing a block to ensure we're not missing any.
#[derive(Debug, Clone)]
enum BlockListSlice {
/// The slice is empty (zero bytes).
Empty,
/// The slice starts at the beginning of the block list and ends at or after the last block.
FileStartToFileEnd { blocks: Vec<IndexedBlock> },
/// The slice starts at the beginning of the block list and ends at a block boundary.
FileStartToBlockBoundary { blocks: Vec<IndexedBlock> },
/// The slice starts at the beginning of the block list and ends in the middle of that same block.
FileStartToMidSameBlock {
block: IndexedBlock,
end_offset: BlockOffset,
},
/// The slice starts at the beginning of the block list and ends in the middle of a different
/// block.
FileStartToMidDifferentBlock {
blocks: Vec<IndexedBlock>,
end_offset: BlockOffset,
},
/// The slice starts at a block boundary and ends at or after the last block.
BlockBoundaryToFileEnd { blocks: Vec<IndexedBlock> },
/// The slice starts at a block boundary and ends at a different block boundary.
BlockBoundaryToBlockBoundary { blocks: Vec<IndexedBlock> },
/// The slice starts at a block boundary and ends in the middle of that same block.
BlockBoundaryToMidSameBlock {
block: IndexedBlock,
end_offset: BlockOffset,
},
/// The slice starts at a block boundary and ends in the middle of a different block.
BlockBoundaryToMidDifferentBlock {
blocks: Vec<IndexedBlock>,
end_offset: BlockOffset,
},
/// The slice starts in the middle of a block and ends at or after the last block.
MidBlockToFileEnd {
blocks: Vec<IndexedBlock>,
start_offset: BlockOffset,
},
/// The slice starts in the middle of a block and ends at the end of that same block.
MidBlockToBlockBoundary {
block: IndexedBlock,
start_offset: BlockOffset,
},
/// The slice starts in the middle of a block and ends in the middle of that same block.
MidBlockToMidSameBlock {
block: IndexedBlock,
start_offset: BlockOffset,
end_offset: BlockOffset,
},
/// The slice starts in the middle of a block and ends in the middle of a different block.
MidBlockToMidDifferentBlock {
blocks: Vec<IndexedBlock>,
start_offset: BlockOffset,
end_offset: BlockOffset,
},
/// The slice starts at the end of the last block.
Append,
/// The slice starts after the last block.
AppendWithHole { offset_after_end: BlockOffset },
}
impl BlockListSlice {
/// Returns `true` if any block in the slice is a hole.
///
/// When a slice contains hole blocks, the full re-chunking path is unsafe because the loaded
/// buffer omits the hole's implicit zero bytes — re-chunking would either panic on
/// out-of-bounds buffer access or destroy sparsity by materializing the holes as data.
fn contains_hole(&self) -> bool {
let is_hole =
|block: &IndexedBlock| matches!(block.block.signature, BlockSignature::Hole { .. });
match self {
BlockListSlice::Empty
| BlockListSlice::Append
| BlockListSlice::AppendWithHole { .. } => false,
BlockListSlice::FileStartToFileEnd { blocks }
| BlockListSlice::FileStartToBlockBoundary { blocks }
| BlockListSlice::FileStartToMidDifferentBlock { blocks, .. }
| BlockListSlice::BlockBoundaryToFileEnd { blocks }
| BlockListSlice::BlockBoundaryToBlockBoundary { blocks }
| BlockListSlice::BlockBoundaryToMidDifferentBlock { blocks, .. }
| BlockListSlice::MidBlockToFileEnd { blocks, .. }
| BlockListSlice::MidBlockToMidDifferentBlock { blocks, .. } => {
blocks.iter().any(is_hole)
}
BlockListSlice::FileStartToMidSameBlock { block, .. }
| BlockListSlice::BlockBoundaryToMidSameBlock { block, .. }
| BlockListSlice::MidBlockToBlockBoundary { block, .. }
| BlockListSlice::MidBlockToMidSameBlock { block, .. } => is_hole(block),
}
}
}
impl BlockList {
fn slice(&mut self, start: FileOffset, end: FileOffset) -> BlockListSlice {
if start == end {
return BlockListSlice::Empty;
}
let total_len = self.file_len();
if start > total_len {
return BlockListSlice::AppendWithHole {
offset_after_end: (start - total_len) as BlockOffset,
};
}
if start == total_len {
return BlockListSlice::Append;
}
// Find the block and offset where the start of the slice falls.
let mut offset_so_far: FileOffset = 0;
let mut start_block_index: BlockIndex = 0;
let mut start_offset_in_block: BlockOffset = 0;
for (i, block) in self.iter().enumerate() {
if offset_so_far + block.len() as FileOffset > start {
start_block_index = i;
start_offset_in_block = (start - offset_so_far) as BlockOffset;
break;
}
offset_so_far += block.len() as FileOffset;
}
// Determine if start is at a block boundary or the start of the file.
let start_at_boundary = start_offset_in_block == 0;
let start_at_file_start = start == 0;
// Find the block and offset where the end of the slice falls.
let mut end_block_index: BlockIndex = 0;
let mut end_offset_in_block: BlockOffset = 0;
// Determine if end is at a block boundary or the end of the file.
let mut end_at_boundary = false;
let end_at_or_after_file_end = end >= total_len;
if !end_at_or_after_file_end {
for (i, block) in self.iter().enumerate().skip(start_block_index) {
if offset_so_far + block.len() as FileOffset > end {
end_block_index = i;
end_offset_in_block = (end - offset_so_far) as BlockOffset;
end_at_boundary = false;
break;
} else if offset_so_far + block.len() as FileOffset == end {
end_block_index = i;
end_offset_in_block = block.len();
end_at_boundary = true;
break;
}
offset_so_far += block.len() as FileOffset;
}
}
let blocks = self
.iter()
.enumerate()
.map(|(i, block)| IndexedBlock {
index: i,
block: block.to_owned(),
})
.collect::<Vec<_>>();
match (
start_at_file_start,
start_at_boundary,
end_at_or_after_file_end,
) {
(true, _, true) => BlockListSlice::FileStartToFileEnd { blocks },
(true, _, false) if end_at_boundary => BlockListSlice::FileStartToBlockBoundary {
blocks: blocks
.get(..=end_block_index)
.expect("Out of bounds slicing block list.")
.to_vec(),
},
(true, _, false) if start_block_index == end_block_index => {
BlockListSlice::FileStartToMidSameBlock {
block: blocks
.get(start_block_index)
.expect("Out of bounds slicing block list.")
.clone(),
end_offset: end_offset_in_block,
}
}
(true, _, false) => BlockListSlice::FileStartToMidDifferentBlock {
blocks: blocks
.get(..=end_block_index)
.expect("Out of bounds slicing block list.")
.to_vec(),
end_offset: end_offset_in_block,
},
(false, true, true) => BlockListSlice::BlockBoundaryToFileEnd {
blocks: blocks
.get(start_block_index..)
.expect("Out of bounds slicing block list.")
.to_vec(),
},
(false, true, false) if end_at_boundary => {
BlockListSlice::BlockBoundaryToBlockBoundary {
blocks: blocks
.get(start_block_index..=end_block_index)
.expect("Out of bounds slicing block list.")
.to_vec(),
}
}
(false, true, false) if start_block_index == end_block_index => {
BlockListSlice::BlockBoundaryToMidSameBlock {
block: blocks
.get(start_block_index)
.expect("Out of bounds slicing block list.")
.clone(),
end_offset: end_offset_in_block,
}
}
(false, true, false) => BlockListSlice::BlockBoundaryToMidDifferentBlock {
blocks: blocks
.get(start_block_index..=end_block_index)
.expect("Out of bounds slicing block list.")
.to_vec(),
end_offset: end_offset_in_block,
},
(false, false, true) => BlockListSlice::MidBlockToFileEnd {
blocks: blocks
.get(start_block_index..)
.expect("Out of bounds slicing block list.")
.to_vec(),
start_offset: start_offset_in_block,
},
(false, false, false) if start_block_index == end_block_index => {
if end_offset_in_block
== blocks
.get(start_block_index)
.expect("Out of bounds slicing block list.")
.block
.len()
{
BlockListSlice::MidBlockToBlockBoundary {
block: blocks
.get(start_block_index)
.expect("Out of bounds slicing block list.")
.clone(),
start_offset: start_offset_in_block,
}
} else {
BlockListSlice::MidBlockToMidSameBlock {
block: blocks
.get(start_block_index)
.expect("Out of bounds slicing block list.")
.clone(),
start_offset: start_offset_in_block,
end_offset: end_offset_in_block,
}
}
}
(false, false, false) => BlockListSlice::MidBlockToMidDifferentBlock {
blocks: blocks
.get(start_block_index..=end_block_index)
.expect("Out of bounds slicing block list.")
.to_vec(),
start_offset: start_offset_in_block,
end_offset: end_offset_in_block,
},
}
}
}
impl BlockList {
fn block_at_offset(&self, offset: FileOffset) -> BlockListOffset {
if offset == 0 {
return BlockListOffset::AtStart;
}
let mut bytes_so_far: FileOffset = 0;
let mut block_iter = self.iter().enumerate().peekable();
while let Some((_, block)) = block_iter.peek() {
if bytes_so_far + block.len() as FileOffset > offset {
break;
}
bytes_so_far += block.len() as FileOffset;
block_iter.next();
}
match block_iter.next() {
None if offset == bytes_so_far => BlockListOffset::AtEnd,
None if offset > bytes_so_far => BlockListOffset::AfterEnd,
Some((index, block)) => BlockListOffset::BeforeEnd {
index,
offset_in_block: (offset - bytes_so_far) as BlockOffset,
block: block.to_owned(),
},
_ => unreachable!(
"By this point, we should have verified that thet offset is before the end of the block list."
),
}
}
}
impl<'a> BlockStoreInput<'a> {
pub fn into_block(self, block_id: BlockId) -> Block {
match self {
BlockStoreInput::Data {
bytes,
hash,
len: logical_len,
..
} => Block {
id: block_id,
signature: BlockSignature::Data {
hash,
len: logical_len.unwrap_or(bytes.len()),
},
},
BlockStoreInput::Hole { len } => Block {
id: block_id,
signature: BlockSignature::Hole { len },
},
}
}
}
impl<Store> ChunkingBlockStoreAdapter<Store>
where
Store: BlockStore,
{
fn new_op<'a>(&'a mut self, file: FileId, block_list: BlockList) -> WriteOperation<'a, Store> {
WriteOperation::new(&mut self.inner, WriteOperationState::new(file, block_list))
}
fn new_slice_op<'a>(
&'a mut self,
file: FileId,
block_list: BlockList,
) -> SliceOperation<'a, Store> {
SliceOperation::new(
&mut self.inner,
WriteOperationState::new(file, block_list),
&mut self.chunker,
)
}
}
impl<Store> BlockStore for ChunkingBlockStoreAdapter<Store>
where
Store: BlockStore,
{
fn list_blocks(&self, file: FileId) -> crate::Result<BlockList> {
self.inner.list_blocks(file)
}
fn read_block(&mut self, block: BlockId, buf: &mut Vec<u8>) -> crate::Result<ReadBlock> {
self.inner.read_block(block, buf)
}
fn replace_block(
&mut self,
file: FileId,
index: BlockIndex,
input: BlockStoreInput,
) -> crate::Result<BlockId> {
self.inner.replace_block(file, index, input)
}
fn insert_block(
&mut self,
file: FileId,
index: BlockIndex,
input: BlockStoreInput,
) -> crate::Result<BlockId> {
self.inner.insert_block(file, index, input)
}
fn append_block(
&mut self,
file: FileId,
index: BlockIndex,
input: BlockStoreInput,
) -> crate::Result<BlockId> {
self.inner.append_block(file, index, input)
}
fn remove_blocks<R: std::ops::RangeBounds<usize>>(
&mut self,
file: FileId,
blocks: R,
) -> crate::Result<Vec<BlockId>> {
self.inner.remove_blocks(file, blocks)
}
}
impl<Store> DataStore for ChunkingBlockStoreAdapter<Store>
where
Store: BlockStore,
{
fn list_blocks(&mut self, file: FileId) -> crate::Result<BlockList> {
self.inner.list_blocks(file)
}
fn read_block(&mut self, block: BlockId, buf: &mut Vec<u8>) -> crate::Result<ReadBlock> {
self.inner.read_block(block, buf)
}
fn write_block(
&mut self,
file: FileId,
offset: FileOffset,
mut block_list: BlockList,
input: BlockStoreInput,
) -> crate::Result<BlockList> {
if input.len() == 0 {
return self.inner.list_blocks(file);
}
let block_slice = block_list
.slice(offset, offset + input.len() as FileOffset)
.clone();
// The full re-chunking path cannot be used when the slice contains hole blocks: it would
// either index out of bounds (the loaded buffer omits implicit hole bytes) or destroy
// sparsity by absorbing the holes into newly chunked data blocks. The partial path splits
// each hole at the splice boundary, preserving sparsity on either side of the write.
let read_mode =
if input.len() < self.settings.small_write_threshold || block_slice.contains_hole() {
SliceReadMode::Partial
} else {
SliceReadMode::Full
};
let mut op = self.new_slice_op(file, block_list);
match block_slice {
BlockListSlice::Empty => Ok(op.into_inner().finish()),
BlockListSlice::FileStartToFileEnd { blocks } => {
op.as_mut().replace_blocks(0..blocks.len(), input)?;
Ok(op.into_inner().finish())
}
BlockListSlice::FileStartToBlockBoundary { blocks } => Ok(op
.read_slice(blocks, read_mode)?
.splice(SliceBound::SliceStart, SliceBound::SliceEnd, input)?
.finish()),
BlockListSlice::FileStartToMidSameBlock { block, end_offset } => {
let block_index = block.index;
Ok(op
.read_slice(vec![block], read_mode)?
.splice(
SliceBound::SliceStart,
SliceBound::BlockOffset {
index: block_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::FileStartToMidDifferentBlock { blocks, end_offset } => {
let end_index = blocks.len() as BlockIndex - 1;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::SliceStart,
SliceBound::BlockOffset {
index: end_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::BlockBoundaryToFileEnd { blocks } => {
let start_index = blocks
.first()
.expect("Block list unexpectedly empty.")
.index;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::BlockOffset {
index: start_index,
offset: 0,
},
SliceBound::SliceEnd,
input,
)?
.finish())
}
BlockListSlice::BlockBoundaryToBlockBoundary { blocks } => {
let start_index = blocks
.first()
.expect("Block list unexpectedly empty.")
.index;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::BlockOffset {
index: start_index,
offset: 0,
},
SliceBound::SliceEnd,
input,
)?
.finish())
}
BlockListSlice::BlockBoundaryToMidSameBlock { block, end_offset } => {
let block_index = block.index;
Ok(op
.read_slice(vec![block], read_mode)?
.splice(
SliceBound::BlockOffset {
index: block_index,
offset: 0,
},
SliceBound::BlockOffset {
index: block_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::BlockBoundaryToMidDifferentBlock { blocks, end_offset } => {
let start_index = blocks
.first()
.expect("Block list unexpectedly empty.")
.index;
let end_index = blocks.last().expect("Block list unexpectedly empty.").index;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::BlockOffset {
index: start_index,
offset: 0,
},
SliceBound::BlockOffset {
index: end_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::MidBlockToFileEnd {
blocks,
start_offset,
} => {
let start_index = blocks
.first()
.expect("Block list unexpectedly empty.")
.index;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::BlockOffset {
index: start_index,
offset: start_offset,
},
SliceBound::SliceEnd,
input,
)?
.finish())
}
BlockListSlice::MidBlockToBlockBoundary {
block,
start_offset,
} => {
let block_index = block.index;
let end_offset = block.block.len();
Ok(op
.read_slice(vec![block], read_mode)?
.splice(
SliceBound::BlockOffset {
index: block_index,
offset: start_offset,
},
SliceBound::BlockOffset {
index: block_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::MidBlockToMidSameBlock {
block,
start_offset,
end_offset,
} => {
let block_index = block.index;
Ok(op
.read_slice(vec![block], read_mode)?
.splice(
SliceBound::BlockOffset {
index: block_index,
offset: start_offset,
},
SliceBound::BlockOffset {
index: block_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::MidBlockToMidDifferentBlock {
blocks,
start_offset,
end_offset,
} => {
let start_index = blocks
.first()
.expect("Block list unexpectedly empty.")
.index;
let end_index = blocks.last().expect("Block list unexpectedly empty.").index;
Ok(op
.read_slice(blocks, read_mode)?
.splice(
SliceBound::BlockOffset {
index: start_index,
offset: start_offset,
},
SliceBound::BlockOffset {
index: end_index,
offset: end_offset,
},
input,
)?
.finish())
}
BlockListSlice::Append => {
let len = op.as_ref().len();
op.as_mut().insert_block(len, input)?;
Ok(op.into_inner().finish())
}
BlockListSlice::AppendWithHole { offset_after_end } => {
let len = op.as_ref().len();
op.as_mut().insert_block(
len,
BlockStoreInput::Hole {
len: offset_after_end as HoleLen,
},
)?;
let len = op.as_ref().len();
op.as_mut().insert_block(len, input)?;
Ok(op.into_inner().finish())
}
}
}
fn truncate(
&mut self,
file: FileId,
block_list: BlockList,
len: FileOffset,
) -> crate::Result<BlockList> {
let block_list_len = block_list.len();
let block_at_offset = block_list.block_at_offset(len).clone();
let mut op = self.new_op(file, block_list);
match block_at_offset {
// No truncation needed. The file is already smaller than or equal to the requested
// length.
BlockListOffset::AtEnd | BlockListOffset::AfterEnd => Ok(op.finish()),
// Truncate the entire file.
BlockListOffset::AtStart => {
op.remove_blocks(0..block_list_len)?;
Ok(BlockList::new(Vec::new()))
}
// The truncation point is exactly at a block boundary, so we can just remove all
// blocks after the split index.
BlockListOffset::BeforeEnd {
index,
offset_in_block: 0,
..
} => {
op.remove_blocks(index..block_list_len)?;
Ok(op.finish())
}
// The length we're truncating the file to falls in the middle of a block. So, we need
// to:
//
// 1. Find the block that needs split.
// 2. Read that block's data in from the store (if it's a data block).
// 3. Replace the block with a truncated copy.
// 4. Remove all blocks after it.
BlockListOffset::BeforeEnd {
index: split_index,
block: split_block,
offset_in_block: split_index_in_block,
..
} => {
let split_block = op.read_block(&split_block)?;
let op = split_block.truncate(split_index, split_index_in_block)?;
Ok(op.finish())
}
}
}
}