Andrey Yarovoy created HDDS-17806:
-------------------------------------
Summary: Bound every consumer of a replica's chunk list by the
committed block length
Key: HDDS-17806
URL: https://issues.apache.org/jira/browse/HDDS-17806
Project: Apache Ozone
Issue Type: Bug
Components: Ozone Manager
Reporter: Andrey Yarovoy
Assignee: Andrey Yarovoy
Bound every consumer of a replica's chunk list by the committed block length
h3. Problem
A replica can record more of a block than OM committed, and nothing removes the
extra part. Two write paths leave this state behind:
- *EC, partial PutBlock.* Every WriteChunk of stripe N succeeds, then the
PutBlock of stripe N succeeds on some replicas and fails on others: a datanode
stopped between the two, a container closed on one replica, or a PutBlock that
timed out on the client but was applied.
\{{ECKeyOutputStream#flushStripeToDatanodes}} rolls back to the acked length
(\{{resetToAckedPosition}}), closes the block group and writes stripe N again
into a new block group. OM commits the old block group with N-1 stripes. The
replicas whose PutBlock succeeded keep stripe N in their chunk list and in
\{{blockGroupLen}}. Closing the old entry sends no further PutBlock, because EC
streams do not use the \{{BufferPool}}.
- *Ratis, acked length below the applied length.* When \{{watchForCommit}}
fails, \{{KeyOutputStream#handleExceptionInternal}} keeps
\{{getTotalAckDataLength()}} for the block and writes the rest to a new block.
A majority of replicas may already have applied chunks beyond the acked length.
A write-side fix cannot remove this state in general. A PutBlock can time out
on the client and still be applied, a replica can become unreachable after
applying it, and the client can fail between a partial PutBlock and its retry.
Replicas have no atomic commit across them.
So Ozone already relies on this invariant: *the length committed in OM is
authoritative, and a replica may carry an uncommitted tail beyond it.* Each
consumer that reads a replica's chunk list or \{{blockGroupLen}} has to stay
within the committed length. Today each one is fixed on its own after a bug
report:
||Consumer||Bounded?||
|\{{ECBlockInputStream}} and \{{BlockInputStream}} (reads)|Yes: lengths come
from OM, except for blocks under construction|
|\{{ECReconstructionCoordinator}} (reconstruction)|Partly: HDDS-10985 bounds
the reconstructed PutBlock. Without the OM length,
\{{calcEffectiveBlockGroupLen}} takes the minimum \{{blockGroupLen}} of the
surviving replicas and, per its javadoc, may rebuild one extra stripe.|
|\{{ECBlockOutputStream}} stripe checksum during reconstruction|Yes:
\{{min(blockData size, blockGroupLength)}}, with a comment on this "dirty data"
case|
|\{{ECBlockChecksumComputer}} (EC file checksum)|Fixed by HDDS-16974. MD5MD5CRC
returned a wrong checksum, and COMPOSITE_CRC never returned.|
|\{{ReplicatedFileChecksumHelper}} and \{{ReplicatedBlockChecksumComputer}}
(replicated file checksum)|*No:* every chunk the replica lists is combined,
with no block length. Suspected to be the replicated form of HDDS-16974; not
reproduced yet.|
|\{{ozone debug replicas chunk-info}} (\{{ChunkKeyHandler}})|No: it prints the
replica's chunk list without marking chunks beyond the committed length|
h3. Proposal
# Add one helper in \{{hdds-common}} that returns the committed part of a
replica's chunk list for a given committed length:
#* replicated: the chunks starting below the length, with the last one cut to
the length;
#* EC: the stripes within the block group length, for the replica index.
#* Document the invariant on it, so that new consumers have one place to use
and one rule to follow.
# Use the helper in the existing consumers in place of their own bounds:
\{{ECBlockChecksumComputer}}, the \{{ECBlockOutputStream}} stripe checksum, and
the EC and replicated read paths where they trim chunk lists.
# Fix \{{ReplicatedFileChecksumHelper}} and
\{{ReplicatedBlockChecksumComputer}}: pass the block length and combine only
the committed chunks, as \{{ECBlockChecksumComputer}} now does. Reproduce first
with a mini-cluster test that commits a block below the length its replicas
applied.
# Make \{{ozone debug replicas chunk-info}} report chunks beyond the committed
length as uncommitted instead of listing them as block data.
# Audit the remaining readers of \{{BlockData#getChunks}} and
\{{BlockData#getBlockGroupLength}} outside the write path, for example Recon
and any comparison of replicas with each other, and record the result for each
in this Jira.
h3. Tests
For each consumer, a unit test that gives it a replica chunk list with an
uncommitted tail (one extra EC stripe, or extra replicated chunks), and asserts
that the result equals the one for the same block without the tail. Add a
mini-cluster test for the replicated checksum case.
h3. Out of scope
- *Cleanup at write time.* On a stripe rollback, send the replicas whose
PutBlock succeeded a corrective PutBlock with the acked chunk list and
\{{blockGroupLen}}. The datanode overwrites an EC block's data for a PutBlock
with \{{bcsId == 0}} (\{{BlockManagerImpl#persistPutBlock}}). This would tidy
replicas in the common case, but it cannot cover the cases above, and a late
original PutBlock could arrive after the corrective one. It would be a separate
optimization, after verifying the ordering of requests on a datanode's gRPC
stream.
- *Repair after the fact.* A datanode cannot know the OM length, and container
replication copies the tail as it is. A repair would need a new protocol
between OM or SCM and the datanodes.
h3. References
- HDDS-16974: EC file checksum not bounded by the committed block group length.
- HDDS-10985: EC reconstruction bounded by the block group length.
- \{{ECKeyOutputStream#flushStripeToDatanodes}}, \{{rollbackAndReset}},
\{{commitStripeWrite}}.
- \{{ECReconstructionCoordinator#calcEffectiveBlockGroupLen}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]