久久久久久久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>

                            主站蜘蛛池模板: 性色的免费视频 | 亚洲一区二区在线 | 欧美在线视频一区二区 | 日韩在线大片 | 国产精品久久久久无码av | 欧美久久久 | 桃色五月 | 伦理二区 | 国产精品伦一区二区三级视频 | 欧美最猛性xxxxx亚洲精品 | 日韩精品在线观看网站 | 黄色网址在线免费观看 | 91精品国产欧美一区二区 | 毛片a级毛片免费播放100 | 久国久产久精永久网页 | 久久久国产一区 | 国产成人精品免费视频大全最热 | 成人午夜免费在线视频 | 好婷婷网 | 成人亚洲精品 | 久久成人国产精品 | 男女av| 天天亚洲 | 国产免费又黄又爽又刺激蜜月al | 成人精品视频99在线观看免费 | 青青操av| 91原创视频 | 精品视频一区二区三区在线观看 | 天天色官网 | 亚洲精品视频免费 | 中文成人无字幕乱码精品 | 日本精品一区二区 | 四虎影院免费在线播放 | 99久久免费精品视频 | 亚洲视频在线观看 | 欧美一区二区三区在线 | 日本福利一区 | 日韩av黄色| 综合国产在线 | 日韩在线国产 | 国偷自产av一区二区三区 |