(rpcClient *rpc.RPCClient, serverId int64, currentTime string)
| 412 | } |
| 413 | |
| 414 | func (this *KVTask) uploadServerStats(rpcClient *rpc.RPCClient, serverId int64, currentTime string) (countValues int, uploadErr error) { |
| 415 | var pbStats []*pb.UploadingMetricStat |
| 416 | var keepKeys []string |
| 417 | |
| 418 | var prefix = string(byteutils.Concat([]byte(currentTime), []byte{'_'}, int32ToBigEndian(this.itemConfig.Version), int64ToBigEndian(serverId))) |
| 419 | var newCachedKeys = map[string]int64{} |
| 420 | queryErr := this.valuesTable. |
| 421 | Query(). |
| 422 | Prefix(prefix). |
| 423 | Desc(). |
| 424 | Limit(20). |
| 425 | FindAll(func(tx *kvstore.Tx[[]byte], item kvstore.Item[[]byte]) (goNext bool, err error) { |
| 426 | _, _, version, value, hash, decodeErr := DecodeValueKey(item.Key) |
| 427 | if decodeErr != nil { |
| 428 | return false, decodeErr |
| 429 | } |
| 430 | if value <= 0 { |
| 431 | return true, nil |
| 432 | } |
| 433 | |
| 434 | // value not changed for the key |
| 435 | if this.valuesCacheMap[hash] == value { |
| 436 | keepKeys = append(keepKeys, hash) |
| 437 | return true, nil |
| 438 | } |
| 439 | |
| 440 | newCachedKeys[hash] = value |
| 441 | |
| 442 | stat, valueErr := this.itemsTable.Get(string(byteutils.Concat([]byte(currentTime), []byte{'_'}, int32ToBigEndian(version), []byte(hash)))) |
| 443 | if valueErr != nil { |
| 444 | if kvstore.IsNotFound(valueErr) { |
| 445 | return true, nil |
| 446 | } |
| 447 | return false, valueErr |
| 448 | } |
| 449 | if stat == nil { |
| 450 | return true, nil |
| 451 | } |
| 452 | |
| 453 | pbStats = append(pbStats, &pb.UploadingMetricStat{ |
| 454 | Id: 0, // not used in node |
| 455 | Hash: hash, |
| 456 | Keys: stat.Keys, |
| 457 | Value: float32(value), |
| 458 | }) |
| 459 | |
| 460 | return true, nil |
| 461 | }) |
| 462 | if queryErr != nil { |
| 463 | return 0, queryErr |
| 464 | } |
| 465 | |
| 466 | // count & total |
| 467 | var count, total uint64 |
| 468 | { |
| 469 | sumValue, err := this.sumTable.Get(prefix) |
| 470 | if err != nil { |
| 471 | if kvstore.IsNotFound(err) { |
no test coverage detected