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