From patchwork Wed Mar 19 15:29:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022777 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67DB61C9B62 for ; Wed, 19 Mar 2025 15:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398190; cv=none; b=UPt+6w+/z2pVb+nuKVrEnv0+OD9gFgq5ZQPq4kJXDzQiemN4vt3Vg6RH8TBwSt/M4BJUzXCPaJgtJXR967lALufUFd5z9reennDan8ka4KfgAtuvC41vZs/ZNl0yZ5Bu2eK+UgfTrmehQYaSFUszkKS8wA9MUrLzlBX+/uUbGqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398190; c=relaxed/simple; bh=eCqJmXbmnfHlqtGyzxAU4mH0rtHKpAbQZBB8F0dK7xA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RJjRa+yVEetpa+QMaAO6zrIvSVLJCAGOotKkOl/eaCpidNBFqCh0jerD3FekgwCgZ6y2AgY3avW2A0ABqAgaU0QjOlAv6Dxv2yyRBjO7q9dg0PC8Y9S3R6EntP/AIDdPBpmjWvp8GtEVuBD+1FgIX3XnuC9NlopgELyFeiVCMzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TsblhUDS; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TsblhUDS" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-225fbdfc17dso72576045ad.3 for ; Wed, 19 Mar 2025 08:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742398186; x=1743002986; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pojrb7k0iUaf6SLCizu6NSGr3KjLGA0sCocaSPwq2A8=; b=TsblhUDSiuWypNxpJfjKyaO7oHSMFIkhMamEGtLAXEi23z0J56usQL5P5cJwkaBO4d pvbc01EUf3YHmRXrIX6j8/G6hVEgrOqTOB2Ywl0CtF3Q9AIVsJBZ97GJtx1xOoPIPMmH 4hs3ltrvGoD8aewKVLV7E8xezc5snQihJJ17kVWiHk2X7otJsSuvQ1fIxJKzuh1Rlz11 3i+u1iHsRCy24HWJyYOz/FvjmK5iz+oKv4tPcnKOq+ciXOjvx2X+/n20/mgN5avOBlJ8 VLdBdzkfbeFY7QzYs+hB0OrH/hCaI7GmK5mY731ls03+zOngFiWVkO+knnlKNn58O33i PACQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742398186; x=1743002986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pojrb7k0iUaf6SLCizu6NSGr3KjLGA0sCocaSPwq2A8=; b=RezHFclM+TzN3x5Ccc6JRzQKOFbPr6IbHVtR/3dGPUK0tJB+3bbhHj3SOtIzulUpQx sU+dpO7DOZDG/tUH6obpzDGKzC2gwE3uggV+KmgYh55RAe0nGy6Nw66s55ugx/jCkf+K F/n7kdzniJTIh85HI/y7Z2BR8OrDFtm+GBgcX7eaOGZa0ng5zW/gtKsyqDJe0q3CzDqs R6RiUhEqYT3Go4lpOx/PQ3/rt1t2uOEv/4XHc72uOe3X0mt4Aru+46V8Ff5LcYcaMx24 WSzcKHsbmPGVcUoXUAhkCF+6Igrv1yPvQp7JBH3EUTdYbRUBRIA0cLVfs3GKFBBiUtTM Y5Dg== X-Gm-Message-State: AOJu0YxbvTkKzPirjgXlIhuWS9n7OCPMSDiL6h/ARqriLXx7SCe3jSHB pKiqIAePhzJDeUhHGTArtjuz8GENKXBxOYnO2Feq907cc2b/9S1YHZ3wOg== X-Gm-Gg: ASbGncs0439XNDbY6/8Dfio6NU1yCI42LQE+nIRUDueKzTE+8Sh5UsmdvpqAAxkNSb3 7vPEeKcSwSXv3naZs7NW5jLGM5+MQrJfupgpgQyR2zS383LjdxcqcKC02Bb6gfETFWJbqeEkHff 4RMDexp3dy3w7SMsszFdsWM0Ye+RdGzjPjEjTkWQ8hqCZNdieUa86GXn8vkRtwEuDJ0n0ZZX3+B YpzAwJhaK3qnM1vMxJrIHdpYjjyNdxtv2bnICazmtdeCuJwaviuEqoekGNSeSjO1JjWIqc/99+s p+VPmN2WEZtDzHwT/TWJAXnNkCWXHdIYtFhpnvjl X-Google-Smtp-Source: AGHT+IFuuMwwgDTeMR6uPVlgK71oNapLKnrdk3fiIzlwYiNNTdHQbfESzWEfKwicJMTDazQ75U4HsQ== X-Received: by 2002:a17:902:e80c:b0:224:2201:84da with SMTP id d9443c01a7336-2264981b269mr40120955ad.6.1742398186127; Wed, 19 Mar 2025 08:29:46 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c68a6865sm115889305ad.75.2025.03.19.08.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 08:29:45 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [GSoC PATCH v5 1/3] reftable: propagate specific error codes in block_writer_add() Date: Wed, 19 Mar 2025 20:59:25 +0530 Message-Id: <20250319152927.1263033-2-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319152927.1263033-1-meetsoni3017@gmail.com> References: <20250319075943.28904-1-meetsoni3017@gmail.com> <20250319152927.1263033-1-meetsoni3017@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously, functions block_writer_add() and related functions returned -1 when the record did not fit, forcing the caller to assume that any failure meant the entry was too big. Replace these generic -1 returns with defined error codes. This prepares the codebase for finer-grained error handling so that callers can distinguish between a block-full condition and other errors. Signed-off-by: Meet Soni --- reftable/block.c | 13 ++++++------ reftable/block.h | 2 +- reftable/record.c | 53 +++++++++++++++++++++-------------------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/reftable/block.c b/reftable/block.c index b14a8f1259..0b8ebc3aa5 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -49,7 +49,7 @@ static int block_writer_register_restart(struct block_writer *w, int n, if (is_restart) rlen++; if (2 + 3 * rlen + n > w->block_size - w->next) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; if (is_restart) { REFTABLE_ALLOC_GROW_OR_NULL(w->restarts, w->restart_len + 1, w->restart_cap); @@ -97,9 +97,10 @@ uint8_t block_writer_type(struct block_writer *bw) return bw->block[bw->header_off]; } -/* Adds the reftable_record to the block. Returns -1 if it does not fit, 0 on - success. Returns REFTABLE_API_ERROR if attempting to write a record with - empty key. */ +/* + * Adds the reftable_record to the block. Returns 0 on success and + * appropriate error codes on failure. + */ int block_writer_add(struct block_writer *w, struct reftable_record *rec) { struct reftable_buf empty = REFTABLE_BUF_INIT; @@ -126,14 +127,14 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) n = reftable_encode_key(&is_restart, out, last, w->scratch, reftable_record_val_type(rec)); if (n < 0) { - err = -1; + err = n; goto done; } string_view_consume(&out, n); n = reftable_record_encode(rec, out, w->hash_size); if (n < 0) { - err = -1; + err = n; goto done; } string_view_consume(&out, n); diff --git a/reftable/block.h b/reftable/block.h index bef2b8a4c5..64732eba7d 100644 --- a/reftable/block.h +++ b/reftable/block.h @@ -53,7 +53,7 @@ int block_writer_init(struct block_writer *bw, uint8_t typ, uint8_t *block, /* returns the block type (eg. 'r' for ref records. */ uint8_t block_writer_type(struct block_writer *bw); -/* appends the record, or -1 if it doesn't fit. */ +/* Attempts to append the record. Returns 0 on success or error code on failure. */ int block_writer_add(struct block_writer *w, struct reftable_record *rec); /* appends the key restarts, and compress the block if necessary. */ diff --git a/reftable/record.c b/reftable/record.c index 8919df8a4d..d9fba8ff38 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -61,7 +61,7 @@ int put_var_int(struct string_view *dest, uint64_t value) while (value >>= 7) varint[--pos] = 0x80 | (--value & 0x7f); if (dest->len < sizeof(varint) - pos) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(dest->buf, varint + pos, sizeof(varint) - pos); return sizeof(varint) - pos; } @@ -129,10 +129,10 @@ static int encode_string(const char *str, struct string_view s) size_t l = strlen(str); int n = put_var_int(&s, l); if (n < 0) - return -1; + return n; string_view_consume(&s, n); if (s.len < l) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(s.buf, str, l); string_view_consume(&s, l); @@ -148,18 +148,18 @@ int reftable_encode_key(int *restart, struct string_view dest, uint64_t suffix_len = key.len - prefix_len; int n = put_var_int(&dest, prefix_len); if (n < 0) - return -1; + return n; string_view_consume(&dest, n); *restart = (prefix_len == 0); n = put_var_int(&dest, suffix_len << 3 | (uint64_t)extra); if (n < 0) - return -1; + return n; string_view_consume(&dest, n); if (dest.len < suffix_len) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(dest.buf, key.buf + prefix_len, suffix_len); string_view_consume(&dest, suffix_len); @@ -324,30 +324,27 @@ static int reftable_ref_record_encode(const void *rec, struct string_view s, struct string_view start = s; int n = put_var_int(&s, r->update_index); if (n < 0) - return -1; + return n; string_view_consume(&s, n); switch (r->value_type) { case REFTABLE_REF_SYMREF: n = encode_string(r->value.symref, s); - if (n < 0) { - return -1; - } + if (n < 0) + return n; string_view_consume(&s, n); break; case REFTABLE_REF_VAL2: - if (s.len < 2 * hash_size) { - return -1; - } + if (s.len < 2 * hash_size) + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(s.buf, r->value.val2.value, hash_size); string_view_consume(&s, hash_size); memcpy(s.buf, r->value.val2.target_value, hash_size); string_view_consume(&s, hash_size); break; case REFTABLE_REF_VAL1: - if (s.len < hash_size) { - return -1; - } + if (s.len < hash_size) + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(s.buf, r->value.val1, hash_size); string_view_consume(&s, hash_size); break; @@ -531,24 +528,22 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s, uint64_t last = 0; if (r->offset_len == 0 || r->offset_len >= 8) { n = put_var_int(&s, r->offset_len); - if (n < 0) { - return -1; - } + if (n < 0) + return n; string_view_consume(&s, n); } if (r->offset_len == 0) return start.len - s.len; n = put_var_int(&s, r->offsets[0]); if (n < 0) - return -1; + return n; string_view_consume(&s, n); last = r->offsets[0]; for (i = 1; i < r->offset_len; i++) { int n = put_var_int(&s, r->offsets[i] - last); - if (n < 0) { - return -1; - } + if (n < 0) + return n; string_view_consume(&s, n); last = r->offsets[i]; } @@ -783,7 +778,7 @@ static int reftable_log_record_encode(const void *rec, struct string_view s, return 0; if (s.len < 2 * hash_size) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; memcpy(s.buf, r->value.update.old_hash, hash_size); memcpy(s.buf + hash_size, r->value.update.new_hash, hash_size); @@ -791,22 +786,22 @@ static int reftable_log_record_encode(const void *rec, struct string_view s, n = encode_string(r->value.update.name ? r->value.update.name : "", s); if (n < 0) - return -1; + return n; string_view_consume(&s, n); n = encode_string(r->value.update.email ? r->value.update.email : "", s); if (n < 0) - return -1; + return n; string_view_consume(&s, n); n = put_var_int(&s, r->value.update.time); if (n < 0) - return -1; + return n; string_view_consume(&s, n); if (s.len < 2) - return -1; + return REFTABLE_ENTRY_TOO_BIG_ERROR; put_be16(s.buf, r->value.update.tz_offset); string_view_consume(&s, 2); @@ -814,7 +809,7 @@ static int reftable_log_record_encode(const void *rec, struct string_view s, n = encode_string( r->value.update.message ? r->value.update.message : "", s); if (n < 0) - return -1; + return n; string_view_consume(&s, n); return start.len - s.len; From patchwork Wed Mar 19 15:29:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022778 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACB791CCEE2 for ; Wed, 19 Mar 2025 15:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398191; cv=none; b=j8CNtexs0ch4BFGoAL9IADID6ZvLJBMkJx5ckMEzXtDUJgtyg+Ue5CLqCtBcJLnhibh992IA6Ucrs+pCcOtXxRsgqcGj5wmWY1g7aVR1LCOJeHiQ+jaJvzionKYRsCrfQM2WsTsrTr3MuwLPBXZ+7O2p1ujQvFZalmV6bcTiqnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398191; c=relaxed/simple; bh=xCsELOKJo2yITodFA7dw4PRpeGmlM6nRVS4bmwdVDzc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HrD4SyuONDvr42bk13LBWZug81hZcfyrGB1YFN0rQ91vqWFDhjFCtmLx23rSbvsyBnys8+J3K9XK0XWA+9dNl7S12aDGMX/m+22F1kP4jkS37vsviOCQncQzYA++l39nx3U5D7E4qkwtQoLQ/ssp66Y3FIq061UK1qOUt0hkV80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bR/leRQc; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bR/leRQc" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2235189adaeso18625825ad.0 for ; Wed, 19 Mar 2025 08:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742398188; x=1743002988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NdQ5HRVrF38ciU+o2i2T+yki11qh40uKQL0iG8b5D0U=; b=bR/leRQcKUB/yQoVCQmV+3AF+N2BcdVj/qoTi73lfapkfk7Om+eEJiB9A26Lr1AD26 AgTQtwsNNiCUQpAvW3/34fyiLEkj6Vw+NoU6yNaQrcagElLBW4Ahvr0rfESWVXxRiQ/g 1JgYh7ATi7dh3LGQ9HkVy1ahd7w+9FsTAB8+oOLx51kIyVliIoZIXJ3XC+UcWhX2Ejhg pRm6CTlsREPND/8/VxiTKJbch7GNv9ZcRGfjVYr0p8U4FcCRUMyAB701ZjOkiRCVsby6 AOa3od8lYuMhRV+Ki5ZB29REDe/Vf541FA9V/lyUa27QSbiFeOMFFcsOF/MdRsGO6PYW gnaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742398188; x=1743002988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NdQ5HRVrF38ciU+o2i2T+yki11qh40uKQL0iG8b5D0U=; b=dF0Lr6l1ny/cqeRMV5mfIxmEMlNBHHbGGPHDe/c0rHA9vK6LW3ArX2oianrCF3lPMt sRnR8aYyWGqF50mop8Hj9gGq5lbiI/fQPT53puRj8VQMRa1p3yIx1dPlPf4+vLBmoPBQ KjsDZ6jn6YTT1nkM7psyazD8kxdZ+fFXc3AHJMpcftGy6b4OmyOjBRlraJkICdhjejGh LuWUzQwGvw7E0jcNgYPIuw1CaJVRi5L6BUlD+EBC06raCtDDmY9MkWs006i2rQfVBQ0J Vbo5IJxxEg8Y1uRbmKdu7rh/U7Mq2NOnqbxtJVVRnSYXAY51x8FOlTWkZ5TRvrdT8bz5 pWfA== X-Gm-Message-State: AOJu0Yx3QK/tTwY9bP7tUwCkdSr/OL2pEiiIzF3MPjEhAEdK/6tJXyws tDDqKbtOnP62Fh1AxMnDk3gfFUpTEmZUoNu/lAFuVeWE/jYE/wmaQ0bOTg== X-Gm-Gg: ASbGncuPFJDGRfZgw4UduCYbNQ/Zlb1KvJner6vB62vAK/U8iII2+y79Zw54a6y9gvC I8hh38JioGkZZxmWcPWULsidderX0JiBr3uKbd/QtotfyEZZrY5hw+XukJiFTHULrex7NpmoJSb bIWiMY82BxA3YGIj5cRKQgETY+ctWeAwQFBTKPQnbVt5S0t4CaAxwuIyMoh0zgUbv+gd7lbltmf gr/xR9QViKfVBbJLpqvOPem1Itx/zztXw0JiVQJWyd8dMvEDpmU5IIZg0yh8tEnPnvgB2CKGmEX Vijdr4HtJOepQpFPhwIW5FtttP56kvrQrcVprJxO X-Google-Smtp-Source: AGHT+IGzXDSg7GFoYtnMhQ2GjDaGz0sqykcQYCw3ayMv0GG3eruaDBWAihSMG2WjRcz3nnQWUySEjQ== X-Received: by 2002:a17:902:f610:b0:21f:58fd:d215 with SMTP id d9443c01a7336-2262c9bf151mr125733875ad.11.1742398188497; Wed, 19 Mar 2025 08:29:48 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c68a6865sm115889305ad.75.2025.03.19.08.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 08:29:48 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [GSoC PATCH v5 2/3] reftable: adapt writer_add_record() to propagate block_writer_add() errors Date: Wed, 19 Mar 2025 20:59:26 +0530 Message-Id: <20250319152927.1263033-3-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319152927.1263033-1-meetsoni3017@gmail.com> References: <20250319075943.28904-1-meetsoni3017@gmail.com> <20250319152927.1263033-1-meetsoni3017@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- reftable/writer.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/reftable/writer.c b/reftable/writer.c index f3ab1035d6..94c97b7ac0 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -310,11 +310,12 @@ static int writer_add_record(struct reftable_writer *w, * done. Otherwise the block writer may have hit the block size limit * and needs to be flushed. */ - if (!block_writer_add(w->block_writer, rec)) { - err = 0; + err = block_writer_add(w->block_writer, rec); + if (err == 0) goto done; - } + if (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. @@ -329,16 +330,10 @@ static int writer_add_record(struct reftable_writer *w, /* * Try to add the record to the writer again. If this still fails then * the record does not fit into the block size. - * - * TODO: it would be great to have `block_writer_add()` return proper - * error codes so that we don't have to second-guess the failure - * mode here. */ err = block_writer_add(w->block_writer, rec); - if (err) { - err = REFTABLE_ENTRY_TOO_BIG_ERROR; + if (err) goto done; - } done: return err; From patchwork Wed Mar 19 15:29:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022779 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2727A1D5AB2 for ; Wed, 19 Mar 2025 15:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398193; cv=none; b=XpzrYOEH8+LuSq+BikEdNhS4ZS906tMns32mV/LhQsDJDjVt3X+p72nEBPemVNned1nPOc0nW+GKGgbgrLgI+9lpD7lyKuVqNIf+nkeFyCqnFcSkoHFUnwjd1dFbyi1oh4smmy+RxhUU10kwgrNG6/8hqi/Z9bR5re8+qjL8aoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742398193; c=relaxed/simple; bh=bpRt6Qmct1IkprOo/qyL3C67MQsxwAyV3RJZj/aLAQk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l/B2CTQDyoYSoLi6iVwv0d9k7C8syLFrQJpdQcPXaOl4EaH+URt9E0R+rtBtpg7XKjHeYX8uGCfDlVC3wH8+TQpB7DxFWpC4zTxnHB21o5dQHfHDmVVYu87KgORjCnQYmv4WwjvVx0Er1vc9+x9OYGscBn+oPhgwlER8EhFfFUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I7N+QW6k; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I7N+QW6k" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-22349bb8605so157450555ad.0 for ; Wed, 19 Mar 2025 08:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742398191; x=1743002991; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YVHrWd7Lb4i+qpKmnMBEF86TEF7UFSfEvV/jH/a5SWo=; b=I7N+QW6kYs4XstkbWpEgslvvL8e2A1/On5ybVJWdoYcBuejfPZEJ1WCUVnOEKxMX0Q setrU5D3qUxVAu2mC/0ukyFzR3xk0peBfPTqEzMNd4jAEg1GmEpQSxhRBIVmop9Gd4kc vyRbFSeBj4cnL6MQFZUsHy+k6bn0sq2VTi+Mims2YmhYbB0GmfwgPk0hOOvGFEKCIdtK 0+dL8m6dRz0BmL/Yk6hQ5HMfjRFD5rkA3PGjleQNFIvv4t8DarpoVTNnK+3Vb/Hdrt0N QusqZ4OZuSLAtMOOtULvSM//dPYtDAmjzDdPO7rqsA3Ibp79af3iCbRr9+m4Xp3n4jux /Iww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742398191; x=1743002991; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YVHrWd7Lb4i+qpKmnMBEF86TEF7UFSfEvV/jH/a5SWo=; b=qEf+G4azHeZhiZm1MjjP9YptxeZrWm89qL77FJ/7Ed+RJ0aFXNS9rMvupvEnLmwm+D SwD2vZa7f5gIZ0Ryy6YcAHp92dNxAXGcV04FYpg0nfFQx5WtjK/F6pE9UmrI5uUfMprV asFhJgewb4OYGXpUlqpcefQfWaP3KmCm3Op5cGE16dhvQtQhFs3CPt17pq+nfgkZa8Af pROQ7U9TsR+Hfh8c/sqNfVmvumBI9+dOcnxrn5QyN+iRiV0cyhGbWyfOB2YqOZ6T5LTV 0Xgu8zmClKjZQC6m8GPuuLsxCnemHzRWO4CtrT0fi7QelbapCTz0/MgHfwQALgDFV2tQ imcg== X-Gm-Message-State: AOJu0YypS/92wL2vnVxYjyXQ2Zakqb4fWtayWV2ASNeEooTXhTRfG4we 4XIaCtvyWr/mAD00VefdeeQ+wC9NNfCGpF1SoSy4jy2T64OOz6u/fS0FHw== X-Gm-Gg: ASbGncsswHOCj+yAWpMfGzRU+KkncenZMHISwTTdrEgO6J0v21n+/fEhFtYiTrw6HLP YcIcKZ0+2gVNqVQMiOoTO8CAKT/TGyagGGGfiNjo0aGTEIH+Ied1NcXTP5ekyvKw291Di2hGRV9 j1BQt4Lh8733jJopNXL3HfMFjumjaQz3lPISG70YT298tcRWwI+KSbAWFysVcDjXApTNgwtu3gb KdX8q2bt/SNi3A3BREu6i0f0LZqluuc3eYOokJ3pMnKEUD1EEMdHhlIa3+tagH3X0284Z2RGqSD 4kngH7wJ0meExivWvi9mmCnHkqqoFJ16+/4k0c9j X-Google-Smtp-Source: AGHT+IHll4KPD3h59wrcuBuFFHVYAw9+b37p4XUdB8nVFxEOGJfxehhT4UlgZzbCbH7jNxsSD/rBlg== X-Received: by 2002:a17:902:ebc3:b0:225:ac99:ae0d with SMTP id d9443c01a7336-2264992dd80mr66670565ad.10.1742398190880; Wed, 19 Mar 2025 08:29:50 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c68a6865sm115889305ad.75.2025.03.19.08.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 08:29:50 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [GSoC PATCH v5 3/3] reftable: adapt write_object_record() to propagate block_writer_add() errors Date: Wed, 19 Mar 2025 20:59:27 +0530 Message-Id: <20250319152927.1263033-4-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319152927.1263033-1-meetsoni3017@gmail.com> References: <20250319075943.28904-1-meetsoni3017@gmail.com> <20250319152927.1263033-1-meetsoni3017@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- reftable/writer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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);