ilovesoup / hyracks

Automatically exported from code.google.com/p/hyracks
Apache License 2.0
0 stars 0 forks source link

race condition in BufferCache.invalidateIfFileIdMatch() #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The BufferCache.invalidateIfFileIdMatch() could have some race condition due to 
read/write is not in synchronized block.

Alex proposed this fix (so far it works in hyracks_giraph branch):

private boolean invalidateIfFileIdMatch(int fileId, CachedPage cPage, boolean 
flushDirty)
            throws HyracksDataException {
        if (BufferedFileHandle.getFileId(cPage.dpid) == fileId) {
            if (cPage.dirty.get()) {
                if (flushDirty) {
                    write(cPage);
                }
                cPage.dirty.set(false);
                int newPinCount = cPage.pinCount.decrementAndGet();
                if (newPinCount != 0) {
                    throw new IllegalStateException("Page is pinned and file is being closed");
                }
            } else {
                if (cPage.pinCount.get() != 0) {
                    throw new IllegalStateException("Page is pinned and file is being closed");
                }
            }
            cPage.invalidate();
            return true;
        }
        return false;
    }

Original issue reported on code.google.com by buyingyi@gmail.com on 15 Nov 2011 at 11:09

GoogleCodeExporter commented 9 years ago
Nice one!

Fixed it in my hyracks_btree_updates_next branch which is going to be merged 
into hyracks_dev_next soon.

Original comment by alexande...@gmail.com on 16 Nov 2011 at 5:35