Skip to content

本页为英文技术参考;字段、编号与支持状态直接来自同一契约源。中文学习路线见 开发文档。

Storage ​

Persist private plugin data in authorized namespaces with revision checks and transactions. Namespace handles are scoped to the admitted load even when the persisted data survives restart.

Contract: nexa.storage/100. API index.

Typical sequence ​

Open the namespace, read before conditional writes, and use CompareExchange for competing updates. Commit a transaction only with its actual returned identity and revision.

Behavior and limits ​

Migration is explicit and bounded. A failed or oversized migration must not reset the store. The storage implementation assumes one trusted Host owner; it is not a distributed database protocol.

The recorded Host maps 8 of 8 operations in this group. A mapping is subject to permission, phase, scope, platform and business preconditions. Host snapshot identifies the source revision; negotiate against the actual installed Host.

Operations ​

OpenNamespace · Read · Write · CompareExchange · Query · BeginTransaction · Commit · Migrate

OpenNamespace ​

NamespaceRequest → StorageNamespace

PropertyContract
Local SDK method ID1
KindAcquisition
Permissionnexa.storage.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
NamespaceQualifiedIdPrivate storage namespace identity or handle. It remains subject to current-load ownership.
SchemaVersionulongVersion of the declared data schema; independent of SDK and ABI versions.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_OpenNamespace(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_OpenNamespace_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Read ​

StorageKey → StorageValue

PropertyContract
Local SDK method ID2
KindQuery
Permissionnexa.storage.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
NamespaceStorageNamespacePrivate storage namespace identity or handle. It remains subject to current-load ownership.
KeystringPrivate entry key inside the supplied namespace.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_Read(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_Read_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Write ​

StorageWrite → StorageValue

PropertyContract
Local SDK method ID3
KindMutation
Permissionnexa.storage.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

The recorded storage owner requires the existing entry’s exact revision for an update. An absent ExpectedRevision creates only a missing key; it does not mean unconditional overwrite.

Request fields

FieldTypeMeaning
NamespaceStorageNamespacePrivate storage namespace identity or handle. It remains subject to current-load ownership.
KeystringKey within this model’s owning namespace or record. It does not grant access outside that owner.
ValueAbiValuePayload interpreted using the accompanying or declared schema; Null is not a substitute for an error.
SchemaSchemaRefExact schema identity, version and fingerprint used to validate Value.
ExpectedRevisionRevision?Revision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target. Nullable; omission is distinct from an empty value. No implicit default is promised by this type.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_Write(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_Write_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

CompareExchange ​

StorageWrite → StorageValue

PropertyContract
Local SDK method ID4
KindMutation
Permissionnexa.storage.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Read the entry first and supply its exact revision. For a missing key, use an absent revision. A competing create/update fails with STALE_REVISION; both Write and CompareExchange enforce this rule in the recorded owner.

Request fields

FieldTypeMeaning
NamespaceStorageNamespacePrivate storage namespace identity or handle. It remains subject to current-load ownership.
KeystringKey within this model’s owning namespace or record. It does not grant access outside that owner.
ValueAbiValuePayload interpreted using the accompanying or declared schema; Null is not a substitute for an error.
SchemaSchemaRefExact schema identity, version and fingerprint used to validate Value.
ExpectedRevisionRevision?Revision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target. Nullable; omission is distinct from an empty value. No implicit default is promised by this type.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_CompareExchange(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_CompareExchange_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Query ​

StorageQuery → Page<StorageEntry> (wrapper, item)

PropertyContract
Local SDK method ID5
KindQuery
Permissionnexa.storage.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
NamespaceStorageNamespacePrivate storage namespace identity or handle. It remains subject to current-load ownership.
PrefixstringDomain value named by this field; additional accepted values and bounds are determined by the operation and Host policy.
PagePageRequestStructured PageRequest value; follow its linked field contract.

Successful result

Read Items and continue with NextCursor while preserving the original query. An absent cursor ends the sequence; an invalid cursor is an error.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_Query(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_Query_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

BeginTransaction ​

StorageNamespace → StorageTransaction

PropertyContract
Local SDK method ID6
KindMutation
Permissionnexa.storage.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
TokenGuidOpaque Host-issued handle token. Keep it with its owner and resource type.
LoadInstanceIdGuidIdentity of the admitted load that owns this handle; it is not portable to a replacement load.
NamespaceQualifiedIdPrivate storage namespace identity or handle. It remains subject to current-load ownership.
RevisionRevisionOpaque version token issued by the owner. Do not increment it or substitute another object’s revision.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_BeginTransaction(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_BeginTransaction_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Commit ​

StorageCommit → StorageNamespace

PropertyContract
Local SDK method ID7
KindMutation
Permissionnexa.storage.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
TransactionStorageTransactionStructured StorageTransaction value; follow its linked field contract.
WritesStorageWrite[]Structured StorageWrite value; follow its linked field contract. A bounded collection; do not assume an unbounded result or unspecified ordering.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_Commit(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_Commit_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Migrate ​

StorageMigration → OperationRef

PropertyContract
Local SDK method ID8
KindOperation
Permissionnexa.storage.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

The current migration boundary accepts at most 256 entries and invokes an owned read-only migration action. Read the resulting operation to obtain the new namespace; do not reuse an obsolete namespace revision.

Request fields

FieldTypeMeaning
NamespaceStorageNamespacePrivate storage namespace identity or handle. It remains subject to current-load ownership.
FromVersionulongExact stored setting version to transform. A mismatch rejects migration before committing.
ToVersionulongCurrently registered positive setting version. Migrations must move forward.
ActionQualifiedIdIdentity or revision in this model’s domain; preserve ownership and exact spelling.

Successful result

Work has been admitted. Read or watch the owned operation through Tasks to establish its terminal result; admission is not completion.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_Storage_Migrate(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_Storage_Migrate_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.


来源: NexaCL-Plugin-SDK · Apache-2.0.

Site documentation: CC BY-SA 4.0. Imported SDK documents: Apache-2.0 as marked.