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

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

Issue 1853433002: LogDog: Handle archive failures. (Closed) Base URL: https://github.com/luci/luci-go@logdog-gs-update
Patch Set: Regenerate protobufs. 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
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 coordinator 5 package coordinator
6 6
7 import ( 7 import (
8 "crypto/sha256" 8 "crypto/sha256"
9 "encoding/hex" 9 "encoding/hex"
10 "errors" 10 "errors"
(...skipping 14 matching lines...) Expand all
25 // LSPending indicates that no archival has occurred yet. 25 // LSPending indicates that no archival has occurred yet.
26 LSPending LogStreamState = iota 26 LSPending LogStreamState = iota
27 // LSTerminated indicates that the log stream has received a terminal in dex 27 // LSTerminated indicates that the log stream has received a terminal in dex
28 // and is awaiting archival. 28 // and is awaiting archival.
29 LSTerminated 29 LSTerminated
30 // LSArchived indicates that the log stream has been successfully archiv ed but 30 // LSArchived indicates that the log stream has been successfully archiv ed but
31 // has not yet been cleaned up. 31 // has not yet been cleaned up.
32 LSArchived 32 LSArchived
33 ) 33 )
34 34
35 // ArchiveState is the state of archival. It is valid on log streams whose
36 // log stream state is LSArchived.
37 type ArchiveState int
38
39 const (
40 // NotArchived is the default archive state, indicating that the log str eam is
41 // not archived.
42 NotArchived ArchiveState = iota
43 // Archived indicates that the log stream was archived completely and
44 // successfully.
45 Archived
46 // ArchivedPartially indicates that the log stream has been archived, bu t that
47 // there are missing log stream entries. This will happen when the strea m has
48 // exceeded an archival threshold without all of its log entries availab le
49 // in intermediate storage.
50 ArchivedPartially
51 // ArchivedWithErrors indicates that the log stream is in an archived st ate,
52 // but that there were errors. Archive files may be present in any state .
53 ArchivedWithErrors
54 )
55
35 // LogStream is the primary datastore model containing information and state of 56 // LogStream is the primary datastore model containing information and state of
36 // an individual log stream. 57 // an individual log stream.
37 // 58 //
38 // This structure contains the standard queryable fields, and is the source of 59 // This structure contains the standard queryable fields, and is the source of
39 // truth for log stream state. Writes to LogStream should be done via Put, which 60 // truth for log stream state. Writes to LogStream should be done via Put, which
40 // will ensure that the LogStream's related query objects are kept in sync. 61 // will ensure that the LogStream's related query objects are kept in sync.
41 // 62 //
42 // This structure has additional datastore fields imposed by the 63 // This structure has additional datastore fields imposed by the
43 // PropertyLoadSaver. These fields enable querying against some of the complex 64 // PropertyLoadSaver. These fields enable querying against some of the complex
44 // data types: 65 // data types:
(...skipping 13 matching lines...) Expand all
58 // - KEY=[VALUE] key/value tags. 79 // - KEY=[VALUE] key/value tags.
59 // - KEY key presence tags. 80 // - KEY key presence tags.
60 // 81 //
61 // - _Terminated is true if the LogStream has been terminated. 82 // - _Terminated is true if the LogStream has been terminated.
62 // - _Archived is true if the LogStream has been archived. 83 // - _Archived is true if the LogStream has been archived.
63 // 84 //
64 // Most of the values in QueryBase are static. Those that change can only be 85 // Most of the values in QueryBase are static. Those that change can only be
65 // changed through service endpoint methods. 86 // changed through service endpoint methods.
66 // 87 //
67 // LogStream's QueryBase is authortative. 88 // LogStream's QueryBase is authortative.
89 //
90 // TODO(dnj): Migration schema checklist. Next migration, we will want to...
91 // - Add schema version.
92 // - Remove State, ArchiveWhole in favor of "_Terminated" and "ArchiveState ".
68 type LogStream struct { 93 type LogStream struct {
69 // Prefix is this log stream's prefix value. Log streams with the same p refix 94 // Prefix is this log stream's prefix value. Log streams with the same p refix
70 // are logically grouped. 95 // are logically grouped.
71 Prefix string 96 Prefix string
72 // Name is the unique name of this log stream within the Prefix scope. 97 // Name is the unique name of this log stream within the Prefix scope.
73 Name string 98 Name string
74 99
75 // State is the log stream's current state. 100 // State is the log stream's current state.
76 State LogStreamState 101 State LogStreamState
77 102
(...skipping 29 matching lines...) Expand all
107 // can be queried against. 132 // can be queried against.
108 // 133 //
109 // The serialization/deserialization is handled manually in order to ena ble 134 // The serialization/deserialization is handled manually in order to ena ble
110 // key/value queries. 135 // key/value queries.
111 Tags TagMap `gae:"-"` 136 Tags TagMap `gae:"-"`
112 137
113 // Source is the set of source strings sent by the Butler. 138 // Source is the set of source strings sent by the Butler.
114 Source []string 139 Source []string
115 140
116 // TerminalIndex is the log stream index of the last log entry in the st ream. 141 // TerminalIndex is the log stream index of the last log entry in the st ream.
117 » // If the value is -1, the log is still streaming. 142 » //
143 » // When the value is <0:
144 » //» - If the log is not archived, this means that the stream is stil l
145 » //» streaming without a known terminal index.
146 » //» - If the log is archived, it means that the stream's archival ha s
147 » //» completed, but had no log entries.
118 TerminalIndex int64 `gae:",noindex"` 148 TerminalIndex int64 `gae:",noindex"`
119 149
120 // ArchiveIndexURL is the Google Storage URL where the log stream's inde x is 150 // ArchiveIndexURL is the Google Storage URL where the log stream's inde x is
121 // archived. 151 // archived.
122 ArchiveIndexURL string `gae:",noindex"` 152 ArchiveIndexURL string `gae:",noindex"`
123 // ArchiveIndexSize is the size, in bytes, of the archived Index. It wil l be 153 // ArchiveIndexSize is the size, in bytes, of the archived Index. It wil l be
124 // zero if the file is not archived. 154 // zero if the file is not archived.
125 ArchiveIndexSize int64 `gae:",noindex"` 155 ArchiveIndexSize int64 `gae:",noindex"`
126 // ArchiveStreamURL is the Google Storage URL where the log stream's raw 156 // ArchiveStreamURL is the Google Storage URL where the log stream's raw
127 // stream data is archived. If this is not empty, the log stream is cons idered 157 // stream data is archived. If this is not empty, the log stream is cons idered
128 // archived. 158 // archived.
129 ArchiveStreamURL string `gae:",noindex"` 159 ArchiveStreamURL string `gae:",noindex"`
130 // ArchiveStreamSize is the size, in bytes, of the archived stream. It w ill be 160 // ArchiveStreamSize is the size, in bytes, of the archived stream. It w ill be
131 // zero if the file is not archived. 161 // zero if the file is not archived.
132 ArchiveStreamSize int64 `gae:",noindex"` 162 ArchiveStreamSize int64 `gae:",noindex"`
133 // ArchiveDataURL is the Google Storage URL where the log stream's assem bled 163 // ArchiveDataURL is the Google Storage URL where the log stream's assem bled
134 // data is archived. If this is not empty, the log stream is considered 164 // data is archived. If this is not empty, the log stream is considered
135 // archived. 165 // archived.
136 ArchiveDataURL string `gae:",noindex"` 166 ArchiveDataURL string `gae:",noindex"`
137 // ArchiveDataSize is the size, in bytes, of the archived data. It will be 167 // ArchiveDataSize is the size, in bytes, of the archived data. It will be
138 // zero if the file is not archived. 168 // zero if the file is not archived.
139 ArchiveDataSize int64 `gae:",noindex"` 169 ArchiveDataSize int64 `gae:",noindex"`
140 // ArchiveWhole is true if archival is complete and the archived log str eam 170 // ArchiveWhole is true if archival is complete and the archived log str eam
141 // was not missing any entries. 171 // was not missing any entries.
172 //
173 // TODO(dnj): Next migration, deprecate this in favor of ArchiveState. F or
174 // now, we will parallel it.
142 ArchiveWhole bool 175 ArchiveWhole bool
176 // ArchiveState is the state of log stream archival.
177 ArchiveState ArchiveState
178 // ArchiveErrors is the number of errors encountered during archival. Th is
179 // will be incremented when incomplete archival is permitted, but the ar chival
180 // still failed due to an error (e.g., data corruption). If this exceeds a
181 // threshold, the stream may be marked archived even if the archival fai led.
182 ArchiveErrors int
143 183
144 // _ causes datastore to ignore unrecognized fields and strip them in fu ture 184 // _ causes datastore to ignore unrecognized fields and strip them in fu ture
145 // writes. 185 // writes.
146 _ ds.PropertyMap `gae:"-,extra"` 186 _ ds.PropertyMap `gae:"-,extra"`
147 187
148 // hashID is the cached generated ID from the stream's Prefix/Name field s. If 188 // hashID is the cached generated ID from the stream's Prefix/Name field s. If
149 // this is populated, ID metadata will be retrieved from this field inst ead of 189 // this is populated, ID metadata will be retrieved from this field inst ead of
150 // generated. 190 // generated.
151 hashID string 191 hashID string
152 } 192 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 return nil, err 386 return nil, err
347 } 387 }
348 return &pb, nil 388 return &pb, nil
349 } 389 }
350 390
351 // Terminated returns true if this stream has been terminated. 391 // Terminated returns true if this stream has been terminated.
352 func (s *LogStream) Terminated() bool { 392 func (s *LogStream) Terminated() bool {
353 return s.State >= LSTerminated 393 return s.State >= LSTerminated
354 } 394 }
355 395
356 // Archived returns true if this stream has been archived. A stream is archived 396 // Streaming returns true if this log stream is still streaming without a known
357 // if it has any of its archival properties set. 397 // terminal index.
398 func (s *LogStream) Streaming() bool {
399 » return (s.State == LSPending && s.TerminalIndex < 0)
400 }
401
402 // Archived returns true if this stream has been archived.
358 func (s *LogStream) Archived() bool { 403 func (s *LogStream) Archived() bool {
359 » return s.State >= LSArchived 404 » return (s.ArchiveState != NotArchived) || (s.State >= LSArchived)
360 } 405 }
361 406
362 // ArchiveMatches tests if the supplied Stream, Index, and Data archival URLs 407 // ArchiveMatches tests if the supplied Stream, Index, and Data archival URLs
363 // match the current values. 408 // match the current values.
364 func (s *LogStream) ArchiveMatches(sURL, iURL, dURL string) bool { 409 func (s *LogStream) ArchiveMatches(sURL, iURL, dURL string) bool {
365 return (s.ArchiveStreamURL == sURL && s.ArchiveIndexURL == iURL && s.Arc hiveDataURL == dURL) 410 return (s.ArchiveStreamURL == sURL && s.ArchiveIndexURL == iURL && s.Arc hiveDataURL == dURL)
366 } 411 }
367 412
368 // LoadDescriptor loads the fields in the log stream descriptor into this 413 // LoadDescriptor loads the fields in the log stream descriptor into this
369 // LogStream entry. These fields are: 414 // LogStream entry. These fields are:
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // were created before the supplied time. 619 // were created before the supplied time.
575 func AddOlderFilter(q *ds.Query, t time.Time) *ds.Query { 620 func AddOlderFilter(q *ds.Query, t time.Time) *ds.Query {
576 return q.Lt("Created", t.UTC()).Order("-Created") 621 return q.Lt("Created", t.UTC()).Order("-Created")
577 } 622 }
578 623
579 // AddNewerFilter adds a filter to queries that restricts them to results that 624 // AddNewerFilter adds a filter to queries that restricts them to results that
580 // were created after the supplied time. 625 // were created after the supplied time.
581 func AddNewerFilter(q *ds.Query, t time.Time) *ds.Query { 626 func AddNewerFilter(q *ds.Query, t time.Time) *ds.Query {
582 return q.Gt("Created", t.UTC()).Order("-Created") 627 return q.Gt("Created", t.UTC()).Order("-Created")
583 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698