Ejemplo n.º 1
0
Archivo: db.cpp Proyecto: gilles/mongo
BOOL CtrlHandler( DWORD fdwCtrlType )
{
    switch( fdwCtrlType )
    {
    case CTRL_C_EVENT:
        rawOut("Ctrl-C signal");
        ctrlCTerminate();
        return( TRUE );
    case CTRL_CLOSE_EVENT:
        rawOut("CTRL_CLOSE_EVENT signal");
        ctrlCTerminate();
        return( TRUE );
    case CTRL_BREAK_EVENT:
        rawOut("CTRL_BREAK_EVENT signal");
        ctrlCTerminate();
        return TRUE;
    case CTRL_LOGOFF_EVENT:
        rawOut("CTRL_LOGOFF_EVENT signal (ignored)");
        return FALSE;
    case CTRL_SHUTDOWN_EVENT:
         rawOut("CTRL_SHUTDOWN_EVENT signal (ignored)");
         return FALSE;
    default:
        return FALSE;
    }
}
Ejemplo n.º 2
0
Archivo: db.cpp Proyecto: zhuk/mongo
    void abruptQuit(int x) {
        ostringstream ossSig;
        ossSig << "Got signal: " << x << " (" << strsignal( x ) << ")." << endl;
        rawOut( ossSig.str() );

        ostringstream ossOp;
        ossOp << "Last op: " << currentOp.infoNoauth() << endl;
        rawOut( ossOp.str() );

        ostringstream oss;
        oss << "Backtrace:" << endl;
        printStackTrace( oss );
        rawOut( oss.str() );
        dbexit( EXIT_ABRUBT );
    }
Ejemplo n.º 3
0
 // called when a GTID has finished being applied, which means
 // we can remove it from the unappliedGTIDs set
 void GTIDManager::noteGTIDApplied(const GTID& gtid) {
     try {
         boost::unique_lock<boost::mutex> lock(_lock);
         dassert(GTID::cmp(gtid, _minUnappliedGTID) >= 0);
         dassert(_unappliedGTIDs.size() > 0);
         // remove from list of GTIDs
         _unappliedGTIDs.erase(gtid);
         // if what we are removing is currently the minumum live GTID
         // we need to update the minimum live GTID
         if (GTID::cmp(_minUnappliedGTID, gtid) == 0) {
             if (_unappliedGTIDs.size() == 0) {
                 _minUnappliedGTID = _lastUnappliedGTID;
                 _minUnappliedGTID.inc();
             }
             else {
                 // get the minumum from _liveGTIDs and set it to _minLiveGTIDs
                 _minUnappliedGTID = *(_unappliedGTIDs.begin());
             }
         }
     }
     catch (std::exception &e) {
         StackStringBuilder ssb;
         ssb << "exception during noteGTIDApplied, aborting system: " << e.what();
         rawOut(ssb.str());
         ::abort();
     }
 }
Ejemplo n.º 4
0
    void shutdown() {

#ifndef _WIN32
        {
            // close listener sockets
            // We would only hang here if a synchronous signal is received 
            // during a registerListenerSocket() call, which we don't expect.
            boostlock lk( listenerSocketMutex );
            for( vector< int >::iterator i = listenerSockets.begin(); i != listenerSockets.end(); ++i )
                close( *i );
        }
#endif

        log() << "\t shutdown: going to flush oplog..." << endl;
        stringstream ss2;
        flushOpLog( ss2 );
        rawOut( ss2.str() );

        /* must do this before unmapping mem or you may get a seg fault */
        log() << "\t shutdown: going to close sockets..." << endl;
        closeAllSockets();

        // wait until file preallocation finishes
        // we would only hang here if the file_allocator code generates a
        // synchronous signal, which we don't expect
        log() << "\t shutdown: waiting for fs..." << endl;
        theFileAllocator().waitUntilFinished();
        
        log() << "\t shutdown: closing all files..." << endl;
        stringstream ss3;
        MemoryMappedFile::closeAllFiles( ss3 );
        rawOut( ss3.str() );

        // should we be locked here?  we aren't. might be ok as-is.
        recCacheCloseAll();
        
#if !defined(_WIN32) && !defined(__sunos__)
        if ( lockFile ){
            log() << "\t shutdown: removing fs lock..." << endl;
            if( ftruncate( lockFile , 0 ) ) 
                log() << "\t couldn't remove fs lock errno=" << errno << endl;
            flock( lockFile, LOCK_UN );
        }
#endif
    }
Ejemplo n.º 5
0
    /* not using log() herein in case we are already locked */
    void dbexit( ExitCode rc, const char *why) {        
        {
            boostlock lk( exitMutex );
            if ( !firstExit ) {
                stringstream ss;
                ss << "dbexit: " << why << "; exiting immediately" << endl;
                rawOut( ss.str() );
                ::exit( rc );                
            }
            firstExit = false;
        }
            
        stringstream ss;
        ss << "dbexit: " << why << endl;
        rawOut( ss.str() );

		shutdown(); // gracefully shutdown instance

        rawOut( "dbexit: really exiting now\n" );
        ::exit(rc);
    }
Ejemplo n.º 6
0
    void tryToOutputFatal( const string& s ) {
        try {
            rawOut( s );
            return;
        }
        catch ( ... ) {}

        try {
            cerr << s << endl;
            return;
        }
        catch ( ... ) {}

        // uh - oh, not sure there is anything else we can do...
    }
Ejemplo n.º 7
0
    // called when a secondary takes an unapplied GTID it has read in the oplog
    // and starts to apply it
    void GTIDManager::noteApplyingGTID(const GTID& gtid) {
        try {
            boost::unique_lock<boost::mutex> lock(_lock);
            dassert(GTID::cmp(gtid, _minUnappliedGTID) >= 0);
            dassert(GTID::cmp(gtid, _lastUnappliedGTID) > 0);
            if (_unappliedGTIDs.size() == 0) {
                _minUnappliedGTID = gtid;
            }

            _unappliedGTIDs.insert(gtid);
            _lastUnappliedGTID = gtid;
        }
        catch (std::exception &e) {
            StackStringBuilder ssb;
            ssb << "exception during noteApplyingGTID, aborting system: " << e.what();
            rawOut(ssb.str());
            ::abort();
        }
    }
Ejemplo n.º 8
0
 // this gets called when new fails to allocate memory
 void my_new_handler() {
     rawOut( "out of memory, printing stack and exiting:" );
     printStackTrace();
     ::_exit(EXIT_ABRUPT);
 }
Ejemplo n.º 9
0
 void mongoAbort(const char *msg) { 
     if( reportEventToSystem ) 
         reportEventToSystem(msg);
     rawOut(msg);
     ::abort();
 }
Ejemplo n.º 10
0
Archivo: db.cpp Proyecto: gilles/mongo
 void myPurecallHandler() {
     rawOut( "pure virtual method called, printing stack:" );
     printStackTrace();
     abort();        
 }
Ejemplo n.º 11
0
Archivo: db.cpp Proyecto: gilles/mongo
 // this will be called in certain c++ error cases, for example if there are two active
 // exceptions
 void myterminate() {
     rawOut( "terminate() called, printing stack:" );
     printStackTrace();
     abort();
 }
Ejemplo n.º 12
0
static void
irt_rpf_nominal_deriv2(const double *spec,
		       const double *param,
		       double *out)
{
  int nfact = spec[RPF_ISpecDims];
  int nzeta = spec[RPF_ISpecOutcomes] - 1;
  const double *aa = param;

  for (int dx=0; dx < nfact; dx++) {
    if (aa[dx] < 0) {
      set_deriv_nan(spec, out);
      return;
    }
  }

  int ckoffset = nzeta;
  if (nfact == 0) ckoffset = 0;

  const double *Ta = spec + RPF_ISpecCount;
  const double *Tc = spec + RPF_ISpecCount + nzeta * nzeta;
  const int numParam = irt_rpf_nominal_numParam(spec);
  Eigen::VectorXd rawOut(numParam);
  memcpy(rawOut.data(), out, sizeof(double) * numParam);

  // gradient
  for (int tx=0; tx < nzeta; tx++) {
    double ak1=0;
    double ck1=0;
    for (int kx=0; kx < nzeta; kx++) {
      int Tcell = tx * nzeta + kx;
      ak1 += rawOut[nfact + kx] * Ta[Tcell];
      ck1 += rawOut[nfact + ckoffset + kx] * Tc[Tcell];
    }
    out[nfact + tx] = ak1;
    out[nfact + ckoffset + tx] = ck1;
  }

  // don't need to transform the main a parameters TODO
  double *dmat = Realloc(NULL, 3 * numParam * numParam, double);
  const int hsize = hessianIndex(0, numParam-1, numParam-1);
  {
	  // unpack triangular storage into a full matrix
    int row=0;
    int col=0;
    for (int dx=0; dx <= hsize; dx++) {
      dmat[numParam * col + row] = out[numParam + dx];
      if (row == col) {
	col=0; ++row;
      } else {
	dmat[numParam * row + col] = out[numParam + dx];
	++col;
      }
    }
  }

  double *tmat = dmat + numParam * numParam;
  for (int dx=0; dx < numParam * numParam; dx++) tmat[dx] = 0;
  for (int dx=0; dx < nfact; dx++) {
    tmat[dx * numParam + dx] = 1;
  }
  for (int rx=0; rx < nzeta; rx++) {
    for (int cx=0; cx < nzeta; cx++) {
      tmat[(cx + nfact)*numParam + nfact + rx] = Ta[rx * nzeta + cx];
      tmat[(cx + nfact + ckoffset)*numParam + nfact + ckoffset + rx] = Tc[rx * nzeta + cx];
    }
  }

  double *dest = dmat + 2 * numParam * numParam;

  // It is probably possible to do this more efficiently than dgemm
  // since we know that we only care about the lower triangle.
  // I'm not sure whether this is worth optimizing. TODO

  char normal = 'n';
  char transpose = 't';
  double one = 1;
  double zero = 0;
  F77_CALL(dgemm)(&normal, &normal, &numParam, &numParam, &numParam,
		  &one, tmat, &numParam, dmat, &numParam, &zero, dest, &numParam);
  F77_CALL(dgemm)(&normal, &transpose, &numParam, &numParam, &numParam,
		  &one, dest, &numParam, tmat, &numParam, &zero, dmat, &numParam);

  {
    int row=0;
    int col=0;
    for (int dx=0; dx <= hsize; dx++) {
      out[numParam + dx] = dmat[numParam * col + row];
      if (row == col) {
	col=0; ++row;
      } else {
	++col;
      }
    }
  }

  Free(dmat);
}