@@ -32,7 +32,6 @@ import (
32
32
"github.com/cockroachdb/cockroach/pkg/storage/disk"
33
33
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
34
34
"github.com/cockroachdb/cockroach/pkg/storage/fs"
35
- "github.com/cockroachdb/cockroach/pkg/storage/minversion"
36
35
"github.com/cockroachdb/cockroach/pkg/storage/mvccencoding"
37
36
"github.com/cockroachdb/cockroach/pkg/storage/pebbleiter"
38
37
"github.com/cockroachdb/cockroach/pkg/util/buildutil"
@@ -1076,54 +1075,25 @@ func newPebble(ctx context.Context, cfg engineConfig) (p *Pebble, err error) {
1076
1075
cfg .opts .Experimental .RemoteStorage = remoteStorageAdaptor {p : p , ctx : logCtx , factory : cfg .remoteStorageFactory }
1077
1076
}
1078
1077
}
1078
+ // If the store cluster version is not empty, it means that we initialized
1079
+ // the env using a min-version file. We can use that to determine if the
1080
+ // store should already exist or not.
1081
+ initFromMinVersionFile := cfg .env .StoreClusterVersion != (roachpb.Version {})
1079
1082
1080
- // Read the current store cluster version.
1081
- storeClusterVersion , minVerFileExists , err := minversion .GetMinVersion (p .cfg .env .UnencryptedFS , cfg .env .Dir )
1082
- if err != nil {
1083
- return nil , err
1084
- }
1085
- if minVerFileExists {
1086
- // Avoid running a binary too new for this store. This is what you'd catch
1087
- // if, say, you restarted directly from v21.2 into v22.2 (bumping the min
1088
- // version) without going through v22.1 first.
1089
- //
1090
- // Note that "going through" above means that v22.1 successfully upgrades
1091
- // all existing stores. If v22.1 crashes half-way through the startup
1092
- // sequence (so now some stores have v21.2, but others v22.1) you are
1093
- // expected to run v22.1 again (hopefully without the crash this time) which
1094
- // would then rewrite all the stores.
1095
- if v := cfg .settings .Version ; storeClusterVersion .Less (v .MinSupportedVersion ()) {
1096
- if storeClusterVersion .Major < clusterversion .DevOffset && v .LatestVersion ().Major >= clusterversion .DevOffset {
1097
- return nil , errors .Errorf (
1098
- "store last used with cockroach non-development version v%s " +
1099
- "cannot be opened by development version v%s" ,
1100
- storeClusterVersion , v .LatestVersion (),
1101
- )
1102
- }
1103
- return nil , errors .Errorf (
1104
- "store last used with cockroach version v%s " +
1105
- "is too old for running version v%s (which requires data from v%s or later)" ,
1106
- storeClusterVersion , v .LatestVersion (), v .MinSupportedVersion (),
1107
- )
1108
- }
1109
- cfg .opts .ErrorIfNotExists = true
1110
- } else {
1111
- if cfg .opts .ErrorIfNotExists || cfg .opts .ReadOnly {
1112
- // Make sure the message is not confusing if the store does exist but
1113
- // there is no min version file.
1114
- filename := p .cfg .env .UnencryptedFS .PathJoin (cfg .env .Dir , minversion .MinVersionFilename )
1115
- return nil , errors .Errorf (
1116
- "pebble: database %q does not exist (missing required file %q)" ,
1117
- cfg .env .Dir , filename ,
1118
- )
1119
- }
1120
- // If there is no min version file, there should be no store. If there is
1121
- // one, it's either 1) a store from a very old version (which we don't want
1122
- // to open) or 2) an empty store that was created from a previous bootstrap
1123
- // attempt that failed right before writing out the min version file. We set
1124
- // a flag to disallow the open in case 1.
1125
- cfg .opts .ErrorIfNotPristine = true
1083
+ if ! initFromMinVersionFile && (cfg .opts .ErrorIfNotExists || cfg .opts .ReadOnly ) {
1084
+ filename := p .cfg .env .UnencryptedFS .PathJoin (cfg .env .Dir , fs .MinVersionFilename )
1085
+ return nil , errors .Errorf (
1086
+ "pebble: database %q does not exist (missing required file %q)" ,
1087
+ cfg .env .Dir , filename ,
1088
+ )
1126
1089
}
1090
+ cfg .opts .ErrorIfNotExists = cfg .opts .ErrorIfNotExists || initFromMinVersionFile
1091
+ // If there is no min version file, there should be no store. If there is
1092
+ // one, it's either 1) a store from a very old version (which we don't want
1093
+ // to open) or 2) an empty store that was created from a previous bootstrap
1094
+ // attempt that failed right before writing out the min version file. We set
1095
+ // a flag to disallow the open in case 1.
1096
+ cfg .opts .ErrorIfNotPristine = ! initFromMinVersionFile
1127
1097
1128
1098
if WorkloadCollectorEnabled {
1129
1099
p .replayer .Attach (cfg .opts )
@@ -1132,10 +1102,10 @@ func newPebble(ctx context.Context, cfg engineConfig) (p *Pebble, err error) {
1132
1102
db , err := pebble .Open (cfg .env .Dir , cfg .opts )
1133
1103
if err != nil {
1134
1104
// Decorate the errors caused by the flags we set above.
1135
- if minVerFileExists && errors .Is (err , pebble .ErrDBDoesNotExist ) {
1105
+ if initFromMinVersionFile && errors .Is (err , pebble .ErrDBDoesNotExist ) {
1136
1106
err = errors .Wrap (err , "min version file exists but store doesn't" )
1137
1107
}
1138
- if ! minVerFileExists && errors .Is (err , pebble .ErrDBNotPristine ) {
1108
+ if ! initFromMinVersionFile && errors .Is (err , pebble .ErrDBNotPristine ) {
1139
1109
err = errors .Wrap (err , "store has no min-version file; this can " +
1140
1110
"happen if the store was created by an old CockroachDB version that is no " +
1141
1111
"longer supported" )
@@ -1144,7 +1114,8 @@ func newPebble(ctx context.Context, cfg engineConfig) (p *Pebble, err error) {
1144
1114
}
1145
1115
p .db = db
1146
1116
1147
- if ! minVerFileExists {
1117
+ storeClusterVersion := cfg .env .StoreClusterVersion
1118
+ if storeClusterVersion == (roachpb.Version {}) {
1148
1119
storeClusterVersion = cfg .settings .Version .ActiveVersionOrEmpty (ctx ).Version
1149
1120
if storeClusterVersion == (roachpb.Version {}) {
1150
1121
// If there is no active version, use the minimum supported version.
0 commit comments