Skip to content

Commit 3eeaf89

Browse files
authored
Apply additive storage changes at boot on BanyanDB, name the storage stage in StorageManipulationOpt, and log every storage resource's outcome in one place (#14276)
1 parent 410c5ed commit 3eeaf89

53 files changed

Lines changed: 2204 additions & 1151 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/en/changes/changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
* Debug the network-alias pairing of OTLP calls through a new admin module, `trace-pairing-debugging` (`SW_TRACE_PAIRING_DEBUGGING`, on by default, requires `trace-analyzer`). `POST /trace-pairing-debugging/start` turns on one capture per OAP node, shared by every reader, as each node owns a share of the traces; it runs while it is read, and stops a minute after the latest read or on `POST /trace-pairing-debugging/stop`, releasing what it found; each capture from a start to its stop is a round with its own `roundId`, which every node in it shares, and each listed entry names the OAP nodes that hold it. `GET /trace-pairing-debugging/pairings` lists, over the nodes, the peers matched to a server, with the server before it when a later match moved it, the callers, the count of calls and each match's outcome (`registered`, `gateway`, `uncomposed`, `tooLong`, `noService`); and the peers and the servers whose halves left without their pair (`expired`, `evicted`, `replaced`), each with its latest five trace ids.
111111
* BanyanDB: the OAP works with BanyanDB servers reporting API version `0.11` or `0.13`, the versions it supports. The `compatibleServerApiVersions` setting in `bydb.yml` (`SW_STORAGE_BANYANDB_COMPATIBLE_SERVER_API_VERSIONS`) is removed, as it could list versions the OAP does not support: a server reporting another API version, such as `0.10`, no longer boots even if the setting listed it, and a `bydb.yml` that still sets it boots with a warning. For debugging only, the environment variable `SW_STORAGE_BANYANDB_FORCE_SERVER_API_VERSION` makes the OAP work as one of those versions, whatever version the server reports.
112112
* Fix OAL `maxDouble()` / `minDouble()` failing the OAP boot on Elasticsearch without `logicSharding`: their column is now `double_value`.
113+
* BanyanDB: an init or default-mode OAP now applies additive schema changes (new columns, tags or fields) at boot to every measure, stream and trace, as it already did on JDBC and Elasticsearch, so a metric whose storage only gained columns in an upgrade no longer stays disabled. A breaking change (a removed or retyped column, a different entity) is still refused at boot. The OAP logs one line for each storage resource outcome its installers record: DEBUG when unchanged, INFO when created, updated or dropped, ERROR when an incompatible change is refused; the storage plugins log the DDL they run at DEBUG.
113114

114115
#### UI
115116

‎docs/en/concepts-and-designs/runtime-rule-hot-update.md‎

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ disagree a periodic scan is in flight or the node is mid-apply.
9595
The feature is three cooperating workflows:
9696

9797
1. **Boot** — OAP starts; static rule files on disk are loaded, with persisted
98-
runtime-rule entries substituted in or skipped at load time. Backend schema is
99-
read-only at boot — never reshaped, never dropped.
98+
runtime-rule entries substituted in or skipped at load time. Boot runs in
99+
production with no operator watching, so it only extends backend schema: it
100+
creates missing resources and applies additive changes, and never drops or
101+
breaks one.
100102
2. **On-demand** — an operator calls `POST /addOrUpdate`, `/inactivate`, or
101-
`/delete`. This is the **only** workflow that may change backend schema, because
102-
the operator explicitly asked for it.
103+
`/delete`. This is the **only** workflow that may make a breaking schema change
104+
(with `allowStorageChange=true`), because the operator explicitly asked for it.
103105
3. **Periodic scan** — every OAP node re-reads every runtime-rule entry every 30 s
104106
and converges its local state to match. This is what closes the convergence
105107
bounds above; nothing else does.
@@ -136,76 +138,99 @@ plugin intercepts each file before compilation and decides per-`(catalog, name)`
136138
- Persisted `ACTIVE` entry → compile the entry's content in place of the disk file.
137139
- Persisted `INACTIVE` entry → skip the file; the operator has tombstoned the rule.
138140

139-
Compilation registers each rule under **create-if-absent** semantics: missing backend
140-
resources are created; resources that already exist with a different shape are
141-
**skipped with an ERROR log**, the affected metric is disabled until the operator
142-
reconciles via `/addOrUpdate`. Boot is **never** allowed to silently reshape the
143-
backend — that would mask edits made while OAP was offline.
141+
Compilation registers each rule with the boot policy: missing backend resources
142+
are created, and a resource that lacks declared columns, tags or fields is
143+
**extended** (an additive change). Boot never applies a **breaking** difference — a
144+
removed or retyped column, tag or field, or a different entity: that would lose data
145+
or mask edits made while OAP was offline. On BanyanDB it is **refused with an ERROR
146+
log**, and the resource keeps its shape until an operator drops it with the storage's
147+
own tools or gives the metric a new name. (A rule edit that changes a metric's
148+
storage goes through `/addOrUpdate` with `allowStorageChange=true`.)
144149

145150
After every analyzer has loaded, the runtime-rule plugin runs **one synchronous
146151
scan** so any runtime-only entries (no static disk file) are applied before
147152
receivers open ingress. From that point on, the periodic-scan workflow takes over.
148153

149-
### Why boot cannot reshape the backend
154+
### Why boot applies additive changes only
150155

151-
If boot were allowed to update backend storage, a shape mismatch could silently
152-
rewrite the BanyanDB measure or the Elasticsearch mapping. Before this feature, the
153-
backends behaved inconsistently:
156+
An additive change leaves the stored data in place and keeps every writer working
157+
(OAP writes name their columns, tags and fields, in a layout each OAP keeps stable),
158+
so it is safe to apply unattended; the one cost, older rows of a BanyanDB tag moved
159+
between families, is described below. A breaking
160+
change can lose data or break readers, so it needs an operator decision. Before this
161+
policy, the backends behaved inconsistently:
154162

155163
- BanyanDB and JDBC silently accepted the mismatch — samples were written against
156164
the old schema and quietly truncated or rejected later.
157165
- Elasticsearch hard-failed boot on a strict-mapping type conflict.
158166

159-
Create-if-absent unifies the contract: schema mismatches are always surfaced as an
160-
explicit ERROR, boot always continues, the affected metric is disabled, and the
161-
operator reconciles explicitly through the on-demand workflow. The same shape is
162-
visible across every backend.
167+
The boot policy unifies the contract: additive changes are applied on every backend;
168+
a breaking change to a table, an index, a measure, a stream or a trace is left as it is
169+
(BanyanDB reports each as an ERROR); and boot always continues. A BanyanDB property is
170+
schemaless and takes any change. An Elasticsearch template is re-put when its mapping,
171+
shard / replica settings or order differ, and the new definition reaches only the
172+
indices created after it.
163173

164-
### Code-defined stream opt-in (narrow exception)
174+
### What boot does on each storage
165175

166-
The "boot never reshapes" rule above applies to **runtime-rule (MAL / LAL)**
167-
registration — those rules ride the `/addOrUpdate` REST workflow when their
168-
backing schema needs to change.
176+
Only an init or default-mode OAP changes the schema at boot; a `no-init` OAP waits
177+
until the init OAP has created the resources.
169178

170-
BanyanDB streams whose schema lives in OAP source code (e.g. `AlarmRecord`) can
171-
opt in to **additive** boot-time reshape via
172-
`@BanyanDB.Stream.AllowBootReshape`. When the stream opts in and the diff is
173-
purely additive, the installer calls `client.update` at boot to extend the
174-
live stream; non-additive divergences still record
175-
`SKIPPED_SHAPE_MISMATCH` and require an operator drop+recreate. Only the
176-
init / standalone OAP performs the reshape; non-init peers continue through
177-
the existing poll-and-wait loop so a single node drives DDL during a rolling
178-
restart.
179+
| Storage / resource | Additive change at boot | Breaking change at boot |
180+
|---|---|---|
181+
| JDBC table | `ALTER TABLE ... ADD COLUMN` | left as it is (JDBC only checks that columns exist) |
182+
| Elasticsearch index / template | mapping fields appended | the current index keeps its fields and settings (a settings difference on the `management` index, which is never re-created, is logged as a WARN); a re-put template applies to indices created later |
183+
| BanyanDB measure, stream, trace | updated in place | refused, with an ERROR log |
184+
| BanyanDB property | updated in place (schemaless: any change) | — |
185+
| BanyanDB index rule, binding, TopN | reconciled to the declared rule | reconciled to the declared rule |
179186

180-
"Additive" includes two cases:
187+
"Additive" for a BanyanDB measure, stream or trace covers two cases:
181188

182-
1. **New tag** — a brand-new `@Column` is appended to the live tag family.
189+
1. **New tag or field** — a brand-new `@Column` is added to the live schema.
183190
2. **Tag relocation between families** — a `@Column`'s `storageOnly` flag
184191
flips, moving the tag between the `storage-only` and `searchable`
185192
families. The tag identity and type are preserved; only its on-disk
186-
family location changes.
193+
family location changes. An entity tag cannot move: BanyanDB refuses it.
187194

188-
Drops, tag-type changes and entity changes are still rejected with
189-
`SKIPPED_SHAPE_MISMATCH`.
195+
A dropped or retyped tag or field, and a change to the entity, the sharding key,
196+
the interval, or a trace's trace-id / span-id / timestamp tag, are breaking and
197+
refused with `BOOT_REFUSED_BREAKING_CHANGE`.
190198

191-
When the primary `check*` records `SKIPPED_SHAPE_MISMATCH`, the dependent
192-
`IndexRule` and `IndexRuleBinding` reconciliation is **also skipped**. This
193-
preserves coherence between the stream / measure tag layout and the binding
194-
that points into it — without the gate, the binding would silently update to
195-
reference the new declared tag list while the live tag families still carry
196-
the old shape, leaving operators with a binding routing to tags that don't
197-
exist in the live family layout.
198-
199-
This opt-in is **BanyanDB-only**. JDBC and Elasticsearch are append-only on
200-
the data path and already accept additive column / mapping additions at boot
201-
without operator intervention, so the flag is unread on those backends.
199+
When a measure, stream or trace is refused, its `IndexRule` and `IndexRuleBinding`
200+
are **also left as they are** (the refusal's log line says so). This preserves
201+
coherence between the tag layout and the binding that points into it — without
202+
the gate, the binding would silently update to reference the new declared tag list
203+
while the live tag families still carry the old shape, leaving operators with a
204+
binding routing to tags that don't exist in the live family layout.
202205

203206
> **Operator caveat:** BanyanDB does not physically migrate existing rows
204207
> when a tag's family changes. Pre-existing data for the relocated tag stays
205208
> in its original on-disk family location; new writes go to the declared
206209
> family. Queries that route through a new IndexRule on the relocated tag
207210
> will only see post-reshape rows until historical data ages out via TTL.
208211
212+
### The schema log
213+
214+
Every OAP logs what it found and did for each storage resource — a table, an index
215+
or template, a BanyanDB group, measure, stream, trace, property, index rule, binding
216+
or TopN aggregation — one line for each outcome the installer records, with the mode it ran in: DEBUG when
217+
nothing changed, INFO when it was created, updated or dropped, ERROR when an
218+
incompatible difference was left unapplied. The storage plugins log the DDL they
219+
execute at DEBUG.
220+
For example:
221+
222+
```
223+
storage schema [BOOT_INSTALL] model [service_cpm]: measure(sw_metricsMinute/service_cpm_minute)=UPDATED[adds tags [layer searchable:TAG_TYPE_STRING]]
224+
storage schema [BOOT_INSTALL] model [service_resp_time]: measure(sw_metricsMinute/service_resp_time_minute)=BOOT_REFUSED_BREAKING_CHANGE[changes fields [value FIELD_TYPE_INT/... → FIELD_TYPE_FLOAT/...]; its index rules and binding are left as they are. To store the declared shape, delete the measure with BanyanDB's own tools before the next start (its data is lost), or give the metric a new name] — left as it is: boot applies additive changes only.
225+
```
226+
227+
The modes are `BOOT_INSTALL` (an OAP registering models at startup),
228+
`RUNTIME_APPLY` (the main OAP applying a runtime-rule change),
229+
`RUNTIME_PEER_VERIFY` (a not-main OAP checking at startup that the main OAP has
230+
applied the persisted rules; a rule that fails the check is loaded by a later scan)
231+
and `RUNTIME_LOCAL_ONLY` (no backend call: a not-main OAP's periodic scan, or the
232+
main OAP's `/inactivate`).
233+
209234
## On-demand workflow
210235

211236
Triggered by an HTTP call to one of the admin endpoints. A request arriving at any
@@ -293,7 +318,7 @@ never destroys data they might want back:
293318
row (returns `HTTP 409 requires_inactivate_first`), so destruction always goes
294319
through the explicit two-step `/inactivate → /delete` workflow. On an absent
295320
row it is an idempotent `200 not_found`. The `/inactivate` step has already
296-
torn down OAP-internal state under `withoutSchemaChange` (handlers, prototypes,
321+
torn down OAP-internal state under `RUNTIME_LOCAL_ONLY` (handlers, prototypes,
297322
Models cleared; backend measure preserved). What `/delete` does next depends on
298323
whether a bundled YAML twin exists on disk:
299324
- **No bundled twin (default mode)** — drops the row only; the backend measure
@@ -308,9 +333,9 @@ never destroys data they might want back:
308333
- **Bundled twin exists, `?mode=revertToBundled`** — schema-change path.
309334
Bundled may have a different shape than runtime, so the apply pipeline runs
310335
a unified flow: re-install the prior runtime DSL locally under
311-
`withoutSchemaChange` (no backend touch), apply the bundled YAML through
336+
`RUNTIME_LOCAL_ONLY` (no backend touch), apply the bundled YAML through
312337
the standard `compile → fireSchemaChanges → verify → commit` pipeline with
313-
`withSchemaChange`. The commit's delta drops runtime-only metrics through
338+
`RUNTIME_APPLY`. The commit's delta drops runtime-only metrics through
314339
the listener chain, registers bundled-only metrics, and reuses bundled-shared
315340
metrics at matching shape. The runtime row is then removed and the bundled
316341
rule is the active loader on this node. Peers converge via the periodic

‎oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/Analyzer.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ public static Analyzer prepare(final String metricName,
170170
final DslSourceRef sourceRef,
171171
final ClassPool pool,
172172
final ClassLoader targetClassLoader) {
173-
// Static boot / default path: create-if-absent. Runtime-rule on-demand apply passes
174-
// withSchemaChange() via the explicit-opt overload.
173+
// Static boot / default path: boot install (additive changes only). Runtime-rule on-demand apply passes
174+
// runtimeApply() via the explicit-opt overload.
175175
return prepare(metricName, filter, expression, meterSystem, sourceRef, pool, targetClassLoader,
176-
StorageManipulationOpt.schemaCreateIfAbsent());
176+
StorageManipulationOpt.bootInstall());
177177
}
178178

179179
/**
180180
* Prepare overload that carries a {@link StorageManipulationOpt}. Runtime-rule peer-side
181-
* apply passes {@link StorageManipulationOpt#withoutSchemaChange()} so subsequent
181+
* apply passes {@link StorageManipulationOpt#runtimeLocalOnly()} so subsequent
182182
* {@link #register()} call skips server-side DDL.
183183
*/
184184
public static Analyzer prepare(final String metricName,
@@ -194,7 +194,7 @@ public static Analyzer prepare(final String metricName,
194194
Analyzer analyzer = new Analyzer(metricName, filter, e, meterSystem, ctx);
195195
analyzer.pool = pool;
196196
analyzer.targetClassLoader = targetClassLoader;
197-
analyzer.storageOpt = storageOpt == null ? StorageManipulationOpt.schemaCreateIfAbsent() : storageOpt;
197+
analyzer.storageOpt = storageOpt == null ? StorageManipulationOpt.bootInstall() : storageOpt;
198198
analyzer.resolveTypeFromMetadata();
199199
return analyzer;
200200
}
@@ -233,13 +233,13 @@ public void register() {
233233
private ClassLoader targetClassLoader;
234234
/**
235235
* Storage-install policy threaded through to {@link MeterSystem#create}. Startup uses
236-
* {@link StorageManipulationOpt#schemaCreateIfAbsent()} (the default when callers don't set
237-
* it — never reshape the backend at boot). Main-node on-demand apply sets
238-
* {@link StorageManipulationOpt#withSchemaChange()}. Peer-node apply sets
239-
* {@link StorageManipulationOpt#withoutSchemaChange()} so local Metrics classes + BanyanDB
236+
* {@link StorageManipulationOpt#bootInstall()} (the default when callers don't set
237+
* it — boot applies additive changes only). Main-node on-demand apply sets
238+
* {@link StorageManipulationOpt#runtimeApply()}. Peer-node apply sets
239+
* {@link StorageManipulationOpt#runtimeLocalOnly()} so local Metrics classes + BanyanDB
240240
* MetadataRegistry populate without server-side DDL.
241241
*/
242-
private StorageManipulationOpt storageOpt = StorageManipulationOpt.schemaCreateIfAbsent();
242+
private StorageManipulationOpt storageOpt = StorageManipulationOpt.bootInstall();
243243

244244
/**
245245
* Analyse the full sample family map and produce meter-system metrics.
@@ -486,7 +486,7 @@ private void createMetric(final ScopeType scopeType,
486486
// bundle drops together on hot-remove.
487487
if (pool != null && targetClassLoader != null) {
488488
// Per-file: generated Metrics class goes directly into the supplied RuleClassLoader.
489-
// storageOpt controls server-side DDL: withSchemaChange() on main, withoutSchemaChange()
489+
// storageOpt controls server-side DDL: runtimeApply() on main, runtimeLocalOnly()
490490
// on peer — see the Analyzer class-level Javadoc for the main/peer contract.
491491
meterSystem.create(metricName, functionName, scopeType, pool, targetClassLoader, storageOpt);
492492
} else {

‎oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/MetricConvert.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ public static <T> Stream<T> log(Try<T> t, String debugMessage) {
8484
private final List<Analyzer> analyzers;
8585

8686
public MetricConvert(MetricRuleConfig rule, MeterSystem service) {
87-
// Static boot default: create-if-absent semantics. Runtime-rule on-demand callers use
88-
// the explicit-opt overload and pass withSchemaChange() to get reshape permission.
89-
this(rule, service, null, null, StorageManipulationOpt.schemaCreateIfAbsent());
87+
// Static boot default: additive changes only. Runtime-rule on-demand callers use
88+
// the explicit-opt overload and pass runtimeApply() to get reshape permission.
89+
this(rule, service, null, null, StorageManipulationOpt.bootInstall());
9090
}
9191

9292
public MetricConvert(final MetricRuleConfig rule, final MeterSystem service,
9393
final ClassPool pool,
9494
final ClassLoader targetClassLoader) {
9595
this(rule, service, pool, targetClassLoader,
96-
StorageManipulationOpt.schemaCreateIfAbsent());
96+
StorageManipulationOpt.bootInstall());
9797
}
9898

9999
/**
@@ -103,8 +103,8 @@ public MetricConvert(final MetricRuleConfig rule, final MeterSystem service,
103103
* @param service MeterSystem target for registration
104104
* @param pool per-file Javassist pool, or null to use the shared default
105105
* @param targetClassLoader per-file ClassLoader, or null to use the shared default
106-
* @param storageOpt policy for backend-side install; main-node passes withSchemaChange,
107-
* peer-node passes withoutSchemaChange to skip server DDL
106+
* @param storageOpt policy for backend-side install; main-node passes runtimeApply,
107+
* peer-node passes runtimeLocalOnly to skip server DDL
108108
*/
109109
public MetricConvert(final MetricRuleConfig rule, final MeterSystem service,
110110
final ClassPool pool,

‎oap-server/analyzer/trace-analyzer/src/main/java/org/apache/skywalking/oap/trace/analyzer/v2/compiler/TALClassGenerator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ private void collectSegmentDefs(final List<?> statements, final Map<String, Inte
572572

573573
/**
574574
* Install the storage model for every metric the rule declared. Runs before the rule sees a span; on the
575-
* boot path {@code create} is create-if-absent, as it is for MAL.
575+
* boot path {@code create} creates what is absent and applies additive changes only, as it does for MAL.
576576
*
577577
* @param meterSystem the meter system to register with
578578
*/

0 commit comments

Comments
 (0)