mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* mq client: dial brokers with the publisher's dial option The publisher dialed every broker with insecure credentials, and the per-partition connection added the configured option on top of them, so a publisher could not reach a broker that requires TLS. That connection was also never closed. PublisherConfiguration now takes the dial option, insecure only when none is given, the agent passes its own, and the partition connection is closed when its publish job ends. * mq client: resend unacked messages when a partition's publish stream fails A publisher sent each message once and kept no record of it. Acks were only logged, a broker error on the stream was written to a field nobody read, and the scheduler's wait loop broke out of its select instead of the loop, so after the first stream failure it never looked the partitions up again. Losing a partition leader silently dropped every unacked message and stopped that partition for good. Each partition now keeps its queue and the messages it sent but has not had acked across streams. When a stream fails, or the broker answers with an error or error code, the job ends, the scheduler looks the topic up again with a short backoff, and the replacement stream resends the unacked messages in order before draining the queue. Acks remove messages up to the acked timestamp, so timestamps are made strictly increasing per publisher. A partition holds at most 1024 queued or unacked messages, and Publish blocks beyond that instead of growing without bound. FinishPublish and Shutdown stop the input, Publish then fails, and Shutdown returns once everything queued is acked. * mq client: bound how long a closed publisher keeps resending Once its input is closed, a publisher kept retrying a partition until every message was acked, so Shutdown never returned while no broker could take the partition, and a publisher that was only finished kept looking the topic up forever. Resending now stops a minute after FinishPublish or Shutdown, the open streams are cancelled, and Shutdown reports how many messages were left unacknowledged. * mq/kafka: replace a publish session whose call failed or was cancelled PublishRecord ran Send and Recv in goroutines and returned when the request context ended, leaving them on the stream. A leftover Recv then took the ack meant for the next call on that partition, so acks and offsets drifted apart, and a session whose stream had failed or whose broker answered with an error stayed cached until the topic was deleted. A call that fails, is cancelled, or gets an error response now drops its session and cancels the stream, so the next call opens a fresh one. PublishRecordValue shares the same path. * mq/kafka: publish to the partition's current leader The gateway opened every publish stream on the one broker it was configured with, and a broker answers a publish for a partition it does not lead with not-leader, so with more than one broker most partitions could not be produced to, and none could after its leader moved. The gateway now opens the stream on the leader named by the partition lookup it already caches. A not-leader or connection failure drops the session and the cached lookup and comes back as ErrNotLeaderOrFollower, so the next attempt finds the new leader. * mq/kafka: answer a produce that lost its partition leader with NOT_LEADER_OR_FOLLOWER Every failed produce went back to the client as UNKNOWN_SERVER_ERROR, which Kafka clients do not retry, so a partition leader change surfaced as failed sends. A publish that failed because the leader moved or could not be reached now answers NOT_LEADER_OR_FOLLOWER, and the client refreshes its metadata and sends again. * mq client: let the flush timeout cancel a stalled partition lookup A lookup after a stream failure used context.Background, so a broker that accepted LookupTopicBrokers and never answered kept the scheduler inside it after the flush timeout, and Shutdown never returned. Lookups now run under a context cancelled when the publisher stops, and each broker attempt is bounded so a stalled one does not hold up the next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq client: stop each test publisher and release held acks on cancel A test that never shut its publisher down left the scheduler retrying lookups against the stopped fake broker for the rest of the package run, and a fake ack worker held on the gate could not exit when its stream was cancelled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq client: do not restart a partition whose stream finished during the switch A re-lookup that moved a partition's leader cancelled its stream and waited for it, then started a new one. If that stream had just finished cleanly, the replacement ran for a job already counted as done, and the scheduler could exit with it still running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq client: count only data messages as unacknowledged at Shutdown The count added the in-flight list and the queue length, so the close marker FinishPublish queues counted as a lost message: an empty publisher whose marker went unacked reported one unacknowledged message. Every data message holds a slot until it is acked, so the slots are the count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq/kafka: let a produce's deadline bound opening its publish stream Opening a session ran under the gateway's own context and waited for the leader's hello, so a leader that took the init and never answered held the produce, and every produce to that partition queued on the creation lock, past their deadlines. Setup now also ends when the caller's context does, without invalidating the assignment for a caller timeout, and the stream outlives the call once open. A call whose context ended while it waited for a dropped session no longer opens another one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq/kafka: cancel the held publish only once the broker holds its data The test cancelled on a 200 ms timer. A slow session setup let that deadline pass before the data went out, leaving the first stream open for the next call, which then waited on the held ack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq/kafka: fetch and read offsets from the partition's leader Produces go to the leader, but fetches and the high water mark and log start offset reads still went to the gateway's own broker, which answers partition not found for a partition it does not lead. Reads now use the leader the assignment lookup returns, as the publish path does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq agent: report unacknowledged messages when a publish session closes ClosePublishSession returned success right after FinishPublish, which only queues the close marker, so a message the brokers never acked was lost without an error. The close now waits for Shutdown, which returns once everything is acked or reports what was not after the flush timeout, and no longer holds the session map lock while it waits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq/kafka: look the leader up again after a read it cannot serve Reads used the cached assignment until its TTL, so after a leader died or gave the partition up, every fetch for the next 30 seconds went to it. A connection failure or a partition-not-found answer from the leader now drops the cached assignment, unless the caller's own context ended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq client: leave a Publish still waiting to enqueue out of the Shutdown count Publish takes a slot before it checks that the input is open, so a Publish paused between the two still held its slot when Shutdown counted, and Shutdown reported a message the caller was then told was rejected. Each job now counts the data messages it accepted and has not had acked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq/kafka: cancel the silent-leader publish once its hello is withheld The test cancelled on a 200 ms timer, which could fire before the call opened a stream; the retry then opened the withheld stream with no deadline and hung the suite. It now cancels once the fixture holds the hello and bounds the retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq: retain the original publisher payload for replay * mq agent: flush accepted records when the publish stream closes * mq client: isolate bootstrap RPCs by publisher credentials * mq/kafka: honor publish cancellation during lookup and partition waits * mq/kafka: read a partition's offset range from its leader GetHighWaterMark and GetEarliestOffset asked the gateway's configured broker, which answers from its own log buffer. Publishes now go to the partition's leader, so a non-leader gateway broker reported a high water mark that missed the leader's unflushed records. Send the range query to the leader and drop the cached assignment when that broker fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq agent client: bound the wait for the agent to finish a session CloseSession waited in Recv until the agent answered EOF. An agent blocked enqueueing to a partition whose broker stopped acknowledging never reads the close, so it never starts its bounded flush and the close hung. After two minutes, cancel the stream: the agent then stops accepting and flushes, and the close reports the timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq agent: wait for both closers to reach the flush in the close test The duplicate-close test slept 100 ms to let the second close start. A late goroutine then found the session already removed and the test failed. Wait until both closers are inside finishPublisher instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq: answer a partition's offset range only from its leader A broker answered GetPartitionRangeInfo from its offset manager even after the partition moved away, so the gateway kept reading the old leader's range until its assignment cache expired. The broker now checks ownership the way FetchMessage does, and the gateway drops the cached assignment when the range request fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>