Пример #1
0
std::shared_ptr<CoreContext> CoreContext::CurrentContext(void) {
  if(!autoCurrentContext.get())
    return std::static_pointer_cast<CoreContext, GlobalCoreContext>(GetGlobalContext());

  std::shared_ptr<CoreContext>* retVal = autoCurrentContext.get();
  assert(retVal);
  assert(*retVal);
  return *retVal;
}
Пример #2
0
    /** Get a scope from the pool of scopes matching the supplied pool name */
    auto_ptr<Scope> ScriptEngine::getPooledScope(const string& pool) {
        if (!scopeCache.get())
            scopeCache.reset(new ScopeCache());

        Scope* s = scopeCache->get(pool);
        if (!s)
            s = newScope();

        auto_ptr<Scope> p;
        p.reset(new PooledScope(pool, s));
        return p;
    }
Пример #3
0
    /** Get a scope from the pool of scopes matching the supplied pool name */
    auto_ptr<Scope> ScriptEngine::getPooledScope(const string& pool, const string& scopeType) {
        if (!scopeCache.get())
            scopeCache.reset(new ScopeCache());

        Scope* s = scopeCache->get(pool + scopeType);
        if (!s)
            s = newScope();

        auto_ptr<Scope> p;
        p.reset(new PooledScope(pool + scopeType, s));
        p->setLocalDB(pool);
        p->loadStored(true);
        return p;
    }
Пример #4
0
		void checkTSSInit()
		{
			if(m_transactionInProgress.get() == 0)
			{
				m_transactionInProgress.reset(new bool);
				(*m_transactionInProgress) = false;
			}

			if(m_transaction.get() == 0)
			{
				m_transaction.reset(new DbTxn *);
				(*m_transaction) = NULL;
			}
		}
Пример #5
0
 virtual bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     string fromhost = cmdObj.getStringField("fromhost");
     if ( fromhost.empty() ) {
         /* copy from self */
         stringstream ss;
         ss << "localhost:" << cmdLine.port;
         fromhost = ss.str();
     }
     string fromdb = cmdObj.getStringField("fromdb");
     string todb = cmdObj.getStringField("todb");
     if ( fromhost.empty() || todb.empty() || fromdb.empty() ) {
         errmsg = "parms missing - {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>}";
         return false;
     }
     Cloner c;
     string username = cmdObj.getStringField( "username" );
     string nonce = cmdObj.getStringField( "nonce" );
     string key = cmdObj.getStringField( "key" );
     if ( !username.empty() && !nonce.empty() && !key.empty() ) {
         uassert( 13008, "must call copydbgetnonce first", authConn_.get() );
         BSONObj ret;
         {
             dbtemprelease t;
             if ( !authConn_->runCommand( fromdb, BSON( "authenticate" << 1 << "user" << username << "nonce" << nonce << "key" << key ), ret ) ) {
                 errmsg = "unable to login " + string( ret );
                 return false;
             }
         }
         c.setConnection( authConn_.release() );
     }
     Client::Context ctx(todb);
     bool res = c.go(fromhost.c_str(), errmsg, fromdb, /*logForReplication=*/!fromRepl, /*slaveok*/false, /*replauth*/false, /*snapshot*/true);
     return res;
 }
Пример #6
0
        virtual bool run(OperationContext* txn,
                         const string&,
                         BSONObj& cmdObj,
                         int,
                         string& errmsg,
                         BSONObjBuilder& result) {

            string fromhost = cmdObj.getStringField("fromhost");
            if ( fromhost.empty() ) {
                /* copy from self */
                stringstream ss;
                ss << "localhost:" << serverGlobalParams.port;
                fromhost = ss.str();
            }

            const ConnectionString cs(uassertStatusOK(ConnectionString::parse(fromhost)));

            authConn_.reset(cs.connect(errmsg));
            if (!authConn_.get()) {
                return false;
            }

            BSONObj ret;

            if( !authConn_->runCommand( "admin", BSON( "getnonce" << 1 ), ret ) ) {
                errmsg = "couldn't get nonce " + ret.toString();
                return false;
            }

            result.appendElements( ret );
            return true;
        }
Пример #7
0
 static ClientConnections* threadInstance() {
     ClientConnections* cc = _perThread.get();
     if ( ! cc ) {
         cc = new ClientConnections();
         _perThread.reset( cc );
     }
     return cc;
 }
Пример #8
0
		disable_syscall_interruption() {
			if (_syscalls_interruptable.get() == NULL) {
				last_value = true;
				_syscalls_interruptable.reset(new bool(false));
			} else {
				last_value = *_syscalls_interruptable;
				*_syscalls_interruptable = false;
			}
		}
 ostream & operator()() {
     ThreadOutputStream * tos( threadOutputStream_.get() );
     if( tos == nullptr ) {
         tos = new ThreadOutputStream();
         threadOutputStream_.reset( tos );
     }
     return (*tos) << boost::posix_time::microsec_clock::universal_time() <<
             ' ' << format("%014s") % boost::this_thread::get_id() <<
             " [ " << format("%-20.20s") % name_ << " ] ";
 };
Пример #10
0
        virtual bool run(OperationContext* txn,
                         const string&,
                         BSONObj& cmdObj,
                         int,
                         string& errmsg,
                         BSONObjBuilder& result) {

            const string fromDb = cmdObj.getStringField("fromdb");

            string fromHost = cmdObj.getStringField("fromhost");
            if ( fromHost.empty() ) {
                /* copy from self */
                stringstream ss;
                ss << "localhost:" << serverGlobalParams.port;
                fromHost = ss.str();
            }

            const ConnectionString cs(uassertStatusOK(ConnectionString::parse(fromHost)));

            BSONElement mechanismElement;
            Status status = bsonExtractField(cmdObj,
                                             saslCommandMechanismFieldName,
                                             &mechanismElement);
            if (!status.isOK()) {
                return appendCommandStatus(result, status);
            }

            BSONElement payloadElement;
            status = bsonExtractField(cmdObj, saslCommandPayloadFieldName, &payloadElement);
            if (!status.isOK()) {
                log() << "Failed to extract payload: " << status;
                return false;
            }

            authConn_.reset(cs.connect(errmsg));
            if (!authConn_.get()) {
                return false;
            }

            BSONObj ret;
            if( !authConn_->runCommand( fromDb,
                                        BSON( "saslStart" << 1 <<
                                              mechanismElement <<
                                              payloadElement),
                                        ret ) ) {
                return appendCommandStatus(result,
                                           Command::getStatusFromCommandResult(ret));

            }

            result.appendElements( ret );
            return true;
        }
Пример #11
0
 virtual ~PooledScope(){
     ScopeCache * sc = scopeCache.get();
     if ( sc ){
         sc->done( _pool , _real );
         _real = 0;
     }
     else {
         log() << "warning: scopeCache is empty!" << endl;
         delete _real;
         _real = 0;
     }
 }
Пример #12
0
 virtual ~PooledScope() {
     ScopeCache* sc = scopeCache.get();
     if (sc) {
         sc->done(_pool, _real);
         _real = NULL;
     }
     else {
         // this means that the Scope was killed from a different thread
         // for example a cursor got timed out that has a $where clause
         LOG(3) << "warning: scopeCache is empty!" << endl;
         delete _real;
         _real = 0;
     }
 }
Пример #13
0
		restore_syscall_interruption(const disable_syscall_interruption &intr) {
			assert(_syscalls_interruptable.get() != NULL);
			last_value = *_syscalls_interruptable;
			*_syscalls_interruptable = intr.last_value;
		}
Пример #14
0
const std::shared_ptr<CoreContext>& CoreContext::CurrentContextOrNull(void) {
  static const std::shared_ptr<CoreContext> empty;
  auto retVal = autoCurrentContext.get();
  return retVal ? *retVal : empty;
}
Пример #15
0
 void ScriptEngine::threadDone(){
     ScopeCache * sc = scopeCache.get();
     if ( sc ){
         sc->clear();
     }
 }
Пример #16
0
CoreContext::~CoreContext(void) {
  // Evict from the parent's child list first, if we have a parent:
  if(m_pParent)
  {
    expiredContext();

    // Also clear out any parent pointers:
    std::lock_guard<std::mutex> lk(m_pParent->m_stateBlock->m_lock);
    m_pParent->m_children.erase(m_backReference);
  }

  // The autoCurrentContext pointer holds a shared_ptr to this--if we're in a dtor, and our caller
  // still holds a reference to us, then we have a serious problem.
  assert(
    !autoCurrentContext.get() ||
    !autoCurrentContext.get()->use_count() ||
    autoCurrentContext.get()->get() != this
  );

  // Notify all ContextMember instances that their parent is going away
  onTeardown(*this);

  // Tell all context members that we're tearing down:
  for(ContextMember* q : m_contextMembers)
    q->NotifyContextTeardown();

  // Perform unlinking, if requested:
  if(m_unlinkOnTeardown)
    for (const auto& ccType : m_concreteTypes) {
      uint8_t* pBase = (uint8_t*)ccType.value.ptr();

      // Enumerate all slots and unlink them one at a time
      for (auto cur = ccType.stump->pHead; cur; cur = cur->pFlink) {
        if (cur->autoRequired)
          // Only unlink slots that were Autowired.  AutoRequired slots will never participate
          // in a cycle (because we would wind up with constructive chaos) so we don't really
          // need to worry about them.  Furthermore, there are cases where users may want to
          // refer to a context member in their destructor; in that case, they should use
          // AutoRequired to enforce the relationship.
          continue;

        auto& slot = *reinterpret_cast<DeferrableAutowiring*>(pBase + cur->slotOffset);
        if (!slot.IsAutowired())
          // Nothing to do here, just short-circuit
          continue;

        auto q = m_typeMemos.find(slot.GetType());
        if (q == m_typeMemos.end())
          // Weird.  A slot is present on a member of this context, but the wired type doesn't
          // have a memo entry anywhere.
          continue;

        if (!q->second.m_local)
          // Entry exists, but was not locally satisfied.  We can circle around.
          continue;

        // OK, interior pointer and context teardown is underway, clear it out
        slot.reset();
      }
    }
}
Пример #17
0
std::shared_ptr<CoreContext> CoreContext::CurrentContext(void) {
  if (auto* retVal = autoCurrentContext.get())
    if(*retVal)
      return *retVal;
  return GetGlobalContext();
}