mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

Prior to this CL, `ETCDCTL_API=2 etcdctl backup --with-v3` was readacting WAL log (by removal of some entries), but was NOT updating consistent_index in the backend. Also the WAL editing logic was buggy, as it didn't took in consideration the fact that when TERM changes, there can be entries with duplicated indexes in the log. So its NOT sufficient to subtract number of removed entries to get accurate log indexes. The PR replaces removing and shifting of WAL entries with replacing them with an no-op entries. Thanks to this consistent-index references are staying up to date. The PR also: - updates 'verification' logic to check whether consistent_index does not lag befor last snapshot - env-gated execution of verification framework in `etcdctl backup`. Tested with: ``` (./build.sh && cd tests && EXPECT_DEBUG=TRUE 'env' 'go' 'test' '-timeout=300m' 'go.etcd.io/etcd/tests/v3/e2e' -run=TestCtlV2Backup --count=1000 2>&1 | tee TestCtlV2BackupV3.log) ```
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
// Copyright 2015 The etcd Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package cindex
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
"go.etcd.io/etcd/server/v3/mvcc/backend"
|
|
betesting "go.etcd.io/etcd/server/v3/mvcc/backend/testing"
|
|
)
|
|
|
|
// TestConsistentIndex ensures that LoadConsistentIndex/Save/ConsistentIndex and backend.BatchTx can work well together.
|
|
func TestConsistentIndex(t *testing.T) {
|
|
|
|
be, tmpPath := betesting.NewTmpBackend(t, time.Microsecond, 10)
|
|
ci := NewConsistentIndex(be.BatchTx())
|
|
|
|
tx := be.BatchTx()
|
|
if tx == nil {
|
|
t.Fatal("batch tx is nil")
|
|
}
|
|
tx.Lock()
|
|
UnsafeCreateMetaBucket(tx)
|
|
tx.Unlock()
|
|
be.ForceCommit()
|
|
r := rand.Uint64()
|
|
ci.SetConsistentIndex(r)
|
|
index := ci.ConsistentIndex()
|
|
if index != r {
|
|
t.Errorf("expected %d,got %d", r, index)
|
|
}
|
|
tx.Lock()
|
|
ci.UnsafeSave(tx)
|
|
tx.Unlock()
|
|
be.ForceCommit()
|
|
be.Close()
|
|
|
|
b := backend.NewDefaultBackend(tmpPath)
|
|
defer b.Close()
|
|
ci.SetConsistentIndex(0)
|
|
ci.SetBatchTx(b.BatchTx())
|
|
index = ci.ConsistentIndex()
|
|
if index != r {
|
|
t.Errorf("expected %d,got %d", r, index)
|
|
}
|
|
|
|
ci = NewConsistentIndex(b.BatchTx())
|
|
index = ci.ConsistentIndex()
|
|
if index != r {
|
|
t.Errorf("expected %d,got %d", r, index)
|
|
}
|
|
}
|
|
|
|
func TestFakeConsistentIndex(t *testing.T) {
|
|
|
|
r := rand.Uint64()
|
|
ci := NewFakeConsistentIndex(r)
|
|
index := ci.ConsistentIndex()
|
|
if index != r {
|
|
t.Errorf("expected %d,got %d", r, index)
|
|
}
|
|
r = rand.Uint64()
|
|
ci.SetConsistentIndex(r)
|
|
index = ci.ConsistentIndex()
|
|
if index != r {
|
|
t.Errorf("expected %d,got %d", r, index)
|
|
}
|
|
|
|
}
|