| OLD | NEW |
| 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 services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/subtle" | 8 "crypto/subtle" |
| 9 | 9 |
| 10 ds "github.com/luci/gae/service/datastore" | 10 ds "github.com/luci/gae/service/datastore" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 if req.TerminalIndex < 0 { | 32 if req.TerminalIndex < 0 { |
| 33 return nil, grpcutil.Errf(codes.InvalidArgument, "Negative termi
nal index.") | 33 return nil, grpcutil.Errf(codes.InvalidArgument, "Negative termi
nal index.") |
| 34 } | 34 } |
| 35 | 35 |
| 36 id := coordinator.HashID(req.Id) | 36 id := coordinator.HashID(req.Id) |
| 37 if err := id.Normalize(); err != nil { | 37 if err := id.Normalize(); err != nil { |
| 38 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid ID (%s
): %s", id, err) | 38 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid ID (%s
): %s", id, err) |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Load our service and project configs. |
| 41 svc := coordinator.GetServices(c) | 42 svc := coordinator.GetServices(c) |
| 42 cfg, err := svc.Config(c) | 43 cfg, err := svc.Config(c) |
| 43 if err != nil { | 44 if err != nil { |
| 44 log.WithError(err).Errorf(c, "Failed to load configuration.") | 45 log.WithError(err).Errorf(c, "Failed to load configuration.") |
| 45 return nil, grpcutil.Internal | 46 return nil, grpcutil.Internal |
| 46 } | 47 } |
| 47 | 48 |
| 49 pcfg, err := coordinator.CurrentProjectConfig(c) |
| 50 if err != nil { |
| 51 log.WithError(err).Errorf(c, "Failed to load current project con
figuration.") |
| 52 return nil, grpcutil.Internal |
| 53 } |
| 54 |
| 55 // Initialize our archival parameters. |
| 56 params := coordinator.ArchivalParams{ |
| 57 RequestID: info.Get(c).RequestID(), |
| 58 SettleDelay: cfg.Coordinator.ArchiveSettleDelay.Duration(), |
| 59 CompletePeriod: resolveArchiveDelay(cfg.Coordinator, pcfg), |
| 60 } |
| 61 |
| 48 ap, err := svc.ArchivalPublisher(c) | 62 ap, err := svc.ArchivalPublisher(c) |
| 49 if err != nil { | 63 if err != nil { |
| 50 log.WithError(err).Errorf(c, "Failed to get archival publisher i
nstance.") | 64 log.WithError(err).Errorf(c, "Failed to get archival publisher i
nstance.") |
| 51 return nil, grpcutil.Internal | 65 return nil, grpcutil.Internal |
| 52 } | 66 } |
| 53 | 67 |
| 54 // Initialize our log stream state. | 68 // Initialize our log stream state. |
| 55 di := ds.Get(c) | 69 di := ds.Get(c) |
| 56 lst := coordinator.NewLogStreamState(di, id) | 70 lst := coordinator.NewLogStreamState(di, id) |
| 57 | 71 |
| 58 // Initialize our archival parameters. | |
| 59 params := coordinator.ArchivalParams{ | |
| 60 RequestID: info.Get(c).RequestID(), | |
| 61 SettleDelay: cfg.Coordinator.ArchiveSettleDelay.Duration(), | |
| 62 CompletePeriod: cfg.Coordinator.ArchiveDelayMax.Duration(), | |
| 63 } | |
| 64 | |
| 65 // Transactionally validate and update the terminal index. | 72 // Transactionally validate and update the terminal index. |
| 66 err = di.RunInTransaction(func(c context.Context) error { | 73 err = di.RunInTransaction(func(c context.Context) error { |
| 67 di := ds.Get(c) | 74 di := ds.Get(c) |
| 68 | 75 |
| 69 if err := di.Get(lst); err != nil { | 76 if err := di.Get(lst); err != nil { |
| 70 if err == ds.ErrNoSuchEntity { | 77 if err == ds.ErrNoSuchEntity { |
| 71 log.Debugf(c, "Log stream state not found.") | 78 log.Debugf(c, "Log stream state not found.") |
| 72 return grpcutil.Errf(codes.NotFound, "Log stream
%q is not registered", id) | 79 return grpcutil.Errf(codes.NotFound, "Log stream
%q is not registered", id) |
| 73 } | 80 } |
| 74 | 81 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 }, nil) | 143 }, nil) |
| 137 if err != nil { | 144 if err != nil { |
| 138 log.Fields{ | 145 log.Fields{ |
| 139 log.ErrorKey: err, | 146 log.ErrorKey: err, |
| 140 }.Errorf(c, "Failed to update LogStream.") | 147 }.Errorf(c, "Failed to update LogStream.") |
| 141 return nil, err | 148 return nil, err |
| 142 } | 149 } |
| 143 | 150 |
| 144 return &google.Empty{}, nil | 151 return &google.Empty{}, nil |
| 145 } | 152 } |
| OLD | NEW |