关于Weblogic Server重启或log rotation导致server.log的 i node number变化问题
2009-09-22 00:00:00 来源:WEB开发网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内容也是个问题,于是作罢。
更多精彩
赞助商链接