Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojCVY-0004tN-6Z for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Oct 2022 04:41:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojCVV-0006pe-Vx for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Oct 2022 04:41:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojCVV-0006pU-La for pgsql-hackers@lists.postgresql.org; Fri, 14 Oct 2022 04:41:13 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ojCVT-0000og-1L for pgsql-hackers@postgresql.org; Fri, 14 Oct 2022 04:41:13 +0000 Received: by mail-pj1-x102a.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so3784068pjl.0 for ; Thu, 13 Oct 2022 21:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=35AuE0VFsm+SfgMMiQ9X9c29XjeU7t5NGNnu61VhnSo=; b=GErZqfuqI2ZicoNbaaOQDJOcj8Lo9pM1Zfrnk4sEWQ1Akhdme4DT9B54L4Nq7Ly695 9FrQc1SOK5ScclWynmwAiQ7+ksCpHD+CXxndkPYSSju/SATG57KcohGJJNrv/6JQcM4r /jqHYgoP80cHNbng5gIAKri/EsXwmknMfXntvFX7q4VPTs27N9WF0iort6AZiQ+bKjYS ZWcZeUWi8R7hq2hYlHXoHXTI9B3z+sreHdXfUIzV0V5Yof/FcuvGr+t9GpXWwKHRxzGV 4nus8FBQ9k+dDZloa5s11iyZ7FshIgACKjFfrpWwEAmj2QWg8KmhGm4GHk2MumJ22lpQ WHXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=35AuE0VFsm+SfgMMiQ9X9c29XjeU7t5NGNnu61VhnSo=; b=sOHvNJ5fu8w2NoO+pUCTAqq2q+VWeblyDyauCDoXs9dvjDpomAOZLByBDBxuJ/71Us PCNRNPWBIqRovwJJCRH274+cdG6ridnzhUklwF+RanRrnOawWyCJMwuxjYBb1jUFiRGM 7ZBEcsGRoXYk0vgYQLGZshttq6vyY+XvtBPSgIEtQfiR+2HaPgWaApAhgYe/NWq2G6oD SHCdgPX2uHWIbeMlCpSgkTqKQ+a5bKzIWVMr5O29Yo7jdVET5W7EKV+onywVGNClXLBA /P3eQ1cNks4Lh6npnj4KnrvbAwAF+ERxW4LQjCLwQpF+q8t/AD6882Dg8eR6o/iysz03 1ejw== X-Gm-Message-State: ACrzQf3f934XjUEElSNKYMhsjPY2mN2YfSWE+fagZ9NPuolmdweS/cKI 2XYVfsVFWPqQHjToSIOiHEjJ07mCIzg= X-Google-Smtp-Source: AMsMyM4hbszS2O8OP3y+AVJTIxVUnDNHXzCaGc1JlWBAUKPS0jPGPRMJGoYXVnypyIUmn134fz2Axw== X-Received: by 2002:a17:90b:2741:b0:20a:ebc3:6513 with SMTP id qi1-20020a17090b274100b0020aebc36513mr3706187pjb.29.1665722468729; Thu, 13 Oct 2022 21:41:08 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id d14-20020a170902b70e00b00178af82a08dsm670587pls.91.2022.10.13.21.41.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 21:41:07 -0700 (PDT) Date: Thu, 13 Oct 2022 21:41:06 -0700 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: thinko in basic_archive.c Message-ID: <20221014044106.GA1673343@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="a8Wt8u1KmwUX3Y2C" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi hackers, I intended for the temporary file name generated by basic_archive.c to include the current timestamp so that the name was "sufficiently unique." Of course, this could also be used to determine the creation time, but you can just as easily use stat(1) for that. In any case, I forgot to divide the microseconds field by 1000 to obtain the current timestamp in milliseconds, so while the value is unique, it's also basically garbage. I've attached a small patch that fixes this so that the temporary file name includes the timestamp in milliseconds for when it was created. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --a8Wt8u1KmwUX3Y2C Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="fix_basic_archive_timestamp.patch" diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c index 776a386e35..a02708fc12 100644 --- a/contrib/basic_archive/basic_archive.c +++ b/contrib/basic_archive/basic_archive.c @@ -265,7 +265,7 @@ basic_archive_file_internal(const char *file, const char *path) */ gettimeofday(&tv, NULL); if (pg_mul_u64_overflow((uint64) 1000, (uint64) tv.tv_sec, &epoch) || - pg_add_u64_overflow(epoch, (uint64) tv.tv_usec, &epoch)) + pg_add_u64_overflow(epoch, (uint64) tv.tv_usec / 1000, &epoch)) elog(ERROR, "could not generate temporary file name for archiving"); snprintf(temp, sizeof(temp), "%s/%s.%s.%d." UINT64_FORMAT, --a8Wt8u1KmwUX3Y2C--