Exemplo n.º 1
0
        private static object UpdateFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Updating column family cf1 GC rule...");
            // [START bigtable_update_gc_rule]
            // Update the column family metadata to update the GC rule.
            // Initialize request argument(s).
            // Updated column family GC rule.
            GcRule maxVersionsRule = new GcRule {
                MaxNumVersions = 1
            };

            // Column family to create
            ColumnFamily columnFamily = new ColumnFamily {
                GcRule = maxVersionsRule
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to update column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Update = columnFamily,
                Id     = "cf1"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Updated column family");
                // [END bigtable_update_gc_rule]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_update_gc_rule]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error updating column family {ex.Message}");
            }

            // [END bigtable_update_gc_rule]
            return(0);
        }
Exemplo n.º 2
0
        private static object CreateMaxVersionsFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf2 with max versions GC rule...");
            // [START bigtable_create_family_gc_max_versions]
            // Create a column family with GC policy : most recent N versions
            // where 1 = most recent version
            // Initialize request argument(s).
            // Define the GC policy to retain only the most recent 2 versions
            GcRule maxVersionsRule = new GcRule {
                MaxNumVersions = 2
            };

            // Column family to create
            ColumnFamily columnFamily = new ColumnFamily {
                GcRule = maxVersionsRule
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to create column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Create = columnFamily,
                Id     = "cf2"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Created column family");
                // [END bigtable_create_family_gc_max_versions]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_family_gc_max_versions]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_max_versions]
            return(0);
        }
Exemplo n.º 3
0
        private static object CreateMaxAgeFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf1 with max age GC rule...");
            // [START bigtable_create_family_gc_max_age]
            // Create a column family with GC policy : maximum age
            // where age = current time minus cell timestamp
            // Initialize request argument(s).
            // Define the GC rule to retain data with max age of 5 days
            GcRule MaxAgeRule = new GcRule {
                MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5.0))
            };

            // Column family to create
            ColumnFamily columnFamily = new ColumnFamily {
                GcRule = MaxAgeRule
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to create column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Create = columnFamily,
                Id     = "cf1"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Created column family");
                // [END bigtable_create_bigtableTableAdminClient]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_bigtableTableAdminClient]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_max_age]
            return(0);
        }
Exemplo n.º 4
0
 internal RetentionPolicy(GcRule gcRule, string gcExpression) : this()
 {
     if (gcRule.MaxNumVersions != 0)
     {
         Duration = DurationTypes.Versions;
         MaxAge   = gcRule.MaxNumVersions;
     }
     else if (gcRule.MaxAge.Nanos != 0)
     {
         // The protobufs I've seen don't support nanos
         // But there are artifacts (like .Nanos) all over
         // that make me think it would work.  Maybe as part
         // of the release-to-world, that feature was depreciated.
         // It probably works, though, so handle it.
         MaxAge   = gcRule.MaxAge.Nanos / 1000;
         Duration = DurationTypes.Milliseconds;
     }
     else if (gcRule.MaxAge.Seconds != 0)
     {
         var span = TimeSpan.FromSeconds(gcRule.MaxAge.Seconds);
         if (span.TotalDays > 365)
         {
             Duration = DurationTypes.Years;
             MaxAge   = (long)(span.TotalDays / 365);
         }
         else if (span.TotalDays > 0)
         {
             Duration = DurationTypes.Days;
             MaxAge   = (long)span.TotalDays;
         }
         else if (span.TotalHours > 0)
         {
             Duration = DurationTypes.Hours;
             MaxAge   = (long)span.TotalHours;
         }
         else if (span.TotalMinutes > 0)
         {
             Duration = DurationTypes.Minutes;
             MaxAge   = (long)span.TotalMinutes;
         }
         else if (span.TotalSeconds > 0)
         {
             Duration = DurationTypes.Seconds;
             MaxAge   = (long)span.TotalSeconds;
         }
     }
     if (!String.IsNullOrEmpty(gcExpression))
     {
         _expression = gcExpression;
     }
 }
Exemplo n.º 5
0
        private static object DeleteFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Deleting column family cf2 GC rule...");
            // [START bigtable_delete_family]
            // Delete a column family.
            // Initialize request argument(s).
            GcRule maxVersionsRule = new GcRule {
                MaxNumVersions = 1
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to update column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Drop = true,
                Id   = "cf2"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Deleted column family");
                // [END bigtable_delete_family]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_delete_family]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error deleting column family {ex.Message}");
            }

            // [END bigtable_delete_family]
            return(0);
        }
Exemplo n.º 6
0
        private static object CreateNestedFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf5 with a nested GC rule...");
            // [START bigtable_create_family_gc_nested]
            // Create a nested GC rule:
            // Drop cells that are either older than the 10 recent versions
            // OR
            // Drop cells that are older than a month AND older than the 2 recent versions.
            // Initialize request argument(s).
            GcRule.Types.Intersection intersectionRule = new GcRule.Types.Intersection
            {
                Rules =
                {
                    new GcRule {
                        MaxNumVersions = 2
                    },
                    new GcRule {
                        MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5))
                    }
                }
            };

            GcRule.Types.Union nestedRule = new GcRule.Types.Union
            {
                Rules =
                {
                    new GcRule {
                        MaxNumVersions = 10
                    },
                    new GcRule {
                        Intersection = intersectionRule
                    }
                }
            };

            GcRule gcRule = new GcRule {
                Union = nestedRule
            };

            // Column family to create
            ColumnFamily columnFamily = new ColumnFamily {
                GcRule = gcRule
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to create column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Create = columnFamily,
                Id     = "cf5"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Created column family");
                // [END bigtable_create_family_gc_nested]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_family_gc_nested]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_nested]
            return(0);
        }
Exemplo n.º 7
0
        private static object CreateIntersectionFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf4 with intersect GC rule...");
            // [START bigtable_create_family_gc_intersection]
            // Create a column family with GC policy to drop data that matches all conditions.
            // Initialize request argument(s).
            // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions.
            GcRule.Types.Intersection intersectionRule = new GcRule.Types.Intersection
            {
                Rules =
                {
                    new GcRule {
                        MaxNumVersions = 2
                    },
                    new GcRule {
                        MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5))
                    }
                }
            };
            GcRule gcRule = new GcRule {
                Intersection = intersectionRule
            };

            // Column family to create
            ColumnFamily columnFamily = new ColumnFamily {
                GcRule = gcRule
            };

            TableName tableName = new TableName(projectId, instanceId, tableId);

            // Modification to create column family
            ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
            {
                Create = columnFamily,
                Id     = "cf4"
            };

            ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
            {
                TableName     = tableName,
                Modifications = { modification }
            };

            try
            {
                // Make the request
                Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
                Console.WriteLine("Created column family");
                // [END bigtable_create_family_gc_intersection]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_family_gc_intersection]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_intersection]
            return(0);
        }