Changeset 19688 for trunk


Ignore:
Timestamp:
02/10/12 20:31:17 (3 months ago)
Author:
sys
Message:

Tree en cours...

Location:
trunk/Jav_Orient
Files:
45 added
16 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/base/StructListLong.java

    r19672 r19688  
    4444import eu.scenari.orient.recordstruct.IStructList; 
    4545import eu.scenari.orient.recordstruct.IValue.CopyObjective; 
     46import eu.scenari.orient.recordstruct.IValueList; 
    4647import eu.scenari.orient.recordstruct.IValueOwner; 
    4748import eu.scenari.orient.recordstruct.impl.StructReader; 
     
    4950import eu.scenari.orient.recordstruct.struct.StructAbstract; 
    5051 
    51 public class StructListLong extends StructAbstract<ValueListLong> implements IStructList<ValueListLong> { 
     52public class StructListLong extends StructAbstract<IValueList<Long>> implements IStructList<IValueList<Long>> { 
    5253 
    53         public StructListLong(int pCoreStructId) { 
     54        protected boolean fCacheEntries; 
     55 
     56        public StructListLong(int pCoreStructId, boolean pCacheEntries) { 
    5457                super(pCoreStructId, IStruct.LENGTH_DYNAMIC, null); 
     58                fCacheEntries = pCacheEntries; 
    5559        } 
    5660 
    57         public ValueListLong toValue(Object pPojo, IValueOwner pOwner) { 
    58                 if (pPojo == null) return new ValueListLong(pOwner); 
    59                 if (pPojo instanceof ValueListLong) return ((ValueListLong) pPojo).copy(pOwner, CopyObjective.forDuplicate); 
    60                 if (pPojo instanceof List) return new ValueListLong((List) pPojo, pOwner); 
     61        public IValueList<Long> toValue(Object pPojo, IValueOwner pOwner) { 
     62                if (pPojo == null) return fCacheEntries ? new ValueListLongCached(pOwner) : new ValueListLong(pOwner); 
     63                if (pPojo instanceof ValueListLong) return ((IValueList<Long>) pPojo).copy(pOwner, CopyObjective.forDuplicate); 
     64                if (pPojo instanceof List) return fCacheEntries ? new ValueListLongCached((List) pPojo, pOwner) : new ValueListLong((List) pPojo, pOwner); 
    6165                throw new ConversionException(this, pPojo); 
    6266        } 
    6367 
    64         public ValueListLong newValue(int pDefaultCapacity, IValueOwner pOwner) { 
    65                 return new ValueListLong(pDefaultCapacity, pOwner); 
     68        public IValueList<Long> newValue(int pDefaultCapacity, IValueOwner pOwner) { 
     69                return fCacheEntries ? new ValueListLongCached(pDefaultCapacity, pOwner) : new ValueListLong(pDefaultCapacity, pOwner); 
    6670        } 
    6771 
    68         public ValueListLong readValue(StructReader pReader, int pLen, IValueOwner pOwner) { 
    69                 return new ValueListLong(pReader, pLen, pOwner); 
     72        public IValueList<Long> readValue(StructReader pReader, int pLen, IValueOwner pOwner) { 
     73                return fCacheEntries ? new ValueListLongCached(pReader, pLen, pOwner) : new ValueListLong(pReader, pLen, pOwner); 
    7074        } 
    7175} 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/base/ValueListAsciiFixed.java

    r19672 r19688  
    8282        } 
    8383 
    84         protected String unmarshallEntry(int pOffset) { 
    85                 if (fRawEntries[pOffset] == -1) return null; 
    86                 return new String(fRawEntries, pOffset, fStruct.getFixedLength()); 
     84        protected String readEntry(int pIndex) { 
     85                int vOffset = index2Offset(pIndex); 
     86                if (fRawEntries[vOffset] == -1) return null; 
     87                return new String(fRawEntries, vOffset, fStruct.getFixedLength()); 
    8788        } 
    8889 
    89         protected void marshallEntry(String pElt, int pOffset) { 
     90        protected void writeEntry(String pElt, int pIndex) { 
     91                int vOffset = index2Offset(pIndex); 
    9092                int vLen = fStruct.getFixedLength(); 
    9193                if (pElt != null) { 
    9294                        for (int i = 0; i < vLen; i++) { 
    93                                 fRawEntries[pOffset++] = (byte) pElt.charAt(i); 
     95                                fRawEntries[vOffset++] = (byte) pElt.charAt(i); 
    9496                        } 
    9597                } else { 
    9698                        for (int i = 0; i < vLen; i++) { 
    97                                 fRawEntries[pOffset++] = (byte) -1; 
     99                                fRawEntries[vOffset++] = (byte) -1; 
    98100                        } 
    99101                } 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/base/ValueListLong.java

    r19672 r19688  
    3838        } 
    3939 
    40         protected Long unmarshallEntry(int pOffset) { 
    41                 return OBinaryProtocol.bytes2long(fRawEntries, pOffset); 
     40        protected Long readEntry(int pIndex) { 
     41                return OBinaryProtocol.bytes2long(fRawEntries, index2Offset(pIndex)); 
    4242        } 
    4343 
    44         protected void marshallEntry(Long pElt, int pOffset) { 
    45                 OBinaryProtocol.long2bytes(pElt != null ? pElt : 0L, fRawEntries, pOffset); 
     44        protected void writeEntry(Long pElt, int pIndex) { 
     45                OBinaryProtocol.long2bytes(pElt != null ? pElt : 0L, fRawEntries, index2Offset(pIndex)); 
    4646        } 
    4747 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/base/ValueListRID.java

    r19672 r19688  
    4040        } 
    4141 
    42         protected ORID unmarshallEntry(int pOffset) { 
    43                 return new ORecordId(OBinaryProtocol.bytes2short(fRawEntries, pOffset), OBinaryProtocol.bytes2long(fRawEntries, pOffset + 2)); 
     42        protected ORID readEntry(int pIndex) { 
     43                int vOffset = index2Offset(pIndex); 
     44                return new ORecordId(OBinaryProtocol.bytes2short(fRawEntries, vOffset), OBinaryProtocol.bytes2long(fRawEntries, vOffset + 2)); 
    4445        } 
    4546 
    46         protected void marshallEntry(ORID pElt, int pOffset) { 
     47        protected void writeEntry(ORID pElt, int pIndex) { 
     48                int vOffset = index2Offset(pIndex); 
    4749                if (pElt != null) { 
    48                         OBinaryProtocol.short2bytes((short) pElt.getClusterId(), fRawEntries, pOffset); 
    49                         OBinaryProtocol.long2bytes(pElt.getClusterPosition(), fRawEntries, pOffset + 2); 
     50                        OBinaryProtocol.short2bytes((short) pElt.getClusterId(), fRawEntries, vOffset); 
     51                        OBinaryProtocol.long2bytes(pElt.getClusterPosition(), fRawEntries, vOffset + 2); 
    5052                } else { 
    51                         OBinaryProtocol.short2bytes((short) ORecordId.CLUSTER_ID_INVALID); 
    52                         OBinaryProtocol.long2bytes(ORecordId.CLUSTER_POS_INVALID); 
     53                        OBinaryProtocol.short2bytes((short) ORecordId.CLUSTER_ID_INVALID, fRawEntries, vOffset); 
     54                        OBinaryProtocol.long2bytes(ORecordId.CLUSTER_POS_INVALID, fRawEntries, vOffset + 2); 
    5355                } 
    5456        } 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTree.java

    r19681 r19688  
    4040 
    4141import java.util.ArrayList; 
    42 import java.util.Map; 
     42import java.util.SortedMap; 
    4343 
    4444import com.orientechnologies.orient.core.id.ORecordId; 
     
    5959import eu.scenari.orient.recordstruct.value.ValueUpdatableAbstract; 
    6060import eu.scenari.orient.tree.impl.RSTree; 
    61 import eu.scenari.orient.tree.impl.RSTreeConcurrent; 
     61import eu.scenari.orient.tree.impl.RSTreeRWLock; 
    6262import eu.scenari.orient.tree.provider.ITreeNodeProvider; 
    6363import eu.scenari.orient.tree.provider.ITreeProvider; 
     
    6565import eu.scenari.orient.tree.provider.ITreeSlotProvider; 
    6666 
    67 public class ValueTree<K, V> extends ValueUpdatableAbstract<Map<K, V>> implements ITreeProvider<K, V>, IValueSubRecord { 
     67public class ValueTree<K, V> extends ValueUpdatableAbstract<SortedMap<K, V>> implements ITreeProvider<K, V>, IValueSubRecord { 
    6868 
    6969        public static final int FIXED_SER_LENGTH = TypesBase.RID.getFullSerializedLentgh() + OBinaryProtocol.SIZE_INT; 
     
    8989                fSize = 0; 
    9090                if (getTreeStorageConfig().isTreeThreadSafe()) { 
    91                         fPojo = new RSTreeConcurrent(this, getTreeStorageConfig().getKeyComparator(), getTreeStorageConfig().getBalancingLayout(), 5000); 
     91                        fPojo = new RSTreeRWLock(this, getTreeStorageConfig().getKeyComparator(), getTreeStorageConfig().getBalancingLayout(), 5000); 
    9292                } else { 
    9393                        fPojo = new RSTree(this, getTreeStorageConfig().getKeyComparator(), getTreeStorageConfig().getBalancingLayout()); 
     
    108108        } 
    109109 
    110         public Map<K, V> getPojo() { 
     110        public SortedMap<K, V> getPojo() { 
    111111                return fPojo; 
    112112        } 
     
    277277        } 
    278278 
    279         public <RET extends IValue<Map<K, V>>> RET copyFrom(IValue<?> pFromValue, CopyObjective pObjective) { 
     279        public <RET extends IValue<SortedMap<K, V>>> RET copyFrom(IValue<?> pFromValue, CopyObjective pObjective) { 
    280280                ValueTree vFrom = (ValueTree) pFromValue; 
    281281                fRootEntry = vFrom.fRootEntry.copy(this, pObjective); 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/lib/tree/ValueTreeSlotKV.java

    r19680 r19688  
    8888 
    8989        public float getFillRate() { 
    90                 return fKeys.size() / fTree.getDefaultRakeCapacity(); 
     90                return fKeys.size() / fTree.getDefaultSlotCapacity(); 
    9191        } 
    9292 
    9393        public boolean adoptAllEntriesFromLeft(ITreeNodeProvider<K, V> pLeftNodeToKill) { 
    9494                ValueTreeSlotKV<K, V> vOther = (ValueTreeSlotKV<K, V>) pLeftNodeToKill; 
    95                 if (fKeys.size() + vOther.getSize() >= fTree.getDefaultRakeCapacity()) return false; 
     95                if (fKeys.size() + vOther.getSize() >= fTree.getDefaultSlotCapacity()) return false; 
    9696                fKeys.addAll(0, vOther.fKeys); 
    9797                fValues.addAll(0, vOther.fValues); 
     
    101101        public boolean adoptAllEntriesFromRight(ITreeNodeProvider<K, V> pRightNodeToKill) { 
    102102                ValueTreeSlotKV<K, V> vOther = (ValueTreeSlotKV<K, V>) pRightNodeToKill; 
    103                 if (fKeys.size() + vOther.getSize() >= fTree.getDefaultRakeCapacity()) return false; 
     103                if (fKeys.size() + vOther.getSize() >= fTree.getDefaultSlotCapacity()) return false; 
    104104                fKeys.addAll(vOther.fKeys); 
    105105                fValues.addAll(vOther.fValues); 
     
    109109        public int adoptEntriesFromLeft(ITreeNodeProvider<K, V> pLeftNode, float pTargetFillRate) { 
    110110                ValueTreeSlotKV<K, V> vOther = (ValueTreeSlotKV<K, V>) pLeftNode; 
    111                 int vTargetSize = (int) (fTree.getDefaultRakeCapacity() * pTargetFillRate); 
     111                int vTargetSize = (int) (fTree.getDefaultSlotCapacity() * pTargetFillRate); 
    112112                int vOtherSize = vOther.getSize(); 
    113113                int vRecordsToMove = Math.min(vTargetSize - fKeys.size(), vOtherSize - 1); 
    114114                if (vRecordsToMove > 0) { 
    115115                        List<K> vOtherKeys = vOther.fKeys.subList(vOtherSize - vRecordsToMove, vOtherSize); 
    116                         List<V> vOtherSubNodes = vOther.fValues.subList(vOtherSize - vRecordsToMove, vOtherSize); 
     116                        List<V> vOtherValues = vOther.fValues.subList(vOtherSize - vRecordsToMove, vOtherSize); 
    117117                        fKeys.addAll(0, vOtherKeys); 
    118                         fValues.addAll(0, vOtherSubNodes); 
     118                        fValues.addAll(0, vOtherValues); 
    119119                        vOtherKeys.clear(); 
    120                         vOtherSubNodes.clear(); 
     120                        vOtherValues.clear(); 
    121121                } 
    122122                return vRecordsToMove; 
     
    125125        public int adoptEntriesFromRight(ITreeNodeProvider<K, V> pRightNode, float pTargetFillRate) { 
    126126                ValueTreeSlotKV<K, V> vOther = (ValueTreeSlotKV<K, V>) pRightNode; 
    127                 int vTargetSize = (int) (fTree.getDefaultRakeCapacity() * pTargetFillRate); 
     127                int vTargetSize = (int) (fTree.getDefaultSlotCapacity() * pTargetFillRate); 
    128128                int vOtherSize = vOther.getSize(); 
    129129                int vRecordsToMove = Math.min(vTargetSize - fKeys.size(), vOtherSize - 1); 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/types/TypesBase.java

    r19672 r19688  
    119119        //**** List de pojo .... 
    120120 
    121         public static final StructListLong LIST_LONG = new StructListLong(195); 
     121        public static final StructListLong LIST_LONG = new StructListLong(195, false); 
     122 
     123        public static final StructListLong LIST_LONG_CACHED = new StructListLong(196, true); 
    122124 
    123125} 
  • trunk/Jav_Orient/src/eu/scenari/orient/recordstruct/value/ValueListImmutableFixed.java

    r19687 r19688  
    5858 
    5959/** 
    60  *  
     60 * List of fixed serialisation length immutable values. 
    6161 */ 
    6262public abstract class ValueListImmutableFixed<E> extends ValueUpdatableAbstract<List<E>> implements IValueList<E> { 
     
    192192 
    193193        public boolean contains(Object pO) { 
    194                 int vOffset = fOffset; 
    195194                for (int i = 0; i < fSize; i++) { 
    196                         if (unmarshallEntry(vOffset).equals(pO)) return true; 
    197                         vOffset += getFixedLengthEntry(); 
     195                        if (readEntry(i).equals(pO)) return true; 
    198196                } 
    199197                return false; 
     
    209207                                //Cherche à renseigner fNext 
    210208                                if (fIndex < fSize) { 
    211                                         fNext = unmarshallEntry(index2Offset(fIndex)); 
     209                                        fNext = readEntry(fIndex); 
    212210                                        fIndex++; 
    213211                                } 
     
    219217        public Object[] toArray() { 
    220218                Object[] vResult = new Object[fSize]; 
    221                 int vOffset = fOffset; 
    222219                for (int i = 0; i < fSize; i++) { 
    223                         vResult[i] = unmarshallEntry(vOffset); 
    224                         vOffset += getFixedLengthEntry(); 
     220                        vResult[i] = readEntry(i); 
    225221                } 
    226222                return vResult; 
     
    229225        public <T> T[] toArray(T[] pArray) { 
    230226                if (pArray.length < fSize) pArray = (pArray.getClass() == Object[].class) ? (T[]) new Object[fSize] : (T[]) Array.newInstance(pArray.getClass().getComponentType(), fSize); 
    231                 int vOffset = fOffset; 
    232227                for (int i = 0; i < fSize; i++) { 
    233                         pArray[i] = (T) unmarshallEntry(vOffset); 
    234                         vOffset += getFixedLengthEntry(); 
     228                        pArray[i] = (T) readEntry(i); 
    235229                } 
    236230                return pArray; 
     
    239233        public boolean add(E pElement) { 
    240234                isolateBufferForUpdates(fSize + 1); 
    241                 marshallEntry(pElement, index2Offset(fSize)); 
    242235                fSize++; 
     236                writeEntry(pElement, fSize - 1); 
    243237                setDirty(); 
    244238                return true; 
     
    248242                int vOffset = fOffset; 
    249243                for (int i = 0; i < fSize; i++) { 
    250                         if (unmarshallEntry(vOffset).equals(pO)) { 
     244                        if (readEntry(i).equals(pO)) { 
    251245                                if (i < fSize - 1) { 
    252246                                        isolateBufferForUpdates(fSize - 1); 
     
    266260                int vCountToAdd = pC.size(); 
    267261                if (vCountToAdd == 0) return false; 
    268                 isolateBufferForUpdates(fSize + vCountToAdd); 
     262                int vCurrentSize = fSize; 
     263                isolateBufferForUpdates(vCurrentSize + vCountToAdd); 
     264                fSize += vCountToAdd; 
    269265                Iterator<? extends E> vEntry = pC.iterator(); 
    270                 int vOffset = index2Offset(fSize); 
    271266                while (vEntry.hasNext()) { 
    272                         marshallEntry(vEntry.next(), vOffset); 
    273                         vOffset += getFixedLengthEntry(); 
    274                 } 
    275                 fSize += vCountToAdd; 
     267                        writeEntry(vEntry.next(), vCurrentSize++); 
     268                } 
    276269                setDirty(); 
    277270                return true; 
     
    281274                int vCountToAdd = pC.size(); 
    282275                if (vCountToAdd == 0) return false; 
    283                 isolateBufferForUpdates(fSize + vCountToAdd); 
     276                int vCurrentSize = fSize; 
     277                isolateBufferForUpdates(vCurrentSize + vCountToAdd); 
     278                fSize += vCountToAdd; 
    284279                int vOffset = index2Offset(pIndex); 
    285                 if (pIndex < fSize) { 
    286                         System.arraycopy(fRawEntries, vOffset, fRawEntries, vOffset + (vCountToAdd * getFixedLengthEntry()), (fSize - pIndex) * getFixedLengthEntry()); 
     280                if (pIndex < vCurrentSize) { 
     281                        System.arraycopy(fRawEntries, vOffset, fRawEntries, vOffset + (vCountToAdd * getFixedLengthEntry()), (vCurrentSize - pIndex) * getFixedLengthEntry()); 
    287282                } 
    288283                Iterator<? extends E> vIt = pC.iterator(); 
    289284                while (vIt.hasNext()) { 
    290                         marshallEntry(vIt.next(), vOffset); 
    291                         vOffset += getFixedLengthEntry(); 
    292                 } 
    293                 fSize += vCountToAdd; 
     285                        writeEntry(vIt.next(), pIndex++); 
     286                } 
    294287                setDirty(); 
    295288                return true; 
     
    304297        public E get(int pIndex) { 
    305298                assert (pIndex >= 0 && pIndex < fSize); 
    306                 return unmarshallEntry(index2Offset(pIndex)); 
     299                return readEntry(pIndex); 
    307300        } 
    308301 
     
    310303                assert (pIndex >= 0 && pIndex <= fSize); 
    311304                isolateBufferForUpdates(fSize); 
    312                 int vOffset = index2Offset(pIndex); 
    313                 E vElt = unmarshallEntry(vOffset); 
    314                 marshallEntry(pElement, vOffset); 
     305                E vElt = readEntry(pIndex); 
     306                writeEntry(pElement, pIndex); 
    315307                return vElt; 
    316308        } 
     
    318310        public void add(int pIndex, E pElement) { 
    319311                assert (pIndex >= 0 && pIndex <= fSize); 
     312                int vCurrentSize = fSize; 
    320313                isolateBufferForUpdates(fSize + 1); 
     314                fSize++; 
    321315                int vOffset = index2Offset(pIndex); 
    322                 if (pIndex < fSize) { 
    323                         System.arraycopy(fRawEntries, vOffset, fRawEntries, vOffset + getFixedLengthEntry(), (fSize - pIndex) * getFixedLengthEntry()); 
    324                 } 
    325                 marshallEntry(pElement, vOffset); 
    326                 fSize++; 
     316                if (pIndex < vCurrentSize) { 
     317                        System.arraycopy(fRawEntries, vOffset, fRawEntries, vOffset + getFixedLengthEntry(), (vCurrentSize - pIndex) * getFixedLengthEntry()); 
     318                } 
     319                writeEntry(pElement, pIndex); 
    327320        } 
    328321 
    329322        public E remove(int pIndex) { 
    330323                assert (pIndex >= 0 && pIndex < fSize); 
    331                 E vElt = unmarshallEntry(index2Offset(pIndex)); 
     324                E vElt = readEntry(pIndex); 
    332325                if (pIndex < fSize - 1) { 
    333326                        isolateBufferForUpdates(fSize - 1); 
     
    342335 
    343336        public int indexOf(Object pO) { 
    344                 int vOffset = fOffset; 
    345337                for (int i = 0; i < fSize; i++) { 
    346                         if (unmarshallEntry(vOffset).equals(pO)) return i; 
    347                         vOffset += getFixedLengthEntry(); 
     338                        if (readEntry(i).equals(pO)) return i; 
    348339                } 
    349340                return -1; 
     
    352343        public int lastIndexOf(Object pO) { 
    353344                for (int i = fSize - 1; i >= 0; i--) { 
    354                         if (unmarshallEntry(index2Offset(i)).equals(pO)) return i; 
     345                        if (readEntry(i).equals(pO)) return i; 
    355346                } 
    356347                return -1; 
     
    402393 
    403394        public void writeValue(IStructWriter pWriter) { 
     395                assert (fRawEntries.length >= fSize * getFixedLengthEntry() + fOffset); 
    404396                pWriter.addAsValue(this, fRawEntries, fOffset, fSize * getFixedLengthEntry()); 
    405397        } 
     
    430422        protected abstract int getFixedLengthEntry(); 
    431423 
    432         protected abstract E unmarshallEntry(int pOffset); 
    433  
    434         protected abstract void marshallEntry(E pElt, int pOffset); 
     424        protected abstract E readEntry(int pIndex); 
     425 
     426        protected abstract void writeEntry(E pElt, int pIndex); 
    435427 
    436428} 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/BalancedLayout.java

    r19681 r19688  
    1414 
    1515        /** When fill rate is reduced and less than <code>fOptimizeThreshold</code>, try to merge with siblings. */ 
    16         protected float fOptimizeThreshold = 0.25f; 
     16        protected float fOptimizeThreshold = 0.2f; 
    1717 
    1818        /**  
    1919         * Target fillRate on the rightNode when a node is splitted.  
    20          * If keys are incremental values (ID, timestamp, ...), it would better to set 0.1. 
     20         * If keys are incremental values (ID, timestamp, ...), it would better to set 0.1 or 0.0. 
    2121         */ 
    2222        protected float fTargetFillRateForNewRightNode = 0.5f; 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/IBalancingLayout.java

    r19680 r19688  
    33public interface IBalancingLayout { 
    44 
    5         public final IBalancingLayout DEFAULT_BALANCED_RANDOM_INSERT = new BalancedLayout(); 
     5        public final IBalancingLayout DEFAULT_BALANCED_RANDOM_INSERT = new BalancedLayout(0.5f, 0.2f, 0.5f); 
    66 
    77        public final IBalancingLayout DEFAULT_BALANCED_INCREMENTAL_INSERT = new BalancedLayout(0.0f, 0.2f, 0.0f); 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/RSTreeRWLock.java

    r19681 r19688  
    5353 
    5454/** 
    55  * RSTree with concurrent access management. 
     55 * RSTree with concurrent access management in a ReadWriteLock manner. 
    5656 */ 
    57 public class RSTreeConcurrent<K, V> extends RSTree<K, V> implements OMemoryWatchDog.Listener { 
     57public class RSTreeRWLock<K, V> extends RSTree<K, V> implements OMemoryWatchDog.Listener { 
    5858 
    5959        protected AtomicBoolean fNeedFreeMemory = new AtomicBoolean(false); 
     
    115115        } 
    116116 
    117         public RSTreeConcurrent(ITreeProvider<K, V> pProvider) { 
     117        public RSTreeRWLock(ITreeProvider<K, V> pProvider) { 
    118118                this(pProvider, null, null, 5000); 
    119119        } 
    120120 
    121         public RSTreeConcurrent(ITreeProvider<K, V> pProvider, Comparator<? super K> pComparator, IBalancingLayout pBalancingLayout, int pLockTimeout) { 
     121        public RSTreeRWLock(ITreeProvider<K, V> pProvider, Comparator<? super K> pComparator, IBalancingLayout pBalancingLayout, int pLockTimeout) { 
    122122                super(pProvider, pComparator, pBalancingLayout); 
    123123                fLock = new Lock(pLockTimeout); 
  • trunk/Jav_Orient/src/eu/scenari/orient/tree/impl/RSTreeRake.java

    r19687 r19688  
    361361                                        if (getNode(i).accept(pVisitor, pVisitOnlyInMemoryNodes) == Result.stopVisiting) return Result.stopVisiting; 
    362362                                        if (fTree.isThreadSafe()) { 
    363                                                 ((RSTreeConcurrent) fTree).freeMemoryIfNeeded(); 
     363                                                ((RSTreeRWLock) fTree).freeMemoryIfNeeded(); 
    364364                                        } 
    365365                                } 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBasicTestAbstract.java

    r19687 r19688  
    4141import java.util.Iterator; 
    4242import java.util.Map; 
     43import java.util.SortedMap; 
    4344 
    4445import junit.framework.Assert; 
     
    6970 
    7071                //Inserts 
    71                 Map<Long, Long> vTree = vRecord.getValue().getPojo(); 
     72                SortedMap<Long, Long> vTree = vRecord.getValue().getPojo(); 
    7273                for (int i = 1; i <= vSize; i++) { 
    7374                        Long vKey = pFactory.newKey(); 
     
    7576                        vRecord.save(); 
    7677                        checkSize(vTree, i); 
     78                        //checkEntrySetIterator(vTree, pFactory); 
    7779                } 
    7880                checkSize(vTree, vSize); 
     
    121123        } 
    122124 
    123         protected void checkEntrySetIterator(Map<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
     125        protected void checkEntrySetIterator(SortedMap<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
    124126                int vCount = 0; 
     127                Long vPreviousKey = null; 
    125128                for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
    126129                        pFactory.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
     130                        if (vPreviousKey != null) Assert.assertTrue(pTree.comparator().compare(vPreviousKey, vEntry.getKey()) > 0); 
    127131                        vCount++; 
    128132                } 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBasicUnorderedTest.java

    r19687 r19688  
    4747        @Test 
    4848        public void testUnorderedInserts() { 
    49                 executeTest(new FactoryUnorderedLong(), TypesTreeTests.TREE_LL_RANDOM); 
     49                executeTest(new FactoryUnorderedLong(), TypesTreeTests.TREE_LL); 
    5050        } 
    5151 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBigTestAbstract.java

    r19687 r19688  
    4040 
    4141import java.util.Iterator; 
    42 import java.util.Map; 
     42import java.util.SortedMap; 
    4343 
    4444import junit.framework.Assert; 
     
    4949import eu.scenari.orient.recordstruct.lib.tree.StructTree; 
    5050import eu.scenari.orient.recordstruct.lib.tree.ValueTree; 
    51 import eu.scenari.orient.test.TestDbAbstract; 
    5251import eu.scenari.orient.tree.datafactory.IKVFactory; 
    53 import eu.scenari.orient.tree.impl.RSTreeConcurrent; 
     52import eu.scenari.orient.tree.impl.RSTreeRWLock; 
    5453 
    55 public class TreeBigTestAbstract extends TestDbAbstract { 
     54public class TreeBigTestAbstract extends TreeBasicTestAbstract { 
    5655 
    57         public static int MAP_SIZE = 1 * 1000000; 
     56        public static int MAP_BIG_SIZE = 1 * 1000000; 
    5857 
    5958        @Override 
     
    6261 
    6362        public void executeTest(IKVFactory<Long, Long> pFactory, StructTree pStructTree) { 
    64                 int vSize = MAP_SIZE; 
    6563                fDatabase = fDbDriver.acquireDatabase(); 
    6664                IRecordStruct<ValueTree<Long, Long>> vRecord = fDatabase.newInstance(); 
    6765                vRecord.setValue((ValueTree) pStructTree.toValue(null, vRecord)); 
    6866                vRecord.save(); 
    69                 Map<Long, Long> vTree = vRecord.getValue().getPojo(); 
    70                 Orient.instance().getMemoryWatchDog().addListener((RSTreeConcurrent) vTree); 
     67                SortedMap<Long, Long> vTree = vRecord.getValue().getPojo(); 
     68                Orient.instance().getMemoryWatchDog().addListener((RSTreeRWLock) vTree); 
    7169 
    7270                //Inserts 
    73                 for (int i = 1; i <= vSize; i++) { 
     71                for (int i = 1; i <= MAP_BIG_SIZE; i++) { 
    7472                        Long vKey = pFactory.newKey(); 
    7573                        vTree.put(vKey, pFactory.newValueFor(vKey)); 
     
    8179                vRecord.save(); 
    8280                System.out.println("[END INSERT]"); 
    83                 checkSize(vTree, vSize); 
     81                checkSize(vTree, MAP_BIG_SIZE); 
    8482                System.out.println("[END CHECKSIZE]"); 
    8583                checkEntrySetIterator(vTree, pFactory); 
     
    117115        } 
    118116 
    119         protected void checkSize(Map<Long, Long> pTree, int pExpectedSize) { 
    120                 if (TypesTreeTests.STORE_SIZE) { 
    121                         Assert.assertEquals(pExpectedSize, pTree.size()); 
    122                 } 
    123         } 
    124  
    125         protected void checkEntrySetIterator(Map<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
    126                 int vCount = 0; 
    127                 for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
    128                         pFactory.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
    129                         vCount++; 
    130                 } 
    131                 checkSize(pTree, vCount); 
    132         } 
    133  
    134         protected void checkAllEntries(Map<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
    135                 int vCount = 0; 
    136                 for (Iterator<Long> vIt = pFactory.creationOrderIterator(); vIt.hasNext();) { 
    137                         Long vKey = vIt.next(); 
    138                         pFactory.checkValueForKey(vKey, pTree.get(vKey)); 
    139                         vCount++; 
    140                 } 
    141                 checkSize(pTree, vCount); 
    142  
    143         } 
    144  
    145117} 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TreeBigUnorderedTest.java

    r19687 r19688  
    99        @Test 
    1010        public void testUnorderedInserts() { 
    11                 executeTest(new FactoryUnorderedLong(), TypesTreeTests.TREE_LL_RANDOM_CONCUR); 
     11                executeTest(new FactoryUnorderedLong(), TypesTreeTests.TREE_LL_CONCUR); 
    1212        } 
    1313} 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/TypesTreeTests.java

    r19687 r19688  
    1212 
    1313        /** */ 
    14         public static final TreeStorageConfig TREECONFIG_LL_INCR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
    15                         .setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT).setRakeCapacity(32).setSlotCapacity(32); 
     14        public static final TreeStorageConfig TREECONFIG_LL = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG_CACHED).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE).setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_RANDOM_INSERT) 
     15                        .setRakeCapacity(256).setSlotCapacity(256); 
    1616 
    1717        /** */ 
    18         public static final TreeStorageConfig TREECONFIG_LL_INCR_CONCUR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
     18        public static final TreeStorageConfig TREECONFIG_LL_CONCUR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG_CACHED).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
     19                        .setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_RANDOM_INSERT).setRakeCapacity(256).setSlotCapacity(256).setTreeThreadSafe(true); 
     20 
     21        /** */ 
     22        public static final TreeStorageConfig TREECONFIG_LL_INCR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG_CACHED).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
     23                        .setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT).setRakeCapacity(256).setSlotCapacity(256); 
     24 
     25        /** */ 
     26        public static final TreeStorageConfig TREECONFIG_LL_INCR_CONCUR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG_CACHED).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
    1927                        .setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_INCREMENTAL_INSERT).setRakeCapacity(256).setSlotCapacity(256).setTreeThreadSafe(true); 
    2028 
    21         /** */ 
    22         public static final TreeStorageConfig TREECONFIG_LL_RANDOM = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE).setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_RANDOM_INSERT) 
    23                         .setRakeCapacity(32).setSlotCapacity(32); 
     29        public static final StructTree TREE_LL = new StructTree(new ExtendedStructId(1, 1), "LL").setTreeConfig(TREECONFIG_LL); 
    2430 
    25         /** */ 
    26         public static final TreeStorageConfig TREECONFIG_LL_RANDOM_CONCUR = new TreeStorageConfig().setKeysStruct(TypesBase.LIST_LONG).setValuesStruct(TypesBase.LIST_LONG).setSizeStored(STORE_SIZE) 
    27                         .setBalancingLayout(IBalancingLayout.DEFAULT_BALANCED_RANDOM_INSERT).setRakeCapacity(256).setSlotCapacity(256).setTreeThreadSafe(true); 
     31        public static final StructTree TREE_LL_CONCUR = new StructTree(new ExtendedStructId(1, 2), "LL_CONCUR").setTreeConfig(TREECONFIG_LL_CONCUR); 
    2832 
    29         public static final StructTree TREE_LL_INCR = new StructTree(new ExtendedStructId(1, 1), "LL_INCR").setTreeConfig(TREECONFIG_LL_INCR); 
     33        public static final StructTree TREE_LL_INCR = new StructTree(new ExtendedStructId(1, 3), "LL_INCR").setTreeConfig(TREECONFIG_LL_INCR); 
    3034 
    31         public static final StructTree TREE_LL_INCR_CONCUR = new StructTree(new ExtendedStructId(1, 2), "LL_INCR_CONCUR").setTreeConfig(TREECONFIG_LL_INCR_CONCUR); 
    32  
    33         public static final StructTree TREE_LL_RANDOM = new StructTree(new ExtendedStructId(1, 3), "LL_RANDOM").setTreeConfig(TREECONFIG_LL_RANDOM); 
    34  
    35         public static final StructTree TREE_LL_RANDOM_CONCUR = new StructTree(new ExtendedStructId(1, 4), "LL_RANDOM_CONCUR").setTreeConfig(TREECONFIG_LL_RANDOM_CONCUR); 
     35        public static final StructTree TREE_LL_INCR_CONCUR = new StructTree(new ExtendedStructId(1, 4), "LL_INCR_CONCUR").setTreeConfig(TREECONFIG_LL_INCR_CONCUR); 
    3636 
    3737} 
  • trunk/Jav_Orient/test/eu/scenari/orient/tree/perf/TreePerfTestAbstract.java

    r19687 r19688  
    33import java.util.Iterator; 
    44import java.util.Map; 
     5import java.util.SortedMap; 
    56 
    67import junit.framework.Assert; 
    78 
    8 import org.junit.Test; 
    9  
     9import com.orientechnologies.common.profiler.OProfiler; 
    1010import com.orientechnologies.orient.core.id.ORID; 
    11 import com.orientechnologies.orient.core.serialization.serializer.stream.OStreamSerializerLong; 
    12 import com.orientechnologies.orient.core.type.tree.OMVRBTreeDatabaseLazySave; 
    13 import com.orientechnologies.orient.core.type.tree.provider.OMVRBTreeMapProvider; 
    1411 
    1512import eu.scenari.orient.test.TestDbAbstract; 
    16 import eu.scenari.orient.tree.datafactory.FactorySequentialLong; 
     13import eu.scenari.orient.tree.datafactory.IKVFactory; 
     14import eu.scenari.orient.tree.mapsupplier.ITreeMapSupplier; 
    1715 
    18 public class MVRBTreePerfTest extends TestDbAbstract { 
    19         public static int MAP_SIZE = 20000; 
    20  
    21         protected FactorySequentialLong fFactorySeqLong = new FactorySequentialLong(); 
     16public abstract class TreePerfTestAbstract extends TestDbAbstract { 
    2217 
    2318        @Override 
     
    2520        } 
    2621 
    27         @Test 
    28         public void test1() { 
    29                 int vSize = MAP_SIZE; 
     22        public void executeTest(String pTestName, int pSizeMap, boolean pTestRefreshDb, int pModuloSave, IKVFactory<Long, Long> pKVFactory, ITreeMapSupplier<Long, Long> pTreeSupplier) { 
    3023                fDatabase = fDbDriver.acquireDatabase(); 
     24                int vModuloPrintProgress = pModuloSave * 100; 
    3125 
    32                 OMVRBTreeDatabaseLazySave<Long, Long> vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, null, OStreamSerializerLong.INSTANCE, OStreamSerializerLong.INSTANCE); 
    33                 vTree.save(); 
    34                 vTree.lazySave(); 
    35                 ORID vId = ((OMVRBTreeMapProvider) vTree.getProvider()).getRecord().getIdentity(); 
     26                SortedMap<Long, Long> vTree = pTreeSupplier.createMap(fDatabase); 
     27                ORID vRid = pTreeSupplier.getIdMap(vTree); 
    3628 
    37                 for (int i = 1; i <= vSize; i++) { 
    38                         Long vKey = fFactorySeqLong.newKey(); 
    39                         vTree.put(vKey, fFactorySeqLong.newValueFor(vKey)); 
    40                         vTree.lazySave(); 
    41                         checkSize(vTree, i); 
     29                long vTimer = OProfiler.getInstance().startChrono(); 
     30                for (int i = 1; i <= pSizeMap; i++) { 
     31                        Long vKey = pKVFactory.newKey(); 
     32                        vTree.put(vKey, pKVFactory.newValueFor(vKey)); 
     33                        if (i % pModuloSave == 0) { 
     34                                pTreeSupplier.saveMap(vTree); 
     35                                if (i % vModuloPrintProgress == 0) { 
     36                                        System.out.print('+'); 
     37                                } 
     38                        } 
    4239                } 
    43                 checkSize(vTree, vSize); 
    44                 checkAllEntries(vTree); 
     40                OProfiler.getInstance().stopChrono(pTestName + ".1.createEntries", vTimer); 
    4541 
    46                 forceNewDatabase(); 
    47                 vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
    48                 vTree.load(); 
    49                 checkSize(vTree, vSize); 
    50                 checkAllEntries(vTree); 
     42                vTimer = OProfiler.getInstance().startChrono(); 
     43                browseEntrySetEntries(vTree, pKVFactory); 
     44                OProfiler.getInstance().stopChrono(pTestName + ".2.browseEntrySet", vTimer); 
    5145 
    52                 forceNewDatabase(); 
    53                 vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
    54                 vTree.load(); 
    55                 for (Iterator<Long> vIt = fFactorySeqLong.unorderedIterator(); vIt.hasNext();) { 
    56                         Long vKey = vIt.next(); 
    57                         fFactorySeqLong.checkValueForKey(vKey, vTree.get(vKey)); 
     46                vTimer = OProfiler.getInstance().startChrono(); 
     47                requestAllKeys(vTree, pKVFactory); 
     48                OProfiler.getInstance().stopChrono(pTestName + ".3.requestAllKeys", vTimer); 
     49 
     50                if (pTestRefreshDb) { 
     51                        forceNewDatabase(); 
     52                        vTree = pTreeSupplier.load(fDatabase, vRid); 
     53 
     54                        vTimer = OProfiler.getInstance().startChrono(); 
     55                        browseEntrySetEntries(vTree, pKVFactory); 
     56                        OProfiler.getInstance().stopChrono(pTestName + ".4.browseEntrySet.fromFreshDb", vTimer); 
     57 
     58                        forceNewDatabase(); 
     59                        vTree = pTreeSupplier.load(fDatabase, vRid); 
     60 
     61                        vTimer = OProfiler.getInstance().startChrono(); 
     62                        requestAllKeys(vTree, pKVFactory); 
     63                        OProfiler.getInstance().stopChrono(pTestName + ".5.requestAllKeys.fromFreshDb", vTimer); 
    5864                } 
    5965 
    60                 //Remove entries 
    61                 forceNewDatabase(); 
    62                 vTree = new OMVRBTreeDatabaseLazySave<Long, Long>(fDatabase, vId); 
    63                 vTree.load(); 
    64                 Long vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     66                vTimer = OProfiler.getInstance().startChrono(); 
     67                Long vKey = pKVFactory.getUnorderedKeyToRemove(); 
     68                int i = 0; 
    6569                while (vKey != null) { 
    66                         //System.out.println(vKey); 
     70                        i++; 
    6771                        vTree.remove(vKey); 
    68                         vTree.lazySave(); 
    69                         //checkAllEntries(vTree); 
    70                         vKey = fFactorySeqLong.getUnorderedKeyToRemove(); 
     72                        if (i % pModuloSave == 0) { 
     73                                pTreeSupplier.saveMap(vTree); 
     74                                if (i % vModuloPrintProgress == 0) System.out.print('-'); 
     75                        } 
     76                        vKey = pKVFactory.getUnorderedKeyToRemove(); 
    7177                } 
    7278                Assert.assertTrue(vTree.isEmpty()); 
     79                OProfiler.getInstance().stopChrono(pTestName + ".6.removeEntries", vTimer); 
    7380        } 
    7481 
    75         protected void checkSize(Map<Long, Long> pTree, int pSize) { 
    76                 Assert.assertEquals(pTree.size(), pSize); 
     82        /** Iterate over Map.entrySet iterator. */ 
     83        protected void browseEntrySetEntries(SortedMap<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
     84                Long vPreviousKey = null; 
     85                for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
     86                        pFactory.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
     87                        if (vPreviousKey != null) Assert.assertTrue(pTree.comparator().compare(vPreviousKey, vEntry.getKey()) > 0); 
     88                } 
    7789        } 
    7890 
    79         protected void checkAllEntries(Map<Long, Long> pTree) { 
    80                 int vCount = 0; 
    81                 for (Map.Entry<Long, Long> vEntry : pTree.entrySet()) { 
    82                         fFactorySeqLong.checkValueForKey(vEntry.getKey(), vEntry.getValue()); 
    83                         vCount++; 
     91        /** Each key in the Map is requested one by one in an unordored order. */ 
     92        protected void requestAllKeys(SortedMap<Long, Long> pTree, IKVFactory<Long, Long> pFactory) { 
     93                for (Iterator<Long> vIt = pFactory.unorderedIterator(); vIt.hasNext();) { 
     94                        Long vKey = vIt.next(); 
     95                        pFactory.checkValueForKey(vKey, pTree.get(vKey)); 
    8496                } 
    85                 checkSize(pTree, vCount); 
    86                 for (Iterator<Long> vIt = fFactorySeqLong.creationOrderIterator(); vIt.hasNext();) { 
    87                         Long vKey = vIt.next(); 
    88                         fFactorySeqLong.checkValueForKey(vKey, pTree.get(vKey)); 
    89                 } 
    90  
    9197        } 
    9298} 
Note: See TracChangeset for help on using the changeset viewer.