![]() ![]() lib/gitlab/testing/request_blocker_middleware.rb:47:in `call' #. lib/gitlab/testing/request_inspector_middleware.rb:33:in `call' #. lib/gitlab/middleware/static.rb:11:in `call' #. config/initializers/fix_local_cache_middleware.rb:9:in `call' #. lib/gitlab/request_context.rb:20:in `call' #. lib/gitlab/middleware/basic_health_check.rb:25:in `call' #. lib/gitlab/middleware/read_only.rb:18:in `call' #. lib/gitlab/middleware/read_only/controller.rb:40:in `call' #. lib/gitlab/middleware/correlation_id.rb:15:in `call' #. lib/gitlab/correlation_id.rb:15:in `use_id' #. lib/gitlab/middleware/correlation_id.rb:16:in `block in call' #. lib/gitlab/etag_caching/middleware.rb:13:in `call' #. lib/gitlab/middleware/go.rb:19:in `call' #. lib/gitlab/query_limiting/middleware.rb:16:in `call' #. lib/gitlab/query_limiting/transaction.rb:39:in `run' #. lib/gitlab/query_limiting/middleware.rb:17:in `block in call' #. lib/gitlab/request_profiler/middleware.rb:16:in `call' #. lib/gitlab/middleware/multipart.rb:103:in `call' #. app/controllers/application_controller.rb:420:in `set_locale' #. app/controllers/concerns/uploads_actions.rb:10:in `create' #. ![]() app/services/upload_service.rb:12:in `execute' #. app/uploaders/object_storage.rb:327:in `store!' #. app/uploaders/records_uploads.rb:26:in `record_upload' #. app/uploaders/records_uploads.rb:30:in `block in record_upload' #. ![]() app/uploaders/records_uploads.rb:30:in `tap' #. config/initializers/active_record_locking.rb:11:in `_create_record' #. config/initializers/connection_fix.rb:20:in `execute' #. So for now it appears manually locking the table is the only thing that works.Failures: 1) User uploads file to note uploading is in progress shows "Attaching 2 files" message on uploading 2 file Failure/Error: self.upload = build_upload.tap(&:save!) ActiveRecord::StatementInvalid: Mysql2::Error: Deadlock found when trying to get lock try restarting transaction: INSERT INTO `uploads` (`size`, `path`, `checksum`, `model_id`, `model_type`, `uploader`, `created_at`, `secret`, `store`) VALUES (1062, 'c96261f3ae2db692311d58a5b7be2a76/dk.png', 'b804383982bb89b00e828e3f44c038cc991d3d1768009fc39ba8e2c081b9fb75', 168, 'Project', 'FileUploader', ' 06:49:31', 'c96261f3ae2db692311d58a5b7be2a76', 1) #. WITH CONSISTENT SNAPSHOT and READ WRITE still gave me deadlock error, while READ ONLY naturally didn't even allow me to execute the INSERT. All 3 options required PDO::setAttribute(PDO::ATTR_EMULATE_PREPARES, true) to be set. Is that the only way to get this to work, or can I with 100% certainty prevent deadlocks without having to manually lock the table?ġ) Putting the query in a transaction - still deadlock errorĢ) Starting the transaction with WITH CONSISTENT SNAPSHOT, READ WRITE, READ ONLY. With that method I ran the code 4 times simultaneously, each instance inserting 2500 users, without problems. Insert into `tt_users` (`state`, `state_position`)Īnd then: PDO::setAttribute(PDO::ATTR_EMULATE_PREPARES, false) Then locking the table manually, and running my query: SET autocommit=0 The only way I managed to get this to work, and work consistently, is this (language is PHP): PDO::setAttribute(PDO::ATTR_EMULATE_PREPARES, true) I read this post - How to avoid mysql 'Deadlock found when trying to get lock try restarting transaction' but I didn't understand what I should do with my query to prevent deadlocks, if that is at all possible, since the answer to this question - Working around MySQL error "Deadlock found when trying to get lock try restarting transaction" - says deadlocks can happen no matter what. (SELECT MAX(state_position) AS maxStatePositionįor testing, I inserted a large amount of users simultaneously, and each time I got the deadlock error. This is the query I'm running that causes deadlocks: insert into `tt_users` (`state`, `state_position`) if I have 5 users with state 'x', their state_positions must be 1,2,3,4,5 State_positions must always be consecutive, and there may never be a duplicate position for a certain state, i.e. I have table tt_users which has id as primary key, and columns state (CHAR(1)), which can be "x" or "y", and state_position (INT). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |