Add ThingsBoard latest-telemetry and attributes DAOs on IoTDB Table Mode#112
Closed
PDGGK wants to merge 4 commits into
Closed
Add ThingsBoard latest-telemetry and attributes DAOs on IoTDB Table Mode#112PDGGK wants to merge 4 commits into
PDGGK wants to merge 4 commits into
Conversation
… Mode (GSOC-304 Wk 5) Implements the ThingsBoard AttributesDao SPI (v4.3.1.2, 14 methods) on IoTDB Table Mode against the entity_attributes table, as a Path-3 stretch artifact that stays inert by default. - 13/14 methods implemented; findNextBatch is a relational keyset-pagination migration helper with no IoTDB equivalent, so it throws UnsupportedOperationException. The three v4.3.1.2 additions (findAllKeysByEntityIdsAndScopeAsync, findLatestByEntityIdsAndScope and its async form) are implemented. - save is a tag-only delete-then-insert under an entity read lock plus a per-identity lock; find takes the same identity lock so the gap is invisible. - Inert by default: no @repository on the DAO; an independent database.attributes.type selector decoupled from the timeseries selectors; an AttributesDaoConflictGuard fail-fast; and a constructor cluster-mode acknowledgement gate (iotdb.attributes.cluster_mode). - Strategy F: eight compile-only ThingsBoard/commons stubs, excluded from the built jar. - Documented Phase-1 limitations: null version (IoTDB has no sequence), empty non-null-profile key lookup, best-effort bulk reads. - 114 unit tests and 11 Testcontainers integration tests against apache/iotdb:2.0.8-standalone. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
…04 Wk 4) Adapts the Wk4 IoTDBTableLatestDao (single-table derived-latest, no shadow table) onto the merged PR-1 base so it coexists with the timeseries and attributes DAOs. No latest overlay yet — that is a follow-up. - LatestDao: findLatest (ORDER BY time DESC LIMIT 1), findAllLatest (LAST_BY(col,time) + MAX(time) GROUP BY key); saveLatest no-op and removeLatest half-open-window are documented derived-latest gaps. - Coherent opt-in activation via IoTDBTableLatestEnabledCondition (database.ts.type=iotdb-table AND database.ts_latest.type=iotdb-table + experimental flag), reusing the shared named session pool; a TimeseriesLatestDaoConflictGuard fails startup on a conflicting host DAO. - v4.3.1.2 TimeseriesLatestDao SPI stub (10 methods incl. findLatestByEntityIds /+Async) verified byte-for-byte against the real ThingsBoard source; pinned by StrategyFContractTest with a getDeclaredMethods length guard. - All three DAOs share one session pool via @ConditionalOnMissingBean(name). - 131 unit tests + 24 Testcontainers ITs (Latest 4 + Timeseries 9 + Attributes 11) against apache/iotdb:2.0.8-standalone. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
Closes the saveLatest/removeLatest gaps the single-table derived-latest cannot satisfy (mentor-confirmed: add a minimal latest overlay rather than document the latest-only paths as unsupported). - New telemetry_latest overlay table (telemetry shape, TTL='INF'), created only under the latest selector via a second schema-bootstrap bean. - saveLatest does a tag-only delete-then-insert into the overlay under a per-identity lock; the async batch writer prevents distinguishing latest-only from full-save, so the overlay is written on every saveLatest (it is therefore a per-key latest store, written once per latest update). version stays null. - findLatest/findAllLatest merge the derived latest (telemetry) with the overlay by max timestamp per key (overlay wins ties); the merge is max-by-ts, never additive, so latest-only keys surface and stale overlay rows are shadowed. - removeLatest snapshots the merged latest under the per-identity lock, deletes the in-window overlay row, and on rewriteLatestIfDeleted resurrects the next-older telemetry value into the overlay. - Documented Phase-1 residuals (flagged for review): version always null (Cassandra parity), a telemetry-derived removeLatest race for full-save values, overlay TTL='INF' growth, and the same-ts overlay-wins tie-break. - 141 unit tests + 31 Testcontainers ITs (Latest 11) against apache/iotdb:2.0.8-standalone. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
…304 PR-2) Make the non-null deviceProfileId degradation rationale precise in the DAO javadoc + the module README: it mirrors the official non-relational backend (CassandraBaseTimeseriesLatestDao.findAllKeysByDeviceProfileId also returns Collections.emptyList()), entity_attributes has no device_profile_id tag, and the sole upstream caller is DeviceProfileController GET /api/deviceProfile/devices/keys/attributes (TENANT_ADMIN, a config-time UI key enumeration) which tolerates an empty result. Failing loud would 500 under IoTDB while Cassandra returns empty -- an avoidable backend inconsistency. A real device->profile lookup remains a Phase-2 optional enhancement. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the second PR of the GSoC series (follows #110, the timeseries
TimeseriesDao, now merged). It adds the latest-telemetry and attributes storage paths for running ThingsBoard on Apache IoTDB 2.x Table Mode.What this adds
1.
IoTDBTableLatestDao— the ThingsBoardTimeseriesLatestDaoSPI on Table Mode.telemetrytable (ORDER BY time DESC LIMIT 1for a single key;LAST_BY(col, time) + MAX(time) GROUP BY keyfor all keys), so the normal full-save path needs no separate latest table.telemetry_latest) that captures the latest-only write/delete cases the single-table derived read cannot satisfy (e.g. the EntityViewLATEST_AND_WScopy path callssaveLatestwith no pairedsave()).findLatest/findAllLatestmerge the derived latest with the overlay by max timestamp per key. The overlay table is created only under the latest selector.2.
IoTDBTableAttributesDao— the ThingsBoardAttributesDaoSPI on Table Mode, against a dedicatedentity_attributestable.database.attributes.type=iotdb-tableis set — a selector that no current ThingsBoard release exposes — so a normal deployment never instantiates it and attributes keep flowing to the host entity DB. No@Repository; anAttributesDaoConflictGuardfails startup if a conflicting hostAttributesDaois present; a constructor gate requires an explicitiotdb.attributes.cluster_modeacknowledgement.Both follow the same activation isolation + compile-only ThingsBoard stub surface (excluded from the built jar) as #110, and reuse the module's single named session pool (deduped via
@ConditionalOnMissingBean(name=...)); each DAO can be activated independently.Testing
Verified with the build cache off: 141 unit tests + 31 Testcontainers integration tests (Latest 11 / Timeseries 9 / Attributes 11) against
apache/iotdb:2.0.8-standalone; apache-rat, checkstyle, spotless, dependency-analyze, and enforcer all clean. The compile-only SPI stubs are pinned to the real ThingsBoard v4.3.1.2 signatures byStrategyFContractTest.Points I'd appreciate review on
saveLatestwrites the overlay on every call: the async batch writer means the DAO cannot tell a latest-onlysaveLatestfrom a full-save's pairedsaveLatest, sotelemetry_latestends up being a per-key latest store (one row per key, delete-then-insert), merged with the derived read. It is therefore effectively a latest table (one extra write per latest update). It closes the gaps; I'd welcome confirmation the shape is acceptable, or a preference for a narrower variant.IoTDBTableLatestDaojavadoc):versionis alwaysnull(IoTDB has no per-series sequence — same as the Cassandra backend; the EDQS latest-indexonUpdateis suppressed for latest-only writes); for a purely telemetry-derived (full-save) latest,removeLatestand a concurrent historical delete are separate futures, so a re-read can transiently disagree until the historical delete lands;telemetry_latestisTTL='INF'with no entity-level cleanup; a same-timestamp cross-store type change resolves to the overlay value.AttributesDao.findAllKeysByDeviceProfileIdwith a non-nullDeviceProfileIdreturns an empty list — matching the official non-relational backend (CassandraBaseTimeseriesLatestDao.findAllKeysByDeviceProfileIdalso returnsCollections.emptyList()); the sole caller is a TENANT_ADMIN config-time UI key-enumeration endpoint (GET /api/deviceProfile/devices/keys/attributes) that tolerates empty. The rationale is documented in the DAO javadoc + README; a real device→profile lookup is a future optional enhancement.Happy to iterate.