Should I lock the targets file when updating it?

10 views
Skip to first unread message

Wang Yngwie

unread,
Jan 13, 2021, 8:18:55 AM1/13/21
to Prometheus Users
I have a big targets file, it's about 8M size and there are more than twenty thousand targetgroups. When Prometheus scans  sd_files, my updating program might writing that file simultaneously. In that case, the Discovery process may read part of the file or encounter an error. Is it possible and should I lock the targets file while updating it?

Brian Brazil

unread,
Jan 13, 2021, 8:24:43 AM1/13/21
to Wang Yngwie, Prometheus Users
On Wed, 13 Jan 2021 at 13:18, Wang Yngwie <yngwi...@gmail.com> wrote:
I have a big targets file, it's about 8M size and there are more than twenty thousand targetgroups. When Prometheus scans  sd_files, my updating program might writing that file simultaneously. In that case, the Discovery process may read part of the file or encounter an error. Is it possible and should I lock the targets file while updating it?

Don't try locking, instead build up the new file in a temporary file and then rename() when you're done. 

--

Julien Pivotto

unread,
Jan 13, 2021, 8:26:36 AM1/13/21
to Wang Yngwie, Prometheus Users
You should then create a .tmp.yml file, then move the file (rename) to
the .yml, which is an atomic operation.

>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/37552d38-afd6-4162-a7ee-4a3fb5262ad2n%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Wang Yngwie

unread,
Jan 13, 2021, 8:44:10 AM1/13/21
to Wang Yngwie, Prometheus Users
Thanks for your reply very much, it really helps. ☺

Julien Pivotto <roidel...@prometheus.io> 于2021年1月13日周三 下午9:26写道:
Reply all
Reply to author
Forward
0 new messages