lizining1231 opened a new pull request, #3812:
URL: https://github.com/apache/dubbo-go/pull/3812
### Description
Part of #3810.
This is PR 1 of the three-PR replacement for #3811, which is being closed to
reduce review size. This PR implements the shared extension mechanism,
configuration and Triple integration. Classic Dubbo and the independent gRPC
protocol will follow in separate sub-issues and PRs, each containing its
implementation and tests.
Applications can register serialization plugins outside the framework and
select them through standard client/server options or YAML. Registration
describes the supported protocol and encoding mode; factories receive local
configuration snapshots and create runtime instances with explicit ownership.
Triple retains responsibility for framing, headers, compression and transport.
```mermaid
flowchart TD
A[Plugin registration] --> B[Protocol-scoped serialization factory]
C[Client or server configuration] --> D[Local configuration snapshot and
receive policy]
B --> E[Triple codec binding]
D --> E
E --> F{Encoding mode}
F --> G[Message codec]
F --> H[Object codec inside Triple wrapper]
G --> I[Triple framing and transport]
H --> I
```
### Changes
#### 1. Public contracts and factory registration
- Add protocol-scoped serialization registration and factory construction,
with validation of names, modes, IDs and required capabilities.
- Define message encoding, optional append support, stream capability
contracts and optional argument type resolution. Stream capability is a shared
contract here; Classic Dubbo consumes it in its follow-up PR.
- Clean up factory results when construction or validation fails and manage
shared instances through scoped resource ownership.
#### 2. Configuration and initialization
- Expose serialization selection and accepted receive formats through
high-level client/server options and YAML.
- Preserve precedence between defaults and per-reference/service settings,
including the distinction between omitted and explicitly empty receive lists.
- Pass private parameter copies and read-only local configuration snapshots
to factories; keep local configuration and receive policies intact across
discovery and reconnects.
- Roll back partial reference, service and cluster initialization without
leaking codec instances or invokers.
#### 3. Triple integration
- Support message encoding and non-IDL wrapped-object encoding on gRPC wire
and Triple wire. Wrapped-object streaming remains unsupported; streaming uses
message codecs.
- Enforce receive policies before decoding, including empty unary and
streaming envelopes, and report malformed payloads without trying another codec.
- Preserve declared argument types, wrapper schema behavior and existing
low-level Triple codec APIs.
- Keep group/version codec contexts independent on a shared endpoint; retain
the captured context for in-flight requests during handler replacement.
- Keep codecs alive for active calls, streams and discovered providers, and
release them after their final user finishes.
#### 4. Tests and documentation
- Include registration and configuration tests, initialization rollback
tests, Triple dispatch and lifecycle regressions, and six scenarios in an
independent plugin module.
- Document public contracts, registration modes, configuration, receive
policies and Triple integration, with navigation from both repository READMEs.
- Keep Classic Dubbo framing/stream integration and independent gRPC subtype
adapters in their respective follow-up PRs.
### Test
This PR adds 34 root-module tests and 6 independent-module RPC scenarios.
Every new top-level test is listed below; table-driven subtests remain under
their parent functions.
#### `common/extension/serialization_test.go`
| Test | Description |
| --- | --- |
| `TestSerializationConstruction` | Construct a codec from its registration
and validate the resulting instance. |
| `TestSerializationValidation` | Reject invalid serialization registrations
and incompatible capabilities. |
| `TestInitializeSerializationSnapshots` | Initialize extension
configuration and produce independent runtime snapshots. |
| `TestLocalSerializationPolicySurvivesDiscovery` | Preserve local receive
policy when discovery parameters are merged. |
| `TestCodecRegistrationValidationAndAtomicID` | Validate registration
fields and reserve Dubbo IDs atomically. |
| `TestCodecSerializationFactoryCleanup` | Release factory results when
construction or validation fails. |
| `TestCodecConfigurationFinalValuesAndAtomicPublication` | Publish
snapshots only after successful initialization using final configuration
values. |
#### `serialization/resources_test.go`
| Test | Description |
| --- | --- |
| `TestResourcesDrainAndCloseOnce` | Wait for resource users to finish and
close each owned resource once. |
| `TestCodecResourcesCloseErrors` | Handle resource-close failures without
skipping remaining cleanup. |
#### `client/client_test.go`
| Test | Description |
| --- | --- |
| `TestCodecDialConfigurationIsolation` | Keep Dial and DialWithDefinition
settings isolated, including inherited and explicitly empty receive lists. |
#### `client/codec_action_test.go`
| Test | Description |
| --- | --- |
| `TestCodecReferenceRollback` | Release prepared reference resources after
partial initialization failures. |
| `TestCodecLegacyReferenceInitialization` | Preserve reference
initialization for legacy protocol implementations. |
| `TestCodecClusterAssemblyRollback` | Destroy created invokers when cluster
lookup or assembly fails. |
#### `global/serialization_test.go`
| Test | Description |
| --- | --- |
| `TestAcceptedSerializationsClonePresence` | Clone receive lists without
losing nil versus explicit-empty semantics. |
| `TestCodecReceivePolicyYAMLAndNestedClones` | Decode YAML receive policies
and keep nested configuration clones independent. |
#### `server/codec_action_test.go`
| Test | Description |
| --- | --- |
| `TestCodecServiceRollback` | Release service resources after partial
export failures. |
#### `server/options_test.go`
| Test | Description |
| --- | --- |
| `TestCodecServiceReceivePolicyInheritance` | Inherit provider receive
policy without sharing mutable slices; retain explicit-empty overrides. |
#### `protocol/triple/client_test.go`
| Test | Description |
| --- | --- |
| `TestCodecClientInitializationRollback` | Release codec instances when
Triple client construction fails. |
#### `protocol/triple/serialization_lifecycle_test.go`
| Test | Description |
| --- | --- |
| `TestDiscoveredProvidersShareCodecLease` | Keep shared codec resources
alive while another discovered provider still uses them. |
| `TestProviderCodecConcurrentRelease` | Release provider leases safely
under concurrent teardown. |
| `TestCodecTripleGenerationInterleaveAndRetry` | Keep codec generations
independent across release, reconstruction and retry. |
| `TestCodecServerStopOwnsAllServiceCodecs` | Release service codec
resources when the Triple server stops. |
#### `protocol/triple/triple_invoker_test.go`
| Test | Description |
| --- | --- |
| `TestCodecInvocationDeclaredTypesReachWrapper` | Carry invocation-declared
argument types into the Triple request wrapper. |
#### `protocol/triple/triple_protocol/serialization_lifecycle_test.go`
| Test | Description |
| --- | --- |
| `TestCodecStreamLeaseTermination` | Release stream leases on terminal
operations. |
| `TestCodecStreamCloseWaitsForOperations` | Keep stream resources alive
until active operations finish. |
| `TestCodecCompleteCallResourceBoundaries` | Retain resources across
complete client and handler call boundaries. |
| `TestCodecHandlerReplacementKeepsInflightContext` | Preserve captured
codec contexts for requests executing during handler replacement. |
#### `protocol/triple/triple_protocol/serialization_test.go`
| Test | Description |
| --- | --- |
| `TestConfiguredSerializationSessions` | Dispatch configured
request/response codecs through serialization sessions. |
| `TestDisabledProtobufEmptyEnvelope` | Reject empty Protobuf envelopes when
that format is disabled. |
| `TestCodecDeclaredTypesAndResolver` | Honor declared parameter types and
optional plugin type resolution. |
| `TestCodecRuntimeMapIsolationAndRejection` | Keep runtime codec maps
isolated and reject unsupported or disabled entries. |
| `TestCodecResponseSchemasAndPayloadErrors` | Validate supported response
wrapper schemas and propagate malformed-payload errors. |
| `TestCodecMessageSessionAppender` | Use optional append support in
configured message sessions. |
| `TestCodecStreamingEmptyMessagePolicy` | Apply receive-policy checks to
empty streaming messages. |
#### `tests/codec-plugin/codec_test.go`
| Test | Description |
| --- | --- |
| `TestHighLevelPluginRPC` | Select external plugins through public APIs on
both Triple wires and exercise all four encoding/decoding steps. |
| `TestUnknownAndDisabledPlugin` | Reject unknown or disabled external
plugin formats. |
| `TestBuiltinsAndCorruptPayload` | Preserve built-in formats and reject
corrupted custom payloads. |
#### `tests/codec-plugin/handler_context_test.go`
| Test | Description |
| --- | --- |
| `TestCodecSharedTripleHandlerContexts` | Verify group/version-specific
codec and receive policies on a shared Triple endpoint. |
| `TestCodecTripleFailedExportRetryRPC` | Complete real RPC after a failed
multi-protocol export and retry. |
| `TestCodecClusterAssemblyFailureReleasesLease` | Verify real Dial failures
release codec leases before returning. |
Updated existing tests: `TestCloneConfig` covers accepted-serialization
cloning; `Test_newClientManager_Serialization` expects initialization errors
instead of panics for unsupported formats.
### Checklist
- [x] I confirm the target branch is `develop`
- [x] I have run `make fmt` to format my code
- [x] I have run the full repository `make test` target
- [x] I have added tests that prove the feature works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]