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

Tomek Rękawek commented on OAK-3645:
------------------------------------

Also, I wonder if we shouldn't change the time difference resolution to 
seconds. We got a number of seconds*1000 from the DB and then we compare it to 
number of millis from the local machine. As a result, even on a embedded 
database, the time diff varies from 0 to 999 millis (as the milliseconds are 
truncated on the database timestamp).

Maybe we should compare seconds and then multiply the difference by 1000 to be 
consistent with the method contract? Something like:
{code}
stmt = connection.prepareStatement(sql);
long start = System.currentTimeMillis() / 1000;
rs = stmt.executeQuery();
if (rs.next()) {
    long roundtrip = System.currentTimeMillis() / 1000 - start;
    long serverTime = rs.getInt(1);
    long roundedTime = start + roundtrip / 2;
    result = roundedTime - serverTime;
    String msg = String.format("instance timestamp: %d, DB timestamp: %d, 
difference: %d", roundedTime, serverTime,
            result);
    System.err.println(msg);
    if (Math.abs(result) >= 2) {
        LOG.info(msg);
    } else {
        LOG.debug(msg);
    }
} else {
    throw new DocumentStoreException("failed to determine server timestamp");
}
return result * 1000;
{code}

> RDBDocumentStore: server time detection for DB2 fails due to timezone/dst 
> differences
> -------------------------------------------------------------------------------------
>
>                 Key: OAK-3645
>                 URL: https://issues.apache.org/jira/browse/OAK-3645
>             Project: Jackrabbit Oak
>          Issue Type: Technical task
>          Components: rdbmk
>    Affects Versions: 1.3.10, 1.2.8, 1.0.24
>            Reporter: Julian Reschke
>            Assignee: Tomek Rękawek
>         Attachments: OAK-3645-jr.patch, OAK-3645.patch
>
>
> We use {{CURRENT_TIMESTAMP(4)}} to ask the DB for it's system time.
> Apparently, at least with DB2, this might return a value that is off by a 
> multiple of one hour (3600 * 1000ms) depending on whether the OAK instance 
> and the DB run in different timezones.
> Known to work: both on the same machine.
> Known to fail: OAK in CET, DB2 in UTC, in which case we're getting a 
> timestamp one hour in the past.
> At this time it's not clear whether the same problem occurs for other 
> databases.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to