@@ -68,6 +68,10 @@ var minWALSyncInterval = settings.RegisterDurationSetting(
6868 0 * time .Millisecond ,
6969)
7070
71+ // TODO(mberhault): enterprise encryption flags will dictate the need for the
72+ // switching env format. Until then, use an env variable.
73+ var useSwitchingEnv = envutil .EnvOrDefaultBool ("COCKROACH_USE_SWITCHING_ENV" , false )
74+
7175//export rocksDBLog
7276func rocksDBLog (s * C.char , n C.int ) {
7377 // Note that rocksdb logging is only enabled if log.V(3) is true
@@ -401,28 +405,40 @@ func (r *RocksDB) String() string {
401405}
402406
403407func (r * RocksDB ) open () error {
404- var ver storageVersion
408+ var existingVersion , newVersion storageVersion
405409 if len (r .cfg .Dir ) != 0 {
406410 log .Infof (context .TODO (), "opening rocksdb instance at %q" , r .cfg .Dir )
407411
408412 // Check the version number.
409413 var err error
410- if ver , err = getVersion (r .cfg .Dir ); err != nil {
414+ if existingVersion , err = getVersion (r .cfg .Dir ); err != nil {
411415 return err
412416 }
413- if ver < versionMinimum || ver > versionCurrent {
417+ if existingVersion < versionMinimum || existingVersion > versionCurrent {
414418 // Instead of an error, we should call a migration if possible when
415419 // one is needed immediately following the DBOpen call.
416420 return fmt .Errorf ("incompatible rocksdb data version, current:%d, on disk:%d, minimum:%d" ,
417- versionCurrent , ver , versionMinimum )
421+ versionCurrent , existingVersion , versionMinimum )
422+ }
423+
424+ if existingVersion != versionCurrent {
425+ if useSwitchingEnv {
426+ newVersion = versionCurrent
427+ } else {
428+ // If the switching env is not needed, use the older version. This allows downgrade to binaries unaware
429+ // of versionSwitchingEnv.
430+ // TODO(mberhault): once enough releases supporting versionSwitchingEnv have passed, we can upgrade
431+ // to it without worry.
432+ newVersion = versionBeta20160331
433+ }
418434 }
419435 } else {
420436 if log .V (2 ) {
421437 log .Infof (context .TODO (), "opening in memory rocksdb instance" )
422438 }
423439
424440 // In memory dbs are always current.
425- ver = versionCurrent
441+ existingVersion = versionCurrent
426442 }
427443
428444 blockSize := envutil .EnvOrDefaultBytes ("COCKROACH_ROCKSDB_BLOCK_SIZE" , defaultBlockSize )
@@ -434,20 +450,21 @@ func (r *RocksDB) open() error {
434450
435451 status := C .DBOpen (& r .rdb , goToCSlice ([]byte (r .cfg .Dir )),
436452 C.DBOptions {
437- cache : r .cache .cache ,
438- block_size : C .uint64_t (blockSize ),
439- wal_ttl_seconds : C .uint64_t (walTTL ),
440- logging_enabled : C .bool (log .V (3 )),
441- num_cpu : C .int (runtime .NumCPU ()),
442- max_open_files : C .int (maxOpenFiles ),
453+ cache : r .cache .cache ,
454+ block_size : C .uint64_t (blockSize ),
455+ wal_ttl_seconds : C .uint64_t (walTTL ),
456+ logging_enabled : C .bool (log .V (3 )),
457+ num_cpu : C .int (runtime .NumCPU ()),
458+ max_open_files : C .int (maxOpenFiles ),
459+ use_switching_env : C .bool (useSwitchingEnv ),
443460 })
444461 if err := statusToError (status ); err != nil {
445462 return errors .Wrap (err , "could not open rocksdb instance" )
446463 }
447464
448- // Update or add the version file if needed.
449- if ver < versionCurrent {
450- if err := writeVersionFile (r .cfg .Dir ); err != nil {
465+ // Update or add the version file if needed and if on-disk .
466+ if len ( r . cfg . Dir ) != 0 && existingVersion != newVersion {
467+ if err := writeVersionFile (r .cfg .Dir , newVersion ); err != nil {
451468 return err
452469 }
453470 }
0 commit comments