Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

Commit

Permalink
choose random partition if none is set
Browse files Browse the repository at this point in the history
  • Loading branch information
celrenheit committed Dec 2, 2017
1 parent 3ff3e1e commit a427d12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion broker/broker_produce.go
Expand Up @@ -28,7 +28,7 @@ func (b *Broker) Produce(ctx context.Context, req *sgproto.ProduceMessageRequest
return nil, fmt.Errorf("unknown partition '%s'", req.Partition)
}
} else { // choose one
p = t.ChoosePartition(req.Messages[0]) // FIXME: choose randomly
p = t.ChooseRandomPartition() // FIXME: choose randomly
}

leader := b.getPartitionLeader(req.Topic, p.Id)
Expand Down
6 changes: 6 additions & 0 deletions topic/topic.go
@@ -1,6 +1,7 @@
package topic

import (
"math/rand"
"path/filepath"
"sync"

Expand Down Expand Up @@ -107,6 +108,11 @@ func (t *Topic) ChoosePartition(msg *sgproto.Message) *Partition {
return t.Partitions[idx]
}

func (t *Topic) ChooseRandomPartition() *Partition {
idx := rand.Int() % len(t.Partitions)
return t.Partitions[idx]
}

func (t *Topic) PutMessage(partition string, msg *sgproto.Message) error {
var p *Partition
if partition != "" {
Expand Down

0 comments on commit a427d12

Please sign in to comment.