Skip to content

Commit

Permalink
[wip,dnm,dnr] migration: prototype lrm orchestrator
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
irfansharif committed Oct 22, 2020
1 parent 8b25c05 commit cd533d7
Show file tree
Hide file tree
Showing 26 changed files with 2,604 additions and 638 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@
<tr><td><code>trace.debug.enable</code></td><td>boolean</td><td><code>false</code></td><td>if set, traces for recent requests can be seen in the /debug page</td></tr>
<tr><td><code>trace.lightstep.token</code></td><td>string</td><td><code></code></td><td>if set, traces go to Lightstep using this token</td></tr>
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>if set, traces go to the given Zipkin instance (example: '127.0.0.1:9411'); ignored if trace.lightstep.token is set</td></tr>
<tr><td><code>version</code></td><td>custom validation</td><td><code>20.2-1</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
<tr><td><code>version</code></td><td>custom validation</td><td><code>20.2-2</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
33 changes: 32 additions & 1 deletion pkg/clusterversion/clusterversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ package clusterversion

import (
"context"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/redact"
)
Expand Down Expand Up @@ -76,6 +76,11 @@ func SetBeforeChange(

// Handle is a read-only view to the active cluster version and this binary's
// version details.
//
// XXX: We'll want this same handle to exist going forward. Except underneath
// the hood the "setting" of things doesn't happen through this StateMachine guy
// anymore. It happens through the one RPC.
// XXX: I'm unsure what the migration story _there_ looks like.
type Handle interface {
// ActiveVersion returns the cluster's current active version: the minimum
// cluster version the caller may assume is in effect.
Expand Down Expand Up @@ -158,6 +163,32 @@ func MakeVersionHandle(sv *settings.Values) Handle {
return MakeVersionHandleWithOverride(sv, binaryVersion, binaryMinSupportedVersion)
}

type MutableRef struct {
handleImpl *handleImpl
}

func (r MutableRef) Set(ctx context.Context, v *roachpb.Version) error {
sv := r.handleImpl.sv
newV := *v
if err := version.validateSupportedVersionInner(ctx, newV, sv); err != nil {
return err
}

value := ClusterVersion{Version: newV}
encoded, err := protoutil.Marshal(&value)
if err != nil {
return err
}
version.SetInternal(sv, encoded)
return nil
}

func MakeMutableRef(handle Handle) MutableRef {
return MutableRef{
handleImpl: handle.(*handleImpl),
}
}

// MakeVersionHandleWithOverride returns a Handle that has its
// binary and minimum supported versions initialized to the provided versions.
//
Expand Down
6 changes: 6 additions & 0 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const (
VersionHBAForNonTLS
Version20_2
VersionStart21_1
VersionLRMTable

// Add new versions here (step one of two).
)
Expand Down Expand Up @@ -441,6 +442,11 @@ var versionsSingleton = keyedVersions([]keyedVersion{
Key: VersionStart21_1,
Version: roachpb.Version{Major: 20, Minor: 2, Unstable: 1},
},
{
// XXX:
Key: VersionLRMTable,
Version: roachpb.Version{Major: 20, Minor: 2, Unstable: 2},
},

// Add new versions here (step two of two).
})
Expand Down
74 changes: 74 additions & 0 deletions pkg/clusterversion/migration/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package migration

import (
"context"
"github.com/cockroachdb/cockroach/pkg/roachpb"
)

var _ Migration = UnreplicatedTruncatedStateMigration
var _ Migration = GenerationComparableMigration
var _ Migration = SeparateRaftLogMigration
var _ Migration = ReplicatedLockTableMigration
var _ Migration = ReplicasKnowReplicaIDMigration

func UnreplicatedTruncatedStateMigration(ctx context.Context, h *Helper) error {
if err := h.IterRangeDescriptors(func(descs ...roachpb.RangeDescriptor) error {
// Really AdminMigrate but it doesn't exist yet. It takes an argument
// determining the range version to migrate into. Unsure if that's a
// different kind of version or just `h.Version()`. I think I lean
// towards the latter.
_, err := h.db.Scan(ctx, descs[0].StartKey, descs[len(descs)-1].EndKey, -1)
return err
}); err != nil {
return err
}
if err := h.EveryNode(ctx, "forced-replicagc"); err != nil {
return err
}
return nil
}

func GenerationComparableMigration(ctx context.Context, h *Helper) error {
// Hmm now that I look at this again I think we can remove it just like that.
// No snapshots are in flight any more that don't respect the generational
// rules. Replicas get replicaGC'ed eagerly. (Once round of forced-replicagc
// somewhere is enough). Need to think this through more.
return nil
}

func SeparateRaftLogMigration(ctx context.Context, h *Helper) error {
// Impl will loop through all repls on the node and migrate them one by one
// (get raftMu, check if already copied, if not copy stuff, delete old stuff,
// release raftMu).
if err := h.EveryNode(ctx, "move-raft-logs"); err != nil {
return err
}
// TODO: sanity check that all are really using separate raft log now?
return nil
}

func ReplicatedLockTableMigration(ctx context.Context, h *Helper) error {
// Pretty vanilla Raft migration, see
// https://github.com/cockroachdb/cockroach/issues/41720#issuecomment-590817261
// also run forced-replicagc.
// Should probably bake the forced replicaGC and migrate command into a
// helper, there's never a reason not to run forced-replicaGC after a Migrate.
return nil
}

func ReplicasKnowReplicaIDMigration(ctx context.Context, h *Helper) error {
// Is a migration necessary here or are we already nuking them at startup anyway?
// Oh seems like it, so nothing to do here:
// https://github.com/cockroachdb/cockroach/blob/f0e751f00b7ba41f39dd83ddc8238011fa5b9c19/pkg/storage/store.go#L1347-L1350
return nil
}
Loading

0 comments on commit cd533d7

Please sign in to comment.