Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Add EngineTypeDefault, resolve it to Pebble if last used #45512

Merged
merged 1 commit into from
Mar 2, 2020

Conversation

itsbilal
Copy link
Member

@itsbilal itsbilal commented Feb 27, 2020

Adds a new engine type called EngineTypeDefault, that resolves
at start time to RocksDB, or Pebble if that was last used
to write to the first store. This effectively makes the
--storage-engine flag sticky for future runs where no
engine is specified. If the flag is passed in again, that
specified engine type takes priority over the one used last.

Fixes #42445 .

Release note (cli change): Add new "default" option for
--storage-engine flag that respects the engine used last.

@itsbilal itsbilal requested a review from a team as a code owner February 27, 2020 20:37
@itsbilal itsbilal self-assigned this Feb 27, 2020
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@itsbilal
Copy link
Member Author

First commit is #45499 , will rebase it away when that gets merged.

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks generally good, though I'm worried about how many places you need to add support for EngineTypeDefault. Were all of those additions actually needed, or should we be making sure that the engine type is "resolved" early and instead error out if we get to server.Start and the engine type is still "default"?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal, @knz, @petermattis, and @sumeerbhola)


pkg/cli/debug.go, line 158 at r2 (raw file):

		db, err = engine.NewPebble(context.Background(), cfg)

	case enginepb.EngineTypeDefault:

I think this should have the same behavior as start. Specifically, we should query pebble.GetVersion. The reason for this is so commands like cockroach debug keys use the same engine that was previously used. That was actually my initial motivation behind this functionality.


pkg/server/server.go, line 1747 at r2 (raw file):

	case enginepb.EngineTypePebble:
		nodeStartCounter += "pebble."
	case enginepb.EngineTypeDefault:

I think we want to know what engine is actually being used at this point. Will we ever get here with enginepb.EngineTypeDefault still be a valid case?

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think you need to update the help text for the --storage-engine flag.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal, @knz, @petermattis, and @sumeerbhola)

@itsbilal itsbilal force-pushed the sticky-storage-engine branch 2 times, most recently from 499c0ef to 8c1eaf7 Compare February 29, 2020 00:22
Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Walked back some of the Default checks, and added an error at engine creation time, if the engine type is still left at EngineTypeDefault. Test code still continues to treat Default = RocksDB

Also made the help text change.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @petermattis, and @sumeerbhola)


pkg/cli/debug.go, line 158 at r2 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I think this should have the same behavior as start. Specifically, we should query pebble.GetVersion. The reason for this is so commands like cockroach debug keys use the same engine that was previously used. That was actually my initial motivation behind this functionality.

Done.


pkg/server/server.go, line 1747 at r2 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I think we want to know what engine is actually being used at this point. Will we ever get here with enginepb.EngineTypeDefault still be a valid case?

The storage engine value should have been resolved by this point, but just in case it isn't, I added a case for default instead of not reporting anything or errorring out, so we can at least find out something's wrong without erroring out.

@itsbilal
Copy link
Member Author

Actually, this turned out to be more involved to implement in test code than I expected at first. We'd basically have to take all instances of MakeConfig in tests, and append a conditional that goes if cfg.StorageEngine == Default { cfg.StorageEngine = EngineTypeRocksDB } (or alternatively we could just set engine.DefaultStorageEngine to EngineTypeRocksDB if it's default right before the MakeConfig calls).

I'd now make the case to go back to the previous, defensive solution where we treat EngineTypeDefault as akin to EngineTypeRocksDB whenever it's encountered, except in start and debug where we make the GetVersion check. It might seem like more threading, but it's less threading than the alternative, plus it feels safer.

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd now make the case to go back to the previous, defensive solution where we treat EngineTypeDefault as akin to EngineTypeRocksDB whenever it's encountered, except in start and debug where we make the GetVersion check. It might seem like more threading, but it's less threading than the alternative, plus it feels safer.

Ack. Not all of my suggestions are good suggestions. I like this proposal.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal, @knz, @petermattis, and @sumeerbhola)


pkg/cli/cliflags/flags.go, line 719 at r3 (raw file):

		Description: `
Storage engine to use for all stores on this cockroach node. Options are rocksdb,
or pebble.

Isn't default an option now too?


pkg/cli/cliflags/flags.go, line 721 at r3 (raw file):

or pebble.

If left unspecified, the storage engine last used to write to the

I'd rephrase this to mention "default": If default is specified. That applies to the other references to "unspecified" as well.

@itsbilal itsbilal force-pushed the sticky-storage-engine branch 2 times, most recently from 8696b29 to e0d59b8 Compare March 2, 2020 17:35
Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, this is ready for another look. I've reverted to the default = rocksdb idea. Also added a release note.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @petermattis, and @sumeerbhola)


pkg/cli/cliflags/flags.go, line 719 at r3 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Isn't default an option now too?

Done. Yeah, it is, but I was trying to simplify it to just the unspecified case. I like explicitly mentioning default better, so I made the change.


pkg/cli/cliflags/flags.go, line 721 at r3 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I'd rephrase this to mention "default": If default is specified. That applies to the other references to "unspecified" as well.

Done.

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo a couple of nits.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal, @knz, and @sumeerbhola)


pkg/cli/debug.go, line 154 at r4 (raw file):

			}
		}
	}

This is duplicated with code in runStart, and is just past my threshold where I'd want to extract it into a common method. Something like resolveStorageEngineType(engine.DefaultStorageEngine, dir).


pkg/storage/engine/engine.go, line 560 at r4 (raw file):

	case enginepb.EngineTypeDefault:
		fallthrough
	case enginepb.EngineTypeRocksDB:

Nit: you can write this as case enginepb.EngineTypeDefault, enginepb.EngineTypeDefault:.


pkg/storage/engine/in_mem.go, line 35 at r4 (raw file):

	case enginepb.EngineTypeDefault:
		fallthrough
	case enginepb.EngineTypeRocksDB:

See nit about multi-version case statements.


pkg/storage/engine/temp_engine.go, line 42 at r4 (raw file):

	case enginepb.EngineTypeDefault:
		fallthrough
	case enginepb.EngineTypeRocksDB:

See nit about multi-version case statements.

Adds a new engine type called EngineTypeDefault, that resolves
at start time to RocksDB, or Pebble if that was last used
to write to the first store. This effectively makes the
--storage-engine flag sticky for future runs where no
engine is specified. If the flag is passed in again, that
specified engine type takes priority over the one used last.

Fixes cockroachdb#42445 .

Release note (cli change): Add new "default" option for
--storage-engine flag that respects the engine used last.
Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @petermattis, and @sumeerbhola)


pkg/cli/debug.go, line 154 at r4 (raw file):

Previously, petermattis (Peter Mattis) wrote…

This is duplicated with code in runStart, and is just past my threshold where I'd want to extract it into a common method. Something like resolveStorageEngineType(engine.DefaultStorageEngine, dir).

Done.


pkg/storage/engine/in_mem.go, line 35 at r4 (raw file):

Previously, petermattis (Peter Mattis) wrote…

See nit about multi-version case statements.

Done.


pkg/storage/engine/temp_engine.go, line 42 at r4 (raw file):

Previously, petermattis (Peter Mattis) wrote…

See nit about multi-version case statements.

Done.

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @sumeerbhola)

@itsbilal
Copy link
Member Author

itsbilal commented Mar 2, 2020

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 2, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Mar 2, 2020

Build succeeded

@craig craig bot merged commit 3e56193 into cockroachdb:master Mar 2, 2020
@knz knz added this to To do in DB Server & Security via automation Mar 7, 2020
@knz knz moved this from To do to Done 20.1 in DB Server & Security Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: make --storage-engine sticky
3 participants