Skip to content

Commit 9ce2972

Browse files
inosmeetgitster
authored andcommitted
reftable: adapt writer_add_record() to propagate block_writer_add() errors
Previously, writer_add_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 writer_add_record() to inspect the error code returned by block_writer_add() and only flush and reinitialize the writer when the error is REFTABLE_ENTRY_TOO_BIG_ERROR. For any other error, immediately propagate it. Signed-off-by: Meet Soni <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2757168 commit 9ce2972

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

reftable/writer.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,12 @@ static int writer_add_record(struct reftable_writer *w,
310310
* done. Otherwise the block writer may have hit the block size limit
311311
* and needs to be flushed.
312312
*/
313-
if (!block_writer_add(w->block_writer, rec)) {
314-
err = 0;
313+
err = block_writer_add(w->block_writer, rec);
314+
if (err == 0)
315315
goto done;
316-
}
317316

317+
if (err != REFTABLE_ENTRY_TOO_BIG_ERROR)
318+
goto done;
318319
/*
319320
* The current block is full, so we need to flush and reinitialize the
320321
* writer to start writing the next block.
@@ -329,16 +330,10 @@ static int writer_add_record(struct reftable_writer *w,
329330
/*
330331
* Try to add the record to the writer again. If this still fails then
331332
* the record does not fit into the block size.
332-
*
333-
* TODO: it would be great to have `block_writer_add()` return proper
334-
* error codes so that we don't have to second-guess the failure
335-
* mode here.
336333
*/
337334
err = block_writer_add(w->block_writer, rec);
338-
if (err) {
339-
err = REFTABLE_ENTRY_TOO_BIG_ERROR;
335+
if (err)
340336
goto done;
341-
}
342337

343338
done:
344339
return err;

0 commit comments

Comments
 (0)