func doSetGCPolicy(ctx context.Context, args ...string) { if len(args) < 3 { log.Fatalf("usage: cbt setgcpolicy <table> <family> ( maxage=<d> | maxversions=<n> )") } table := args[0] fam := args[1] var pol bigtable.GCPolicy switch p := args[2]; { case strings.HasPrefix(p, "maxage="): d, err := parseDuration(p[7:]) if err != nil { log.Fatal(err) } pol = bigtable.MaxAgePolicy(d) case strings.HasPrefix(p, "maxversions="): n, err := strconv.ParseUint(p[12:], 10, 16) if err != nil { log.Fatal(err) } pol = bigtable.MaxVersionsPolicy(int(n)) default: log.Fatalf("Bad GC policy %q", p) } if err := getAdminClient().SetGCPolicy(ctx, table, fam, pol); err != nil { log.Fatalf("Setting GC policy: %v", err) } }
// handleReset deletes the table if it exists, creates it again, and creates its column families. func handleReset(w http.ResponseWriter, r *http.Request, table string, adminClient *bigtable.AdminClient) { if r.Method != "POST" { http.Error(w, "POST requests only", http.StatusMethodNotAllowed) return } ctx, _ := context.WithTimeout(context.Background(), 5*time.Minute) adminClient.DeleteTable(ctx, table) if err := adminClient.CreateTable(ctx, table); err != nil { http.Error(w, "Error creating Bigtable: "+err.Error(), http.StatusInternalServerError) return } time.Sleep(20 * time.Second) // Create two column families, and set the GC policy for each one to keep one version. for _, family := range []string{indexColumnFamily, contentColumnFamily} { if err := adminClient.CreateColumnFamily(ctx, table, family); err != nil { http.Error(w, "Error creating column family: "+err.Error(), http.StatusInternalServerError) return } if err := adminClient.SetGCPolicy(ctx, table, family, bigtable.MaxVersionsPolicy(1)); err != nil { http.Error(w, "Error setting GC policy: "+err.Error(), http.StatusInternalServerError) return } } w.Write([]byte("<html><body>Done.</body></html>")) return }