久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <small id='ZjeXh'></small><noframes id='ZjeXh'>

    1. <tfoot id='ZjeXh'></tfoot>

      <i id='ZjeXh'><tr id='ZjeXh'><dt id='ZjeXh'><q id='ZjeXh'><span id='ZjeXh'><b id='ZjeXh'><form id='ZjeXh'><ins id='ZjeXh'></ins><ul id='ZjeXh'></ul><sub id='ZjeXh'></sub></form><legend id='ZjeXh'></legend><bdo id='ZjeXh'><pre id='ZjeXh'><center id='ZjeXh'></center></pre></bdo></b><th id='ZjeXh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZjeXh'><tfoot id='ZjeXh'></tfoot><dl id='ZjeXh'><fieldset id='ZjeXh'></fieldset></dl></div>
      1. <legend id='ZjeXh'><style id='ZjeXh'><dir id='ZjeXh'><q id='ZjeXh'></q></dir></style></legend>

          <bdo id='ZjeXh'></bdo><ul id='ZjeXh'></ul>

        如何避免 MySQL '嘗試獲取鎖時發現死鎖;嘗試

        How to avoid MySQL #39;Deadlock found when trying to get lock; try restarting transaction#39;(如何避免 MySQL 嘗試獲取鎖時發現死鎖;嘗試重新啟動事務)
        <legend id='lynJK'><style id='lynJK'><dir id='lynJK'><q id='lynJK'></q></dir></style></legend>

          1. <small id='lynJK'></small><noframes id='lynJK'>

              <bdo id='lynJK'></bdo><ul id='lynJK'></ul>
                <tbody id='lynJK'></tbody>
            • <i id='lynJK'><tr id='lynJK'><dt id='lynJK'><q id='lynJK'><span id='lynJK'><b id='lynJK'><form id='lynJK'><ins id='lynJK'></ins><ul id='lynJK'></ul><sub id='lynJK'></sub></form><legend id='lynJK'></legend><bdo id='lynJK'><pre id='lynJK'><center id='lynJK'></center></pre></bdo></b><th id='lynJK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lynJK'><tfoot id='lynJK'></tfoot><dl id='lynJK'><fieldset id='lynJK'></fieldset></dl></div>

                  <tfoot id='lynJK'></tfoot>
                  本文介紹了如何避免 MySQL '嘗試獲取鎖時發現死鎖;嘗試重新啟動事務'的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個記錄在線用戶的 innoDB 表.它會在用戶每次刷新頁面時更新,以跟蹤他們所在的頁面以及他們上次訪問站點的日期.然后我有一個 cron,它每 15 分鐘運行一次以刪除舊記錄.

                  I have a innoDB table which records online users. It gets updated on every page refresh by a user to keep track of which pages they are on and their last access date to the site. I then have a cron that runs every 15 minutes to DELETE old records.

                  我在嘗試獲取鎖時發現了死鎖";昨晚嘗試重新啟動事務大約 5 分鐘,似乎是在將 INSERT 運行到此表中時.有人可以建議如何避免此錯誤嗎?

                  I got a 'Deadlock found when trying to get lock; try restarting transaction' for about 5 minutes last night and it appears to be when running INSERTs into this table. Can someone suggest how to avoid this error?

                  === 編輯 ===

                  以下是正在運行的查詢:

                  Here are the queries that are running:

                  首次訪問網站:

                  INSERT INTO onlineusers SET
                  ip = 123.456.789.123,
                  datetime = now(),
                  userid = 321,
                  page = '/thispage',
                  area = 'thisarea',
                  type = 3
                  

                  在每次頁面刷新時:

                  UPDATE onlineusers SET
                  ips = 123.456.789.123,
                  datetime = now(),
                  userid = 321,
                  page = '/thispage',
                  area = 'thisarea',
                  type = 3
                  WHERE id = 888
                  

                  每 15 分鐘 Cron:

                  DELETE FROM onlineusers WHERE datetime <= now() - INTERVAL 900 SECOND
                  

                  然后它會記錄一些統計數據(即:在線成員、在線訪問者).

                  It then does some counts to log some stats (ie: members online, visitors online).

                  推薦答案

                  一個可以幫助解決大多數死鎖的簡單技巧是按特定順序對操作進行排序.

                  One easy trick that can help with most deadlocks is sorting the operations in a specific order.

                  當兩個事務試圖以相反的順序鎖定兩個鎖時,您會遇到死鎖,即:

                  You get a deadlock when two transactions are trying to lock two locks at opposite orders, ie:

                  • 連接1:鎖鑰匙(1),鎖鑰匙(2);
                  • 連接2:鎖鑰匙(2),鎖鑰匙(1);

                  如果兩者同時運行,連接 1 將鎖定 key(1),連接 2 將鎖定 key(2),并且每個連接都將等待對方釋放密鑰 ->死鎖.

                  If both run at the same time, connection 1 will lock key(1), connection 2 will lock key(2) and each connection will wait for the other to release the key -> deadlock.

                  現在,如果您更改查詢,使連接以相同的順序鎖定密鑰,即:

                  Now, if you changed your queries such that the connections would lock the keys at the same order, ie:

                  • 連接1:鎖鑰匙(1),鎖鑰匙(2);
                  • 連接2:鎖鑰匙(1),鎖鑰匙(2);
                  • connection 1: locks key(1), locks key(2);
                  • connection 2: locks key(1), locks key(2);

                  不可能陷入僵局.

                  所以這就是我的建議:

                  1. 確保除了刪除語句之外,沒有其他查詢會一次鎖定多個鍵的訪問.如果您這樣做(我懷疑您這樣做),請按升序排列 (k1,k2,..kn) 中的 WHERE.

                  1. Make sure you have no other queries that lock access more than one key at a time except for the delete statement. if you do (and I suspect you do), order their WHERE in (k1,k2,..kn) in ascending order.

                  修復您的刪除語句以按升序工作:

                  Fix your delete statement to work in ascending order:

                  改變

                  DELETE FROM onlineusers 
                  WHERE datetime <= now() - INTERVAL 900 SECOND
                  

                  DELETE FROM onlineusers 
                  WHERE id IN (
                      SELECT id FROM onlineusers
                      WHERE datetime <= now() - INTERVAL 900 SECOND 
                      ORDER BY id
                  ) u;
                  

                  要記住的另一件事是 MySQL 文檔建議,在出現死鎖的情況下,客戶端應自動重試.您可以將此邏輯添加到您的客戶端代碼中.(比如說,在放棄之前對這個特定錯誤重試 3 次).

                  Another thing to keep in mind is that MySQL documentation suggest that in case of a deadlock the client should retry automatically. you can add this logic to your client code. (Say, 3 retries on this particular error before giving up).

                  這篇關于如何避免 MySQL '嘗試獲取鎖時發現死鎖;嘗試重新啟動事務'的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                  • <bdo id='NKPoJ'></bdo><ul id='NKPoJ'></ul>

                    • <tfoot id='NKPoJ'></tfoot>

                      <small id='NKPoJ'></small><noframes id='NKPoJ'>

                          <tbody id='NKPoJ'></tbody>
                        1. <i id='NKPoJ'><tr id='NKPoJ'><dt id='NKPoJ'><q id='NKPoJ'><span id='NKPoJ'><b id='NKPoJ'><form id='NKPoJ'><ins id='NKPoJ'></ins><ul id='NKPoJ'></ul><sub id='NKPoJ'></sub></form><legend id='NKPoJ'></legend><bdo id='NKPoJ'><pre id='NKPoJ'><center id='NKPoJ'></center></pre></bdo></b><th id='NKPoJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NKPoJ'><tfoot id='NKPoJ'></tfoot><dl id='NKPoJ'><fieldset id='NKPoJ'></fieldset></dl></div>
                          <legend id='NKPoJ'><style id='NKPoJ'><dir id='NKPoJ'><q id='NKPoJ'></q></dir></style></legend>

                            主站蜘蛛池模板: 国产精品久久久久久久久久免费看 | 91视频精选 | 色婷婷国产精品 | 男女羞羞视频免费 | 日本视频免费观看 | 色网站在线免费观看 | 亚洲人成在线播放 | 日韩精品久久久 | 欧美日韩视频一区二区 | 日本三级在线 | 中文字幕久久久 | 精品国产伦一区二区三区观看方式 | 欧美电影免费网站 | 日韩久久久久 | 亚州春色| 91精品国模一区二区三区 | 国产精品视频偷伦精品视频 | 国产精品免费小视频 | 综合精品| 日韩综合一区 | 手机在线一区二区三区 | 超碰97av | 激情久久av一区av二区av三区 | 自拍视频网站 | 中文天堂在线一区 | 亚洲视频在线一区 | 欧美在线一区二区三区 | 精品一区二区三区免费毛片 | aaaaaaa片毛片免费观看 | 日韩在线视频一区 | 亚洲精品在线视频 | 久久蜜桃精品 | 日本久久一区二区三区 | 日本天堂一区 | 狠狠综合网| 日韩中出 | 国产精品嫩草影院精东 | 亚洲高清一区二区三区 | 成人国产一区二区三区精品麻豆 | 国产亚洲二区 | 国产精品有限公司 |