(store *raftwal.DiskStorage)
| 146 | } |
| 147 | |
| 148 | func overwriteSnapshot(store *raftwal.DiskStorage) error { |
| 149 | snap, err := store.Snapshot() |
| 150 | x.Checkf(err, "Unable to get snapshot") |
| 151 | cs := snap.Metadata.ConfState |
| 152 | fmt.Printf("Confstate: %+v\n", cs) |
| 153 | |
| 154 | var dsnap pb.Snapshot |
| 155 | if len(snap.Data) > 0 { |
| 156 | x.Check(proto.Unmarshal(snap.Data, &dsnap)) |
| 157 | } |
| 158 | fmt.Printf("Previous snapshot: %+v\n", dsnap) |
| 159 | |
| 160 | splits := strings.Split(opt.wsetSnapshot, ",") |
| 161 | x.AssertTruef(len(splits) == 3, |
| 162 | "Expected term,index,readts in string. Got: %s", splits) |
| 163 | term, err := strconv.Atoi(splits[0]) |
| 164 | x.Check(err) |
| 165 | index, err := strconv.Atoi(splits[1]) |
| 166 | x.Check(err) |
| 167 | readTs, err := strconv.Atoi(splits[2]) |
| 168 | x.Check(err) |
| 169 | |
| 170 | ent := raftpb.Entry{ |
| 171 | Term: uint64(term), |
| 172 | Index: uint64(index), |
| 173 | Type: raftpb.EntryNormal, |
| 174 | } |
| 175 | fmt.Printf("Using term: %d , index: %d , readTs : %d\n", term, index, readTs) |
| 176 | if dsnap.Index >= ent.Index { |
| 177 | fmt.Printf("Older snapshot is >= index %d", ent.Index) |
| 178 | return nil |
| 179 | } |
| 180 | |
| 181 | // We need to write the Raft entry first. |
| 182 | fmt.Printf("Setting entry: %+v\n", ent) |
| 183 | hs := raftpb.HardState{ |
| 184 | Term: ent.Term, |
| 185 | Commit: ent.Index, |
| 186 | } |
| 187 | fmt.Printf("Setting hard state: %+v\n", hs) |
| 188 | err = store.Save(&hs, []raftpb.Entry{ent}, &snap) |
| 189 | x.Check(err) |
| 190 | |
| 191 | dsnap.Index = ent.Index |
| 192 | dsnap.ReadTs = uint64(readTs) |
| 193 | |
| 194 | fmt.Printf("Setting snapshot to: %+v\n", dsnap) |
| 195 | data, err := proto.Marshal(&dsnap) |
| 196 | x.Check(err) |
| 197 | if err = store.CreateSnapshot(dsnap.Index, &cs, data); err != nil { |
| 198 | fmt.Printf("Created snapshot with error: %v\n", err) |
| 199 | } |
| 200 | return err |
| 201 | } |
| 202 | |
| 203 | func handleWal(store *raftwal.DiskStorage) error { |
| 204 | rid := store.Uint(raftwal.RaftId) |
no test coverage detected