2020-07-29 04:31:46 +00:00
|
|
|
package remotedbserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2021-03-19 21:24:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/gointerfaces/remote"
|
2020-07-29 04:31:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DBServer struct {
|
2020-10-24 06:54:03 +00:00
|
|
|
remote.UnimplementedDBServer // must be embedded to have forward compatible implementations.
|
2020-07-29 04:31:46 +00:00
|
|
|
|
|
|
|
kv ethdb.KV
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDBServer(kv ethdb.KV) *DBServer {
|
|
|
|
return &DBServer{kv: kv}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DBServer) Size(ctx context.Context, in *remote.SizeRequest) (*remote.SizeReply, error) {
|
|
|
|
sz, err := s.kv.(ethdb.HasStats).DiskSize(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &remote.SizeReply{Size: sz}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DBServer) BucketSize(ctx context.Context, in *remote.BucketSizeRequest) (*remote.BucketSizeReply, error) {
|
|
|
|
out := &remote.BucketSizeReply{}
|
|
|
|
if err := s.kv.View(ctx, func(tx ethdb.Tx) error {
|
2020-08-17 07:24:59 +00:00
|
|
|
sz, err := tx.BucketSize(in.BucketName)
|
2020-07-29 04:31:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out.Size = sz
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|