Пример #1
0
NS_IMETHODIMP
nsAutoCompleteController::SetInput(nsIAutoCompleteInput *aInput)
{
  // Don't do anything if the input isn't changing.
  if (mInput == aInput)
    return NS_OK;

  // Clear out the current search context
  if (mInput) {
    // Stop all searches in case they are async.
    StopSearch();
    ClearResults();
    ClosePopup();
    mSearches.Clear();
  }

  mInput = aInput;

  // Nothing more to do if the input was just being set to null.
  if (!aInput)
    return NS_OK;

  nsAutoString newValue;
  aInput->GetTextValue(newValue);

  // Clear out this reference in case the new input's popup has no tree
  mTree = nsnull;

  // Reset all search state members to default values
  mSearchString = newValue;
  mDefaultIndexCompleted = false;
  mBackspaced = false;
  mSearchStatus = nsIAutoCompleteController::STATUS_NONE;
  mRowCount = 0;
  mSearchesOngoing = 0;

  // Initialize our list of search objects
  PRUint32 searchCount;
  aInput->GetSearchCount(&searchCount);
  mResults.SetCapacity(searchCount);
  mSearches.SetCapacity(searchCount);
  mMatchCounts.SetLength(searchCount);

  const char *searchCID = kAutoCompleteSearchCID;

  for (PRUint32 i = 0; i < searchCount; ++i) {
    // Use the search name to create the contract id string for the search service
    nsCAutoString searchName;
    aInput->GetSearchAt(i, searchName);
    nsCAutoString cid(searchCID);
    cid.Append(searchName);

    // Use the created cid to get a pointer to the search service and store it for later
    nsCOMPtr<nsIAutoCompleteSearch> search = do_GetService(cid.get());
    if (search)
      mSearches.AppendObject(search);
  }

  return NS_OK;
}
Пример #2
0
// -----------------------------------------------------------------------------
// CreateTablesL
// Create table through database session
// -----------------------------------------------------------------------------
//
LOCAL_C void CreateTablesL(RDbDatabase& aDatabase)
{
#ifdef _DRM_TESTING
    WriteL(_L8("CreateTablesL"));
#endif

    CDbColSet* columns = CDbColSet::NewLC();

    //filename columns
    TDbCol filename(KColFilename,EDbColLongText16);
    filename.iAttributes = TDbCol::ENotNull;
    columns->AddL(filename);

    //position columns
    TDbCol position(KColPosition,EDbColUint16);
    position.iAttributes = TDbCol::ENotNull;
    columns->AddL(position);

    //content id columns
    TDbCol cid(KColCid,EDbColLongText16);
    cid.iAttributes = TDbCol::ENotNull;
    columns->AddL(cid);

    //content group id columns
    TDbCol group(KColGroupId,EDbColLongText16);
    columns->AddL(group);

    //transaction id columns
    TDbCol ttid(KColTtid,EDbColText16,KTtidLen);
    columns->AddL(ttid);

    aDatabase.CreateTable( KTable,*columns);
    CleanupStack::PopAndDestroy(columns); //columns

}
	private: void do_remove(customer_pointer const& ptr_customer)
	{
		// precondition: customer pointer must be a valid pointer.
		DCS_ASSERT(
			ptr_customer,
			throw ::std::invalid_argument("[dcs::des::model::qn::load_independent_service_strategy::do_remove] Null pointer to a customer.")
		);
//		// precondition: customer must already be assigned for service
//		DCS_ASSERT(
//			customers_servers_.count(ptr_customer->id()) != 0,
//			throw ::std::logic_error("[dcs::des::model::qn::load_independent_service_strategy::do_remove] Customer not in service.")
//		);

		// Retrieve the id of this customer
		customer_identifier_type cid(ptr_customer->id());

		// Retrieve the server assigned to this customer
//		uint_type s_id = customers_servers_[c_id];
		uint_type sid(this->info(cid).server_id());

		// Erase the associated service info 
		servers_.erase(sid);
//		servers_[sid].reset();
		--num_busy_;
	}
Пример #4
0
QString Core::getPeerName(const ToxId& id) const
{
    QString name;
    CUserId cid(id.toString());

    uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        qWarning() << "getPeerName: No such peer";
        return name;
    }

    const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr);
    if (nameSize == SIZE_MAX)
        return name;

    uint8_t* cname = new uint8_t[nameSize<TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
    if (!tox_friend_get_name(tox, friendId, cname, nullptr))
    {
        qWarning() << "getPeerName: Can't get name of friend "+QString().setNum(friendId);
        delete[] cname;
        return name;
    }

    name = CString::toString(cname, nameSize);
    delete[] cname;
    return name;
}
UserPtr DirectoryListing::getUserFromFilename(const string& fileName) {
    // General file list name format: [username].[CID].[xml|xml.bz2|DcLst]

    string name = Util::getFileName(fileName);

    // Strip off any extensions
    if(Util::stricmp(name.c_str() + name.length() - 6, ".DcLst") == 0) {
        name.erase(name.length() - 6);
    }

    if(Util::stricmp(name.c_str() + name.length() - 4, ".bz2") == 0) {
        name.erase(name.length() - 4);
    }

    if(Util::stricmp(name.c_str() + name.length() - 4, ".xml") == 0) {
        name.erase(name.length() - 4);
    }

    // Find CID
    string::size_type i = name.rfind('.');
    if(i == string::npos) {
        return UserPtr();
    }

    size_t n = name.length() - (i + 1);
    // CID's always 39 chars long...
    if(n != 39)
        return UserPtr();

    CID cid(name.substr(i + 1));
    if(cid.isZero())
        return UserPtr();

    return ClientManager::getInstance()->getUser(cid);
}
nsresult
nsXBLContentSink::ConstructBinding()
{
  nsCOMPtr<nsIContent> binding = GetCurrentContent();
  nsAutoString id;
  binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
  NS_ConvertUTF16toUTF8 cid(id);

  nsresult rv = NS_OK;
  
  if (!cid.IsEmpty()) {
    mBinding = new nsXBLPrototypeBinding();
    if (!mBinding)
      return NS_ERROR_OUT_OF_MEMORY;
      
    rv = mBinding->Init(cid, mDocInfo, binding);
    if (NS_SUCCEEDED(rv) &&
        NS_SUCCEEDED(mDocInfo->SetPrototypeBinding(cid, mBinding))) {
      if (!mFoundFirstBinding) {
        mFoundFirstBinding = PR_TRUE;
        mDocInfo->SetFirstPrototypeBinding(mBinding);
      }
      binding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::id, PR_FALSE);
    } else {
      delete mBinding;
      mBinding = nsnull;
    }
  }

  return rv;
}
Пример #7
0
QString Core::getPeerName(const ToxID& id) const
{
    QString name;
    CUserId cid(id.toString());

    uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        qWarning() << "Core::getPeerName: No such peer "+id.toString();
        return name;
    }

    const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr);
    if (nameSize == SIZE_MAX)
    {
        //qDebug() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        return name;
    }

    uint8_t* cname = new uint8_t[nameSize<TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
    if (tox_friend_get_name(tox, friendId, cname, nullptr) == false)
    {
        qWarning() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        delete[] cname;
        return name;
    }

    name = name.fromLocal8Bit((char*)cname, nameSize);
    delete[] cname;
    return name;
}
Пример #8
0
fc::vector<char> cafs::get_chunk( const fc::sha1& id, uint32_t pos, uint32_t s ) {
  try {
    fc::string cid(id);
    fc::path cdir = my->datadir / cid.substr(0,2) / cid.substr(2,2) / cid.substr(4, 2);
    fc::path cfile = cdir / cid.substr( 6 );
    if( !fc::exists( cfile ) ) {
      FC_THROW_REPORT( "File ${path} does not exist", fc::value().set( "path", cfile ) );
    }
    fc::ifstream in( cfile, fc::ifstream::binary );
    chunk_header ch;
    fc::raw::unpack( in, ch );
    //  slog( "get chunk header: %s", fc::json::to_string( ch ).c_str() );
    if( s == uint32_t(-1) ) {
      s = ch.calculate_size();
    }
    // TODO: validate size is not too big... potential for crash allocating size read from disk
    //slog( "size %llu", s );
    //slog( "pos %llu", pos );
    fc::vector<char> v(s);
  //  in.read(v.data(),s);

    // validate that we actually have the data for the range pos -> pos +s
    fc::datastream<char*> ds(v.data(),s);
  #if 1
    uint32_t cpos = 0;
    for( auto itr = ch.slices.begin(); itr != ch.slices.end(); ++itr ) {
      if( pos >= cpos && pos < cpos + itr->size ) {
          fc::vector<char> tmp(itr->size);
          in.read(tmp.data(),itr->size);

          if( fc::sha1::hash( tmp.data(), tmp.size() ) != itr->hash ) {
            FC_THROW_REPORT( "Slice hash does not match header for chunk ${chunk_id}",
               fc::value().set( "chunk_id", id ).set("pos", pos).set("size",s).set("chunk_header",ch));
          }
          //slog( "pos %d   cpos %d  size %d  remain %d", pos, cpos, s, ds.remaining() );

          int start  = (pos-cpos);
          int left   = tmp.size()-start;
          int cbytes = (fc::min)(size_t(left),size_t(ds.remaining()));
          ds.write( tmp.data() + start, cbytes );
          pos += cbytes;
          s   -= cbytes;
      } else {
          in.seekg( itr->size, fc::ifstream::cur );
      }
      cpos += itr->size;
      if( ds.remaining() == 0 )
        return v;
    }

    //slog( "data %llu  %s", v.size(), fc::to_hex( v.data(), 16 ).c_str() );
  #endif

    return v;
  } catch ( fc::error_report& er ) {
    throw FC_REPORT_PUSH( er, "Unable to get chunk id ${chunk_id}", 
                              fc::value().set( "chunk_id", id ).set("pos", pos).set("size",s) );
  }
}
Пример #9
0
int CComponentIDToolApp::Cmd_Dump()
{
    CCompoundID cid(m_CompoundIDPool.FromString(m_Opts.cid));

    fprintf(m_Opts.output_stream, "%s\n", cid.Dump().c_str());

    return 0;
}
list<ContainerId> StopContainersResponse::getSucceededRequests() {
	list<ContainerId> cids;
	int size = responseProto.succeeded_requests_size();
	for (int i = 0; i < size; i++) {
		ContainerIdProto proto = responseProto.succeeded_requests(i);
		ContainerId cid(proto);
		cids.push_back(cid);
	}
	return cids;
}
 const ComponentID& ComponentManager::createComponent(const ComponentTypeID& type, const ObjectID& oid) {
     unsigned int typeIndex = type; //conversion to index
     tComponentCreator creator = m_componentInfos[typeIndex].Creator;
     unsigned int componentIndex = m_componentIndices.allocate();
     ComponentID cid(componentIndex); // convert to ComponentID
     ComponentBase* component = (*creator)(cid, oid);
     m_instanceInfos[componentIndex].Component = type;
     m_instanceInfos[componentIndex].Pointer = component;
     return component->getComponentID();
 }
Пример #12
0
Array<CQLIdentifier> CQLChainedIdentifier::getSubIdentifiers()const
{
  Array<CQLIdentifier> result;
  Array<QueryIdentifier> qIds = _rep->getSubIdentifiers();
  for (Uint32 i = 0; i < qIds.size(); i++)
  {
    CQLIdentifier cid(qIds[i]);
    result.append(cid);
  }

  return result;
}
Пример #13
0
	unsigned cid(int ic){
		bool upper = ic >= nwords/2;
		int ib = ic/4;

		if (verbose > 1){
			printf("cid(%d) ib:%d switch(%c) %s\n",
				ic, ib, actual_banks[ib], actual_banks);
		}

		switch(actual_banks[ib]){
		case 'A':	return cid(ic, upper, 0);
		case 'B':	return cid(ic, upper, 4);
		case 'C':	return cid(ic, upper, 8);
		case 'D':	return cid(ic, upper,12);
		case 'S': 	
		case 'P':
		case 'l':
		case 'm':
			return 0;
		default:
			assert(0);
		}
	}
Пример #14
0
bool Controller::Run()
{   
    TRACE("Controller::Run");
    string cid("adaptor");
    string uri = string("tcp://173.39.202.21:1883");
    mqtt_svc.Init( uri, cid);
    int port = 3000;  //get from config
    tcp_svc.Init(port);

    mqtt_svc.Monitor();
    tcp_svc.Monitor();     
    loop.run(); 
    return true;
}
Пример #15
0
void Patch::gbisP2Ready() {
 ComputePtrListIter cid(positionComputeList);

  int compute_count = 0;
  int seq = flags.sequence;
  for(cid = cid.begin(); cid != cid.end(); cid++) {
    if ( (*cid)->type() == computeNonbondedSelfType ||
         (*cid)->type() == computeNonbondedPairType ||
         (*cid)->type() == computeNonbondedCUDAType) {
      compute_count++;
      (*cid)->gbisP2PatchReady(patchID,seq);
    }
  }
}
Пример #16
0
/**
 * main deserialization hook
 */
void
ClientManifest::Deserialize(ClientID _clientID, UserID _userID, std::string serializedOccupiedRoomIDs, std::string serializedObservedRoomIDs,
		std::string globalAttrs, std::vector<std::string> roomAttrs) {
	clientID = _clientID;
	userID = _userID;
	DeserializeOccupiedRoomIDs(serializedOccupiedRoomIDs);
	DeserializeObservedRoomIDs(serializedObservedRoomIDs);
	DeserializeAttributesByScope(Token::GLOBAL_ATTR, globalAttrs);

	auto it=roomAttrs.begin();
	while (it!=roomAttrs.end()) {
		std::string cid(*it);
		++it;
		DeserializeAttributesByScope(cid, *(it));
		++it;
	}
};
Пример #17
0
int CComponentIDToolApp::Cmd_Make()
{
    string dump;

    char buffer[1024];
    size_t bytes_read;

    do {
        bytes_read = fread(buffer, 1, sizeof(buffer), m_Opts.input_stream);
        dump.append(buffer, bytes_read);
    } while (bytes_read == sizeof(buffer));

    CCompoundID cid(m_CompoundIDPool.FromDump(dump));

    puts(cid.ToString().c_str());

    return 0;
}
Пример #18
0
/**
 *  Validates that the chunk id matches the chunk_header and data.
 *  Stores the chunk to disk
 *
 *  @pre data is randomized
 */
fc::sha1 cafs::store_chunk( const chunk_header& head, const fc::vector<char>& data ) {
  // TODO: validate pre-conditions
  fc::sha1 h = head.calculate_id();
  fc::string cid(h);
  fc::path cdir = my->datadir / cid.substr(0,2) / cid.substr(2,2) / cid.substr(4, 2);
  create_directories( cdir );
  fc::path cfile = cdir / cid.substr( 6 );
  if( fc::exists( cfile ) ) {
      wlog( "store chunk %s already exists", cfile.string().c_str() );
      return h;
  }
  slog( "store chunk %s size %d", cfile.string().c_str(), data.size() );
  fc::ofstream out( cfile.string(), fc::ofstream::binary );
  fc::raw::pack( out, head );
//  slog( "header size %d", fc::raw::pack(head).size() );
//  slog( "data %llu  %s", data.size(), fc::to_hex( data.data(), 16 ).c_str() );
  out.write( data.data(), data.size() );
  return h;
}
Пример #19
0
inline class_id_type
basic_iarchive_impl::register_type(
    const basic_iserializer & bis
){
    class_id_type cid(cobject_info_set.size());
    cobject_type co(cid, bis);
    std::pair<cobject_info_set_type::const_iterator, bool>
        result = cobject_info_set.insert(co);

    if(result.second){
        cobject_id_vector.push_back(cobject_id(bis));
        BOOST_ASSERT(cobject_info_set.size() == cobject_id_vector.size());
    }
    cid = result.first->m_class_id;
    // borland complains without this minor hack
    const int tid = cid;
    cobject_id & coid = cobject_id_vector[tid];
    coid.bpis_ptr = bis.get_bpis_ptr();
    return cid;
}
Пример #20
0
User UserManagement::fetchUser(QString username)
{
    QSqlQuery fetchquery;
    QString customername,customersurname, cid ("");

    fetchquery = sqlMechanism.myQuery();
    fetchquery.prepare("SELECT * FROM Users WHERE Username= :uname");
    fetchquery.bindValue(":uname",username);
    fetchquery.exec();

    while (fetchquery.next())
    {
     user.setName(fetchquery.value(1).toString());
     user.setSurname(fetchquery.value(2).toString());
     user.setUsername(fetchquery.value(3).toString());
     user.setPassword(fetchquery.value(4).toString());
     user.setRole(fetchquery.value(5).toString());
    }

    return user;
}
Пример #21
0
void
basic_iarchive_impl::load_preamble(
    basic_iarchive & ar,
    cobject_id & co
){
    if(! co.initialized){
        if(co.bis_ptr->class_info()){
            class_id_optional_type cid(class_id_type(0));
            load(ar, cid);    // to be thrown away
            load(ar, co.tracking_level);
            load(ar, co.file_version);
        }
        else{
            // override tracking with indicator from class information
            co.tracking_level = co.bis_ptr->tracking(m_flags);
            co.file_version = version_type(
                co.bis_ptr->version()
            );
        }
        co.initialized = true;
    }
}
Пример #22
0
void
DCStartd::asyncRequestOpportunisticClaim( ClassAd const *req_ad, char const *description, char const *scheduler_addr, int alive_interval, int timeout, int deadline_timeout, classy_counted_ptr<DCMsgCallback> cb )
{
	dprintf(D_FULLDEBUG|D_PROTOCOL,"Requesting claim %s\n",description);

	setCmdStr( "requestClaim" );
	ASSERT( checkClaimId() );
	ASSERT( checkAddr() );

	classy_counted_ptr<ClaimStartdMsg> msg = new ClaimStartdMsg( claim_id, extra_ids, req_ad, description, scheduler_addr, alive_interval );

	ASSERT( msg.get() );
	msg->setCallback(cb);

	msg->setSuccessDebugLevel(D_ALWAYS|D_PROTOCOL);

		// if this claim is associated with a security session
	ClaimIdParser cid(claim_id);
	msg->setSecSessionId(cid.secSessionId());

	msg->setTimeout(timeout);
	msg->setDeadlineTimeout(deadline_timeout);
	sendMsg(msg.get());
}
Пример #23
0
void
DCStartd::asyncSwapClaims(const char * claim_id, char const *src_descrip, const char * dest_slot_name, int timeout, classy_counted_ptr<DCMsgCallback> cb)
{
	dprintf(D_FULLDEBUG|D_PROTOCOL,"Swapping claim %s into slot %s\n", src_descrip, dest_slot_name);

	setCmdStr( "swapClaims" );
	ASSERT( checkClaimId() );
	ASSERT( checkAddr() );

	classy_counted_ptr<SwapClaimsMsg> msg = new SwapClaimsMsg( claim_id, src_descrip, dest_slot_name );

	ASSERT( msg.get() );
	msg->setCallback(cb);

	msg->setSuccessDebugLevel(D_ALWAYS|D_PROTOCOL);

		// if this claim is associated with a security session
	ClaimIdParser cid(claim_id);
	msg->setSecSessionId(cid.secSessionId());

	msg->setTimeout(timeout);
	//msg->setDeadlineTimeout(deadline_timeout);
	sendMsg(msg.get());
}
Пример #24
0
void CCompoundIDField::Remove()
{
    CCompoundID cid(m_Impl->m_CID);
    m_Impl->m_CID = NULL;
    cid->Remove(m_Impl);
}
Пример #25
0
    void WriteBackListener::run() {
        int secsToSleep = 0;
        while ( ! inShutdown() ) {
            
            if ( ! Shard::isAShardNode( _addr ) ) {
                log(1) << _addr << " is not a shard node" << endl;
                sleepsecs( 60 );
                continue;
            }

            try {
                ScopedDbConnection conn( _addr );

                BSONObj result;

                {
                    BSONObjBuilder cmd;
                    cmd.appendOID( "writebacklisten" , &serverID ); // Command will block for data
                    if ( ! conn->runCommand( "admin" , cmd.obj() , result ) ) {
                        log() <<  "writebacklisten command failed!  "  << result << endl;
                        conn.done();
                        continue;
                    }

                }

                log(1) << "writebacklisten result: " << result << endl;

                BSONObj data = result.getObjectField( "data" );
                if ( data.getBoolField( "writeBack" ) ) {
                    string ns = data["ns"].valuestrsafe();

                    ConnectionIdent cid( "" , 0 );
                    OID wid;
                    if ( data["connectionId"].isNumber() && data["id"].type() == jstOID ) {
                        string s = "";
                        if ( data["instanceIdent"].type() == String )
                            s = data["instanceIdent"].String();
                        cid = ConnectionIdent( s , data["connectionId"].numberLong() );
                        wid = data["id"].OID();
                    }
                    else {
                        warning() << "mongos/mongod version mismatch (1.7.5 is the split)" << endl;
                    }

                    int len; // not used, but needed for next call
                    Message m( (void*)data["msg"].binData( len ) , false );
                    massert( 10427 ,  "invalid writeback message" , m.header()->valid() );

                    DBConfigPtr db = grid.getDBConfig( ns );
                    ShardChunkVersion needVersion( data["version"] );

                    LOG(1) << "connectionId: " << cid << " writebackId: " << wid << " needVersion : " << needVersion.toString()
                           << " mine : " << db->getChunkManager( ns )->getVersion().toString() << endl;// TODO change to log(3)

                    if ( logLevel ) log(1) << debugString( m ) << endl;

                    if ( needVersion.isSet() && needVersion <= db->getChunkManager( ns )->getVersion() ) {
                        // this means when the write went originally, the version was old
                        // if we're here, it means we've already updated the config, so don't need to do again
                        //db->getChunkManager( ns , true ); // SERVER-1349
                    }
                    else {
                        // we received a writeback object that was sent to a previous version of a shard
                        // the actual shard may not have the object the writeback operation is for
                        // we need to reload the chunk manager and get the new shard versions
                        db->getChunkManager( ns , true );
                    }

                    // do request and then call getLastError
                    // we have to call getLastError so we can return the right fields to the user if they decide to call getLastError

                    BSONObj gle;
                    try {
                        
                        Request r( m , 0 );
                        r.init();

                        ClientInfo * ci = r.getClientInfo();
                        if (!noauth) {
                            ci->getAuthenticationInfo()->authorize("admin", internalSecurity.user);
                        }
                        ci->noAutoSplit();

                        r.process();
                        
                        ci->newRequest(); // this so we flip prev and cur shards

                        BSONObjBuilder b;
                        if ( ! ci->getLastError( BSON( "getLastError" << 1 ) , b , true ) ) {
                            b.appendBool( "commandFailed" , true );
                        }
                        gle = b.obj();

                        ci->clearSinceLastGetError();
                    }
                    catch ( DBException& e ) {
                        error() << "error processing writeback: " << e << endl;
                        BSONObjBuilder b;
                        b.append( "err" , e.toString() );
                        e.getInfo().append( b );
                        gle = b.obj();
                    }

                    {
                        scoped_lock lk( _seenWritebacksLock );
                        WBStatus& s = _seenWritebacks[cid];
                        s.id = wid;
                        s.gle = gle;
                    }
                }
                else if ( result["noop"].trueValue() ) {
                    // no-op
                }
                else {
                    log() << "unknown writeBack result: " << result << endl;
                }

                conn.done();
                secsToSleep = 0;
                continue;
            }
            catch ( std::exception& e ) {

                if ( inShutdown() ) {
                    // we're shutting down, so just clean up
                    return;
                }

                log() << "WriteBackListener exception : " << e.what() << endl;

                // It's possible this shard was removed
                Shard::reloadShardInfo();
            }
            catch ( ... ) {
                log() << "WriteBackListener uncaught exception!" << endl;
            }
            secsToSleep++;
            sleepsecs(secsToSleep);
            if ( secsToSleep > 10 )
                secsToSleep = 0;
        }

        log() << "WriteBackListener exiting : address no longer in cluster " << _addr;

    }
Пример #26
0
		void BaseCalendarUpdateAction::_setCalendarUpdateFromParametersMap(
			Env& env,
			const util::ParametersMap& map
		){
			// Calendar template
			RegistryKeyType cid(map.getDefault<RegistryKeyType>(PARAMETER_CALENDAR_TEMPLATE_ID, 0));
			if(cid > 0) try
			{
				_calendarTemplate = CalendarTemplateTableSync::GetEditable(cid, env);
				CalendarTemplateElementTableSync::Search(env, cid);
			}
			catch(ObjectNotFoundException<CalendarTemplate>&)
			{
				throw ActionException("No such calendar template");
			}

			// Calendar template
			RegistryKeyType cid2(map.getDefault<RegistryKeyType>(PARAMETER_CALENDAR_TEMPLATE_ID2, 0));
			if(cid2 > 0) try
			{
				_calendarTemplate2 = CalendarTemplateTableSync::GetEditable(cid2, env);
				CalendarTemplateElementTableSync::Search(env, cid2);
			}
			catch(ObjectNotFoundException<CalendarTemplate>&)
			{
				throw ActionException("No such calendar template 2");
			}

			// Start and end dates
			string startDateStr(
				map.getDefault<string>(PARAMETER_START_DATE)
			);
			if(!startDateStr.empty())
			{
				_startDate = from_string(startDateStr);
				_endDate = from_string(map.getDefault<string>(PARAMETER_END_DATE, startDateStr));
				if(_startDate > _endDate)
				{
					throw ActionException("The start date must be after the end date");
				}

				// Period
				_period = days(map.getDefault<long>(PARAMETER_PERIOD, 1));
				if(_period.days() < 1)
				{
					throw ActionException("Period must be at least one day long");
				}
			}

			// Add or remove
			_add = map.getDefault<bool>(PARAMETER_ADD, _add);

			// Add a new link
			_addLink = map.getDefault<bool>(PARAMETER_ADD_LINK, _addLink);

			// Link to remove
			_linkToRemove = map.getOptional<RegistryKeyType>(PARAMETER_LINK_TO_REMOVE);

			// date to force to add
			string addDateToForceStr(
				map.getDefault<string>(PARAMETER_ADD_DATE_TO_FORCE)
			);
			if(!addDateToForceStr.empty())
			{
				_dateToForceToAdd = from_string(addDateToForceStr);
			}

			// date to force to remove
			string removeDateToForceStr(
				map.getDefault<string>(PARAMETER_REMOVE_DATE_TO_FORCE)
			);
			if(!removeDateToForceStr.empty())
			{
				_dateToForceToRemove = from_string(removeDateToForceStr);
			}

			// date to bypass to add
			string addDateToBypassStr(
				map.getDefault<string>(PARAMETER_ADD_DATE_TO_BYPASS)
			);
			if(!addDateToBypassStr.empty())
			{
				_dateToBypassToAdd = from_string(addDateToBypassStr);
			}

			// date to bypass to remove
			string removeDateToBypassStr(
				map.getDefault<string>(PARAMETER_REMOVE_DATE_TO_BYPASS)
			);
			if(!removeDateToBypassStr.empty())
			{
				_dateToBypassToRemove = from_string(removeDateToBypassStr);
			}
		}
Пример #27
0
bool CNetScheduleKey::ParseJobKey(const string& key_str,
        CCompoundIDPool::TInstance id_pool)
{
    // Parses several notations for job id:
    // version 1:
    //   JSID_01_JOBNUMBER_IP_PORT_QUEUE
    // "version 0", or just a job number.

    const char* ch = key_str.c_str();
    if (key_str.compare(0, NS_KEY_V1_PREFIX_LEN, NS_KEY_V1_PREFIX) == 0) {
        // Version 1 key
        version = 1;
        ch += NS_KEY_V1_PREFIX_LEN;

        // Extract the job number field.
        if ((id = (unsigned) atoi(ch)) == 0)
            return false;
        do
            if (*++ch == '\0')
                return false;
        while (*ch != '_');

        // Find the host name field boundaries.
        const char* token_begin = ++ch;
        while (*ch != '\0' && *ch++ != '_')
            /* noop */;

        // Extract the server port number.
        if ((port = (unsigned short) atoi(ch)) == 0)
            return false;

        // Everything's OK so far, save the host name/IP.
        host.assign(token_begin, ch - token_begin - 1);
        if (host.empty())
            return false;

        // Skip to the queue name.
        while (*++ch != '_')
            if (*ch < '0' || *ch > '9')
                return *ch == '\0';

        // Queue name is specified - extract it.
        int underscores_to_skip = 0;
        while (*++ch == '_')
            ++underscores_to_skip;
        if (*ch == '\0')
            return false;
        // At this point, *ch is neither '_' nor '\0'.
        token_begin = ch;
        while (*++ch != '\0')
            if ((*ch < '0' || *ch > '9') && (*ch < 'a' || *ch > 'z') &&
                    (*ch < 'A' || *ch > 'Z') && *ch != '-') {
                if (*ch != '_')
                    return false;
                else if (--underscores_to_skip < 0)
                    break;
            }
        if (underscores_to_skip > 0)
            return false;
        queue.assign(token_begin, ch - token_begin);

        return true;
    } else if (id_pool != NULL) {
        try {
            CCompoundIDPool pool_obj(id_pool);
            CCompoundID cid(pool_obj.FromString(key_str));
            version = 2;
            CCompoundIDField field(cid.GetFirst(eCIT_ID));
            if (field) {
                id = (unsigned) field.GetID();
                field = cid.GetFirst(eCIT_DatabaseName);
                if (field)
                    queue = field.GetDatabaseName();
                field = cid.GetFirst(eCIT_IPv4SockAddr);
                if (field) {
                    host = CSocketAPI::ntoa(field.GetIPv4Address());
                    port = field.GetPort();
                    return true;
                } else {
                    field = cid.GetFirst(eCIT_Host);
                    if (field) {
                        host = field.GetHost();
                        field = cid.GetFirst(eCIT_Port);
                        if (field) {
                            port = field.GetPort();
                            return true;
                        }
                    }
                }
            }
        }
        catch (CCompoundIDException&) {
            // Do not exit the function yet -- check if
            // it's a verbatim job ID.
        }
    }

    if (isdigit(*ch)) {
        version = 0;
        id = (unsigned) atoi(ch);
        return true;
    }

    return false;
}
Пример #28
0
    void WriteBackListener::run() {

        int secsToSleep = 0;
        scoped_ptr<ChunkVersion> lastNeededVersion;
        int lastNeededCount = 0;
        bool needsToReloadShardInfo = false;

        while ( ! inShutdown() ) {

            if ( ! Shard::isAShardNode( _addr ) ) {
                LOG(1) << _addr << " is not a shard node" << endl;
                sleepsecs( 60 );
                continue;
            }

            try {
                if (needsToReloadShardInfo) {
                    // It's possible this shard was removed
                    Shard::reloadShardInfo();
                    needsToReloadShardInfo = false;
                }

                scoped_ptr<ScopedDbConnection> conn(
                        ScopedDbConnection::getInternalScopedDbConnection( _addr ) );

                BSONObj result;

                {
                    BSONObjBuilder cmd;
                    cmd.appendOID( "writebacklisten" , &serverID ); // Command will block for data
                    if ( ! conn->get()->runCommand( "admin" , cmd.obj() , result ) ) {
                        result = result.getOwned();
                        log() <<  "writebacklisten command failed!  "  << result << endl;
                        conn->done();
                        continue;
                    }

                }
                conn->done();

                LOG(1) << "writebacklisten result: " << result << endl;

                BSONObj data = result.getObjectField( "data" );
                if ( data.getBoolField( "writeBack" ) ) {
                    string ns = data["ns"].valuestrsafe();

                    ConnectionIdent cid( "" , 0 );
                    OID wid;
                    if ( data["connectionId"].isNumber() && data["id"].type() == jstOID ) {
                        string s = "";
                        if ( data["instanceIdent"].type() == String )
                            s = data["instanceIdent"].String();
                        cid = ConnectionIdent( s , data["connectionId"].numberLong() );
                        wid = data["id"].OID();
                    }
                    else {
                        warning() << "mongos/mongod version mismatch (1.7.5 is the split)" << endl;
                    }

                    int len; // not used, but needed for next call
                    Message msg( (void*)data["msg"].binData( len ) , false );
                    massert( 10427 ,  "invalid writeback message" , msg.header()->valid() );

                    DBConfigPtr db = grid.getDBConfig( ns );
                    ChunkVersion needVersion = ChunkVersion::fromBSON( data, "version" );

                    //
                    // TODO: Refactor the sharded strategy to correctly handle all sharding state changes itself,
                    // we can't rely on WBL to do this for us b/c anything could reset our state in-between.
                    // We should always reload here for efficiency when possible, but staleness is also caught in the
                    // loop below.
                    //

                    ChunkManagerPtr manager;
                    ShardPtr primary;
                    db->getChunkManagerOrPrimary( ns, manager, primary );

                    ChunkVersion currVersion;
                    if( manager ) currVersion = manager->getVersion();

                    LOG(1) << "connectionId: " << cid << " writebackId: " << wid << " needVersion : " << needVersion.toString()
                           << " mine : " << currVersion.toString() << endl;

                    LOG(1) << msg.toString() << endl;

                    //
                    // We should reload only if we need to update our version to be compatible *and* we
                    // haven't already done so.  This avoids lots of reloading when we remove/add a sharded collection
                    //

                    bool alreadyReloaded = lastNeededVersion &&
                                           lastNeededVersion->isEquivalentTo( needVersion );

                    if( alreadyReloaded ){

                        LOG(1) << "wbl already reloaded config information for version "
                               << needVersion << ", at version " << currVersion << endl;
                    }
                    else if( lastNeededVersion ) {

                        log() << "new version change detected to " << needVersion.toString()
                              << ", " << lastNeededCount << " writebacks processed at "
                              << lastNeededVersion->toString() << endl;

                        lastNeededCount = 0;
                    }

                    //
                    // Set our lastNeededVersion for next time
                    //

                    lastNeededVersion.reset( new ChunkVersion( needVersion ) );
                    lastNeededCount++;

                    //
                    // Determine if we should reload, if so, reload
                    //

                    bool shouldReload = ! needVersion.isWriteCompatibleWith( currVersion ) &&
                                        ! alreadyReloaded;

                    if( shouldReload && currVersion.isSet()
                                     && needVersion.isSet()
                                     && currVersion.hasCompatibleEpoch( needVersion ) )
                    {

                        //
                        // If we disagree about versions only, reload the chunk manager
                        //

                        db->getChunkManagerIfExists( ns, true );
                    }
                    else if( shouldReload ){

                        //
                        // If we disagree about anything else, reload the full db
                        //

                        warning() << "reloading config data for " << db->getName() << ", "
                                  << "wanted version " << needVersion.toString()
                                  << " but currently have version " << currVersion.toString() << endl;

                        db->reload();
                    }

                    // do request and then call getLastError
                    // we have to call getLastError so we can return the right fields to the user if they decide to call getLastError

                    BSONObj gle;
                    int attempts = 0;
                    while ( true ) {
                        attempts++;

                        try {

                            Request r( msg , 0 );
                            r.init();

                            r.d().reservedField() |= Reserved_FromWriteback;

                            ClientInfo * ci = r.getClientInfo();
                            if (!noauth) {
                                ci->getAuthorizationManager()->grantInternalAuthorization(
                                        "_writebackListener");
                            }
                            ci->noAutoSplit();

                            r.process( attempts );

                            ci->newRequest(); // this so we flip prev and cur shards

                            BSONObjBuilder b;
                            string errmsg;
                            if ( ! ci->getLastError( "admin",
                                                     BSON( "getLastError" << 1 ),
                                                     b,
                                                     errmsg,
                                                     true ) )
                            {
                                b.appendBool( "commandFailed" , true );
                                if( ! b.hasField( "errmsg" ) ){

                                    b.append( "errmsg", errmsg );
                                    gle = b.obj();
                                }
                                else if( errmsg.size() > 0 ){

                                    // Rebuild GLE object with errmsg
                                    // TODO: Make this less clumsy by improving GLE interface
                                    gle = b.obj();

                                    if( gle["errmsg"].type() == String ){

                                        BSONObj gleNoErrmsg =
                                                gle.filterFieldsUndotted( BSON( "errmsg" << 1 ),
                                                                          false );
                                        BSONObjBuilder bb;
                                        bb.appendElements( gleNoErrmsg );
                                        bb.append( "errmsg", gle["errmsg"].String() +
                                                             " ::and:: " +
                                                             errmsg );
                                        gle = bb.obj().getOwned();
                                    }
                                }
                            }
                            else{
                                gle = b.obj();
                            }

                            if ( gle["code"].numberInt() == 9517 ) {

                                log() << "new version change detected, "
                                      << lastNeededCount << " writebacks processed previously" << endl;

                                lastNeededVersion.reset();
                                lastNeededCount = 1;

                                log() << "writeback failed because of stale config, retrying attempts: " << attempts << endl;
                                LOG(1) << "writeback error : " << gle << endl;

                                //
                                // Bringing this in line with the similar retry logic elsewhere
                                //
                                // TODO: Reloading the chunk manager may not help if we dropped a
                                // collection, but we don't actually have that info in the writeback
                                // error
                                //

                                if( attempts <= 2 ){
                                    db->getChunkManagerIfExists( ns, true );
                                }
                                else{
                                    versionManager.forceRemoteCheckShardVersionCB( ns );
                                    sleepsecs( attempts - 1 );
                                }

                                uassert( 15884, str::stream()
                                         << "Could not reload chunk manager after "
                                         << attempts << " attempts.", attempts <= 4 );

                                continue;
                            }

                            ci->clearSinceLastGetError();
                        }
                        catch ( DBException& e ) {
                            error() << "error processing writeback: " << e << endl;
                            BSONObjBuilder b;
                            e.getInfo().append( b, "err", "code" );
                            gle = b.obj();
                        }

                        break;
                    }

                    {
                        scoped_lock lk( _seenWritebacksLock );
                        WBStatus& s = _seenWritebacks[cid];
                        s.id = wid;
                        s.gle = gle;
                    }
                }
                else if ( result["noop"].trueValue() ) {
                    // no-op
                }
                else {
                    log() << "unknown writeBack result: " << result << endl;
                }

                secsToSleep = 0;
                continue;
            }
            catch ( std::exception& e ) {
                // Attention! Do not call any method that would throw an exception
                // (or assert) in this block.

                if ( inShutdown() ) {
                    // we're shutting down, so just clean up
                    return;
                }

                log() << "WriteBackListener exception : " << e.what() << endl;

                needsToReloadShardInfo = true;
            }
            catch ( ... ) {
                log() << "WriteBackListener uncaught exception!" << endl;
            }
            secsToSleep++;
            sleepsecs(secsToSleep);
            if ( secsToSleep > 10 )
                secsToSleep = 0;
        }

        log() << "WriteBackListener exiting : address no longer in cluster " << _addr;

    }
Пример #29
0
void Module::insert(Class* c)
{
    ClassMap::iterator iter = classes_.find( c->id() );


    if (iter != classes_.end())
    {
        errorf(c->loc(), "there is already a class '%s' defined in module '%s'", c->cid(), cid());
        SWIFT_PREV_ERROR(iter->second->loc());

        ctxt_->result_ = false;
        return;
    }

    classes_[c->id()] = c;
    ctxt_->class_ = c;

    return;
}
Пример #30
0
	ACQ435_Data(const char* _def, int _site,
			const char* _banks, unsigned id_mask) :
				def(_def), site(_site),
				banks(_banks),
				nwords(0), nbanks(0),
				ID_MASK(id_mask)
	{
		memset(bank_mask, 0, sizeof(bank_mask));


		for (int ii = 0; ii < strlen(banks); ++ii){
			bank_mask[banks[ii]] = 1;
			switch(banks[ii]){
			case 'A':
			case 'B':
			case 'C':
			case 'D':
				nwords += 8;
				++nbanks;
				break;
			case 'S':
				nwords += 8;
				spad_enabled = true;
			case 'P':
				nwords += 1;
				pmod_present = true;
				break;
			case 'l':
			case 'm':
				// bitslice opts: ignore
				break;
			default:
				fprintf(stderr, "ERROR invalid bank %c\n", banks[ii]);
				exit(-1);
			}
		}
		unsigned sid = site << 5;
		actual_banks = new char[nbanks*2+2+1];
		int ib = 0;

		// banks ABCD actual_banks ABCDDCBA
		for (; ib < nbanks; ++ib){
			actual_banks[ib] = banks[ib];
			actual_banks[2*nbanks-ib-1] = banks[ib];
		}
		ib = nbanks * 2;

		if (pmod_present) actual_banks[ib++] = 'P';
		if (spad_enabled) actual_banks[ib++] = 'S';
		actual_banks[ib] = '\0';


		ids = new unsigned[nwords];

		if (spad_enabled && monitor_spad){
			printf("MONITOR_SPAD: enabled\n");
			spad_cache = new unsigned[nwords];
		}

		bool pmod_done = false;
		bool sample_done = false;

		for (int ic = 0; ic < nwords; ++ic){
			if (ic < nbanks*8){
				ids[ic] = sid | cid(ic);
			}else{
				if (pmod_present && !pmod_done){
					ids[ic] = IDS_NOCHECK;
					pmod_done = true;
				}else if (spad_enabled && !sample_done){
					ids[ic] = IDS_SAMPLE;
					sample_done = true;
				}else{
					ids[ic] = monitor_spad? IDS_SPAD: IDS_NOCHECK;
				}
			}
		}
	}