-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2878 from influxdb/shard_precreation
Shard precreation service
- Loading branch information
Showing
11 changed files
with
316 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package precreator | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/influxdb/influxdb/toml" | ||
) | ||
|
||
const ( | ||
// DefaultCheckInterval is the shard precreation check time if none is specified. | ||
DefaultCheckInterval = 10 * time.Minute | ||
|
||
// DefaultAdvancePeriod is the default period ahead of the endtime of a shard group | ||
// that its successor group is created. | ||
DefaultAdvancePeriod = 30 * time.Minute | ||
) | ||
|
||
// Config represents the configuration for shard precreation. | ||
type Config struct { | ||
Enabled bool `toml:"enabled"` | ||
CheckInterval toml.Duration `toml:"check-interval"` | ||
AdvancePeriod toml.Duration `toml:"advance-period"` | ||
} | ||
|
||
// NewConfig returns a new Config with defaults. | ||
func NewConfig() Config { | ||
return Config{ | ||
Enabled: true, | ||
CheckInterval: toml.Duration(DefaultCheckInterval), | ||
AdvancePeriod: toml.Duration(DefaultAdvancePeriod), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package precreator_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/influxdb/influxdb/services/precreator" | ||
) | ||
|
||
func TestConfig_Parse(t *testing.T) { | ||
// Parse configuration. | ||
var c precreator.Config | ||
if _, err := toml.Decode(` | ||
enabled = true | ||
check-interval = "2m" | ||
advance-period = "10m" | ||
`, &c); err != nil { | ||
|
||
t.Fatal(err) | ||
} | ||
|
||
// Validate configuration. | ||
if !c.Enabled { | ||
t.Fatalf("unexpected enabled state: %v", c.Enabled) | ||
} else if time.Duration(c.CheckInterval) != 2*time.Minute { | ||
t.Fatalf("unexpected check interval: %s", c.CheckInterval) | ||
} else if time.Duration(c.AdvancePeriod) != 10*time.Minute { | ||
t.Fatalf("unexpected advance period: %s", c.AdvancePeriod) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Shard Precreation | ||
============ | ||
|
||
During normal operation when InfluxDB receives time-series data, it writes the data to files known as _shards_. Each shard only contains data for a specific range of time. Therefore, before data can be accepted by the system, the shards must exist and InfluxDB always checks that the required shards exist for every incoming data point. If the required shards do not exist, InfluxDB will create those shards. Because this requires a cluster to reach consensus, the process is not instantaneous and can temporarily impact write-throughput. | ||
|
||
Since almost all time-series data is written sequentially in time, the system has an excellent idea of the timestamps of future data. Shard precreation takes advantage of this fact by creating required shards ahead of time, thereby ensuring the required shards exist by the time new time-series data actually arrives. Write-throughput is therefore not affected when data is first received for a range of time that would normally trigger shard creation. | ||
|
||
Note that the shard-existence check must remain in place in the code, even with shard precreation. This is because while most data is written sequentially in time, this is not always the case. Data may be written with timestamps in the past, or farther in the future than shard precreation handles. | ||
|
||
## Configuration | ||
Shard precreation can be disabled if necessary, though this is not recommended. If it is disabled, then shards will be only be created when explicitly needed. | ||
|
||
The interval between runs of the shard precreation service, as well as the time-in-advance the shards are created, are also configurable. The defaults should work for most deployments. |
Oops, something went wrong.