You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Stepan Mishura <st...@gmail.com> on 2006/09/01 02:23:17 UTC

Re: [classlib][logging] A non bug difference from RI?

On 8/31/06, Stepan Mishura wrote:
>
>  On 8/30/06, Andrew Zhang  wrote:
>
> > <SNIP>
>
>
> > > > If I understoond correctly, new FileHandler() creates temporary file
> > for
> > > > logging (its name is defined by default configuration properties).
> > That
> > > is
> > > > true for Harmony and RI. Right?
> > >
> > >
> > > Stepan, you missed something here. :)
> > > Both Harmony and RI creates a file (not temporary) for logging, and RI
> > > created one more file(temporary) for locking.
> > > RI tries to delete the temporary .lck file when fileHandler.close ()
> is
> > > invoked. Harmony has nothing to be deleted. :)
> >
> >
> > IOW, Harmony uses different locking approach for log-files and the test
> > above demonstrate side-effect of different approaches. Right?
>
>
> Yes, exatcly.
>
> IMO, we should add a note to the documentation: why we chose different
> > locking approach.
>
>
> Rather than adding a note to source code, I think it's more helpful to
> document the difference on the test.
>
> Yes, documenting our implementation design is helpful, but I think there's
> no need to document the design differences between Harmony and RI.
>
> We don't care the design and implementation of RI, do we? So I suggest
> document some words on the test case, like "RI fails here because ....".
>
> Comments/objections? Thanks!
>
>
> BTW, if two VMs tries to open the same file for logging how this conflict
> is resolved by Harmony if there is not lock file?
>
>

It seems that nobody understood the question. OK, I'll try to put the
question in other words: if there is 2 VM running on the same machine and on
both VMs new FileHandler() is invoked then there is a files conflict. And it
is possible to resolve such kind of conflict only by creating lock-file.
Right?

Thanks,
Stepan.


>
>
> > >
> > > > RI tries to delete the created file if FileHandler.close() is
> > invoked.
> > > And
> > > > > Harmony doesn't. Why?
> > > > >
> > > > > Thanks,
> > > > > Stepan.
> > > > >
> > > > > If we revise the MockSecurityManager a little, to allow .lck file
> > > > > > permission,
> > > > > >
> > > > > >    public void checkPermission(Permission perm) {
> > > > > >            if (perm instanceof FilePermission) {
> > > > > >                if (perm.getName().indexOf(".lck") == -1) {
> > > > > >                    System.out.println("check " + perm.getName
> > ());
> > > > > >                    throw new SecurityException();
> > > > > >                }
> > > > > >            }
> > > > > >        }
> > > > > >
> > > > > > The test will pass both against RI and Harmony.
> > > > > >
> > > > > > So I'd suggest to leave it as "non-bug difference from RI".
> > > > > >
> > > > > > Any comments? Thank you!
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Andrew Zhang
> > > > > > China Software Development Lab, IBM
> >
> >
------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Re: [classlib][logging] A non bug difference from RI?

Posted by Paulex Yang <pa...@gmail.com>.
Stepan Mishura wrote:
> On 9/1/06, Paulex Yang wrote:
>>
>> Stepan Mishura wrote:
>> > Andrew, thanks for the test. But working test doesn't mean that there
>> > is no
>> > bug :-)
>> >
>> > AFAIK in our case an operation on file (if file is not exist  - create
>> > file)
>> > should be atomic. And it looks like Harmony implementation doesn't 
>> do in
>> > atomic way.(see FileHandler.initOutputFiles() method)
>> Seems there is a bug in the FileHandler.initOutputFiles(), in Ln. 232,
>> if the FileLock isn't held, the FileOutputStream should be closed before
>> continue.
>>
>> <code>
>>                lock = channel.tryLock();
>>                if (null == lock) {
>>                   //the FileChannel(or FileOutputStream) should be
>> closed here
>>                    continue;
>>                }
>> </code>
>
>
> BTW, why FileNotFoundException is re-thrown  in Ln. 223 ? IMO, try-catch
> block should be deleted.
>
>                try {
>                    fileStream = new FileOutputStream(fileName, append);
>                    channel = fileStream.getChannel();
>                } catch(FileNotFoundException e){
>                    //invalid path name, throw exception
>                    throw e;
>                }
Agree, fixed at revision r440292.
>
>
> But I didn't catch up what's the "atomic" means here, do you mean the
>> tryLock() is not atomic or sth.? If so, any other solutions for Java
>> codes? Otherwise, I think current implementation is fine, if two process
>> try to open same log file at same time, only one process can get the
>> lock by tryLock(), and the other will close the FileOutputStream then
>> continue to try another log file name, anything I missed?
>
>
> I was confused by gaps in code between File.exists(), new 
> FileOutputStream()
> and FileChannel.tryLock().
>
> For example, I've tried to emulate the following situation:
> A process VM_1 is up to lock a created file (Ln.230) and in this time a
> process VM_2 found out that the file exists and deleted it (Ln.213). My
> current result is that the file is locked successfully but may be I
> incorrectly emulated situation. I'm going to continue experimenting 
> and let
> you know if it is possible to create reproducible files conflict.
>
> Thanks,
> Stepan Mishura
> Intel Middleware Products Division
>
> ------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>


-- 
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][logging] A non bug difference from RI?

Posted by Stepan Mishura <st...@gmail.com>.
On 9/1/06, Paulex Yang wrote:
>
> Stepan Mishura wrote:
> > Andrew, thanks for the test. But working test doesn't mean that there
> > is no
> > bug :-)
> >
> > AFAIK in our case an operation on file (if file is not exist  - create
> > file)
> > should be atomic. And it looks like Harmony implementation doesn't do in
> > atomic way.(see FileHandler.initOutputFiles() method)
> Seems there is a bug in the FileHandler.initOutputFiles(), in Ln. 232,
> if the FileLock isn't held, the FileOutputStream should be closed before
> continue.
>
> <code>
>                lock = channel.tryLock();
>                if (null == lock) {
>                   //the FileChannel(or FileOutputStream) should be
> closed here
>                    continue;
>                }
> </code>


BTW, why FileNotFoundException is re-thrown  in Ln. 223 ? IMO, try-catch
block should be deleted.

                try {
                    fileStream = new FileOutputStream(fileName, append);
                    channel = fileStream.getChannel();
                } catch(FileNotFoundException e){
                    //invalid path name, throw exception
                    throw e;
                }


But I didn't catch up what's the "atomic" means here, do you mean the
> tryLock() is not atomic or sth.? If so, any other solutions for Java
> codes? Otherwise, I think current implementation is fine, if two process
> try to open same log file at same time, only one process can get the
> lock by tryLock(), and the other will close the FileOutputStream then
> continue to try another log file name, anything I missed?


I was confused by gaps in code between File.exists(), new FileOutputStream()
and FileChannel.tryLock().

For example, I've tried to emulate the following situation:
A process VM_1 is up to lock a created file (Ln.230) and in this time a
process VM_2 found out that the file exists and deleted it (Ln.213). My
current result is that the file is locked successfully but may be I
incorrectly emulated situation. I'm going to continue experimenting and let
you know if it is possible to create reproducible files conflict.

Thanks,
Stepan Mishura
Intel Middleware Products Division

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Re: [classlib][logging] A non bug difference from RI?

Posted by Paulex Yang <pa...@gmail.com>.
Stepan Mishura wrote:
> Andrew, thanks for the test. But working test doesn't mean that there 
> is no
> bug :-)
>
> AFAIK in our case an operation on file (if file is not exist  - create 
> file)
> should be atomic. And it looks like Harmony implementation doesn't do in
> atomic way.(see FileHandler.initOutputFiles() method)
Seems there is a bug in the FileHandler.initOutputFiles(), in Ln. 232, 
if the FileLock isn't held, the FileOutputStream should be closed before 
continue.

<code>
                lock = channel.tryLock();
                if (null == lock) {
                   //the FileChannel(or FileOutputStream) should be 
closed here
                    continue;
                }
</code>

But I didn't catch up what's the "atomic" means here, do you mean the 
tryLock() is not atomic or sth.? If so, any other solutions for Java 
codes? Otherwise, I think current implementation is fine, if two process 
try to open same log file at same time, only one process can get the 
lock by tryLock(), and the other will close the FileOutputStream then 
continue to try another log file name, anything I missed?
>
> Thanks,
> Stepan.
>


-- 
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [classlib][logging] A non bug difference from RI?

Posted by Stepan Mishura <st...@gmail.com>.
On 9/1/06, Andrew Zhang wrote:
>
> On 9/1/06, Stepan Mishura  wrote:
> <SNIP>
> OK, I'll try to put the
> > question in other words: if there is 2 VM running on the same machine
> and
> > on
> > both VMs new FileHandler() is invoked then there is a files conflict.
> And
> > it
> > is possible to resolve such kind of conflict only by creating lock-file.
>
>
> RI output:
> a a.1 a.lck a.1.lck
>
> Harmony output
> a a.1
>
> The test case is simple if you'd like to try, just run two times, and
> check
> the log file in your disk.
> public void test_FileHandler() throws Exception {
>        FileHandler handler = new FileHandler("a");
>        handler.publish(new LogRecord(Level.SEVERE, "msg"));
>        int count = 0;
>        while (count++ < 60) {
>            Thread.sleep(1000);
>        }
>        handler.close();
>    }


Andrew, thanks for the test. But working test doesn't mean that there is no
bug :-)

AFAIK in our case an operation on file (if file is not exist  - create file)
should be atomic. And it looks like Harmony implementation doesn't do in
atomic way.(see FileHandler.initOutputFiles() method)

Thanks,
Stepan.

>
> > Thanks,
> > Stepan.
> >
> >
> > >
> > >
> > > > >
> > > > > > RI tries to delete the created file if FileHandler.close() is
> > > > invoked.
> > > > > And
> > > > > > > Harmony doesn't. Why?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Stepan.
> > > > > > >
> > > > > > > If we revise the MockSecurityManager a little, to allow .lck
> > file
> > > > > > > > permission,
> > > > > > > >
> > > > > > > >    public void checkPermission(Permission perm) {
> > > > > > > >            if (perm instanceof FilePermission) {
> > > > > > > >                if (perm.getName().indexOf(".lck") == -1) {
> > > > > > > >                    System.out.println("check " +
> perm.getName
> > > > ());
> > > > > > > >                    throw new SecurityException();
> > > > > > > >                }
> > > > > > > >            }
> > > > > > > >        }
> > > > > > > >
> > > > > > > > The test will pass both against RI and Harmony.
> > > > > > > >
> > > > > > > > So I'd suggest to leave it as "non-bug difference from RI".
> > > > > > > >
> > > > > > > > Any comments? Thank you!
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Andrew Zhang
> > > > > > > > China Software Development Lab, IBM
>
>
------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Re: [classlib][logging] A non bug difference from RI?

Posted by Andrew Zhang <zh...@gmail.com>.
On 9/1/06, Stepan Mishura <st...@gmail.com> wrote:
>
> On 8/31/06, Stepan Mishura wrote:
> >
> >  On 8/30/06, Andrew Zhang  wrote:
> >
> > > <SNIP>
> >
> >
> > > > > If I understoond correctly, new FileHandler() creates temporary
> file
> > > for
> > > > > logging (its name is defined by default configuration properties).
> > > That
> > > > is
> > > > > true for Harmony and RI. Right?
> > > >
> > > >
> > > > Stepan, you missed something here. :)
> > > > Both Harmony and RI creates a file (not temporary) for logging, and
> RI
> > > > created one more file(temporary) for locking.
> > > > RI tries to delete the temporary .lck file when fileHandler.close ()
> > is
> > > > invoked. Harmony has nothing to be deleted. :)
> > >
> > >
> > > IOW, Harmony uses different locking approach for log-files and the
> test
> > > above demonstrate side-effect of different approaches. Right?
> >
> >
> > Yes, exatcly.
> >
> > IMO, we should add a note to the documentation: why we chose different
> > > locking approach.
> >
> >
> > Rather than adding a note to source code, I think it's more helpful to
> > document the difference on the test.
> >
> > Yes, documenting our implementation design is helpful, but I think
> there's
> > no need to document the design differences between Harmony and RI.
> >
> > We don't care the design and implementation of RI, do we? So I suggest
> > document some words on the test case, like "RI fails here because ....".
> >
> > Comments/objections? Thanks!
> >
> >
> > BTW, if two VMs tries to open the same file for logging how this
> conflict
> > is resolved by Harmony if there is not lock file?
> >
> >
>
> It seems that nobody understood the question.


No. Your description is very clear, but I was on vacation yesterday.

OK, I'll try to put the
> question in other words: if there is 2 VM running on the same machine and
> on
> both VMs new FileHandler() is invoked then there is a files conflict. And
> it
> is possible to resolve such kind of conflict only by creating lock-file.


RI output:
a a.1 a.lck a.1.lck

Harmony output
a a.1

The test case is simple if you'd like to try, just run two times, and check
the log file in your disk.
  public void test_FileHandler() throws Exception {
        FileHandler handler = new FileHandler("a");
        handler.publish(new LogRecord(Level.SEVERE, "msg"));
        int count = 0;
        while (count++ < 60) {
            Thread.sleep(1000);
        }
        handler.close();
    }

Right?
>
> Thanks,
> Stepan.
>
>
> >
> >
> > > >
> > > > > RI tries to delete the created file if FileHandler.close() is
> > > invoked.
> > > > And
> > > > > > Harmony doesn't. Why?
> > > > > >
> > > > > > Thanks,
> > > > > > Stepan.
> > > > > >
> > > > > > If we revise the MockSecurityManager a little, to allow .lck
> file
> > > > > > > permission,
> > > > > > >
> > > > > > >    public void checkPermission(Permission perm) {
> > > > > > >            if (perm instanceof FilePermission) {
> > > > > > >                if (perm.getName().indexOf(".lck") == -1) {
> > > > > > >                    System.out.println("check " + perm.getName
> > > ());
> > > > > > >                    throw new SecurityException();
> > > > > > >                }
> > > > > > >            }
> > > > > > >        }
> > > > > > >
> > > > > > > The test will pass both against RI and Harmony.
> > > > > > >
> > > > > > > So I'd suggest to leave it as "non-bug difference from RI".
> > > > > > >
> > > > > > > Any comments? Thank you!
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Andrew Zhang
> > > > > > > China Software Development Lab, IBM
> > >
> > >
> ------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Andrew Zhang
China Software Development Lab, IBM