uint32_t ObjectStore::_startSync( Object* object, NodePtr master, const uint128_t& id, const uint32_t instanceID ) { LB_TS_NOT_THREAD( _receiverThread ); LBLOG( LOG_OBJECTS ) << "Syncing " << lunchbox::className( object ) << " with id " << id << std::endl; LBASSERT( object ); LBASSERTINFO( id.isUUID(), id ); if( !object || !id.isUUID( )) { LBWARN << "Invalid object " << object << " or id " << id << std::endl; return LB_UNDEFINED_UINT32; } if( !master ) master = _localNode->connectObjectMaster( id ); if( !master || !master->isReachable( )) { LBWARN << "Mapping of object " << id << " failed, invalid master node" << std::endl; return LB_UNDEFINED_UINT32; } const uint32_t request = _localNode->registerRequest( new ObjectDataIStream ); uint128_t minCachedVersion = VERSION_HEAD; uint128_t maxCachedVersion = VERSION_NONE; uint32_t cacheInstanceID = 0; bool useCache = _checkInstanceCache( id, minCachedVersion, maxCachedVersion, cacheInstanceID ); if( useCache ) { switch( instanceID ) { case CO_INSTANCE_ALL: break; default: if( instanceID == cacheInstanceID ) break; useCache = false; LBCHECK( _instanceCache->release( id, 1 )); break; } } // Use stream expected by MasterCMCommand master->send( CMD_NODE_SYNC_OBJECT ) << VERSION_NEWEST << minCachedVersion << maxCachedVersion << id << uint64_t(0) /* maxVersions */ << request << instanceID << cacheInstanceID << useCache; return request; }
uint32_t ObjectStore::mapNB( Object* object, const uint128_t& id, const uint128_t& version, NodePtr master ) { LB_TS_NOT_THREAD( _receiverThread ); LBLOG( LOG_OBJECTS ) << "Mapping " << lunchbox::className( object ) << " to id " << id << " version " << version << std::endl; LBASSERT( object ); LBASSERTINFO( id.isUUID(), id ); if( !master ) master = _localNode->connectObjectMaster( id ); if( !master || !master->isReachable( )) { LBWARN << "Mapping of object " << id << " failed, invalid master node" << std::endl; return LB_UNDEFINED_UINT32; } if( !object || !id.isUUID( )) { LBWARN << "Invalid object " << object << " or id " << id << std::endl; return LB_UNDEFINED_UINT32; } const bool isAttached = object->isAttached(); const bool isMaster = object->isMaster(); LBASSERTINFO( !isAttached, *object ); LBASSERT( !isMaster ) ; if( isAttached || isMaster ) { LBWARN << "Invalid object state: attached " << isAttached << " master " << isMaster << std::endl; return LB_UNDEFINED_UINT32; } const uint32_t request = _localNode->registerRequest( object ); uint128_t minCachedVersion = VERSION_HEAD; uint128_t maxCachedVersion = VERSION_NONE; uint32_t masterInstanceID = 0; const bool useCache = _checkInstanceCache( id, minCachedVersion, maxCachedVersion, masterInstanceID ); object->notifyAttach(); master->send( CMD_NODE_MAP_OBJECT ) << version << minCachedVersion << maxCachedVersion << id << object->getMaxVersions() << request << _genNextID( _instanceIDs ) << masterInstanceID << useCache; return request; }