google-cloud-platformcloudgoogle-cloud-bigtablebigtable

How to set maxage and maxversions for bigtable table at the same time?


Could someone please let me know how could I set the maxage and maxversions policy for bigtable table at the same time in Google Cloud Platform. I tried to use below commands but only one policy is getting reflected for the table. I need both policies to be set.

Commands I used:

cbt -project <project_name> -instance <instance_name> setgcpolicy <table_name> <column_family> maxage=30d maxversions=100
cbt -project <project_name> -instance <instance_name> setgcpolicy <table_name> <column_family> "maxage=30d" && "maxversions=100"
cbt -project <project_name> -instance <instance_name> setgcpolicy <table_name> <column_family> maxage=30d and maxversions=100
cbt -project <project_name> -instance <instance_name> setgcpolicy <table_name> <column_family> maxage=30d|maxversions=100

The next setgcpolicy policy I set is just over-riding the previous policy.

The expected output should be as below -

cbt -project <project_name> -instance <instance_name> ls <table_name>
Family Name     GC Policy
-----------     ---------
rec             (age() > 30d || versions() > 100)

Could you please direct me on how to achieve the above output FYI, for all the tries/commands I am only seeing below output which shows only one policy set.

Family Name     GC Policy
-----------     ---------
demoSeg         versions() > 1
<columne_family>          age() > 30d

Could you please direct me on this requirement?


Solution

  • I think you need to update your cbt tool. The feature for setting multiple garbage collection was added in the past few months, so it's likely you haven't updated since then.

    Run this to update your tool:

    gcloud components update
    

    I'm on version "cbt 0.9.0 6ab8d8ff 2020-02-07 17:57:00", and I was able to successfully do this using the commands you specified:

    bigtable[master]$ cbt createtable gc-test
    bigtable[master]$ cbt createfamily gc-test cf
    bigtable[master]$ cbt setgcpolicy gc-test cf maxage=30d and maxversions=100
    bigtable[master]$ cbt ls gc-test
    Family Name GC Policy
    ----------- ---------
    cf      (age() > 30d && versions() > 100)
    

    Also, when using || and && for your policy definition instead of "and"/"or", you should put the entire policy in quotes (more info here):

    cbt -project <project_name> -instance <instance_name> setgcpolicy <table_name> <column_family> "maxage=30d && maxversions=100"