WIP: Add metadata to store record (#1604)
* Add metadata to store record * Add metadata to cockroach store * add metadata to store service implementation * fix breaking cache test * Test/fix cockroach metadata usage * fix store memory metadata bug
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: store/service/proto/store.proto
|
||||
// source: github.com/micro/go-micro/store/service/proto/store.proto
|
||||
|
||||
package go_micro_store
|
||||
|
||||
|
@@ -11,6 +11,13 @@ service Store {
|
||||
rpc Tables(TablesRequest) returns (TablesResponse) {};
|
||||
}
|
||||
|
||||
message Field {
|
||||
// type of value e.g string, int, int64, bool, float64
|
||||
string type = 1;
|
||||
// the actual value
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message Record {
|
||||
// key of the record
|
||||
string key = 1;
|
||||
@@ -18,6 +25,8 @@ message Record {
|
||||
bytes value = 2;
|
||||
// time.Duration (signed int64 nanoseconds)
|
||||
int64 expiry = 3;
|
||||
// the associated metadata
|
||||
map<string,Field> metadata = 4;
|
||||
}
|
||||
|
||||
message ReadOptions {
|
||||
|
@@ -3,7 +3,9 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
@@ -137,10 +139,21 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco
|
||||
records := make([]*store.Record, 0, len(rsp.Records))
|
||||
|
||||
for _, val := range rsp.Records {
|
||||
metadata := make(map[string]interface{})
|
||||
|
||||
for k, v := range val.Metadata {
|
||||
switch v.Type {
|
||||
// TODO: parse all types
|
||||
default:
|
||||
metadata[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
records = append(records, &store.Record{
|
||||
Key: val.Key,
|
||||
Value: val.Value,
|
||||
Expiry: time.Duration(val.Expiry) * time.Second,
|
||||
Key: val.Key,
|
||||
Value: val.Value,
|
||||
Expiry: time.Duration(val.Expiry) * time.Second,
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -163,11 +176,21 @@ func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) er
|
||||
Table: options.Table,
|
||||
}
|
||||
|
||||
metadata := make(map[string]*pb.Field)
|
||||
|
||||
for k, v := range record.Metadata {
|
||||
metadata[k] = &pb.Field{
|
||||
Type: reflect.TypeOf(v).String(),
|
||||
Value: fmt.Sprintf("%v", v),
|
||||
}
|
||||
}
|
||||
|
||||
_, err := s.Client.Write(s.Context(), &pb.WriteRequest{
|
||||
Record: &pb.Record{
|
||||
Key: record.Key,
|
||||
Value: record.Value,
|
||||
Expiry: int64(record.Expiry.Seconds()),
|
||||
Key: record.Key,
|
||||
Value: record.Value,
|
||||
Expiry: int64(record.Expiry.Seconds()),
|
||||
Metadata: metadata,
|
||||
},
|
||||
Options: writeOpts}, client.WithAddress(s.Nodes...))
|
||||
if err != nil && errors.Equal(err, errors.NotFound("", "")) {
|
||||
|
Reference in New Issue
Block a user