xtdb icon indicating copy to clipboard operation
xtdb copied to clipboard

Postgres open-tx-log should not OOM

Open refset opened this issue 3 years ago • 3 comments

Based on a report from @jacobobryant via https://discuss.xtdb.com/t/where-clause-not-working/34

This should never cause an OOM:

(with-open [l (xt/open-tx-log (xtdb-node) nil true)]
  (while (.hasNext l)
    (.next l)))

This is using Postgres JDBC for the tx-log.

A SNAPSHOT release with a change to the fetch-size parameter was created (see 247dda0c62ff7b4f1ac534ae687e711976ddd5c7) but does not seem to have improved the situation.

Related: https://github.com/xtdb/xtdb/discussions/1163

refset avatar Jan 04 '22 14:01 refset

@jacobobryant does this print out anything successfully?

(def c (atom 0))
(with-open [l (xt/open-tx-log (xtdb-node) nil true)]
  (prn :next 0)
  (while (.hasNext l)
    (when (zero? (mod (swap! c inc) 1000))
      (prn :next @c))
    (.next l)))

There are one of two possibilities: (1) the open-tx-log call is fully materializing before returning (which this tests for), or (2) the consumed results are being retained somewhere.

refset avatar Jan 04 '22 14:01 refset

It does print. I modified the code segment to be more verbose:

(do
  (prn (java.util.Date.))
  (with-open [l (xt/open-tx-log (xtdb-node) nil true)]
    (prn :next 0 (java.util.Date.))
    (while (.hasNext l)
      (prn :next (swap! c inc) (java.util.Date.))
      (.next l))))

See xtdb-oom-output.txt. open-tx-log takes about 30 seconds to return, then the loop proceeds at several iterations per second until iteration 355, at which point it slows to 1 iteration per 1-2 seconds, then at iteration 360 it hung for 10-15 seconds and then OOMed.

jacobobryant avatar Jan 14 '22 22:01 jacobobryant

This is a behaviour of the postgres jdbc driver: https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor

It is tricky to get it to enable cursor support.

SevereOverfl0w avatar May 11 '22 22:05 SevereOverfl0w

MySQL's connector also fully materializes result sets by default https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html

wotbrew avatar Aug 30 '22 14:08 wotbrew

Moved notes to PR #1815

wotbrew avatar Aug 31 '22 13:08 wotbrew