mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Cleanup references to bucket module
This commit is contained in:
parent
a1fd98c6b0
commit
a97e48e08d
@ -931,8 +931,8 @@ func NewAuthStore(lg *zap.Logger, be backend.Backend, tp TokenProvider, bcryptCo
|
|||||||
tx.Lock()
|
tx.Lock()
|
||||||
|
|
||||||
schema.UnsafeCreateAuthBucket(tx)
|
schema.UnsafeCreateAuthBucket(tx)
|
||||||
tx.UnsafeCreateBucket(schema.AuthUsers)
|
schema.UnsafeCreateAuthUsersBucket(tx)
|
||||||
tx.UnsafeCreateBucket(schema.AuthRoles)
|
schema.UnsafeCreateAuthRolesBucket(tx)
|
||||||
|
|
||||||
enabled := schema.UnsafeReadAuthEnabled(tx)
|
enabled := schema.UnsafeReadAuthEnabled(tx)
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfi
|
|||||||
tx := s.b.BatchTx()
|
tx := s.b.BatchTx()
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
tx.UnsafeCreateBucket(schema.Key)
|
tx.UnsafeCreateBucket(schema.Key)
|
||||||
tx.UnsafeCreateBucket(schema.Meta)
|
schema.UnsafeCreateMetaBucket(tx)
|
||||||
tx.Unlock()
|
tx.Unlock()
|
||||||
s.b.ForceCommit()
|
s.b.ForceCommit()
|
||||||
|
|
||||||
@ -340,7 +340,6 @@ func (s *store) restore() error {
|
|||||||
|
|
||||||
s.lg.Info(
|
s.lg.Info(
|
||||||
"restored last compact revision",
|
"restored last compact revision",
|
||||||
zap.Stringer("meta-bucket-name", schema.Meta),
|
|
||||||
zap.String("meta-bucket-name-key", string(schema.FinishedCompactKeyName)),
|
zap.String("meta-bucket-name-key", string(schema.FinishedCompactKeyName)),
|
||||||
zap.Int64("restored-compact-revision", s.compactMainRev),
|
zap.Int64("restored-compact-revision", s.compactMainRev),
|
||||||
)
|
)
|
||||||
@ -412,8 +411,6 @@ func (s *store) restore() error {
|
|||||||
|
|
||||||
s.lg.Info(
|
s.lg.Info(
|
||||||
"resume scheduled compaction",
|
"resume scheduled compaction",
|
||||||
zap.Stringer("meta-bucket-name", schema.Meta),
|
|
||||||
zap.String("meta-bucket-name-key", string(schema.ScheduledCompactKeyName)),
|
|
||||||
zap.Int64("scheduled-compact-revision", scheduledCompact),
|
zap.Int64("scheduled-compact-revision", scheduledCompact),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func TestScheduleCompaction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
vals, _ := UnsafeReadFinishedCompact(tx)
|
vals, _ := UnsafeReadFinishedCompact(tx)
|
||||||
if !reflect.DeepEqual(vals, tt.rev) {
|
if !reflect.DeepEqual(vals, tt.rev) {
|
||||||
t.Errorf("#%d: vals on %v = %+v, want %+v", i, schema.FinishedCompactKeyName, vals, tt.rev)
|
t.Errorf("#%d: finished compact equal %+v, want %+v", i, vals, tt.rev)
|
||||||
}
|
}
|
||||||
tx.Unlock()
|
tx.Unlock()
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ func TestRestoreContinueUnfinishedCompaction(t *testing.T) {
|
|||||||
revToBytes(revision{main: 2}, rbytes)
|
revToBytes(revision{main: 2}, rbytes)
|
||||||
tx := s0.b.BatchTx()
|
tx := s0.b.BatchTx()
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
tx.UnsafePut(schema.Meta, schema.ScheduledCompactKeyName, rbytes)
|
UnsafeSetScheduledCompact(tx, 2)
|
||||||
tx.Unlock()
|
tx.Unlock()
|
||||||
|
|
||||||
s0.Close()
|
s0.Close()
|
||||||
|
@ -20,6 +20,10 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func UnsafeCreateAuthRolesBucket(tx backend.BatchTx) {
|
||||||
|
tx.UnsafeCreateBucket(AuthRoles)
|
||||||
|
}
|
||||||
|
|
||||||
func UnsafeGetRole(lg *zap.Logger, tx backend.BatchTx, roleName string) *authpb.Role {
|
func UnsafeGetRole(lg *zap.Logger, tx backend.BatchTx, roleName string) *authpb.Role {
|
||||||
_, vs := tx.UnsafeRange(AuthRoles, []byte(roleName), nil, 0)
|
_, vs := tx.UnsafeRange(AuthRoles, []byte(roleName), nil, 0)
|
||||||
if len(vs) == 0 {
|
if len(vs) == 0 {
|
||||||
|
@ -20,6 +20,10 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func UnsafeCreateAuthUsersBucket(tx backend.BatchTx) {
|
||||||
|
tx.UnsafeCreateBucket(AuthUsers)
|
||||||
|
}
|
||||||
|
|
||||||
func UnsafeGetUser(lg *zap.Logger, tx backend.BatchTx, username string) *authpb.User {
|
func UnsafeGetUser(lg *zap.Logger, tx backend.BatchTx, username string) *authpb.User {
|
||||||
_, vs := tx.UnsafeRange(AuthUsers, []byte(username), nil, 0)
|
_, vs := tx.UnsafeRange(AuthUsers, []byte(username), nil, 0)
|
||||||
if len(vs) == 0 {
|
if len(vs) == 0 {
|
||||||
|
@ -55,11 +55,11 @@ func detectStorageVersion(lg *zap.Logger, tx backend.ReadTx) (*semver.Version, e
|
|||||||
}
|
}
|
||||||
confstate := UnsafeConfStateFromBackend(lg, tx)
|
confstate := UnsafeConfStateFromBackend(lg, tx)
|
||||||
if confstate == nil {
|
if confstate == nil {
|
||||||
return nil, fmt.Errorf("missing %q key", MetaConfStateName)
|
return nil, fmt.Errorf("missing confstate information")
|
||||||
}
|
}
|
||||||
_, term := UnsafeReadConsistentIndex(tx)
|
_, term := UnsafeReadConsistentIndex(tx)
|
||||||
if term == 0 {
|
if term == 0 {
|
||||||
return nil, fmt.Errorf("missing %q key", MetaTermKeyName)
|
return nil, fmt.Errorf("missing term information")
|
||||||
}
|
}
|
||||||
copied := V3_5
|
copied := V3_5
|
||||||
return &copied, nil
|
return &copied, nil
|
||||||
|
@ -31,48 +31,63 @@ func TestUpdateStorageVersion(t *testing.T) {
|
|||||||
tcs := []struct {
|
tcs := []struct {
|
||||||
name string
|
name string
|
||||||
version string
|
version string
|
||||||
metaKeys [][]byte
|
setupKeys func(tx backend.BatchTx)
|
||||||
expectVersion *semver.Version
|
expectVersion *semver.Version
|
||||||
expectError bool
|
expectError bool
|
||||||
expectedErrorMsg string
|
expectedErrorMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: `Backend before 3.6 without "confState" should be rejected`,
|
name: `Backend before 3.6 without confstate should be rejected`,
|
||||||
version: "",
|
version: "",
|
||||||
expectVersion: nil,
|
expectVersion: nil,
|
||||||
|
setupKeys: func(tx backend.BatchTx) {},
|
||||||
expectError: true,
|
expectError: true,
|
||||||
expectedErrorMsg: `cannot determine storage version: missing "confState" key`,
|
expectedErrorMsg: `cannot determine storage version: missing confstate information`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `Backend before 3.6 without "term" should be rejected`,
|
name: `Backend before 3.6 without term should be rejected`,
|
||||||
version: "",
|
version: "",
|
||||||
metaKeys: [][]byte{MetaConfStateName},
|
setupKeys: func(tx backend.BatchTx) {
|
||||||
|
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||||
|
},
|
||||||
expectVersion: nil,
|
expectVersion: nil,
|
||||||
expectError: true,
|
expectError: true,
|
||||||
expectedErrorMsg: `cannot determine storage version: missing "term" key`,
|
expectedErrorMsg: `cannot determine storage version: missing term information`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Backend with 3.5 with all metadata keys should be upgraded to v3.6",
|
name: "Backend with 3.5 with all metadata keys should be upgraded to v3.6",
|
||||||
version: "",
|
version: "",
|
||||||
metaKeys: [][]byte{MetaTermKeyName, MetaConfStateName},
|
setupKeys: func(tx backend.BatchTx) {
|
||||||
|
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||||
|
UnsafeUpdateConsistentIndex(tx, 1, 1, false)
|
||||||
|
},
|
||||||
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Backend in 3.6.0 should be skipped",
|
name: "Backend in 3.6.0 should be skipped",
|
||||||
version: "3.6.0",
|
version: "3.6.0",
|
||||||
metaKeys: [][]byte{MetaTermKeyName, MetaConfStateName, MetaStorageVersionName},
|
setupKeys: func(tx backend.BatchTx) {
|
||||||
|
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||||
|
UnsafeUpdateConsistentIndex(tx, 1, 1, false)
|
||||||
|
},
|
||||||
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Backend with current version should be skipped",
|
name: "Backend with current version should be skipped",
|
||||||
version: version.Version,
|
version: version.Version,
|
||||||
metaKeys: [][]byte{MetaTermKeyName, MetaConfStateName, MetaStorageVersionName},
|
setupKeys: func(tx backend.BatchTx) {
|
||||||
|
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||||
|
UnsafeUpdateConsistentIndex(tx, 1, 1, false)
|
||||||
|
},
|
||||||
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
expectVersion: &semver.Version{Major: 3, Minor: 6},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Backend in 3.7.0 should be skipped",
|
name: "Backend in 3.7.0 should be skipped",
|
||||||
version: "3.7.0",
|
version: "3.7.0",
|
||||||
metaKeys: [][]byte{MetaTermKeyName, MetaConfStateName, MetaStorageVersionName, []byte("future-key")},
|
setupKeys: func(tx backend.BatchTx) {
|
||||||
|
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||||
|
UnsafeUpdateConsistentIndex(tx, 1, 1, false)
|
||||||
|
},
|
||||||
expectVersion: &semver.Version{Major: 3, Minor: 7},
|
expectVersion: &semver.Version{Major: 3, Minor: 7},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -86,16 +101,7 @@ func TestUpdateStorageVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
UnsafeCreateMetaBucket(tx)
|
UnsafeCreateMetaBucket(tx)
|
||||||
for _, k := range tc.metaKeys {
|
tc.setupKeys(tx)
|
||||||
switch string(k) {
|
|
||||||
case string(MetaConfStateName):
|
|
||||||
MustUnsafeSaveConfStateToBackend(lg, tx, &raftpb.ConfState{})
|
|
||||||
case string(MetaTermKeyName):
|
|
||||||
UnsafeUpdateConsistentIndex(tx, 1, 1, false)
|
|
||||||
default:
|
|
||||||
tx.UnsafePut(Meta, k, []byte{})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tc.version != "" {
|
if tc.version != "" {
|
||||||
UnsafeSetStorageVersion(tx, semver.New(tc.version))
|
UnsafeSetStorageVersion(tx, semver.New(tc.version))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user