forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 3
/
persistent_msgs_helper.go
61 lines (53 loc) · 1.51 KB
/
persistent_msgs_helper.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
61
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pvtdatastorage
func newExpiryData() *ExpiryData {
return &ExpiryData{Map: make(map[string]*Collections)}
}
func (e *ExpiryData) getOrCreateCollections(ns string) *Collections {
collections, ok := e.Map[ns]
if !ok {
collections = &Collections{
Map: make(map[string]*TxNums),
MissingDataMap: make(map[string]bool)}
e.Map[ns] = collections
} else {
// due to protobuf encoding/decoding, the previously
// initialized map could be a nil now due to 0 length.
// Hence, we need to reinitialize the map.
if collections.Map == nil {
collections.Map = make(map[string]*TxNums)
}
if collections.MissingDataMap == nil {
collections.MissingDataMap = make(map[string]bool)
}
}
return collections
}
func (e *ExpiryData) addPresentData(ns, coll string, txNum uint64) {
collections := e.getOrCreateCollections(ns)
txNums, ok := collections.Map[coll]
if !ok {
txNums = &TxNums{}
collections.Map[coll] = txNums
}
txNums.List = append(txNums.List, txNum)
}
func (e *ExpiryData) addMissingData(ns, coll string) {
collections := e.getOrCreateCollections(ns)
collections.MissingDataMap[coll] = true
}
func newCollElgInfo(nsCollMap map[string][]string) *CollElgInfo {
m := &CollElgInfo{NsCollMap: map[string]*CollNames{}}
for ns, colls := range nsCollMap {
collNames, ok := m.NsCollMap[ns]
if !ok {
collNames = &CollNames{}
m.NsCollMap[ns] = collNames
}
collNames.Entries = colls
}
return m
}