int StaticFileCacheData::readyGziped() { time_t tm = time( NULL ); if ( tm == getLastMod() ) return -1; if ( tm != m_tmLastCheckGzip ) { struct stat st; m_tmLastCheckGzip = tm; if ( !m_gzippedPath.c_str() || !*m_gzippedPath.c_str() ) { if ( buildGzipPath() == -1 ) return -1; } int ret = nio_stat( m_gzippedPath.c_str(), &st ); if (( ret == -1 )||( st.st_mtime != getLastMod() )) { if (( !m_pGziped )||( m_pGziped->getRef() == 0 )) { if ( ret != -1 ) unlink( m_gzippedPath.c_str() ); ret = tryCreateGziped(); if ( ret == -1 ) { if ( m_pGziped ) { delete m_pGziped; m_pGziped = NULL; } return -1; } else { ret = nio_stat( m_gzippedPath.c_str(), &st ); if ( ret ) return -1; } } else return -1; } if (( !m_pGziped )||( m_pGziped->isDirty( st ) )) buildGzipCache( st ); } if ( m_pGziped ) { if (( m_pGziped->isCached() || ( m_pGziped->getfd() != -1 ))) return 0; return m_pGziped->readyData( m_gzippedPath.c_str() ); } return -1; }
void forceDatabaseRefresh(OperationContext* opCtx, const StringData dbName) { invariant(!opCtx->lockState()->isLocked()); invariant(!opCtx->getClient()->isInDirectClient()); auto const shardingState = ShardingState::get(opCtx); invariant(shardingState->canAcceptShardedCommands()); const auto refreshedDbVersion = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getDatabaseWithRefresh(opCtx, dbName)) .databaseVersion(); // First, check under a shared lock if another thread already updated the cached version. // This is a best-effort optimization to make as few threads as possible to convoy on the // exclusive lock below. auto databaseHolder = DatabaseHolder::get(opCtx); { // Take the DBLock directly rather than using AutoGetDb, to prevent a recursive call // into checkDbVersion(). Lock::DBLock dbLock(opCtx, dbName, MODE_IS); auto db = databaseHolder->getDb(opCtx, dbName); if (!db) { log() << "Database " << dbName << " has been dropped; not caching the refreshed databaseVersion"; return; } auto& dss = DatabaseShardingState::get(db); auto dssLock = DatabaseShardingState::DSSLock::lock(opCtx, &dss); const auto cachedDbVersion = dss.getDbVersion(opCtx, dssLock); if (cachedDbVersion && cachedDbVersion->getUuid() == refreshedDbVersion.getUuid() && cachedDbVersion->getLastMod() >= refreshedDbVersion.getLastMod()) { LOG(2) << "Skipping setting cached databaseVersion for " << dbName << " to refreshed version " << refreshedDbVersion.toBSON() << " because current cached databaseVersion is already " << cachedDbVersion->toBSON(); return; } } // The cached version is older than the refreshed version; update the cached version. Lock::DBLock dbLock(opCtx, dbName, MODE_X); auto db = databaseHolder->getDb(opCtx, dbName); if (!db) { log() << "Database " << dbName << " has been dropped; not caching the refreshed databaseVersion"; return; } auto& dss = DatabaseShardingState::get(db); auto dssLock = DatabaseShardingState::DSSLock::lockExclusive(opCtx, &dss); dss.setDbVersion(opCtx, std::move(refreshedDbVersion), dssLock); }
ArrayElement* ToDo::clone() { ToDo* ret = new ToDo(); if (getClass()) ret->setClass(*classEvent); if (getCompleted()) ret->setCompleted(*completed); if (getCreated()) ret->setCreated(*created); if (getDescription()) ret->setDescription(*description); if (getDtStamp()) ret->setDtStamp(*dtStamp); if (getDtStart()) ret->setDtStart(*dtStart); if (getGeo()) ret->setGeo(*geo); if (getLastMod()) ret->setLastMod(*lastMod); if (getLocation()) ret->setLocation(*location); if (getOrganizer()) ret->setOrganizer(*organizer); if (getPercent()) ret->setPercent(*percent); if (getPriority()) ret->setPriority(*priority); if (getRecurID()) ret->setRecurID(*recurID); if (getSequence()) ret->setSequence(*seq); if (getStatus()) ret->setStatus(*status); if (getSummary()) ret->setSummary(*summary); if (getUid()) ret->setUid(*uid); if (getUrl()) ret->setUrl(*url); if (getDue()) ret->setDue(*due); if (getDuration()) ret->setDuration(*duration); if (getAttach()) ret->setAttach(*attach); if (getAttendee()) ret->setAttendee(*attendee); if (getCategories()) ret->setCategories(*categories); if (getComment()) ret->setComment(*comment); if (getContact()) ret->setContact(*contact); if (getExDate()) ret->setExDate(*exDate); if (getExRule()) ret->setExRule(*exRule); if (getRStatus()) ret->setRStatus(*rStatus); if (getRelated()) ret->setRelated(*related); if (getResources()) ret->setResources(*resources); if (getRDate()) ret->setRDate(*rDate); if (getRRule()) ret->setRRule(*rRule); if (getXProp()) ret->setXProp(*xProp); return ret; }