mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
remove print statements
This commit is contained in:
parent
4e2727c255
commit
abcd90b60a
1 changed files with 1 additions and 38 deletions
39
api.go
39
api.go
|
|
@ -944,24 +944,20 @@ type MemoryUsage struct {
|
|||
|
||||
// Returns disk usage from cache. Waits for calculation if cache is empty.
|
||||
func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, error) {
|
||||
// time.Sleep(time.Second * 2)
|
||||
fmt.Println("Usage: 1")
|
||||
span, _ := tracing.StartSpanFromContext(ctx, "API.Usage")
|
||||
defer span.Finish()
|
||||
|
||||
api.usageCache.muRead.Lock()
|
||||
defer api.usageCache.muRead.Unlock()
|
||||
fmt.Println("Usage: 2")
|
||||
|
||||
var t time.Time
|
||||
if api.usageCache.lastUpdated == t {
|
||||
api.calculateUsage()
|
||||
}
|
||||
fmt.Printf("Usage: 3, %+v\n", api.usageCache.data)
|
||||
|
||||
if !remote {
|
||||
api.requestUsageOfNodes()
|
||||
}
|
||||
fmt.Println("Usage: 4")
|
||||
|
||||
api.server.logger.Infof("disk usage results last updated: %v", api.usageCache.lastUpdated.Format(time.RFC1123))
|
||||
return api.usageCache.data, nil
|
||||
|
|
@ -969,36 +965,20 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
|
|||
|
||||
// Makes a ui/usage request for each node in cluster to calculates its usage and adds it to the cache
|
||||
func (api *API) requestUsageOfNodes() {
|
||||
// err := api.server.cluster.no
|
||||
// if err != nil {
|
||||
// t.Fatalf("starting cluster: %v", err)
|
||||
// }
|
||||
|
||||
// time.Sleep(time.Second * 10)
|
||||
|
||||
nodes := api.cluster.Nodes()
|
||||
for _, node := range nodes {
|
||||
if node.ID == api.server.nodeID {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("Server ID: %v, Node ID: %v, Node URI: %v\n", api.server.nodeID, node.ID, node.URI)
|
||||
// if node.URI.Scheme == "" || node.URI.Host == "" {
|
||||
// continue
|
||||
// }
|
||||
nodeUsage, err := api.server.defaultClient.GetNodeUsage(context.Background(), &node.URI)
|
||||
if err != nil {
|
||||
api.server.logger.Infof("couldn't collect disk usage from %s: %s", node.URI, err)
|
||||
}
|
||||
|
||||
fmt.Println("NU: 2")
|
||||
fmt.Printf("NU: %+v\n", nodeUsage)
|
||||
// api.usageCache.muRead.Lock()
|
||||
fmt.Println("NU: 3")
|
||||
api.usageCache.data[node.ID] = nodeUsage[node.ID]
|
||||
fmt.Println("NU: 4")
|
||||
// api.usageCache.muRead.Unlock()
|
||||
fmt.Println("NU: 5")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1013,19 +993,14 @@ func (api *API) calculateUsage() {
|
|||
// api.usageCache.muRead.Unlock()
|
||||
|
||||
if time.Since(lastUpdated) > api.usageCache.refreshInterval {
|
||||
fmt.Printf("RefreshRate, expired: time: %v, current time: %v \n", api.usageCache.lastUpdated, time.Now())
|
||||
|
||||
indexDetails, nodeMetadataBytes, err := api.holder.Txf().IndexUsageDetails()
|
||||
if err != nil {
|
||||
api.server.logger.Infof("couldn't get index usage details: %s", err)
|
||||
}
|
||||
fmt.Printf("Calculate - Index Details: %+v\n", indexDetails)
|
||||
totalSize := nodeMetadataBytes
|
||||
fmt.Printf("totalSize: %+v\n", totalSize)
|
||||
for _, s := range indexDetails {
|
||||
totalSize += s.Total
|
||||
}
|
||||
fmt.Println("3")
|
||||
|
||||
// NOTE: these errors are ignored in api.Info(), but checked here
|
||||
si := api.server.systemInfo
|
||||
|
|
@ -1033,18 +1008,15 @@ func (api *API) calculateUsage() {
|
|||
if err != nil {
|
||||
api.server.logger.Infof("couldn't read disk capacity: %s", err)
|
||||
}
|
||||
fmt.Println("4")
|
||||
|
||||
memoryCapacity, err := si.MemTotal()
|
||||
if err != nil {
|
||||
api.server.logger.Infof("couldn't read memory capacity: %s", err)
|
||||
}
|
||||
fmt.Println("5")
|
||||
memoryUse, err := si.MemUsed()
|
||||
if err != nil {
|
||||
api.server.logger.Infof("couldn't read memory usage: %s", err)
|
||||
}
|
||||
fmt.Println("6")
|
||||
|
||||
// Insert into result.
|
||||
nodeUsage := NodeUsage{
|
||||
|
|
@ -1059,33 +1031,24 @@ func (api *API) calculateUsage() {
|
|||
},
|
||||
LastUpdated: time.Now(),
|
||||
}
|
||||
fmt.Println("7")
|
||||
// api.usageCache.muRead.Lock()
|
||||
// defer api.usageCache.muRead.Unlock()
|
||||
api.usageCache.data = make(map[string]NodeUsage)
|
||||
|
||||
fmt.Printf("Calculate - Node Usage: %+v\n", nodeUsage)
|
||||
api.usageCache.data[api.server.nodeID] = nodeUsage
|
||||
fmt.Printf("Calculate - NU from Map: %+v\n", api.usageCache.data[api.server.nodeID])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Periodically calculates disk usage
|
||||
func (api *API) RefreshUsageCache(refresh time.Duration) {
|
||||
fmt.Println("STARTING REFRESH")
|
||||
api.usageCache = &usageCache{
|
||||
data: make(map[string]NodeUsage),
|
||||
refreshInterval: refresh,
|
||||
}
|
||||
fmt.Println("Loop: 0")
|
||||
// time.Sleep(time.Second * 5)
|
||||
for {
|
||||
fmt.Println("Loop: 1")
|
||||
api.calculateUsage()
|
||||
fmt.Printf("Loop: 2, %+v\n", api.usageCache.data)
|
||||
api.usageCache.lastUpdated = time.Now()
|
||||
fmt.Println("Loop: 3")
|
||||
time.Sleep(api.usageCache.refreshInterval)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue