Skip to content

Commit 0e1b9c5

Browse files
inosmeetgitster
authored andcommitted
reftable: adapt write_object_record() to propagate block_writer_add() errors
Previously, write_object_record() would flush the current block and retry appending the record whenever block_writer_add() returned any nonzero error. This forced an assumption that every failure meant the block was full, even when errors such as memory allocation or I/O failures occurred. Update the write_object_record() to inspect the error code returned by block_writer_add() and flush and reinitialize the writer iff the error is REFTABLE_ENTRY_TOO_BIG_ERROR. For any other error, immediately propagate it. If the flush and reinitialization still fail with REFTABLE_ENTRY_TOO_BIG_ERROR, reset the record's offset length to zero before a final attempt. All call sites now handle various error codes returned by block_writer_add(). Signed-off-by: Meet Soni <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ce2972 commit 0e1b9c5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

reftable/writer.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,22 @@ static void write_object_record(void *void_arg, void *key)
620620
if (arg->err < 0)
621621
goto done;
622622

623+
/*
624+
* Try to add the record to the writer. If this succeeds then we're
625+
* done. Otherwise the block writer may have hit the block size limit
626+
* and needs to be flushed.
627+
*/
623628
arg->err = block_writer_add(arg->w->block_writer, &rec);
624629
if (arg->err == 0)
625630
goto done;
626631

632+
if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR)
633+
goto done;
634+
635+
/*
636+
* The current block is full, so we need to flush and reinitialize the
637+
* writer to start writing the next block.
638+
*/
627639
arg->err = writer_flush_block(arg->w);
628640
if (arg->err < 0)
629641
goto done;
@@ -632,10 +644,17 @@ static void write_object_record(void *void_arg, void *key)
632644
if (arg->err < 0)
633645
goto done;
634646

647+
/*
648+
* If this still fails then we may need to reset record's offset
649+
* length to reduce the data size to be written.
650+
*/
635651
arg->err = block_writer_add(arg->w->block_writer, &rec);
636652
if (arg->err == 0)
637653
goto done;
638654

655+
if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR)
656+
goto done;
657+
639658
rec.u.obj.offset_len = 0;
640659
arg->err = block_writer_add(arg->w->block_writer, &rec);
641660

0 commit comments

Comments
 (0)