Class BatchedDefinitionResolver<N extends HistoricalNode & Comparable<? super N>>
- Type Parameters:
N- the node type the backend stores; seeAbstractDefinitionResolver.
AbstractDefinitionResolver. Definition writes are buffered per flush
and written in one round trip, then published to the lookup caches only after they are durable.
Callers validate points with validatePointForBatch(P, BatchContext, BatchedDefinitionResolver.DefinitionBatch), then call flush(BatchedDefinitionResolver.DefinitionBatch, BatchContext) (or run
executeDefinitionBatch(List) themselves and call stageForCachePublication(List, BatchedDefinitionResolver.FlushResult, BatchContext, BatchedDefinitionResolver.DefinitionBatch)), and
finally drainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch, BatchContext) after the value writes commit, or invalidateStagedKeys(BatchContext) on rollback. Backends implement executeDefinitionBatch(List), withResolvedId(N, HistoricalNodeId), publishResolvedNode(N), pathKeyFor(N) and isImplicit(N).
Safe for concurrent validation threads: per-point scratch state is thread-local and the batch they buffer into is deduplicated by path.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final classThread-safe accumulator of one flush's pending definition writes, deduplicated by path.static final recordThe resolver could not produce a usable node (implicit id).static final recordThe outcome of a definition flush.static final recordA write was buffered; the node's id is known after the flush.static final classThe accumulated definition work for one path in one flush: a retire, an upsert, or both.static final recordThe node already carries a real id.Nested classes/interfaces inherited from class AbstractDefinitionResolver
AbstractDefinitionResolver.LookupResult<N>, AbstractDefinitionResolver.NormalizedPathBundle, AbstractDefinitionResolver.ValidationResult<N> -
Field Summary
Fields inherited from class AbstractDefinitionResolver
logger, nodeIdCache, nodeTree, pathAdapter, tempDefinitionCache -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBatchedDefinitionResolver(BatchScopedDefinitionCache<N> tempDefinitionCache, HistoricalNodeTree<N> nodeTree, Map<HistoricalNodeId, HistoricalNodeVersionList<N>> nodeIdCache, QualifiedPathAdapter pathAdapter, LoggerEx logger, BiFunction<HistoricalNodeId, Instant, Optional<N>> priorNodeQuery, BiFunction<TemporalPoint<?, ?>, @Nullable N, N> newNodeBuilder, BiFunction<N, Instant, N> withCreatedTime, BiFunction<N, @Nullable Instant, N> withRetiredTime, BiFunction<N, DataType, N> withDataType, BiFunction<N, MetadataPoint, N> withMetadata, Function<TemporalPoint<?, ?>, Optional<DataType>> dataTypeExtractor, Consumer<N> cacheUpdater) -
Method Summary
Modifier and TypeMethodDescriptionfinal voiddrainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch<N> defBatch, BatchContext ctx) Publishes the flush's definitions to the lookup caches under the node tree write lock and clears their staging entries.final longReturns and resets the number of definition writes resolved by flushes since the last call.protected abstract BatchedDefinitionResolver.FlushResultWrites the batched definitions (retires and upserts) in the backend's own transaction and commits them before returning.flush(BatchedDefinitionResolver.DefinitionBatch<N> defBatch, BatchContext ctx) Writes the batch's buffered definitions throughexecuteDefinitionBatch(List), then stages each resolved node for publication bydrainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch, BatchContext).final voidClears the staging entries recorded inctxwithout publishing; the rollback counterpart todrainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch, BatchContext).protected abstract booleanisImplicit(N node) Returns whether the node still carries the not-yet-assigned id.protected abstract StringpathKeyFor(N node) Returns the path that correlates a node to its buffered write.protected abstract voidpublishResolvedNode(N node) Registers a resolved node in the lookup caches.final voidstageForCachePublication(List<BatchedDefinitionResolver.PendingWrite<N>> writes, BatchedDefinitionResolver.FlushResult result, BatchContext ctx, BatchedDefinitionResolver.DefinitionBatch<N> defBatch) Rebuilds each written node with its real id, stages it, and queues its cache publication on the batch.final <P extends TemporalPoint<?,?>>
BatchedDefinitionResolver.BatchValidation<N> validatePointForBatch(P point, BatchContext ctx, BatchedDefinitionResolver.DefinitionBatch<N> defBatch) Resolves a point to its node, buffering a definition write when one is needed.protected abstract NwithResolvedId(N template, HistoricalNodeId id) Rebuildstemplatewith the backend-assigned id.protected final voidwriteDefinition(N node, BatchContext ctx) Buffers the write into the current batch;flush(BatchedDefinitionResolver.DefinitionBatch, BatchContext)issues it.Methods inherited from class AbstractDefinitionResolver
backdatesVersions, lookupMatchingNode, lookupMatchingNode, normalizePath, publicNormalizePath, tempDefinitionCache, validateMetadataPoint, validatePointType
-
Constructor Details
-
BatchedDefinitionResolver
protected BatchedDefinitionResolver(BatchScopedDefinitionCache<N> tempDefinitionCache, HistoricalNodeTree<N> nodeTree, Map<HistoricalNodeId, HistoricalNodeVersionList<N>> nodeIdCache, QualifiedPathAdapter pathAdapter, LoggerEx logger, BiFunction<HistoricalNodeId, Instant, Optional<N>> priorNodeQuery, BiFunction<TemporalPoint<?, ?>, @Nullable N, N> newNodeBuilder, BiFunction<N, Instant, N> withCreatedTime, BiFunction<N, @Nullable Instant, N> withRetiredTime, BiFunction<N, DataType, N> withDataType, BiFunction<N, MetadataPoint, N> withMetadata, Function<TemporalPoint<?, ?>, Optional<DataType>> dataTypeExtractor, Consumer<N> cacheUpdater)
-
-
Method Details
-
drainWriteDefinitionCount
public final long drainWriteDefinitionCount()Returns and resets the number of definition writes resolved by flushes since the last call. At steady state this is0; otherwise new tags are registering or timestamps fall outside existing nodes' ranges. -
validatePointForBatch
public final <P extends TemporalPoint<?,?>> BatchedDefinitionResolver.BatchValidation<N> validatePointForBatch(P point, BatchContext ctx, BatchedDefinitionResolver.DefinitionBatch<N> defBatch) Resolves a point to its node, buffering a definition write when one is needed.- Returns:
BatchedDefinitionResolver.ResolvedNowwhen the node's id is already known,BatchedDefinitionResolver.PendingDefinitionwhen the flush will resolve it (correlate by path key), orBatchedDefinitionResolver.FailedValidation.
-
writeDefinition
Buffers the write into the current batch;flush(BatchedDefinitionResolver.DefinitionBatch, BatchContext)issues it.ctxis unused.- Specified by:
writeDefinitionin classAbstractDefinitionResolver<N extends HistoricalNode & Comparable<? super N>>- Parameters:
node- the node version to persist.ctx- the batch context that tracks staged keys.
-
flush
public final BatchedDefinitionResolver.FlushResult flush(BatchedDefinitionResolver.DefinitionBatch<N> defBatch, BatchContext ctx) Writes the batch's buffered definitions throughexecuteDefinitionBatch(List), then stages each resolved node for publication bydrainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch, BatchContext).- Returns:
- the resolved path-to-id map, or
BatchedDefinitionResolver.FlushResult.EMPTYwhen nothing was buffered.
-
stageForCachePublication
public final void stageForCachePublication(List<BatchedDefinitionResolver.PendingWrite<N>> writes, BatchedDefinitionResolver.FlushResult result, BatchContext ctx, BatchedDefinitionResolver.DefinitionBatch<N> defBatch) Rebuilds each written node with its real id, stages it, and queues its cache publication on the batch. Call only after the definition writes have committed. Use directly when runningexecuteDefinitionBatch(List)withoutflush(BatchedDefinitionResolver.DefinitionBatch, BatchContext);writesshould bedefBatch.snapshot(). -
drainPendingCachePublications
public final void drainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch<N> defBatch, BatchContext ctx) Publishes the flush's definitions to the lookup caches under the node tree write lock and clears their staging entries. Call only on the success path, after the value writes commit; on rollback callinvalidateStagedKeys(BatchContext)instead. No-op when nothing was published. -
invalidateStagedKeys
Clears the staging entries recorded inctxwithout publishing; the rollback counterpart todrainPendingCachePublications(BatchedDefinitionResolver.DefinitionBatch, BatchContext). Durable definition rows are left in place. -
executeDefinitionBatch
protected abstract BatchedDefinitionResolver.FlushResult executeDefinitionBatch(List<BatchedDefinitionResolver.PendingWrite<N>> writes) Writes the batched definitions (retires and upserts) in the backend's own transaction and commits them before returning.- Returns:
- the resolved path-to-id map and any paths that failed.
-
withResolvedId
Rebuildstemplatewith the backend-assigned id. -
publishResolvedNode
Registers a resolved node in the lookup caches. The caller holds the node tree write lock. -
pathKeyFor
-
isImplicit
Returns whether the node still carries the not-yet-assigned id.
-