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

Unified Diff: logdog/common/storage/archive/logdog_archive_test/main.go

Issue 2435883002: LogDog: Fix archival Get/Tail implementations. (Closed)
Patch Set: LogDog: Fix archival Get/Tail implementations. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: logdog/common/storage/archive/logdog_archive_test/main.go
diff --git a/logdog/common/storage/archive/logdog_archive_test/main.go b/logdog/common/storage/archive/logdog_archive_test/main.go
index 5ed39d95a12fc947a46a4fafbecf4c8f8eea65df..471cad5208f7fc5d7a723f7b21e7a66eed620809 100644
--- a/logdog/common/storage/archive/logdog_archive_test/main.go
+++ b/logdog/common/storage/archive/logdog_archive_test/main.go
@@ -175,10 +175,13 @@ func (cmd *cmdRunDumpIndex) Run(baseApp subcommands.Application, args []string)
}
func unmarshalAndDump(c context.Context, out io.Writer, data []byte, msg proto.Message) error {
- if err := proto.Unmarshal(data, msg); err != nil {
- log.WithError(err).Errorf(c, "Failed to unmarshal protobuf.")
- return err
+ if data != nil {
+ if err := proto.Unmarshal(data, msg); err != nil {
+ log.WithError(err).Errorf(c, "Failed to unmarshal protobuf.")
+ return err
+ }
}
+
if err := proto.MarshalText(out, msg); err != nil {
log.WithError(err).Errorf(c, "Failed to dump protobuf to output.")
return err
@@ -347,13 +350,18 @@ func (cmd *cmdRunGet) Run(baseApp subcommands.Application, args []string) int {
err = stClient.Get(storage.GetRequest{
Index: types.MessageIndex(cmd.index),
Limit: cmd.limit,
- }, func(idx types.MessageIndex, data []byte) bool {
+ }, func(e *storage.Entry) bool {
+ le, err := e.GetLogEntry()
+ if err != nil {
+ log.WithError(err).Errorf(c, "Failed to unmarshal log entry.")
+ return false
+ }
+
log.Fields{
- "index": idx,
+ "index": le.StreamIndex,
}.Infof(c, "Fetched log entry.")
- var log logpb.LogEntry
- if innerErr = unmarshalAndDump(c, os.Stdout, data, &log); innerErr != nil {
+ if innerErr = unmarshalAndDump(c, os.Stdout, nil, le); innerErr != nil {
return false
}
return true
@@ -426,23 +434,28 @@ func (cmd *cmdRunTail) Run(baseApp subcommands.Application, args []string) int {
}
defer stClient.Close()
- data, idx, err := stClient.Tail("", "")
+ e, err := stClient.Tail("", "")
if err != nil {
log.WithError(err).Errorf(c, "Failed to Tail log entries.")
return 1
}
- if data == nil {
+ if e == nil {
log.Infof(c, "No log data to tail.")
return 0
}
+ le, err := e.GetLogEntry()
+ if err != nil {
+ log.WithError(err).Errorf(c, "Failed to unmarshal log entry.")
+ return 1
+ }
+
log.Fields{
- "index": idx,
- "size": len(data),
+ "index": le.StreamIndex,
+ "size": len(e.D),
}.Debugf(c, "Dumping tail entry.")
- var entry logpb.LogEntry
- if err := unmarshalAndDump(c, os.Stdout, data, &entry); err != nil {
+ if err := unmarshalAndDump(c, os.Stdout, nil, le); err != nil {
log.WithError(err).Errorf(c, "Failed to dump tail entry.")
return 1
}

Powered by Google App Engine
This is Rietveld 408576698