Search and contents

Database Log Scanning

How a MES Node reads from a table in a target system's own database: an audit table, a transaction log, a status table. Kindred connects to the database the site already runs, reads the rows added since the place it stored last time, and each new row becomes one record. The record goes through the same Data Transformation Layer, Identity Resolution and Trigger Dispatch Queue path an OPC UA or MQTT record takes, so a mapping that works for one source key works for the others.

This is for a system whose own database is the integration surface the vendor leaves you. Kindred only reads it. It never writes to the target and never runs SQL you wrote.

What it can and cannot do

It can:

  • Read one table or view (a materialized view too), by schema-qualified name, in a Postgres database reached by host and port, in the order of a watermark column: an integer sequence, or a timestamp together with a key column that breaks ties.
  • Verify the database with a CA bundle (verify-full) and authenticate with a user name and password.
  • Keep its place: the position it has read up to is stored in the Node's own database, so a restart resumes where it stopped (see Delivery).
  • Catch a row that commits late, with a re-read window (lookback), and a row that is changed in place, with a hash of the row (change_detection).
  • Keep a row that cannot be ingested in a table of its own and go on with the rows behind it.

It cannot:

  • Read any database engine but Postgres. The engine is a provider, selected by the provider field, and Postgres is the only one shipped.
  • Run a query you write. There is no where, no join and no expression: the section names a table, a watermark column, a key column and the columns to read, and nothing else reaches the database as statement text. To filter or join, ask the site's DBA for a view and read the view.
  • Write to the target, or notice a row that was deleted there.
  • Read a table with no column that only moves forward. A column of any other type than an integer or a timestamp is refused.
  • Read a file-based database. A provider is for a database server reached over the network.

Only a MES Node takes a database_log section. Its config carries exactly one source, opcua, mqtt or database_log; a config with more than one, or none, is refused when it loads. The deviation_flagging, costing_variance, material_consumption and instruction_bindings sections each have a form that reads a field of each row, and it is the only form allowed beside database_log: the section names a field of your mapping (field, cycle_time_field, material_field) in place of an OPC UA node, the order is the row's own, and a section that names a node or a fixed order is refused. What is allowed beside which source has the table. The ERP and PLC / Generic Device Node Types do not take the section.

What a provider is

A provider is the part that knows one database engine: how to connect, quote a name, ask for the next rows after a position, describe a table and convert a value. Everything else (the scan, the stored position, batching, the lookback, the row's identity, dead letters and the redaction of the password) is shared. provider defaults to postgres; a value that is not a supported kind is refused when the config loads, and the message names the supported ones. A provider added later is a change to Kindred, not to a config, and owes the same four guarantees as the Postgres one:

  • It is handed declared names only and quotes them with the engine's own mechanism. No value from the config is ever statement text.
  • The session is read-only.
  • TLS is verified whenever a CA is set.
  • No secret appears in any error.

What the site provides

  • A read-only account. Grant it SELECT on the one table or view and nothing else. The Node also opens every session read-only, but that is a second line of defence, not the first.
  • A table or view with a watermark column that only moves forward and a key column that is unique per row. The watermark and the key must be two different columns. An index on the watermark (on the watermark and key together, for a timestamp) keeps each poll cheap.
  • Network reachability from the Node to the database's port, and the CA certificate that signed the database's certificate.
  • A host on the site's own network. See The host rule.
  • A DBA who agrees which columns the table exposes, and who keeps their names and types stable. The data dictionary below is what to agree. A column the Node reads that is later renamed or dropped makes every poll fail until the config is changed.

The data dictionary

A site's DBA decides what a table or view exposes, and the integrator writes the mapping against it. The data dictionary writes down what they should agree before a scan is configured: for each canonical event, the fields a row must carry, and the columns any log table needs. A Node Type ships its dictionary beside its definition, as data_dictionary.json: node-types/mes/data_dictionary.json for a MES Node.

The dictionary is a contract between the people, not a setting. The scan does not read it. At run time the mapping in the database_log section (source_keys, field_map and state_transition_rules) does all the work, so a site can run with no dictionary at all, and a dictionary that disagrees with a mapping changes nothing about what the Node does. It is also not a second list of events: the events are the Node Type's own event_types, and the dictionary only adds what the database side has to look like.

For each field the dictionary gives its canonical name, its type, whether a row must carry it, what it means, its unit where it has one, and a standard_ref: free text naming the element of an industry standard the field corresponds to. standard_ref is empty wherever none has been checked, and it stays empty until someone has checked one.

The log shape

Whatever it records, a log table needs these columns. The names below are the dictionary's; the site's columns have their own, and the mapping and the section's watermark_column and key_column say which is which.

ColumnTypeRequiredWhat it is
watermark integer or timestamp yes Only moves forward as rows are written. Rows are read in this order, and the last one read is remembered. A timestamp with no time zone needs source_timezone
key string or integer yes Unique per row, and a different column from the watermark
event_type string or integer yes Which kind of event the row records, as a name or a code. A mapping rule reads it; the connector does not
entity_id string yes The order the row is about, as the target's own system identifies it
status string yes The order's state when the row was written

The payload columns are the fields of the event the row becomes. For a MES Node:

EventFieldTypeRequired
OrderRelease order_id string yes
OrderRelease status string yes
OrderCompletion order_id string yes
OrderCompletion status string yes

status takes one of in-progress, blocked, completed, flagged or at-risk. A target that writes its own status text or integer codes keeps them: the mapping's rules turn them into these.

How a target exposes it

The dictionary says what the data is and not how it is reached. A DBA can:

  • Expose a view over the target's own tables, with the columns above. The Node reads it like a table. The read-only account cannot create one, so a view needs a DBA.
  • Fill a staging table, either the target itself or a job the integrator runs. The Node reads it like any table.
  • Offer an API. An API is not a database source: the REST connector reads it. The same dictionary can still be what the DBA and the integrator agree the API returns.

This connector reads a view or a table, anything the table check can describe (see A table that does not fit). It does not read an API.

Extending it

An integrator adds fields, or events, in a file of the same format and merges it over the shipped dictionary. The shipped meaning of a name is never replaced: a name the shipped dictionary already has is refused, in the log shape and in any event. An event that names a shipped event adds fields to it; a new event is added as it stands. A file must be for the same Node Type as the dictionary it extends.

{
  "node_type": "MES",
  "events": [
    {
      "event_type": "OrderRelease",
      "fields": [
        {
          "name": "work_center",
          "type": "string",
          "required": false,
          "meaning": "The work center the order was released to.",
          "standard_ref": ""
        }
      ]
    }
  ]
}

Load, validate and merge from the repository root:

from pathlib import Path

from engine.data_dictionary import (
    load_data_dictionary,
    load_shipped_data_dictionary,
    merge_data_dictionaries,
)

shipped = load_shipped_data_dictionary(Path("node-types/mes"))
site = load_data_dictionary(Path("site_dictionary.json"))
merged = merge_data_dictionaries(shipped, site)

Loading refuses a field with no type, a name used twice, and a key the format does not have; merging refuses a name the shipped dictionary has. Each error says where.

The ERP dictionary

node-types/erp/data_dictionary.json is kept, in the same format, for what an ERP's log would have to expose. It is not support for an ERP Node reading a database. An ERP Node reads its rest source only and takes no database_log section, so no ERP Node's config reads a table, and the connector described here is a MES Node's. An ERP's data reaches Kindred through the REST connector.

The stand-in database

The site's database is often not reachable while a config is written. Three table layouts that an integrator will meet are kept as a stand-in, each with a few rows and a mapping config, so the connector can be tried against a database of your own first:

LayoutWhat it is
audit_log An append-only audit table: an identity sequence, an integer event code, an entity, and an old and a new value. Mapped with state_transition_rules
order_status A wide order-status table updated in place, with an integer status code and an updated_at that has no time zone. Mapped with state_transition_rules, change_detection set to row_hash and a source_timezone
inventory_ledger An inventory transaction ledger of the kind an ERP keeps. Mapped with a field_map

They carry the awkward parts on purpose: integer codes, NULL, numeric values, padded char columns and timestamps with no time zone. A mapping config for each is checked against the data dictionary of its Node Type, so a config that names a canonical field the dictionary lacks fails.

A small command creates a layout in a database you provide and plays inserts and updates into it at the pace you choose, including a transaction that stays open while later ones commit (which is how to see what lookback does). It is test tooling, and the one Kindred tool that writes to a database, so it refuses a database it did not set up and a host that is not on a private network. Its page, db-row-player.md, has the layouts, the file formats and every command.

inventory_ledger is scanned and mapped against the ERP dictionary and is not wired to an ERP Node. An ERP Node reads its rest source only and takes no database_log section, so the ledger is there to try a ledger-shaped log, not as ERP support.

Configuration reference

The section is the database_log key of the Node's config. Every field is optional unless marked.

FieldDefaultMeaning
provider postgres The database engine. Postgres is the only one shipped
host required A host name or a literal IP address (see The host rule), at most 253 characters
port 5432 The database server's port (1 to 65535)
database required The database to connect to
user required The account to connect as
password Secret. Needs ca_bundle_path: a password is never sent over a connection that is not verified
ca_bundle_path CA certificate file the database's certificate must chain to. Setting it turns on verify-full
connect_timeout_seconds 10 How long a connection attempt may take (at most 3600)
statement_timeout_seconds 30 The longest any one statement may run (at most 3600)
table required The table or view, as name or schema.name. Names are case-sensitive: write them as the database holds them
watermark_column required An integer (smallint, integer, bigint) or a timestamp (timestamp, timestamptz) that only moves forward
key_column required Unique per row. Identifies a row, and orders the rows that share a timestamp
columns required The columns to read. A row's values are exactly these
start_from now Where the first scan begins: now reads nothing that exists yet, beginning reads the whole table
batch_size 500 Rows per read (1 to 10000)
poll_interval_seconds 30 Seconds between scans. A starting point: tune it for your site
max_consecutive_rejections 50 How many rows in a row may be dead-lettered before the scan stops (1 to 1,000,000). A row that ingests ends the run. A starting point: tune it for your site. See Dead letters
max_gap none For an integer watermark: a jump larger than this is written to the Activity Log. The rows after it are still read
lookback 1000 positions for an integer watermark, 300 seconds for a timestamp How far below the stored position each scan starts. 0 turns it off. At most 1,000,000 positions, or 86,400 seconds for a timestamp. The defaults are starting points: tune them for your site
change_detection key key, or row_hash for a table whose rows are updated in place
source_timezone The IANA zone a timestamp column without a time zone is written in, such as America/Chicago. Required when any column the scan reads, or the key column, is such a column
qualification_relevant true Whether an order release from this source runs First Article Inspection
source_keys The columns the mapping uses. Each must be read by field_map or state_transition_rules, or the Node refuses to start
field_map Canonical field to column name, for the Explicit mapping
state_transition_rules Rules that classify a row into canonical fields, for the Inferred mapping

poll_interval_seconds must be at least 1 and at most 86400.

A column the mapping reads that is not in columns would be null for every row. The Node refuses such a section when it loads, with a message that names the column, and the offline check reports it too (see Trying a config before it reaches the Node).

A worked example

{
  "host": "10.20.30.40",
  "database": "mes",
  "user": "kindred_reader",
  "password": "set-this-through-the-encrypted-config",
  "ca_bundle_path": "/etc/kindred/site-ca.pem",
  "table": "audit.order_events",
  "watermark_column": "seq",
  "key_column": "event_id",
  "columns": ["seq", "event_id", "order_no", "status", "changed_at"],
  "source_keys": ["order_no", "status"],
  "field_map": { "order_id": "order_no", "status": "status" }
}

A row of audit.order_events read with this config:

{
  "seq": 4121,
  "event_id": "e-8f2c",
  "order_no": "MO-2027-0412",
  "status": "released",
  "changed_at": "2027-03-08T09:15:00+00:00"
}

is the record, and the Explicit mapping turns it into these canonical fields:

{ "order_id": "MO-2027-0412", "status": "released" }

A value reaches the mapping converted to JSON: a timestamp as ISO 8601 text in UTC (one with no time zone is read in source_timezone first), a numeric as a string, bytea as base64, a date or time as ISO 8601 text, a UUID as text and NULL as null.

Supplying the password and confirming TLS

Put the password in the Node's config and keep that config encrypted: a file named *.enc.json is a SOPS file, decrypted in memory when the Node loads it (see the integrator walkthrough). The password field is marked secret, so it is replaced by a placeholder in GET /v1/config, left out of every validation error, and never appears in a log or in GET /v1/status.

TLS is verified whenever ca_bundle_path is set, and there is no fallback: if the certificate does not verify, the connection fails and is not retried in plaintext. Without ca_bundle_path the certificate is not checked (the session may still be encrypted), which is why a config with a password and no ca_bundle_path is refused when it loads. Two ways to confirm it is on: the config check refuses the password-only config, and the DBA can ask the database which sessions are encrypted. Kindred's sessions are named kindred-database-log:

SELECT a.usename, s.ssl, s.version
FROM pg_stat_ssl s JOIN pg_stat_activity a USING (pid)
WHERE a.application_name = 'kindred-database-log';

ssl is t for an encrypted session. The Node itself refuses a connection whose certificate does not chain to the CA, so an encrypted session from a config with ca_bundle_path is a verified one. Run the query on the database server, as an account that may read those views.

The host rule

host is a name or a literal IP address, and the database must be on the site's own network.

  • A literal IP is checked when the config loads: it must be a private address and not the unspecified one (0.0.0.0). A carrier-grade NAT range (100.64.0.0/10) is not private, so it is refused.
  • A name is not looked up when the config loads, so loading never depends on DNS. When the Node connects it resolves the name once, refuses the connection unless every address it got is private, and connects to those addresses, while the certificate is still verified against the name. There is no second lookup to change the answer.
  • Where the site has no DNS entry for the database, give its IP address. verify-full then compares the certificate against that address, so the address must be among the certificate's names.

Delivery

What counts as one record. A row is one record: the columns in columns, converted as above. A row whose watermark or key is NULL cannot be tracked and is never read.

The first scan. With start_from: now the Node stores the table's current highest position and reads only what is added after it; a table that is empty then still counts as a first scan done. With beginning it reads the whole table in batches of batch_size. Either way it then polls every poll_interval_seconds, and each poll reads to the end of the table.

Where it resumes. The position read up to is kept in the Node's own database, in database_log_watermarks, one row per Node instance and source. The source is host:port/database/table, so pointing the section at another database or table starts a first scan again. A row is delivered, and the position saved, batch by batch: the position moves only after a batch's rows are enqueued.

At least once, ingested once. A row's identity is a hash of the target, the table and the key value, the same on every read. The Trigger Dispatch Queue ignores a second Trigger with the same identity, so a row read twice (after a crash between the enqueue and the save, or by the lookback) is one Trigger. A row the queue or the dead-letter table already holds is not offered to ingest again, so a re-read adds nothing to the Activity Log either.

A restart. The Node resumes from the stored position. Rows that arrived while it was down are read on the first scan after it returns.

A reset. If the table's highest watermark is below the stored position (the database was restored from a backup, the sequence was reset), the scan stops, writes one Activity Log entry that starts reset: scan stopped, and does not read again by itself, because it cannot tell whether the old rows will come back. An empty table is not a reset: a log that is purged or rotated keeps scanning. To resume after a reset, remove the watermark row and restart the Node with start_from: beginning. Rows the queue already holds are skipped, so nothing is ingested twice. Do not use now: it would store the current highest position and skip everything between.

SELECT node_instance_id, source, position, start_position, updated_at FROM database_log_watermarks;
DELETE FROM database_log_watermarks WHERE node_instance_id = '<node instance id>' AND source = '<source>';

A jump in the watermark. A gap in an integer sequence is not an error by itself: rolled-back transactions leave them. With max_gap set, a larger jump is written to the Activity Log as gap: watermark jumped from X to Y and the rows after it are still read. max_gap means nothing for a timestamp watermark.

A table that does not fit. The table is checked once, as the Node starts: it exists, the account can read it, every column exists and the account may read each one the section uses, the watermark is an integer or a timestamp, the key is of a type whose values can be kept (not an interval, JSON, a network address, an array or a range), and a timestamp with no time zone has a source_timezone. A table that does not fit stops the Node, with a message naming the table or column. If the database cannot be reached as the Node starts, the Node starts anyway and tries again at every poll; nothing is read meanwhile, and if the table then turns out not to fit, one Activity Log entry starting scan not started: says so.

source_timezone

A timestamp column (without a time zone) holds a wall-clock time and no zone, so Kindred has to be told the zone. Set source_timezone to the IANA zone the target writes it in. It is required when any column in columns, or the watermark column or the key column, is such a column, and the table check names the column when it is missing. It is ignored for a timestamptz column. A value in the hour that occurs twice when the clock falls back is read as its first occurrence.

A watermark that is a zone-less timestamp repeats an hour when the target's clock falls back. A backward move of up to one hour within a day of a daylight-saving change in source_timezone is not taken for a reset, but rows written in the repeated hour, below the stored position, are not read until the clock passes it. Prefer a sequence as the watermark for such a target.

lookback

A sequence value is assigned when a row is inserted, but the row is visible only once its transaction commits. A row can therefore commit after a higher one has been read, and a scan that resumed exactly at the stored position would never see it. With lookback, each scan starts at the stored position less the lookback instead: a row that commits late inside the window is read on a later poll.

How to choose it. Longer than the target's longest write transaction, with room to spare. The default (1000 positions for an integer watermark, 300 seconds for a timestamp) is a starting point, not a recommendation for every site. The window includes its own start, so a lookback of 1000 re-reads 1001 positions.

What it costs. One query, and a re-read of that many rows on every poll. A re-read row is not ingested again and writes nothing to the Activity Log.

What it cannot catch. A transaction held open longer than the lookback is still missed. With lookback: 0 a late commit is lost. With start_from: now the lookback never reaches below the position the first scan began from, so rows that existed before the section was configured are still not read. The stored position never moves backward, and a re-read below it is not a reset.

change_detection

With key (the default) a row's identity is its key, which is right for an append-only log: a row is written once. A row that is updated in place (an order's status moves from in-progress to blocked) is read again, has the same identity as before, and is discarded as a repeat.

With row_hash the identity also holds a SHA-256 of the row's declared columns, so a changed row is a new event and a replayed row is not. This only works if the change can be seen:

  • The row must be read again, so the watermark must move when the row is updated: a timestamp such as updated_at. A table whose id watermark is unchanged by an update, or lookback: 0, never re-reads an edit. row_hash with an integer watermark is allowed, because a version counter does move on update, but an id sequence does not; the table check then adds a note (in the health check's message, and as a warning in the Node's log at start) and does not refuse the section.
  • The lookback must reach the row. An edit older than the window is not seen.
  • A row that changes from A to B and back to A has the identity of its first version, which the queue already holds, so the second change is dropped.
  • A column the section does not read cannot change the hash.
  • Editing columns changes every identity, so rows inside the lookback are emitted once more after such an edit.

Dead letters

One row that will not ingest must not stop a production feed, and a scan that raised on it would retry it for ever. So:

  • A row the pipeline rejects (the transform raises on it, for example) is kept at once.
  • A row the Node's own database keeps refusing with an error that can pass, such as a deadlock or a statement timeout, is tried five times in all (a wait of 0.5 s, doubling up to 10 s) and then kept.
  • Any other error on the Node's side, one that is not about the row (a role that has lost its right to write the queue, say), is kept too, row by row. Nothing replays a dead letter, so watch the count after such a fault.
  • The Node's own database being unreachable is not a row's fault. The scan stops, nothing moves forward, and the next poll tries again.

A run of rejections stops the scan. One bad row is not a fault in the mapping; fifty in a row (max_consecutive_rejections) are. A mapping that reads the wrong column, or a changed status code, would otherwise copy the table into the dead-letter table, row by row, and move the watermark past all of it. When the run is reached the scan stops, the Activity Log gets one entry starting scan stopped: that says how many rows, and the watermark stays where the last finished batch left it. The scan does not start again until the Node is restarted; the rows already kept stay held, so the restart reads on from behind them. Find the cause, fix the mapping, and restart. If the rows were wrongly kept, they stay in the dead-letter table; see below for making them eligible again. A row that ingests ends the run, so scattered bad rows never reach it.

A kept row is one row of database_log_dead_letters, written once. The watermark then moves past it and the rows behind it ingest. The Node's log has one error line for each (the table, the trigger id, the number of attempts and the exception type, never the row), and the Activity Log has an entry starting dead letter: that names the table and the trigger id and no row content, not even the key (the Activity Log cannot be edited afterwards, so the key is kept only in the dead-letter table).

ColumnMeaning
id The row's trigger id, the primary key
target host:port/database/table the row came from
key The row's key column value, as text
record The converted row (JSONB). It is stored here and never written to a log
reason The exception type, never its text
attempts Ingest attempts made
dead_lettered_at When it was kept
SELECT count(*) FROM database_log_dead_letters;
SELECT dead_lettered_at, key, reason, attempts, record FROM database_log_dead_letters ORDER BY dead_lettered_at;

Find the cause in the Node's log, using the trigger id. A dead-lettered id counts as dealt with, like a queued one, so neither a lookback re-read nor a full rescan offers the row again. Nothing reads the table back by itself. Once the cause is fixed, deleting its row makes the row eligible again only while it is still inside the lookback (or on a rescan from the beginning); past that, have the target write a new row for the event (or, with row_hash, change the row so that it has a new identity).

Reading status and failures

GET /v1/status runs a connection check on the database_log section as a session of its own. It asks the database whether it can be reached and whether the table and every declared column are there. It reads no row, it shows no row content, and it never reads or moves the Node's watermark. The check is named database_log, has connector type database_log, and its target is host:port/database. The messages you will see:

MessageMeaning
host:port/database is reachable and table 'T' has the declared columns The database answered, the account may read the table and every column is there
host:port/database refused the account 'U' The database refused the user name or password
could not reach host:port/database: ... Nothing answered, or the certificate did not verify; the reason follows
host:port/database: table 'T' was not found No such table or view, or the name's case differs
host:port/database: the account cannot read table 'T' The account has no SELECT on it
host:port/database: table 'T' has no column(s) a, b A declared column is missing
host:port/database: the account cannot read column(s) a, b of table 'T' The account has SELECT on some columns of the table but not on these
host:port/database: watermark column 'C' is of type X; only an integer sequence or a timestamp can be a watermark The watermark column is of another type
host:port/database: key column 'C' is of type X, whose values cannot be kept as a position; ... The key column is an interval, JSON, a network address, an array or a range; use a column of a plain type
host:port/database: column 'C' is a timestamp without a time zone: set source_timezone ... source_timezone is missing
a statement on host:port/database ran past the N s limit The database is too slow for statement_timeout_seconds
host:port/database: a value in table 'T' could not be read (DataError); ... A row holds a value the driver cannot decode; see Pitfalls
host:port/database: watermark column 'C' holds 'infinity' or '-infinity', which cannot be a watermark; ... A timestamp watermark has a row at infinity; read a view that gives a real time or NULL
the host name 'H' did not resolve; ... The name has no address; give the IP address

The check says nothing about the scan. To see where the scan is, and what it did:

SELECT node_instance_id, source, position, updated_at FROM database_log_watermarks;
SELECT occurred_at, outcome FROM activity_log
WHERE task_type IN ('database_log_scan', 'database_log_dead_letter') ORDER BY occurred_at DESC LIMIT 20;

The entries the scan writes to the Activity Log:

Entry startsWhen
scan started: ... Once each time the Node starts, with the lookback and change_detection in force.
gap: A jump in an integer watermark larger than max_gap.
reset: The table's highest watermark fell below the stored position.
scan not started: The start-up table check found a table that does not fit, after the database was unreachable at start.
dead letter: A row was kept in the dead-letter table.
poll failed: A poll failed, when the failure first appears or its message changes.
poll recovered: The next poll succeeded after a failure.
scan stopped: The run of rejections described under Dead letters.

A target that stays down is written once, not once per poll

A poll that fails for any reason is logged and tried again at the next poll. The reasons include the database being unreachable, a statement past its limit, a driver error, a changed watermark type, a stored position that cannot be read, and a key the table cannot keep.

  • Activity Log: one poll failed: entry when a failure first appears or its message changes, and one poll recovered: when the next poll succeeds. The entry carries the provider's message, or only the error's type for an error that is not Kindred's own. It never carries a row or a credential.
  • The Node's log has every poll, found with:
journalctl -u kindred-node.service --since '1 hour ago' | grep 'database log'

A line database log scan of host:port/database/table failed (...); trying again next poll appears once per poll for as long as the fault lasts, with the reason. database log table check could not run means the same for the start-up check.

Reading the two together. If the health check is red and the scan lines repeat, the fault is the target or the network, not Kindred. A scan that has simply caught up writes nothing at all, so a quiet log with a green check is a healthy, idle feed.

Trying a config before it reaches the Node

Set CANDIDATE to the config file, and run these from the repository root. The offline check validates the file the way the Node does, and for a database_log section also applies the section's own rules (a password needs a ca_bundle_path; the host must be a private-network address or a host name) and checks that every name the mapping reads is one of the declared columns. It reaches no database and looks up no host name:

python3 -m engine.offline_check_cli "${CANDIDATE:?set CANDIDATE to the config file}" node-types

--connect also tests the database with the check above, and --db-sample reads one row (the one with the highest watermark) and prints it, which shows what the mapping will be given. It is off by default, because the row is production data; a plain --connect reads none, and --mqtt-wait never turns it on. This one fails, because nothing answers on the database's port:

python3 -m engine.offline_check_cli "${CANDIDATE:?set CANDIDATE to the config file}" node-types --connect --db-sample --timeout 2

--db-sample belongs to --connect and is refused without it (exit 2):

python3 -m engine.offline_check_cli "${CANDIDATE:?set CANDIDATE to the config file}" node-types --db-sample

None of this writes to the Node's database, creates a watermark or advances one. See Checking a config before it is staged for the exit codes and the Python call, and Previewing a mapping over a sample to run captured rows through the mapping.

Pitfalls

  • row_hash sees a change only when the row is read again. It needs a watermark that moves on update and a lookback that reaches the row. A table whose id watermark does not change on update never shows an edit, whatever change_detection is.
  • With an integer watermark, row_hash sees an edit only by accident. A row still inside the lookback is read again and an edit shows; a row older than the lookback is never read, so the same edit shows or not depending on how recent the row is. Use it with a timestamp that moves on update.
  • A row edited from A to B and back to A is dropped the second time. It has the first version's identity, which the queue holds.
  • The lookback must be longer than the target's longest write transaction. A transaction held open past it commits a row the scan has already moved beyond, and that row is never read.
  • The lookback window includes its own start. lookback: 1000 re-reads 1001 positions on every poll.
  • The default lookback and poll interval are starting points. Set both on purpose for a production table.
  • Pruning trigger_queue inside the lookback re-reads those rows as new. The queue is what remembers a row was ingested; delete from it only rows older than the lookback.
  • Removing the watermark row recovers only with start_from: beginning. With now the scan stores the table's current highest position and skips every row in between.
  • The watermark table is not migrated. The Node creates database_log_watermarks if it is missing and never alters one that exists, so a column that a later release adds is not added to the table you have. A changelog entry marked "Action needed" says when a table must be changed by hand.
  • A name the mapping reads that is not in columns stops the Node at load, with a message that names the column. The offline check names it too, before the config reaches the Node.
  • A timestamp or date of infinity is read as text. In a declared column the value infinity or -infinity reaches the mapping as that text, not as a time, so a field_map copies it as it is and a rule can match on it. As the watermark it cannot work, since a position needs a real time: the table check refuses a timestamp watermark that holds one (the Node stops at start, or the health check goes red), and a scan that meets one later stops with the same message. Ask the DBA for a view that gives NULL or a real time instead, and read the view.
  • The host, port, database and table text is the source. Spelling the host differently (a name for an IP address, or the other way), or audit_log for public.audit_log, is another source with no stored position, so the first scan runs again: with start_from: now it skips what was written while the old spelling was in use, and with beginning it reads the whole table again under new identities, which the queue does not recognise.
  • Names are case-sensitive. Orders and orders are different tables. The table check says "was not found" for the wrong case.
  • Any other Node-side error is dead-lettered row by row, and nothing replays dead letters. After a fault on the Node's own database that was not an outage, look at the count of database_log_dead_letters and re-create the events from the target.
  • A target that stays down writes one Activity Log entry, not one per poll. The poll failed: entry appears when a failure first shows or its message changes. The repeats show only in the Node's log and the health check, so watch one of them.
  • A target that is down when the Node starts does not stop it. The Node starts, checks the table at the next poll that reaches the target, and writes one Activity Log entry if the table does not fit.
  • A deleted row is not noticed. A truncated or restored table whose highest watermark falls below the stored position is a reset and stops the scan; one that is simply emptied is not.
  • A second session counts against the database's connection limit. The Node holds one connection for its scans, and each status check opens another for a moment.
  • A literal IP with verify-full needs the address in the certificate. A certificate issued for the database's name alone fails when the config gives its address.

Release: v0.11.0