Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow PointerWriter timeout to be configurable #3218

Merged
merged 3 commits into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Bugfixes

- [#3180](https://github.com/influxdb/influxdb/pull/3180): Log GOMAXPROCS, version, and commit on startup.
- [#3218](https://github.com/influxdb/influxdb/pull/3218): Allow write timeouts to be configurable.


## v0.9.1 [unreleased]
Expand Down
5 changes: 5 additions & 0 deletions cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ import (
)

const (
// DefaultWriteTimeout is the default timeout for a complete write to succeed.
DefaultWriteTimeout = 5 * time.Second

// DefaultShardWriterTimeout is the default timeout set on shard writers.
DefaultShardWriterTimeout = 5 * time.Second
)

// Config represents the configuration for the the clustering service.
type Config struct {
WriteTimeout toml.Duration `toml:"write-timeout"`
ShardWriterTimeout toml.Duration `toml:"shard-writer-timeout"`
}

// NewConfig returns an instance of Config with defaults.
func NewConfig() Config {
return Config{
WriteTimeout: toml.Duration(DefaultWriteTimeout),
ShardWriterTimeout: toml.Duration(DefaultShardWriterTimeout),
}
}
5 changes: 4 additions & 1 deletion cluster/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ func TestConfig_Parse(t *testing.T) {
var c cluster.Config
if _, err := toml.Decode(`
shard-writer-timeout = "10s"
write-timeout = "20s"
`, &c); err != nil {
t.Fatal(err)
}

// Validate configuration.
if time.Duration(c.ShardWriterTimeout) != 10*time.Second {
t.Fatalf("unexpected bind address: %s", c.ShardWriterTimeout)
t.Fatalf("unexpected shard-writer timeout: %s", c.ShardWriterTimeout)
} else if time.Duration(c.WriteTimeout) != 20*time.Second {
t.Fatalf("unexpected write timeout s: %s", c.WriteTimeout)
}
}
16 changes: 8 additions & 8 deletions cluster/points_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/influxdb/influxdb/tsdb"
)

const DefaultWriteTimeout = 5 * time.Second

// ConsistencyLevel represent a required replication criteria before a write can
// be returned as successful
type ConsistencyLevel int
Expand Down Expand Up @@ -67,9 +65,10 @@ func ParseConsistencyLevel(level string) (ConsistencyLevel, error) {

// PointsWriter handles writes across multiple local and remote data nodes.
type PointsWriter struct {
mu sync.RWMutex
closing chan struct{}
Logger *log.Logger
mu sync.RWMutex
closing chan struct{}
WriteTimeout time.Duration
Logger *log.Logger

MetaStore interface {
NodeID() uint64
Expand All @@ -96,8 +95,9 @@ type PointsWriter struct {
// NewPointsWriter returns a new instance of PointsWriter for a node.
func NewPointsWriter() *PointsWriter {
return &PointsWriter{
closing: make(chan struct{}),
Logger: log.New(os.Stderr, "[write] ", log.LstdFlags),
closing: make(chan struct{}),
WriteTimeout: DefaultWriteTimeout,
Logger: log.New(os.Stderr, "[write] ", log.LstdFlags),
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (w *PointsWriter) writeToShard(shard *meta.ShardInfo, database, retentionPo
}

var wrote int
timeout := time.After(DefaultWriteTimeout)
timeout := time.After(w.WriteTimeout)
var writeError error
for _, nodeID := range shard.OwnerIDs {
select {
Expand Down
1 change: 1 addition & 0 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func NewServer(c *Config, version string) (*Server, error) {

// Initialize points writer.
s.PointsWriter = cluster.NewPointsWriter()
s.PointsWriter.WriteTimeout = time.Duration(c.Cluster.WriteTimeout)
s.PointsWriter.MetaStore = s.MetaStore
s.PointsWriter.TSDBStore = s.TSDBStore
s.PointsWriter.ShardWriter = s.ShardWriter
Expand Down
3 changes: 2 additions & 1 deletion etc/config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ reporting-disabled = false
###

[cluster]
shard-writer-timeout = "5s"
shard-writer-timeout = "5s" # The time within which a shard must respond to write.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for a local shard? If so it seems this should be in the data section and not cluster

write-timeout = "5s" # The time within which a write operation must complete on the cluster.

###
### [retention]
Expand Down