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

Bigtable: add row_affinity support for the Row Affinity feature. #11839

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.T
obj.ClusterIds = append(obj.ClusterIds, id.(string))
}

if _, ok := d.GetOkExists("row_affinity"); ok {
obj.RowAffinity = bigtableadmin.RowAffinity{}
}

return obj, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "google_bigtable_instance" "instance" {
name = "{{index $.Vars "instance_name"}}"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-2"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-3"
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "{{index $.Vars "deletion_protection"}}"
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "{{index $.Vars "app_profile_name"}}"

// Requests will be routed to the following 2 clusters.
multi_cluster_routing_use_any = true
multi_cluster_routing_cluster_ids = ["cluster-1", "cluster-2"]

row_affinity = true

ignore_warnings = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
Type: schema.TypeString,
},
ConflictsWith: []string{"single_cluster_routing"},
},
},
"row_affinity": {
Type: schema.TypeBool,
Optional: true,
Description: `Must be used with multi-cluster routing. If true, then this app profile will use row affinity sticky routing. With row affinity, Bigtable will route single row key requests based on the row key, rather than randomly. Instead, each row key will be assigned to a cluster by Cloud Bigtable, and will stick to that cluster. Choosing this option improves read-your-writes consistency for most requests under most circumstances, without sacrificing availability. Consistency is not guaranteed, as requests may still fail over between clusters in the event of errors or latency.`,
ConflictsWith: []string{"single_cluster_routing"},
},
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,99 @@ func TestAccBigtableAppProfile_updateStandardIsolationToDataBoost(t *testing.T)
},
})
}
func testAccBigtableAppProfile_updateRowAffinity(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 1
storage_type = "HDD"
}
cluster {
cluster_id = "%s2"
zone = "us-central1-a"
num_nodes = 1
storage_type = "HDD"
}
cluster {
cluster_id = "%s3"
zone = "us-central1-c"
num_nodes = 1
storage_type = "HDD"
}
deletion_protection = false
}
resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.id
app_profile_id = "test"
multi_cluster_routing_use_any = true
multi_cluster_routing_cluster_ids = ["%s", "%s2", "%s3"]
row_affinity = true
ignore_warnings = true
}
`, instanceName, instanceName, instanceName, instanceName, instanceName, instanceName, instanceName)
}

func TestAccBigtableAppProfile_updateRowAffinity(t *testing.T) {
// bigtable instance does not use the shared HTTP client, this test creates an instance
acctest.SkipIfVcr(t)
t.Parallel()

instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_update1(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_updateMC2(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_updateRowAffinity(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_update1(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_updateRowAffinity(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
},
})
}