[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-1366?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13189573#comment-13189573
 ] 

Ted Dunning commented on ZOOKEEPER-1366:
----------------------------------------

For the test, I have created a branch in my github fork of zookeeper called 
timer-test and one called ZK-1366.  Both have the test case below but only 
ZK-1366 has the fix.

The test procedure is to do this in one window:
{code}
git checkout timer-test
ant clean compile-test
echo build/test/lib/*.jar build/lib/*.jar build/classes build/test/classes | 
sed -e 's/ /:/g' > cp
java -cp $(cat cp) org.apache.zookeeper.common.TimeTest | tee log-without-patch
{code}
After the test program starts, in a second window, do these commands separated 
by a second or three
{code}
date -s '+1hour'
date -s '-1hour'
{code}
This will produce output that looks like this
{code}
ubuntu@ip-10-113-27-85:~/zookeeper$ java -cp $(cat cp) 
org.apache.zookeeper.common.TimeTest | tee log-without-patch
1
log4j:WARN No appenders could be found for logger 
(org.apache.zookeeper.PortAssignment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
after construct
server start
client
1       true
1       true
0       true
1       true
3600000 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Disconnected type:None path:null
3600001 event = WatchedEvent state:Expired type:None path:null
3600001 event = WatchedEvent state:Expired type:None path:null
3600001 event = WatchedEvent state:Expired type:None path:null
3600001 event = WatchedEvent state:Expired type:None path:null
3600001 event = WatchedEvent state:Expired type:None path:null
{code}
The number is the time discrepancy between the system clock and the elapsed 
time from start of the program.

With the patch,
{code}
git checkout ZK-1366
ant clean compile-test
echo build/test/lib/*.jar build/lib/*.jar build/classes build/test/classes | 
sed -e 's/ /:/g' > cp
java -cp $(cat cp) org.apache.zookeeper.common.TimeTest | tee log-with-patch
{code}
The output looks like this:
{code}
ubuntu@ip-10-113-27-85:~/zookeeper$ less log-with-patch 
1
after construct
server start
client
0       true
0       true
1       true
0       true
1       true
0       true
0       true
3600000 true
3600000 true
3600000 true
3600000 true
0       true
0       true
0       true
0       true
-3600000        true
-3600001        true
-3600000        true
-1      true
-1      true
-1      true
-1      true
{code}
As you can see, the timing discrepancy goes up and down but the ephemerals 
never disappear.

I will update the patch shortly to match the ZK-1366 branch on my github clone.
                
> Zookeeper should be tolerant of clock adjustments
> -------------------------------------------------
>
>                 Key: ZOOKEEPER-1366
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1366
>             Project: ZooKeeper
>          Issue Type: Bug
>            Reporter: Ted Dunning
>             Fix For: 3.4.3
>
>         Attachments: ZOOKEEPER-1366.patch, ZOOKEEPER-1366.patch
>
>
> If you want to wreak havoc on a ZK based system just do [date -s "+1hour"] 
> and watch the mayhem as all sessions expire at once.
> This shouldn't happen.  Zookeeper could easily know handle elapsed times as 
> elapsed times rather than as differences between absolute times.  The 
> absolute times are subject to adjustment when the clock is set while a timer 
> is not subject to this problem.  In Java, System.currentTimeMillis() gives 
> you absolute time while System.nanoTime() gives you time based on a timer 
> from an arbitrary epoch.
> I have done this and have been running tests now for some tens of minutes 
> with no failures.  I will set up a test machine to redo the build again on 
> Ubuntu and post a patch here for discussion.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to