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

Shard metadata never be expired #767

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion cluster/cluster_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (self *ClusterConfiguration) PeriodicallyDropShardsWithRetentionPolicies()
log.Info("Checking for shards to drop")
shards := self.getExpiredShards()
for _, s := range shards {
self.shardStore.DeleteShard(s.id)
self.DropShard(s.id, s.serverIds)
}
}
}()
Expand Down
41 changes: 41 additions & 0 deletions integration/single_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"strconv"
"time"

influxdb "github.com/influxdb/influxdb/client"
. "github.com/influxdb/influxdb/integration/helpers"
Expand Down Expand Up @@ -790,6 +791,46 @@ func (self *SingleServerSuite) TestCreateShardSpace(c *C) {
c.Assert(spaceShards, HasLen, 1)
}

func (self *SingleServerSuite) TestShardExpiration(c *C) {
// makes sure when a shard expires due to retention policy the data
// is deleted as well as the metadata

client := self.server.GetClient("", c)
space := &influxdb.ShardSpace{Name: "short", RetentionPolicy: "5s", Database: "db1", Regex: "/^test_shard_expiration/"}
err := client.CreateShardSpace(space)
c.Assert(err, IsNil)

self.server.WriteData(`
[
{
"name": "test_shard_expiration",
"columns": ["time", "val"],
"points":[[1307997668000, 1]]
}
]`, c)

// Make sure the shard exists
shards, err := client.GetShards()
shardsInSpace := filterShardsInSpace("short", shards.All)
c.Assert(shardsInSpace, HasLen, 1)

time.Sleep(6 * time.Second)

// Make sure the shard is gone
shards, err = client.GetShards()
shardsInSpace = filterShardsInSpace("short", shards.All)
c.Assert(shardsInSpace, HasLen, 0)
}

func filterShardsInSpace(spaceName string, shards []*influxdb.Shard) (filteredShards []*influxdb.Shard) {
for _, s := range shards {
if s.SpaceName == spaceName {
filteredShards = append(filteredShards, s)
}
}
return
}

func (self *SingleServerSuite) getShardsForSpace(name string, shards []*influxdb.Shard) []*influxdb.Shard {
filteredShards := make([]*influxdb.Shard, 0)
for _, s := range shards {
Expand Down
6 changes: 3 additions & 3 deletions integration/test_config_single.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ dir = "/tmp/influxdb/development/raft"

[storage]

# The server will check this often for shards that have expired and should be cleared.
retention-sweep-period = "1s"

dir = "/tmp/influxdb/development/db"
# How many requests to potentially buffer in memory. If the buffer gets filled then writes
# will still be logged and once the local storage has caught up (or compacted) the writes
Expand Down Expand Up @@ -158,9 +161,6 @@ max-response-buffer-size = 100
# that you don't need to buffer in memory, but you won't get the best performance.
concurrent-shard-query-limit = 10

# The server will check this often for shards that have expired and should be cleared.
retention-sweep-period = "10000u"

[wal]

dir = "/tmp/influxdb/development/wal"
Expand Down