github.com/defanghe/fabric@v2.1.1+incompatible/core/ledger/pvtdatastorage/persistent_msgs_helper.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package pvtdatastorage 8 9 func newExpiryData() *ExpiryData { 10 return &ExpiryData{Map: make(map[string]*Collections)} 11 } 12 13 func (e *ExpiryData) getOrCreateCollections(ns string) *Collections { 14 collections, ok := e.Map[ns] 15 if !ok { 16 collections = &Collections{ 17 Map: make(map[string]*TxNums), 18 MissingDataMap: make(map[string]bool)} 19 e.Map[ns] = collections 20 } else { 21 // due to protobuf encoding/decoding, the previously 22 // initialized map could be a nil now due to 0 length. 23 // Hence, we need to reinitialize the map. 24 if collections.Map == nil { 25 collections.Map = make(map[string]*TxNums) 26 } 27 if collections.MissingDataMap == nil { 28 collections.MissingDataMap = make(map[string]bool) 29 } 30 } 31 return collections 32 } 33 34 func (e *ExpiryData) addPresentData(ns, coll string, txNum uint64) { 35 collections := e.getOrCreateCollections(ns) 36 37 txNums, ok := collections.Map[coll] 38 if !ok { 39 txNums = &TxNums{} 40 collections.Map[coll] = txNums 41 } 42 txNums.List = append(txNums.List, txNum) 43 } 44 45 func (e *ExpiryData) addMissingData(ns, coll string) { 46 collections := e.getOrCreateCollections(ns) 47 collections.MissingDataMap[coll] = true 48 } 49 50 func newCollElgInfo(nsCollMap map[string][]string) *CollElgInfo { 51 m := &CollElgInfo{NsCollMap: map[string]*CollNames{}} 52 for ns, colls := range nsCollMap { 53 collNames, ok := m.NsCollMap[ns] 54 if !ok { 55 collNames = &CollNames{} 56 m.NsCollMap[ns] = collNames 57 } 58 collNames.Entries = colls 59 } 60 return m 61 }