mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* mq broker: give up topic.conf filer calls with the caller's context The topic.conf read and save helpers took no context, so a filer that took the call and never answered kept the balancer inside topicConfLock for good, and every ConfigureTopic, lookup repair and EndPartitionGeneration queued behind it on a plain mutex. reportGenerationEnded's per-attempt deadline could not bound any of it. The helpers now take a context, the RPC paths pass their request context, and topicConfLock is a one-slot semaphore whose wait ends with the caller's context. Calls made while holding it are also bounded by topicConfTimeout, so a caller without a deadline cannot hold it forever. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: save topic.conf only if it is still what was read Every topic.conf update is a read-modify-write on the balancer, but the save was unconditional, so a balancer whose lease ran out between its read and its save wrote its stale assignments over a successor's newer epoch. topicConfLock only orders writers within one broker. A failed read in ConfigureTopic could also recreate an existing topic from scratch. The read now returns the topic.conf entry, and the save is an ObjectTransaction requiring that entry unchanged, or the file still absent for a new topic. A refused save is redone from a fresh read a few times, so a report for an epoch a successor already ended finds it moved on, and then gives up with Unavailable for the caller to retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: save mq.balance moves to topic.conf before assigning them A balance move only told the target to load the partition and the source to drain it. It never touched topic.conf, so lookups kept sending publishers to the source, and since partitions are fenced by epoch the target was asked to lead at epoch 0 and refused before anything moved. The balancer now runs the move itself: it saves the target as leader at the next epoch through the conditional topic.conf save, tells the source about the new epoch so it retires its copy, flushing what it holds under its own fence and sealing it, and then assigns the target, which takes the fence at the new epoch. A follower that becomes the leader swaps places with the old leader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: keep a retiring leader's fence renewed until it seals A leader told of a newer epoch, as a balance move's source is, retires its copy by shutting it down and waiting for its last flush before sealing the fence, but it did not renew the fence meanwhile. A flush outlasting fenceSealWait left an aged unsealed fence the new leader could take, and the pending flush then failed its fence check and dropped acknowledged messages. The fence is now renewed for as long as the flush takes. Loaders retiring the same copy at once share one renewal, which the first to return stops before any seal, so no renewal lands on a sealed fence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: save a configure's assignment repair with its update ConfigureTopic saved the repair of assignments on dead brokers on its own, then saved the requested schema or retention change against the entry it had read before that repair. The second save was always refused, so the update went round a full reread, and a resize first drained brokers for nothing. The repair is now applied in memory and saved together with the requested change in one conditional save. A resize replaces the assignments anyway, so it no longer saves a repair first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: report a balance move the target refused assignTopicPartitionsToBrokers logged each broker that refused its assignment and returned nil, so mq.balance reported success for a move whose target never took the partition, after topic.conf had already moved and the source had retired its copy. It now returns the refusals, and BalanceTopics passes them to its caller. The saved move stands: a retry assigns the target again, and the target also loads the partition on first use. ConfigureTopic keeps logging a refused assignment of a topic it has saved, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: give up a topic.conf cache miss with the caller's context getTopicConfFromCache waited for topicConfLock and read the filer under context.Background(), so a lookup whose caller had already given up stayed queued behind whatever held the lock and then did up to topicConfTimeout of filer work for nobody. It now takes the caller's context, which LookupTopicBrokers and the retention purge pass along and the partition loaders pass as Background; cache hits are unchanged. A waiter whose context has already ended no longer takes a free lock either, since a select with both cases ready picks one at random. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mq broker: require exactly one moved partition in the balance tests The move tests took the last partition led by the target as the moved one, so a move that handed both partitions to the target would pass. They now fail unless exactly one partition moved. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer_client"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/logstore"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/schema"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandMqTopicCompact{})
|
|
}
|
|
|
|
type commandMqTopicCompact struct {
|
|
}
|
|
|
|
func (c *commandMqTopicCompact) Name() string {
|
|
return "mq.topic.compact"
|
|
}
|
|
|
|
func (c *commandMqTopicCompact) Help() string {
|
|
return `compact the topic storage into parquet format
|
|
|
|
Example:
|
|
mq.topic.compact -namespace <namespace> -topic <topic_name> -timeAgo <time_ago>
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandMqTopicCompact) HasTag(tag CommandTag) bool {
|
|
return ResourceHeavy == tag
|
|
}
|
|
|
|
func (c *commandMqTopicCompact) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
|
|
|
|
// parse parameters
|
|
mqCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
namespace := mqCommand.String("namespace", "", "namespace name")
|
|
topicName := mqCommand.String("topic", "", "topic name")
|
|
timeAgo := mqCommand.Duration("timeAgo", 2*time.Minute, "start time before now. \"300ms\", \"1.5h\" or \"2h45m\". Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"")
|
|
replication := mqCommand.String("replication", "", "replication type")
|
|
collection := mqCommand.String("collection", "", "optional collection name")
|
|
dataCenter := mqCommand.String("dataCenter", "", "optional data center name")
|
|
diskType := mqCommand.String("disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag")
|
|
maxMB := mqCommand.Int("maxMB", 4, "split files larger than the limit")
|
|
|
|
if err := mqCommand.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
// The AssignVolumeRequest collection falls back to the path rule and the
|
|
// filer default when empty, so the empty-named collection cannot be
|
|
// requested explicitly.
|
|
if *collection == CollectionDefault {
|
|
return fmt.Errorf("%s is not a usable collection name here; omit -collection to inherit the configured collection", CollectionDefault)
|
|
}
|
|
|
|
storagePreference := &operation.StoragePreference{
|
|
Replication: *replication,
|
|
Collection: *collection,
|
|
DataCenter: *dataCenter,
|
|
DiskType: *diskType,
|
|
MaxMB: *maxMB,
|
|
}
|
|
|
|
// read topic configuration
|
|
fca := filer_client.NewFilerClientAccessor(
|
|
[]pb.ServerAddress{commandEnv.FilerAddress()},
|
|
commandEnv.option.GrpcDialOption,
|
|
)
|
|
fca.TokenSource = commandEnv.option.FilerTokenSource
|
|
t := topic.NewTopic(*namespace, *topicName)
|
|
topicConf, err := fca.ReadTopicConfFromFiler(context.Background(), t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// get record type - prefer flat schema if available
|
|
var recordType *schema_pb.RecordType
|
|
if topicConf.GetMessageRecordType() != nil {
|
|
// New flat schema format - use directly
|
|
recordType = topicConf.GetMessageRecordType()
|
|
}
|
|
recordType = schema.NewRecordTypeBuilder(recordType).
|
|
WithField(logstore.SW_COLUMN_NAME_TS, schema.TypeInt64).
|
|
WithField(logstore.SW_COLUMN_NAME_KEY, schema.TypeBytes).
|
|
RecordTypeEnd()
|
|
|
|
// compact the topic partition versions
|
|
if err = logstore.CompactTopicPartitions(commandEnv, t, *timeAgo, recordType, storagePreference); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|