-
Notifications
You must be signed in to change notification settings - Fork 30
/
process_put.go
60 lines (44 loc) · 1.14 KB
/
process_put.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package store
import (
"time"
"github.com/chrislusf/glog"
"github.com/chrislusf/vasto/pb"
"github.com/chrislusf/vasto/storage/codec"
)
func (ss *storeServer) processPut(shard *shard, putRequest *pb.PutRequest) *pb.WriteResponse {
key := putRequest.Key
nowInNano := putRequest.UpdatedAtNs
if nowInNano == 0 {
nowInNano = uint64(time.Now().UnixNano())
}
entry := codec.NewPutEntry(putRequest, nowInNano)
resp := &pb.WriteResponse{
Ok: true,
}
// glog.V(2).Infof"shard %d put key: %v\n", shard.id, string(putRequest.KeyValue.Key))
err := shard.db.Put(key, entry.ToBytes())
if err != nil {
resp.Ok = false
resp.Status = err.Error()
} else {
if !*ss.option.DisableBinLog {
shard.logPut(putRequest, nowInNano)
}
}
return resp
}
func (s *shard) logPut(putRequest *pb.PutRequest, updatedAtNs uint64) {
// println("logPut1", putRequest.String())
if s.lm == nil {
return
}
// println("logPut2", putRequest.String())
err := s.lm.AppendEntry(&pb.LogEntry{
UpdatedAtNs: updatedAtNs,
Put: putRequest,
})
if err != nil {
glog.Errorf("append put log entry: %v", err)
}
// println("logPut3", putRequest.String())
}