本文整理汇总了C++中CommitJob类的典型用法代码示例。如果您正苦于以下问题:C++ CommitJob类的具体用法?C++ CommitJob怎么用?C++ CommitJob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommitJob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findMMF_inlock
namespace dur {
extern Journal j;
extern CommitJob commitJob;
const RelativePath local = RelativePath::fromRelativePath("local");
static DurableMappedFile* findMMF_inlock(void* ptr, size_t& ofs) {
DurableMappedFile* f = privateViews.find_inlock(ptr, ofs);
if (f == 0) {
error() << "findMMF_inlock failed " << privateViews.numberOfViews_inlock() << endl;
// we want a stack trace and the assert below didn't print a trace once in the real world
// - not sure why
printStackTrace();
stringstream ss;
ss << "view pointer cannot be resolved " << std::hex << (size_t)ptr;
journalingFailure(ss.str().c_str()); // asserts, which then abends
}
return f;
}
/** put the basic write operation into the buffer (bb) to be journaled */
static void prepBasicWrite_inlock(AlignedBuilder& bb,
const WriteIntent* i,
RelativePath& lastDbPath) {
size_t ofs = 1;
DurableMappedFile* mmf = findMMF_inlock(i->start(), /*out*/ ofs);
if (MONGO_unlikely(!mmf->willNeedRemap())) {
// tag this mmf as needed a remap of its private view later.
// usually it will already be dirty/already set, so we do the if above first
// to avoid possibility of cpu cache line contention
mmf->setWillNeedRemap();
}
// since we have already looked up the mmf, we go ahead and remember the write view location
// so we don't have to find the DurableMappedFile again later in WRITETODATAFILES()
//
// this was for WRITETODATAFILES_Impl2 so commented out now
//
/*
dassert( i->w_ptr == 0 );
i->w_ptr = ((char*)mmf->view_write()) + ofs;
*/
JEntry e;
e.len = min(i->length(), (unsigned)(mmf->length() - ofs)); // don't write past end of file
verify(ofs <= 0x80000000);
e.ofs = (unsigned)ofs;
e.setFileNo(mmf->fileSuffixNo());
if (mmf->relativePath() == local) {
e.setLocalDbContextBit();
} else if (mmf->relativePath() != lastDbPath) {
lastDbPath = mmf->relativePath();
JDbContext c;
bb.appendStruct(c);
bb.appendStr(lastDbPath.toString());
}
bb.appendStruct(e);
bb.appendBuf(i->start(), e.len);
if (MONGO_unlikely(e.len != (unsigned)i->length())) {
log() << "journal info splitting prepBasicWrite at boundary" << endl;
// This only happens if we write to the last byte in a file and
// the fist byte in another file that is mapped adjacently. I
// think most OSs leave at least a one page gap between
// mappings, but better to be safe.
WriteIntent next((char*)i->start() + e.len, i->length() - e.len);
prepBasicWrite_inlock(bb, &next, lastDbPath);
}
}
/** basic write ops / write intents. note there is no particular order to these : if we have
two writes to the same location during the group commit interval, it is likely
(although not assured) that it is journaled here once.
*/
static void prepBasicWrites(AlignedBuilder& bb, const std::vector<WriteIntent>& intents) {
stdx::lock_guard<stdx::mutex> lk(privateViews._mutex());
// Each time write intents switch to a different database we journal a JDbContext.
// Switches will be rare as we sort by memory location first and we batch commit.
RelativePath lastDbPath;
invariant(!intents.empty());
WriteIntent last;
for (std::vector<WriteIntent>::const_iterator i = intents.begin(); i != intents.end(); i++) {
if (i->start() < last.end()) {
// overlaps
last.absorb(*i);
} else {
// discontinuous
if (i != intents.begin()) {
prepBasicWrite_inlock(bb, &last, lastDbPath);
}
//.........这里部分代码省略.........
示例2: defined
namespace dur {
#if defined(_DEBUG)
const bool DebugValidateMapsMatch = false;
const bool DebugCheckLastDeclaredWrite = false;
#else
const bool DebugValidateMapsMatch = false;
const bool DebugCheckLastDeclaredWrite = false;
#endif
DurableInterface* DurableInterface::_impl = new NonDurableImpl();
#if !defined(_DURABLE)
// called by startup/main
void enableDurability() {}
#else
void enableDurability() { // TODO: merge with startup() ?
assert(typeid(*DurableInterface::_impl) == typeid(NonDurableImpl));
// lets NonDurableImpl instance leak, but its tiny and only happens once
DurableInterface::_impl = new DurableImpl();
}
// later in this file
static void groupCommit();
static CommitJob commitJob;
bool DurableImpl::awaitCommit() {
commitJob.awaitNextCommit();
return true;
}
/** Declare that a file has been created
Normally writes are applied only after journalling, for safety. But here the file
is created first, and the journal will just replay the creation if the create didn't
happen because of crashing.
*/
void DurableImpl::createdFile(string filename, unsigned long long len) {
shared_ptr<DurOp> op( new FileCreatedOp(filename, len) );
commitJob.noteOp(op);
}
/** indicate that a database is about to be dropped. call before the actual drop. */
void DurableImpl::droppingDb(string db) {
shared_ptr<DurOp> op( new DropDbOp(db) );
commitJob.noteOp(op);
// must commit now, before files are actually unlinked:
groupCommit();
}
/** declare write intent. when already in the write view if testIntent is true. */
void DurableImpl::declareWriteIntent(void *p, unsigned len) {
WriteIntent w(p, len);
commitJob.note(w);
}
void* DurableImpl::writingPtr(void *x, unsigned len) {
void *p = x;
if( testIntent )
p = MongoMMF::switchToPrivateView(x);
declareWriteIntent(p, len);
return p;
}
/** declare intent to write
@param ofs offset within buf at which we will write
@param len the length at ofs we will write
@return new buffer pointer. this is modified when testIntent is true.
*/
void* DurableImpl::writingAtOffset(void *buf, unsigned ofs, unsigned len) {
char *p = (char *) buf;
if( testIntent )
p = (char *) MongoMMF::switchToPrivateView(buf);
declareWriteIntent(p+ofs, len);
return p;
}
/** Used in _DEBUG builds to check that we didn't overwrite the last intent
that was declared. called just before writelock release. we check a few
bytes after the declared region to see if they changed.
@see MongoMutex::_releasedWriteLock
SLOW
*/
#if defined(_DEBUG)
void DurableImpl::debugCheckLastDeclaredWrite() {
if( !DebugCheckLastDeclaredWrite )
return;
if( testIntent )
return;
static int n;
++n;
assert(debug && cmdLine.dur);
vector<WriteIntent>& w = commitJob.writes();
if( w.size() == 0 )
//.........这里部分代码省略.........
示例3: shutdownRequested
//.........这里部分代码省略.........
<< t.millis() << "ms";
}
// One instance of each durability interface
DurableImpl durableImpl;
NonDurableImpl nonDurableImpl;
// Notified when we commit to the journal.
static JournalListener* journalListener = &NoOpJournalListener::instance;
// Protects journalListener.
static stdx::mutex journalListenerMutex;
} // namespace
// Declared in dur_preplogbuffer.cpp
void PREPLOGBUFFER(JSectHeader& outHeader,
AlignedBuilder& outBuffer,
ClockSource* cs,
int64_t serverStartMs);
// Declared in dur_journal.cpp
boost::filesystem::path getJournalDir();
void preallocateFiles();
// Forward declaration
static void durThread(ClockSource* cs, int64_t serverStartMs);
// Durability activity statistics
Stats stats;
// Reference to the write intents tracking object
CommitJob commitJob;
// Reference to the active durability interface
DurableInterface* DurableInterface::_impl(&nonDurableImpl);
//
// Stats
//
Stats::Stats() : _currIdx(0) {}
void Stats::reset() {
// Seal the current metrics
_stats[_currIdx]._durationMillis = _stats[_currIdx].getCurrentDurationMillis();
// Use a new metric
const unsigned newCurrIdx = (_currIdx + 1) % (sizeof(_stats) / sizeof(_stats[0]));
_stats[newCurrIdx].reset();
_currIdx = newCurrIdx;
}
BSONObj Stats::asObj() const {
// Use the previous statistic
const S& stats = _stats[(_currIdx - 1) % (sizeof(_stats) / sizeof(_stats[0]))];
BSONObjBuilder builder;
stats._asObj(&builder);
return builder.obj();
}
示例4: WRITETODATAFILES
/** apply the writes back to the non-private MMF after they are for certain in redo log
(1) todo we don't need to write back everything every group commit. we MUST write back
that which is going to be a remapped on its private view - but that might not be all
views.
(2) todo should we do this using N threads? would be quite easy
see Hackenberg paper table 5 and 6. 2 threads might be a good balance.
locking: in read lock when called
*/
static void WRITETODATAFILES() {
/* we go backwards as what is at the end is most likely in the cpu cache. it won't be much, but we'll take it. */
for( int i = commitJob.writes().size() - 1; i >= 0; i-- ) {
const WriteIntent& intent = commitJob.writes()[i];
char *dst = (char *) (intent.w_ptr);
memcpy(dst, intent.p, intent.len);
}
debugValidateMapsMatch();
}
示例5: declareWriteIntents
void DurableImpl::declareWriteIntents(const std::vector<std::pair<void*, unsigned>>& intents) {
typedef std::vector<std::pair<void*, unsigned>> Intents;
stdx::lock_guard<SimpleMutex> lk(commitJob.groupCommitMutex);
for (Intents::const_iterator it(intents.begin()), end(intents.end()); it != end; ++it) {
commitJob.note(it->first, it->second);
}
}
示例6: remapPrivateView
/**
* Remaps the private view from the shared view so that it does not consume too much
* copy-on-write/swap space. Must only be called after the in-memory journal has been flushed
* to disk and applied on top of the shared view.
*
* @param fraction Value between (0, 1] indicating what fraction of the memory to remap.
* Remapping too much or too frequently incurs copy-on-write page fault cost.
*/
static void remapPrivateView(double fraction) {
// Remapping private views must occur after WRITETODATAFILES otherwise we wouldn't see any
// newly written data on reads.
invariant(!commitJob.hasWritten());
try {
Timer t;
remapPrivateViewImpl(fraction);
stats.curr()->_remapPrivateViewMicros += t.micros();
LOG(4) << "remapPrivateView end";
return;
} catch (DBException& e) {
severe() << "dbexception in remapPrivateView causing immediate shutdown: " << e.toString();
} catch (std::ios_base::failure& e) {
severe() << "ios_base exception in remapPrivateView causing immediate shutdown: "
<< e.what();
} catch (std::bad_alloc& e) {
severe() << "bad_alloc exception in remapPrivateView causing immediate shutdown: "
<< e.what();
} catch (std::exception& e) {
severe() << "exception in remapPrivateView causing immediate shutdown: " << e.what();
} catch (...) {
severe() << "unknown exception in remapPrivateView causing immediate shutdown: ";
}
invariant(false);
}
示例7: debugValidateMapsMatch
/** (SLOW) diagnostic to check that the private view and the non-private view are in sync.
*/
static void debugValidateMapsMatch() {
if( !DebugValidateMapsMatch )
return;
Timer t;
set<MongoFile*>& files = MongoFile::getAllFiles();
for( set<MongoFile*>::iterator i = files.begin(); i != files.end(); i++ ) {
MongoFile *mf = *i;
if( mf->isMongoMMF() ) {
MongoMMF *mmf = (MongoMMF*) mf;
const char *p = (const char *) mmf->getView();
const char *w = (const char *) mmf->view_write();
unsigned low = 0xffffffff;
unsigned high = 0;
for( unsigned i = 0; i < mmf->length(); i++ ) {
if( p[i] != w[i] ) {
log() << i << '\t' << (int) p[i] << '\t' << (int) w[i] << endl;
if( i < low ) low = i;
if( i > high ) high = i;
}
}
if( low != 0xffffffff ) {
std::stringstream ss;
ss << "dur error warning views mismatch " << mmf->filename() << ' ' << (hex) << low << ".." << high << " len:" << high-low+1;
log() << ss.str() << endl;
log() << "priv loc: " << (void*)(p+low) << endl;
vector<WriteIntent>& w = commitJob.writes();
(void)w; // mark as unused. Useful for inspection in debugger
breakpoint();
}
}
}
log() << "debugValidateMapsMatch " << t.millis() << "ms " << endl;
}
示例8: droppingDb
/** indicate that a database is about to be dropped. call before the actual drop. */
void DurableImpl::droppingDb(string db) {
shared_ptr<DurOp> op( new DropDbOp(db) );
commitJob.noteOp(op);
// must commit now, before files are actually unlinked:
groupCommit();
}
示例9: closingFileNotification
void DurableImpl::closingFileNotification() {
if (commitJob.hasWritten()) {
severe() << "journal warning files are closing outside locks with writes pending";
// File is closing while there are unwritten changes
invariant(false);
}
}
示例10: groupCommit
/** locking in read lock when called
@see MongoMMF::close()
*/
static void groupCommit() {
dbMutex.assertAtLeastReadLocked();
if( !commitJob.hasWritten() )
return;
PREPLOGBUFFER();
WRITETOJOURNAL(commitJob._ab);
// data is now in the journal, which is sufficient for acknowledging getlasterror.
// (ok to crash after that)
log() << "TEMP NOTIFYING COMMITTED" << endl;
commitJob.notifyCommitted();
// write the noted write intent entries to the data files.
// this has to come after writing to the journal, obviously...
MongoFile::markAllWritable(); // for _DEBUG. normally we don't write in a read lock
WRITETODATAFILES();
if (!dbMutex.isWriteLocked())
MongoFile::unmarkAllWritable();
commitJob.reset();
// REMAPPRIVATEVIEW
//
// remapping private views must occur after WRITETODATAFILES otherwise
// we wouldn't see newly written data on reads.
//
DEV assert( !commitJob.hasWritten() );
if( !dbMutex.isWriteLocked() ) {
// this needs done in a write lock thus we do it on the next acquisition of that
// instead of here (there is no rush if you aren't writing anyway -- but it must happen,
// if it is done, before any uncommitted writes occur).
//
dbMutex._remapPrivateViewRequested = true;
}
else {
// however, if we are already write locked, we must do it now -- up the call tree someone
// may do a write without a new lock acquisition. this can happen when MongoMMF::close() calls
// this method when a file (and its views) is about to go away.
//
REMAPPRIVATEVIEW();
}
}
示例11: commitIfNeeded
bool DurableImpl::commitIfNeeded() {
if (MONGO_likely(commitJob.bytes() < UncommittedBytesLimit)) {
return false;
}
// Just wake up the flush thread
flushRequested.notify_one();
return true;
}
示例12: closingFileNotification
/** called when a MongoMMF is closing -- we need to go ahead and group commit in that case before its
views disappear
*/
void closingFileNotification() {
if( dbMutex.atLeastReadLocked() ) {
groupCommit();
}
else {
assert( inShutdown() );
if( commitJob.hasWritten() ) {
log() << "dur warning files are closing outside locks with writes pending" << endl;
}
}
}
示例13: _PREPLOGBUFFER
/** we will build an output buffer ourself and then use O_DIRECT
we could be in read lock for this
caller handles locking
@return partially populated sectheader and _ab set
*/
static void _PREPLOGBUFFER(JSectHeader& h, AlignedBuilder& bb) {
// Add the JSectHeader
// Invalidate the total length, we will fill it in later.
h.setSectionLen(0xffffffff);
h.seqNumber = getLastDataFileFlushTime();
h.fileId = j.curFileId();
// Ops other than basic writes (DurOp's) go first
const std::vector<std::shared_ptr<DurOp>>& durOps = commitJob.ops();
for (std::vector<std::shared_ptr<DurOp>>::const_iterator i = durOps.begin(); i != durOps.end();
i++) {
(*i)->serialize(bb);
}
// Write intents
const std::vector<WriteIntent>& intents = commitJob.getIntentsSorted();
if (!intents.empty()) {
prepBasicWrites(bb, intents);
}
}
示例14: REMAPPRIVATEVIEW
/** We need to remap the private views periodically. otherwise they would become very large.
Call within write lock.
*/
void REMAPPRIVATEVIEW() {
static unsigned startAt;
static unsigned long long lastRemap;
dbMutex.assertWriteLocked();
dbMutex._remapPrivateViewRequested = false;
assert( !commitJob.hasWritten() );
if( 0 ) {
log() << "TEMP remapprivateview disabled for testing - will eventually run oom in this mode if db bigger than ram" << endl;
return;
}
// we want to remap all private views about every 2 seconds. there could be ~1000 views so
// we do a little each pass; beyond the remap time, more significantly, there will be copy on write
// faults after remapping, so doing a little bit at a time will avoid big load spikes on
// remapping.
unsigned long long now = curTimeMicros64();
double fraction = (now-lastRemap)/20000000.0;
set<MongoFile*>& files = MongoFile::getAllFiles();
unsigned sz = files.size();
if( sz == 0 )
return;
unsigned ntodo = (unsigned) (sz * fraction);
if( ntodo < 1 ) ntodo = 1;
if( ntodo > sz ) ntodo = sz;
const set<MongoFile*>::iterator b = files.begin();
const set<MongoFile*>::iterator e = files.end();
set<MongoFile*>::iterator i = b;
// skip to our starting position
for( unsigned x = 0; x < startAt; x++ ) {
i++;
if( i == e ) i = b;
}
startAt = (startAt + ntodo) % sz; // mark where to start next time
for( unsigned x = 0; x < ntodo; x++ ) {
dassert( i != e );
if( (*i)->isMongoMMF() ) {
MongoMMF *mmf = (MongoMMF*) *i;
assert(mmf);
if( mmf->willNeedRemap() ) {
mmf->willNeedRemap() = false;
mmf->remapThePrivateView();
}
i++;
if( i == e ) i = b;
}
}
}
示例15: go
static void go() {
if( !commitJob.hasWritten() )
return;
{
readlocktry lk("", 1000);
if( lk.got() ) {
groupCommit();
return;
}
}
// starvation on read locks could occur. so if read lock acquisition is slow, try to get a
// write lock instead. otherwise writes could use too much RAM.
writelock lk;
groupCommit();
}