Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "bytes" |
| 20 | "crypto/md5" |
| 21 | "fmt" |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 22 | "github.com/golang/protobuf/proto" |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 23 | "github.com/opencord/voltha-go/common/log" |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 24 | "reflect" |
| 25 | "sort" |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 26 | "sync" |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 27 | ) |
| 28 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 29 | type revCacheSingleton struct { |
| 30 | sync.RWMutex |
| 31 | Cache map[string]interface{} |
| 32 | } |
| 33 | |
| 34 | var revCacheInstance *revCacheSingleton |
| 35 | var revCacheOnce sync.Once |
| 36 | |
| 37 | func GetRevCache() *revCacheSingleton { |
| 38 | revCacheOnce.Do(func() { |
| 39 | revCacheInstance = &revCacheSingleton{Cache: make(map[string]interface{})} |
| 40 | }) |
| 41 | return revCacheInstance |
| 42 | } |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 43 | |
| 44 | type NonPersistedRevision struct { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 45 | mutex sync.RWMutex |
| 46 | Root *root |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 47 | Config *DataRevision |
| 48 | Children map[string][]Revision |
| 49 | Hash string |
| 50 | Branch *Branch |
| 51 | WeakRef string |
| 52 | } |
| 53 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 54 | func NewNonPersistedRevision(root *root, branch *Branch, data interface{}, children map[string][]Revision) Revision { |
| 55 | r := &NonPersistedRevision{} |
| 56 | r.Root = root |
| 57 | r.Branch = branch |
| 58 | r.Config = NewDataRevision(root, data) |
| 59 | r.Children = children |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 60 | return r |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | func (npr *NonPersistedRevision) SetConfig(config *DataRevision) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 64 | npr.mutex.Lock() |
| 65 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 66 | npr.Config = config |
| 67 | } |
| 68 | |
| 69 | func (npr *NonPersistedRevision) GetConfig() *DataRevision { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 70 | npr.mutex.Lock() |
| 71 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 72 | return npr.Config |
| 73 | } |
| 74 | |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 75 | func (npr *NonPersistedRevision) SetAllChildren(children map[string][]Revision) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 76 | npr.mutex.Lock() |
| 77 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 78 | npr.Children = children |
| 79 | } |
| 80 | |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 81 | func (npr *NonPersistedRevision) SetChildren(name string, children []Revision) { |
| 82 | npr.mutex.Lock() |
| 83 | defer npr.mutex.Unlock() |
| 84 | if _, exists := npr.Children[name]; exists { |
| 85 | npr.Children[name] = children |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func (npr *NonPersistedRevision) GetAllChildren() map[string][]Revision { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 90 | npr.mutex.Lock() |
| 91 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 92 | return npr.Children |
| 93 | } |
| 94 | |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 95 | func (npr *NonPersistedRevision) GetChildren(name string) []Revision { |
| 96 | npr.mutex.Lock() |
| 97 | defer npr.mutex.Unlock() |
| 98 | if _, exists := npr.Children[name]; exists { |
| 99 | return npr.Children[name] |
| 100 | } |
| 101 | return nil |
| 102 | } |
| 103 | |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 104 | func (npr *NonPersistedRevision) SetHash(hash string) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 105 | npr.mutex.Lock() |
| 106 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 107 | npr.Hash = hash |
| 108 | } |
| 109 | |
| 110 | func (npr *NonPersistedRevision) GetHash() string { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 111 | //npr.mutex.Lock() |
| 112 | //defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 113 | return npr.Hash |
| 114 | } |
| 115 | |
| 116 | func (npr *NonPersistedRevision) ClearHash() { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 117 | npr.mutex.Lock() |
| 118 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 119 | npr.Hash = "" |
| 120 | } |
| 121 | |
| 122 | func (npr *NonPersistedRevision) SetBranch(branch *Branch) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 123 | npr.mutex.Lock() |
| 124 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 125 | npr.Branch = branch |
| 126 | } |
| 127 | |
| 128 | func (npr *NonPersistedRevision) GetBranch() *Branch { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 129 | npr.mutex.Lock() |
| 130 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 131 | return npr.Branch |
| 132 | } |
| 133 | |
| 134 | func (npr *NonPersistedRevision) GetData() interface{} { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 135 | npr.mutex.Lock() |
| 136 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 137 | if npr.Config == nil { |
| 138 | return nil |
| 139 | } |
| 140 | return npr.Config.Data |
| 141 | } |
| 142 | |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 143 | func (npr *NonPersistedRevision) GetNode() *node { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 144 | npr.mutex.Lock() |
| 145 | defer npr.mutex.Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 146 | return npr.Branch.Node |
| 147 | } |
| 148 | |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 149 | func (npr *NonPersistedRevision) Finalize(skipOnExist bool) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 150 | GetRevCache().Lock() |
| 151 | defer GetRevCache().Unlock() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 152 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 153 | if !skipOnExist { |
| 154 | npr.Hash = npr.hashContent() |
| 155 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 156 | if _, exists := GetRevCache().Cache[npr.Hash]; !exists { |
| 157 | GetRevCache().Cache[npr.Hash] = npr |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 158 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 159 | if _, exists := GetRevCache().Cache[npr.Config.Hash]; !exists { |
| 160 | GetRevCache().Cache[npr.Config.Hash] = npr.Config |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 161 | } else { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 162 | npr.Config = GetRevCache().Cache[npr.Config.Hash].(*DataRevision) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | func (npr *NonPersistedRevision) hashContent() string { |
| 167 | var buffer bytes.Buffer |
| 168 | var childrenKeys []string |
| 169 | |
| 170 | if npr.Config != nil { |
| 171 | buffer.WriteString(npr.Config.Hash) |
| 172 | } |
| 173 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 174 | for key := range npr.Children { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 175 | childrenKeys = append(childrenKeys, key) |
| 176 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 177 | |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 178 | sort.Strings(childrenKeys) |
| 179 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 180 | if len(npr.Children) > 0 { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 181 | // Loop through sorted Children keys |
| 182 | for _, key := range childrenKeys { |
| 183 | for _, child := range npr.Children[key] { |
| 184 | if child != nil && child.GetHash() != "" { |
| 185 | buffer.WriteString(child.GetHash()) |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | return fmt.Sprintf("%x", md5.Sum(buffer.Bytes()))[:12] |
| 192 | } |
| 193 | |
| 194 | func (npr *NonPersistedRevision) Get(depth int) interface{} { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 195 | // 1. Clone the data to avoid any concurrent access issues |
| 196 | // 2. The current rev might still be pointing to an old config |
| 197 | // thus, force the revision to get its latest value |
| 198 | latestRev := npr.GetBranch().GetLatest() |
| 199 | originalData := proto.Clone(latestRev.GetData().(proto.Message)) |
| 200 | |
| 201 | data := originalData |
| 202 | // Get back to the interface type |
| 203 | //data := reflect.ValueOf(originalData).Interface() |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 204 | |
| 205 | if depth != 0 { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 206 | for fieldName, field := range ChildrenFields(latestRev.GetData()) { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 207 | childDataName, childDataHolder := GetAttributeValue(data, fieldName, 0) |
| 208 | if field.IsContainer { |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 209 | for _, rev := range latestRev.GetChildren(fieldName) { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 210 | childData := rev.Get(depth - 1) |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 211 | foundEntry := false |
| 212 | for i := 0; i < childDataHolder.Len(); i++ { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 213 | cdh_if := childDataHolder.Index(i).Interface() |
| 214 | if cdh_if.(proto.Message).String() == childData.(proto.Message).String() { |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 215 | foundEntry = true |
| 216 | break |
| 217 | } |
| 218 | } |
| 219 | if !foundEntry { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 220 | // avoid duplicates by adding it only if the child was not found in the holder |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 221 | childDataHolder = reflect.Append(childDataHolder, reflect.ValueOf(childData)) |
| 222 | } |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 223 | } |
| 224 | } else { |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 225 | if revs := latestRev.GetChildren(fieldName); revs != nil && len(revs) > 0 { |
| 226 | rev := latestRev.GetChildren(fieldName)[0] |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 227 | if rev != nil { |
| 228 | childData := rev.Get(depth - 1) |
| 229 | if reflect.TypeOf(childData) == reflect.TypeOf(childDataHolder.Interface()) { |
| 230 | childDataHolder = reflect.ValueOf(childData) |
| 231 | } |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 232 | } |
| 233 | } |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 234 | } |
| 235 | // Merge child data with cloned object |
| 236 | reflect.ValueOf(data).Elem().FieldByName(childDataName).Set(childDataHolder) |
| 237 | } |
| 238 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 239 | |
| 240 | result := data |
| 241 | |
| 242 | if result != nil { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 243 | // We need to send back a copy of the retrieved object |
| 244 | result = proto.Clone(data.(proto.Message)) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return result |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | func (npr *NonPersistedRevision) UpdateData(data interface{}, branch *Branch) Revision { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 251 | npr.mutex.Lock() |
| 252 | defer npr.mutex.Unlock() |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 253 | |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 254 | if npr.Config.Data != nil && npr.Config.hashData(npr.Root, data) == npr.Config.Hash { |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 255 | log.Debugw("stored-data-matches-latest", log.Fields{"stored": npr.Config.Data, "provided": data}) |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 256 | return npr |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 257 | } |
| 258 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 259 | newRev := NonPersistedRevision{} |
| 260 | newRev.Config = NewDataRevision(npr.Root, data) |
| 261 | newRev.Hash = npr.Hash |
| 262 | newRev.Branch = branch |
| 263 | |
| 264 | newRev.Children = make(map[string][]Revision) |
| 265 | for entryName, childrenEntry := range npr.Children { |
| 266 | newRev.Children[entryName] = append(newRev.Children[entryName], childrenEntry...) |
| 267 | } |
| 268 | |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 269 | newRev.Finalize(false) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 270 | |
| 271 | return &newRev |
| 272 | } |
| 273 | |
| 274 | func (npr *NonPersistedRevision) UpdateChildren(name string, children []Revision, branch *Branch) Revision { |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 275 | npr.mutex.Lock() |
| 276 | defer npr.mutex.Unlock() |
| 277 | |
| 278 | updatedRev := npr |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 279 | |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 280 | // Verify if the map contains already contains an entry matching the name value |
| 281 | // If so, we need to retain the contents of that entry and merge them with the provided children revision list |
| 282 | if _, exists := updatedRev.Children[name]; exists { |
| 283 | // Go through all child hashes and save their index within the map |
| 284 | existChildMap := make(map[string]int) |
| 285 | for i, child := range updatedRev.Children[name] { |
| 286 | existChildMap[child.GetHash()] = i |
| 287 | } |
| 288 | |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 289 | for _, newChild := range children { |
| 290 | if _, childExists := existChildMap[newChild.GetHash()]; !childExists { |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 291 | // revision is not present in the existing list... add it |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 292 | updatedRev.Children[name] = append(updatedRev.Children[name], newChild) |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 293 | } else { |
| 294 | // replace |
| 295 | updatedRev.Children[name][existChildMap[newChild.GetHash()]] = newChild |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | } else { |
| 299 | // Map entry does not exist, thus just create a new entry and assign the provided revisions |
| 300 | updatedRev.Children[name] = make([]Revision, len(children)) |
| 301 | copy(updatedRev.Children[name], children) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Stephane Barbarie | 933b09b | 2019-01-09 11:12:09 -0500 | [diff] [blame] | 304 | updatedRev.Config = NewDataRevision(npr.Root, npr.Config.Data) |
| 305 | updatedRev.Hash = npr.Hash |
| 306 | updatedRev.Branch = branch |
| 307 | updatedRev.Finalize(false) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 308 | |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 309 | return updatedRev |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | func (npr *NonPersistedRevision) UpdateAllChildren(children map[string][]Revision, branch *Branch) Revision { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 313 | npr.mutex.Lock() |
| 314 | defer npr.mutex.Unlock() |
| 315 | |
| 316 | newRev := &NonPersistedRevision{} |
| 317 | newRev.Config = npr.Config |
| 318 | newRev.Hash = npr.Hash |
| 319 | newRev.Branch = branch |
| 320 | newRev.Children = make(map[string][]Revision) |
| 321 | for entryName, childrenEntry := range npr.Children { |
| 322 | newRev.Children[entryName] = make([]Revision, len(childrenEntry)) |
| 323 | copy(newRev.Children[entryName], childrenEntry) |
| 324 | } |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 325 | newRev.Finalize(false) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 326 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 327 | return newRev |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 328 | } |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 329 | |
| 330 | func (npr *NonPersistedRevision) Drop(txid string, includeConfig bool) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 331 | GetRevCache().Lock() |
| 332 | defer GetRevCache().Unlock() |
| 333 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 334 | if includeConfig { |
| 335 | delete(GetRevCache().Cache, npr.Config.Hash) |
| 336 | } |
| 337 | delete(GetRevCache().Cache, npr.Hash) |
Stephane Barbarie | 88fbe7f | 2018-09-25 12:25:23 -0400 | [diff] [blame] | 338 | } |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 339 | |
| 340 | func (npr *NonPersistedRevision) LoadFromPersistence(path string, txid string) []Revision { |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 341 | // stub... required by interface |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 342 | return nil |
| 343 | } |
Stephane Barbarie | e0a4c79 | 2019-01-16 11:26:29 -0500 | [diff] [blame] | 344 | |
| 345 | func (npr *NonPersistedRevision) SetupWatch(key string) { |
| 346 | // stub ... required by interface |
| 347 | } |