本文整理汇总了C++中DurableMappedFile::getView方法的典型用法代码示例。如果您正苦于以下问题:C++ DurableMappedFile::getView方法的具体用法?C++ DurableMappedFile::getView怎么用?C++ DurableMappedFile::getView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DurableMappedFile
的用法示例。
在下文中一共展示了DurableMappedFile::getView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void operator () (MongoFile *mf) {
if( mf->isDurableMappedFile() ) {
DurableMappedFile *mmf = (DurableMappedFile*) mf;
const unsigned char *p = (const unsigned char *) mmf->getView();
const unsigned char *w = (const unsigned char *) mmf->view_write();
if (!p || !w) return; // File not fully opened yet
_bytes += mmf->length();
verify( mmf->length() == (unsigned) mmf->length() );
if (memcmp(p, w, (unsigned) mmf->length()) == 0)
return; // next file
unsigned low = 0xffffffff;
unsigned high = 0;
log() << "DurParanoid mismatch in " << mmf->filename() << endl;
int logged = 0;
unsigned lastMismatch = 0xffffffff;
for( unsigned i = 0; i < mmf->length(); i++ ) {
if( p[i] != w[i] ) {
if( lastMismatch != 0xffffffff && lastMismatch+1 != i )
log() << endl; // separate blocks of mismatches
lastMismatch= i;
if( ++logged < 60 ) {
if( logged == 1 )
log() << "ofs % 628 = 0x" << hex << (i%628) << endl; // for .ns files to find offset in record
stringstream ss;
ss << "mismatch ofs:" << hex << i << "\tfilemap:" << setw(2) << (unsigned) w[i] << "\tprivmap:" << setw(2) << (unsigned) p[i];
if( p[i] > 32 && p[i] <= 126 )
ss << '\t' << p[i];
log() << ss.str() << endl;
}
if( logged == 60 )
log() << "..." << endl;
if( i < low ) low = i;
if( i > high ) high = i;
}
}
if( low != 0xffffffff ) {
std::stringstream ss;
ss << "journal 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>& _intents = commitJob.wi()._intents;
//(void) _intents; // mark as unused. Useful for inspection in debugger
// should we abort() here so this isn't unnoticed in some circumstances?
massert(13599, "Written data does not match in-memory view. Missing WriteIntent?", false);
}
}
}
示例2: debugCheckLastDeclaredWrite
void DurableImpl::debugCheckLastDeclaredWrite() {
static int n;
++n;
verify(debug && storageGlobalParams.dur);
if (commitJob.writes().empty())
return;
const WriteIntent &i = commitJob.lastWrite();
size_t ofs;
DurableMappedFile *mmf = privateViews.find(i.start(), ofs);
if( mmf == 0 )
return;
size_t past = ofs + i.length();
if( mmf->length() < past + 8 )
return; // too close to end of view
char *priv = (char *) mmf->getView();
char *writ = (char *) mmf->view_write();
unsigned long long *a = (unsigned long long *) (priv+past);
unsigned long long *b = (unsigned long long *) (writ+past);
if( *a != *b ) {
for( set<WriteIntent>::iterator it(commitJob.writes().begin()), end((commitJob.writes().begin())); it != end; ++it ) {
const WriteIntent& wi = *it;
char *r1 = (char*) wi.start();
char *r2 = (char*) wi.end();
if( r1 <= (((char*)a)+8) && r2 > (char*)a ) {
//log() << "it's ok " << wi.p << ' ' << wi.len << endl;
return;
}
}
log() << "journal data after write area " << i.start() << " does not agree" << endl;
log() << " was: " << ((void*)b) << " " << hexdump((char*)b, 8) << endl;
log() << " now: " << ((void*)a) << " " << hexdump((char*)a, 8) << endl;
log() << " n: " << n << endl;
log() << endl;
}
}
示例3: run
void run() {
try { boost::filesystem::remove(fn); }
catch(...) { }
MMAPV1LockerImpl lockState;
Lock::GlobalWrite lk(&lockState);
{
DurableMappedFile f;
unsigned long long len = 256 * 1024 * 1024;
verify( f.create(fn, len, /*sequential*/false) );
{
char *p = (char *) f.getView();
verify(p);
// write something to the private view as a test
if (storageGlobalParams.dur)
privateViews.makeWritable(p, 6);
strcpy(p, "hello");
}
if (storageGlobalParams.dur) {
char *w = (char *) f.view_write();
strcpy(w + 6, "world");
}
MongoFileFinder ff;
ASSERT( ff.findByPath(fn) );
ASSERT( ff.findByPath("asdf") == 0 );
}
{
MongoFileFinder ff;
ASSERT( ff.findByPath(fn) == 0 );
}
int N = 10000;
#if !defined(_WIN32) && !defined(__linux__)
// seems this test is slow on OS X.
N = 100;
#endif
// we make a lot here -- if we were leaking, presumably it would fail doing this many.
Timer t;
for( int i = 0; i < N; i++ ) {
DurableMappedFile f;
verify( f.open(fn, i%4==1) );
{
char *p = (char *) f.getView();
verify(p);
if (storageGlobalParams.dur)
privateViews.makeWritable(p, 4);
strcpy(p, "zzz");
}
if (storageGlobalParams.dur) {
char *w = (char *) f.view_write();
if( i % 2 == 0 )
++(*w);
verify( w[6] == 'w' );
}
}
if( t.millis() > 10000 ) {
mongo::unittest::log() << "warning: MMap LeakTest is unusually slow N:" << N <<
' ' << t.millis() << "ms" << endl;
}
}