repair.go (etcd-3.5.6) | : | repair.go (etcd-3.5.7) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
// | // | |||
// Unless required by applicable law or agreed to in writing, software | // Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | // distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | |||
// limitations under the License. | // limitations under the License. | |||
package wal | package wal | |||
import ( | import ( | |||
"errors" | ||||
"io" | "io" | |||
"os" | "os" | |||
"path/filepath" | "path/filepath" | |||
"time" | "time" | |||
"go.etcd.io/etcd/client/pkg/v3/fileutil" | "go.etcd.io/etcd/client/pkg/v3/fileutil" | |||
"go.etcd.io/etcd/server/v3/wal/walpb" | "go.etcd.io/etcd/server/v3/wal/walpb" | |||
"go.uber.org/zap" | "go.uber.org/zap" | |||
) | ) | |||
skipping to change at line 47 | skipping to change at line 48 | |||
} | } | |||
defer f.Close() | defer f.Close() | |||
lg.Info("repairing", zap.String("path", f.Name())) | lg.Info("repairing", zap.String("path", f.Name())) | |||
rec := &walpb.Record{} | rec := &walpb.Record{} | |||
decoder := newDecoder(fileutil.NewFileReader(f.File)) | decoder := newDecoder(fileutil.NewFileReader(f.File)) | |||
for { | for { | |||
lastOffset := decoder.lastOffset() | lastOffset := decoder.lastOffset() | |||
err := decoder.decode(rec) | err := decoder.decode(rec) | |||
switch err { | switch { | |||
case nil: | case err == nil: | |||
// update crc of the decoder when necessary | // update crc of the decoder when necessary | |||
switch rec.Type { | switch rec.Type { | |||
case crcType: | case crcType: | |||
crc := decoder.crc.Sum32() | crc := decoder.crc.Sum32() | |||
// current crc of decoder must match the crc of t he record. | // current crc of decoder must match the crc of t he record. | |||
// do no need to match 0 crc, since the decoder i s a new one at this case. | // do no need to match 0 crc, since the decoder i s a new one at this case. | |||
if crc != 0 && rec.Validate(crc) != nil { | if crc != 0 && rec.Validate(crc) != nil { | |||
return false | return false | |||
} | } | |||
decoder.updateCRC(rec.Crc) | decoder.updateCRC(rec.Crc) | |||
} | } | |||
continue | continue | |||
case io.EOF: | case errors.Is(err, io.EOF): | |||
lg.Info("repaired", zap.String("path", f.Name()), zap.Err or(io.EOF)) | lg.Info("repaired", zap.String("path", f.Name()), zap.Err or(io.EOF)) | |||
return true | return true | |||
case io.ErrUnexpectedEOF: | case errors.Is(err, io.ErrUnexpectedEOF): | |||
bf, bferr := os.Create(f.Name() + ".broken") | bf, bferr := os.Create(f.Name() + ".broken") | |||
if bferr != nil { | if bferr != nil { | |||
lg.Warn("failed to create backup file", zap.Strin g("path", f.Name()+".broken"), zap.Error(bferr)) | lg.Warn("failed to create backup file", zap.Strin g("path", f.Name()+".broken"), zap.Error(bferr)) | |||
return false | return false | |||
} | } | |||
defer bf.Close() | defer bf.Close() | |||
if _, err = f.Seek(0, io.SeekStart); err != nil { | if _, err = f.Seek(0, io.SeekStart); err != nil { | |||
lg.Warn("failed to read file", zap.String("path", f.Name()), zap.Error(err)) | lg.Warn("failed to read file", zap.String("path", f.Name()), zap.Error(err)) | |||
return false | return false | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 5 lines changed or added |