代码之家  ›  专栏  ›  技术社区  ›  Jannik

死锁:插入到filetable语句中似乎会互相阻塞

  •  3
  • Jannik  · 技术社区  · 6 年前

    我们无法插入到文件表中。这是我们当前的星座,我将尽可能详细地解释它:

    基本上我们有三张桌子:

    • t_文档(文档的主要元数据)

      //This is the point where the tranaction starts
      using (IDBTransaction tran = db.GetTransaction())
      {
          try
          {
              m_commandFassade.SaveDocument(document, m_loginName, db, options, lastVersion);
              tran.Commit();
              return document;
          }
          catch
          {
              tran.Rollback();
              throw;
          }
      }
      

      public void SaveDocument(E2TDocument document, string login, IDBConnection db, DocumentUploadOptions options, int lastVersion)
      {
          document.GuardNotNull();
          options.GuardNotNull();
      
          if (lastVersion == -1)
          {
              //inserting new T_Document
              SaveDocument(document, db);
          }
          else
          {
              //updating the existing T_Document
              UpdateDocument(document, db); //document already exists, updating it
          }
      
          Guid contentID = Guid.NewGuid();
          //inserting the content
          SaveDocumentContent(document, contentID, db); 
          //inserting the new / initial version
          SaveDocumentVersion(document, contentID, db); 
      }
      

       INSERT INTO T_Content
             (stream_id
             ,file_stream
             ,name)
       VALUES
             (#ContentID
             ,#Content
             ,#Title) 
      

          private void SaveDocumentContent(E2TDocument e2TDokument, Guid contentID, IDBConnection db)
          {
              using (m_log.CreateScope<MethodScope>(GlobalDefinitions.TracePriorityForData))
              {
                  Command cmd = CommandFactory.CreateCommand("InsertContents");
                  cmd.SetParameter("ContentID", contentID);
                  cmd.SetParameter("Content", e2TDokument.Content);
                  string title = string.Concat(e2TDokument.Titel.RemoveIllegalPathCharacters(), GlobalDefinitions.UNTERSTRICH,
                      contentID).TrimToMaxLength(MaxLength_T_Contents_Col_Name, SuffixLength_T_Contents_Col_Name);
                  cmd.SetParameter("Title", title);
                  db.Execute(cmd);
              }
          }
      

      Deadlock

      set @pathlocator = convert(hierachyid, @path_locator__bin)
      

      if exists (
            select 1
                   from [LGOL_Content01].[dbo].[T_Contents]
                  where parent_path_locator = @path_locator
              )
      

    1 回复  |  直到 6 年前
        1
  •  0
  •   Jannik    6 年前

    因此,经过数小时的研究和咨询,死锁实际上是一个与FileTable/SQL Server相关的bug,微软将对此进行热修复。