Commit Graph

1210 Commits

Author SHA1 Message Date
Stan Hu d306b0d7c2 Merge branch 'use-optimistic-locking' into 'master'
Use optimistic locking

## What does this MR do?
Removes the usage of pessimistic locking in favor of optimistic which is way cheaper and doesn't block database operation.

Since this is very simple change it should be safe. If we receive `StaleObjectError` message we will reload object a retry operations in lock.

However, I still believe that we need this one: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7005 as this will reduce a load on Database and FS.
This changes a behavior from:

### Pesimistic locking (previous behavior)

#### For updating
1. SELECT * FOR UPDATE (other updates wait on this)
2. we update ci_pipeline
3. latest_build_status
4. enqueue: (use: transition :created -> :pending)
5. [state_machine] we are in  state created, we can go to pending
6. [state_machine] ci_pipeline.status = created
7. [state_machine] ci_pipeline.save
8. [state_machine] after_transition: (if for success): PipelineSuccessWorker on Sidekiq
9. release DB lock

#### If no update is required
1. SELECT * FOR UPDATE (other updates wait on this)
2. we update ci_pipeline
3. latest_build_status
4. we are in pending, we can't transition to pending, because it's forbidden
5. release DB lock

### Optimistic locking (implemented by this MR)

#### For updating
1. latest_build_status
2. enqueue: (use `transition :created -> :pending`)
3. [state_machine] we are in state created, we can go to pending
4. [state_machine] ci_pipeline.status = created
5. [state_machine] ci_pipeline.save
6. [state_machine] [save] where(lock_version: ci_pipeline.lock_version).update_all(status: :created, updated_at: Time.now)
7. [state_machine] [save] unless we_updated_row then raise ObjectInconsistentError

#### If no update is required
1. we update ci_pipeline
2. latest_build_status
3. we are in pending, we can't transition to pending, because it's forbidden

## Why was this MR needed?
We have been seeing a number of problems when we migrated Pipeline/Build processing to Sidekiq. Especially we started seeing a lot of blocking queries.

We used a pessimistic locking which doesn't seem to be required. This effectively allows us to fix our issues with blocked queries by using more efficient method of operation.

## What are the relevant issue numbers?
Issues: https://gitlab.com/gitlab-com/infrastructure/issues/623 and https://gitlab.com/gitlab-com/infrastructure/issues/584, but also there's a bunch of Merge Requests that try to improve behavior of scheduled jobs.

cc @pcarranza @yorickpeterse @stanhu

See merge request !7040
2016-10-28 14:41:24 +00:00
Felipe Artur c2d6822e94 Finish updates to use JIRA gem
Code improvements, bug fixes, finish documentation and specs
2016-10-26 15:02:16 -02:00
Drew Blessing f4bc18d237 Refactor JIRA service to use gem 2016-10-26 15:02:16 -02:00
Kamil Trzcinski 5d7ee7a1b6 Use optimistic locking 2016-10-26 11:37:23 +02:00
Stan Hu 59ed1d3cbb Fix reply-by-email not working due to queue name mismatch
mail_room was configured to deliver mail to the `incoming_email`
queue while `EmailReceiveWorker` was reading the `email_receiver`
queue. Adds a migration that repeats the work of a previous
migration to ensure all mails that wound up in the old
queue get processed.

Closes #23689
2016-10-23 21:35:52 -07:00
Yorick Peterse 97731760d7
Re-organize queues to use for Sidekiq
Dumping too many jobs in the same queue (e.g. the "default" queue) is a
dangerous setup. Jobs that take a long time to process can effectively
block any other work from being performed given there are enough of
these jobs.

Furthermore it becomes harder to monitor the jobs as a single queue
could contain jobs for different workers. In such a setup the only
reliable way of getting counts per job is to iterate over all jobs in a
queue, which is a rather time consuming process.

By using separate queues for various workers we have better control over
throughput, we can add weight to queues, and we can monitor queues
better. Some workers still use the same queue whenever their work is
related. For example, the various CI pipeline workers use the same
"pipeline" queue.

This commit includes a Rails migration that moves Sidekiq jobs from the
old queues to the new ones. This migration also takes care of doing the
inverse if ever needed. This does require downtime as otherwise new jobs
could be scheduled in the old queues after this migration completes.

This commit also includes an RSpec test that blacklists the use of the
"default" queue and ensures cron workers use the "cronjob" queue.

Fixes gitlab-org/gitlab-ce#23370
2016-10-21 18:17:07 +02:00
Sean McGivern 6c09fbd889 Merge branch 'fix_project_member_access_levels' into 'master'
Fix project member access levels

Migrate invalid project members (owner -> master)

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/18616

See merge request !6957
2016-10-21 12:51:44 +00:00
Stan Hu b332931af3 Fix broken label uniqueness label migration
The previous implementation of the migration failed on staging because
the migration was attempted to remove labels from projects that did not
actually have duplicates. This occurred because the SQL query did not
account for the project ID when selecting the labels.

To replicate the problem:

1. Disable the uniqueness validation in app/models/label.rb.
2. Create a duplicate label "bug" in project A.
3. Create the same label in project B with label "bug".

The migration will attempt to remove the label in B even if there are no duplicates.

Closes #23609
2016-10-21 12:45:10 +02:00
Valery Sizov 168197cd5a Fix project member access levels 2016-10-21 12:57:53 +03:00
Felipe Artur ed9838cd29 Create project feature when project is created 2016-10-19 20:00:52 -02:00
Douglas Barbosa Alexandre 771d3fc3cb Split migration to create label priorities 2016-10-19 14:58:27 -02:00
Douglas Barbosa Alexandre 074c964913 Add label type to group and project labels lists 2016-10-19 14:58:27 -02:00
Douglas Barbosa Alexandre 2978920113 Add LabelPriority model 2016-10-19 14:58:27 -02:00
Douglas Barbosa Alexandre 9629bb962c Add column type to labels and do the batch update in the same migration 2016-10-19 14:58:25 -02:00
Douglas Barbosa Alexandre cfedd42bad Add ProjectLabel model 2016-10-19 14:58:24 -02:00
Douglas Barbosa Alexandre d820c090ec Add GroupLabel model 2016-10-19 14:57:14 -02:00
Kamil Trzcinski 19300a1a3d Merge remote-tracking branch 'origin/master' into 22191-delete-dynamic-envs-mr 2016-10-18 17:48:27 +02:00
Felipe Artur da07c2e4d3 Add visibility level to project repository 2016-10-17 18:12:18 -02:00
Kamil Trzcinski 18bb0a5696 Add on_stop column [ci skip] 2016-10-17 15:34:30 +02:00
Kamil Trzcinski 53d79469b0 Update `db/schema.rb` 2016-10-17 12:51:37 +02:00
Kamil Trzcinski 6cdbb27ec3 Refactor code to use available and stopped statuses and refactor views to use separate renders 2016-10-17 12:45:31 +02:00
Kamil Trzcinski 40528a1326 Merge remote-tracking branch 'origin/master' into 22191-delete-dynamic-envs-mr 2016-10-17 11:24:51 +02:00
Rémy Coutable 254c8200ef
Use activerecord_sane_schema_dumper
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-10-12 14:51:29 +02:00
Yorick Peterse 237c8f66e6
Precalculate trending projects
This commit introduces a Sidekiq worker that precalculates the list of
trending projects on a daily basis. The resulting set is stored in a
database table that is then queried by Project.trending.

This setup means that Unicorn workers no longer _may_ have to calculate
the list of trending projects. Furthermore it supports filtering without
any complex caching mechanisms.

The data in the "trending_projects" table is inserted in the same order
as the project ranking. This means that getting the projects in the
correct order is simply a matter of:

    SELECT projects.*
    FROM projects
    INNER JOIN trending_projects ON trending_projects.project_id = projects.id
    ORDER BY trending_projects.id ASC;

Such a query will only take a few milliseconds at most (as measured on
GitLab.com), opposed to a few seconds for the query used for calculating
the project ranks.

The migration in this commit does not require downtime and takes care of
populating an initial list of trending projects.
2016-10-10 12:27:08 +02:00
Nick Thomas e94cd6fdfe Add markdown cache columns to the database, but don't use them yet
This commit adds a number of _html columns and, with the exception of Note,
starts updating them whenever the content of their partner fields changes.

Note has a collision with the note_html attr_accessor; that will be fixed later

A background worker for clearing these cache columns is also introduced - use
`rake cache:clear` to set it off. You can clear the database or Redis caches
separately by running `rake cache:clear:db` or `rake cache:clear:redis`,
respectively.
2016-10-07 02:54:25 +01:00
Kamil Trzcinski 0e1f39d8ce Allow to close environments 2016-10-06 14:16:03 +02:00
Kamil Trzcinski c319cc5ab5 Make environments to be close able 2016-10-06 13:45:45 +02:00
Kamil Trzcinski 3f85c3ef16 Initial support for closing environments 2016-10-06 13:16:34 +02:00
Grzegorz Bizon ebeee31100 Fix pipeline fixtures and calls to removed method 2016-10-04 14:43:24 +02:00
Rémy Coutable ec0061a95c Allow Member.add_user to handle access requesters
Changes include:

- Ensure Member.add_user is not called directly when not necessary
- New GroupMember.add_users_to_group to have the same abstraction level as for Project
- Refactor Member.add_user to take a source instead of an array of members
- Fix Rubocop offenses
- Always use Project#add_user instead of project.team.add_user
- Factorize users addition as members in Member.add_users_to_source
- Make access_level a keyword argument in GroupMember.add_users_to_group and ProjectMember.add_users_to_projects
- Destroy any requester before adding them as a member
- Improve the way we handle access requesters in Member.add_user
  Instead of removing the requester and creating a new member,
  we now simply accepts their access request. This way, they will
  receive a "access request granted" email.
- Fix error that was previously silently ignored
- Stop raising when access level is invalid in Member, let Rails validation do their work

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-09-28 09:43:00 +02:00
Dmitriy Zaporozhets c17383a730 Improvements to user organization field feature after code review
* Add newline to user organization spec according to test guide
* Remove unnecessary comments from user organization database migration

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-09-27 14:04:39 +03:00
Dmitriy Zaporozhets 0275f203ef Add organization field to user profile
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-09-27 14:04:39 +03:00
Rémy Coutable c2b8063fda Merge branch 'fix/database-seeds' into 'master'
Fix database seeds for development environment

## What does this MR do?

This MR fixes database seeds for development environment and adds CI test for it.

## Why was this MR needed?

Database seeds for development environment are often broken, and we are not able to catch that when someone modified `db/fixtures` and forgets to reseed database.

Closes #22422

See merge request !6475
2016-09-23 14:50:36 +00:00
Ahmad Sherif 0560b7a2ab Add index on labels title 2016-09-23 13:19:16 +02:00
Grzegorz Bizon c2083b7997 Limit test environment size to one project in CI 2016-09-23 10:21:12 +02:00
Yorick Peterse 4d63a1569e
Update db/schema.rb per most recent migrations
It seems this wasn't updated properly when migrations were added in a
previous commit.
2016-09-21 21:44:13 +02:00
Timothy Andrew 918e589c2b Implement a second round of review comments from @DouweM.
- Don't use `TableReferences` - using `.arel_table` is shorter!
- Move some database-related code to `Gitlab::Database`
- Remove the `MergeRequest#issues_closed` and
  `Issue#closed_by_merge_requests`  associations. They were either
  shadowing or were too similar to existing methods. They are not being
  used anywhere, so it's better to remove them to reduce confusion.
- Use Rails 3-style validations
- Index for `MergeRequest::Metrics#first_deployed_to_production_at`
- Only include `CycleAnalyticsHelpers::TestGeneration` for specs that
  need it.
- Other minor refactorings.
2016-09-21 00:47:37 +05:30
Timothy Andrew 6f194e28e4 Update schema.rb 2016-09-20 16:55:00 +05:30
Timothy Andrew 8747f29db7 Fix `ON DELETE CASCADE` migrations.
Incorrect syntax.
2016-09-20 16:31:52 +05:30
Timothy Andrew 8957293d9b Implement review comments from @yorickpeterse
1. Change multiple updates to a single `update_all`

2. Use cascading deletes

3. Extract an average function for the database median.

4. Move database median to `lib/gitlab/database`

5. Use `delete_all` instead of `destroy_all`

6. Minor refactoring
2016-09-20 16:05:25 +05:30
Timothy Andrew fa890604aa Merge remote-tracking branch 'origin/master' into 21170-cycle-analytics 2016-09-20 14:48:13 +05:30
Timothy Andrew b43d3af782 Miscellaneous cycle-analytics-related changes.
1. Add indexes to `CreateMergeRequestsClosingIssues` columns.
2. Remove an extraneous `check_if_open` check that is redundant now.

It would've been better to rebase this in, but that's not possible
because more people are working on this branch.
2016-09-20 13:23:14 +05:30
Kamil Trzcinski 967eb8fb55 Merge branch 'master' into per-build-token 2016-09-19 13:31:42 +02:00
Kamil Trzcinski abfceb1e56 Cleanup changes 2016-09-19 10:07:14 +02:00
Kamil Trzcinski 274d3d50e5 Added missing db/schema changes 2016-09-19 10:07:13 +02:00
Kamil Trzcinski a4638dddf2 Add support for dynamic environments
Environments that can have a URL with predefined CI variables.
2016-09-19 10:05:35 +02:00
Timothy Andrew 2cddd02ec5 Remove unused merge request metrics.
- These are not being used anymore.
- Consolidate all issue metrics into a single migration.
- Consolidate all merge request metrics into a single migration.
2016-09-19 13:12:06 +05:30
Timothy Andrew 161804bf40 Add a "populate metrics directly" option to the cycle analytics seed.
- The normal seed creates all the data for cycle analytics the "right"
  way. It creates issues, merge requests, commits, branches,
  deployments, etc. This is good, but too slow for perf testing.
  Generating a 1000 sets of records this way takes more than an hour.

- When the `CYCLE_ANALYTICS_POPULATE_METRICS_DIRECTLY` environment
  variable is passed in, the seed only creates issues and merge
  requests. It then adds the `metrics` for each issue and
  merge request directly, to save time.

- The seed now takes about 4 minutes to run for 1000 sets of records.
2016-09-17 12:16:48 +05:30
Yorick Peterse 065341bf04 Merge branch 'increase_artifact_size_column' into 'master'
Increase ci_builds artifacts_size column to 8-byte integer to allow larger files

See merge request !6333
2016-09-16 10:44:55 +00:00
Rémy Coutable 6e4582f2f2 Merge branch 'group-specific-lfs-settings' into 'master'
Added group-specific setting for LFS.

Groups can enable/disable LFS, but this setting can be overridden at the project level. **Admin only**

Closes #18092

See merge request !6164
2016-09-16 09:10:36 +00:00