From patchwork Wed Mar 19 07:59:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022226 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 8F942801 for ; Wed, 19 Mar 2025 08:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742371246; cv=none; b=MH7nfdfXE8QBo/dI8RrAqsRGgnJKOTUm7/VZqAEutStSjHnzCCh6CqS3tNI4x4OGXmf+0UgmjhHIXA0SHoekU03XNEnxZ4cS1JY1aE5CiVAF6DXLtWsdhFhRoXvn5BodAcVbpLjX9yepRPkmgM2Z82w2BUUdFviLhWyRCwfuHbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742371246; c=relaxed/simple; bh=eCqJmXbmnfHlqtGyzxAU4mH0rtHKpAbQZBB8F0dK7xA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tHyFLumxv3MgVZCRIDdH1ld0mane8Zci0ziWHb9ER184kAjTz2FpIpeVyZp8N+Uki0EZvnnu856AHVcpLtBEA05/xkh9NMxnf2156lcw6XxWTsTl6VFwqlfcXP9vKOpsYeeZvrDhvK+dcSouaIB42Oa60OxIG1/VjZQvlU3rRb4= 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=CgfzF1rY; arc=none smtp.client-ip=209.85.216.51 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="CgfzF1rY" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ff784dc055so7058266a91.1 for ; Wed, 19 Mar 2025 01:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742371243; x=1742976043; 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=CgfzF1rYS4GyQ8brSwy2qe8UPWRROATGz3jP567nILN0wWXege/qsTUWxQRo/c6o4c +HKxv5KLHR4TMBvPE3Zqaw7zoprDROdd4sxvY6knEO6Jzgc27PTaW/j3mTesgKwHCByR vZs2wcCeASm38UfqVyuwc1ZWEUI2byDbYnk4xDa1URTYXkrbCIJy59FafsIwnYJJZYl1 ivDCT/oHFIClzHOawCxj2X/2LqyeEQknSJFDJ1TcEF+2Mxl2BhJ10mtTMfeEOA45oG8x ws5sTGDRGe13ipwgVyVzOTiDLq+O3qAc8tPX+jbPfUpeg6+XTSgzDeDbT6v9TN5ImZXq GvyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742371243; x=1742976043; 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=K5sPA5N7WYMqsRlbrkc2vGvG+69iXmvp9reRcbMt17eGDp5IGrAgSS4+0cBVN63FfJ E+FQB5sfNgRYdiWT2mbEDAKSTVRgWXgdzfAV2zajSOEdw492uQbXcQIgir9J66XsUi71 X8UKC6YKJ2kfr6P1OZkOr7yn8rcdoppVMID82poGAwBqLikt68WZb8ercWbuYeZq4vAn Fb2X4IvvgaqtA0WU1s8XPJC7ia8wwUjcSCGOB4NPBnaKcmnNQgcaH2buGhs7OdFMLI6h 7QAWHcZtJJCJ5+4WtsJ8JM4iOWEfqw+9K6CliQcMnATe2uS4kvOyya24ytvHh6UEZJ89 8BEg== X-Gm-Message-State: AOJu0Yw0oHWx4OMtjZMwz4Oi6DdRfzUF4zFMRWGwb2zmQnF9F2LFo8BM 9Fa27R8cW1/K4R/M3idfUqI5+uP80I60YC5trGuxs+2b4lCDLlJ5VMCplA== X-Gm-Gg: ASbGncthByf915nvJBBoY4IkiDgPvcQr3UNWN2SL95T3Ja3nd4nTZVacbCKiC1kRH9v 4xQV0hAev6KAga7kgAxP26ccUDuStN4RYND3UBZzrBNLZuyVBKXan0JGNunvsQOhkRceQ+zPpd0 A5ToByhYlNrxDydnuBwi1EGk1vYb25cMSYRKwDxfdbAY1TvjQtYRJL+AtjGSc4AYzXg60Yr9C5D e/FNtTwYv3ReSMIx0jbXVRKZYUiZiK7JLvfASlDCmfnUbfqZypgyzKQjJ/sw+G3ED9kTUiV+UEC zfQkNMdoG2Kx5bHhlSjQ0aBGDSHARAJAuzZ1hIQU X-Google-Smtp-Source: AGHT+IGbIPnrdmYQbjENvgDmPeywYFNLEN19eZxsVJH3F3ViZ0SsSiDyNqJQrZisQfUx3k+1qLwfCg== X-Received: by 2002:a17:90b:2e86:b0:2ee:edae:780 with SMTP id 98e67ed59e1d1-301bdf941bcmr2972015a91.15.1742371243164; Wed, 19 Mar 2025 01:00:43 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22629cfbcb2sm32866715ad.176.2025.03.19.01.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 01:00:42 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [PATCH v4 1/3] reftable: propagate specific error codes in block_writer_add() Date: Wed, 19 Mar 2025 13:29:41 +0530 Message-Id: <20250319075943.28904-2-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319075943.28904-1-meetsoni3017@gmail.com> References: <20250312121148.1879604-1-meetsoni3017@gmail.com> <20250319075943.28904-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 07:59:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022227 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 E88881F5851 for ; Wed, 19 Mar 2025 08:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742371248; cv=none; b=Go6a8fsd5gZTnwBab1IOoR6EsSTkF3KurxOBUFMvJzgufJuCZ9jhb0EmAy5H47veCaf5j1IBbJHGo4i5NcmWUNpqLo3XGAoAxNjkvLDSqM5wne6KPMPkv7ArvSjjLkwOE5JoXlIeN/ZNm1V7l2JS+WkxYC6vShe7fcicW6Ldtmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742371248; c=relaxed/simple; bh=DgvDv3Ky2Ar7SkF3BgaKbwfJO0L58lDr43Dc1IlMQ40=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q0zKVnKReYZ23lD5ka/1z5jZ66HJGQkpnaTZMafIMwN2mqKHDHuGfYqy/8KRP/J8iIsoeuQDAUNirMW0svXYNtjJ/Xng2b9VWXjjaqVT1Gr8cpzaXTFKoqV7Gdan6tmkyONcqt0YucBrISDblyHn8ehZXKzsRdY7aWRbXAhXkT8= 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=hBMtCWkI; arc=none smtp.client-ip=209.85.214.171 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="hBMtCWkI" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-22438c356c8so113053475ad.1 for ; Wed, 19 Mar 2025 01:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742371246; x=1742976046; 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=/KRJSq/HS6oHh+qF3++84kdXC12S4wmBjADRcMDgt+I=; b=hBMtCWkIb8EgjFmArkX6mRUbPFL0lOKo/9QSP0I64SNAS9Hh4C4DnIsUDcszByWRw4 Fvi4QZLgK5LrlJr82soTw8a/nH0C5MbH9iplLZU22PD4xKdp9ycWE0xoOWOwoWDd/pot C6APQ2d2kfqKBDDlM8cSO5RgBgxWr3ts+I8RsxOqTGm3BUy2gDdSiL2TQ5VMtUoiZTLr Feu112j4fANt/scGMw6L7CTyRpQznMdP6eX2UAU17Y2UvyvHQPM5/kKuDWpKqgj+8FBH w0aF6p8yWVt3mefconnPihfSKTiT0e5XE5qz/bvKuhNDxy2h5F52hUmwlIj+F1wrPnVt ecrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742371246; x=1742976046; 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=/KRJSq/HS6oHh+qF3++84kdXC12S4wmBjADRcMDgt+I=; b=M2hr/YhAG2jDs+pFvAxZFzOdKGSvVX5biJUK4l6dMfAzM7CcGpfqxpGsleOKR6ak4J SnADh4mIMP/HwEZnXACN1CzJvr05bBwPJsWreHeG3mRhQuCgD6ooh4dtWwxHNREQX+8T 3vBZ/WYiYGP/G2iwr8+Kz12gr8PFGZlTeE4nRF4QP61FEp9tTIEKJrzVTdQQd86GpA41 zn2UE/f3qGV/5FVXqkUJo+idEF1nk2ox4d4dIhhmJhBJ5FaPSEYmlnkO4+H+GirYqivI UvuZP9Dz/BLpMRDn+reEVkMkJxcRLtITMp0MEhe4UfSf9DbKtluVJNbVv6D+zHGRmVGD vYfg== X-Gm-Message-State: AOJu0Yx0MHAriFyLoKBZnQOa1GSt4JBsdxVN7SHzMozEIiw2spf8vnZ5 0RhV9yYASlcbtsIWfvWyrt4Y9DOQP5Du7vP+JLKyc1X//gbDOHEX4VWvFA== X-Gm-Gg: ASbGncvtBBlkkKfsFRlJMD+fi/MZiGRx795lOdcv+ppkqeKCeBSZKlOqmm0Kj9HrGvu kVSOxNAjFrOkXN6wR/y0KyZVvo/qdy/MPPM6LvPOm4AiSBqDubF4ZgRDihkXeJ3riWLiwYUizpZ ON/4SkxsjzODPqK3L+jKgdchi2Etav+uJbQPd66eQtAATaFGwVL3UQJB+GxomscBuE8A1PBkIKl Tm6zegBS2nEv0hpImQM5OfWE4BifI/ACEy3Mjjl8xlI/Ovt3P1AKnoIgdkzmnsXvW+j2SHjfcMx icTc/cClYuJx5/3ckZxG4WYkQVkYtd/CSKNJUvHT X-Google-Smtp-Source: AGHT+IFQbhTrLqw8RmHQZV3dC5o2XZwDi8KilN+me38wC6g2T9M5iVs6MxgWEH7GPAfnEz3u5Wbzhw== X-Received: by 2002:a17:90b:4b89:b0:2ff:4e8f:b055 with SMTP id 98e67ed59e1d1-301be2341f8mr3242518a91.35.1742371245677; Wed, 19 Mar 2025 01:00:45 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22629cfbcb2sm32866715ad.176.2025.03.19.01.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 01:00:45 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [PATCH v4 2/3] reftable: adapt writer_add_record() to propagate block_writer_add() errors Date: Wed, 19 Mar 2025 13:29:42 +0530 Message-Id: <20250319075943.28904-3-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319075943.28904-1-meetsoni3017@gmail.com> References: <20250312121148.1879604-1-meetsoni3017@gmail.com> <20250319075943.28904-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 07:59:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meet Soni X-Patchwork-Id: 14022228 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 61E78250BF6 for ; Wed, 19 Mar 2025 08:00: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=1742371250; cv=none; b=JFSEPJ/idnWTXO8zL8rI9PQFM60CC+gkAWnf4QlHGq4tobdx9Dp1him8lUW35Y3qlkPFkaYUqmbgDzXuJYhwb29OuVmY4v7c/HBO/lCgk/45PvQlT9DswlJyye/2FJQHXWy3q8+H4vff/Q19wOdfK9PndjO0zSwfzSAtqRw9xvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742371250; c=relaxed/simple; bh=x3uL6OdmoBHRcUt67v3bS3j6ggRMVoNwH/JbOHEjNMg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZKie6gXXgmsA2p47Djq6fbl2gwGUb1Tn1WeAVEnaUlbvetJveeT+i/RqDZD63ToYTEI2Djf7xUK/7A+kI4+3l5LtyZS54I44a3nYbz5xJiG+6EDGOvVZmq2RBwpgaR4brXq+WHaOulE6ZxZU88YZHrgET0Mt5Tfc1tWDXvHiw1Y= 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=i1gvyCSi; 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="i1gvyCSi" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2264aefc45dso10167225ad.0 for ; Wed, 19 Mar 2025 01:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742371248; x=1742976048; 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=tjI24SGYnVXZJlEp5CthDwOZMHEZshSmzDOwlPJdwqs=; b=i1gvyCSi7f44TRROj+FtsZkxY6UC7ZmkBecvHfyQbUzo6y+tHoeRLHYfStPKADG7tV JcA+zXk12q8sfpJfLsy3VFyIJduiChhmnKoDB2IsHCCbVCEIaXVWXq+WWmXKJoj1hfar ygGP0ANztF2Ch09u+7Z45+5ScvRRgN/JqcKyUgpZ8nKYryRYzHlpNi4ejGvS8HvM7cSE pv8XctPJpBbDQUMzg0KTdee0tABGjYQDf5Gpl/olBteE1Lxn5bY/qCBGDYj8Qydx/fOV VWZwSQNMSyc25KZmfccUq324rh5qV49+0cox8aKMl4jqXYwaeYNFSzGf4vJtNlHpiG7D X86A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742371248; x=1742976048; 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=tjI24SGYnVXZJlEp5CthDwOZMHEZshSmzDOwlPJdwqs=; b=oC+m2CPJdHSMo93Svu7gV2kH+BwyCeWdNgu5WYhWd4pR5+47ok4BXJZ/MD46kE/QyX 3dymwopzUVGzsB97L5HSjP79wBJba2fKP63D9VtmDcqq0EiPzJYGd7a8tTJMW+B3I6q0 477vx9po4WrPb9sG/3tuHZhKvrAYo01euTPoT5DKFQXxx8zTGHZcBzsm0E4Z10wZ+/Ej Mz5myngLjWFwOdog/X8LaoKIRDNdeKH1ch4G4qNa+sDtC2dFwuEymYRBNgwO6NrVdMif lTozV6/2jwyoufFx+VPiRSuk4fsGKqQOH+HFp31LysXsLOBJJnmEVMkoaGYS0G4yn5ix tz7A== X-Gm-Message-State: AOJu0YyG0ZUeqtoLehufzd5+4qdh+z5mDdl3ATvJM2BjtdvYhwJQ04h/ 59DMpmDVvTPvAtJVPg7SlKOUcUStCom1fODXxB0q/Gx9zMK12fdTP1gStQ== X-Gm-Gg: ASbGncvrqOa3AFrUyEAXJ2bsbxMcth1qq8N7gYFtaPymP7dZo66Wid1ovD49G6WtBXe OOmj6eTUi5zdZ0NXx4HwaYEPpMIF/Df6auo1j6GUyfc0k+o6aIj6L6qhrHdDXqx6pBPHVx8Q55q 0l7Xpeti42NTAkRwS4Ts9dCnTaLAWdPsXzz0a2gIDa2F3BJCBjNNHY092qfg0/TqbERrUf8AHrz xPjbch52sGOfXaJgCR7/TlBkfo1c9NI+GfrSx+FMuiskqVGIb8lsZXpfAbrJaRDFKuuK7fCJeBD YkLa09FPnSasVISbO2BWRkkwYMlBSoIgHfAwzOqX X-Google-Smtp-Source: AGHT+IFUGyOSJ9Yj//4Q1HHt/+RpftnJA1MFEgG5SLvFzEY+I7ylQj/0JuUnvJIoCVGR6PExloW9hQ== X-Received: by 2002:a17:902:d2c6:b0:223:5c33:56b4 with SMTP id d9443c01a7336-22649935b27mr20983585ad.20.1742371248146; Wed, 19 Mar 2025 01:00:48 -0700 (PDT) Received: from meet.. ([103.86.19.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22629cfbcb2sm32866715ad.176.2025.03.19.01.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 01:00:47 -0700 (PDT) From: Meet Soni To: git@vger.kernel.org Cc: ps@pks.im, gitster@pobox.com, Meet Soni Subject: [PATCH v4 3/3] reftable: adapt write_object_record() to propagate block_writer_add() errors Date: Wed, 19 Mar 2025 13:29:43 +0530 Message-Id: <20250319075943.28904-4-meetsoni3017@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250319075943.28904-1-meetsoni3017@gmail.com> References: <20250312121148.1879604-1-meetsoni3017@gmail.com> <20250319075943.28904-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 only flush and reinitialize the writer when the error is REFTABLE_ENTRY_TOO_BIG_ERROR. For any other error, immediately propagate it. All call sites now handle various error codes returned by block_writer_add(). Signed-off-by: Meet Soni --- reftable/writer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/reftable/writer.c b/reftable/writer.c index 94c97b7ac0..3fdfa4d34b 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;