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 1jlGfg-0008C7-Gs for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2020 18:50:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlGff-0003RE-11 for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2020 18:50:55 +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 1jlGfe-0003R6-Qa for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2020 18:50:54 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jlGfc-0000wN-2i for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2020 18:50:54 +0000 Received: by mail-qt1-x82f.google.com with SMTP id g18so16342483qtu.13 for ; Tue, 16 Jun 2020 11:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=zpWZP56pVFnhthsM2vbTCaXuFI7C71v5xZgUykZl12M=; b=m9l1eaFyqoOtkF6xXFBU+gCvjRTCAOBcq6Oh+vQYlPkddbGesLWEebdpKf3dmJF8+S UOK40mpB4cZebbCB1ezkcjFbKbT6JWg/w6EirjHWApeznrWqF5GtLrYTHH4hVqU7dhGF UwxEKKiIrCf++vTMIJXQZ/N4UxlDl2uq0gsSwrFbT4mUDxciInm3KcwNxb0c0aRfjjo6 CkRTUcnvNlCH6sgfDn2n2mts4ALwCYRuOZrsZVc2hTmEQv+jOXZTrtBNjrKq8S5esG8q Mf5pAF7N2TWvOnDSux8timHBRquKkRWawz560zXvnVKfyLEQ9x0GXhpvyHRJ9Y5RA1xf m5Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=zpWZP56pVFnhthsM2vbTCaXuFI7C71v5xZgUykZl12M=; b=W7388bItRexwM+KzIfCsxoR8pRVsh0lRkpkpSb4dun9WFUH1v7QVQbEt445F7t7gD/ CZV+OSOUeDnwzlWl6VgRnSM0Y10Rfo3fidvyC+djTo+wd++kzdvk8ESFEAHlebIZ2vPC chHXNHFBi0t5YRm5WAOB1hanakrkM8eFjDR1t1vT7W7TCXy3ucswVZ9EdwTj+F+NYC+R zDdOmMmQJomf8woHgsImDjD9PYkMvtwoYTPsu4WuYYFnrcb0AbZ/qpK4yUMTWFLo5wsg 97ryVU8rAo70NYkS7X8mgufnSkrArnPc4Pj9ozaFqCghpJ+ZDpL58dNlHniuYuwQDnlV hZkg== X-Gm-Message-State: AOAM532uz7YrlrY/YF3S9LjUCgS+MCWHNuPLainRzWKqRvqDJmqCJCIx 2zkEfpwI79GOhWGQEnLPNBP16A== X-Google-Smtp-Source: ABdhPJzj+IE5GaEUi6H7fp564Nm45z/mcI7EUKg8e+tY58ZaX+9OVAb2qT7iUwcPuIQAx1FVGMG+6g== X-Received: by 2002:ac8:6f79:: with SMTP id u25mr22970867qtv.183.1592333450051; Tue, 16 Jun 2020 11:50:50 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id v189sm14756653qkb.64.2020.06.16.11.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 11:50:49 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id A823F2A3ACF; Tue, 16 Jun 2020 14:50:47 -0400 (-04) Date: Tue, 16 Jun 2020 14:50:47 -0400 From: Alvaro Herrera To: Fujii Masao Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: Review for GetWALAvailability() Message-ID: <20200616185047.GA19008@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Jun-17, Fujii Masao wrote: > While reading InvalidateObsoleteReplicationSlots() code, I found another issue. > > ereport(LOG, > (errmsg("terminating walsender %d because replication slot \"%s\" is too far behind", > wspid, NameStr(slotname)))); > (void) kill(wspid, SIGTERM); > > wspid indicates the PID of process using the slot. That process can be > a backend, for example, executing pg_replication_slot_advance(). > So "walsender" in the above log message is not always correct. Good point. > int wspid = ReplicationSlotAcquire(NameStr(slotname), > SAB_Inquire); > > Why do we need to call ReplicationSlotAcquire() here and mark the slot as > used by the checkpointer? Isn't it enough to check directly the slot's > active_pid, instead? > > Maybe ReplicationSlotAcquire() is necessary because > ReplicationSlotRelease() is called later? If so, why do we need to call > ReplicationSlotRelease()? ISTM that we don't need to do that if the slot's > active_pid is zero. No? I think the point here was that in order to modify the slot you have to acquire it -- it's not valid to modify a slot you don't own. > + /* > + * Signal to terminate the process using the replication slot. > + * > + * Try to signal every 100ms until it succeeds. > + */ > + if (!killed && kill(active_pid, SIGTERM) == 0) > + killed = true; > + ConditionVariableTimedSleep(&slot->active_cv, 100, > + WAIT_EVENT_REPLICATION_SLOT_DROP); > + } while (ReplicationSlotIsActive(slot, NULL)); Note that here you're signalling only once and then sleeping many times in increments of 100ms -- you're not signalling every 100ms as the comment claims -- unless the signal fails, but you don't really expect that. On the contrary, I'd claim that the logic is reversed: if the signal fails, *then* you should stop signalling. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services