From dc6e4916ec7e6db6b1eb622a76facc36278dc5c7 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Wed, 4 May 2022 13:54:39 -0400 Subject: [PATCH 01/10] Add GC policy proto to FamilyInfo. --- bigtable/admin.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bigtable/admin.go b/bigtable/admin.go index 6127c8999060..e3579786de77 100644 --- a/bigtable/admin.go +++ b/bigtable/admin.go @@ -310,8 +310,9 @@ type TableInfo struct { // FamilyInfo represents information about a column family. type FamilyInfo struct { - Name string - GCPolicy string + Name string + GCPolicy string + GCPolicyProto *btapb.GcRule } func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Table_View) (*btapb.Table, error) { @@ -347,7 +348,11 @@ func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, ti := &TableInfo{} for name, fam := range res.ColumnFamilies { ti.Families = append(ti.Families, name) - ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{Name: name, GCPolicy: GCRuleToString(fam.GcRule)}) + ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{ + Name: name, + GCPolicy: GCRuleToString(fam.GcRule), + GCPolicyProto: fam.GcRule, + }) } return ti, nil } From 992dbfffcdc9860d439bd75e9e009ca93093fcba Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Sun, 8 May 2022 22:59:00 -0400 Subject: [PATCH 02/10] Add PolicyType and expose GCPolicyObject. --- bigtable/admin.go | 12 ++++----- bigtable/gc.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ bigtable/gc_test.go | 23 ++++++++++++++++ 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/bigtable/admin.go b/bigtable/admin.go index e3579786de77..fc0575407ec5 100644 --- a/bigtable/admin.go +++ b/bigtable/admin.go @@ -310,9 +310,9 @@ type TableInfo struct { // FamilyInfo represents information about a column family. type FamilyInfo struct { - Name string - GCPolicy string - GCPolicyProto *btapb.GcRule + Name string + GCPolicy string + GCPolicyObject GCPolicy } func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Table_View) (*btapb.Table, error) { @@ -349,9 +349,9 @@ func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, for name, fam := range res.ColumnFamilies { ti.Families = append(ti.Families, name) ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{ - Name: name, - GCPolicy: GCRuleToString(fam.GcRule), - GCPolicyProto: fam.GcRule, + Name: name, + GCPolicy: GCRuleToString(fam.GcRule), + GCPolicyObject: GCRuleToPolicy(fam.GcRule), }) } return ti, nil diff --git a/bigtable/gc.go b/bigtable/gc.go index dce4c823f275..481e242494da 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -25,10 +25,19 @@ import ( bttdpb "google.golang.org/genproto/googleapis/bigtable/admin/v2" ) +const ( + PolicyType_None = iota + PolicyType_MaxAge + PolicyType_MaxVersion + PolicyType_Union + PolicyType_Intersection +) + // A GCPolicy represents a rule that determines which cells are eligible for garbage collection. type GCPolicy interface { String() string proto() *bttdpb.GcRule + PolicyType() int } // IntersectionPolicy returns a GC policy that only applies when all its sub-policies apply. @@ -56,6 +65,10 @@ func (ip intersectionPolicy) proto() *bttdpb.GcRule { } } +func (intersectionPolicy) PolicyType() int { + return PolicyType_Intersection +} + // UnionPolicy returns a GC policy that applies when any of its sub-policies apply. func UnionPolicy(sub ...GCPolicy) GCPolicy { return unionPolicy{sub} } @@ -81,6 +94,10 @@ func (up unionPolicy) proto() *bttdpb.GcRule { } } +func (unionPolicy) PolicyType() int { + return PolicyType_Union +} + // MaxVersionsPolicy returns a GC policy that applies to all versions of a cell // except for the most recent n. func MaxVersionsPolicy(n int) GCPolicy { return maxVersionsPolicy(n) } @@ -93,6 +110,10 @@ func (mvp maxVersionsPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: &bttdpb.GcRule_MaxNumVersions{MaxNumVersions: int32(mvp)}} } +func (maxVersionsPolicy) PolicyType() int { + return PolicyType_MaxVersion +} + // MaxAgePolicy returns a GC policy that applies to all cells // older than the given age. func MaxAgePolicy(d time.Duration) GCPolicy { return maxAgePolicy(d) } @@ -130,12 +151,20 @@ func (ma maxAgePolicy) proto() *bttdpb.GcRule { } } +func (maxAgePolicy) PolicyType() int { + return PolicyType_MaxAge +} + type noGCPolicy struct{} func (n noGCPolicy) String() string { return "" } func (n noGCPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: nil} } +func (n noGCPolicy) PolicyType() int { + return PolicyType_None +} + // NoGcPolicy applies to all cells setting maxage and maxversions to nil implies no gc policies func NoGcPolicy() GCPolicy { return noGCPolicy{} } @@ -158,6 +187,24 @@ func GCRuleToString(rule *bttdpb.GcRule) string { } } +func GCRuleToPolicy(rule *bttdpb.GcRule) GCPolicy { + if rule == nil { + return NoGcPolicy() + } + switch r := rule.Rule.(type) { + case *bttdpb.GcRule_Intersection_: + return fromRuleToPolicy(r.Intersection.Rules, PolicyType_Intersection) + case *bttdpb.GcRule_Union_: + return fromRuleToPolicy(r.Union.Rules, PolicyType_Union) + case *bttdpb.GcRule_MaxAge: + return MaxAgePolicy(time.Duration(r.MaxAge.Seconds) * time.Second) + case *bttdpb.GcRule_MaxNumVersions: + return MaxVersionsPolicy(int(r.MaxNumVersions)) + default: + return NoGcPolicy() + } +} + func joinRules(rules []*bttdpb.GcRule, sep string) string { var chunks []string for _, r := range rules { @@ -165,3 +212,22 @@ func joinRules(rules []*bttdpb.GcRule, sep string) string { } return "(" + strings.Join(chunks, sep) + ")" } + +func fromRuleToPolicy(rules []*bttdpb.GcRule, mode int) GCPolicy { + sub := []GCPolicy{} + for _, r := range rules { + p := GCRuleToPolicy(r) + if p.String() != "" { + sub = append(sub, GCRuleToPolicy(r)) + } + } + + switch mode { + case PolicyType_Union: + return unionPolicy{sub: sub} + case PolicyType_Intersection: + return intersectionPolicy{sub: sub} + default: + return NoGcPolicy() + } +} diff --git a/bigtable/gc_test.go b/bigtable/gc_test.go index 70849ab4122c..4ba223f247d4 100644 --- a/bigtable/gc_test.go +++ b/bigtable/gc_test.go @@ -44,3 +44,26 @@ func TestGcRuleToString(t *testing.T) { } } } + +func TestGCRuleToPolicy(t *testing.T) { + var tc = []struct { + proto *bttdpb.GcRule + want string + }{ + {MaxAgePolicy(72 * time.Hour).proto(), "age() > 3d"}, + {MaxVersionsPolicy(5).proto(), "versions() > 5"}, + {IntersectionPolicy(MaxAgePolicy(5*time.Hour), MaxVersionsPolicy(4)).proto(), + "(age() > 5h && versions() > 4)"}, + {UnionPolicy(MaxAgePolicy(5*time.Hour), MaxVersionsPolicy(4)).proto(), + "(age() > 5h || versions() > 4)"}, + {IntersectionPolicy(UnionPolicy(MaxAgePolicy(5*time.Hour), MaxVersionsPolicy(4)), MaxVersionsPolicy(8)).proto(), + "((age() > 5h || versions() > 4) && versions() > 8)"}, + } + + for _, test := range tc { + got := GCRuleToPolicy(test.proto) + if got.String() != test.want { + t.Errorf("got gc rule %v, want: %v", got, test.want) + } + } +} From dc64bdd925680da180e16aa372ef3ce600900743 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Sun, 8 May 2022 23:02:20 -0400 Subject: [PATCH 03/10] Add PolicyType alias to int. --- bigtable/gc.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bigtable/gc.go b/bigtable/gc.go index 481e242494da..e02a0bd09cb6 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -33,11 +33,13 @@ const ( PolicyType_Intersection ) +type PolicyType = int + // A GCPolicy represents a rule that determines which cells are eligible for garbage collection. type GCPolicy interface { String() string proto() *bttdpb.GcRule - PolicyType() int + PolicyType() PolicyType } // IntersectionPolicy returns a GC policy that only applies when all its sub-policies apply. @@ -65,7 +67,7 @@ func (ip intersectionPolicy) proto() *bttdpb.GcRule { } } -func (intersectionPolicy) PolicyType() int { +func (intersectionPolicy) PolicyType() PolicyType { return PolicyType_Intersection } @@ -94,7 +96,7 @@ func (up unionPolicy) proto() *bttdpb.GcRule { } } -func (unionPolicy) PolicyType() int { +func (unionPolicy) PolicyType() PolicyType { return PolicyType_Union } @@ -110,7 +112,7 @@ func (mvp maxVersionsPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: &bttdpb.GcRule_MaxNumVersions{MaxNumVersions: int32(mvp)}} } -func (maxVersionsPolicy) PolicyType() int { +func (maxVersionsPolicy) PolicyType() PolicyType { return PolicyType_MaxVersion } @@ -151,7 +153,7 @@ func (ma maxAgePolicy) proto() *bttdpb.GcRule { } } -func (maxAgePolicy) PolicyType() int { +func (maxAgePolicy) PolicyType() PolicyType { return PolicyType_MaxAge } @@ -161,7 +163,7 @@ func (n noGCPolicy) String() string { return "" } func (n noGCPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: nil} } -func (n noGCPolicy) PolicyType() int { +func (n noGCPolicy) PolicyType() PolicyType { return PolicyType_None } @@ -213,7 +215,7 @@ func joinRules(rules []*bttdpb.GcRule, sep string) string { return "(" + strings.Join(chunks, sep) + ")" } -func fromRuleToPolicy(rules []*bttdpb.GcRule, mode int) GCPolicy { +func fromRuleToPolicy(rules []*bttdpb.GcRule, mode PolicyType) GCPolicy { sub := []GCPolicy{} for _, r := range rules { p := GCRuleToPolicy(r) From 5741a5a0837a855929c998023559a2707ff14896 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Thu, 12 May 2022 10:07:32 -0400 Subject: [PATCH 04/10] Add new TypedGCPolicy to prevent breaking changes --- bigtable/admin.go | 4 +-- bigtable/gc.go | 61 +++++++++++++++++++++++++++++---------------- bigtable/gc_test.go | 2 +- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/bigtable/admin.go b/bigtable/admin.go index fc0575407ec5..056bf2101745 100644 --- a/bigtable/admin.go +++ b/bigtable/admin.go @@ -312,7 +312,7 @@ type TableInfo struct { type FamilyInfo struct { Name string GCPolicy string - GCPolicyObject GCPolicy + TypedGCPolicy TypedGCPolicy } func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Table_View) (*btapb.Table, error) { @@ -351,7 +351,7 @@ func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{ Name: name, GCPolicy: GCRuleToString(fam.GcRule), - GCPolicyObject: GCRuleToPolicy(fam.GcRule), + TypedGCPolicy: fromPolicyToTypedPolicy(gcRuleToPolicy(fam.GcRule)), }) } return ti, nil diff --git a/bigtable/gc.go b/bigtable/gc.go index e02a0bd09cb6..10e0532832c4 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -25,21 +25,25 @@ import ( bttdpb "google.golang.org/genproto/googleapis/bigtable/admin/v2" ) +type PolicyType = int + const ( - PolicyType_None = iota - PolicyType_MaxAge - PolicyType_MaxVersion - PolicyType_Union - PolicyType_Intersection + PolicyTypeNone PolicyType = iota + PolicyTypeMaxAge + PolicyTypeMaxVersion + PolicyTypeUnion + PolicyTypeIntersection ) -type PolicyType = int - // A GCPolicy represents a rule that determines which cells are eligible for garbage collection. type GCPolicy interface { String() string proto() *bttdpb.GcRule - PolicyType() PolicyType +} + +type TypedGCPolicy struct { + GCPolicy + PolicyType PolicyType } // IntersectionPolicy returns a GC policy that only applies when all its sub-policies apply. @@ -68,7 +72,7 @@ func (ip intersectionPolicy) proto() *bttdpb.GcRule { } func (intersectionPolicy) PolicyType() PolicyType { - return PolicyType_Intersection + return PolicyTypeIntersection } // UnionPolicy returns a GC policy that applies when any of its sub-policies apply. @@ -97,7 +101,7 @@ func (up unionPolicy) proto() *bttdpb.GcRule { } func (unionPolicy) PolicyType() PolicyType { - return PolicyType_Union + return PolicyTypeUnion } // MaxVersionsPolicy returns a GC policy that applies to all versions of a cell @@ -113,7 +117,7 @@ func (mvp maxVersionsPolicy) proto() *bttdpb.GcRule { } func (maxVersionsPolicy) PolicyType() PolicyType { - return PolicyType_MaxVersion + return PolicyTypeMaxVersion } // MaxAgePolicy returns a GC policy that applies to all cells @@ -154,7 +158,7 @@ func (ma maxAgePolicy) proto() *bttdpb.GcRule { } func (maxAgePolicy) PolicyType() PolicyType { - return PolicyType_MaxAge + return PolicyTypeMaxAge } type noGCPolicy struct{} @@ -164,7 +168,7 @@ func (n noGCPolicy) String() string { return "" } func (n noGCPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: nil} } func (n noGCPolicy) PolicyType() PolicyType { - return PolicyType_None + return PolicyTypeNone } // NoGcPolicy applies to all cells setting maxage and maxversions to nil implies no gc policies @@ -189,15 +193,15 @@ func GCRuleToString(rule *bttdpb.GcRule) string { } } -func GCRuleToPolicy(rule *bttdpb.GcRule) GCPolicy { +func gcRuleToPolicy(rule *bttdpb.GcRule) GCPolicy { if rule == nil { return NoGcPolicy() } switch r := rule.Rule.(type) { case *bttdpb.GcRule_Intersection_: - return fromRuleToPolicy(r.Intersection.Rules, PolicyType_Intersection) + return compoundRuleToPolicy(r.Intersection.Rules, PolicyTypeIntersection) case *bttdpb.GcRule_Union_: - return fromRuleToPolicy(r.Union.Rules, PolicyType_Union) + return compoundRuleToPolicy(r.Union.Rules, PolicyTypeUnion) case *bttdpb.GcRule_MaxAge: return MaxAgePolicy(time.Duration(r.MaxAge.Seconds) * time.Second) case *bttdpb.GcRule_MaxNumVersions: @@ -215,21 +219,36 @@ func joinRules(rules []*bttdpb.GcRule, sep string) string { return "(" + strings.Join(chunks, sep) + ")" } -func fromRuleToPolicy(rules []*bttdpb.GcRule, mode PolicyType) GCPolicy { +func compoundRuleToPolicy(rules []*bttdpb.GcRule, mode PolicyType) GCPolicy { sub := []GCPolicy{} for _, r := range rules { - p := GCRuleToPolicy(r) + p := gcRuleToPolicy(r) if p.String() != "" { - sub = append(sub, GCRuleToPolicy(r)) + sub = append(sub, gcRuleToPolicy(r)) } } switch mode { - case PolicyType_Union: + case PolicyTypeUnion: return unionPolicy{sub: sub} - case PolicyType_Intersection: + case PolicyTypeIntersection: return intersectionPolicy{sub: sub} default: return NoGcPolicy() } } + +func fromPolicyToTypedPolicy(gcPolicy GCPolicy) TypedGCPolicy { + switch gcPolicy.proto().Rule.(type) { + case *bttdpb.GcRule_Intersection_: + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeIntersection} + case *bttdpb.GcRule_Union_: + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnion} + case *bttdpb.GcRule_MaxAge: + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxAge} + case *bttdpb.GcRule_MaxNumVersions: + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxVersion} + default: + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeNone} + } +} diff --git a/bigtable/gc_test.go b/bigtable/gc_test.go index 4ba223f247d4..81e80bef2d06 100644 --- a/bigtable/gc_test.go +++ b/bigtable/gc_test.go @@ -61,7 +61,7 @@ func TestGCRuleToPolicy(t *testing.T) { } for _, test := range tc { - got := GCRuleToPolicy(test.proto) + got := gcRuleToPolicy(test.proto) if got.String() != test.want { t.Errorf("got gc rule %v, want: %v", got, test.want) } From a215371db1bf3a342e6e738eee33e85adccd2cd0 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Thu, 12 May 2022 10:11:01 -0400 Subject: [PATCH 05/10] Remove unused methods --- bigtable/gc.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/bigtable/gc.go b/bigtable/gc.go index 10e0532832c4..271dca8e8326 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -71,10 +71,6 @@ func (ip intersectionPolicy) proto() *bttdpb.GcRule { } } -func (intersectionPolicy) PolicyType() PolicyType { - return PolicyTypeIntersection -} - // UnionPolicy returns a GC policy that applies when any of its sub-policies apply. func UnionPolicy(sub ...GCPolicy) GCPolicy { return unionPolicy{sub} } @@ -100,10 +96,6 @@ func (up unionPolicy) proto() *bttdpb.GcRule { } } -func (unionPolicy) PolicyType() PolicyType { - return PolicyTypeUnion -} - // MaxVersionsPolicy returns a GC policy that applies to all versions of a cell // except for the most recent n. func MaxVersionsPolicy(n int) GCPolicy { return maxVersionsPolicy(n) } @@ -116,10 +108,6 @@ func (mvp maxVersionsPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: &bttdpb.GcRule_MaxNumVersions{MaxNumVersions: int32(mvp)}} } -func (maxVersionsPolicy) PolicyType() PolicyType { - return PolicyTypeMaxVersion -} - // MaxAgePolicy returns a GC policy that applies to all cells // older than the given age. func MaxAgePolicy(d time.Duration) GCPolicy { return maxAgePolicy(d) } @@ -157,20 +145,12 @@ func (ma maxAgePolicy) proto() *bttdpb.GcRule { } } -func (maxAgePolicy) PolicyType() PolicyType { - return PolicyTypeMaxAge -} - type noGCPolicy struct{} func (n noGCPolicy) String() string { return "" } func (n noGCPolicy) proto() *bttdpb.GcRule { return &bttdpb.GcRule{Rule: nil} } -func (n noGCPolicy) PolicyType() PolicyType { - return PolicyTypeNone -} - // NoGcPolicy applies to all cells setting maxage and maxversions to nil implies no gc policies func NoGcPolicy() GCPolicy { return noGCPolicy{} } From ee17e0785e0e75f9bed8c0acdfc4ec53a102be3b Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Mon, 16 May 2022 10:15:21 -0400 Subject: [PATCH 06/10] Address PR comments. --- bigtable/gc.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigtable/gc.go b/bigtable/gc.go index 271dca8e8326..a38fafaa6b7b 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -25,10 +25,10 @@ import ( bttdpb "google.golang.org/genproto/googleapis/bigtable/admin/v2" ) -type PolicyType = int +type PolicyType int const ( - PolicyTypeNone PolicyType = iota + PolicyTypeUnknown PolicyType = iota PolicyTypeMaxAge PolicyTypeMaxVersion PolicyTypeUnion @@ -229,6 +229,6 @@ func fromPolicyToTypedPolicy(gcPolicy GCPolicy) TypedGCPolicy { case *bttdpb.GcRule_MaxNumVersions: return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxVersion} default: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeNone} + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnknown} } } From 6597b60444062fa20da8f6a1dc73df442ab069fd Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Thu, 2 Jun 2022 10:10:40 -0400 Subject: [PATCH 07/10] Change variable name to Unspecified instead of Unknown. --- bigtable/gc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigtable/gc.go b/bigtable/gc.go index a38fafaa6b7b..3148adfb8d69 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -28,7 +28,7 @@ import ( type PolicyType int const ( - PolicyTypeUnknown PolicyType = iota + PolicyTypeUnspecified PolicyType = iota PolicyTypeMaxAge PolicyTypeMaxVersion PolicyTypeUnion @@ -229,6 +229,6 @@ func fromPolicyToTypedPolicy(gcPolicy GCPolicy) TypedGCPolicy { case *bttdpb.GcRule_MaxNumVersions: return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxVersion} default: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnknown} + return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnspecified} } } From 8eb8f753ed5eb0eab018a29b3b3f333fdee5cdd4 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Tue, 7 Jun 2022 15:06:33 -0400 Subject: [PATCH 08/10] Fix go fmt. --- bigtable/admin.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bigtable/admin.go b/bigtable/admin.go index 056bf2101745..3e92d4f0d609 100644 --- a/bigtable/admin.go +++ b/bigtable/admin.go @@ -310,9 +310,9 @@ type TableInfo struct { // FamilyInfo represents information about a column family. type FamilyInfo struct { - Name string - GCPolicy string - TypedGCPolicy TypedGCPolicy + Name string + GCPolicy string + TypedGCPolicy TypedGCPolicy } func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Table_View) (*btapb.Table, error) { @@ -349,9 +349,9 @@ func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, for name, fam := range res.ColumnFamilies { ti.Families = append(ti.Families, name) ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{ - Name: name, - GCPolicy: GCRuleToString(fam.GcRule), - TypedGCPolicy: fromPolicyToTypedPolicy(gcRuleToPolicy(fam.GcRule)), + Name: name, + GCPolicy: GCRuleToString(fam.GcRule), + TypedGCPolicy: fromPolicyToTypedPolicy(gcRuleToPolicy(fam.GcRule)), }) } return ti, nil From 0e2a8153673f05e9209224f638df5b4b5be131a1 Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Fri, 10 Jun 2022 10:33:21 -0400 Subject: [PATCH 09/10] Address build failure. --- bigtable/gc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bigtable/gc.go b/bigtable/gc.go index 3148adfb8d69..9803a162cd3e 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -25,6 +25,7 @@ import ( bttdpb "google.golang.org/genproto/googleapis/bigtable/admin/v2" ) +// PolicyType to distinguish between max_age, max_version and compound types type PolicyType int const ( @@ -41,6 +42,7 @@ type GCPolicy interface { proto() *bttdpb.GcRule } +// TypedGCPolicy is a wrapper around GCPolicy that allows GC type detection type TypedGCPolicy struct { GCPolicy PolicyType PolicyType From 0d12c0a2e4a1db84860a8d2b93f0db7f2139279a Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Mon, 13 Jun 2022 10:07:38 -0400 Subject: [PATCH 10/10] Add FullGCPolicy to admin.go. --- bigtable/admin.go | 12 ++++++------ bigtable/gc.go | 41 ++++++++--------------------------------- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/bigtable/admin.go b/bigtable/admin.go index 3e92d4f0d609..8b318ce409f1 100644 --- a/bigtable/admin.go +++ b/bigtable/admin.go @@ -310,9 +310,9 @@ type TableInfo struct { // FamilyInfo represents information about a column family. type FamilyInfo struct { - Name string - GCPolicy string - TypedGCPolicy TypedGCPolicy + Name string + GCPolicy string + FullGCPolicy GCPolicy } func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Table_View) (*btapb.Table, error) { @@ -349,9 +349,9 @@ func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, for name, fam := range res.ColumnFamilies { ti.Families = append(ti.Families, name) ti.FamilyInfos = append(ti.FamilyInfos, FamilyInfo{ - Name: name, - GCPolicy: GCRuleToString(fam.GcRule), - TypedGCPolicy: fromPolicyToTypedPolicy(gcRuleToPolicy(fam.GcRule)), + Name: name, + GCPolicy: GCRuleToString(fam.GcRule), + FullGCPolicy: gcRuleToPolicy(fam.GcRule), }) } return ti, nil diff --git a/bigtable/gc.go b/bigtable/gc.go index 9803a162cd3e..0c3efbddf25a 100644 --- a/bigtable/gc.go +++ b/bigtable/gc.go @@ -25,15 +25,11 @@ import ( bttdpb "google.golang.org/genproto/googleapis/bigtable/admin/v2" ) -// PolicyType to distinguish between max_age, max_version and compound types -type PolicyType int +type policyType int const ( - PolicyTypeUnspecified PolicyType = iota - PolicyTypeMaxAge - PolicyTypeMaxVersion - PolicyTypeUnion - PolicyTypeIntersection + policyTypeUnion policyType = iota + policyTypeIntersection ) // A GCPolicy represents a rule that determines which cells are eligible for garbage collection. @@ -42,12 +38,6 @@ type GCPolicy interface { proto() *bttdpb.GcRule } -// TypedGCPolicy is a wrapper around GCPolicy that allows GC type detection -type TypedGCPolicy struct { - GCPolicy - PolicyType PolicyType -} - // IntersectionPolicy returns a GC policy that only applies when all its sub-policies apply. func IntersectionPolicy(sub ...GCPolicy) GCPolicy { return intersectionPolicy{sub} } @@ -181,9 +171,9 @@ func gcRuleToPolicy(rule *bttdpb.GcRule) GCPolicy { } switch r := rule.Rule.(type) { case *bttdpb.GcRule_Intersection_: - return compoundRuleToPolicy(r.Intersection.Rules, PolicyTypeIntersection) + return compoundRuleToPolicy(r.Intersection.Rules, policyTypeIntersection) case *bttdpb.GcRule_Union_: - return compoundRuleToPolicy(r.Union.Rules, PolicyTypeUnion) + return compoundRuleToPolicy(r.Union.Rules, policyTypeUnion) case *bttdpb.GcRule_MaxAge: return MaxAgePolicy(time.Duration(r.MaxAge.Seconds) * time.Second) case *bttdpb.GcRule_MaxNumVersions: @@ -201,7 +191,7 @@ func joinRules(rules []*bttdpb.GcRule, sep string) string { return "(" + strings.Join(chunks, sep) + ")" } -func compoundRuleToPolicy(rules []*bttdpb.GcRule, mode PolicyType) GCPolicy { +func compoundRuleToPolicy(rules []*bttdpb.GcRule, mode policyType) GCPolicy { sub := []GCPolicy{} for _, r := range rules { p := gcRuleToPolicy(r) @@ -211,26 +201,11 @@ func compoundRuleToPolicy(rules []*bttdpb.GcRule, mode PolicyType) GCPolicy { } switch mode { - case PolicyTypeUnion: + case policyTypeUnion: return unionPolicy{sub: sub} - case PolicyTypeIntersection: + case policyTypeIntersection: return intersectionPolicy{sub: sub} default: return NoGcPolicy() } } - -func fromPolicyToTypedPolicy(gcPolicy GCPolicy) TypedGCPolicy { - switch gcPolicy.proto().Rule.(type) { - case *bttdpb.GcRule_Intersection_: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeIntersection} - case *bttdpb.GcRule_Union_: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnion} - case *bttdpb.GcRule_MaxAge: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxAge} - case *bttdpb.GcRule_MaxNumVersions: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeMaxVersion} - default: - return TypedGCPolicy{GCPolicy: gcPolicy, PolicyType: PolicyTypeUnspecified} - } -}