add query totals by group

This commit is contained in:
Ben McClelland
2021-10-04 13:09:09 -07:00
parent 0cca7e27f0
commit 777740e7e1
2 changed files with 111 additions and 7 deletions

View File

@@ -4,6 +4,14 @@
// that can be found in the LICENSE file in the root of the source
// tree.
// This example returns the values of a "group" of totl counts/values
// given a 2 uint64 id group tuple. Or it will return the single value
// for a unique 3 uint64 id triple.
// id1 id2 id3
// |--group--|
// |--specific id---|
package main
import (
@@ -16,8 +24,9 @@ import (
)
func main() {
if len(os.Args) != 5 || os.Args[1] == "-h" {
fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "<scoutfs mount point> <id1> <id2> <id3>")
if (len(os.Args) != 4 && len(os.Args) != 5) || os.Args[1] == "-h" {
fmt.Fprintln(os.Stderr, "usage:", os.Args[0],
"<scoutfs mount point> <id1> <id2> or <scoutfs mount point> <id1> <id2> <id3>")
os.Exit(1)
}
@@ -35,16 +44,33 @@ func main() {
if err != nil {
log.Fatalln("error parsing id2:", err)
}
if len(os.Args) == 4 {
tg := scoutfs.NewTotalsGroup(f, u1, u2, 10)
for {
ttls, err := tg.Next()
if err != nil {
log.Fatalln("error read totals:", err)
}
if ttls == nil {
break
}
for _, t := range ttls {
fmt.Println("id:", t.ID[2], "xattrs match:", t.Count, "total value:", t.Total)
}
}
return
}
u3, err := strconv.ParseUint(os.Args[4], 10, 64)
if err != nil {
log.Fatalln("error parsing id3:", err)
log.Fatalln("error parsing id2:", err)
}
t, err := scoutfs.ReadXattrTotals(f, u1, u2, u3)
if err != nil {
log.Fatalln("error read totals:", err)
log.Fatalln("error reading totals:", err)
}
fmt.Println("xattrs match: ", t.Count)
fmt.Println("total value : ", t.Total)
fmt.Println("Count", t.Count)
fmt.Println("Total", t.Total)
}