mff-uk / odcs

ODCleanStore
1 stars 11 forks source link

Pipeline up-to-date depends on timestamp #1160

Open ghost opened 10 years ago

ghost commented 10 years ago

See the code in PipelineFacadeImpl:

    /**
     * Checks if (possibly detached) pipeline has been modified by someone else.
     * 
     * @param pipeline to check
     * @return true if pipeline was changed while detached from entity manager,
     *          false otherwise
     */
    @Override
    public boolean isUpToDate(Pipeline pipeline) {
        LOG.trace("isUpToDate({})", pipeline.getId());
        if (pipeline.getId() == null) {
            // new pipeline -> lets say it is up-to-date
            return true;
        }

        // fetch fresh pipeline from db
        Pipeline dbPipeline = getPipeline(pipeline.getId());
        if (dbPipeline == null) {
            // someone probably deleted pipeline in the meantime
            // -> lets say it is NOT up-to-date
            return false;
        }

        Date lastChange = dbPipeline.getLastChange();
                Date myLastChange = pipeline.getLastChange();
        return lastChange == null ? true :
                        myLastChange == null ? false : !lastChange.after(myLastChange);
    }

It uses timestamps to check if something is up-to-date. This can lead (especially on Windows OS) to errors. It is possible to hit the same timestamp value. I have seen (in practice) situations where new Date() was generating only 4 distinct timestamp values per second. Lets use Lamport timestamps. Moreover, there are dead branches I think. dbPipeline can never be null in my opinion lastChange can never be null in my opinion