RescanBlocks returns a slice of append blocks from the wal folder
(additionalStartSlack time.Duration, log log.Logger)
| 77 | |
| 78 | // RescanBlocks returns a slice of append blocks from the wal folder |
| 79 | func (w *WAL) RescanBlocks(additionalStartSlack time.Duration, log log.Logger) ([]common.WALBlock, error) { |
| 80 | files, err := os.ReadDir(w.c.Filepath) |
| 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | |
| 85 | // For wal ownership, add Unsupported to the list at the end. |
| 86 | // It will catch any removed preview encodings. |
| 87 | encodings := append(encoding.AllEncodings(), unsupported.Encoding{}) |
| 88 | |
| 89 | blocks := make([]common.WALBlock, 0, len(files)) |
| 90 | for _, f := range files { |
| 91 | // find owner |
| 92 | var owner encoding.VersionedEncoding |
| 93 | for _, e := range encodings { |
| 94 | if e.OwnsWALBlock(f) { |
| 95 | owner = e |
| 96 | break |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if owner == nil { |
| 101 | level.Warn(log).Log("msg", "unowned file entry ignored during wal replay", "file", f.Name(), "err", err) |
| 102 | continue |
| 103 | } |
| 104 | |
| 105 | start := time.Now() |
| 106 | fileInfo, err := f.Info() |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | level.Info(log).Log("msg", "beginning replay", "file", f.Name(), "size", fileInfo.Size()) |
| 112 | b, warning, err := owner.OpenWALBlock(f.Name(), w.c.Filepath, w.c.IngestionSlack, additionalStartSlack) |
| 113 | |
| 114 | remove := false |
| 115 | if err != nil { |
| 116 | // wal replay failed, clear and warn |
| 117 | level.Warn(log).Log("msg", "failed to replay block. removing.", "file", f.Name(), "err", err) |
| 118 | remove = true |
| 119 | } |
| 120 | |
| 121 | if b != nil && b.DataLength() == 0 { |
| 122 | level.Warn(log).Log("msg", "empty wal file. ignoring.", "file", f.Name(), "err", err) |
| 123 | remove = true |
| 124 | } |
| 125 | |
| 126 | if warning != nil { |
| 127 | level.Warn(log).Log("msg", "received warning while replaying block. partial replay likely.", "file", f.Name(), "warning", warning, "length", b.DataLength()) |
| 128 | } |
| 129 | |
| 130 | if remove { |
| 131 | err = os.RemoveAll(filepath.Join(w.c.Filepath, f.Name())) |
| 132 | if err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | continue |
| 136 | } |