Merge branch 'master' into nomerge2

This commit is contained in:
Ai Lin Chia
2017-03-21 13:16:22 +01:00
3 changed files with 5 additions and 94 deletions

@ -726,6 +726,9 @@ int32_t Mem::validate ( ) {
int32_t Mem::getMemSlot ( void *mem ) {
if(!s_lock.working) return true;
ScopedLock sl(s_lock);
// hash into table
uint32_t u = (PTRTYPE)mem * (PTRTYPE)0x4bf60ade;
uint32_t h = u % (uint32_t)m_memtablesize;

@ -41,7 +41,6 @@ RdbTree::RdbTree () {
m_dataInPtrs = false;
m_overhead = 0;
m_maxMem = 0;
m_baseMem = 0;
m_allocName = NULL;
m_bytesWritten = 0;
m_bytesRead = 0;
@ -327,11 +326,6 @@ int32_t RdbTree::getFirstNode ( ) {
return getNextNode ( 0 , k );
}
int32_t RdbTree::getFirstNode2 ( collnum_t collnum ) {
const char *k = KEYMIN();
return getNextNode ( collnum , k );
}
int32_t RdbTree::getLastNode ( ) {
const char *k = KEYMAX();
return getPrevNode ( (collnum_t)0x7fff , k );
@ -427,13 +421,6 @@ int32_t RdbTree::getPrevNode ( int32_t i ) {
return p;
}
// . get the node with the lowest key
int32_t RdbTree::getLowestNode ( ) {
int32_t i = m_headNode;
while ( m_left[i] != -1 ) i = m_left [ i ];
return i;
}
// . returns -1 if we coulnd't allocate the new space and sets g_errno to ENOMEM
// or ETREENOGROW, ...
// . returns node # we added it to on success
@ -975,62 +962,6 @@ bool RdbTree::deleteList(collnum_t collnum, RdbList *list) {
return allgood;
}
// TODO: speed up since keys are usually ordered (use getNextNode())
void RdbTree::deleteOrderedList(collnum_t collnum, RdbList *list) {
// return if no non-empty nodes in the tree
if ( m_numUsedNodes <= 0 ) return ;
// reset before calling list->getCurrent*() functions
list->resetListPtr();
char key [ MAX_KEY_BYTES ];
// bail if list is empty now
if ( list->isEmpty() ) return;
list->getCurrentKey ( key );
// get the node whose keys is just <= key
int32_t node = getPrevNode ( collnum , key );
top:
// bail if no nodes in tree left that have keys >= "key"
if ( node == -1 ) goto done;
top2:
// . if key of node equals key, remove node and advance key and node
// . this condition is usually the case, so check it first for speed
//if ( m_keys [ node ] == key && m_collnums [ node ] == collnum ) {
if ( KEYCMP(m_keys,node,key,0,m_ks)==0 && m_collnums[node] == collnum){
// trim the node from the tree
deleteNode(node, true /*freeData?*/ );
// get next node in tree
node = getNextNode ( node ) ;
// . point to next key in list to delete
// . return if list exhausted
if ( ! list->skipCurrentRecord() ) goto done;
// reference that key
//key = list->getCurrentKey() ;
list->getCurrentKey ( key );
goto top;
}
// bust out if done
if ( m_collnums [ node ] > collnum ) goto done;
// if node's key is < "key" advance node
//if ( m_keys [ node ] < key ) {
if ( KEYCMP(m_keys,node,key,0,m_ks)<0 ) {
// get next node in tree
node = getNextNode ( node ) ;
goto top;
}
// . otherwise, we passed "key" so "key" must have not been in tree
// . point to next key in list to delete
// . return if list exhausted
if ( ! list->skipCurrentRecord() ) goto done;
// reference that key
//key = list->getCurrentKey() ;
list->getCurrentKey ( key ) ;
goto top2;
done:
;
}
// . this fixes the tree
// returns false if could not fix tree and sets g_errno, otherwise true
bool RdbTree::fixTree ( ) {
@ -1437,8 +1368,7 @@ bool RdbTree::growTree(int32_t nn) {
m_dbname, m_memAllocated, m_maxMem );
return false;
}
// base mem is mem that cannot be freed
m_baseMem = m_overhead * nn ;
// and the new # of nodes we have
m_numNodes = nn;

@ -65,11 +65,6 @@ public:
return ( m_numUsedNodes/90 >= m_numNodes/100 );
}
bool isFull() const { return (m_numUsedNodes >= m_numNodes); }
bool hasRoomForKeys ( int32_t nk ) {
return (m_numUsedNodes + nk <= m_numNodes); }
// . a fixedDataSize of -1 means each node has data of a variable size
// . set maxMem to -1 for no max
// . returns false & sets errno if fails to alloc "maxNumNodes" nodes
@ -129,18 +124,12 @@ public:
int32_t getFirstNode ( );
int32_t getLastNode ( );
int32_t getFirstNode2 ( collnum_t collnum );
// . get the node whose key is <= "key"
int32_t getPrevNode(collnum_t collnum, const char *key);
// . get the prev node # whose key is <= to key of node #i
int32_t getPrevNode ( int32_t i ) ;
// returns the node # with the lowest key, -1 if no nodes in tree
int32_t getLowestNode ( ) ;
// . returns true iff was found and deleted
// . returns false iff not found
// . frees m_data[node] if freeIt is true
@ -156,11 +145,6 @@ public:
// . this happens if memory is corrupted!
bool deleteList(collnum_t collnum, RdbList *list);
// . if the list's keys are ordered from smallest to largest
// this acts just like deleteList() above, but saves time by
// using getNextNode() rather than lookup each key from root of tree
void deleteOrderedList(collnum_t collnum, RdbList *list);
bool isSaving() const { return m_isSaving; }
bool isWritable() const { return m_isWritable; }
@ -181,7 +165,6 @@ public:
int32_t getDataSize ( int32_t node ) const { return m_sizes [node]; }
char *getKey(int32_t node) { return &m_keys[node*m_ks]; }
const char *getKey(int32_t node) const { return &m_keys[node*m_ks]; }
int32_t getParentNum ( int32_t node ) const { return m_parents [node]; }
collnum_t getCollnum ( int32_t node ) const { return m_collnums [node];}
@ -288,9 +271,6 @@ public:
bool checkTree2 ( bool printMsgs , bool doChainTest );
bool fixTree ( );
// all except the data: the keys,dataPtr,size,left,right,parents,depth
int32_t getRecOverhead () { return m_overhead; }
void disableWrites () { m_isWritable = false; }
void enableWrites () { m_isWritable = true ; }
@ -377,9 +357,7 @@ private:
// total amount of m_memAllocated that is occupied
int32_t m_memOccupied;
// max limit of m_memAllocated
int32_t m_maxMem;
// mem allocated for overhead of tree structure
int32_t m_baseMem;
int32_t m_maxMem;
// -1 means any dataSize, otherwise, it's fixed to this
int32_t m_fixedDataSize;
// node of the next available/empty node