From 7a4cafac16ac5702ebc70f9d70d8ff9972312e8a Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Mon, 11 Dec 2023 22:56:18 +0800 Subject: [PATCH] dump buffer on invalid insert (#3613) * dump buffer on invalid insert * dump to PERSISTENT_CACHE_DIR * fix warning * ensure dir is not nil --- config/runtime.exs | 3 ++- lib/plausible/ingestion/write_buffer.ex | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index 986a8b09d..830d459e9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -291,7 +291,8 @@ config :plausible, super_admin_user_ids: super_admin_user_ids, is_selfhost: is_selfhost, custom_script_name: custom_script_name, - log_failed_login_attempts: log_failed_login_attempts + log_failed_login_attempts: log_failed_login_attempts, + persistent_cache_dir: maxmind_cache_dir config :plausible, :selfhost, enable_email_verification: enable_email_verification, diff --git a/lib/plausible/ingestion/write_buffer.ex b/lib/plausible/ingestion/write_buffer.ex index 7854357fb..1c1d7191a 100644 --- a/lib/plausible/ingestion/write_buffer.ex +++ b/lib/plausible/ingestion/write_buffer.ex @@ -100,6 +100,15 @@ defmodule Plausible.Ingestion.WriteBuffer do Logger.info("Flushing #{buffer_size} byte(s) RowBinary from #{name}") IngestRepo.query!(insert_sql, [header | buffer], insert_opts) end + rescue + _ -> + path = + Path.join( + Application.get_env(:plausible, :persistent_cache_dir) || System.tmp_dir!(), + "insert_error.dump" + ) + + File.write!(path, state.buffer) end defp default_flush_interval_ms do