Just a quick thing I noticed while looking at this again: this won't prevent 
conflicts in multi-server deployments.

-David


On Dec 7, 2009, at 7:00 AM, jler...@apache.org wrote:

> Author: jleroux
> Date: Mon Dec  7 13:00:09 2009
> New Revision: 887916
> 
> URL: http://svn.apache.org/viewvc?rev=887916&view=rev
> Log:
> A patch from Adrian Crum "ServerHit aborts transactions when trying to create 
> entries with duplicate startTime(s)." 
> (https://issues.apache.org/jira/browse/OFBIZ-2208) - OFBIZ-2208
> This add synchronization for ServerHit entities creation. Hence startTime is 
> no longer used. 
> I have also removed some comment about the problem, and added one for 
> startTime no longer used.
> 
> Note: If synchronization proves to slow down sites we could introduce a 
> properties in serverstats.properties to switch from using it or not since I 
> did not remove startTime from the method signature
> Then we will use one or the other lines
> -            serverHit.set("hitStartDateTime", new 
> java.sql.Timestamp(startTime));
> +            serverHit.set("hitStartDateTime", getNowTimestamp());
> 
> Modified:
>    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
> 
> Modified: 
> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java?rev=887916&r1=887915&r2=887916&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java 
> (original)
> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java 
> Mon Dec  7 13:00:09 2009
> @@ -618,7 +618,7 @@
>             GenericValue serverHit = delegator.makeValue("ServerHit");
> 
>             serverHit.set("visitId", visitId);
> -            serverHit.set("hitStartDateTime", new 
> java.sql.Timestamp(startTime));
> +            serverHit.set("hitStartDateTime", getNowTimestamp()); // A 
> change was introduced with https://issues.apache.org/jira/browse/OFBIZ-2208. 
> Since then startTime is not used anymore 
>             serverHit.set("hitTypeId", ServerHitBin.typeIds[this.type]);
>             if (userLogin != null) {
>                 serverHit.set("userLoginId", userLogin.get("userLoginId"));
> @@ -651,27 +651,15 @@
>                 Debug.logError("Unable to get localhost internet address: " + 
> e.toString(), module);
>             }
> 
> -            // The problem with
> -            //
> -            //     serverHit.create();
> -            //
> -            // is that if there are two requests with the same startTime 
> (this should only happen with MySQL see 
> https://issues.apache.org/jira/browse/OFBIZ-2208)
> -            // then this will go wrong and abort the actual
> -            // transaction we are interested in.
> -            // Another way instead of using create is to store or update,
> -            // that is overwrite in case there already was an entry, thus
> -            // avoiding the transaction being aborted which is not
> -            // less desirable than having multiple requests with the
> -            // same startTime overwriting each other.
> -            // This may not satisfy those who want to record each and
> -            // every server hit even with equal startTimes but that could be
> -            // solved adding a counter to the ServerHit's PK (a counter
> -            // counting multiple hits at the same startTime).
>             try {
>                 serverHit.create();
>             } catch (GenericEntityException e) {
> -                Debug.logError(e, "Could not save ServerHit:", module);
> +                Debug.logError(e, "Could not save ServerHit: ", module);
>             }
>         }
>     }
> +    
> +    public synchronized java.sql.Timestamp getNowTimestamp() {
> +        return new java.sql.Timestamp(System.currentTimeMillis());
> +    }
> }
> 
> 

Reply via email to