posts - 42,comments - 83,trackbacks - 0
                  前兩天同事問我一個問題,說是客戶那邊使用Tivoli分析weblogic server日志的時候,每當server重啟,Tivoli就出錯,說是FileId is changed。當時就懷疑可能跟server log的iNodeNumber有關。因為沒怎么仔細看過weblogic server logging的代碼,也不是很確認。跟同事說,讓客戶通過 ls -i 確認一下對應的iNodeNumber。客戶反饋說:iNodeNumber沒有發生變化,崩潰,文件名沒變, iNodeNumber沒變,Tivoli說的FileId到底是什么? FileSystem里還有其他標識文件的東西?我有點開始懷疑這個客戶了,嘿嘿。 索性,自己做個測試吧。

                  首先看了看weblogic的代碼,log rotation的時候,只是調用了File.renameTo(),  如下:
                  weblogic.loggin.FileStreamHandler.rotateLog()
                  logFile.renameTo(rotatedFile)

                  見鬼了, rename完了iNodeNumber還有不變的道理?看看JDK代碼再說,
                  
           File.renameTo()
          1     public boolean renameTo(File dest) {
          2                 SecurityManager security = System.getSecurityManager();
          3                 if (security != null) {
          4                     security.checkWrite(path);
          5                     security.checkWrite(dest.path);
          6                 }
          7                 return fs.rename(this, dest);
          8     }

                  這家伙,還是依賴于FileSystem的,再一看,FileSystem是個抽象類,rename的具體實現肯定跟具體的subclass有關了,只能看看Win32FileSystem吧,

          Win32FileSystem.java
           1     public boolean rename(File f1, File f2) {
           2         // Keep canonicalization caches in sync after file deletion
           3         // and renaming operations. Could be more clever than this
           4         // (i.e., only remove/update affected entries) but probably
           5         // not worth it since these entries expire after 30 seconds
           6         // anyway.
           7         cache.clear();
           8         prefixCache.clear();
           9         return rename0(f1, f2);
          10     }
          11     private native boolean rename0(File f1, File f2);

                 好了,現在看到了,rename0()是個native 操作,跟共享庫(.dll or .so)又扯上關系了。得, 沒有本地庫代碼,也看不到什么實現了(不過個人感覺,本地實現調用應該是系統函數rename:  int rename(const char *old, const char *new)),只能自己做實現了。寫了個小測試程序, 如下:
           
           1 package com.bea.cs.test.file;
           2 
           3 import java.io.File;
           4 
           5 public class FileTest {
           6     
           7     private File src = new File("test");
           8     
           9     public static void main(String args[])
          10     {
          11         FileTest test = new FileTest();
          12         test.run();
          13     }
          14     
          15     public void run()
          16     {
          17         rename("test1");
          18     }
          19     
          20     private boolean rename(String name)
          21     {
          22         boolean ret = false;
          23         File dest = new File(name);
          24         ret = src.renameTo(dest);
          25         /*
          26          * as src is renamed to dest, dest should hold the iNodeNumber of src
          27          */
          28         src = new File("test");
          29         try
          30         {
          31             /*
          32              * As has been renamed to dest, src should not exist again
          33              * so we should create a new src file, or it will disappear when
          34              * test exits. As a new file, src shuold get a new iNodeNumber
          35              * that different from it's original value
          36              */
          37             if(!src.exists())
          38                 src.createNewFile();
          39         }catch(Exception e)
          40         {
          41             e.printStackTrace();
          42         }
          43         return ret;
          44     }
          45 }

          測試的結果如下:
          Test Reustlslsol6% ls -il
          total 8
             6033508 drwxr-xr-x   3 fjin     staff       4096 Sep 26 23:48 com
             6033514 -rw-r--r--   1 fjin     staff          0 Sep 26 23:56 test
          slsol6% java com.bea.cs.test.file.FileTest
          slsol6% ls -il
          total 8
             6033508 drwxr-xr-x   3 fjin     staff       4096 Sep 26 23:48 com
             6033506 -rw-r--r--   1 fjin     staff          0 Sep 27 01:03 test
             6033514 -rw-r--r--   1 fjin     staff          0 Sep 26 23:56 test1


                   現在我這能懷疑客戶了, Tivoli報錯應該是正常的(Work as design),不過比較納悶的是:Tivoli為什么要引用FileId,而不是FileName? 開始想改改weblogic的代碼,調用類似于copy的操作,而不是rename。結果沒有看到File提供類似的API,而且如果這樣做的話,清空原先file內容也是個問題,于是作罷。
                  
          posted on 2008-09-27 14:05 走走停停又三年 閱讀(2194) 評論(0)  編輯  收藏 所屬分類: Weblogic
          主站蜘蛛池模板: 交口县| 调兵山市| 罗江县| 文昌市| 弥勒县| 辉县市| 文安县| 新兴县| 晋江市| 资源县| 仪陇县| 遵义县| 渭源县| 涞水县| 阜城县| 呼图壁县| 册亨县| 曲水县| 罗田县| 常州市| 扶沟县| 宁德市| 娱乐| 海南省| 永泰县| 长武县| 岳阳县| 隆尧县| 山东省| 千阳县| 江口县| 邢台市| 桑植县| 于田县| 甘南县| 安丘市| 西平县| 蓬溪县| 水城县| 宜川县| 马龙县|