Example #1
0
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)
	}
}
Example #2
0
func initTables(addr string) error {
	client, err := adminClient(addr)
	if err != nil {
		return err
	}

	ctx, _ := context.WithTimeout(context.Background(), defaultTimeout)
	for table, cFams := range tables {
		if err := client.CreateTable(ctx, table); err != nil {
			// we log only instead of fatal directly
			log.Printf("create table failed:%v\n", err)
		}
		for _, cFam := range cFams {
			if err := client.CreateColumnFamily(ctx, table, cFam); err != nil {
				log.Printf("create column family failed:%v\n", err)
			}

			// this is used to minic hbase behavior where only one recent result is returned
			if err := client.SetGCPolicy(ctx, table, cFam, bgt.MaxVersionsPolicy(1)); err != nil {
				log.Printf("set gcpolicy failed:%v\n", err)
			}
		}
	}
	return nil
}
Example #3
0
// 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
}