-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix retention policy creation inconsistencies
- Loading branch information
Showing
13 changed files
with
128 additions
and
62 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 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 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 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,56 @@ | ||
package meta | ||
|
||
import ( | ||
"reflect" | ||
"sort" | ||
"time" | ||
|
||
"testing" | ||
) | ||
|
||
func Test_newShardOwner(t *testing.T) { | ||
// An error is returned if there are no data nodes available. | ||
_, err := NewShardOwner(ShardInfo{}, map[int]int{}) | ||
if err == nil { | ||
t.Error("got no error, but expected one") | ||
} | ||
|
||
ownerFreqs := map[int]int{1: 15, 2: 11, 3: 12} | ||
id, err := NewShardOwner(ShardInfo{ID: 4}, ownerFreqs) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// The ID that owns the fewest shards is returned. | ||
if got, exp := id, uint64(2); got != exp { | ||
t.Errorf("got id %d, expected id %d", got, exp) | ||
} | ||
|
||
// The ownership frequencies are updated. | ||
if got, exp := ownerFreqs, map[int]int{1: 15, 2: 12, 3: 12}; !reflect.DeepEqual(got, exp) { | ||
t.Errorf("got owner frequencies %v, expected %v", got, exp) | ||
} | ||
} | ||
|
||
func TestShardGroupSort(t *testing.T) { | ||
sg1 := ShardGroupInfo{ | ||
ID: 1, | ||
StartTime: time.Unix(1000, 0), | ||
EndTime: time.Unix(1100, 0), | ||
TruncatedAt: time.Unix(1050, 0), | ||
} | ||
|
||
sg2 := ShardGroupInfo{ | ||
ID: 2, | ||
StartTime: time.Unix(1000, 0), | ||
EndTime: time.Unix(1100, 0), | ||
} | ||
|
||
sgs := ShardGroupInfos{sg2, sg1} | ||
|
||
sort.Sort(sgs) | ||
|
||
if sgs[len(sgs)-1].ID != 2 { | ||
t.Fatal("unstable sort for ShardGroupInfos") | ||
} | ||
} |
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 |
---|---|---|
@@ -1,56 +1,55 @@ | ||
package meta | ||
package meta_test | ||
|
||
import ( | ||
"reflect" | ||
"sort" | ||
"testing" | ||
"time" | ||
|
||
"testing" | ||
"github.com/influxdata/influxdb/services/meta" | ||
) | ||
|
||
func Test_newShardOwner(t *testing.T) { | ||
// An error is returned if there are no data nodes available. | ||
_, err := NewShardOwner(ShardInfo{}, map[int]int{}) | ||
if err == nil { | ||
t.Error("got no error, but expected one") | ||
} | ||
func Test_Data_CreateRetentionPolicy(t *testing.T) { | ||
data := meta.Data{} | ||
|
||
ownerFreqs := map[int]int{1: 15, 2: 11, 3: 12} | ||
id, err := NewShardOwner(ShardInfo{ID: 4}, ownerFreqs) | ||
err := data.CreateDatabase("foo") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// The ID that owns the fewest shards is returned. | ||
if got, exp := id, uint64(2); got != exp { | ||
t.Errorf("got id %d, expected id %d", got, exp) | ||
err = data.CreateRetentionPolicy("foo", &meta.RetentionPolicyInfo{ | ||
Name: "bar", | ||
ReplicaN: 1, | ||
Duration: 24 * time.Hour, | ||
}, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// The ownership frequencies are updated. | ||
if got, exp := ownerFreqs, map[int]int{1: 15, 2: 12, 3: 12}; !reflect.DeepEqual(got, exp) { | ||
t.Errorf("got owner frequencies %v, expected %v", got, exp) | ||
rp, err := data.RetentionPolicy("foo", "bar") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestShardGroupSort(t *testing.T) { | ||
sg1 := ShardGroupInfo{ | ||
ID: 1, | ||
StartTime: time.Unix(1000, 0), | ||
EndTime: time.Unix(1100, 0), | ||
TruncatedAt: time.Unix(1050, 0), | ||
if rp == nil { | ||
t.Fatal("creation of retention policy failed") | ||
} | ||
|
||
sg2 := ShardGroupInfo{ | ||
ID: 2, | ||
StartTime: time.Unix(1000, 0), | ||
EndTime: time.Unix(1100, 0), | ||
// Try to recreate the same RP with default set to true, should fail | ||
err = data.CreateRetentionPolicy("foo", &meta.RetentionPolicyInfo{ | ||
Name: "bar", | ||
ReplicaN: 1, | ||
Duration: 24 * time.Hour, | ||
}, true) | ||
if err == nil || err != meta.ErrRetentionPolicyConflict { | ||
t.Fatalf("unexpected error. got: %v, exp: %s", err, meta.ErrRetentionPolicyConflict) | ||
} | ||
|
||
sgs := ShardGroupInfos{sg2, sg1} | ||
|
||
sort.Sort(sgs) | ||
|
||
if sgs[len(sgs)-1].ID != 2 { | ||
t.Fatal("unstable sort for ShardGroupInfos") | ||
// Creating the same RP with the same specifications should succeed | ||
err = data.CreateRetentionPolicy("foo", &meta.RetentionPolicyInfo{ | ||
Name: "bar", | ||
ReplicaN: 1, | ||
Duration: 24 * time.Hour, | ||
}, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |