Граф коммитов

19 Коммитов

Автор SHA1 Сообщение Дата
Evan Elias d3858906a4 Add new option temp-schema-binlog controlling workspace DDL replication
Previously, with workspace=temp-schema (the default), all workspace operations
were written to the binary log, meaning that replicas would execute them. This
can be undesirable for performance or operational cleanliness reasons, since
running the operations on replicas serves no real purpose: the temp schema is
dropped after each run, and Skeema won't interact with the replicas anyway.

This commit adds a new enum option, temp-schema-binlog, which can be set to
either "on" (keep the old behavior of writing these queries to binlog), "off"
(skip binlogging of workspace queries -- error if non-super-user), or the
default of "auto" (skip binlogging of workspace queries only if super-user).

This relates to issue #93.
2019-11-04 18:34:39 -05:00
Evan Elias b22daf5bbe Add option temp-schema-threads for configurable concurrency
This commit adds a new option, temp-schema-threads, which controls the
concurrency level for workspace CREATE and DROP queries when using
workspace=temp-schema. The default value for this option is 5 threads, which
is a reduction from the previous hardcoded default concurrency of 10 threads.

Users may wish to raise this value to improve Skeema's performance in some
scenarios, or lower this value to prevent mutex contention in other scenarios.
Refer to the option reference for more information about tuning this option.

This relates to #93. Keeping that issue open for now though since an
additional related improvement is also planned (ability to disable binlogging
for temp-schema operations)
2019-10-31 19:15:06 -04:00
Evan Elias e98d7302fe Deprecate option --reuse-temp-schema, and fix bugs in it
This commit deprecates the reuse-temp-schema option, since it is not commonly
used, and doesn't provide any real advantages over the default behavior of
dropping and recreating the temp schema each time.

This commit also fixes two edge case bugs in reuse-temp-schema's behavior:

* When used in an environment with multiple schemas per instance and
  differing schema-level default charset or collation values, a previously-
  processed schema's defaults could remain in-place on the temp schema,
  inadvertently affecting the introspected workspace for subsequent schemas.

* When used in the presence of stored procs/funcs, the procs/funcs would not
  be cleaned up between runs, typically causing the subsequent run to fail
  with duplicate routine errors.

Integration testing coverage has been added to ensure that the temp schema is
truly empty of all supported object types prior to use. This will avoid an
undetected regression if e.g. support for views or triggers is added to a
future version of Skeema.
2019-10-30 17:07:01 -04:00
Evan Elias 9f8c88a7cb Internal refactoring to improve gocyclo score
This commit refactors a number of overly-large functions, in order to reduce
cyclomatic complexity. No change in behavior or functionality is made.
2019-09-04 01:29:44 -04:00
Evan Elias 81b104b615 User-friendliness improvements to enums, lint-* options
* Despite being enums, lint-* options now treat falsey values (including
  --skip- prefix) as equivalent to "ignore"

* Enum values are now lowercase throughout all usage messages and docs. In
  terms of functionality, enums have always been case-insensitive, but the
  use of all-caps in usage/docs led many to think it was required.
2019-08-21 17:41:08 -04:00
Evan Elias f896e486c9 workspace=docker: Improve image verification logic
When using workspace=docker, if Skeema finds a pre-existing container created
from a previous run, the image of the container is verified. The previous
logic was overly strict, erroring in two valid situations:

* If the local Docker tag for the major.minor version now points to a
  different patch release, due to other non-Skeema Docker usage on the system

* If the version of Docker is several years old and uses the previous
  hashing scheme for image identification

In either of these cases, Skeema no longer errors, as long as the Dockerized
instance's flavor (vendor and major.minor version) can be introspected and
correctly match that of the desired image (via Skeema's flavor option).
2019-08-19 18:05:39 -04:00
Evan Elias 314163d920 Shellouts for host-wrapper and schema: ignore trailing spaces
The host-wrapper and schema options both support shelling out to an external
script, whose output is parsed to obtain a list of host:port or schema names,
respectively. When parsing the output, these options support a few different
delimiters (in order from highest precedence: newlines, commas, tabs, spaces)
and attempt to split the output on the highest-precedence delimiter found in
the output string.

However, since newline has the highest precedence, this means output with a
trailing newline would cause Skeema to assume newline is the delimiter, even
if the output was actually using some other delimiter.

This commit fixes the bug by removing trailing (and leading) spacing of any
type, prior to searching the output for delimiters.

Additionally, this commit fixes exposure of error messages around invalid
values for host and host-wrapper, which were inadvertently obscure ("dir maps
to an empty list of instances") previously in some cases.
2019-07-18 19:42:29 -04:00
Evan Elias 0666e6938d Internal improvements to util.ShellOut
* New field Timeout provides a way to terminate the process after specified
  amount of time has elapsed

* New field CombineOutput provides a way to redirect STDERR to STDOUT

These are not used in Skeema yet, but may prove useful in the future.
2019-05-29 01:21:21 -04:00
Evan Elias ffa83b1203 Don't prompt for password if explicitly set to blank string. Fixes #73
This commit fixes edge cases where the behavior of Skeema's password option
did not exactly match the behavior of the MySQL command-line client. In
particular, this caused problems with Travis CI's default ~/.my.cnf file.

These command-line invocations now correctly use no password, rather than
prompting from a TTY:
* --password=
* --password=''
* --password=""

Ditto for these option file lines:
* password=
* password=''
* password=""

In other words, Skeema only prompts for a password on STDIN if no equals sign
is found immediately after the password option.
2019-05-15 15:50:51 -04:00
Evan Elias ae6fe52b92 Docs: tweak text around my-cnf, and simplify test
* Add options.md index link at top
* Alphabetize in options.md
* Other related doc tweaks
* README: Update contributors list
* Tests: move skip-my-cnf logic from TestConfigIgnoreOptions into existing
  TestAddGlobalConfigFiles (achieves same test coverage)
2019-05-12 11:46:45 -04:00
Sam Chow 1d18414473 Rename ignore-my-cnf to overrideable skip-my-cnf
Changes logic to dynamically ignore my-cnf based off flag, meaning it
can potentially be disabled by an earlier configuration option.

Add documentation for the flag.
2019-05-11 22:19:46 -07:00
Sam Chow d55cfbbd47 Add option to ignore .my.cnf file
Feature requested by #64
2019-05-11 12:48:31 -07:00
Evan Elias 705fb734c9 Internal improvements to linter and util packages
* linter.Result now includes a map field, storing pointers to all schemas
  that were introspected during linting. The schemas are keyed by dir path.

* util.ShellOut now includes a Dir field, allowing callers to specify the
  initial working directory of the process.

* util.NewShellOut() has been removed, as it was unused and would not support
  adding additional fields to the ShellOut struct. Callers should create
  &ShellOut{} values directly with the desired fields.
2019-04-17 17:18:32 -04:00
Evan Elias af9a9897a0 Option file handling: ignore host option in .my.cnf
Skeema parses the standard per-user MySQL option file, ~/.my.cnf, for username
and password values. The intended behavior is to ignore the host option
though, if present in this specific file. However, a regression in Skeema
v1.0.6 broke this, and presence of host in ~/.my.cnf was triggering a fatal
error.

This commit fixes the regression, so that host is now ignored in ~/.my.cnf
again. See discussion in #64 for more context.
2019-03-15 16:18:50 -04:00
Evan Elias 37a1a2da43 Help text: fix typo
Thank you to @PsyonixDan for catching.
2019-03-06 18:00:42 -05:00
Evan Elias b81b89ccdc
Options to use local Docker for temporary schema (#45)
BACKGROUND:

Skeema's behavior does not rely on parsing SQL DDL, as this can be too brittle across various MySQL versions and vendors, which have subtle differences in features and functionality. Instead, Skeema uses metadata reported directly from the database to introspect schemas, using information_schema as well as various SHOW commands.

In order to accurately introspect the schemas represented in your filesystem's *.sql files, Skeema actually runs the files' CREATE TABLE statements in a temporary location, now called a "workspace." Previously (and still by default), Skeema creates, uses, and then drops a temporary schema on each database it interacts with.

WHAT'S NEW:

This PR adds the ability to instead use a local Docker container for workspace operations. Two new options control this behavior:

* `workspace=docker` tells Skeema to dynamically manage local Docker container(s) for workspace operations, instead of using a temporary schema on each live DB.

* `docker-cleanup` controls how to manage the container lifecycle as Skeema is exiting. The default, `docker-cleanup=none`, leaves containers running so that subsequent invocations of Skeema are faster. Setting `docker-cleanup=stop` stops containers but does not remove them, and `docker-cleanup=destroy` deletes them entirely.

This functionality is especially useful when running Skeema from a different region/datacenter than your database -- for example, running Skeema on your laptop, when your databases are in AWS. Using `workspace=docker` greatly reduces painful network latency in this scenario, especially if you have a large number of tables. See discussion in #25 for background.
2018-11-09 13:07:38 -05:00
Evan Elias 1d7a994a60 Fixes for help handler
* Fix `skeema help`, `skeema --help`, etc which were broken by refactor in #44

* Fix `skeema add-environment --help`, which was always broken due to having a
  required positional arg (although other forms like `skeema help
  add-environment` worked previously)

* Add tests to help handlers to ensure no error is returned
2018-10-30 15:44:39 -04:00
Evan Elias 135162a674 Minor cleanups after reviewing the code in this branch
* When `skeema` exits, gracefully close all connection pools, to avoid aborted
  connection counter/logging in some versions of MySQL

* `skeema diff`: If the only differences for a dir are schema-level DDL, the
  exit code now reflects this as a difference

* applier.TargetGroupChanForDir: skipCount return value is no longer a pointer

* cmd_init.go: Remove unnecessary createOptionFile() function

* cmd_pull.go: Track skipCount by return value, rather than a pointer arg
2018-10-29 16:13:47 -04:00
Evan Elias 42d3772bf7 Major internal refactor to use subpackages
This PR moves much of Skeema's logic out of the main package and into several
new sub-packages, which can be imported by other applications if desired.

Functionality is largely unchanged, and no new features have been added. But a
few foundational benefits of this work include:

* The codebase no longer assumes a 1:1 mapping between *.sql files and tables.
  This will eventually permit non-table object types (views, procs, grants, etc)
  to be stored in the same repo as schemas, if desired. See #41 for background.

* In the upcoming Skeema 1.1.x series, it will be possible to use a local Docker
  instance for temp schema operations. This performs better in high-latency,
  high-table-count scenarios; see #25 for background.

* The limit on max *.sql file size has been removed. Closes #34.

* `skeema pull` now performs much better than before, as long as --normalize is
  enabled (which it is by default).

* The code supporting `skeema push --concurrent-instances` is now much cleaner
  and more idiomatic.

* Test coverage has been improved.
2018-10-26 18:04:46 -04:00