const SdfNamespaceEdit_Namespace::_Node*
SdfNamespaceEdit_Namespace::_Node::GetChild(const SdfPath& path) const
{
    // Make a key node for the path.
    _VerifyPath(path.GetParentPath());
    _Node keyNode(path);

    _Children::const_iterator i = _children->find(keyNode);
    return (i == _children->end()) ? NULL : &*i;
}
示例#2
0
        /* Since the last noteLocation(), our key may have moved around, and that old cached
           information may thus be stale and wrong (although often it is right).  We check
           that here; if we have moved, we have to search back for where we were at.

           i.e., after operations on the index, the BtreeCursor's cached location info may
           be invalid.  This function ensures validity, so you should call it before using
           the cursor if other writers have used the database since the last noteLocation
           call.
        */
        void checkLocation() {
            if ( eof() )
                return;

            _multikey = d->isMultikey(idxNo);

            if ( keyOfs >= 0 ) {
                assert( !keyAtKeyOfs.isEmpty() );

                try {
                    // Note keyAt() returns an empty BSONObj if keyOfs is now out of range,
                    // which is possible as keys may have been deleted.
                    int x = 0;
                    while( 1 ) {
                        //  if ( b->keyAt(keyOfs).woEqual(keyAtKeyOfs) &&
                        //       b->k(keyOfs).recordLoc == locAtKeyOfs ) {
                        if ( keyAt(keyOfs).binaryEqual(keyAtKeyOfs) ) {
                            const _KeyNode& kn = keyNode(keyOfs);
                            if( kn.recordLoc == locAtKeyOfs ) {
                                if ( !kn.isUsed() ) {
                                    // we were deleted but still exist as an unused
                                    // marker key. advance.
                                    skipUnusedKeys();
                                }
                                return;
                            }
                        }

                        // we check one key earlier too, in case a key was just deleted.  this is
                        // important so that multi updates are reasonably fast.
                        if( keyOfs == 0 || x++ )
                            break;
                        keyOfs--;
                    }
                }
                catch(UserException& e) { 
                    if( e.getCode() != 15850 )
                        throw;
                    // hack: fall through if bucket was just deleted. should only happen under deleteObjects()
                    DEV log() << "debug info: bucket was deleted" << endl;
                }
            }

            /* normally we don't get to here.  when we do, old position is no longer
                valid and we must refind where we left off (which is expensive)
            */

            /* TODO: Switch to keep indexdetails and do idx.head! */
            bucket = _locate(keyAtKeyOfs, locAtKeyOfs);
            RARELY log() << "key seems to have moved in the index, refinding. " << bucket.toString() << endl;
            if ( ! bucket.isNull() )
                skipUnusedKeys();

        }
bool CRedisProxyCfg::saveProxyLastState(RedisProxy* proxy) {
    TiXmlElement* pRootNode = (TiXmlElement*)m_operateXmlPointer->get_rootElement();
    string nodeHash = "hash_mapping";
    TiXmlElement* pOldHashMap;
    if (GetNodePointerByName(pRootNode, nodeHash, pOldHashMap)) {
        pRootNode->RemoveChild(pOldHashMap);
    }
    TiXmlElement hashMappingNode("hash_mapping");
    for (int i = 0; i < proxy->slotCount(); ++i) {
        TiXmlElement hashNode("hash");
        hashNode.SetAttribute("value", i);
        hashNode.SetAttribute("group_name", proxy->groupBySlot(i)->groupName());
        hashMappingNode.InsertEndChild(hashNode);
    }
    pRootNode->InsertEndChild(hashMappingNode);

    // key mapping
    string nodeKey = "key_mapping";
    TiXmlElement* pKey;
    if (GetNodePointerByName(pRootNode, nodeKey, pKey)) {
        pRootNode->RemoveChild(pKey);
    }
    TiXmlElement keyMappingNode("key_mapping");

    StringMap<RedisServantGroup*>& keyMapping = proxy->keyMapping();
    StringMap<RedisServantGroup*>::iterator it = keyMapping.begin();
    for (; it != keyMapping.end(); ++it) {
        String key = it->first;
        TiXmlElement keyNode("key");
        keyNode.SetAttribute("key_name", key.data());
        RedisServantGroup* group = it->second;
        if (group != NULL) {
            keyNode.SetAttribute("group_name", group->groupName());
        }
        keyMappingNode.InsertEndChild(keyNode);
    }
    pRootNode->InsertEndChild(keyMappingNode);

    // add time
    time_t now = time(NULL);
    char fileName[512];
    struct tm* current_time = localtime(&now);
    sprintf(fileName,"onecache%d%02d%02d%02d.xml",
        current_time->tm_year + 1900,
        current_time->tm_mon + 1,
        current_time->tm_mday,
        current_time->tm_hour);

    bool ok = m_operateXmlPointer->m_docPointer->SaveFile(fileName);
    return ok;
}
示例#4
0
 void BucketBasics::assertValid(const Ordering &order, bool force) {
     if ( !debug && !force )
         return;
     wassert( n >= 0 && n < Size() );
     wassert( emptySize >= 0 && emptySize < BucketSize );
     wassert( topSize >= n && topSize <= BucketSize );
     DEV {
         // slow:
         for ( int i = 0; i < n-1; i++ ) {
             BSONObj k1 = keyNode(i).key;
             BSONObj k2 = keyNode(i+1).key;
             int z = k1.woCompare(k2, order); //OK
             if ( z > 0 ) {
                 out() << "ERROR: btree key order corrupt.  Keys:" << endl;
                 if ( ++nDumped < 5 ) {
                     for ( int j = 0; j < n; j++ ) {
                         out() << "  " << keyNode(j).key.toString() << endl;
                     }
                     ((BtreeBucket *) this)->dump();
                 }
                 wassert(false);
                 break;
             }
             else if ( z == 0 ) {
                 if ( !(k(i).recordLoc < k(i+1).recordLoc) ) {
                     out() << "ERROR: btree key order corrupt (recordloc's wrong).  Keys:" << endl;
                     out() << " k(" << i << "):" << keyNode(i).key.toString() << " RL:" << k(i).recordLoc.toString() << endl;
                     out() << " k(" << i+1 << "):" << keyNode(i+1).key.toString() << " RL:" << k(i+1).recordLoc.toString() << endl;
                     wassert( k(i).recordLoc < k(i+1).recordLoc );
                 }
             }
         }
     }
     else {
         //faster:
         if ( n > 1 ) {
SdfNamespaceEdit_Namespace::_Node*
SdfNamespaceEdit_Namespace::_Node::FindOrCreateChild(const SdfPath& path)
{
    // Make a key node for the name.
    _VerifyPath(path.GetParentPath());
    _Node keyNode(path.GetNameToken());

    _Children::iterator i = _children->find(keyNode);
    if (i == _children->end()) {
        SdfPath originalPath =
            path.ReplacePrefix(path.GetParentPath(), GetOriginalPath());
        i = _children->insert(new _Node(this, keyNode.GetKey(),
                                        originalPath)).first;
    }
    return &*i;
}
示例#6
0
 bool skipUnusedKeys() {
     int u = 0;
     while ( 1 ) {
         if ( !ok() )
             break;
         const _KeyNode& kn = keyNode(keyOfs);
         if ( kn.isUsed() )
             break;
         bucket = _advance(bucket, keyOfs, _direction, "skipUnusedKeys");
         u++;
         //don't include unused keys in nscanned
         //++_nscanned;
     }
     if ( u > 10 )
         OCCASIONALLY log() << "btree unused skipped:" << u << '\n';
     return u;
 }
SdfNamespaceEdit_Namespace::_Node*
SdfNamespaceEdit_Namespace::_Node::FindOrCreateChild(
    const SdfPath& target,
    const SdfPath& originalTarget,
    bool* created)
{
    // Make a key node for the path.
    _Node keyNode((_TargetKey(target)));

    _Children::iterator i = _children->find(keyNode);
    if ((*created = (i == _children->end()))) {
        SdfPath originalPath = GetOriginalPath().AppendTarget(originalTarget);
        i = _children->insert(new _Node(this, keyNode.GetKey(),
                                        originalPath)).first;
    }
    return &*i;
}
示例#8
0
 /* skip unused keys. */
 bool BtreeCursor::skipUnusedKeys( bool mayJump ) {
     int u = 0;
     while ( 1 ) {
         if ( !ok() )
             break;
         const _KeyNode& kn = keyNode(keyOfs);
         if ( kn.isUsed() )
             break;
         bucket = _advance(bucket, keyOfs, _direction, "skipUnusedKeys");
         u++;
         //don't include unused keys in nscanned
         //++_nscanned;
         if ( mayJump && ( u % 10 == 0 ) ) {
             skipOutOfRangeKeysAndCheckEnd();
         }
     }
     if ( u > 10 )
         OCCASIONALLY log() << "btree unused skipped:" << u << '\n';
     return u;
 }
bool
SdfNamespaceEdit_Namespace::_Node::Reparent(
    _Node* node,
    const SdfPath& path,
    std::string* whyNot)
{
    _VerifyPath(path.GetParentPath());

    // Make a key node for the new path.
    _Node keyNode(path);

    // Verify that no such key exists in our children.
    if (!TF_VERIFY(_children->find(keyNode) == _children->end())) {
        *whyNot = "Coding error: Object with new path already exists";
        return false;
    }

    // Verify that the node hasn't been removed.
    if (!TF_VERIFY(!node->IsRemoved())) {
        *whyNot = "Coding error: Object at path has been removed";
        return false;
    }

    // Remove the node from its parent.
    if (!node->Remove(whyNot)) {
        return false;
    }

    // Change the key.
    node->_key = keyNode.GetKey();

    // Insert the node into our children, taking ownership.
    TF_VERIFY(_children->insert(node).second);
    node->_parent = this;

    return true;
}
示例#10
0
                    break;
                }
                else if ( z == 0 ) {
                    if ( !(k(i).recordLoc < k(i+1).recordLoc) ) {
                        out() << "ERROR: btree key order corrupt (recordloc's wrong).  Keys:" << endl;
                        out() << " k(" << i << "):" << keyNode(i).key.toString() << " RL:" << k(i).recordLoc.toString() << endl;
                        out() << " k(" << i+1 << "):" << keyNode(i+1).key.toString() << " RL:" << k(i+1).recordLoc.toString() << endl;
                        wassert( k(i).recordLoc < k(i+1).recordLoc );
                    }
                }
            }
        }
        else {
            //faster:
            if ( n > 1 ) {
                BSONObj k1 = keyNode(0).key;
                BSONObj k2 = keyNode(n-1).key;
                int z = k1.woCompare(k2, order);
                //wassert( z <= 0 );
                if ( z > 0 ) {
                    problem() << "btree keys out of order" << '\n';
                    ONCE {
                        ((BtreeBucket *) this)->dump();
                    }
                    assert(false);
                }
            }
        }
    }

    inline void BucketBasics::markUnused(int keypos) {