Skip to content

fix(#5812): make the @props JSON type hint opt-in, off by default - #5860

Merged
lvca merged 2 commits into
mainfrom
fix/5812-props-metadata-opt-in
Aug 6, 2026
Merged

lvca merged 2 commits into
mainfrom
fix/5812-props-metadata-opt-in

Conversation

@lvca

@lvca lvca commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #5812.

The per-column @props type hint (added in #4267/#4849) is meant to let a consumer rebuild the exact Java type of a non-element (projection/aggregate) result column - e.g. count(*) yielding a Long that plain JSON would otherwise collapse to Integer. In practice it was unconditionally emitted on every HTTP response, including plain SELECT projections and SELECT FROM schema:types, regardless of who was asking. Any HTTP client (curl, wget, another language, Studio) got the extra @props field whether it needed it or not, exactly as reported in the issue.

Today the only real consumer of this hint is the RemoteDatabase Java driver (json2Result/RemoteImmutableDocument), and even there only for non-element rows - element/document rows already carry @type plus the schema, so they never needed the hint.

Changes

  • JsonSerializer: new includeTypeHints flag (default false) gates @props emission in serializeResult. Building the per-column type-hint string is now skipped entirely when the flag is off, which also avoids the wasted StringBuilder/type lookups on the hot HTTP response path.
  • AbstractQueryHandler / GetQueryHandler / PostCommandHandler: a new typeHints request flag (query parameter on GET /query, JSON field on POST /command) is threaded through to JsonSerializer, decoupled from the existing serializer (record/graph/studio/default) selection - serializer controls the response shape, typeHints controls this specific metadata field. Both default to false.
  • RemoteHttpComponent: the Java driver now sends typeHints: true alongside the existing serializer: record, so its own type-fidelity behavior (e.g. count(*) staying a Long, FLOAT/SHORT/temporal columns) is unaffected.
  • map2json's existing @props behavior (used when an embedded/document toJSON(true) is requested, e.g. for schemaless properties) is left untouched - it's a separate, already-narrower code path not implicated by the reported issue, called out here so it isn't mistaken for an oversight.

Test plan

  • New Issue5812PropsTypeHintHttpIT reproduces both repros from the issue against a live server: SELECT num FROM Doc (SHORT column) and SELECT FROM schema:types, verifying @props is absent by default and present only with typeHints=true/"typeHints": true.
  • JsonSerializerTest updated: existing type-fidelity tests now opt in via setIncludeTypeHints(true); new propsHintOffByDefault() pins the default-off behavior for a plain JsonSerializer.
  • Ran the existing HTTP handler suite (AbstractQueryHandlerIT, PostCommandHandler*, HTTPDocumentIT, HTTPGraphIT) and the driver suite (RemoteDatabaseIT, Issue4267CountTypeIT, RemoteGraphBatchIT) - all pass, confirming the driver's type reconstruction (the original reason @props exists) is unaffected.
  • mvn compile test-compile clean on engine, network, server

🤖 Generated with Claude Code

The per-column @props type hint (added for issue #4267) leaked into every
HTTP JSON response for non-element rows, including SELECT projections and
SELECT FROM schema:types, even though only a caller rebuilding the exact
Java type of a column - today the RemoteDatabase Java driver - needs it.

JsonSerializer now gates @props emission behind a new includeTypeHints
flag (default false). The HTTP query/command handlers accept a typeHints
request flag (query parameter on GET, JSON field on POST) to opt in, and
RemoteHttpComponent sets it on every driver request so the Java driver's
type fidelity is unaffected.
@mergify

mergify Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@lvca lvca added this to the 26.9.1 milestone Aug 6, 2026
@lvca lvca self-assigned this Aug 6, 2026
@lvca

lvca commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

@claude please review this.

@lvca

lvca commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

@claude please review

@lvca
lvca merged commit fe66e94 into main Aug 6, 2026
7 of 10 checks passed
@lvca
lvca deleted the fix/5812-props-metadata-opt-in branch August 6, 2026 22:32
lvca added a commit that referenced this pull request Aug 7, 2026
… exists, and pin the SORTED elision

The class javadoc referenced issue #5860 as the tracked follow-up for
renumbering ids during the data file rewrite. #5860 is an unrelated,
already-merged PR - the follow-up had never been filed. Filed as #5870
and the reference corrected.

Also pins the JDK behaviour the ascending traversal relies on, since a
review round questioned it: IntPipeline.sorted() returns the sink
unchanged when StreamOpFlag.SORTED is known, and the flag propagates
from a spliterator whose getComparator() is null and survives the
filter() the call sites apply first. A spliterator that claims sorted
and yields descending values comes back descending, which is what makes
declaring SORTED load-bearing rather than decorative - if the traversal
were ever not ascending, ordinalToVectorId would go unsorted and the
Arrays.binarySearch over it would quietly stop finding ordinals.

Release note records that getVectorIdsForRid's contract inverted: live
ids only, ascending, where it used to include tombstoned ones and ask
the caller to re-check.
lvca added a commit that referenced this pull request Aug 7, 2026
…rays (~90 -> ~32 bytes per live vector) (#5861)

* perf(engine) #5588: lay the vector location index out in primitive arrays

VectorLocationIndex held one boxed entry per live vector in a
ConcurrentHashMap<Integer, VectorLocation> plus a ConcurrentHashMap<RID,
int[]> reverse index, retaining ~90 bytes per live vector to carry ~20
bytes of payload. Vector ids are dense and monotonically assigned, so
they address arrays directly.

The mapping is now four primitive arrays indexed by vector id - the file
offset with its compacted flag packed into one long, the RID's bucket id
and position, and one presence bit - at ~21 bytes per id plus 8 to 16
bytes per live vector for the reverse index. A 10M-vector index goes
from ~900MB to ~320MB with no per-entry objects at all.

The arrays are CHUNKED (128 ids) and a chunk is released as soon as its
last live id is tombstoned. That is not an optimisation: it is what
preserves the property #5516 exists for, that residency follows the live
vectors and not the ids handed out. A re-embedding workload hands out
9.3M ids for a 4K live set, and a flat id-indexed array would retain
~190MB where the map it replaces retained ~360KB.

Publication is by release/acquire on the array element itself, at both
levels - the chunk directory slot and the presence word - because a
plain element store into an already-published array carries no
happens-before edge for a reader that read the enclosing field earlier.
Three orderings are load-bearing and documented where they live:

- the offset and its compacted flag share one 64-bit word, so they can
  never be read from two generations. applyReplicatedPageUpdate
  re-points a live id at the compacted file on a replica with no index
  lock held, and a misaligned page read parses into a well-formed vector
  that passes every guard;
- a chunk is dropped only after its bits are cleared, asserted, or a
  reader holding the stale reference resurrects a tombstoned vector;
- clear() zeroes the live chunks before publishing the empty directory,
  since it is the one path that reuses ids.

The reverse index stores no keys: a candidate slot is verified by
reading the id's RID back out of the location arrays, which makes it
unable to produce a wrong id and makes a tombstoned id structurally
unreachable through it. Nothing is ever removed - a dead slot is already
unreachable - and dead slots are reclaimed at a rehash sized from the
live count, never from the current capacity.

Every reader moved onto accessors that answer one field without
materializing anything, so no search path allocates where it did not
before. The graph-build snapshot is the same structure now instead of a
Map<Integer, VectorLocation>, which removes a transient ~900MB copy of
the live set from every rebuild on a 10M-vector index.

estimatedLocationIndexBytes is measured off the arrays actually
allocated rather than count x a constant, and steps down ~3x.
APPROX_RETAINED_BYTES_PER_LOCATION is re-based from 90 to 32 together
with the prose that quotes it.

* chore(engine) #5588: address code review

- rehash() hashes from the bucketId/position it already has in hand
  instead of re-resolving the chunk through the hash(vectorId) overload
- the "no engine path re-points a live vector id" precondition is now
  counted rather than only documented. An assert would have been louder
  and wrong: the branch does the safe thing and has tests that prove it,
  so asserting would fire on them. inPlaceRidRewriteCount() must stay
  zero, pinned by LSMVectorIndexTombstoneMemoryTest across the
  re-embedding cycles that would trip it first, and the counter itself
  is covered so it cannot rot into dead code
- getActiveCount() and estimatedRetainedBytes() document their
  O(allocated chunks) cost and point at size() as the O(1) answer
- the LSMVectorIndexMetadata message notes that quoting the same
  constant as bytes-per-vector and MB-per-million is the same number in
  two units, not a copy-paste slip

Also carries the merge of main: #5786 withdrew GroupedRIDBitsFilter and
rewrote the grouped search, so that file is gone and the two getLocation
call sites the new grouped path introduced were moved onto getRid().

* chore(engine) #5588: getBucketId/getPosition are package-private

No engine caller needs half a RID - the readers either compare one via
isLocationOf() or need the object via getRid(). The two survive only so
a test can read the words straight out of the arrays and check getRid()
against them instead of against itself, which is not a reason to expose
them.

* docs(engine) #5588: quantify the compressed-oops assumption in the retained-heap estimate

estimatedRetainedBytes() assumes a 64-bit JVM with compressed oops, and
a 10M-vector index is exactly the deployment that runs a heap above the
~32GB threshold where they turn off. State what changes there rather
than leaving the reader to guess: array headers 16 -> 24 bytes and the
Chunk object 40 -> 56, so 2728 per chunk instead of 2680 - 1.8%. The
layout is 97% primitive payload, whose size does not depend on the oop
width, so reading the VM option back to correct for it would buy less
than the rounding already in "~21 bytes per id".

* docs(engine) #5588: state why the re-add window is benign, and harden the counting test double

- addOrUpdate's live path leaves the same not-deleted-and-no-location
  window the delete path is ordered to avoid. It is benign, and the
  asymmetry is the interesting part: on the delete path a reader falling
  through to the pages finds the id's PRE-tombstone entry, an older
  generation than the one being installed, while here the pages hold the
  very entry the call is installing. Ordering it the other way would be
  worse - a resident location whose id still reads as deleted makes the
  delta scan skip a live vector.
- ArcadePageVectorValues.getVector resolves the chunk twice on the
  document fallback where the getLocation it replaces resolved it once.
  Quantized indexes never reach it and the second resolution is an array
  index against the lookupByRID on the next line, so it is noted rather
  than fixed with an accessor that would exist for one caller.
- CountingLocationIndex has to extend VectorLocationIndex, so its own
  inherited state is permanently empty and any un-overridden read
  answers about nothing instead of about the delegate - silently. Every
  read LSMVectorIndex performs is now forwarded, not just the counted
  ones.

* docs(engine) #5588: point the renumbering follow-up at the issue that exists, and pin the SORTED elision

The class javadoc referenced issue #5860 as the tracked follow-up for
renumbering ids during the data file rewrite. #5860 is an unrelated,
already-merged PR - the follow-up had never been filed. Filed as #5870
and the reference corrected.

Also pins the JDK behaviour the ascending traversal relies on, since a
review round questioned it: IntPipeline.sorted() returns the sink
unchanged when StreamOpFlag.SORTED is known, and the flag propagates
from a spliterator whose getComparator() is null and survives the
filter() the call sites apply first. A spliterator that claims sorted
and yields descending values comes back descending, which is what makes
declaring SORTED load-bearing rather than decorative - if the traversal
were ever not ascending, ordinalToVectorId would go unsorted and the
Arrays.binarySearch over it would quietly stop finding ordinals.

Release note records that getVectorIdsForRid's contract inverted: live
ids only, ascending, where it used to include tombstoned ones and ask
the caller to re-check.

* fix(engine) #5588: restore the delta-scan tombstone guard the comment claims is there

An earlier edit replaced the guard with the comment explaining it and
dropped the statement itself, leaving a comment block that ends 'It
stays because it is what the line says it does, at the price of one bit'
above no line at all. Restored, and the comment now separates the two
independent reasons it cannot fire today - the flag it used to read has
been permanently false since #5516, and remove() purges the delta buffer
for the RID it deletes - from the reason it stays: the buffer and the
tombstone set are maintained by different code paths.

Also from the same review:
- inPlaceRidRewrites is volatile, so the diagnostic accessor is honest
  for a caller that reads it without having joined the writer. A
  counter that silently under-reports is worse than no counter
- getVectorIdsForRid documents that it allocates, so the 'no new search
  allocation' property is not read as covering it
- the per-vector figure is interpolated from
  APPROX_RETAINED_BYTES_PER_LOCATION where javadoc allows it, instead of
  being restated in prose that can drift away from the constant
waterWang added a commit to waterWang/arcadedb that referenced this pull request Aug 7, 2026
…Metadata in map2json

map2json was using the includeMetadata parameter to decide whether to emit the
@props type-hint string. This bundled @props into every toJSON(true) call,
including the WebSocket ChangeEvent broadcast path where no consumer can opt
in to receiving it.

Fix: use the serializer-level includeTypeHints field (off by default, same
as serializeResult from ArcadeData#5860) instead of the includeMetadata parameter. The
@props hint is now emitted only when the caller explicitly enables it via
JsonSerializer.setIncludeTypeHints(true).
lvca added a commit that referenced this pull request Aug 9, 2026
…n map2json (#5980)

* fix(#5863): decouple @props type hint emission from includeMetadata in map2json

map2json used the includeMetadata parameter to decide whether to emit the
@props type-hint string. This bundled @props into every toJSON(true) call,
including the WebSocket ChangeEvent broadcast path (and the Redis/Postgres
wire-protocol paths, which hit the same map2json call) where no consumer can
opt in to receiving it.

Mirror the #5860 fix for serializeResult: map2json now gates @props on the
serializer-level includeTypeHints field (off by default) instead of
includeMetadata, which keeps its original meaning of "include
@rid/@type/@cat/@in/@out" identity metadata only.

Adds a regression test pinning the off-by-default behavior at the Document
API level (mirroring propsHintOffByDefault from #5860) and a ChangeEvent
test asserting a broadcast payload never contains @props.

* style: unify propertyTypes emptiness check with serializeResult in map2json

Per code-review on #5980: serializeResult already migrated to
!propertyTypes.isEmpty(), map2json still used the older length() > 0 form.
No behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SQL] @props system property in results

1 participant