...

Source file src/go.etcd.io/etcd/server/v3/wal/walpb/record.go

Documentation: go.etcd.io/etcd/server/v3/wal/walpb

     1  // Copyright 2015 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package walpb
    16  
    17  import "errors"
    18  
    19  var (
    20  	ErrCRCMismatch = errors.New("walpb: crc mismatch")
    21  )
    22  
    23  func (rec *Record) Validate(crc uint32) error {
    24  	if rec.Crc == crc {
    25  		return nil
    26  	}
    27  	rec.Reset()
    28  	return ErrCRCMismatch
    29  }
    30  
    31  // ValidateSnapshotForWrite ensures the Snapshot the newly written snapshot is valid.
    32  //
    33  // There might exist log-entries written by old etcd versions that does not conform
    34  // to the requirements.
    35  func ValidateSnapshotForWrite(e *Snapshot) error {
    36  	// Since etcd>=3.5.0
    37  	if e.ConfState == nil && e.Index > 0 {
    38  		return errors.New("Saved (not-initial) snapshot is missing ConfState: " + e.String())
    39  	}
    40  	return nil
    41  }
    42  

View as plain text