diff options
| author | Meet Soni <meetsoni3017@gmail.com> | 2025-03-19 20:59:27 +0530 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-03-21 01:51:08 -0700 |
| commit | 0e1b9c5eed8bfc091570cc93bd15d3c235d15971 (patch) | |
| tree | 5f21c7c59e57fcdd6858c3489f9e207f232d73f9 | |
| parent | 9ce297239b94ca6bc671b629246711d0ebf096ef (diff) | |
| download | git-0e1b9c5eed8bfc091570cc93bd15d3c235d15971.tar.xz | |
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 <meetsoni3017@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
| -rw-r--r-- | reftable/writer.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/reftable/writer.c b/reftable/writer.c index 94c97b7ac0..f48e7cc290 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -620,10 +620,22 @@ static void write_object_record(void *void_arg, void *key) if (arg->err < 0) goto done; + /* + * Try to add the record to the writer. If this succeeds then we're + * done. Otherwise the block writer may have hit the block size limit + * and needs to be flushed. + */ arg->err = block_writer_add(arg->w->block_writer, &rec); if (arg->err == 0) goto done; + if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR) + goto done; + + /* + * The current block is full, so we need to flush and reinitialize the + * writer to start writing the next block. + */ arg->err = writer_flush_block(arg->w); if (arg->err < 0) goto done; @@ -632,10 +644,17 @@ static void write_object_record(void *void_arg, void *key) if (arg->err < 0) goto done; + /* + * If this still fails then we may need to reset record's offset + * length to reduce the data size to be written. + */ arg->err = block_writer_add(arg->w->block_writer, &rec); if (arg->err == 0) goto done; + if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR) + goto done; + rec.u.obj.offset_len = 0; arg->err = block_writer_add(arg->w->block_writer, &rec); |
