milvus/internal/storage/stats.go
Xiangyu Wang 23c4de0eb8
Flush statistics for all int64 fields (#5318)
Resolves: #5262

Signed-off-by: Xiangyu Wang <xiangyu.wang@zilliz.com>
2021-05-20 10:38:45 +00:00

63 lines
1.4 KiB
Go

// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
package storage
import (
"encoding/json"
)
type Int64Stats struct {
Max int64 `json:"max"`
Min int64 `json:"min"`
}
type StatsWriter struct {
buffer []byte
}
func (sw *StatsWriter) GetBuffer() []byte {
return sw.buffer
}
func (sw *StatsWriter) StatsInt64(msgs []int64) error {
if len(msgs) < 1 {
// return error: msgs must has one element at least
return nil
}
stats := &Int64Stats{
Max: msgs[len(msgs)-1],
Min: msgs[0],
}
b, err := json.Marshal(stats)
if err != nil {
return err
}
sw.buffer = b
return nil
}
type StatsReader struct {
buffer []byte
}
func (sr *StatsReader) SetBuffer(buffer []byte) {
sr.buffer = buffer
}
func (sr *StatsReader) GetInt64Stats() Int64Stats {
stats := Int64Stats{}
json.Unmarshal(sr.buffer, &stats)
return stats
}