Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: appengine/logdog/coordinator/hierarchy/hierarchy.go

Issue 1883593005: LogDog: Only create missing hierarchy components. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package hierarchy 5 package hierarchy
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 10
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 if i == len(comps)-1 { 245 if i == len(comps)-1 {
246 // This is the stream component. 246 // This is the stream component.
247 cur.ID.stream = true 247 cur.ID.stream = true
248 } else { 248 } else {
249 prev = di.NewKey("_lsnc", cur.ID.id(), 0, prev) 249 prev = di.NewKey("_lsnc", cur.ID.id(), 0, prev)
250 } 250 }
251 251
252 components = append(components, &cur) 252 components = append(components, &cur)
253 } 253 }
254 » return di.PutMulti(components) 254
255 » // See if any components are already registered.
256 » exists := make([]*ds.Key, len(components))
257 » for i, c := range components {
258 » » exists[i] = di.KeyForObj(c)
259 » }
260 » bl, err := di.ExistsMulti(exists)
261 » if err != nil {
262 » » return err
263 » }
264
265 » // Only create entities that don't already exist.
266 » create := make([]*componentEntity, 0, len(components))
267 » for i, b := range bl {
268 » » if !b {
269 » » » create = append(create, components[i])
270 » » }
271 » }
272
273 » if len(create) > 0 {
274 » » if err := di.PutMulti(create); err != nil {
275 » » » return err
276 » » }
277 » }
278 » return nil
255 } 279 }
256 280
257 // MarkPurged sets the named path component's purged status to v. 281 // MarkPurged sets the named path component's purged status to v.
258 // 282 //
259 // MarkPurged will panic if any input data is invalid. It will only fail if 283 // MarkPurged will panic if any input data is invalid. It will only fail if
260 // datastore operations fail. 284 // datastore operations fail.
261 func MarkPurged(di ds.Interface, p types.StreamPath, v bool) error { 285 func MarkPurged(di ds.Interface, p types.StreamPath, v bool) error {
262 if err := p.Validate(); err != nil { 286 if err := p.Validate(); err != nil {
263 panic(p) 287 panic(p)
264 } 288 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return nil, err 450 return nil, err
427 } 451 }
428 return &l, nil 452 return &l, nil
429 } 453 }
430 454
431 // Root returns the datastore key for the hierarchy entity root. 455 // Root returns the datastore key for the hierarchy entity root.
432 func Root(di ds.Interface) *ds.Key { 456 func Root(di ds.Interface) *ds.Key {
433 k, _ := componentTokenKey(di, nil) 457 k, _ := componentTokenKey(di, nil)
434 return k 458 return k
435 } 459 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698