~nwilliams/akiban-persistit/fix_912514_fetchAndRemove_2

« back to all changes in this revision

Viewing changes to src/main/java/com/persistit/Exchange.java

  • Committer: Nathan Williams
  • Date: 2012-05-29 19:15:06 UTC
  • Revision ID: nwilliams@akiban.com-20120529191506-osg2kum89atgiood
Minor refactoring of fetchInternal into two methods to reduce new duplication in storeInternal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1477
1477
 
1478
1478
                            if (doFetch) {
1479
1479
                                spareValue.copyTo(_spareValue);
1480
 
                                if (!_ignoreMVCCFetch) {
1481
 
                                    if (MVV.isArrayMVV(_spareValue.getEncodedBytes(), 0, _spareValue.getEncodedSize())) {
1482
 
                                        buffer.enqueuePruningAction(_tree.getHandle());
1483
 
                                        if (mvccFetch(_spareValue, Integer.MAX_VALUE)) {
1484
 
                                            fetchFixupForLongRecords(_spareValue, Integer.MAX_VALUE);
1485
 
                                        }
1486
 
                                    }
1487
 
                                    if (_spareValue.isDefined() && _spareValue.isAntiValue()) {
1488
 
                                        _spareValue.clear();
1489
 
                                    }
1490
 
                                }
 
1480
                                fetchFromValueInternal(_spareValue, Integer.MAX_VALUE, buffer);
1491
1481
                            }
1492
1482
                        }
1493
1483
 
2148
2138
                        index = _key.getEncodedSize();
2149
2139
 
2150
2140
                        if (matches) {
2151
 
                            matches = fetchInternal(buffer, outValue, foundAt, minimumBytes);
 
2141
                            matches = fetchFromBufferInternal(buffer, outValue, foundAt, minimumBytes);
2152
2142
                            if (!matches && direction != EQ) {
2153
2143
                                nudged = false;
2154
2144
                                nudgeForMVCC = (direction == GTEQ || direction == LTEQ);
2168
2158
                        if (matches) {
2169
2159
                            index = _key.nextElementIndex(parentIndex);
2170
2160
                            if (index > 0) {
2171
 
                                boolean isVisibleMatch = fetchInternal(buffer, outValue, foundAt, minimumBytes);
 
2161
                                boolean isVisibleMatch = fetchFromBufferInternal(buffer, outValue, foundAt, minimumBytes);
2172
2162
                                //
2173
2163
                                // In any case (matching sibling, child or
2174
2164
                                // niece/nephew) we need to ignore this
2735
2725
        if (minimumBytes < 0) {
2736
2726
            minimumBytes = 0;
2737
2727
        }
2738
 
        fetchInternal(value, minimumBytes);
 
2728
        searchAndFetchInternal(value, minimumBytes);
2739
2729
        return this;
2740
2730
    }
2741
2731
 
2756
2746
     *             As thrown from any internal method.
2757
2747
     * @return <code>true</code> if the value was visible.
2758
2748
     */
2759
 
    private boolean fetchInternal(Buffer buffer, Value value, int foundAt, int minimumBytes) throws PersistitException {
 
2749
    private boolean fetchFromBufferInternal(Buffer buffer, Value value, int foundAt, int minimumBytes) throws PersistitException {
 
2750
        buffer.fetch(foundAt, value);
 
2751
        return fetchFromValueInternal(value, minimumBytes, buffer);
 
2752
    }
 
2753
 
 
2754
    /**
 
2755
     * Helper for finalizing the value to return from a, potentially, MVV
 
2756
     * contained in the given Value.
 
2757
     *
 
2758
     * @param value
 
2759
     *            Value to finalize.
 
2760
     * @param minimumBytes
 
2761
     *            Minimum amount of LONG_RECORD to fetch. If &lt;0, the
 
2762
     *            <code>value</code> will contain just the descriptor portion.
 
2763
     * @param bufferForPruning
 
2764
     *            If not <code>null</code> and <code>Value</code> did contain
 
2765
     *            an MVV, call {@link Buffer#enqueuePruningAction(int)}.
 
2766
     * @throws PersistitException
 
2767
     *             As thrown from any internal method.
 
2768
     * @return <code>true</code> if the value was visible.
 
2769
     */
 
2770
    private boolean fetchFromValueInternal(Value value, int minimumBytes, Buffer bufferForPruning) throws PersistitException {
2760
2771
        boolean visible = true;
2761
 
        buffer.fetch(foundAt, value);
2762
2772
        /*
2763
2773
         * We must fetch the full LONG_RECORD, if needed, while buffer is
2764
2774
         * claimed from calling code so that it can't be de-allocated as we are
2771
2781
             */
2772
2782
            fetchFixupForLongRecords(value, Integer.MAX_VALUE);
2773
2783
            if (MVV.isArrayMVV(value.getEncodedBytes(), 0, value.getEncodedSize())) {
2774
 
                buffer.enqueuePruningAction(_tree.getHandle());
 
2784
                if (bufferForPruning != null) {
 
2785
                    bufferForPruning.enqueuePruningAction(_tree.getHandle());
 
2786
                }
2775
2787
                visible = mvccFetch(value, minimumBytes);
2776
2788
                fetchFixupForLongRecords(value, minimumBytes);
2777
2789
            }
2798
2810
     * @throws PersistitException
2799
2811
     *             As thrown from {@link #search(Key, boolean)}
2800
2812
     */
2801
 
    private void fetchInternal(Value value, int minimumBytes) throws PersistitException {
 
2813
    private void searchAndFetchInternal(Value value, int minimumBytes) throws PersistitException {
2802
2814
        Buffer buffer = null;
2803
2815
        try {
2804
2816
            int foundAt = search(_key, false);
2805
2817
            LevelCache lc = _levelCache[0];
2806
2818
            buffer = lc._buffer;
2807
 
            fetchInternal(buffer, value, foundAt, minimumBytes);
 
2819
            fetchFromBufferInternal(buffer, value, foundAt, minimumBytes);
2808
2820
            _volume.getStatistics().bumpFetchCounter();
2809
2821
            _tree.getStatistics().bumpFetchCounter();
2810
2822
        } finally {
3952
3964
        boolean savedIgnore = _ignoreMVCCFetch;
3953
3965
        try {
3954
3966
            _ignoreMVCCFetch = true;
3955
 
            fetchInternal(_spareValue, -1);
 
3967
            searchAndFetchInternal(_spareValue, -1);
3956
3968
            final boolean wasLong = isLongRecord(_spareValue);
3957
3969
            _spareValue.clear();
3958
3970
            return wasLong;
3974
3986
        boolean savedIgnore = _ignoreMVCCFetch;
3975
3987
        try {
3976
3988
            _ignoreMVCCFetch = true;
3977
 
            fetchInternal(_spareValue, -1);
 
3989
            searchAndFetchInternal(_spareValue, -1);
3978
3990
            final boolean wasLong = isLongMVV(_spareValue);
3979
3991
            _spareValue.clear();
3980
3992
            return wasLong;