typename Ephemeris<Frame>::Checkpoint Ephemeris<Frame>::GetCheckpoint() { std::vector<typename ContinuousTrajectory<Frame>::Checkpoint> checkpoints; for (auto const& trajectory : trajectories_) { checkpoints.push_back(trajectory->GetCheckpoint()); } return Checkpoint({last_state_, checkpoints}); }
HTMLInputCheckpoint BackgroundHTMLInputStream::createCheckpoint(size_t tokensExtractedSincePreviousCheckpoint) { HTMLInputCheckpoint checkpoint = m_checkpoints.size(); m_checkpoints.append(Checkpoint(m_current, m_segments.size(), tokensExtractedSincePreviousCheckpoint)); m_totalCheckpointTokenCount += tokensExtractedSincePreviousCheckpoint; return checkpoint; }
void TDataAscii::Cleanup() { Checkpoint(); if (_data->isTape()) _data->printStats(); }
virtual int run(int checkpoint) override { init_paths(); int local_checkpoint = 0; // Rename the foo to bar if (rename(foo_path.c_str(), bar_path.c_str()) != 0) { return -2; } const int fd_bar = open(bar_path.c_str(), O_RDWR | O_CREAT, TEST_FILE_PERMS); if (fd_bar < 0) { return -3; } if (fsync(fd_bar) < 0) { return -4; } if (Checkpoint() < 0){ return -5; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } //Close open files close(fd_bar); return 0; }
virtual int run(int checkpoint) override { int local_checkpoint = 0; //initialize paths foo_path = mnt_dir_ + "/"+ TEST_DIR_A + "/" + TEST_FILE_FOO; bar_path = mnt_dir_ + "/" TEST_DIR_A + "/" + TEST_FILE_BAR; dummy_path = mnt_dir_ + "/" TEST_DIR_A + "/" + TEST_FILE_DUMMY; dira_path = mnt_dir_ + "/" + TEST_DIR_A; //Create the log tree by creating a random file in dir a, and fsyncing it const int fd_dummy = open(dummy_path.c_str(), O_RDWR | O_CREAT, TEST_FILE_PERMS); if (fd_dummy < 0) { return -1; } int res = fsync(fd_dummy); if (res < 0){ close(fd_dummy); return -2; } //Now rename the special file from foo to bar if(rename(foo_path.c_str() , bar_path.c_str()) < 0){ close(fd_dummy); return -3; } //Create a link to bar. Call this foo again if (link(bar_path.c_str(), foo_path.c_str()) < 0){ close(fd_dummy); return -4; } //persist the log tree. We'll delete the dummy file and fsync it to trigger this if( remove(dummy_path.c_str()) < 0) { close(fd_dummy); return -5; } //fsync file bar res = fsync(fd_dummy); if (res < 0){ close(fd_dummy); return -6; } //Make a user checkpoint here. Checkpoint must be 1 beyond this point if (Checkpoint() < 0){ return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } close(fd_dummy); return 0; }
/* * Initialize the process by reading environment variables and files */ static void Initialize(void) { char *temp; ListOfString *fileList; int stateDirLen; /* * Process miscellaneous parameters from the initial environment. */ checkpointThreshold = IntGetEnv(CKP_THRESHOLD_VAR, CKP_THRESHOLD_DEFAULT); cartHoldSeconds = IntGetEnv(CART_HOLD_MINUTES_VAR, CART_HOLD_MINUTES_DEFAULT)*60; /* * Create an empty in-memory shopping cart data structure. */ cartTablePtr = &cartTable; Tcl_InitHashTable(cartTablePtr, TCL_STRING_KEYS); /* * Compute the state directory name from the initial environment * variables. */ stateDir = getenv(STATE_DIR_VAR); stateDirLen = Strlen(stateDir); assert(stateDirLen > 0); if(stateDir[stateDirLen - 1] == '/') { stateDir[stateDirLen - 1] = '\000'; } fcgiProcessId = getenv(PID_VAR); if(fcgiProcessId != NULL) { stateDir = StringCat4(stateDir, ".", fcgiProcessId, "/"); } else { stateDir = StringCat(stateDir, "/"); } /* * Read the state directory to determine the current * generation number and a list of files that may * need to be deleted (perhaps left over from an earlier * system crash). Recover the current generation * snapshot and log (either or both may be missing), * populating the in-memory shopping cart data structure. * Take a checkpoint, making the current log empty. */ AnalyzeStateDir(stateDir, SNP_PREFIX, &generation, &fileList); snapshotPath = MakePath(stateDir, SNP_PREFIX, generation); RecoverFile(snapshotPath); logPath = MakePath(stateDir, LOG_PREFIX, generation); numLogRecords = RecoverFile(logPath); Checkpoint(); /* * Clean up stateDir without removing the current snapshot and log. */ while(fileList != NULL) { char *cur = ListOfString_Head(fileList); if(strcmp(snapshotPath, cur) && strcmp(logPath, cur)) { remove(cur); } fileList = ListOfString_RemoveElement(fileList, cur); } }
void Memory::Check() { #ifdef _DEBUG if (! _CrtCheckMemory()) { _RPT0(_CRT_ERROR, "\n\nMemory Check Failed.\n"); heapdump(); Checkpoint(); _asm { int 3 } exit(1111); }
Checkpoint GetClosestCheckpoint(const int& nHeight, int& nHeightCheckpoint) { nHeightCheckpoint = -1; for (auto it : mapCheckpoints) { //only checkpoints that are less than the height requested (unless height is less than the first checkpoint) if (it.first < nHeight) { if (nHeightCheckpoint == -1) nHeightCheckpoint = it.first; if (nHeight - it.first < nHeightCheckpoint) nHeightCheckpoint = it.first; } } if (nHeightCheckpoint != -1) return mapCheckpoints.at(nHeightCheckpoint); return Checkpoint(); }
virtual int run(int checkpoint) override { int local_checkpoint = 0; //Rename foo to bar in TEST_DIR if (rename(foo_path.c_str(), bar_path.c_str()) < 0) { return -1; } //Open file_bar const int fd_bar = open(bar_path.c_str(), O_RDWR); if (fd_bar < 0) { return -2; } //Now create file_foo again in TEST_DIR const int fd_foo = open(foo_path.c_str(), O_RDWR | O_CREAT, TEST_FILE_PERMS); if (fd_foo < 0) { return -3; } //fsync only file_bar int res = fsync(fd_bar); if (res < 0){ return -4; } //Make a user checkpoint here. Checkpoint must be 1 beyond this point if (Checkpoint() < 0){ return -5; } //Close open files close(fd_bar); close(fd_foo); local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } return 0; }
void EldritchGame::RequestGoToLevel( const SimpleString& NextLevel, const HashedString& NextWorldDef, const bool RestoreSpawnPoint ) { XTRACE_FUNCTION; if( NextLevel == "" || NextWorldDef == HashedString::NullString ) { WARN; return; } // Make a checkpoint save, for crash protection Checkpoint(); ASSERT( !m_GoToLevelOnNextTick ); m_GoToLevelOnNextTick = true; m_RestoreSpawnPoint = RestoreSpawnPoint; m_NextLevelName = NextLevel; m_NextWorldDef = NextWorldDef; WBEventManager* const pEventManager = WBWorld::GetInstance()->GetEventManager(); WB_MAKE_EVENT( PreLevelTransition, NULL ); WB_DISPATCH_EVENT( pEventManager, PreLevelTransition, NULL ); }
virtual int run(int checkpoint) override { int local_checkpoint = 0; const int fd_foo = open(foo_path.c_str(), O_RDWR | O_CREAT, TEST_FILE_PERMS); if (fd_foo < 0) { return -1; } //remove user.xattr2 int res = removexattr(foo_path.c_str(), "user.xattr2"); if (res < 0) { return -1; } //system("setfattr -x user.xattr2 /mnt/snapshot/foo"); //fsync file_foo res = fsync(fd_foo); if (res < 0){ return -6; } //Make a user checkpoint here. Checkpoint must be 1 beyond this point. if (Checkpoint() < 0){ return -5; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } //Close open files close(fd_foo); return 0; }
static void ConditionalCheckpoint(void) { if(numLogRecords >= checkpointThreshold) { Checkpoint(); } }
bool CDatabase::Init(const DatabaseConfig& config_) { u_int32_t flags = DB_CREATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_PRIVATE; int mode = 0; int ret; env = new DbEnv(DB_CXX_NO_EXCEPTIONS); #if DB_VERSION_MAJOR > 4 #if DB_VERSION_MINOR > 6 env->set_errcall(CDatabaseError); env->set_msgcall(CDatabaseTrace); #endif #endif config = config_; if (config.cacheSize != 0) { u_int32_t gbytes = config.cacheSize / (1024 * 1024 * 1024); u_int32_t bytes = config.cacheSize % (1024 * 1024 * 1024); //env.set_cache_max(gbytes, bytes); env->set_cachesize(gbytes, bytes, 4); } if (config.logBufferSize != 0) env->set_lg_bsize(config.logBufferSize); if (config.logMaxFile != 0) env->set_lg_max(config.logMaxFile); if (config.verbose) { #ifdef DB_VERB_FILEOPS env->set_verbose(DB_VERB_FILEOPS, 1); #endif #ifdef DB_VERB_FILEOPS_ALL env->set_verbose(DB_VERB_FILEOPS_ALL, 1); #endif #ifdef DB_VERB_RECOVERY env->set_verbose(DB_VERB_RECOVERY, 1); #endif #ifdef DB_VERB_REGISTER env->set_verbose(DB_VERB_REGISTER, 1); #endif #ifdef DB_VERB_REPLICATION env->set_verbose(DB_VERB_REPLICATION, 1); #endif #ifdef DB_VERB_WAITSFOR env->set_verbose(DB_VERB_WAITSFOR, 1); #endif } #ifdef DB_LOG_AUTOREMOVE env->set_flags(DB_LOG_AUTOREMOVE, 1); #else env->log_set_config(DB_LOG_AUTO_REMOVE, 1); #endif //#ifdef DB_DIRECT_DB // ret = env->set_flags(DB_DIRECT_DB, config.directDB); //#endif #ifdef DB_TXN_NOSYNC ret = env->set_flags(DB_TXN_NOSYNC, config.txnNoSync); #endif #ifdef DB_TXN_WRITE_NOSYNC ret = env->set_flags(DB_TXN_WRITE_NOSYNC, config.txnWriteNoSync); #endif ret = env->open(config.dir, flags, mode); if (ret != 0) return false; keyspace = new CTable(this, "keyspace", config.pageSize); Checkpoint(); running = true; if (config.checkpointTimeout) { ; // checkpointTimeout.SetDelay(config.checkpointTimeout * 1000); // EventLoop::Add(&checkpointTimeout); } // cpThread = ThreadPool::Create(1); // cpThread->Start(); return true; }
HTMLInputCheckpoint BackgroundHTMLInputStream::createCheckpoint() { HTMLInputCheckpoint checkpoint = m_checkpoints.size(); m_checkpoints.append(Checkpoint(m_current, m_segments.size())); return checkpoint; }
Generate() { static int rsflag = 1; /* flag cleared after restart */ STRUCTURE *temp; /* for swapping population pointers */ register int i; /* for marking structures */ if (Traceflag) printf(" Gen %d\n",Gen); Trace("Generate entered"); /* create a new population */ if (Restartflag && rsflag) { /* this is a restart so read checkpoint file */ Restart(); rsflag = 0; /* disable local restart flag. */ Converge(); } else if (Gen == 0) /* this is a fresh experiment */ { Initialize(); /* form an initial population */ Spin++; } else /* form a new population from */ /* the old one via genetic operators */ { Select(); Mutate(); Crossover(); if (Eliteflag) Elitist(); if (Allflag) /* mark structures for evaluation */ for (i=0; i<Popsize; i++) New[i].Needs_evaluation = 1; Spin++; } /* evaluate the newly formed population */ Evaluate(); /* gather performance statistics */ Measure(); /* check termination condition for this experiment */ Doneflag = Done(); /* checkpoint if appropriate */ if (Num_dumps && Dump_freq && Gen % Dump_freq == 0) { if (Num_dumps > 1) { sprintf(Dumpfile, "dump.%d", Curr_dump); Curr_dump = (Curr_dump + 1) % Num_dumps; Checkpoint(Dumpfile); } Checkpoint(Ckptfile); } else { if (Doneflag) { if (Lastflag) Checkpoint(Ckptfile); else if (Savesize) Printbest(); } } /* swap pointers for next generation */ temp = Old; Old = New; New = temp; /* update generation counter */ Gen++; Trace("Generate completed"); }
// ###################################################################### void WorkThreadServer::run(ThreadData* dat) { GVX_ERR_CONTEXT(rutz::sfmt("running %s worker thread %u/%u", itsName.c_str(), dat->index + 1, itsNumThreads)); rutz::time prev = rutz::time::wall_clock_now(); while (1) { itsJobsCounter.wait(); { rutz::time t = rutz::time::wall_clock_now(); dat->waittime += (t - prev); prev = t; } if (itsJobsQuit == true) break; rutz::shared_ptr<JobServer::Job> job; size_t qsize = 0; { GVX_MUTEX_LOCK(&itsJobsMutex); if (itsJobs.size() == 0) { // If this happens, it probably represents an OS bug // (somehow the semaphore counts have gotten corrupted), // but we will issue an LERROR() instead of an LFATAL() // and try to keep limping along with the goal of not // unnecessarily bombing out of a long analysis job. LERROR("Oops! Received a semaphore but the job queue is empty!"); continue; } ASSERT(itsJobs.size() > 0); if (itsJobs.size() > itsMaxObservedQueueSize) itsMaxObservedQueueSize = itsJobs.size(); job = itsJobs.front(); itsJobs.pop_front(); qsize = itsJobs.size(); ++(dat->njobs); } job->run(); const int c = itsNumRun.atomic_incr_return(); // show our queue once in a while: if (itsCheckpointPeriod > 0 && c > itsLastCheckpoint && c % itsCheckpointPeriod == 0) { itsCheckpoints.push_back(Checkpoint(c, qsize, itsMaxObservedQueueSize)); itsLastCheckpoint = c; } { rutz::time t = rutz::time::wall_clock_now(); dat->worktime += (t - prev); prev = t; } if (itsSleepUsecs > 0) usleep(itsSleepUsecs); } }
/*virtual*/ void EldritchGame::HandleEvent( const WBEvent& Event ) { XTRACE_FUNCTION; STATIC_HASHED_STRING( ReturnToHub ); STATIC_HASHED_STRING( GoToNextLevel ); STATIC_HASHED_STRING( GoToPrevLevel ); STATIC_HASHED_STRING( GoToLevel ); STATIC_HASHED_STRING( Checkpoint ); STATIC_HASHED_STRING( TweetRIP ); STATIC_HASHED_STRING( PlayMusic ); STATIC_HASHED_STRING( StopMusic ); STATIC_HASHED_STRING( LaunchWebSite ); STATIC_HASHED_STRING( GoToLevelImmediate ); const HashedString EventName = Event.GetEventName(); if( EventName == sReturnToHub ) { STATIC_HASHED_STRING( Restart ); const bool Restart = Event.GetBool( sRestart ); STATIC_HASHED_STRING( FlushHub ); const bool FlushHub = Event.GetBool( sFlushHub ); RequestReturnToHub( Restart, FlushHub ); } else if( EventName == sGoToNextLevel ) { RequestGoToNextLevel(); } else if( EventName == sGoToPrevLevel ) { RequestGoToPrevLevel(); } else if( EventName == sGoToLevel ) { STATIC_HASHED_STRING( Level ); const SimpleString Level = Event.GetString( sLevel ); STATIC_HASHED_STRING( WorldDef ); const HashedString WorldDef = Event.GetHash( sWorldDef ); RequestGoToLevel( Level, WorldDef, true ); } else if( EventName == sCheckpoint ) { Checkpoint(); } else if( EventName == sTweetRIP ) { LaunchRIPTweet(); } else if( EventName == sLaunchWebSite ) { LaunchWebSite(); } else if( EventName == sPlayMusic ) { STATIC_HASHED_STRING( Music ); const SimpleString Music = Event.GetString( sMusic ); m_Music->PlayMusic( ( Music == "" ) ? m_CurrentMusic : Music ); } else if( EventName == sStopMusic ) { m_Music->StopMusic(); } else if( EventName == sGoToLevelImmediate ) { // This should only be called after we've queued a go-to. ASSERT( m_GoToLevelOnNextTick ); if( m_GoToLevelOnNextTick ) { GoToLevel(); } // HACK: Tick world once to pump the event queue. Fixes title screen bugs. (Hack because this assumes we only ever use this when returning to title screen.) EldritchFramework* const pFramework = EldritchFramework::GetInstance(); EldritchWorld* const pWorld = pFramework->GetWorld(); pWorld->Tick( 0.0f ); } }
virtual int run(int checkpoint) override { int local_checkpoint = 0; //Open file foo const int fd_foo = open(foo_path.c_str(), O_RDWR); if (fd_foo < 0) { return -1; } // system("stat /mnt/snapshot/foo"); /*-------------------Variant 1 ---------------------------*/ //unaligned offset and size less than a page //Fallocate from off 17000 of length 3000 if(fallocate(fd_foo, FALLOC_FL_KEEP_SIZE ,17000, 3000) < 0){ close(fd_foo); return -2; } //fsync file_foo int res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 1 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 0; } //Expected output if checkpoint = 1 : Size = 16K, blocks == 40 (32 + 8) // system("stat /mnt/snapshot/foo"); /*-------------------Variant 2 ---------------------------*/ //aligned offset and size less than a page //Fallocate from off 24K of length 3000 if(fallocate(fd_foo, FALLOC_FL_KEEP_SIZE ,24576, 3000) < 0){ close(fd_foo); return -2; } //fsync file_foo res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 2 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 0; } //Expected output if checkpoint = 2: size = 16K, blocks == 48 (40 + 8) // system("stat /mnt/snapshot/foo"); /*-------------------Variant 3 ---------------------------*/ //Aligned offset and size > a page //Fallocate from off 32K of length 8192 if(fallocate(fd_foo, FALLOC_FL_KEEP_SIZE , 32768, 8192) < 0){ close(fd_foo); return -2; } //fsync file_foo res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 3 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 0; } //Expected output if checkpoint = 3: size = 16K, blocks == 64 (48 + 16) // system("stat /mnt/snapshot/foo"); /*-------------------Variant 4 ---------------------------*/ //unaligned offset and size less than a page //Fzero from off 42000 of length 3000 if(fallocate(fd_foo, FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE ,42000, 3000) < 0){ close(fd_foo); return -2; } //fsync file_foo res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 4 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 0; } //Expected output if checkpoint = 4 : Size = 16K, blocks == 72 (64 + 8) // system("stat /mnt/snapshot/foo"); /*-------------------Variant 5 ---------------------------*/ //aligned offset and size less than a page //Fzero from off 48K of length 3000 if(fallocate(fd_foo, FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE ,49152, 3000) < 0){ close(fd_foo); return -2; } //fsync file_foo res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 5 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 0; } //Expected output if checkpoint = 5: size = 16K, blocks == 80 (72 + 8) // system("stat /mnt/snapshot/foo"); /*-------------------Variant 6 ---------------------------*/ //Aligned offset and size > a page //Fzero from off 52K of length 8192 if(fallocate(fd_foo, FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE , 53248, 8192) < 0){ close(fd_foo); return -2; } //fsync file_foo res = fsync(fd_foo); if (res < 0){ close(fd_foo); return -3; } // Make a user checkpoint here. Checkpoint must be 6 beyond this point // Beyond this point, the effect of falloc must be visible if (Checkpoint() < 0){ close(fd_foo); return -4; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } //Expected output if checkpoint = 6: size = 16K, blocks == 96 (80 + 16) // system("stat /mnt/snapshot/foo"); //Close open files close(fd_foo); return 0; }