From patchwork Thu Aug 10 20:39:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0154C04A6A for ; Thu, 10 Aug 2023 20:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235506AbjHJUjx (ORCPT ); Thu, 10 Aug 2023 16:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbjHJUjw (ORCPT ); Thu, 10 Aug 2023 16:39:52 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94822733 for ; Thu, 10 Aug 2023 13:39:51 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-99bf1f632b8so189961166b.1 for ; Thu, 10 Aug 2023 13:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699990; x=1692304790; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=wTlu6ioOuZXbw26fjIFdlY7LR+y8R0cVsTh8z5RJBQY=; b=o8pJfJSIBLtVkXErLyYqK2oju8MT7IjromXaCcAnzASVYhKkAiUkxVsDkHIpOETIV2 QuymCBO9nyYmIGBgCc4BUW/5mGfQ3HH1yfNXE1ABYUDPZgQlaik6TIFFfHIkpDfbz3HY CeCHF6hqa3F0iug70U+QNpTrKpjIsA7GaEfRIeyCeuywpj7RxGK2prtodAG+c81/wKKS qRZziyxCGUGcgU+UxMNSY6VvQdR5y5N1OrAcz8PiVAKNf9AeEZ+4ulfwHN3f0MldjyDJ ccBwTUuO8vVry5Dc9fu3zzvne21A9Wba1HflCkF5NPi1n4sPRasMzXvWwGCaG3C3qlCs PHxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699990; x=1692304790; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wTlu6ioOuZXbw26fjIFdlY7LR+y8R0cVsTh8z5RJBQY=; b=NnqUu8Y3ztb0ONfhbu92AZThzAuOZpnOcuB6Ov9bGz0//e5jCExQHoEQ/eOMCDKMiq WpTI7nwMXkj55fgsoJ7AUkMMZ9ypY4bY8aMCB09lkQmo2i/kcRvo9VOkzyqaMNvFfpnO aHeJ/2vmuQ5xCvU+Zsx1k6TnCAkgcx+8bq3aPERog1Do4A9koPbghpRc+NXi2OdfOQoJ HXbXVGbdKF719y5fHxhAGrbcTVqSNOtZpTEt6oRp6hNzIDjlAEw4fsgFNoWowPcRGFQ9 Im+B3b/SZVabJ9rmru1BDPx7k2HZxI4RFhZ46mYJk1TTIF2xHBddqEQQArcF//9w2AxS 4IGQ== X-Gm-Message-State: AOJu0YypQwgcd/sm9p/EPt0lI9pcoYWt9opNnx/qzTEc7tu3t+Gi6b99 6ISkBuCeU84uvwiOIy48rzH5wipiRq0= X-Google-Smtp-Source: AGHT+IFrZNYZQn7YRhFJF8xsvwSdEPEyI5o5Viye1ohgtw9s/6tebmR1T8qnyy6Z256CpFgB7+J9xQ== X-Received: by 2002:a17:906:2ce:b0:99c:bb4d:f5a1 with SMTP id 14-20020a17090602ce00b0099cbb4df5a1mr3438ejk.4.1691699989787; Thu, 10 Aug 2023 13:39:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w14-20020a1709060a0e00b0099b5a71b0bfsm1375124ejf.94.2023.08.10.13.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:49 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:40 +0000 Subject: [PATCH v2 1/8] maintenance: add get_random_minute() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When we initially created background maintenance -- with its hourly, daily, and weekly schedules -- we considered the effects of all clients launching fetches to the server every hour on the hour. The worry of DDoSing server hosts was noted, but left as something we would consider for a future update. As background maintenance has gained more adoption over the past three years, our worries about DDoSing the big Git hosts has been unfounded. Those systems, especially those serving public repositories, are already resilient to thundering herds of much smaller scale. However, sometimes organizations spin up specific custom server infrastructure either in addition to or on top of their Git host. Some of these technologies are built for a different range of scale, and can hit concurrency limits sooner. Organizations with such custom infrastructures are more likely to recommend tools like `scalar` which furthers their adoption of background maintenance. To help solve for this, create get_random_minute() as a method to help Git select a random minute when creating schedules in the future. The integrations with this method do not yet exist, but will follow in future changes. To avoid multiple sources of randomness in the Git codebase, create a new helper function, git_rand(), that returns a random uint32_t. This is similar to how rand() returns a random nonnegative value, except it is based on csprng_bytes() which is cryptographic and will return values larger than RAND_MAX. One thing that is important for testability is that we notice when we are under a test scenario and return a predictable result. The schedules themselves are not checked for this value, but at least one launchctl test checks that we do not unnecessarily reboot the schedule if it has not changed from a previous version. Signed-off-by: Derrick Stolee --- builtin/gc.c | 10 ++++++++++ wrapper.c | 10 ++++++++++ wrapper.h | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index 19d73067aad..2ebae7bc17c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1708,6 +1708,16 @@ static int get_schedule_cmd(const char **cmd, int *is_available) return 1; } +MAYBE_UNUSED +static int get_random_minute(void) +{ + /* Use a static value when under tests. */ + if (getenv("GIT_TEST_MAINT_SCHEDULER")) + return 13; + + return git_rand() % 60; +} + static int is_launchctl_available(void) { const char *cmd = "launchctl"; diff --git a/wrapper.c b/wrapper.c index 5160c9e28de..48065c4f533 100644 --- a/wrapper.c +++ b/wrapper.c @@ -819,3 +819,13 @@ int csprng_bytes(void *buf, size_t len) return 0; #endif } + +uint32_t git_rand(void) +{ + uint32_t result; + + if (csprng_bytes(&result, sizeof(result)) < 0) + die(_("unable to get random bytes")); + + return result; +} diff --git a/wrapper.h b/wrapper.h index 79a9c1b5077..79c7321bb37 100644 --- a/wrapper.h +++ b/wrapper.h @@ -139,4 +139,10 @@ void sleep_millisec(int millisec); */ int csprng_bytes(void *buf, size_t len); +/* + * Returns a random uint32_t, uniformly distributed across all possible + * values. + */ +uint32_t git_rand(void); + #endif /* WRAPPER_H */ From patchwork Thu Aug 10 20:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 770B6C001DE for ; Thu, 10 Aug 2023 20:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235546AbjHJUjx (ORCPT ); Thu, 10 Aug 2023 16:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234614AbjHJUjw (ORCPT ); Thu, 10 Aug 2023 16:39:52 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 230462737 for ; Thu, 10 Aug 2023 13:39:52 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3178fa77b27so1145434f8f.2 for ; Thu, 10 Aug 2023 13:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699990; x=1692304790; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SLLpD9Qi5cOXrWeRuVA5eZ7qq1szHJn7MosVOt346hQ=; b=PpHtvTaQswxFxBxVn9loIz0VJ/0bpkxLXGG2ZQG3j1n+2P1njK1iUho3ooagA5Pzsj cm4fQz/IRSr5DzJqq62OCJnEMwRc3RRI9mwo7bNdwJnKEKxNJpZFtaXupOVFlued8Nlx HoXl0+aElxglKDA8GOiDzg9rmzZCxnIkwhejFTQCuFnu2wtIOZktxekM6BA95WCZuo70 pOa06iEJ8WDMZq4XtEH8uF/J7in/EBJM+mz3RuZa375DoJ1U6f3PM2e3bsRafYFkAff5 KSnkcA0q6CpEmBFZ70eMVXEdFXMxurwSurROvYMY6rvJ3D+Nit3o+s3bMy9AC6ZX/bfX ZWpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699990; x=1692304790; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SLLpD9Qi5cOXrWeRuVA5eZ7qq1szHJn7MosVOt346hQ=; b=b1nTk6Y2l9SRIMARR4NjD1NMWx5U9oJc5n7t8b5i4irB7R2l8ANZK7p5q5A4d+dqY0 oXpfR/JI7mixmPyInk5qXhHPCK2BXEt2B7DCRpMom58hWcBijMWxYu3LsnPAze50X+3s 5qDD7Ll9TnVGf1v8vRY3W4lUwcHxIG0FEF2qZfHpSNb6SylJgU8LV7IBsDkXRiW546k+ QdjBiCHrJ1e8z6E0C4cgAnzAByaKaa8bvI67io3cB/VpYA3AMeZlzSiSQ1Ze9RrlSCbb r0xhUu+GfqR61pKN7MP7gBLl2u/WcDNSBBGNVKYCBMJZrLlTvpBGIfO0QMejnJ8Vc/jD oPDA== X-Gm-Message-State: AOJu0YzP+w/TpRUIIuay/xG0/Z08oCoien43S0eK5yJlshUgNtmFFT4o 9Pxqj30RSxDb6Brk6xFkmCbwFP5cvrg= X-Google-Smtp-Source: AGHT+IHlcoPC7rCYioFKfYE2b4+buiw6gLleqqW+WQKxckKj2gp9iCdgEhBvUK+Rrak7TsJUADtYkw== X-Received: by 2002:a5d:4bc9:0:b0:313:f61c:42ab with SMTP id l9-20020a5d4bc9000000b00313f61c42abmr2829808wrt.56.1691699990334; Thu, 10 Aug 2023 13:39:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a6-20020a17090682c600b0098669cc16b2sm1383261ejy.83.2023.08.10.13.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:50 -0700 (PDT) Message-ID: <72ec86f2f882a575544aef71517b0727f2510a0e.1691699987.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:41 +0000 Subject: [PATCH v2 2/8] maintenance: use random minute in launchctl scheduler Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The get_random_minute() method was created to allow maintenance schedules to be fixed to a random minute of the hour. This randomness is only intended to spread out the load from a number of clients, but each client should have an hour between each maintenance cycle. Use get_random_minute() when constructing the schedules for launchctl. The format already includes a 'Minute' key which is modified from 0 to the random minute. Signed-off-by: Derrick Stolee --- builtin/gc.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 2ebae7bc17c..286ce131a5c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1708,7 +1708,6 @@ static int get_schedule_cmd(const char **cmd, int *is_available) return 1; } -MAYBE_UNUSED static int get_random_minute(void) { /* Use a static value when under tests. */ @@ -1830,6 +1829,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit struct strbuf plist = STRBUF_INIT, plist2 = STRBUF_INIT; struct stat st; const char *cmd = "launchctl"; + int minute = get_random_minute(); get_schedule_cmd(&cmd, NULL); preamble = "\n" @@ -1855,29 +1855,30 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit case SCHEDULE_HOURLY: repeat = "\n" "Hour%d\n" - "Minute0\n" + "Minute%d\n" "\n"; for (i = 1; i <= 23; i++) - strbuf_addf(&plist, repeat, i); + strbuf_addf(&plist, repeat, i, minute); break; case SCHEDULE_DAILY: repeat = "\n" "Day%d\n" "Hour0\n" - "Minute0\n" + "Minute%d\n" "\n"; for (i = 1; i <= 6; i++) - strbuf_addf(&plist, repeat, i); + strbuf_addf(&plist, repeat, i, minute); break; case SCHEDULE_WEEKLY: - strbuf_addstr(&plist, - "\n" - "Day0\n" - "Hour0\n" - "Minute0\n" - "\n"); + strbuf_addf(&plist, + "\n" + "Day0\n" + "Hour0\n" + "Minute%d\n" + "\n", + minute); break; default: From patchwork Thu Aug 10 20:39:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10D6DC04E69 for ; Thu, 10 Aug 2023 20:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235840AbjHJUj6 (ORCPT ); Thu, 10 Aug 2023 16:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235579AbjHJUjy (ORCPT ); Thu, 10 Aug 2023 16:39:54 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6868B90 for ; Thu, 10 Aug 2023 13:39:53 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4fe457ec6e7so2084667e87.3 for ; Thu, 10 Aug 2023 13:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699991; x=1692304791; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=UyVIVcXnMJ/sAFRD9OUPebLLA7kp94IwaUsqTrPoYfU=; b=byFIdY5sRGtEWXthww1QuSMQvzf+sRz1/dH7Zx4Us0/3qaOBY0m9Tho8rguWW+0Prs A1sWNXPoE1aTNy8F21+Kqx+LF84rTShnH8EWhZJUk469+cidOAK5cenKiqZhGTGOmlFf wf3c8YOm4C3rByt4kTkR8OxizhzIEsY8DU2Lby87eVWrdKxN+MrYfz/HOF0Jm9mt7qBT bJetac+5YRSt7zvCmfbLarOV3T4SnRCuvwGanymz6pgCvihbEYrAq6/iuvzSB8T57TsO 8Y1qvsBYqJRa9XXUhkAjIwNQIxtWMPK+B+Ubrhoj2TnlcRabfb1K7H2p3Ebj5XWckQLv S87A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699991; x=1692304791; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UyVIVcXnMJ/sAFRD9OUPebLLA7kp94IwaUsqTrPoYfU=; b=YY6juSGvRTgOfq9M9BAF1+o+thKVCdtM+nJIO68tAFzpz1gcedJbfyH5PXghJ2Ul2t jPRvlK9XIM9ReU6az3U2ui+tvNRolJpDJ9WxQsB3rNbzVGJ5tOdMgPAxCc+q+C2BY6Ak 0PVXtfv3AkS7JmPU4Jt1wyn3C+9bkSH9EQ0MpikWAQw13wr/Sf0Q5q6L+fFg1BCYqI45 1XuPFJfzmFBnU1pJcPdPYCZuekMZrgXYOYZMku/FGonLP9+QOTGI46BPt/GEc1L0VnwV ndPruun94gGXuke9cHC046d7c6lsX7Lj+zDVchChDgAl/4is72vtNLZQ/OEyCANpfqA8 IIBg== X-Gm-Message-State: AOJu0YzjcTKG1zQyEa0iDQhSjGXr8E3wjts4D3ilAUBQ97btBKMmuXlf ctgh5IXeDa29/tm9cj0QqOEnJ2tpeIA= X-Google-Smtp-Source: AGHT+IHmHjOYWWCpv48HnM2OPryzUVEWpVAKZCT9JxL/cJrPnVEelY8ZoSloJOZTe773eBkdle+cOQ== X-Received: by 2002:a05:6512:2312:b0:4fb:7642:88dd with SMTP id o18-20020a056512231200b004fb764288ddmr3807527lfu.67.1691699991111; Thu, 10 Aug 2023 13:39:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m25-20020a17090607d900b009893b06e9e3sm1376934ejc.225.2023.08.10.13.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:50 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:42 +0000 Subject: [PATCH v2 3/8] maintenance: use random minute in Windows scheduler Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The get_random_minute() method was created to allow maintenance schedules to be fixed to a random minute of the hour. This randomness is only intended to spread out the load from a number of clients, but each client should have an hour between each maintenance cycle. Add this random minute to the Windows scheduler integration. We need only to modify the minute value for the 'StartBoundary' tag across the three schedules. Signed-off-by: Derrick Stolee --- builtin/gc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 286ce131a5c..78924bb32c6 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1995,6 +1995,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority const char *frequency = get_frequency(schedule); char *name = schtasks_task_name(frequency); struct strbuf tfilename = STRBUF_INIT; + int minute = get_random_minute(); get_schedule_cmd(&cmd, NULL); @@ -2015,7 +2016,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority switch (schedule) { case SCHEDULE_HOURLY: fprintf(tfile->fp, - "2020-01-01T01:00:00\n" + "2020-01-01T01:%02d:00\n" "true\n" "\n" "1\n" @@ -2024,12 +2025,13 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority "PT1H\n" "PT23H\n" "false\n" - "\n"); + "\n", + minute); break; case SCHEDULE_DAILY: fprintf(tfile->fp, - "2020-01-01T00:00:00\n" + "2020-01-01T00:%02d:00\n" "true\n" "\n" "\n" @@ -2041,19 +2043,21 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority "\n" "\n" "1\n" - "\n"); + "\n", + minute); break; case SCHEDULE_WEEKLY: fprintf(tfile->fp, - "2020-01-01T00:00:00\n" + "2020-01-01T00:%02d:00\n" "true\n" "\n" "\n" "\n" "\n" "1\n" - "\n"); + "\n", + minute); break; default: From patchwork Thu Aug 10 20:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54040C001DE for ; Thu, 10 Aug 2023 20:39:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235776AbjHJUj4 (ORCPT ); Thu, 10 Aug 2023 16:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235583AbjHJUjy (ORCPT ); Thu, 10 Aug 2023 16:39:54 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 725D22733 for ; Thu, 10 Aug 2023 13:39:53 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-99bf9252eddso188718166b.3 for ; Thu, 10 Aug 2023 13:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699992; x=1692304792; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Xll3ttnJ7Sp3nAwkR5sXlixwZZJ4Xijwy7S0Mq57Mm8=; b=Yro8Up5JuKTlCm3xJLFpzXWRPGbjJfPd26Y8QRwxjRrP33Fr4Qehfxnd+6chU6Vrn3 KB1GdgfpkyJ+rb617lJebJR044N2Z8Pp0Xx7ylj7RfPpMXD7s9OvsTf9d+86DpRS9VCe sheWR59IdL3kcj63d0tCzV/jVsXD2sRjlZHHSINxjgwRsM4aZbdfwHYbewwPE5pOashd stPuDzJLpOD+GGAqTXInnodbJJw9igvV7fljgl1j+a0zy+d1T8y6rwygTfl4wePEC+wC 2/GNDp1q1Z4JuDYU/4RtkBA5fcqkWoteXaF7jWe3hhqmCVVPokjmbNfXi/YWN01760WL bhcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699992; x=1692304792; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xll3ttnJ7Sp3nAwkR5sXlixwZZJ4Xijwy7S0Mq57Mm8=; b=fnjTOP2OkWgwfh354NYUdNGYJXSOa82WoahzO3zCs7s487NfkjUdEb6DYsDWqambI1 9ZOmsmekJJOdkazx8caz/YQ5GATpukbY8DVMylJ4G9luiPYy3JO2Ohm5U6zaw9xOgxL5 NFEw8iHKqfvtWwOgGIgDyJZrYIjgEGNPl3Fhja+LiGapQx66MATyAXicXwa1qcqM/mWX d6JUcO8PX3uSi4WTJPQfBQa++6Ndnc2BUV38s8RPvxi7gQK08+80uSxRJzdhU1WLpOmW UEnn9a8uDeOdhnpgAlZOFGNZHtzEecL8Woa/M3fCMnhcIfZdp4LUwPhh/vR6S7iCjybU mfOw== X-Gm-Message-State: AOJu0YxR5hPyOXPCOzb0L/ngsgxkCwofoycUlkulcTzB61tGNLnxpGuO qErx2sjd2D3K975strkclMtEMQ/HOnE= X-Google-Smtp-Source: AGHT+IEqXqO1aCAEvBx+AVMP4+6SgOMcu3U5Hq+tOP34RDLU0c7UrL4cHAa06cr8ZyW0WWxAUJcozA== X-Received: by 2002:a17:906:308d:b0:993:d7cf:f58 with SMTP id 13-20020a170906308d00b00993d7cf0f58mr4283ejv.2.1691699991825; Thu, 10 Aug 2023 13:39:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o20-20020a1709061b1400b0098ce63e36e9sm1384071ejg.16.2023.08.10.13.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:51 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:43 +0000 Subject: [PATCH v2 4/8] maintenance: use random minute in cron scheduler Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The get_random_minute() method was created to allow maintenance schedules to be fixed to a random minute of the hour. This randomness is only intended to spread out the load from a number of clients, but each client should have an hour between each maintenance cycle. Add this random minute to the cron integration. The cron schedule specification starts with a minute indicator, which was previously inserted as the "0" string but now takes the given minute as an integer parameter. Signed-off-by: Derrick Stolee --- builtin/gc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 78924bb32c6..ef8bb772c38 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2174,6 +2174,7 @@ static int crontab_update_schedule(int run_maintenance, int fd) FILE *cron_list, *cron_in; struct strbuf line = STRBUF_INIT; struct tempfile *tmpedit = NULL; + int minute = get_random_minute(); get_schedule_cmd(&cmd, NULL); strvec_split(&crontab_list.args, cmd); @@ -2228,11 +2229,11 @@ static int crontab_update_schedule(int run_maintenance, int fd) "# replaced in the future by a Git command.\n\n"); strbuf_addf(&line_format, - "%%s %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n", + "%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n", exec_path, exec_path); - fprintf(cron_in, line_format.buf, "0", "1-23", "*", "hourly"); - fprintf(cron_in, line_format.buf, "0", "0", "1-6", "daily"); - fprintf(cron_in, line_format.buf, "0", "0", "0", "weekly"); + fprintf(cron_in, line_format.buf, minute, "1-23", "*", "hourly"); + fprintf(cron_in, line_format.buf, minute, "0", "1-6", "daily"); + fprintf(cron_in, line_format.buf, minute, "0", "0", "weekly"); strbuf_release(&line_format); fprintf(cron_in, "\n%s\n", END_LINE); From patchwork Thu Aug 10 20:39:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E69F3C04A6A for ; Thu, 10 Aug 2023 20:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235860AbjHJUkD (ORCPT ); Thu, 10 Aug 2023 16:40:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235718AbjHJUjz (ORCPT ); Thu, 10 Aug 2023 16:39:55 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8054273C for ; Thu, 10 Aug 2023 13:39:54 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b9fa64db41so20785631fa.1 for ; Thu, 10 Aug 2023 13:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699992; x=1692304792; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=jJogg69CvzVrRzoVEjvAs7MdyjeyecWSO/Rc55B2fhc=; b=CQmK+nBLSeL711cfgCZqqauYcGZwtyrZo7Sw02Ps7ZPBRMbYK7xE9kHMYWo/KuYFR6 /w9px+HIeQ7q55cBQN0V4XFEVluPlHmtIxgxulbTEIuwndl4QlA28WOJefX8PgCBd52r mlx+0iLkk7Uvzv1zUVYAxLlQZVA5mxWKAjUE7ZbumzcknwoNdfh3kBI1rs7k25pcOp8v CbEryuUN0ML0RMpzB8B6AL+/bY/XNHkQycjLqgfUbGI6/O0t6IeRfsDPVxVwVDVhU3VM q2GneUNSSQc57UtsXiNq5PYTwkARG6N+TQbYu2Kr5WhTYLvDwk4HMTYx8lYpkPupxK+G /PQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699992; x=1692304792; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jJogg69CvzVrRzoVEjvAs7MdyjeyecWSO/Rc55B2fhc=; b=a8bQKyTCVYT2Ax5lu6tRuuGh075v5j0L1c7mZKuFmbSfhYLrKtwB8shorxOk0RriNs vJg3uMHuiLVlxpTGt4YPu5WNRJlrxXTOjC00ZrnC4AHF6u65knvk+tRGLYNAMM5M3jRo 7d73IX9BT7H8Zq1iS2Jh1yUiWqcIEwk64MoIPQ2hE171Wf1HgoCDNvlGpL5+N3YZbJ8X oEnAdKgMOtDgs+yJ8X93WHi4nsO8+JLMfk05FBcpXebvx0NEwo+NwB2mLBylflYy/pZN 5ExeoCeskUjbNavzml8LrZsAI3KV3AiR06stzxqFddfpJZF/C8ou6GbG4jrtEUlCtXhP y5XQ== X-Gm-Message-State: AOJu0YwedzZ04lUHD7NL/uOgAPOAMG8i5HhM08zBU7nIsxxHUfLUtDiG u3egIe1Eve/9FkA1bOlkazcH+F9vDKU= X-Google-Smtp-Source: AGHT+IFpnAqJdTZJPm2jYA9uV/CM+OtVM/QYWtUb3LB+ef4qfFzadPwcU/ONVhgUdlKl3+RH6Piupw== X-Received: by 2002:a2e:9214:0:b0:2b6:e292:85ab with SMTP id k20-20020a2e9214000000b002b6e29285abmr82125ljg.25.1691699992547; Thu, 10 Aug 2023 13:39:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w20-20020a170906385400b0097404f4a124sm1387865ejc.2.2023.08.10.13.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:52 -0700 (PDT) Message-ID: <88610437b4b53f584c540aca8ec26f40c0f0a426.1691699987.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:44 +0000 Subject: [PATCH v2 5/8] maintenance: swap method locations Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The systemd_timer_write_unit_templates() method writes a single template that is then used to start the hourly, daily, and weekly schedules with systemd. However, in order to schedule systemd maintenance on a given minute, these templates need to be replaced with specific schedules for each of these jobs. Before modifying the schedules, move the writing method above the systemd_timer_enable_unit() method, so we can write a specific schedule for each unit. The diff is computed smaller by showing systemd_timer_enable_unit() and systemd_timer_delete_units() move instead of systemd_timer_write_unit_templates() and systemd_timer_delete_unit_templates(). Signed-off-by: Derrick Stolee --- builtin/gc.c | 96 ++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index ef8bb772c38..e3819fc285a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2292,46 +2292,6 @@ static char *xdg_config_home_systemd(const char *filename) return xdg_config_home_for("systemd/user", filename); } -static int systemd_timer_enable_unit(int enable, - enum schedule_priority schedule) -{ - const char *cmd = "systemctl"; - struct child_process child = CHILD_PROCESS_INIT; - const char *frequency = get_frequency(schedule); - - /* - * Disabling the systemd unit while it is already disabled makes - * systemctl print an error. - * Let's ignore it since it means we already are in the expected state: - * the unit is disabled. - * - * On the other hand, enabling a systemd unit which is already enabled - * produces no error. - */ - if (!enable) - child.no_stderr = 1; - - get_schedule_cmd(&cmd, NULL); - strvec_split(&child.args, cmd); - strvec_pushl(&child.args, "--user", enable ? "enable" : "disable", - "--now", NULL); - strvec_pushf(&child.args, "git-maintenance@%s.timer", frequency); - - if (start_command(&child)) - return error(_("failed to start systemctl")); - if (finish_command(&child)) - /* - * Disabling an already disabled systemd unit makes - * systemctl fail. - * Let's ignore this failure. - * - * Enabling an enabled systemd unit doesn't fail. - */ - if (enable) - return error(_("failed to run systemctl")); - return 0; -} - static int systemd_timer_delete_unit_templates(void) { int ret = 0; @@ -2348,14 +2308,6 @@ static int systemd_timer_delete_unit_templates(void) return ret; } -static int systemd_timer_delete_units(void) -{ - return systemd_timer_enable_unit(0, SCHEDULE_HOURLY) || - systemd_timer_enable_unit(0, SCHEDULE_DAILY) || - systemd_timer_enable_unit(0, SCHEDULE_WEEKLY) || - systemd_timer_delete_unit_templates(); -} - static int systemd_timer_write_unit_templates(const char *exec_path) { char *filename; @@ -2437,6 +2389,54 @@ error: return -1; } +static int systemd_timer_enable_unit(int enable, + enum schedule_priority schedule) +{ + const char *cmd = "systemctl"; + struct child_process child = CHILD_PROCESS_INIT; + const char *frequency = get_frequency(schedule); + + /* + * Disabling the systemd unit while it is already disabled makes + * systemctl print an error. + * Let's ignore it since it means we already are in the expected state: + * the unit is disabled. + * + * On the other hand, enabling a systemd unit which is already enabled + * produces no error. + */ + if (!enable) + child.no_stderr = 1; + + get_schedule_cmd(&cmd, NULL); + strvec_split(&child.args, cmd); + strvec_pushl(&child.args, "--user", enable ? "enable" : "disable", + "--now", NULL); + strvec_pushf(&child.args, "git-maintenance@%s.timer", frequency); + + if (start_command(&child)) + return error(_("failed to start systemctl")); + if (finish_command(&child)) + /* + * Disabling an already disabled systemd unit makes + * systemctl fail. + * Let's ignore this failure. + * + * Enabling an enabled systemd unit doesn't fail. + */ + if (enable) + return error(_("failed to run systemctl")); + return 0; +} + +static int systemd_timer_delete_units(void) +{ + return systemd_timer_enable_unit(0, SCHEDULE_HOURLY) || + systemd_timer_enable_unit(0, SCHEDULE_DAILY) || + systemd_timer_enable_unit(0, SCHEDULE_WEEKLY) || + systemd_timer_delete_unit_templates(); +} + static int systemd_timer_setup_units(void) { const char *exec_path = git_exec_path(); From patchwork Thu Aug 10 20:39:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A87DAC04A6A for ; Thu, 10 Aug 2023 20:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234687AbjHJUkM (ORCPT ); Thu, 10 Aug 2023 16:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235764AbjHJUj4 (ORCPT ); Thu, 10 Aug 2023 16:39:56 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 156CB273D for ; Thu, 10 Aug 2023 13:39:55 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99c1d03e124so179382566b.2 for ; Thu, 10 Aug 2023 13:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699993; x=1692304793; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=duEhc3o+W7MvFcEFf/jVdLaY6ZyFTD0tk+JaqYEJ/gs=; b=n/y1/K5/en6YYUNw2ZhlD8aT/xJw2ezWEY8cNLFxeAUd/BQL0jcMeRpL9vEIBucFjf OllrTNu+3zhK4M90t8NUUqT9Obl9M/Uzzz7T92ZDSDYH3OT0jt5bIiDcD+7R2af6uT3H JNCFHoU9j2sLEltBw0S7WMI6UO3jJttRqsENtCI21cVL2FBBSZjEZC8iDLV5h4ss1kzx EQQh4h3QT3VHfNIz7Cf6JZDHrz/iTOFSjJpDqXzUlkFZooiqDRsDLtfkfjBwXFs6V+3D /hAyVTyNJSqGbXhxVvLSs6avSbItGWMGc11N7zgRzwxjrAd7eholclXPTnq7diLVmN6i MyHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699993; x=1692304793; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=duEhc3o+W7MvFcEFf/jVdLaY6ZyFTD0tk+JaqYEJ/gs=; b=NZzEWT2ygCPbEogiYstYefSmOlRV9engPa0keh3DzsXotOXCtX9EjvSMI/RPBpiOVN gpzVE3ws9YFRnFSD4j6tEA+d9lo1VSIDpPWjSdtqXnlEKYGOFzz9uUKfcT4Ht5kyNZU1 DHYtOQRTIeBo82DpJtlwGAuKWUgo9gYLR7Lmunv6x+SFYuGlodiudh2Yb8HNwBWc8v3s Nae4H/dPGbTuxXxFrd1pyvyEGv+Rd69OUL7vy0QTJG3FJnUF/9JfxJRcbSAz85WCyICD 7vkag+g6o4zAVfDgala6l/Y5M+L9DewbOEq5pRextuilqxoigJssRjWe51B83AD918Dq N+Cw== X-Gm-Message-State: AOJu0YycwQH1CupU6B2JnsrbU0zqcEy3H1vnzcEwq17Z1XATnKcLCUEy x+WKYt8KGYFYEkj1mtZMfcOTn7OEwuQ= X-Google-Smtp-Source: AGHT+IERfVdjjzZwSDKeLXM61etrV7aqsbKEjR3KndkDjtnnpADhUOcEMAXmo2nFfilTJqafIC8H+w== X-Received: by 2002:a17:907:7843:b0:99d:13f:d85f with SMTP id lb3-20020a170907784300b0099d013fd85fmr2961589ejc.61.1691699993312; Thu, 10 Aug 2023 13:39:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r5-20020a1709067fc500b0099bc80d5575sm1365554ejs.200.2023.08.10.13.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:52 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:45 +0000 Subject: [PATCH v2 6/8] maintenance: use random minute in systemd scheduler Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The get_random_minute() method was created to allow maintenance schedules to be fixed to a random minute of the hour. This randomness is only intended to spread out the load from a number of clients, but each client should have an hour between each maintenance cycle. Add this random minute to the systemd integration. This integration is more complicated than similar changes for other schedulers because of a neat trick that systemd allows: templating. The previous implementation generated two template files with names of the form 'git-maintenance@.(timer|service)'. The '.timer' or '.service' indicates that this is a template that is picked up when we later specify '...@.timer' or '...@.service'. The '' string is then used to insert into the template both the 'OnCalendar' schedule setting and the '--schedule' parameter of the 'git maintenance run' command. In order to set these schedules to a given minute, we can no longer use the 'hourly', 'daily', or 'weekly' strings for '' and instead need to abandon the template model for the .timer files. We can still use templates for the .service files. For this reason, we split these writes into two methods. Modify the template with a custom schedule in the 'OnCalendar' setting. This schedule has some interesting differences from cron-like patterns, but is relatively easy to figure out from context. The one that might be confusing is that '*-*-*' is a date-based pattern, but this must be omitted when using 'Mon' to signal that we care about the day of the week. Monday is used since that matches the day used for the 'weekly' schedule used previously. Now that the timer files are not templates, we might want to abandon the '@' symbol in the file names. However, this would cause users with existing schedules to get two competing schedules due to different names. The work to remove the old schedule name is one thing that we can avoid by keeping the '@' symbol in our unit names. Since we are locked into this name, it makes sense that we keep the template model for the .service files. The rest of the change involves making sure we are writing these .timer and .service files before initializing the schedule with 'systemctl' and deleting the files when we are done. Some changes are also made to share the random minute along with a single computation of the execution path of the current Git executable. In addition, older Git versions may have written a 'git-maintenance@.timer' template file. Be sure to remove this when successfully enabling maintenance (or disabling maintenance). Signed-off-by: Derrick Stolee --- builtin/gc.c | 152 ++++++++++++++++++++++++++++++++++------- t/t7900-maintenance.sh | 15 +++- 2 files changed, 142 insertions(+), 25 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index e3819fc285a..e52129e485c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2292,29 +2292,54 @@ static char *xdg_config_home_systemd(const char *filename) return xdg_config_home_for("systemd/user", filename); } -static int systemd_timer_delete_unit_templates(void) +#define SYSTEMD_UNIT_FORMAT "git-maintenance@%s.%s" + +static int systemd_timer_delete_timer_file(enum schedule_priority priority) { int ret = 0; - char *filename = xdg_config_home_systemd("git-maintenance@.timer"); + const char *frequency = get_frequency(priority); + char *local_timer_name = xstrfmt(SYSTEMD_UNIT_FORMAT, frequency, "timer"); + char *filename = xdg_config_home_systemd(local_timer_name); + if (unlink(filename) && !is_missing_file_error(errno)) ret = error_errno(_("failed to delete '%s'"), filename); - FREE_AND_NULL(filename); - filename = xdg_config_home_systemd("git-maintenance@.service"); + free(filename); + free(local_timer_name); + return ret; +} + +static int systemd_timer_delete_service_template(void) +{ + int ret = 0; + char *local_service_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "service"); + char *filename = xdg_config_home_systemd(local_service_name); if (unlink(filename) && !is_missing_file_error(errno)) ret = error_errno(_("failed to delete '%s'"), filename); free(filename); + free(local_service_name); return ret; } -static int systemd_timer_write_unit_templates(const char *exec_path) +/* + * Write the schedule information into a git-maintenance@.timer + * file using a custom minute. This timer file cannot use the templating + * system, so we generate a specific file for each. + */ +static int systemd_timer_write_timer_file(enum schedule_priority schedule, + int minute) { + int res = -1; char *filename; FILE *file; const char *unit; + char *schedule_pattern = NULL; + const char *frequency = get_frequency(schedule); + char *local_timer_name = xstrfmt(SYSTEMD_UNIT_FORMAT, frequency, "timer"); + + filename = xdg_config_home_systemd(local_timer_name); - filename = xdg_config_home_systemd("git-maintenance@.timer"); if (safe_create_leading_directories(filename)) { error(_("failed to create directories for '%s'"), filename); goto error; @@ -2323,6 +2348,23 @@ static int systemd_timer_write_unit_templates(const char *exec_path) if (!file) goto error; + switch (schedule) { + case SCHEDULE_HOURLY: + schedule_pattern = xstrfmt("*-*-* *:%02d:00", minute); + break; + + case SCHEDULE_DAILY: + schedule_pattern = xstrfmt("*-*-* 0:%02d:00", minute); + break; + + case SCHEDULE_WEEKLY: + schedule_pattern = xstrfmt("Mon 0:%02d:00", minute); + break; + + default: + BUG("Unhandled schedule_priority"); + } + unit = "# This file was created and is maintained by Git.\n" "# Any edits made in this file might be replaced in the future\n" "# by a Git command.\n" @@ -2331,12 +2373,12 @@ static int systemd_timer_write_unit_templates(const char *exec_path) "Description=Optimize Git repositories data\n" "\n" "[Timer]\n" - "OnCalendar=%i\n" + "OnCalendar=%s\n" "Persistent=true\n" "\n" "[Install]\n" "WantedBy=timers.target\n"; - if (fputs(unit, file) == EOF) { + if (fprintf(file, unit, schedule_pattern) < 0) { error(_("failed to write to '%s'"), filename); fclose(file); goto error; @@ -2345,9 +2387,36 @@ static int systemd_timer_write_unit_templates(const char *exec_path) error_errno(_("failed to flush '%s'"), filename); goto error; } + + res = 0; + +error: + free(schedule_pattern); + free(local_timer_name); free(filename); + return res; +} - filename = xdg_config_home_systemd("git-maintenance@.service"); +/* + * No matter the schedule, we use the same service and can make use of the + * templating system. When installing git-maintenance@.timer, + * systemd will notice that git-maintenance@.service exists as a template + * and will use this file and insert the into the template at + * the position of "%i". + */ +static int systemd_timer_write_service_template(const char *exec_path) +{ + int res = -1; + char *filename; + FILE *file; + const char *unit; + char *local_service_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "service"); + + filename = xdg_config_home_systemd(local_service_name); + if (safe_create_leading_directories(filename)) { + error(_("failed to create directories for '%s'"), filename); + goto error; + } file = fopen_or_warn(filename, "w"); if (!file) goto error; @@ -2380,17 +2449,18 @@ static int systemd_timer_write_unit_templates(const char *exec_path) error_errno(_("failed to flush '%s'"), filename); goto error; } - free(filename); - return 0; + + res = 0; error: + free(local_service_name); free(filename); - systemd_timer_delete_unit_templates(); - return -1; + return res; } static int systemd_timer_enable_unit(int enable, - enum schedule_priority schedule) + enum schedule_priority schedule, + int minute) { const char *cmd = "systemctl"; struct child_process child = CHILD_PROCESS_INIT; @@ -2407,12 +2477,14 @@ static int systemd_timer_enable_unit(int enable, */ if (!enable) child.no_stderr = 1; + else if (systemd_timer_write_timer_file(schedule, minute)) + return -1; get_schedule_cmd(&cmd, NULL); strvec_split(&child.args, cmd); strvec_pushl(&child.args, "--user", enable ? "enable" : "disable", "--now", NULL); - strvec_pushf(&child.args, "git-maintenance@%s.timer", frequency); + strvec_pushf(&child.args, SYSTEMD_UNIT_FORMAT, frequency, "timer"); if (start_command(&child)) return error(_("failed to start systemctl")); @@ -2429,24 +2501,58 @@ static int systemd_timer_enable_unit(int enable, return 0; } +/* + * A previous version of Git wrote the timer units as template files. + * Clean these up, if they exist. + */ +static void systemd_timer_delete_stale_timer_templates(void) +{ + char *timer_template_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "timer"); + char *filename = xdg_config_home_systemd(timer_template_name); + + if (unlink(filename) && !is_missing_file_error(errno)) + warning(_("failed to delete '%s'"), filename); + + free(filename); + free(timer_template_name); +} + +static int systemd_timer_delete_unit_files(void) +{ + systemd_timer_delete_stale_timer_templates(); + + /* Purposefully not short-circuited to make sure all are called. */ + return systemd_timer_delete_timer_file(SCHEDULE_HOURLY) | + systemd_timer_delete_timer_file(SCHEDULE_DAILY) | + systemd_timer_delete_timer_file(SCHEDULE_WEEKLY) | + systemd_timer_delete_service_template(); +} + static int systemd_timer_delete_units(void) { - return systemd_timer_enable_unit(0, SCHEDULE_HOURLY) || - systemd_timer_enable_unit(0, SCHEDULE_DAILY) || - systemd_timer_enable_unit(0, SCHEDULE_WEEKLY) || - systemd_timer_delete_unit_templates(); + int minute = get_random_minute(); + /* Purposefully not short-circuited to make sure all are called. */ + return systemd_timer_enable_unit(0, SCHEDULE_HOURLY, minute) | + systemd_timer_enable_unit(0, SCHEDULE_DAILY, minute) | + systemd_timer_enable_unit(0, SCHEDULE_WEEKLY, minute) | + systemd_timer_delete_unit_files(); } static int systemd_timer_setup_units(void) { + int minute = get_random_minute(); const char *exec_path = git_exec_path(); - int ret = systemd_timer_write_unit_templates(exec_path) || - systemd_timer_enable_unit(1, SCHEDULE_HOURLY) || - systemd_timer_enable_unit(1, SCHEDULE_DAILY) || - systemd_timer_enable_unit(1, SCHEDULE_WEEKLY); + int ret = systemd_timer_write_service_template(exec_path) || + systemd_timer_enable_unit(1, SCHEDULE_HOURLY, minute) || + systemd_timer_enable_unit(1, SCHEDULE_DAILY, minute) || + systemd_timer_enable_unit(1, SCHEDULE_WEEKLY, minute); + if (ret) systemd_timer_delete_units(); + else + systemd_timer_delete_stale_timer_templates(); + return ret; } diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 487e326b3fa..9ffe76729e6 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -744,7 +744,15 @@ test_expect_success 'start and stop Linux/systemd maintenance' ' # start registers the repo git config --get --global --fixed-value maintenance.repo "$(pwd)" && - test_systemd_analyze_verify "systemd/user/git-maintenance@.service" && + for schedule in hourly daily weekly + do + test_path_is_file "systemd/user/git-maintenance@$schedule.timer" || return 1 + done && + test_path_is_file "systemd/user/git-maintenance@.service" && + + test_systemd_analyze_verify "systemd/user/git-maintenance@hourly.service" && + test_systemd_analyze_verify "systemd/user/git-maintenance@daily.service" && + test_systemd_analyze_verify "systemd/user/git-maintenance@weekly.service" && printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && test_cmp expect args && @@ -755,7 +763,10 @@ test_expect_success 'start and stop Linux/systemd maintenance' ' # stop does not unregister the repo git config --get --global --fixed-value maintenance.repo "$(pwd)" && - test_path_is_missing "systemd/user/git-maintenance@.timer" && + for schedule in hourly daily weekly + do + test_path_is_missing "systemd/user/git-maintenance@$schedule.timer" || return 1 + done && test_path_is_missing "systemd/user/git-maintenance@.service" && printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && From patchwork Thu Aug 10 20:39:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24EEAC001DE for ; Thu, 10 Aug 2023 20:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235881AbjHJUkL (ORCPT ); Thu, 10 Aug 2023 16:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235402AbjHJUj4 (ORCPT ); Thu, 10 Aug 2023 16:39:56 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F3B2D40 for ; Thu, 10 Aug 2023 13:39:55 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99c93638322so274466666b.1 for ; Thu, 10 Aug 2023 13:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699994; x=1692304794; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Pvj7xNw91xVkXjXziYyUb1oHNtWmQxz8O7lU4iJcn9c=; b=cZOc4Pzt0JYrGa2A3Or3gBdohJCFCmpRJgqo4AvckN+oY8FG5knNcE7RsG/gs3IxSp io33ISt2+b39Hes6lbrlER5s/88eN37O8q95r1kVHqfu0K0VJ+7fWKE/c7VuP4kO8m4C puu2EbGMCiX7voFXbexqt9Sia+WcfkElDmIOl/2/LnSyt129Z+m4NxM1etZRkt5QxUX4 pdFeOz/4TYQnSue2b75mB8BK81Ki7tiTMB9aNWVg5Khw970tHz6ke0ytkm5RDG9ZGX4k gugVlqrhi58Dq8oGalkPUBIzCai3ke9HsljmoL68FTmR71dL/uDFUfnOfvI6znf08YZi n0+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699994; x=1692304794; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pvj7xNw91xVkXjXziYyUb1oHNtWmQxz8O7lU4iJcn9c=; b=BZtNdLGSa/Yrh1N1GWKcz1dIXMaVFSNMCc5Jj767k/98iKDhxdZTG/ZQywfR/uMnw+ un+8M1mdzmF6oWeXc98e/e7Qcv0BDAWFTwiWLellyAhUjDPEVhJVmReqliel+m2VPhjB PDgx3USGZ9aXi6Bn6tZIQWHwjKsaEuyjL8s+y5Z3x3wilzsrT0ArAFY58SJ48s8q8yLh MjvjgbAcB7ktpdAXNeP7bGWBflurfW01UGx88oL4W49uxYPOTmGRyieNAJ2ByV8mrIwU qjkvueo1N6syrjyIGFONgrywsg0Xc9qD3lH9gss+VJhSnMO5gaZGt6u6nvh9/cM3jQaW Epbw== X-Gm-Message-State: AOJu0YxT0zhvOboGCTsNq8+OzB4G7689tSgjiEkXMhtERHrElIIvnKkj 9tnF4hV5xwk4mbBqBv2FTSPtiCozvho= X-Google-Smtp-Source: AGHT+IE9pRGMYS6tpOfUtvOfY2Wvi/cx6juBpj1zgh9xr58v2BtXIU+ox2m8FOG77CIsStIiKKUtkA== X-Received: by 2002:a17:907:2c59:b0:99c:ae54:6654 with SMTP id hf25-20020a1709072c5900b0099cae546654mr20527ejc.14.1691699994050; Thu, 10 Aug 2023 13:39:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id kd7-20020a17090798c700b0099ba3438554sm1370402ejc.191.2023.08.10.13.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:53 -0700 (PDT) Message-ID: <86c4255d63d7f38b7a4811e5667404bce04f77f8.1691699987.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:46 +0000 Subject: [PATCH v2 7/8] maintenance: fix systemd schedule overlaps Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'git maintenance run' command prevents concurrent runs in the same repository using a 'maintenance.lock' file. However, when using systemd the hourly maintenance runs the same time as the daily and weekly runs. (Similarly, daily maintenance runs at the same time as weekly maintenance.) These competing commands result in some maintenance not actually being run. This overlap was something we could not fix until we made the recent change to not use the builting 'hourly', 'daily', and 'weekly' schedules in systemd. We can adjust the schedules such that: 1. Hourly runs avoid the 0th hour. 2. Daily runs avoid Monday. This will keep maintenance runs from colliding when using systemd. Signed-off-by: Derrick Stolee --- builtin/gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index e52129e485c..6f8df366fbe 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2350,11 +2350,11 @@ static int systemd_timer_write_timer_file(enum schedule_priority schedule, switch (schedule) { case SCHEDULE_HOURLY: - schedule_pattern = xstrfmt("*-*-* *:%02d:00", minute); + schedule_pattern = xstrfmt("*-*-* 1..23:%02d:00", minute); break; case SCHEDULE_DAILY: - schedule_pattern = xstrfmt("*-*-* 0:%02d:00", minute); + schedule_pattern = xstrfmt("Tue..Sun *-*-* 0:%02d:00", minute); break; case SCHEDULE_WEEKLY: From patchwork Thu Aug 10 20:39:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13349919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A9C3C001DE for ; Thu, 10 Aug 2023 20:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235273AbjHJUkN (ORCPT ); Thu, 10 Aug 2023 16:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235653AbjHJUkB (ORCPT ); Thu, 10 Aug 2023 16:40:01 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAB6790 for ; Thu, 10 Aug 2023 13:39:56 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fe426521adso2007318e87.0 for ; Thu, 10 Aug 2023 13:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691699995; x=1692304795; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=6tzSvACcIG7N9HhDyVHvty0LHt2uJL59NrztVHNMDsI=; b=pZmPOPJoYOOdtldhcxoACK40LDLTxXkDdIqGHCgbKpZE9+p3uQ2/sxsB7DLbKATUkh D4xgcgEAUiv3vE3DnuDWJncBNOGqKAFcZWKI7X9u/Rp10xtR7TIMrxuI5aDvHKG4C3KJ GFvIXxqrlRFSZBKTsQL+7MLe6ZrziwrvvcFT362bXAQv2YURV9HdqcXaP6w87vZLmdmS kpBIh2oikspYcZS7Sz46CN7zSsZD4hzzTasGl8BIV524ONpVKHpXxiSNeYRro+4KCNTZ r5j/CiuKRN9yJvgMofhTW4T4U/F5K1uGyp76n1AXItFtu9gfVXoZM0QJTeBSACqkXAAI zoqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699995; x=1692304795; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6tzSvACcIG7N9HhDyVHvty0LHt2uJL59NrztVHNMDsI=; b=mD/mZM0R7CNkbey4h1j6jc7bW5S/76Y7C7tbAPS6UOaLVGJzQDe+SaQKL0nU50K6ap NH8KEez8JYXFr2zNsgy57e1tWXiC9trnkbscszeUhgbCkKQTIk0UaaiAL8ZlThxJgvOr iEwAoZ7M1PviqnZSXjsdnDl4liSWE3vzsn5xbNvDJwde9aQ7xAqeXqn1x+qYqTrsqy7a tX1LWblsFftPBgl1D7SiQQfNPuxXQLDY9YDnIpXJcuCD2PAFbo266B+Q/HuDPZc87I3+ 5NWfe3UE7pnY9mDOH/EmmtD72AwFCM+BXrbdJy+Dd4UIbU+Z5mqyypGI6nL+iezepH+J J0VA== X-Gm-Message-State: AOJu0YykvzEqN3PBb3i6PJS3zWosFgqdlwN4YCFdVMD5H9AYWWsBkRHB qu0BTryMdy7PgifGf/j7rP1mZyzW8u0= X-Google-Smtp-Source: AGHT+IFzklOYjDh6PL2TM9bj3xYZX4ShbbEwWLehMyFK2CJtS3bPNi3q90ousAWWuqCN8nixScfu2A== X-Received: by 2002:a05:6512:31cf:b0:4fe:56d8:631d with SMTP id j15-20020a05651231cf00b004fe56d8631dmr3214250lfe.25.1691699994756; Thu, 10 Aug 2023 13:39:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m24-20020aa7c498000000b00521953ce6e0sm1204035edq.93.2023.08.10.13.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:39:54 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Thu, 10 Aug 2023 20:39:47 +0000 Subject: [PATCH v2 8/8] maintenance: update schedule before config Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, sandals@crustytoothpaste.net, lenaic@lhuard.fr, Taylor Blau , Phillip Wood , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When running 'git maintenance start', the current pattern is to configure global config settings to enable maintenance on the current repository and set 'maintenance.auto' to false and _then_ to set up the schedule with the system scheduler. This has a problematic error condition: if the scheduler fails to initialize, the repository still will not use automatic maintenance due to the 'maintenance.auto' setting. Fix this gap by swapping the order of operations. If Git fails to initialize maintenance, then the config changes should never happen. Reported-by: Phillip Wood Signed-off-by: Derrick Stolee --- builtin/gc.c | 5 ++++- t/t7900-maintenance.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 6f8df366fbe..fe5f871c493 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2728,9 +2728,12 @@ static int maintenance_start(int argc, const char **argv, const char *prefix) opts.scheduler = resolve_scheduler(opts.scheduler); validate_scheduler(opts.scheduler); + if (update_background_schedule(&opts, 1)) + die(_("failed to set up maintenance schedule")); + if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL)) warning(_("failed to add repo to global config")); - return update_background_schedule(&opts, 1); + return 0; } static const char *const builtin_maintenance_stop_usage[] = { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 9ffe76729e6..e56f5980dc4 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -849,4 +849,17 @@ test_expect_success 'register and unregister bare repo' ' ) ' +test_expect_success 'failed schedule prevents config change' ' + git init --bare failcase && + + for scheduler in crontab launchctl schtasks systemctl + do + GIT_TEST_MAINT_SCHEDULER="$scheduler:false" && + export GIT_TEST_MAINT_SCHEDULER && + test_must_fail \ + git -C failcase maintenance start && + test_must_fail git -C failcase config maintenance.auto || return 1 + done +' + test_done