Repository navigation
Conversation
| * implementations may postpone {@link #serializeToByteBuffer()} for such requests and keep the | ||
| * source objects alive until then. | ||
| * <p>A deferred request keeps its source objects while it waits in the replication queues, so | ||
| * {@link #getMemorySize()} must account for them and the request must be able to rebuild the same |
There was a problem hiding this comment.
This contract clarifies that a deferred request keeps its source objects resident until serialization, so getMemorySize() must include them for accurate queue accounting.
| * Clears source requests after deferred serialization when no subscription queue needs them. The | ||
| * serialized buffers remain available to replication retries. | ||
| */ | ||
| public synchronized void clearRequestsAfterSerialization() { |
There was a problem hiding this comment.
This lifecycle hook lets replication-only requests release source plan nodes once serialized buffers are available, while keeping those buffers for retries and preserving the original queue reservation.
| // Deferred requests are materialized after releasing the per-region lock and before the | ||
| // caller can reuse the applied plan node. | ||
| if (requestToSerialize != null) { | ||
| requestToSerialize.buildSerializedRequests(); |
There was a problem hiding this comment.
The local apply is complete and stateMachineLock has been released before the writer-thread fallback materializes bytes. The synchronous call also ensures the caller cannot reuse the plan node first.
| if (!keepRequestsForSubscription && !serializationDeferred) { | ||
| request.clearRequests(); | ||
| } else if (!keepRequestsForSubscription) { | ||
| request.clearRequestsAfterSerialization(); |
There was a problem hiding this comment.
Deferred requests skip eager encoding here. When subscription delivery did not retain the source node, this flag releases it as soon as serialization produces the replication buffer.
| } | ||
| } | ||
| } | ||
| if (!keepRequestsForSubscription && serializationDeferred && !offeredToAnyThread) { |
There was a problem hiding this comment.
When no peer queue accepts the entry, no batch will materialize its deferred bytes. Releasing the source here avoids retaining it while the dispatcher fills the index gap from WAL.
|
|
||
| @Override | ||
| public long getMemorySize() { | ||
| return insertNode.getMemorySize() + INSTANCE_SIZE; |
There was a problem hiding this comment.
The queued request is the pipe wrapper, so the estimate includes both the wrapped insert payload and the wrapper instance rather than undercounting replication queue memory.
|
|
||
| // A serialized replication request releases its source object when no subscription retains it. | ||
| @Test | ||
| public void testDeferredSourceCanBeClearedAfterSerialization() { |
There was a problem hiding this comment.
This test covers deferred cleanup after bytes are built and verifies source release, retained buffer availability, and stable queue-reservation accounting.
| // A deferred local write is serialized after the state machine lock is released, before callers | ||
| // can reuse the request, and subscription consumers still receive its serialized bytes. | ||
| @Test | ||
| public void testDeferredWriteIsSerializedAfterStateMachineLockRelease() throws Exception { |
There was a problem hiding this comment.
This regression test verifies the write-thread serialization happens after it releases stateMachineLock and that an accepted subscription retains both the source request and encoded bytes.
|
|
||
| // Deferred replication of a pipe-enriched insert must reserve the wrapped insert and wrapper. | ||
| @Test | ||
| public void testDeferredRequestKeepsWrappedInsertMemoryEstimate() throws IllegalPathException { |
There was a problem hiding this comment.
This test protects the pipe wrapper contract by checking that it inherits deferred serialization and accounts for its own instance memory.
|
|
||
| // Type inference after queue creation must be reflected when IoTConsensus later serializes it. | ||
| @Test | ||
| public void testInsertRequestSerializationIsDeferred() throws IllegalPathException { |
There was a problem hiding this comment.
This scenario builds the indexed request before type inference, then checks its eventual encoded form reflects the inferred types and values.
Summary
IoTConsensus currently materializes serialized insert requests in the synchronous replication offer path while the state machine write lock is held. This change lets
InsertNoderequests defer serialization until after local application. The write-thread path serializes after releasingstateMachineLock, while the replication batch builder retains an idempotent fallback.Deferred requests remain accounted for in replication queue memory. Their source plan nodes are released after serialization when no subscription queue needs them. Pipe-enriched inserts include their wrapper size in the memory estimate.
Example
An
InsertRowNodecan arrive with string values and unresolved types. Local application infersDOUBLE,FLOAT,INT64,INT32, andBOOLEAN, with values1.0,2.0f,10000L,100, andfalse. Deferred serialization encodes the applied request state for replication.Validation
IndexedConsensusRequestTestandIoTConsensusServerImplTestpassed, 10 tests total.InsertRowNodeSerdeTestandPipeEnrichedInsertNodeSerdeTestpassed, 14 tests total.git diff --checkpassed.Write benchmark
The A/B comparison used one ConfigNode and two DataNodes. The workload used 200 devices, 100 fields per device, 12 clients, 200 loops, and batches of 100 rows. Each of three runs per version wrote 400 million points with a 1 GiB benchmark JVM. Median throughput increased from 1,585,283 to 1,725,553 points/s, an 8.85% increase. Median P50 latency decreased 6.66%, while median P99 latency increased 2.59%.
Rounds 2 and 3 reused each version's pre-created schema in disjoint time ranges because creating additional databases reached the DataNode region direct-buffer limit. Schema creation was excluded from write elapsed time. The initial baseline run used an 8.5 GiB JVM due to the Windows launcher ignoring the requested heap size, so it was excluded and rerun with a 1 GiB JVM.